Skip to content

Commit

Permalink
add inertial units + squared, cubed, and inverse properties of values
Browse files Browse the repository at this point in the history
  • Loading branch information
sswadkar committed Jan 31, 2023
1 parent 661cdbe commit c8f8de3
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ publishing {
release(MavenPublication) {
groupId = 'org.team4099'
artifactId = 'falconutils'
version = '1.1.7'
version = '1.1.8'

from(components["kotlin"])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.team4099.lib.units.derived.VelocityFeedforward
import org.team4099.lib.units.derived.Volt
import org.team4099.lib.units.derived.inRadians
import org.team4099.lib.units.derived.inVolts
import org.team4099.lib.units.derived.inVoltsPerRadian
import org.team4099.lib.units.derived.inVoltsPerRadianPerSecond
import org.team4099.lib.units.derived.inVoltsPerRadianPerSecondPerSecond
import org.team4099.lib.units.derived.perRadianPerSecondPerSecond
Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/org/team4099/lib/units/Value.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ value class Value<T : UnitKey>(val value: Double) : Comparable<Value<T>> {
inline val sign: Double
get() = sign(value)

inline val inverse: Value<Inverse<T>>
get() = Value(1 / value)

inline val squared: Value<Squared<T>>
get() = Value(value * value)

inline val cubed: Value<Cubed<T>>
get() = Value(value * value * value)

inline operator fun plus(o: Value<T>): Value<T> = Value(value + o.value)
inline operator fun minus(o: Value<T>): Value<T> = Value(value - o.value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.team4099.lib.units.derived
import org.team4099.lib.units.Acceleration
import org.team4099.lib.units.Fraction
import org.team4099.lib.units.UnitKey
import org.team4099.lib.units.Unitless
import org.team4099.lib.units.Value
import org.team4099.lib.units.Velocity
import org.team4099.lib.units.base.Ampere
Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/org/team4099/lib/units/derived/Inertia.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.team4099.lib.units.derived

import org.team4099.lib.units.Product
import org.team4099.lib.units.Squared
import org.team4099.lib.units.Value
import org.team4099.lib.units.base.Kilogram
import org.team4099.lib.units.base.Meter

typealias Inertia = Product<Kilogram, Squared<Meter>>

typealias MomentOfInertia = Value<Inertia>

inline val Double.momentOfInertia
get() = MomentOfInertia(this)

inline val Number.momentOfInertia
get() = MomentOfInertia(this.toDouble())

inline val MomentOfInertia.asKilogramsPerMeterSquared
get() = value
19 changes: 19 additions & 0 deletions src/test/kotlin/team4099/units/InertiaTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package team4099.units

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.kilo

class InertiaTest {

private val kEpsilon = 1E-9

@Test
fun testInertia() {
val inertia: MomentOfInertia = 1.0.kilo.grams * 3.0.inches.squared
println(inertia.asKilogramsPerMeterSquared)
}
}

0 comments on commit c8f8de3

Please sign in to comment.