diff --git a/shared/src/main/scala/squants/space/Length.scala b/shared/src/main/scala/squants/space/Length.scala index c93d4306..1562dace 100644 --- a/shared/src/main/scala/squants/space/Length.scala +++ b/shared/src/main/scala/squants/space/Length.scala @@ -72,6 +72,8 @@ final class Length private (val value: Double, val unit: LengthUnit) def toDecameters = to(Decameters) def toHectometers = to(Hectometers) def toKilometers = to(Kilometers) + def toKiloyards = to(Kiloyards) + def toKilofeet = to(Kilofeet) def toInches = to(Inches) def toFeet = to(Feet) def toYards = to(Yards) @@ -107,7 +109,7 @@ object Length extends Dimension[Length] with BaseDimension { def primaryUnit = Meters def siUnit = Meters def units = Set(Angstroms, Nanometers, Microns, Millimeters, Centimeters, - Decimeters, Meters, Decameters, Hectometers, Kilometers, + Decimeters, Meters, Decameters, Hectometers, Kilometers, Kiloyards, Kilofeet, Inches, Feet, Yards, UsMiles, InternationalMiles, NauticalMiles, AstronomicalUnits, LightYears, Parsecs, KiloParsecs, MegaParsecs, GigaParsecs, SolarRadii, NominalSolarRadii, ElectronVoltLength, MilliElectronVoltLength, KiloElectronVoltLength, MegaElectronVoltLength, @@ -173,6 +175,16 @@ object Kilometers extends LengthUnit with SiUnit { val conversionFactor = MetricSystem.Kilo } +object Kiloyards extends LengthUnit with SiUnit { + val symbol = "kyd" + val conversionFactor = Yards.conversionFactor * MetricSystem.Kilo +} + +object Kilofeet extends LengthUnit with SiUnit { + val symbol = "kft" + val conversionFactor = Kiloyards.conversionFactor / 3 +} + object Inches extends LengthUnit { val conversionFactor = Feet.conversionFactor / 12d val symbol = "in" @@ -304,6 +316,8 @@ object LengthConversions { lazy val hectometre = Hectometers(1) lazy val kilometer = Kilometers(1) lazy val kilometre = Kilometers(1) + lazy val kiloyard = Kiloyards(1) + lazy val kilofoot = Kilofeet(1) lazy val inch = Inches(1) lazy val foot = Feet(1) lazy val yard = Yards(1) @@ -351,6 +365,10 @@ object LengthConversions { def km = Kilometers(n) def kilometers = Kilometers(n) def kilometres = Kilometers(n) + def kyd = Kiloyards(n) + def kiloyards = Kiloyards(n) + def kft = Kilofeet(n) + def kilofeet = Kilofeet(n) def inches = Inches(n) def ft = Feet(n) def feet = Feet(n) diff --git a/shared/src/test/scala/squants/space/LengthSpec.scala b/shared/src/test/scala/squants/space/LengthSpec.scala index 04289bef..f1e9f6d2 100644 --- a/shared/src/test/scala/squants/space/LengthSpec.scala +++ b/shared/src/test/scala/squants/space/LengthSpec.scala @@ -37,6 +37,8 @@ class LengthSpec extends AnyFlatSpec with Matchers { Decameters(1).toDecameters should be(1) Hectometers(1).toHectometers should be(1) Kilometers(1).toKilometers should be(1) + Kiloyards(1).toKiloyards should be(1) + Kilofeet(1).toKilofeet should be(1) Inches(1).toInches should be(1) Feet(1).toFeet should be(1) @@ -74,6 +76,8 @@ class LengthSpec extends AnyFlatSpec with Matchers { Length("10.33 dam").get should be(Decameters(10.33)) Length("10.33 hm").get should be(Hectometers(10.33)) Length("10.33 km").get should be(Kilometers(10.33)) + Length("10.33 kyd").get should be(Kiloyards(10.33)) + Length("10.33 kft").get should be(Kilofeet(10.33)) Length("10.33 in").get should be(Inches(10.33)) Length("10.33 ft").get should be(Feet(10.33)) Length("10.33 yd").get should be(Yards(10.33)) @@ -112,6 +116,8 @@ class LengthSpec extends AnyFlatSpec with Matchers { x.toDecameters should be(1 / MetricSystem.Deca) x.toHectometers should be(1 / MetricSystem.Hecto) x.toKilometers should be(1 / MetricSystem.Kilo) + x.toKiloyards should be(1 / (Yards.conversionFactor * MetricSystem.Kilo)) + x.toKilofeet should be(1 / ((Yards.conversionFactor / 3) * MetricSystem.Kilo)) val metersPerFoot = 0.3048006096 x.toInches should be(1 / (metersPerFoot / 12)) @@ -150,6 +156,8 @@ class LengthSpec extends AnyFlatSpec with Matchers { Decameters(1).toString(Decameters) should be("1.0 dam") Hectometers(1).toString(Hectometers) should be("1.0 hm") Kilometers(1).toString(Kilometers) should be("1.0 km") + Kiloyards(1).toString(Kiloyards) should be ("1.0 kyd") + Kilofeet(1).toString(Kilofeet) should be ("1.0 kft") Inches(1).toString(Inches) should be("1.0 in") Feet(1).toString(Feet) should be("1.0 ft") @@ -237,6 +245,8 @@ class LengthSpec extends AnyFlatSpec with Matchers { hectometre should be(Hectometers(1)) kilometer should be(Kilometers(1)) kilometre should be(Kilometers(1)) + kiloyard should be (Kiloyards(1)) + kilofoot should be (Kilofeet(1)) inch should be(Inches(1)) foot should be(Feet(1)) yard should be(Yards(1)) @@ -285,6 +295,10 @@ class LengthSpec extends AnyFlatSpec with Matchers { d.km should be(Kilometers(d)) d.kilometers should be(Kilometers(d)) d.kilometres should be(Kilometers(d)) + d.kyd should be (Kiloyards(d)) + d.kiloyards should be (Kiloyards(d)) + d.kft should be (Kilofeet(d)) + d.kilofeet should be (Kilofeet(d)) d.inches should be(Inches(d)) d.ft should be(Feet(d)) d.feet should be(Feet(d)) @@ -325,6 +339,8 @@ class LengthSpec extends AnyFlatSpec with Matchers { "10.33 dam".toLength.get should be(Decameters(10.33)) "10.33 hm".toLength.get should be(Hectometers(10.33)) "10.33 km".toLength.get should be(Kilometers(10.33)) + "10.33 kyd".toLength.get should be(Kiloyards(10.33)) + "10.33 kft".toLength.get should be(Kilofeet(10.33)) "10.33 in".toLength.get should be(Inches(10.33)) "10.33 ft".toLength.get should be(Feet(10.33)) "10.33 yd".toLength.get should be(Yards(10.33))