From e22c5184215530bb450fa710b739637504f4ebe6 Mon Sep 17 00:00:00 2001 From: katjam Date: Wed, 3 Oct 2018 19:06:40 +0100 Subject: [PATCH 01/15] Provide initial volume functions --- src/Volume.elm | 131 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 src/Volume.elm diff --git a/src/Volume.elm b/src/Volume.elm new file mode 100644 index 0000000..d759689 --- /dev/null +++ b/src/Volume.elm @@ -0,0 +1,131 @@ +module Volume exposing + ( Volume, CubicMeters + , cubicMeters, inCubicMeters + , cubicMillimeters, inCubicMillimeters, cubicCentimeters, inCubicCentimeters + , cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards + --, milliliter, liter, deciliter + --, usLiquidGallons, usDryGallons, imperialGallons + --, usLiquidQuarts, usDryQuarts, imperialQuarts + --, usLiquidPints, usDryPints, imperialPints + --, usFluidOunces, imperialFluidOunces + ) + +{-| A `Volume` represents a volume in cubic meters, cubic feet, liters, +US liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic meters. + +@docs Volume, CubicMeters + + +## Metric + +@docs cubicMeters, inCubicMeters +@docs cubicMillimeters, inCubicMillimeters, cubicCentimeters, inCubicCentimeters +@docs --@docs milliliters, inMilliliters, liters, etc + + +## Imperial + +@docs cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards +@docs --@docs usLiquidGallons, usDryGallons, imperialGallons +@docs --@docs usLiquidQuarts, usDryQuarts, imperialQuarts +@docs --@docs usLiquidPints, usDryPints, imperialPints +@docs --@docs usFluidOunces, imperialFluidOunces + +-} + +import Length exposing (Meters) +import Quantity exposing (Quantity(..)) + + +{-| -} +type alias CubicMeters = + Cubed Meters + + +{-| -} +type alias Volume = + Quantity Float CubicMeters + + +{-| Construct a volume from a number of cubic meters. +-} +cubicMeters : Float -> Volume +cubicMeters numCubicMeters = + Quantity numCubicMeters + + +{-| Convert a volume to a number of cubic meters. +-} +inCubicMeters : Volume -> Float +inCubicMeters (Quantity numCubicMeters) = + numCubicMeters + + +{-| Construct a volume from a number of cubic millimeters. +-} +cubicMillimeters : Float -> Volume +cubicMillimeters numCubicMillimeters = + cubicMeters (1.0e-9 * numCubicMillimeters) + + +{-| Convert a volume to a number of cubic millimeters. +-} +inCubicMillimeters : Volume -> Float +inCubicMillimeters volume = + 1.0e9 * inCubicMeters volume + + +{-| Construct a volume from a number of cubic inches. +-} +cubicInches : Float -> Volume +cubicInches numCubicInches = + cubicMeters (0.0254 * 0.0254 * 0.0254 * numCubicInches) + + +{-| Convert a volume to a number of cubic inches. +-} +inCubicInches : Volume -> Float +inCubicInches volume = + inCubicMeters volume / (0.0254 * 0.0254 * 0.0254) + + +{-| Construct a volume from a number of cubic centimeters. +-} +cubicCentimeters : Float -> Volume +cubicCentimeters numCubicCentimeters = + cubicMeters (1.0e-6 * numCubicCentimeters) + + +{-| Convert a volume to a number of cubic centimeters. +-} +inCubicCentimeters : Volume -> Float +inCubicCentimeters volume = + 1.0e6 * inCubicMeters volume + + +{-| Construct a volume from a number of cubic feet. +-} +cubicFeet : Float -> Volume +cubicFeet numCubicFeet = + cubicMeters (0.3048 * 0.3048 * 0.3048 * numCubicFeet) + + +{-| Convert a volume to a number of cubic feet. +-} +inCubicFeet : Volume -> Float +inCubicFeet volume = + inCubicMeters volume / (0.3048 * 0.3048 * 0.3048) + + +{-| Construct a volume from a number of cubic yards. +-} +cubicYards : Float -> Volume +cubicYards numCubicYards = + cubicMeters (0.9144 * 0.9144 * 0.9144 * numCubicYards) + + +{-| Convert a volume to a number of cubic yards. +-} +inCubicYards : Volume -> Float +inCubicYards volume = + inCubicMeters volume / (0.9144 * 0.9144 * 0.9144) From b0986d7326f9a77b55f064f5565fc0f0a8b70c67 Mon Sep 17 00:00:00 2001 From: katjam Date: Wed, 3 Oct 2018 20:10:23 +0100 Subject: [PATCH 02/15] Add cubed and cbrt support to Quantity --- src/Quantity.elm | 36 +++++++++++++++++++++++++++++++----- src/Volume.elm | 2 +- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/Quantity.elm b/src/Quantity.elm index 823461e..3a52d12 100644 --- a/src/Quantity.elm +++ b/src/Quantity.elm @@ -1,9 +1,9 @@ module Quantity exposing ( Quantity(..) - , Squared, Rate + , Squared, Cubed, Rate , zero, infinity, positiveInfinity, negativeInfinity , lessThan, greaterThan, compare, equalWithin, max, min, isNaN, isInfinite - , negate, plus, minus, product, ratio, scaleBy, divideBy, abs, clamp, squared, sqrt + , negate, plus, minus, product, ratio, scaleBy, divideBy, abs, clamp, squared, sqrt, cubed, cbrt , round, floor, ceiling, truncate , sum, minimum, maximum, sort , per, times, at, at_, inverse @@ -18,10 +18,10 @@ module Quantity exposing # Unit types -The `Squared` and `Rate` units types allow you to build up and work with +The `Squared`, `Cubed` and `Rate` units types allow you to build up and work with composite units in a fairly flexible way. -@docs Squared, Rate +@docs Squared, Cubed, Rate # Constants @@ -36,7 +36,7 @@ composite units in a fairly flexible way. # Arithmetic -@docs negate, plus, minus, product, ratio, scaleBy, divideBy, abs, clamp, squared, sqrt +@docs negate, plus, minus, product, ratio, scaleBy, divideBy, abs, clamp, squared, sqrt, cubed, cbrt # Rounding @@ -117,6 +117,17 @@ type Squared units = Squared units +{-| Represents a units type that is the cube of some other units type; for +example, `Meters` is one units type (the units type of a `Length`) and `Cubed +Meters` is another (the units type of an `Volume`). This is useful because some +functions in this module (specifically [`cubed`](Quantity#cubed), +and [`cbrt`](Quantity#cbrt)) "know" about the +`Cubed` type and how to work with it. +-} +type Cubed units + = Cubed units + + {-| Represents a rate or quotient such as a speed (`Rate Meters Seconds`) or a pressure (`Rate Newtons SquareMeters`). As with `Squared`, there are several functions that "know" about the `Rate` type and how to work with it - see @@ -506,6 +517,21 @@ sqrt (Quantity value) = Quantity (Basics.sqrt value) +{-| Cube a quantity with some `units`, resulting in a new quantity in +`Cubed units. +-} +cubed : Quantity number units -> Quantity number (Cubed units) +cubed (Quantity value) = + Quantity (value * value * value) + + +{-| Take a quantity in `Cubed units` and return the cube root of that +quantity in plain `units. +-} +cbrt : Quantity Float (Cubed units) -> Quantity Float units +cbrt (Quantity value) = + Quantity (value ^ (1 /3)) + ---------- ROUNDING ---------- diff --git a/src/Volume.elm b/src/Volume.elm index d759689..1813067 100644 --- a/src/Volume.elm +++ b/src/Volume.elm @@ -34,7 +34,7 @@ US liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic -} import Length exposing (Meters) -import Quantity exposing (Quantity(..)) +import Quantity exposing (Quantity(..), Cubed) {-| -} From 41d3a1cc2765def9e549c7fc97e4b4cd39cd0687 Mon Sep 17 00:00:00 2001 From: katjam Date: Thu, 4 Oct 2018 17:20:46 +0100 Subject: [PATCH 03/15] Remove unneccessary cm and mm function. Correct cbtr. --- src/Quantity.elm | 5 ++++- src/Volume.elm | 51 ++++++++++++++++++------------------------------ 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/Quantity.elm b/src/Quantity.elm index 3a52d12..bdd3add 100644 --- a/src/Quantity.elm +++ b/src/Quantity.elm @@ -530,7 +530,10 @@ quantity in plain `units. -} cbrt : Quantity Float (Cubed units) -> Quantity Float units cbrt (Quantity value) = - Quantity (value ^ (1 /3)) + if value >=0 then + Quantity (value ^ (1 /3)) + else + Quantity -((-value) ^ (1 /3)) ---------- ROUNDING ---------- diff --git a/src/Volume.elm b/src/Volume.elm index 1813067..6a10023 100644 --- a/src/Volume.elm +++ b/src/Volume.elm @@ -1,9 +1,8 @@ module Volume exposing ( Volume, CubicMeters , cubicMeters, inCubicMeters - , cubicMillimeters, inCubicMillimeters, cubicCentimeters, inCubicCentimeters , cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards - --, milliliter, liter, deciliter + , milliliters, inMilliliters, liters, inLiters, deciliters, inDeciliters --, usLiquidGallons, usDryGallons, imperialGallons --, usLiquidQuarts, usDryQuarts, imperialQuarts --, usLiquidPints, usDryPints, imperialPints @@ -19,8 +18,7 @@ US liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic ## Metric @docs cubicMeters, inCubicMeters -@docs cubicMillimeters, inCubicMillimeters, cubicCentimeters, inCubicCentimeters -@docs --@docs milliliters, inMilliliters, liters, etc +@docs milliliters, inMilliliters, liters, inLiters, deciliters, inDeciliters ## Imperial @@ -61,20 +59,6 @@ inCubicMeters (Quantity numCubicMeters) = numCubicMeters -{-| Construct a volume from a number of cubic millimeters. --} -cubicMillimeters : Float -> Volume -cubicMillimeters numCubicMillimeters = - cubicMeters (1.0e-9 * numCubicMillimeters) - - -{-| Convert a volume to a number of cubic millimeters. --} -inCubicMillimeters : Volume -> Float -inCubicMillimeters volume = - 1.0e9 * inCubicMeters volume - - {-| Construct a volume from a number of cubic inches. -} cubicInches : Float -> Volume @@ -89,20 +73,6 @@ inCubicInches volume = inCubicMeters volume / (0.0254 * 0.0254 * 0.0254) -{-| Construct a volume from a number of cubic centimeters. --} -cubicCentimeters : Float -> Volume -cubicCentimeters numCubicCentimeters = - cubicMeters (1.0e-6 * numCubicCentimeters) - - -{-| Convert a volume to a number of cubic centimeters. --} -inCubicCentimeters : Volume -> Float -inCubicCentimeters volume = - 1.0e6 * inCubicMeters volume - - {-| Construct a volume from a number of cubic feet. -} cubicFeet : Float -> Volume @@ -129,3 +99,20 @@ cubicYards numCubicYards = inCubicYards : Volume -> Float inCubicYards volume = inCubicMeters volume / (0.9144 * 0.9144 * 0.9144) + + +{-| Construct a volume from a number of milliliters. +-} +milliliters : Float -> Volume +milliliters numMilititers = + cubicMeters (1.0e-6 * numMilliliters) + + +{-| Convert a volume to a number of milliliters. +-} +inMilliliters : Volume -> Float +inMilliliters volume = + 1.0e6 * inMilliliters volume + + + From eed25b319ba752f8fc53c3894f4deb0dc5ab30fb Mon Sep 17 00:00:00 2001 From: katjam Date: Fri, 5 Oct 2018 11:07:14 +0100 Subject: [PATCH 04/15] Tidier docs and remove deciliter stubs (no immediate need). --- elm.json | 3 ++- src/Volume.elm | 26 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/elm.json b/elm.json index 4cf8948..a4fe4c7 100644 --- a/elm.json +++ b/elm.json @@ -22,7 +22,8 @@ "Resistance", "Speed", "Temperature", - "Voltage" + "Voltage", + "Volume" ], "elm-version": "0.19.0 <= v < 0.20.0", "dependencies": { diff --git a/src/Volume.elm b/src/Volume.elm index 6a10023..1391861 100644 --- a/src/Volume.elm +++ b/src/Volume.elm @@ -2,7 +2,7 @@ module Volume exposing ( Volume, CubicMeters , cubicMeters, inCubicMeters , cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards - , milliliters, inMilliliters, liters, inLiters, deciliters, inDeciliters + , milliliters, inMilliliters, liters, inLiters --, usLiquidGallons, usDryGallons, imperialGallons --, usLiquidQuarts, usDryQuarts, imperialQuarts --, usLiquidPints, usDryPints, imperialPints @@ -18,16 +18,16 @@ US liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic ## Metric @docs cubicMeters, inCubicMeters -@docs milliliters, inMilliliters, liters, inLiters, deciliters, inDeciliters +@docs milliliters, inMilliliters, liters, inLiters ## Imperial @docs cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards -@docs --@docs usLiquidGallons, usDryGallons, imperialGallons -@docs --@docs usLiquidQuarts, usDryQuarts, imperialQuarts -@docs --@docs usLiquidPints, usDryPints, imperialPints -@docs --@docs usFluidOunces, imperialFluidOunces +--@docs usLiquidGallons, usDryGallons, imperialGallons +--@docs usLiquidQuarts, usDryQuarts, imperialQuarts +--@docs usLiquidPints, usDryPints, imperialPints +--@docs usFluidOunces, imperialFluidOunces -} @@ -104,7 +104,7 @@ inCubicYards volume = {-| Construct a volume from a number of milliliters. -} milliliters : Float -> Volume -milliliters numMilititers = +milliliters numMilliliters = cubicMeters (1.0e-6 * numMilliliters) @@ -115,4 +115,16 @@ inMilliliters volume = 1.0e6 * inMilliliters volume +{-| Construct a volume from a number of liters. +-} +liters : Float -> Volume +liters numLiters = + cubicMeters (1.0e-6 * numLiters) + + +{-| Convert a volume to a number of liters. +-} +inLiters : Volume -> Float +inLiters volume = + 1.0e6 * inLiters volume From 8edc9f45cdffb140bf63936baf8f47192e5097f8 Mon Sep 17 00:00:00 2001 From: katjam Date: Fri, 5 Oct 2018 18:56:13 +0100 Subject: [PATCH 05/15] Gallon conversions and correct Liter/Milliliter --- src/Volume.elm | 51 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/src/Volume.elm b/src/Volume.elm index 1391861..217b576 100644 --- a/src/Volume.elm +++ b/src/Volume.elm @@ -3,7 +3,7 @@ module Volume exposing , cubicMeters, inCubicMeters , cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards , milliliters, inMilliliters, liters, inLiters - --, usLiquidGallons, usDryGallons, imperialGallons + , usLiquidGallons, inUsLiquidGallons, usDryGallons, inUsDryGallons, imperialGallons, inImperialGallons --, usLiquidQuarts, usDryQuarts, imperialQuarts --, usLiquidPints, usDryPints, imperialPints --, usFluidOunces, imperialFluidOunces @@ -24,7 +24,7 @@ US liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic ## Imperial @docs cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards ---@docs usLiquidGallons, usDryGallons, imperialGallons +@docs usLiquidGallons, inUsLiquidGallons, usDryGallons, inUsDryGallons, imperialGallons, inImperialGallons --@docs usLiquidQuarts, usDryQuarts, imperialQuarts --@docs usLiquidPints, usDryPints, imperialPints --@docs usFluidOunces, imperialFluidOunces @@ -112,19 +112,60 @@ milliliters numMilliliters = -} inMilliliters : Volume -> Float inMilliliters volume = - 1.0e6 * inMilliliters volume + 1.0e6 * inCubicMeters volume {-| Construct a volume from a number of liters. -} liters : Float -> Volume liters numLiters = - cubicMeters (1.0e-6 * numLiters) + cubicMeters (0.001 * numLiters) {-| Convert a volume to a number of liters. -} inLiters : Volume -> Float inLiters volume = - 1.0e6 * inLiters volume + 1000 * inCubicMeters volume + +{-| Construct a volume from a number of usLiquidGallons. +-} +usLiquidGallons : Float -> Volume +usLiquidGallons numUsLiquidGallons = + cubicMeters ( numUsLiquidGallons / 264.17220000000003 ) + + +{-| Convert a volume to a number of usLiquidGallons. +-} +inUsLiquidGallons : Volume -> Float +inUsLiquidGallons volume = + 264.17220000000003 * inCubicMeters volume + + +{-| Construct a volume from a number of usDryGallons. +-} +usDryGallons : Float -> Volume +usDryGallons numUsDryGallons = + cubicMeters (numUsDryGallons / 227.0208) + + +{-| Convert a volume to a number of usDryGallons. +-} +inUsDryGallons : Volume -> Float +inUsDryGallons volume = + 227.0208 * inCubicMeters volume + + +{-| Construct a volume from a number of imperialGallons. +-} +imperialGallons : Float -> Volume +imperialGallons numImperialGallons = + cubicMeters (numImperialGallons / 219.9688) + + +{-| Convert a volume to a number of imperialGallons. +-} +inImperialGallons : Volume -> Float +inImperialGallons volume = + 219.9688 * inCubicMeters volume From ccf08da8d8c3d3260f667f369f2ae6c4b6c512f3 Mon Sep 17 00:00:00 2001 From: katjam Date: Fri, 5 Oct 2018 19:43:06 +0100 Subject: [PATCH 06/15] Volume fuzz tests and responsibility --- AUTHORS | 1 + tests/Tests.elm | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/AUTHORS b/AUTHORS index a18cb0c..648a164 100644 --- a/AUTHORS +++ b/AUTHORS @@ -4,3 +4,4 @@ add your name to the end of this list! Ian Mackenzie Matthias Devlamynck +Katja Mordaunt diff --git a/tests/Tests.elm b/tests/Tests.elm index f323dbc..875b95a 100644 --- a/tests/Tests.elm +++ b/tests/Tests.elm @@ -30,6 +30,7 @@ import Speed exposing (..) import Temperature exposing (Temperature) import Test exposing (Test) import Voltage exposing (..) +import Volume exposing (..) equalityTest : String -> String -> ( Quantity Float units, Quantity Float units ) -> Test @@ -302,4 +303,15 @@ conversionsToQuantityAndBack = , Test.describe "Voltage" <| [ fuzzFloatToQuantityAndBack "volts" Voltage.volts Voltage.inVolts ] + , Test.describe "Volume" <| + [ fuzzFloatToQuantityAndBack "cubicMeters" Volume.cubicMeters Volume.inCubicMeters + , fuzzFloatToQuantityAndBack "cubicInches" Volume.cubicInches Volume.inCubicInches + , fuzzFloatToQuantityAndBack "cubicFeet" Volume.cubicFeet Volume.inCubicFeet + , fuzzFloatToQuantityAndBack "cubicYards" Volume.cubicYards Volume.inCubicYards + , fuzzFloatToQuantityAndBack "milliliters" Volume.milliliters Volume.inMilliliters + , fuzzFloatToQuantityAndBack "liters" Volume.liters Volume.inLiters + , fuzzFloatToQuantityAndBack "usLiquidGallons" Volume.usLiquidGallons Volume.inUsLiquidGallons + , fuzzFloatToQuantityAndBack "usDryGallons" Volume.usDryGallons Volume.inUsDryGallons + , fuzzFloatToQuantityAndBack "imperialGallons" Volume.imperialGallons Volume.inImperialGallons + ] ] From 89118f8dc0f1b3d92042d741f7a643c7ad939e9a Mon Sep 17 00:00:00 2001 From: katjam Date: Sat, 6 Oct 2018 11:53:16 +0100 Subject: [PATCH 07/15] Convert to Quarts --- src/Quantity.elm | 12 +++++---- src/Volume.elm | 66 +++++++++++++++++++++++++++++++++++++++--------- tests/Tests.elm | 24 ++++++++++++++++++ 3 files changed, 85 insertions(+), 17 deletions(-) diff --git a/src/Quantity.elm b/src/Quantity.elm index 97d4472..77b4fa8 100644 --- a/src/Quantity.elm +++ b/src/Quantity.elm @@ -516,7 +516,7 @@ sqrt (Quantity value) = {-| Cube a quantity with some `units`, resulting in a new quantity in -`Cubed units. +`Cubed units`. -} cubed : Quantity number units -> Quantity number (Cubed units) cubed (Quantity value) = @@ -524,14 +524,16 @@ cubed (Quantity value) = {-| Take a quantity in `Cubed units` and return the cube root of that -quantity in plain `units. +quantity in plain `units`. -} cbrt : Quantity Float (Cubed units) -> Quantity Float units cbrt (Quantity value) = - if value >=0 then - Quantity (value ^ (1 /3)) + if value >= 0 then + Quantity (value ^ (1 / 3)) + else - Quantity -((-value) ^ (1 /3)) + Quantity -(-value ^ (1 / 3)) + ---------- INT/FLOAT CONVERSIONS ---------- diff --git a/src/Volume.elm b/src/Volume.elm index 217b576..c351a03 100644 --- a/src/Volume.elm +++ b/src/Volume.elm @@ -1,10 +1,10 @@ module Volume exposing ( Volume, CubicMeters , cubicMeters, inCubicMeters - , cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards , milliliters, inMilliliters, liters, inLiters + , cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards , usLiquidGallons, inUsLiquidGallons, usDryGallons, inUsDryGallons, imperialGallons, inImperialGallons - --, usLiquidQuarts, usDryQuarts, imperialQuarts + , usLiquidQuarts, inUsLiquidQuarts, usDryQuarts, inUsDryQuarts, imperialQuarts, inImperialQuarts --, usLiquidPints, usDryPints, imperialPints --, usFluidOunces, imperialFluidOunces ) @@ -18,21 +18,21 @@ US liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic ## Metric @docs cubicMeters, inCubicMeters -@docs milliliters, inMilliliters, liters, inLiters +@docs milliliters, inMilliliters, liters, inLiters ## Imperial @docs cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards @docs usLiquidGallons, inUsLiquidGallons, usDryGallons, inUsDryGallons, imperialGallons, inImperialGallons ---@docs usLiquidQuarts, usDryQuarts, imperialQuarts ---@docs usLiquidPints, usDryPints, imperialPints ---@docs usFluidOunces, imperialFluidOunces +@docs usLiquidQuarts, inUsLiquidQuarts, usDryQuarts, inUsDryQuarts, imperialQuarts, inImperialQuarts +@docs --@docs usLiquidPints, usDryPints, imperialPints +@docs --@docs usFluidOunces, imperialFluidOunces -} import Length exposing (Meters) -import Quantity exposing (Quantity(..), Cubed) +import Quantity exposing (Cubed, Quantity(..)) {-| -} @@ -133,14 +133,14 @@ inLiters volume = -} usLiquidGallons : Float -> Volume usLiquidGallons numUsLiquidGallons = - cubicMeters ( numUsLiquidGallons / 264.17220000000003 ) + cubicMeters (numUsLiquidGallons / 264.17220000000003) {-| Convert a volume to a number of usLiquidGallons. -} inUsLiquidGallons : Volume -> Float inUsLiquidGallons volume = - 264.17220000000003 * inCubicMeters volume + 264.17220000000003 * inCubicMeters volume {-| Construct a volume from a number of usDryGallons. @@ -154,18 +154,60 @@ usDryGallons numUsDryGallons = -} inUsDryGallons : Volume -> Float inUsDryGallons volume = - 227.0208 * inCubicMeters volume + 227.0208 * inCubicMeters volume {-| Construct a volume from a number of imperialGallons. -} imperialGallons : Float -> Volume imperialGallons numImperialGallons = - cubicMeters (numImperialGallons / 219.9688) + cubicMeters (numImperialGallons / 219.969157) {-| Convert a volume to a number of imperialGallons. -} inImperialGallons : Volume -> Float inImperialGallons volume = - 219.9688 * inCubicMeters volume + 219.969157 * inCubicMeters volume + + +{-| Construct a volume from a number of usLiquidQuarts. +-} +usLiquidQuarts : Float -> Volume +usLiquidQuarts numUsLiquidQuarts = + cubicMeters ((numUsLiquidQuarts / 4) / 264.17220000000003) + + +{-| Convert a volume to a number of usLiquidQuarts. +-} +inUsLiquidQuarts : Volume -> Float +inUsLiquidQuarts volume = + 4 * 264.17220000000003 * inCubicMeters volume + + +{-| Construct a volume from a number of usDryQuarts. +-} +usDryQuarts : Float -> Volume +usDryQuarts numUsDryQuarts = + cubicMeters ((numUsDryQuarts / 4) / 227.0208) + + +{-| Convert a volume to a number of usDryQuarts. +-} +inUsDryQuarts : Volume -> Float +inUsDryQuarts volume = + 4 * 227.0208 * inCubicMeters volume + + +{-| Construct a volume from a number of imperialQuarts. +-} +imperialQuarts : Float -> Volume +imperialQuarts numImperialQuarts = + cubicMeters ((numImperialQuarts / 4) / 219.969157) + + +{-| Convert a volume to a number of imperialQuarts. +-} +inImperialQuarts : Volume -> Float +inImperialQuarts volume = + 4 * 219.969157 * inCubicMeters volume diff --git a/tests/Tests.elm b/tests/Tests.elm index 875b95a..9bc0c44 100644 --- a/tests/Tests.elm +++ b/tests/Tests.elm @@ -7,6 +7,7 @@ module Tests exposing , speeds , temperatureDeltas , temperatures + , volumes ) import Acceleration exposing (..) @@ -186,6 +187,26 @@ temperatureDeltas = ] +volumes : Test +volumes = + equalPairs + "Volumes" + "m^3" + [ ( cubicInches (36 * 36 * 36) + , cubicYards 1 + ) + , ( usLiquidGallons 1 + , usLiquidQuarts 4 + ) + , ( usDryGallons 1 + , usDryQuarts 4 + ) + , ( imperialGallons 1 + , imperialQuarts 4 + ) + ] + + conversionsToQuantityAndBack : Test conversionsToQuantityAndBack = Test.describe "Conversion to Quantity and back is (almost) identity" <| @@ -313,5 +334,8 @@ conversionsToQuantityAndBack = , fuzzFloatToQuantityAndBack "usLiquidGallons" Volume.usLiquidGallons Volume.inUsLiquidGallons , fuzzFloatToQuantityAndBack "usDryGallons" Volume.usDryGallons Volume.inUsDryGallons , fuzzFloatToQuantityAndBack "imperialGallons" Volume.imperialGallons Volume.inImperialGallons + , fuzzFloatToQuantityAndBack "usLiquidQuarts" Volume.usLiquidQuarts Volume.inUsLiquidQuarts + , fuzzFloatToQuantityAndBack "usDryQuarts" Volume.usDryQuarts Volume.inUsDryQuarts + , fuzzFloatToQuantityAndBack "imperialQuarts" Volume.imperialQuarts Volume.inImperialQuarts ] ] From 1c8b749b1799987cc63e60898b8ba0199f7fb7c4 Mon Sep 17 00:00:00 2001 From: katjam Date: Sat, 6 Oct 2018 11:58:32 +0100 Subject: [PATCH 08/15] Remove stray @doc added by elm-format --- src/Volume.elm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Volume.elm b/src/Volume.elm index c351a03..060a0dd 100644 --- a/src/Volume.elm +++ b/src/Volume.elm @@ -26,8 +26,8 @@ US liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic @docs cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards @docs usLiquidGallons, inUsLiquidGallons, usDryGallons, inUsDryGallons, imperialGallons, inImperialGallons @docs usLiquidQuarts, inUsLiquidQuarts, usDryQuarts, inUsDryQuarts, imperialQuarts, inImperialQuarts -@docs --@docs usLiquidPints, usDryPints, imperialPints -@docs --@docs usFluidOunces, imperialFluidOunces +--@docs usLiquidPints, usDryPints, imperialPints +--@docs usFluidOunces, imperialFluidOunces -} From 69c4b994c9047c444daf1900c687b98366fd1098 Mon Sep 17 00:00:00 2001 From: katjam Date: Sat, 6 Oct 2018 17:20:40 +0100 Subject: [PATCH 09/15] Add pints to Volume --- src/Volume.elm | 46 ++++++++++++++++++++++++++++++++++++++++++++-- tests/Tests.elm | 12 ++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/Volume.elm b/src/Volume.elm index 060a0dd..8f61cb7 100644 --- a/src/Volume.elm +++ b/src/Volume.elm @@ -5,7 +5,7 @@ module Volume exposing , cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards , usLiquidGallons, inUsLiquidGallons, usDryGallons, inUsDryGallons, imperialGallons, inImperialGallons , usLiquidQuarts, inUsLiquidQuarts, usDryQuarts, inUsDryQuarts, imperialQuarts, inImperialQuarts - --, usLiquidPints, usDryPints, imperialPints + , usLiquidPints, inUsLiquidPints, usDryPints, inUsDryPints, imperialPints, inImperialPints --, usFluidOunces, imperialFluidOunces ) @@ -26,7 +26,7 @@ US liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic @docs cubicInches, inCubicInches, cubicFeet, inCubicFeet, cubicYards, inCubicYards @docs usLiquidGallons, inUsLiquidGallons, usDryGallons, inUsDryGallons, imperialGallons, inImperialGallons @docs usLiquidQuarts, inUsLiquidQuarts, usDryQuarts, inUsDryQuarts, imperialQuarts, inImperialQuarts ---@docs usLiquidPints, usDryPints, imperialPints +@docs usLiquidPints, inUsLiquidPints, usDryPints, inUsDryPints, imperialPints, inImperialPints --@docs usFluidOunces, imperialFluidOunces -} @@ -211,3 +211,45 @@ imperialQuarts numImperialQuarts = inImperialQuarts : Volume -> Float inImperialQuarts volume = 4 * 219.969157 * inCubicMeters volume + + +{-| Construct a volume from a number of usLiquidPints. +-} +usLiquidPints : Float -> Volume +usLiquidPints numUsLiquidPints = + cubicMeters ((numUsLiquidPints / 8) / 264.17220000000003) + + +{-| Convert a volume to a number of usLiquidPints. +-} +inUsLiquidPints : Volume -> Float +inUsLiquidPints volume = + 8 * 264.17220000000003 * inCubicMeters volume + + +{-| Construct a volume from a number of usDryPints. +-} +usDryPints : Float -> Volume +usDryPints numUsDryPints = + cubicMeters ((numUsDryPints / 8) / 227.0208) + + +{-| Convert a volume to a number of usDryPints. +-} +inUsDryPints : Volume -> Float +inUsDryPints volume = + 8 * 227.0208 * inCubicMeters volume + + +{-| Construct a volume from a number of imperialPints. +-} +imperialPints : Float -> Volume +imperialPints numImperialPints = + cubicMeters ((numImperialPints / 8) / 219.969157) + + +{-| Convert a volume to a number of imperialPints. +-} +inImperialPints : Volume -> Float +inImperialPints volume = + 8 * 219.969157 * inCubicMeters volume diff --git a/tests/Tests.elm b/tests/Tests.elm index 9bc0c44..505a8a5 100644 --- a/tests/Tests.elm +++ b/tests/Tests.elm @@ -204,6 +204,15 @@ volumes = , ( imperialGallons 1 , imperialQuarts 4 ) + , ( usLiquidQuarts 1 + , usLiquidPints 2 + ) + , ( usDryQuarts 1 + , usDryPints 2 + ) + , ( imperialQuarts 1 + , imperialPints 2 + ) ] @@ -337,5 +346,8 @@ conversionsToQuantityAndBack = , fuzzFloatToQuantityAndBack "usLiquidQuarts" Volume.usLiquidQuarts Volume.inUsLiquidQuarts , fuzzFloatToQuantityAndBack "usDryQuarts" Volume.usDryQuarts Volume.inUsDryQuarts , fuzzFloatToQuantityAndBack "imperialQuarts" Volume.imperialQuarts Volume.inImperialQuarts + , fuzzFloatToQuantityAndBack "usLiquidPints" Volume.usLiquidPints Volume.inUsLiquidPints + , fuzzFloatToQuantityAndBack "usDryPints" Volume.usDryPints Volume.inUsDryPints + , fuzzFloatToQuantityAndBack "imperialPints" Volume.imperialPints Volume.inImperialPints ] ] From a041b4e9e7c7710ae9cdb39b7a3114fd36b9db4b Mon Sep 17 00:00:00 2001 From: katjam Date: Sat, 6 Oct 2018 17:45:28 +0100 Subject: [PATCH 10/15] Add fluid ounces to Volume --- src/Volume.elm | 32 ++++++++++++++++++++++++++++++-- tests/Tests.elm | 8 ++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Volume.elm b/src/Volume.elm index 8f61cb7..c98cdc5 100644 --- a/src/Volume.elm +++ b/src/Volume.elm @@ -6,7 +6,7 @@ module Volume exposing , usLiquidGallons, inUsLiquidGallons, usDryGallons, inUsDryGallons, imperialGallons, inImperialGallons , usLiquidQuarts, inUsLiquidQuarts, usDryQuarts, inUsDryQuarts, imperialQuarts, inImperialQuarts , usLiquidPints, inUsLiquidPints, usDryPints, inUsDryPints, imperialPints, inImperialPints - --, usFluidOunces, imperialFluidOunces + , usFluidOunces, inUsFluidOunces, imperialFluidOunces, inImperialFluidOunces ) {-| A `Volume` represents a volume in cubic meters, cubic feet, liters, @@ -27,7 +27,7 @@ US liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic @docs usLiquidGallons, inUsLiquidGallons, usDryGallons, inUsDryGallons, imperialGallons, inImperialGallons @docs usLiquidQuarts, inUsLiquidQuarts, usDryQuarts, inUsDryQuarts, imperialQuarts, inImperialQuarts @docs usLiquidPints, inUsLiquidPints, usDryPints, inUsDryPints, imperialPints, inImperialPints ---@docs usFluidOunces, imperialFluidOunces +@docs usFluidOunces, inUsFluidOunces, imperialFluidOunces, inImperialFluidOunces -} @@ -253,3 +253,31 @@ imperialPints numImperialPints = inImperialPints : Volume -> Float inImperialPints volume = 8 * 219.969157 * inCubicMeters volume + + +{-| Construct a volume from a number of usFluidOunces. +-} +usFluidOunces : Float -> Volume +usFluidOunces numUsFluidOunces = + cubicMeters ((numUsFluidOunces / 128) / 264.17220000000003) + + +{-| Convert a volume to a number of usFluidOunces. +-} +inUsFluidOunces : Volume -> Float +inUsFluidOunces volume = + 128 * 264.17220000000003 * inCubicMeters volume + + +{-| Construct a volume from a number of imperialFluidOunces. +-} +imperialFluidOunces : Float -> Volume +imperialFluidOunces numImperialFluidOunces = + cubicMeters ((numImperialFluidOunces / 160) / 219.969157) + + +{-| Convert a volume to a number of imperialFluidOunces. +-} +inImperialFluidOunces : Volume -> Float +inImperialFluidOunces volume = + 160 * 219.969157 * inCubicMeters volume diff --git a/tests/Tests.elm b/tests/Tests.elm index 505a8a5..fb63b32 100644 --- a/tests/Tests.elm +++ b/tests/Tests.elm @@ -213,6 +213,12 @@ volumes = , ( imperialQuarts 1 , imperialPints 2 ) + , ( usLiquidPints 1 + , usFluidOunces 16 + ) + , ( imperialPints 1 + , imperialFluidOunces 20 + ) ] @@ -349,5 +355,7 @@ conversionsToQuantityAndBack = , fuzzFloatToQuantityAndBack "usLiquidPints" Volume.usLiquidPints Volume.inUsLiquidPints , fuzzFloatToQuantityAndBack "usDryPints" Volume.usDryPints Volume.inUsDryPints , fuzzFloatToQuantityAndBack "imperialPints" Volume.imperialPints Volume.inImperialPints + , fuzzFloatToQuantityAndBack "usFluidOunces" Volume.usFluidOunces Volume.inUsFluidOunces + , fuzzFloatToQuantityAndBack "imperialFluidOunces" Volume.imperialFluidOunces Volume.inImperialFluidOunces ] ] From 348f81367653b325792817a59789b2c3d843bf63 Mon Sep 17 00:00:00 2001 From: katjam Date: Sun, 7 Oct 2018 12:39:10 +0100 Subject: [PATCH 11/15] Include conversion factors as helper constants --- src/Volume.elm | 73 ++++++++++++++++++++++++++++++++++--------------- tests/Tests.elm | 8 +++++- 2 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/Volume.elm b/src/Volume.elm index c98cdc5..e0bc6fe 100644 --- a/src/Volume.elm +++ b/src/Volume.elm @@ -45,6 +45,35 @@ type alias Volume = Quantity Float CubicMeters + +---------- CONVERSION FACTOR CONSTANTS ----------- + + +{-| The number of US liquid gallons in a cubic meter. +-} +numUsLiquidGallonsInACubicMeter : Float +numUsLiquidGallonsInACubicMeter = + 264.17220000000003 + + +{-| The number of US dry gallons in a cubic meter. +-} +numUsDryGallonsInACubicMeter : Float +numUsDryGallonsInACubicMeter = + 227.0208 + + +{-| The number of imperial gallons in a cubic meter. +-} +numImperialGallonsInACubicMeter : Float +numImperialGallonsInACubicMeter = + 219.969157 + + + +---------- CONVERSIONS ----------- + + {-| Construct a volume from a number of cubic meters. -} cubicMeters : Float -> Volume @@ -133,151 +162,151 @@ inLiters volume = -} usLiquidGallons : Float -> Volume usLiquidGallons numUsLiquidGallons = - cubicMeters (numUsLiquidGallons / 264.17220000000003) + cubicMeters (numUsLiquidGallons / numUsLiquidGallonsInACubicMeter) {-| Convert a volume to a number of usLiquidGallons. -} inUsLiquidGallons : Volume -> Float inUsLiquidGallons volume = - 264.17220000000003 * inCubicMeters volume + numUsLiquidGallonsInACubicMeter * inCubicMeters volume {-| Construct a volume from a number of usDryGallons. -} usDryGallons : Float -> Volume usDryGallons numUsDryGallons = - cubicMeters (numUsDryGallons / 227.0208) + cubicMeters (numUsDryGallons / numUsDryGallonsInACubicMeter) {-| Convert a volume to a number of usDryGallons. -} inUsDryGallons : Volume -> Float inUsDryGallons volume = - 227.0208 * inCubicMeters volume + numUsDryGallonsInACubicMeter * inCubicMeters volume {-| Construct a volume from a number of imperialGallons. -} imperialGallons : Float -> Volume imperialGallons numImperialGallons = - cubicMeters (numImperialGallons / 219.969157) + cubicMeters (numImperialGallons / numImperialGallonsInACubicMeter) {-| Convert a volume to a number of imperialGallons. -} inImperialGallons : Volume -> Float inImperialGallons volume = - 219.969157 * inCubicMeters volume + numImperialGallonsInACubicMeter * inCubicMeters volume {-| Construct a volume from a number of usLiquidQuarts. -} usLiquidQuarts : Float -> Volume usLiquidQuarts numUsLiquidQuarts = - cubicMeters ((numUsLiquidQuarts / 4) / 264.17220000000003) + cubicMeters ((numUsLiquidQuarts / 4) / numUsLiquidGallonsInACubicMeter) {-| Convert a volume to a number of usLiquidQuarts. -} inUsLiquidQuarts : Volume -> Float inUsLiquidQuarts volume = - 4 * 264.17220000000003 * inCubicMeters volume + 4 * numUsLiquidGallonsInACubicMeter * inCubicMeters volume {-| Construct a volume from a number of usDryQuarts. -} usDryQuarts : Float -> Volume usDryQuarts numUsDryQuarts = - cubicMeters ((numUsDryQuarts / 4) / 227.0208) + cubicMeters ((numUsDryQuarts / 4) / numUsDryGallonsInACubicMeter) {-| Convert a volume to a number of usDryQuarts. -} inUsDryQuarts : Volume -> Float inUsDryQuarts volume = - 4 * 227.0208 * inCubicMeters volume + 4 * numUsDryGallonsInACubicMeter * inCubicMeters volume {-| Construct a volume from a number of imperialQuarts. -} imperialQuarts : Float -> Volume imperialQuarts numImperialQuarts = - cubicMeters ((numImperialQuarts / 4) / 219.969157) + cubicMeters ((numImperialQuarts / 4) / numImperialGallonsInACubicMeter) {-| Convert a volume to a number of imperialQuarts. -} inImperialQuarts : Volume -> Float inImperialQuarts volume = - 4 * 219.969157 * inCubicMeters volume + 4 * numImperialGallonsInACubicMeter * inCubicMeters volume {-| Construct a volume from a number of usLiquidPints. -} usLiquidPints : Float -> Volume usLiquidPints numUsLiquidPints = - cubicMeters ((numUsLiquidPints / 8) / 264.17220000000003) + cubicMeters ((numUsLiquidPints / 8) / numUsLiquidGallonsInACubicMeter) {-| Convert a volume to a number of usLiquidPints. -} inUsLiquidPints : Volume -> Float inUsLiquidPints volume = - 8 * 264.17220000000003 * inCubicMeters volume + 8 * numUsLiquidGallonsInACubicMeter * inCubicMeters volume {-| Construct a volume from a number of usDryPints. -} usDryPints : Float -> Volume usDryPints numUsDryPints = - cubicMeters ((numUsDryPints / 8) / 227.0208) + cubicMeters ((numUsDryPints / 8) / numUsDryGallonsInACubicMeter) {-| Convert a volume to a number of usDryPints. -} inUsDryPints : Volume -> Float inUsDryPints volume = - 8 * 227.0208 * inCubicMeters volume + 8 * numUsDryGallonsInACubicMeter * inCubicMeters volume {-| Construct a volume from a number of imperialPints. -} imperialPints : Float -> Volume imperialPints numImperialPints = - cubicMeters ((numImperialPints / 8) / 219.969157) + cubicMeters ((numImperialPints / 8) / numImperialGallonsInACubicMeter) {-| Convert a volume to a number of imperialPints. -} inImperialPints : Volume -> Float inImperialPints volume = - 8 * 219.969157 * inCubicMeters volume + 8 * numImperialGallonsInACubicMeter * inCubicMeters volume {-| Construct a volume from a number of usFluidOunces. -} usFluidOunces : Float -> Volume usFluidOunces numUsFluidOunces = - cubicMeters ((numUsFluidOunces / 128) / 264.17220000000003) + cubicMeters ((numUsFluidOunces / 128) / numUsLiquidGallonsInACubicMeter) {-| Convert a volume to a number of usFluidOunces. -} inUsFluidOunces : Volume -> Float inUsFluidOunces volume = - 128 * 264.17220000000003 * inCubicMeters volume + 128 * numUsLiquidGallonsInACubicMeter * inCubicMeters volume {-| Construct a volume from a number of imperialFluidOunces. -} imperialFluidOunces : Float -> Volume imperialFluidOunces numImperialFluidOunces = - cubicMeters ((numImperialFluidOunces / 160) / 219.969157) + cubicMeters ((numImperialFluidOunces / 160) / numImperialGallonsInACubicMeter) {-| Convert a volume to a number of imperialFluidOunces. -} inImperialFluidOunces : Volume -> Float inImperialFluidOunces volume = - 160 * 219.969157 * inCubicMeters volume + 160 * numImperialGallonsInACubicMeter * inCubicMeters volume diff --git a/tests/Tests.elm b/tests/Tests.elm index fb63b32..24839a0 100644 --- a/tests/Tests.elm +++ b/tests/Tests.elm @@ -192,7 +192,13 @@ volumes = equalPairs "Volumes" "m^3" - [ ( cubicInches (36 * 36 * 36) + [ ( cubicMeters 2 + , usLiquidGallons (2 * 264.17220000000003) + ) + , ( imperialGallons 219.969157 + , usDryGallons 227.0208 + ) + , ( cubicInches (36 * 36 * 36) , cubicYards 1 ) , ( usLiquidGallons 1 From a85a6aab8ee0bf7a538d0433ae62f23490669310 Mon Sep 17 00:00:00 2001 From: Ian Mackenzie Date: Sun, 7 Oct 2018 11:37:05 -0400 Subject: [PATCH 12/15] Tweak doc formatting --- src/Volume.elm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Volume.elm b/src/Volume.elm index e0bc6fe..e3da38e 100644 --- a/src/Volume.elm +++ b/src/Volume.elm @@ -9,8 +9,9 @@ module Volume exposing , usFluidOunces, inUsFluidOunces, imperialFluidOunces, inImperialFluidOunces ) -{-| A `Volume` represents a volume in cubic meters, cubic feet, liters, -US liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic meters. +{-| A `Volume` represents a volume in cubic meters, cubic feet, liters, US +liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic +meters. @docs Volume, CubicMeters From 8a2637030ab04881d5ab86eb31d016fa5a092b00 Mon Sep 17 00:00:00 2001 From: Ian Mackenzie Date: Sun, 7 Oct 2018 11:44:06 -0400 Subject: [PATCH 13/15] Rename volume conversion constants --- src/Volume.elm | 56 +++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Volume.elm b/src/Volume.elm index e3da38e..457527b 100644 --- a/src/Volume.elm +++ b/src/Volume.elm @@ -52,22 +52,22 @@ type alias Volume = {-| The number of US liquid gallons in a cubic meter. -} -numUsLiquidGallonsInACubicMeter : Float -numUsLiquidGallonsInACubicMeter = +usLiquidGallonsPerCubicMeter : Float +usLiquidGallonsPerCubicMeter = 264.17220000000003 {-| The number of US dry gallons in a cubic meter. -} -numUsDryGallonsInACubicMeter : Float -numUsDryGallonsInACubicMeter = +usDryGallonsPerCubicMeter : Float +usDryGallonsPerCubicMeter = 227.0208 {-| The number of imperial gallons in a cubic meter. -} -numImperialGallonsInACubicMeter : Float -numImperialGallonsInACubicMeter = +imperialGallonsPerCubicMeter : Float +imperialGallonsPerCubicMeter = 219.969157 @@ -163,151 +163,151 @@ inLiters volume = -} usLiquidGallons : Float -> Volume usLiquidGallons numUsLiquidGallons = - cubicMeters (numUsLiquidGallons / numUsLiquidGallonsInACubicMeter) + cubicMeters (numUsLiquidGallons / usLiquidGallonsPerCubicMeter) {-| Convert a volume to a number of usLiquidGallons. -} inUsLiquidGallons : Volume -> Float inUsLiquidGallons volume = - numUsLiquidGallonsInACubicMeter * inCubicMeters volume + usLiquidGallonsPerCubicMeter * inCubicMeters volume {-| Construct a volume from a number of usDryGallons. -} usDryGallons : Float -> Volume usDryGallons numUsDryGallons = - cubicMeters (numUsDryGallons / numUsDryGallonsInACubicMeter) + cubicMeters (numUsDryGallons / usDryGallonsPerCubicMeter) {-| Convert a volume to a number of usDryGallons. -} inUsDryGallons : Volume -> Float inUsDryGallons volume = - numUsDryGallonsInACubicMeter * inCubicMeters volume + usDryGallonsPerCubicMeter * inCubicMeters volume {-| Construct a volume from a number of imperialGallons. -} imperialGallons : Float -> Volume imperialGallons numImperialGallons = - cubicMeters (numImperialGallons / numImperialGallonsInACubicMeter) + cubicMeters (numImperialGallons / imperialGallonsPerCubicMeter) {-| Convert a volume to a number of imperialGallons. -} inImperialGallons : Volume -> Float inImperialGallons volume = - numImperialGallonsInACubicMeter * inCubicMeters volume + imperialGallonsPerCubicMeter * inCubicMeters volume {-| Construct a volume from a number of usLiquidQuarts. -} usLiquidQuarts : Float -> Volume usLiquidQuarts numUsLiquidQuarts = - cubicMeters ((numUsLiquidQuarts / 4) / numUsLiquidGallonsInACubicMeter) + cubicMeters ((numUsLiquidQuarts / 4) / usLiquidGallonsPerCubicMeter) {-| Convert a volume to a number of usLiquidQuarts. -} inUsLiquidQuarts : Volume -> Float inUsLiquidQuarts volume = - 4 * numUsLiquidGallonsInACubicMeter * inCubicMeters volume + 4 * usLiquidGallonsPerCubicMeter * inCubicMeters volume {-| Construct a volume from a number of usDryQuarts. -} usDryQuarts : Float -> Volume usDryQuarts numUsDryQuarts = - cubicMeters ((numUsDryQuarts / 4) / numUsDryGallonsInACubicMeter) + cubicMeters ((numUsDryQuarts / 4) / usDryGallonsPerCubicMeter) {-| Convert a volume to a number of usDryQuarts. -} inUsDryQuarts : Volume -> Float inUsDryQuarts volume = - 4 * numUsDryGallonsInACubicMeter * inCubicMeters volume + 4 * usDryGallonsPerCubicMeter * inCubicMeters volume {-| Construct a volume from a number of imperialQuarts. -} imperialQuarts : Float -> Volume imperialQuarts numImperialQuarts = - cubicMeters ((numImperialQuarts / 4) / numImperialGallonsInACubicMeter) + cubicMeters ((numImperialQuarts / 4) / imperialGallonsPerCubicMeter) {-| Convert a volume to a number of imperialQuarts. -} inImperialQuarts : Volume -> Float inImperialQuarts volume = - 4 * numImperialGallonsInACubicMeter * inCubicMeters volume + 4 * imperialGallonsPerCubicMeter * inCubicMeters volume {-| Construct a volume from a number of usLiquidPints. -} usLiquidPints : Float -> Volume usLiquidPints numUsLiquidPints = - cubicMeters ((numUsLiquidPints / 8) / numUsLiquidGallonsInACubicMeter) + cubicMeters ((numUsLiquidPints / 8) / usLiquidGallonsPerCubicMeter) {-| Convert a volume to a number of usLiquidPints. -} inUsLiquidPints : Volume -> Float inUsLiquidPints volume = - 8 * numUsLiquidGallonsInACubicMeter * inCubicMeters volume + 8 * usLiquidGallonsPerCubicMeter * inCubicMeters volume {-| Construct a volume from a number of usDryPints. -} usDryPints : Float -> Volume usDryPints numUsDryPints = - cubicMeters ((numUsDryPints / 8) / numUsDryGallonsInACubicMeter) + cubicMeters ((numUsDryPints / 8) / usDryGallonsPerCubicMeter) {-| Convert a volume to a number of usDryPints. -} inUsDryPints : Volume -> Float inUsDryPints volume = - 8 * numUsDryGallonsInACubicMeter * inCubicMeters volume + 8 * usDryGallonsPerCubicMeter * inCubicMeters volume {-| Construct a volume from a number of imperialPints. -} imperialPints : Float -> Volume imperialPints numImperialPints = - cubicMeters ((numImperialPints / 8) / numImperialGallonsInACubicMeter) + cubicMeters ((numImperialPints / 8) / imperialGallonsPerCubicMeter) {-| Convert a volume to a number of imperialPints. -} inImperialPints : Volume -> Float inImperialPints volume = - 8 * numImperialGallonsInACubicMeter * inCubicMeters volume + 8 * imperialGallonsPerCubicMeter * inCubicMeters volume {-| Construct a volume from a number of usFluidOunces. -} usFluidOunces : Float -> Volume usFluidOunces numUsFluidOunces = - cubicMeters ((numUsFluidOunces / 128) / numUsLiquidGallonsInACubicMeter) + cubicMeters ((numUsFluidOunces / 128) / usLiquidGallonsPerCubicMeter) {-| Convert a volume to a number of usFluidOunces. -} inUsFluidOunces : Volume -> Float inUsFluidOunces volume = - 128 * numUsLiquidGallonsInACubicMeter * inCubicMeters volume + 128 * usLiquidGallonsPerCubicMeter * inCubicMeters volume {-| Construct a volume from a number of imperialFluidOunces. -} imperialFluidOunces : Float -> Volume imperialFluidOunces numImperialFluidOunces = - cubicMeters ((numImperialFluidOunces / 160) / numImperialGallonsInACubicMeter) + cubicMeters ((numImperialFluidOunces / 160) / imperialGallonsPerCubicMeter) {-| Convert a volume to a number of imperialFluidOunces. -} inImperialFluidOunces : Volume -> Float inImperialFluidOunces volume = - 160 * numImperialGallonsInACubicMeter * inCubicMeters volume + 160 * imperialGallonsPerCubicMeter * inCubicMeters volume From d560643fbd4176b4022c2ea3792d22827d776155 Mon Sep 17 00:00:00 2001 From: Ian Mackenzie Date: Sun, 7 Oct 2018 11:52:36 -0400 Subject: [PATCH 14/15] Reword Volume doc comments --- src/Volume.elm | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Volume.elm b/src/Volume.elm index 457527b..ef41388 100644 --- a/src/Volume.elm +++ b/src/Volume.elm @@ -159,154 +159,154 @@ inLiters volume = 1000 * inCubicMeters volume -{-| Construct a volume from a number of usLiquidGallons. +{-| Construct a volume from a number of U.S. liquid gallon. -} usLiquidGallons : Float -> Volume usLiquidGallons numUsLiquidGallons = cubicMeters (numUsLiquidGallons / usLiquidGallonsPerCubicMeter) -{-| Convert a volume to a number of usLiquidGallons. +{-| Convert a volume to a number of U.S. liquid gallons. -} inUsLiquidGallons : Volume -> Float inUsLiquidGallons volume = usLiquidGallonsPerCubicMeter * inCubicMeters volume -{-| Construct a volume from a number of usDryGallons. +{-| Construct a volume from a number of U.S. dry gallons. -} usDryGallons : Float -> Volume usDryGallons numUsDryGallons = cubicMeters (numUsDryGallons / usDryGallonsPerCubicMeter) -{-| Convert a volume to a number of usDryGallons. +{-| Convert a volume to a number of U.S. dry gallons. -} inUsDryGallons : Volume -> Float inUsDryGallons volume = usDryGallonsPerCubicMeter * inCubicMeters volume -{-| Construct a volume from a number of imperialGallons. +{-| Construct a volume from a number of imperial gallons. -} imperialGallons : Float -> Volume imperialGallons numImperialGallons = cubicMeters (numImperialGallons / imperialGallonsPerCubicMeter) -{-| Convert a volume to a number of imperialGallons. +{-| Convert a volume to a number of imperial gallons. -} inImperialGallons : Volume -> Float inImperialGallons volume = imperialGallonsPerCubicMeter * inCubicMeters volume -{-| Construct a volume from a number of usLiquidQuarts. +{-| Construct a volume from a number of U.S. liquid quarts. -} usLiquidQuarts : Float -> Volume usLiquidQuarts numUsLiquidQuarts = cubicMeters ((numUsLiquidQuarts / 4) / usLiquidGallonsPerCubicMeter) -{-| Convert a volume to a number of usLiquidQuarts. +{-| Convert a volume to a number of U.S. liquid quarts. -} inUsLiquidQuarts : Volume -> Float inUsLiquidQuarts volume = 4 * usLiquidGallonsPerCubicMeter * inCubicMeters volume -{-| Construct a volume from a number of usDryQuarts. +{-| Construct a volume from a number of U.S. dry quarts. -} usDryQuarts : Float -> Volume usDryQuarts numUsDryQuarts = cubicMeters ((numUsDryQuarts / 4) / usDryGallonsPerCubicMeter) -{-| Convert a volume to a number of usDryQuarts. +{-| Convert a volume to a number of U.S. dry quarts. -} inUsDryQuarts : Volume -> Float inUsDryQuarts volume = 4 * usDryGallonsPerCubicMeter * inCubicMeters volume -{-| Construct a volume from a number of imperialQuarts. +{-| Construct a volume from a number of imperial quarts. -} imperialQuarts : Float -> Volume imperialQuarts numImperialQuarts = cubicMeters ((numImperialQuarts / 4) / imperialGallonsPerCubicMeter) -{-| Convert a volume to a number of imperialQuarts. +{-| Convert a volume to a number of imperial quarts. -} inImperialQuarts : Volume -> Float inImperialQuarts volume = 4 * imperialGallonsPerCubicMeter * inCubicMeters volume -{-| Construct a volume from a number of usLiquidPints. +{-| Construct a volume from a number of U.S. liquid pints. -} usLiquidPints : Float -> Volume usLiquidPints numUsLiquidPints = cubicMeters ((numUsLiquidPints / 8) / usLiquidGallonsPerCubicMeter) -{-| Convert a volume to a number of usLiquidPints. +{-| Convert a volume to a number of U.S. liquid pints. -} inUsLiquidPints : Volume -> Float inUsLiquidPints volume = 8 * usLiquidGallonsPerCubicMeter * inCubicMeters volume -{-| Construct a volume from a number of usDryPints. +{-| Construct a volume from a number of U.S. dry pints. -} usDryPints : Float -> Volume usDryPints numUsDryPints = cubicMeters ((numUsDryPints / 8) / usDryGallonsPerCubicMeter) -{-| Convert a volume to a number of usDryPints. +{-| Convert a volume to a number of U.S. dry pints. -} inUsDryPints : Volume -> Float inUsDryPints volume = 8 * usDryGallonsPerCubicMeter * inCubicMeters volume -{-| Construct a volume from a number of imperialPints. +{-| Construct a volume from a number of imperial pints. -} imperialPints : Float -> Volume imperialPints numImperialPints = cubicMeters ((numImperialPints / 8) / imperialGallonsPerCubicMeter) -{-| Convert a volume to a number of imperialPints. +{-| Convert a volume to a number of imperial pints. -} inImperialPints : Volume -> Float inImperialPints volume = 8 * imperialGallonsPerCubicMeter * inCubicMeters volume -{-| Construct a volume from a number of usFluidOunces. +{-| Construct a volume from a number of U.S. fluid ounces. -} usFluidOunces : Float -> Volume usFluidOunces numUsFluidOunces = cubicMeters ((numUsFluidOunces / 128) / usLiquidGallonsPerCubicMeter) -{-| Convert a volume to a number of usFluidOunces. +{-| Convert a volume to a number of U.S. fluid ounces. -} inUsFluidOunces : Volume -> Float inUsFluidOunces volume = 128 * usLiquidGallonsPerCubicMeter * inCubicMeters volume -{-| Construct a volume from a number of imperialFluidOunces. +{-| Construct a volume from a number of imperial fluid ounces. -} imperialFluidOunces : Float -> Volume imperialFluidOunces numImperialFluidOunces = cubicMeters ((numImperialFluidOunces / 160) / imperialGallonsPerCubicMeter) -{-| Convert a volume to a number of imperialFluidOunces. +{-| Convert a volume to a number of imperial fluid ounces. -} inImperialFluidOunces : Volume -> Float inImperialFluidOunces volume = From 59b5d5c905d682315b696a596163d2283887c398 Mon Sep 17 00:00:00 2001 From: Ian Mackenzie Date: Sun, 7 Oct 2018 11:58:47 -0400 Subject: [PATCH 15/15] Tweak documentation wording --- src/Quantity.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quantity.elm b/src/Quantity.elm index 77b4fa8..eb3cac4 100644 --- a/src/Quantity.elm +++ b/src/Quantity.elm @@ -114,7 +114,7 @@ type Squared units {-| Represents a units type that is the cube of some other units type; for example, `Meters` is one units type (the units type of a `Length`) and `Cubed Meters` is another (the units type of an `Volume`). This is useful because some -functions in this module (specifically [`cubed`](Quantity#cubed), +functions in this module (specifically [`cubed`](Quantity#cubed) and [`cbrt`](Quantity#cbrt)) "know" about the `Cubed` type and how to work with it. -}