Skip to content

Commit

Permalink
inline all extension functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sswadkar committed Jan 21, 2023
1 parent 618ce43 commit b8e4a1a
Show file tree
Hide file tree
Showing 17 changed files with 394 additions and 394 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id "idea"
id 'maven-publish'
id "org.jetbrains.kotlin.jvm" version "1.6.10"
id "edu.wpi.first.GradleRIO" version "2023.1.1"
id "edu.wpi.first.GradleRIO" version "2023.2.1"
id "com.diffplug.spotless" version "6.3.0"
id "com.peterabeles.gversion" version "1.10"
id "org.jetbrains.kotlinx.kover" version "0.4.2"
Expand Down Expand Up @@ -33,8 +33,8 @@ dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib"

implementation "edu.wpi.first.wpimath:wpimath-java:2023.1.1"
implementation "edu.wpi.first.wpiutil:wpiutil-java:2023.1.1"
implementation "edu.wpi.first.wpimath:wpimath-java:2023.2.1"
implementation "edu.wpi.first.wpiutil:wpiutil-java:2023.2.1"

implementation wpi.java.deps.wpilib()
implementation wpi.java.vendor.java()
Expand All @@ -51,7 +51,7 @@ publishing {
release(MavenPublication) {
groupId = 'org.team4099'
artifactId = 'falconutils'
version = '1.0.6'
version = '1.1.0'

from(components["kotlin"])
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/org/team4099/lib/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlin.math.min
* @param tolerance The range within values will be considered near.
* @return If [around] is within [tolerance] of this Double.
*/
fun Double.around(around: Double, tolerance: Double): Boolean {
inline fun Double.around(around: Double, tolerance: Double): Boolean {
return abs(this - around) < tolerance
}

Expand All @@ -24,7 +24,7 @@ fun Double.around(around: Double, tolerance: Double): Boolean {
* @return This value adjusted to smoothly increase from zero if outside the deadband, zero if
* inside the deadband.
*/
fun Double.smoothDeadband(deadband: Double): Double {
inline fun Double.smoothDeadband(deadband: Double): Double {
return if (abs(this) < deadband) {
0.0
} else {
Expand All @@ -39,7 +39,7 @@ fun Double.smoothDeadband(deadband: Double): Double {
* @param upperBound The upper bound of this Double's range.
* @return Return this Double if it is in the range otherwise return [lowerBound] or [upperBound].
*/
fun Double.limit(lowerBound: Double, upperBound: Double): Double {
inline fun Double.limit(lowerBound: Double, upperBound: Double): Double {
return min(upperBound, max(lowerBound, this))
}

Expand All @@ -50,7 +50,7 @@ fun Double.limit(lowerBound: Double, upperBound: Double): Double {
* @param upperBound The upper bound of this Int's range.
* @return Return this Int if it is in the range otherwise return [lowerBound] or [upperBound].
*/
fun Int.limit(lowerBound: Int, upperBound: Int): Int {
inline fun Int.limit(lowerBound: Int, upperBound: Int): Int {
return min(upperBound, max(lowerBound, this))
}

Expand All @@ -63,7 +63,7 @@ fun Int.limit(lowerBound: Int, upperBound: Int): Int {
* to between 0 and 1 inclusive.
* @return A value between [a] and [b] determined by [x].
*/
fun interpolate(a: Double, b: Double, x: Double): Double {
inline fun interpolate(a: Double, b: Double, x: Double): Double {
return a + (b - a) * x
}

Expand All @@ -76,6 +76,6 @@ fun interpolate(a: Double, b: Double, x: Double): Double {
* to between 0 and 1 inclusive.
* @return A value between [a] and [b] determined by [x].
*/
fun <T : UnitKey> interpolate(a: Value<T>, b: Value<T>, x: Double): Value<T> {
inline fun <T : UnitKey> interpolate(a: Value<T>, b: Value<T>, x: Double): Value<T> {
return Value(a.value + (b.value - a.value) * x)
}
36 changes: 18 additions & 18 deletions src/main/kotlin/org/team4099/lib/units/Derivatives.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,56 +20,56 @@ typealias LinearAcceleration = Value<Acceleration<Meter>>

typealias AngularAcceleration = Value<Acceleration<Radian>>

val <K : UnitKey> Value<K>.perSecond
inline val <K : UnitKey> Value<K>.perSecond
get() = Value<Velocity<K>>(value)

val <K : UnitKey> Value<K>.perMinute
inline val <K : UnitKey> Value<K>.perMinute
get() = Value<Velocity<K>>(value / SECONDS_PER_MINUTE)

val LinearVelocity.inMetersPerSecond: Double
inline val LinearVelocity.inMetersPerSecond: Double
get() = value

val LinearVelocity.inFeetPerSecond: Double
inline val LinearVelocity.inFeetPerSecond: Double
get() = value / METERS_PER_FOOT

val LinearVelocity.inFeetPerMinute: Double
inline val LinearVelocity.inFeetPerMinute: Double
get() = inFeetPerSecond * SECONDS_PER_MINUTE

val LinearVelocity.inInchesPerSecond: Double
inline val LinearVelocity.inInchesPerSecond: Double
get() = value / METERS_PER_INCH

val AngularVelocity.inRadiansPerSecond: Double
inline val AngularVelocity.inRadiansPerSecond: Double
get() = value

val AngularVelocity.inDegreesPerSecond: Double
inline val AngularVelocity.inDegreesPerSecond: Double
get() = Math.toDegrees(value)

val AngularVelocity.inRotationsPerSecond: Double
inline val AngularVelocity.inRotationsPerSecond: Double
get() = value / (2 * PI)

val AngularVelocity.inRotationsPerMinute: Double
inline val AngularVelocity.inRotationsPerMinute: Double
get() = value * SECONDS_PER_MINUTE / (2 * PI)

val LinearAcceleration.inMetersPerSecondPerSecond: Double
inline val LinearAcceleration.inMetersPerSecondPerSecond: Double
get() = value

val LinearAcceleration.inFeetPerSecondPerSecond: Double
inline val LinearAcceleration.inFeetPerSecondPerSecond: Double
get() = value / METERS_PER_FOOT

val LinearAcceleration.inFeetPerMinutePerSecond: Double
inline val LinearAcceleration.inFeetPerMinutePerSecond: Double
get() = inFeetPerSecondPerSecond * SECONDS_PER_MINUTE

val LinearAcceleration.inInchesPerSecondPerSecond: Double
inline val LinearAcceleration.inInchesPerSecondPerSecond: Double
get() = value / METERS_PER_INCH

val AngularAcceleration.inRadiansPerSecondPerSecond: Double
inline val AngularAcceleration.inRadiansPerSecondPerSecond: Double
get() = value

val AngularAcceleration.inDegreesPerSecondPerSecond: Double
inline val AngularAcceleration.inDegreesPerSecondPerSecond: Double
get() = Math.toDegrees(value)

val AngularAcceleration.inRotationsPerSecondPerSecond: Double
inline val AngularAcceleration.inRotationsPerSecondPerSecond: Double
get() = value / (2 * PI)

val AngularAcceleration.inRotationsPerMinutePerMinute: Double
inline val AngularAcceleration.inRotationsPerMinutePerMinute: Double
get() = value * SECONDS_PER_MINUTE * SECONDS_PER_MINUTE / (2 * PI)
Loading

0 comments on commit b8e4a1a

Please sign in to comment.