Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kiloyards and Kilofeet to the Length dimension #297

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion shared/src/main/scala/squants/space/Length.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions shared/src/test/scala/squants/space/LengthSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down