Skip to content

Commit

Permalink
- Added a few more extension methods to support proper division
Browse files Browse the repository at this point in the history
- Kotlin -> 1.7.21
- Dokka  -> 1.7.20
- JUnit  -> 5.9.1
- Cleanup repositories
  • Loading branch information
pusolito committed Dec 1, 2022
1 parent 5090ea3 commit 72c379b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
25 changes: 22 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {
val kotlinVersion: String by System.getProperties()

id ("org.jetbrains.kotlin.multiplatform") version kotlinVersion
id ("org.jetbrains.dokka" ) version "1.6.0"
id ("org.jetbrains.dokka" ) version "1.7.20"
id ("maven-publish" )
signing
}
Expand Down Expand Up @@ -65,7 +65,7 @@ kotlin {

jvm().compilations["test"].defaultSourceSet {
dependencies {
implementation("junit:junit:$junitVersion")
implementation("org.junit.jupiter:junit-jupiter:$junitVersion")
implementation(kotlin("test-junit"))
}
}
Expand All @@ -81,10 +81,29 @@ kotlin {
val dokkaJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
classifier = "javadoc"
archiveClassifier.set("javadoc")
from(tasks.dokkaHtml)
}

tasks.dokkaHtml {
outputDirectory.set(buildDir.resolve("javadoc"))

dokkaSourceSets {
configureEach {
includeNonPublic.set(false)

// Do not output deprecated members. Applies globally, can be overridden by packageOptions
skipDeprecated.set(true)

// Emit warnings about not documented members. Applies globally, also can be overridden by packageOptions
reportUndocumented.set(true)

// Do not create index pages for empty packages
skipEmptyPackages.set(true)
}
}
}

publishing {
publications.withType<MavenPublication>().apply {
val jvm by getting {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
systemProp.kotlinVersion = 1.6.10
systemProp.kotlinVersion = 1.7.21

version = 0.3.1
version = 0.3.2
group = io.nacular.measured

junitVersion = 4.12
junitVersion = 5.9.1
kotlin.js.compiler = both
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package io.nacular.measured.units
* Units to measure computer storage, bandwidth, etc..
*/
class BinarySize(suffix: String, ratio: Double = 1.0): Units(suffix, ratio) {
operator fun div(other: GraphicsLength) = ratio / other.ratio
operator fun div(other: BinarySize) = ratio / other.ratio

companion object {
val bytes = BinarySize("B" )
Expand Down
10 changes: 10 additions & 0 deletions src/commonMain/kotlin/io/nacular/measured/units/Units.kt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ operator fun <A: Units, B: Units> UnitsRatio<A, B>.div(other: UnitsRatio<A, Squa
@JvmName("times5") operator fun <A: Units, B: Units, C: Units> Measure<UnitsRatio<A, UnitsProduct<B, C>>>.times(other: Measure<B> ): Measure<UnitsRatio<A, C>> = amount * other.amount * (units * other.units)
@JvmName("times6") operator fun <A: Units, B: Units, C: Units, D: Units> Measure<UnitsRatio<A, UnitsProduct<B, C>>>.times(other: Measure<D> ): Measure<UnitsRatio<UnitsProduct<A, D>, UnitsProduct<B, C>>> = amount * other.amount * (units * other.units)

@JvmName("times8" ) operator fun <A: Units> Measure<A>.times (other: Measure<InverseUnits<Square<A>>>): Measure<InverseUnits<A>> = this.amount * other.amount * InverseUnits(other.units.unit.first)
@JvmName("times9" ) operator fun <A: Units> Measure<InverseUnits<Square<A>>>.times(other: Measure<A> ): Measure<InverseUnits<A>> = other * this
@JvmName("times10") operator fun <A: Units> Measure<InverseUnits<A>>.times (other: Measure<A> ): Double = this.amount * other.amount
@JvmName("times11") operator fun <A: Units> Measure<A>.times (other: Measure<InverseUnits<A>> ): Double = other * this

// endregion

// TODO: Kapt code generation possible?
Expand All @@ -246,6 +251,8 @@ operator fun <A: Units> Measure<A>.rem(other: Measure<A>): Double = amount % oth
@JvmName("div14") operator fun <A: Units, B: Units, C: Units, D: Units> Measure<UnitsRatio<UnitsProduct<A, B>, UnitsProduct<C, D>>>.div(other: Measure<A> ): Measure<UnitsRatio<B, UnitsProduct<C, D>>> = amount / other.amount * (units / other.units)
@JvmName("div15") operator fun <A: Units, B: Units> Measure<A>. div(other: Measure<UnitsRatio<A, B>> ): Measure<B> = amount / other.amount * (units / other.units)

operator fun <A: Units> Measure<InverseUnits<A>>.div (other: Measure<InverseUnits<Square<A>>>): Measure<A> = this.amount * other.amount * other.units.unit.first

// endregion

// region ================ Measure * Units Math ============================
Expand Down Expand Up @@ -304,6 +311,9 @@ operator fun <T: Units> Number.times(unit: T): Measure<T> = this i
operator fun <T: Units> Number.div (unit: T): Measure<InverseUnits<T>> = this into InverseUnits(unit)
operator fun <T: Units> Number.times(measure: Measure<T>): Measure<T> = measure * this

@JvmName("divMeasure" ) operator fun <T: Units> Number.div (measure: Measure<T>): Measure<InverseUnits<T>> = this.toDouble() / measure.amount * InverseUnits(measure.units)
@JvmName("divInvMeasure") operator fun <T: Units> Number.div (measure: Measure<InverseUnits<T>>): Measure<T> = this * measure.units.unit / measure.amount

operator fun <T: Units> T.times (value: Number): Measure<T> = value into this
operator fun <T: Units> T.invoke(value: Number): Measure<T> = value into this

Expand Down

0 comments on commit 72c379b

Please sign in to comment.