Browse Source

Add misc units

David Peter 2 years ago
parent
commit
1b214e25b6

+ 4 - 9
examples/custom_dimensions.nbt

@@ -1,13 +1,8 @@
-dimension Money
-
-@aliases(EUR, €)
-unit euro: Money
-
-dimension Person
-unit person: Person
+dimension Student
+unit student: Student
 
 let lunch_cost = 85 €
 
-let cost_per_person = lunch_cost / 4 person
+let cost_per_student = lunch_cost / 4 student
 
-assert_eq(cost_per_person, 21.25 € / person, 0.01 € / person)
+assert_eq(cost_per_student, 21.25 € / student, 0.01 € / student)

+ 1 - 8
examples/inter_dot_spacing.nbt

@@ -1,10 +1,3 @@
-dimension Dot
-
-@aliases(dots)
-unit dot: Dot
-
-unit dpi = dots / inch
-
-fn inter_dot_spacing(resolution: Dot/Length) -> Length = 1 dot / resolution
+fn inter_dot_spacing(resolution: Dot / Length) -> Length = 1 dot / resolution
 
 assert_eq(inter_dot_spacing(72 dpi), 353 µm, 1µm)

+ 0 - 5
examples/workhours.nbt

@@ -1,8 +1,3 @@
-dimension Money
-
-@aliases(EUR, €)
-unit euro: Money
-
 dimension WorkHour
 
 @aliases(workhours)

+ 8 - 1
modules/prelude.nbt

@@ -6,10 +6,17 @@ use math::functions
 
 use units::si
 use units::time
+use units::astronomical
+use units::imperial
 use units::us_customary
+use units::nautical
+# use units::cgs
+use units::fff
 use units::misc
-use units::astronomical
+
+use units::currency
 use units::bit
+use units::placeholder
 
 use physics::constants
 use physics::temperature_conversion

+ 6 - 1
modules/units/cgs.nbt

@@ -1,3 +1,8 @@
 ### Centimetre–gram–second system of units
 
-unit erg: Energy = 1e-7 joule
+@aliases(dyn)
+unit dyne: Force = 1e-5 N
+
+unit erg: Energy = 1 dyn cm
+
+unit gauss: MagneticFluxDensity = 100 µT

+ 4 - 0
modules/units/currency.nbt

@@ -0,0 +1,4 @@
+dimension Money
+
+@aliases(euros, EUR, €: short)
+unit euro: Money

+ 14 - 0
modules/units/fff.nbt

@@ -0,0 +1,14 @@
+# The furlong–firkin–fortnight system
+# https://en.wikipedia.org/wiki/FFF_system
+
+@metric_prefixes
+@aliases(furlongs)
+unit furlong: Length = 220 yard
+
+@metric_prefixes
+@aliases(firkins)
+unit firkin: Mass = 90 lb
+
+@metric_prefixes
+@aliases(fortnights)
+unit fortnight = 14 days

+ 28 - 0
modules/units/imperial.nbt

@@ -0,0 +1,28 @@
+### Imperial unit system
+
+@aliases(inches, in: short)
+unit inch: Length = 0.0254 meter
+
+@aliases(feet, ft: short)
+unit foot: Length = 0.3048 meter
+assert_eq(1 foot, 12 inches, 0.001 inch)  # TODO: move those assertions somewhere else
+
+@aliases(yards, yd: short)
+unit yard: Length = 0.9144 meter
+assert_eq(1 yard, 3 feet, 0.001 foot)
+
+@aliases(miles, mi: short)
+unit mile: Length = 1609.344 meter
+assert_eq(1 mile, 1760 yard, 0.001 yard)
+
+@aliases(ounces, oz: short)
+unit ounce: Mass = 28.35 gram
+
+@aliases(pounds, lb: short)
+unit pound: Mass = 453.6 gram
+
+@aliases(mils, mil: short)
+unit thou: Length = 0.0000254 meter
+
+@aliases(fathoms)
+unit fathom: Length = 2 yard

+ 31 - 9
modules/units/misc.nbt

@@ -10,22 +10,44 @@ unit angstrom: Length = 1e-10 meter
 @aliases(barns)
 unit barn: Area = 1e-28 meter^2
 
