From e42c2099d64caba0ba5ef9d0b9f0284e7d17aed5 Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Wed, 17 Apr 2024 21:24:45 -0600 Subject: [PATCH 1/4] feature: Adds quart & imperialQuart units --- Sources/Units/Unit/DefaultUnits.swift | 13 +++++++++++++ Sources/Units/Unit/Unit+DefaultUnits.swift | 2 ++ 2 files changed, 15 insertions(+) diff --git a/Sources/Units/Unit/DefaultUnits.swift b/Sources/Units/Unit/DefaultUnits.swift index 375dce1..434352c 100644 --- a/Sources/Units/Unit/DefaultUnits.swift +++ b/Sources/Units/Unit/DefaultUnits.swift @@ -1022,6 +1022,13 @@ enum DefaultUnits { dimension: [.Length: 3], coefficient: 473.176473e-6 ) + // Liquid quart: https://en.wikipedia.org/wiki/Quart#US_liquid_quart + static let quart = try! DefinedUnit( + name: "quart", + symbol: "qt", + dimension: [.Length: 3], + coefficient: 9.46352946e-4 + ) static let gallon = try! DefinedUnit( name: "gallon", symbol: "gal", @@ -1046,6 +1053,12 @@ enum DefaultUnits { dimension: [.Length: 3], coefficient: 568.26125e-6 ) + static let imperialQuart = try! DefinedUnit( + name: "imperialQuart", + symbol: "iqt", + dimension: [.Length: 3], + coefficient: 1.1365225e-3 + ) static let imperialGallon = try! DefinedUnit( name: "imperialGallon", symbol: "igal", diff --git a/Sources/Units/Unit/Unit+DefaultUnits.swift b/Sources/Units/Unit/Unit+DefaultUnits.swift index ce519c2..9442576 100644 --- a/Sources/Units/Unit/Unit+DefaultUnits.swift +++ b/Sources/Units/Unit/Unit+DefaultUnits.swift @@ -239,10 +239,12 @@ public extension Unit { static let fluidOunce = Unit(definedBy: DefaultUnits.fluidOunce) static let cup = Unit(definedBy: DefaultUnits.cup) static let pint = Unit(definedBy: DefaultUnits.pint) + static let quart = Unit(definedBy: DefaultUnits.quart) static let gallon = Unit(definedBy: DefaultUnits.gallon) static let imperialFluidOunce = Unit(definedBy: DefaultUnits.imperialFluidOunce) static let imperialCup = Unit(definedBy: DefaultUnits.imperialCup) static let imperialPint = Unit(definedBy: DefaultUnits.imperialPint) + static let imperialQuart = Unit(definedBy: DefaultUnits.imperialQuart) static let imperialGallon = Unit(definedBy: DefaultUnits.imperialGallon) static let metricCup = Unit(definedBy: DefaultUnits.metricCup) } From 47657f207518c1666c35da7e709bc2b144d7d5de Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Wed, 17 Apr 2024 21:26:58 -0600 Subject: [PATCH 2/4] refactor: Moves & comments volume units --- Sources/Units/Unit/DefaultUnits.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Sources/Units/Unit/DefaultUnits.swift b/Sources/Units/Unit/DefaultUnits.swift index 434352c..9f6e243 100644 --- a/Sources/Units/Unit/DefaultUnits.swift +++ b/Sources/Units/Unit/DefaultUnits.swift @@ -986,12 +986,7 @@ enum DefaultUnits { dimension: [.Length: 3], coefficient: 1000 ) - static let bushel = try! DefinedUnit( - name: "bushel", - symbol: "bushel", - dimension: [.Length: 3], - coefficient: 0.03523907 - ) + // Liquid measures static let teaspoon = try! DefinedUnit( name: "teaspoon", symbol: "tsp", @@ -1022,7 +1017,6 @@ enum DefaultUnits { dimension: [.Length: 3], coefficient: 473.176473e-6 ) - // Liquid quart: https://en.wikipedia.org/wiki/Quart#US_liquid_quart static let quart = try! DefinedUnit( name: "quart", symbol: "qt", @@ -1035,6 +1029,14 @@ enum DefaultUnits { dimension: [.Length: 3], coefficient: 0.003785411784 ) + // Dry measures + static let bushel = try! DefinedUnit( + name: "bushel", + symbol: "bushel", + dimension: [.Length: 3], + coefficient: 0.03523907 + ) + // Imperial measures static let imperialFluidOunce = try! DefinedUnit( name: "imperialFluidOunce", symbol: "ifl_oz", From 374ded6ead733a057dea2a609f071b941eb51357 Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Wed, 17 Apr 2024 21:40:10 -0600 Subject: [PATCH 3/4] feature: Adds volume dry units --- Sources/Units/Registry.swift | 6 ++++- Sources/Units/Unit/DefaultUnits.swift | 30 +++++++++++++++++++--- Sources/Units/Unit/Unit+DefaultUnits.swift | 6 ++++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Sources/Units/Registry.swift b/Sources/Units/Registry.swift index efbcea5..784ade5 100644 --- a/Sources/Units/Registry.swift +++ b/Sources/Units/Registry.swift @@ -324,17 +324,21 @@ internal class Registry { DefaultUnits.deciliter, DefaultUnits.kiloliter, DefaultUnits.megaliter, - DefaultUnits.bushel, DefaultUnits.teaspoon, DefaultUnits.tablespoon, DefaultUnits.fluidOunce, DefaultUnits.cup, DefaultUnits.pint, DefaultUnits.gallon, + DefaultUnits.dryPint, + DefaultUnits.dryQuart, + DefaultUnits.peck, + DefaultUnits.bushel, DefaultUnits.imperialFluidOunce, DefaultUnits.imperialCup, DefaultUnits.imperialPint, DefaultUnits.imperialGallon, + DefaultUnits.imperialPeck, DefaultUnits.metricCup, ] } diff --git a/Sources/Units/Unit/DefaultUnits.swift b/Sources/Units/Unit/DefaultUnits.swift index 9f6e243..672c1af 100644 --- a/Sources/Units/Unit/DefaultUnits.swift +++ b/Sources/Units/Unit/DefaultUnits.swift @@ -1029,12 +1029,30 @@ enum DefaultUnits { dimension: [.Length: 3], coefficient: 0.003785411784 ) - // Dry measures + // Dry measures: https://en.wikipedia.org/wiki/Dry_measure + static let dryPint: DefinedUnit = try! DefinedUnit( + name: "dryPint", + symbol: "drypt", + dimension: [.Length: 3], + coefficient: 5.506104713575e-4 + ) + static let dryQuart: DefinedUnit = try! DefinedUnit( + name: "dryQuart", + symbol: "dryqt", + dimension: [.Length: 3], + coefficient: 1.101220942715e-3 + ) + static let peck: DefinedUnit = try! DefinedUnit( + name: "peck", + symbol: "pk", + dimension: [.Length: 3], + coefficient: 8.80976754172e-3 + ) static let bushel = try! DefinedUnit( name: "bushel", - symbol: "bushel", + symbol: "bu", dimension: [.Length: 3], - coefficient: 0.03523907 + coefficient: 0.035239070167 ) // Imperial measures static let imperialFluidOunce = try! DefinedUnit( @@ -1067,6 +1085,12 @@ enum DefaultUnits { dimension: [.Length: 3], coefficient: 0.00454609 ) + static let imperialPeck: DefinedUnit = try! DefinedUnit( + name: "imperialPeck", + symbol: "ipk", + dimension: [.Length: 3], + coefficient: 9.09218e-3 + ) static let metricCup = try! DefinedUnit( name: "metricCup", symbol: "mcup", diff --git a/Sources/Units/Unit/Unit+DefaultUnits.swift b/Sources/Units/Unit/Unit+DefaultUnits.swift index 9442576..a61aaac 100644 --- a/Sources/Units/Unit/Unit+DefaultUnits.swift +++ b/Sources/Units/Unit/Unit+DefaultUnits.swift @@ -233,7 +233,6 @@ public extension Unit { static let deciliter = Unit(definedBy: DefaultUnits.deciliter) static let kiloliter = Unit(definedBy: DefaultUnits.kiloliter) static let megaliter = Unit(definedBy: DefaultUnits.megaliter) - static let bushel = Unit(definedBy: DefaultUnits.bushel) static let teaspoon = Unit(definedBy: DefaultUnits.teaspoon) static let tablespoon = Unit(definedBy: DefaultUnits.tablespoon) static let fluidOunce = Unit(definedBy: DefaultUnits.fluidOunce) @@ -241,10 +240,15 @@ public extension Unit { static let pint = Unit(definedBy: DefaultUnits.pint) static let quart = Unit(definedBy: DefaultUnits.quart) static let gallon = Unit(definedBy: DefaultUnits.gallon) + static let dryPint = Unit(definedBy: DefaultUnits.dryPint) + static let dryQuart = Unit(definedBy: DefaultUnits.dryQuart) + static let peck = Unit(definedBy: DefaultUnits.peck) + static let bushel = Unit(definedBy: DefaultUnits.bushel) static let imperialFluidOunce = Unit(definedBy: DefaultUnits.imperialFluidOunce) static let imperialCup = Unit(definedBy: DefaultUnits.imperialCup) static let imperialPint = Unit(definedBy: DefaultUnits.imperialPint) static let imperialQuart = Unit(definedBy: DefaultUnits.imperialQuart) static let imperialGallon = Unit(definedBy: DefaultUnits.imperialGallon) + static let imperialPeck = Unit(definedBy: DefaultUnits.imperialPeck) static let metricCup = Unit(definedBy: DefaultUnits.metricCup) } From 338204b4bcbdc921f99da9e8bcfd6b538008ca2a Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Wed, 17 Apr 2024 22:01:44 -0600 Subject: [PATCH 4/4] docs: Adds note to keep Registry in sync --- Sources/Units/Unit/DefaultUnits.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Units/Unit/DefaultUnits.swift b/Sources/Units/Unit/DefaultUnits.swift index 672c1af..adb9763 100644 --- a/Sources/Units/Unit/DefaultUnits.swift +++ b/Sources/Units/Unit/DefaultUnits.swift @@ -1,6 +1,6 @@ /// Static type containing this package's pre-defined units enum DefaultUnits { - // MARK: If adding additional units to this list, add corresponding entries in the `Unit+DefaultUnits.swift` file + // MARK: If adding units to this list, add corresponding entries in the `Unit+DefaultUnits.swift` & `Registry.swift` files // MARK: Acceleration