Skip to content

Commit

Permalink
Add documentation for unit package
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincianfarini committed Jan 2, 2025
1 parent 4ac728d commit 2d4b09d
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public interface AreaUnit {
*/
public val symbol: String

/**
* A non-standard representation of area commonly used as part of the metric system.
*/
public enum class Metric(override val symbol: String, override val millimetersSquaredScale: Long) : AreaUnit {
Decimilliare("dma", 100),
Centiare("ca", 1_000_000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public interface EnergyUnit {
*/
public val symbol: String

/**
* An International System of Units standard representation of energy.
*/
public enum class International(
override val millijouleScale: Long,
override val symbol: String,
Expand All @@ -29,6 +32,9 @@ public interface EnergyUnit {
Petajoule(1_000_000_000_000_000_000, "PJ"),
}

/**
* A non-standard representation of energy commonly used to measure electrical energy.
*/
public enum class Electricity(
override val millijouleScale: Long,
override val symbol: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package io.github.kevincianfarini.alchemist.unit

/**
* A unit of force precise to the nanonewton.
*/
public interface ForceUnit {

/**
* The symbol of this unit.
*/
public val symbol: String

/**
* The amount of nanonewtons in this unit. Implementations of [ForceUnit] should be perfectly divisible by a
* quantity of nanonewtons.
*/
public val nanonewtonScale: Long

/**
* An International System of Units standard representation of force.
*/
public enum class International(override val symbol: String, override val nanonewtonScale: Long) : ForceUnit {
Nanonewton("nN", 1),
Micronewton("μN", 1_000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public interface LengthUnit {
*/
public val symbol: String

/**
* An International System of Units standard representation of length.
*/
public enum class International(
override val nanometerScale: Long,
override val symbol: String,
Expand All @@ -30,6 +33,9 @@ public interface LengthUnit {
Gigameter(1_000_000_000_000_000_000, "Gm"),
}

/**
* A non-standard representation of length commonly used in the United States.
*/
public enum class UnitedStatesCustomary(
override val nanometerScale: Long,
override val symbol: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package io.github.kevincianfarini.alchemist.unit

/**
* A unit of mass precise to the microgram.
*/
public interface MassUnit {

/**
* The amount of micrograms in this unit. Implementations of [MassUnit] should be perfectly divisible by a
* quantity of micrograms.
*/
public val microgramScale: Long

/**
* The symbol of this unit.
*/
public val symbol: String

/**
* An International System of Units standard representation of mass.
*/
public enum class International(override val microgramScale: Long, override val symbol: String): MassUnit {
Microgram(1, "μg"),
Milligram(1_000, "mg"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public interface PowerUnit {
*/
public val symbol: String

/**
* An International System of Units standard representation of power.
*/
public enum class International(
override val microwattScale: Long,
override val symbol: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import io.github.kevincianfarini.alchemist.internal.saturated
import kotlin.math.roundToLong
import kotlin.text.Typography.nbsp

/**
* Marks [TemperatureUnit] as delicate for implementation.
*/
@RequiresOptIn(
message = """
Implementing TemperatureUnit requires detecting integer overflow detection, which normal Long values don't
Expand Down Expand Up @@ -42,6 +45,9 @@ public interface TemperatureUnit {
*/
public fun convertNanokelvinsToThis(nanokelvins: Long): Double

/**
* An International System of Units standard representation of temperature.
*/
public enum class International(override val symbol: String) : TemperatureUnit {
Nanokelvin("${nbsp}nK") {
override fun convertToNanokelvin(degrees: Long): Long = degrees
Expand Down Expand Up @@ -120,6 +126,9 @@ public interface TemperatureUnit {
},
}

/**
* A non-standard unit of temperature used in the United States.
*/
public object Fahrenheit : TemperatureUnit {
override val symbol: String get() = "°F"
override fun convertToNanokelvin(degrees: Long): Long {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ package io.github.kevincianfarini.alchemist.unit

import kotlin.text.Typography.nbsp

/**
* A unit of volume precise to the centimeter³.
*/
public interface VolumeUnit {

/**
* The symbol of this unit.
*/
public val symbol: String

/**
* The amount of centimeter³ in this unit. Implementations of [TemperatureUnit] should be perfectly divisible by a
* quantity of centimeter³.
*/
public val cubicCentimetersScale: Long

/**
* A non-standard representation of volume commonly used as part of the metric system.
*/
public enum class Metric(override val symbol: String, override val cubicCentimetersScale: Long) : VolumeUnit {
Milliliter("${nbsp}mL", 1),
Liter("${nbsp}L", 1_000),
Expand Down

0 comments on commit 2d4b09d

Please sign in to comment.