From 675a3b6f01b46b7c72f6b9f9c55dd637e53688ab Mon Sep 17 00:00:00 2001 From: Andrew Polack Date: Thu, 15 Feb 2018 06:59:53 -0500 Subject: [PATCH] Add Kiloyards and Kilofeet to the Length dimension --- .../src/main/scala/squants/space/Length.scala | 20 ++++++++++++++++++- .../test/scala/squants/space/LengthSpec.scala | 16 +++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/shared/src/main/scala/squants/space/Length.scala b/shared/src/main/scala/squants/space/Length.scala index 1320b067..4f1786cf 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) @@ -104,7 +106,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, SolarRadii, NominalSolarRadii, ElectronVoltLength, MilliElectronVoltLength, KiloElectronVoltLength, MegaElectronVoltLength, @@ -170,6 +172,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" @@ -286,6 +298,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) @@ -330,6 +344,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 8dbeb6dc..6914b765 100644 --- a/shared/src/test/scala/squants/space/LengthSpec.scala +++ b/shared/src/test/scala/squants/space/LengthSpec.scala @@ -36,6 +36,8 @@ class LengthSpec extends FlatSpec 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) @@ -70,6 +72,8 @@ class LengthSpec extends FlatSpec 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)) @@ -105,6 +109,8 @@ class LengthSpec extends FlatSpec 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)) @@ -140,6 +146,8 @@ class LengthSpec extends FlatSpec 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") @@ -224,6 +232,8 @@ class LengthSpec extends FlatSpec 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)) @@ -269,6 +279,10 @@ class LengthSpec extends FlatSpec 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)) @@ -306,6 +320,8 @@ class LengthSpec extends FlatSpec 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))