-@metric_prefixes
-@aliases(Wh: short)
-unit watthour = W h
+@aliases(calories, cal: short)
+unit calorie: Energy = 4.184 joule
+
+unit BTU: Energy = 1055.05585262 joule
+
+@aliases(lbf: short)
+unit pound_force: Force = 4.448222 newton
+
+@aliases(ozf: short)
+unit ounce_force: Force = 16 lbf
+
+@aliases(kgf: short)
+unit kilogram_force: Force = 9.80665 newton
+
+@aliases(RPM: short)
+unit rpm: Frequency = 1 / minute
 
-@aliases(knots)
-unit knot: Speed = 463 m / 900 s
+unit mmHg: Pressure = 133.322387415 pascal
 
-### Useful 'dummy' units
+unit torr: Pressure = 101325 / 760 × pascal
 
-dimension Pixel
+@aliases(PSI: short)
+unit psi: Pressure = 6.894757 kPa
+
+@aliases(atmospheres, atm: short)
+unit atmosphere: Pressure = 101325 pascal
+
+@metric_prefixes
+unit molar: AmountOfSubstance / Volume = 1 mol / litre
 
 @metric_prefixes
-@aliases(pixels, px: short)
-unit pixel: Pixel
+unit molal: AmountOfSubstance / Mass = 1 mole / kilogram
 
 ### Abbreviations
 
+@metric_prefixes
+@aliases(Wh: short)
+unit watthour = W h
+
 unit mph = miles per hour
 unit kph = kilometer per hour

+ 5 - 0
modules/units/nautical.nbt

@@ -0,0 +1,5 @@
+@aliases(knots, kn: short, kt: short)
+unit knot: Speed = 463 m / 900 s
+
+@aliases(nautical_miles, NM: short)
+unit nautical_mile = 1852 m

+ 36 - 0
modules/units/placeholder.nbt

@@ -0,0 +1,36 @@
+# Smallest addressable element on a digital display
+dimension Pixel
+
+@metric_prefixes
+@aliases(pixels, px: short)
+unit pixel: Pixel
+
+
+# Smallest possible output resolution on a printing device
+dimension Dot
+
+@aliases(dots)
+unit dot: Dot
+
+unit dpi: Dot / Length = dots / inch
+
+
+# A single image in a (video) sequence
+dimension Frame
+
+@aliases(frames)
+unit frame: Frame
+
+
+# A separate or limited portion or quantity of something
+dimension Piece
+
+@aliases(pieces)
+unit piece: Piece
+
+
+# A human being
+dimension Person
+
+@aliases(persons, people)
+unit person: Person

+ 25 - 19
modules/units/us_customary.nbt

@@ -1,26 +1,32 @@
-### US customary units
+# US liquid gallon
+@aliases(gallons, gal: short)
+unit gallon: Volume = 0.003785411784 meter^3
+assert_eq(1 gallon, 231 inch^3, 0.001 inch^3)
 
-@aliases(inches, in: short)
-unit inch: Length = 0.0254 meter
+# US liquid pint
+@aliases(pints)
+unit pint = 1/8 × gallon
 
-@aliases(feet, ft: short)
-unit foot: Length = 0.3048 meter
-assert_eq(1 foot, 12 inches, 0.001 inch)  # TODO: move those assertions somewhere else
+# US cup
+@aliases(cups)
+unit cup = 1/2 × pint
 
-@aliases(yards, yd: short)
-unit yard: Length = 0.9144 meter
-assert_eq(1 yard, 3 feet, 0.001 foot)
+# US tablespoon
+@aliases(tablespoons, tbsp)
+unit tablespoon = 1/16 × cup
 
-@aliases(miles, mi: short)
-unit mile: Length = 1609.344 meter
-assert_eq(1 mile, 1760 yard, 0.001 yard)
+# US teaspoon
+@aliases(teaspoons, tsp)
+unit teaspoon = 1/3 × tablespoon
 
-@aliases(gallons, gal: short)
-unit gallon: Volume = 0.003785411784 meter^3
-assert_eq(1 gallon, 231 inch^3, 0.001 inch^3)
+# US fluid ounce
+@aliases(fluidounces, floz: short)
+unit fluidounce = 2 tablespoon
 
-@aliases(fathoms)
-unit fathom: Length = 2 yard
+# US hogshead
+@aliases(hogsheads)
+unit hogshead = 63 gallon
 
-@aliases(furlongs)
-unit furlong: Length = 220 yard
+# US rod
+@aliases(rods)
+unit rod = 16.5 ft