From 208c56b56940e58fae1253a8d38e9e56249eb0cb Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Thu, 26 Aug 2021 11:26:02 -0500 Subject: Finished initial draft of design document --- docs/design.org | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'docs/design.org') diff --git a/docs/design.org b/docs/design.org index 1453327..be345f2 100644 --- a/docs/design.org +++ b/docs/design.org @@ -11,6 +11,11 @@ The frontend code is currently subject to change, so it is not included in the current version of this document. * Unit System Design Any code related to the backend unit system is stored in the ~sevenUnits.unit~ package. + + Here is a class diagram of the system. Unimportant methods, methods inherited from Object, getters and setters have been omitted. + [[./diagrams/units-class-diagram.plantuml.png]] + #+CAPTION: Class diagram of sevenUnits.unit + #+LaTeX: \newpage ** Dimensions Dimensions represent what a unit is measuring, such as length, time, or energy. Dimensions are represented as an [[*ObjectProduct][ObjectProduct]], where ~BaseDimension~ is a very simple class (its only properties are a name and a symbol) which represents the dimension of a base unit; these base dimensions can be multiplied to create all other Dimensions. ** Unit Classes @@ -21,7 +26,7 @@ ~BaseUnit~ represents a unit that all other units are defined by. All of the units used by this system are defined by seven SI ~BaseUnit~ instances (metre, second, kilogram, ampere, kelvin, mole, candela; this is what 7Units is named after) and two non-SI ~BaseUnit~ instances (US dollar and bit). Because base units are themselves units (and should be able to be used as units), ~BaseUnit~ is a subclass of ~Unit~, using its own package-private constructor. However, most units are instances of ~LinearUnit~, another subclass of ~Unit~. ~LinearUnit~ represents a unit that is /a product of a base unit and a constant called the *conversion factor*/. Most units you've ever used fall under this definition, the only common exceptions are degrees Celsius and Fahrenheit. This simplicity allows the ~LinearUnit~ to do many things: - - It can implement conversion to and from the base as multiplying and dividing respectively by the conversion factor + - It can implement conversion to and from the base as multiplying and dividing by the conversion factor respectively - You can easily create new units by multiplying or dividing a ~LinearUnit~ by a number (for example, kilometre = metre * 1000). This can be easily implemented as multiplying this unit's conversion factor by the multiplier and returning a new ~LinearUnit~ with that conversion factor factor. - You can add or subtract two ~LinearUnit~ instances to create a third (as long as they have the same base) by adding or subtracting the conversion factor. - You can multiply or divide any two ~LinearUnit~ instances to create a third by multiplying or dividing the bases and conversion factors. @@ -71,7 +76,7 @@ After evaluating the last token, there should be one value left in the stack - the answer. If there isn't, the original expression was malformed. ** Math Classes There are two simple math classes in 7Units: - - ~UncertainDouble~ :: Like a ~double~, but with an uncertainty (e.g. \(2.0 \pm 0.4\)). The operations are like those of the regular Double, only they also calculate the uncertainty of the final value. They also have "exact" versions to help interoperation between ~double~ and ~UncertainDouble~. + - ~UncertainDouble~ :: Like a ~double~, but with an uncertainty (e.g. \(2.0 \pm 0.4\)). The operations are like those of the regular Double, only they also calculate the uncertainty of the final value. They also have "exact" versions to help interoperation between ~double~ and ~UncertainDouble~. It is used by the converter's Scientific Precision setting. - ~DecimalComparison~ :: A static utility class that contains a few alternate equals() methods for ~double~ and ~UncertainDouble~. These methods allow a slight (configurable) difference between values to still be considered equal, to fight roundoff error. ** Collection Classes The ~ConditionalExistenceCollections~ class contains wrapper implementations of ~Collection~, ~Iterator~, ~Map~ and ~Set~. These implementations ignore elements that do not pass a certain condition - if an element fails the condition, ~contains~ will return false, the iterator will skip past it, it won't be counted in ~size~, etc. even if it exists in the original collection. Effectively, any element of the original collection that fails the test does not exist. -- cgit v1.2.3