summaryrefslogtreecommitdiff
path: root/docs/design.org
diff options
context:
space:
mode:
authorAdrien Hopkins <ahopk127@my.yorku.ca>2021-08-26 08:38:34 -0500
committerAdrien Hopkins <ahopk127@my.yorku.ca>2021-08-26 08:38:34 -0500
commit3eab1082f65687085b04f59605673696353d5ede (patch)
tree7adfc4e411b52ecf3183a78823b0b4b2152e9b90 /docs/design.org
parent1cb69cfdcb18bbafdbc792174697732e7cf359e7 (diff)
Finished sections on prefixes and UnitDatabase
Diffstat (limited to 'docs/design.org')
-rw-r--r--docs/design.org21
1 files changed, 18 insertions, 3 deletions
diff --git a/docs/design.org b/docs/design.org
index 41713eb..1453327 100644
--- a/docs/design.org
+++ b/docs/design.org
@@ -1,11 +1,12 @@
#+TITLE: 7Units Design Document
#+SUBTITLE: For version 0.3.1
-#+DATE: 2021 August 24
+#+DATE: 2021 August 26
#+LaTeX_HEADER: \usepackage[a4paper, lmargin=25mm, rmargin=25mm, tmargin=25mm, bmargin=25mm]{geometry}
#+LaTeX_HEADER: \usepackage{xurl}
+#+LaTeX: \newpage
* Introduction
- 7Units is a program that can convert between units. This document details the internal design of 7Units, for current and future developers.
+ 7Units is a program that can convert between units. This document details the internal design of 7Units, intended to be used by current and future developers.
The frontend code is currently subject to change, so it is not included in the current version of this document.
* Unit System Design
@@ -34,8 +35,22 @@
- BritishImperial :: A static utility class with instances of common units in the British Imperial system (not to be confused with the US Customary system, which is also called "Imperial"; it has the same unit names but the values of a few units are different). This class and the US Customary is divided into static classes for each dimension, such as ~BritishImperial.Length~.
- USCustomary :: A static utility class with instances of common units in the US Customary system (not to be confused with the British Imperial system; it has the same unit names but the values of a few units are different).
** Prefixes
-
+ A ~UnitPrefix~ is a simple object that can multiply a ~LinearUnit~ by a value. It can calculate a new name for the unit by combining its name and the unit's name (symbols are done similarly). It can do multiplication, division and exponentation with a number, as well as multiplication and division with another prefix; all of these work by changing the prefix's multiplier.
** The Unit Database
+ The ~UnitDatabase~ class stores all of the unit, prefix and dimension data used by this program. It is not a representation of an actual database, just a class that stores lots of data.
+
+ Units are stored using a custom ~Map~ implementation (~PrefixedUnitMap~) which maps unit names to units. It is backed by two maps: one for units (without prefixes) and one for prefixes. It is programmed to include prefixes (so if units includes "metre" and prefixes includes "kilo", this map will include "kilometre", mapping it to a unit representing a kilometre). It is immutable, but you can modify the underlying maps, which is reflected in the ~PrefixedUnitMap~. Other than that, it is a normal map implementation.
+
+ Prefixes and dimensions are stored in normal maps.
+*** Parsing Expressions
+ Each ~UnitDatabase~ instance has four [[*ExpressionParser][ExpressionParser]] instances associated with it, for four types of expressions: unit, unit value, prefix and dimension. They are mostly similar, with operators corresponding to each operation of the corresponding class (~LinearUnit~, ~LinearUnitValue~, ~UnitPrefix~, ~ObjectProduct<BaseDimension>~). Unit and unit value expressions use linear units; nonlinear units can be used with a special syntax (like "degC(20)") and are immediately converted to a linear unit representing their base (Kelvin in this case) before operating.
+*** Parsing Files
+ There are two types of data files: unit and dimension.
+
+ Unit files contain data about units and prefixes. Each line contains the name of a unit or prefix (prefixes end in a dash, units don't) followed by an expression which defines it, separated by one or more space characters (this behaviour is defined by the static regular expression ~NAME_EXPRESSION~). Unit files are parsed line by line, each line being run through the ~addUnitOrPrefixFromLine~ method, which splits a line into name and expression, determines whether it's a unit or a prefix, and parses the expression. Because all units are defined by others, base units need to be defined with a special expression "!"; *these units should be added to the database before parsing the file*.
+
+ Dimension files are similar, only for dimensions instead of units and prefixes.
+#+LaTeX: \newpage
* Utility Classes
7Units has a few general "utility" classes. They aren't directly related to units, but are used in the units system.
** ObjectProduct