diff --git a/build.gradle b/build.gradle index 693c38c..9cae16e 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ publishing { release(MavenPublication) { groupId = 'org.team4099' artifactId = 'falconutils' - version = '1.1.10' + version = '1.1.11' from(components["kotlin"]) } diff --git a/src/main/kotlin/org/team4099/lib/controller/TrapezoidProfile.kt b/src/main/kotlin/org/team4099/lib/controller/TrapezoidProfile.kt index 3c67d73..f9ef824 100644 --- a/src/main/kotlin/org/team4099/lib/controller/TrapezoidProfile.kt +++ b/src/main/kotlin/org/team4099/lib/controller/TrapezoidProfile.kt @@ -10,9 +10,9 @@ import org.team4099.lib.units.base.seconds import edu.wpi.first.math.trajectory.TrapezoidProfile as WPITrapezoidProfile class TrapezoidProfile( - constraints: Constraints, - goal: State, - initial: State + val constraints: Constraints, + val goal: State, + val initial: State ) { val trapezoidProfile = WPITrapezoidProfile(constraints.wpiConstraints, goal.wpiState, initial.wpiState) diff --git a/src/main/kotlin/org/team4099/lib/units/Value.kt b/src/main/kotlin/org/team4099/lib/units/Value.kt index aa3ef89..fc76c09 100644 --- a/src/main/kotlin/org/team4099/lib/units/Value.kt +++ b/src/main/kotlin/org/team4099/lib/units/Value.kt @@ -1,6 +1,5 @@ package org.team4099.lib.units -import java.util.function.Supplier import kotlin.math.absoluteValue import kotlin.math.sign @@ -21,8 +20,7 @@ value class Value(val value: Double) : Comparable> { inline val cubed: Value> get() = Value(value * value * value) - inline val asSupplier: Supplier> - get() = Supplier { Value(value) } + inline fun epsilonEquals(o: Value): Boolean = (value - o.value).absoluteValue <= 1E-9 inline operator fun plus(o: Value): Value = Value(value + o.value) inline operator fun minus(o: Value): Value = Value(value - o.value) diff --git a/src/main/kotlin/org/team4099/lib/units/derived/GearRatio.kt b/src/main/kotlin/org/team4099/lib/units/derived/GearRatio.kt index c14abb8..f5d9240 100644 --- a/src/main/kotlin/org/team4099/lib/units/derived/GearRatio.kt +++ b/src/main/kotlin/org/team4099/lib/units/derived/GearRatio.kt @@ -11,18 +11,9 @@ typealias Driving = Unitless typealias Driven = Unitless // Reductions are < 1 -inline val Double.reduction - get() = GearRatio(1 / this) - -inline val Double.overdrive +inline val Double.gearRatio get() = GearRatio(this) -inline val Number.reduction - get() = this.toDouble().reduction - -inline val Number.overdrive - get() = this.toDouble().overdrive - inline val Double.driving get() = Value(this) @@ -30,7 +21,7 @@ inline val Double.driven get() = Value(this) inline val GearRatio.asDrivingOverDriven - get() = 1 / value + get() = value inline val GearRatio.asDrivenOverDriving - get() = value + get() = 1 / value diff --git a/src/main/kotlin/org/team4099/lib/units/derived/Inertia.kt b/src/main/kotlin/org/team4099/lib/units/derived/Inertia.kt index d8bfc0e..83178ca 100644 --- a/src/main/kotlin/org/team4099/lib/units/derived/Inertia.kt +++ b/src/main/kotlin/org/team4099/lib/units/derived/Inertia.kt @@ -2,6 +2,7 @@ package org.team4099.lib.units.derived import org.team4099.lib.units.Product import org.team4099.lib.units.Squared +import org.team4099.lib.units.UnitKey import org.team4099.lib.units.Value import org.team4099.lib.units.base.Kilogram import org.team4099.lib.units.base.Meter @@ -10,11 +11,8 @@ typealias Inertia = Product> typealias MomentOfInertia = Value -inline val Double.momentOfInertia - get() = MomentOfInertia(this) - -inline val Number.momentOfInertia - get() = MomentOfInertia(this.toDouble()) - -inline val MomentOfInertia.asKilogramsPerMeterSquared +inline val MomentOfInertia.inKilogramsMeterSquared get() = value + +inline val Value.meterSquared + get() = Value>>(value) diff --git a/src/test/kotlin/team4099/units/GearRatioTest.kt b/src/test/kotlin/team4099/units/GearRatioTest.kt index 5dfab98..a600887 100644 --- a/src/test/kotlin/team4099/units/GearRatioTest.kt +++ b/src/test/kotlin/team4099/units/GearRatioTest.kt @@ -1,11 +1,12 @@ package team4099.units +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.team4099.lib.units.derived.asDrivenOverDriving +import org.team4099.lib.units.derived.asDrivingOverDriven import org.team4099.lib.units.derived.driven import org.team4099.lib.units.derived.driving -import org.team4099.lib.units.derived.overdrive -import org.team4099.lib.units.derived.reduction +import org.team4099.lib.units.derived.gearRatio class GearRatioTest { @@ -13,9 +14,9 @@ class GearRatioTest { @Test fun testGearRatio() { - val reductionRatio = (18.0.driving / 72.0.driven).reduction - val overdriveRatio = (18.0.driving / 72.0.driven).overdrive - println(reductionRatio.asDrivenOverDriving) // 4.0 - println(overdriveRatio.asDrivenOverDriving) // 0.25 + val reductionRatio = (72.0.driven / 18.0.driving).gearRatio + + assertEquals(reductionRatio.asDrivenOverDriving, 0.25) + assertEquals(reductionRatio.asDrivingOverDriven, 4.0) } } diff --git a/src/test/kotlin/team4099/units/InertiaTest.kt b/src/test/kotlin/team4099/units/InertiaTest.kt index 53c0f1a..4ff294d 100644 --- a/src/test/kotlin/team4099/units/InertiaTest.kt +++ b/src/test/kotlin/team4099/units/InertiaTest.kt @@ -1,10 +1,11 @@ package team4099.units +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.team4099.lib.units.base.grams import org.team4099.lib.units.base.inches -import org.team4099.lib.units.derived.MomentOfInertia -import org.team4099.lib.units.derived.asKilogramsPerMeterSquared +import org.team4099.lib.units.derived.inKilogramsMeterSquared +import org.team4099.lib.units.derived.meterSquared import org.team4099.lib.units.kilo class InertiaTest { @@ -13,7 +14,10 @@ class InertiaTest { @Test fun testInertia() { - val inertia: MomentOfInertia = 1.0.kilo.grams * 3.0.inches.squared - println(inertia.asKilogramsPerMeterSquared) + val inertia = 1.0.kilo.grams * 3.0.inches.squared + val inertiaDefinition = 1.0.kilo.grams.meterSquared + + assertEquals(1.0, inertiaDefinition.inKilogramsMeterSquared) + assertEquals(0.00580644, inertia.inKilogramsMeterSquared, kEpsilon) } }