Skip to content
This repository was archived by the owner on Jan 1, 2023. It is now read-only.
Open
Changes from all commits
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
24 changes: 24 additions & 0 deletions src/main/kotlin/org/sert2521/deepspace/util/Units.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.sert2521.deepspace.util

import org.sert2521.deepspace.Characteristics
import java.lang.Math.PI
import java.util.stream.Collector

data class Unit<T : Unit.Type>(val type: T, val factor: Double) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, gotta come up with a different name for this since it shadow's Kotlin's built-in Unit, (causing this build to fail, eg:

fun String.asResource(body: (String) -> Unit) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha I realized that too! Why do they even call it Unit? Can't they just call it Void? Or None? Or something that makes sense? 😃

sealed class Type {
object Linear : Type()
object Square : Type()
object Cubic : Type()
object Angular : Type()
}
}

fun <T : Unit.Type> Int.convert(units: Pair<Unit<T>, Unit<T>>) =
this * (units.first.factor / units.second.factor)

val m = Unit(Unit.Type.Linear, 1.0)
val inch = Unit(Unit.Type.Linear, 39.3701)
val et = Unit(Unit.Type.Linear, 26876.6549)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

et? encoder tick?


val rad = Unit(Unit.Type.Angular, PI)
val deg = Unit(Unit.Type.Angular, 180.0)