Compare commits
5
Commits
b9673644ab
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1bf76e1be | ||
|
|
10f90e30e2 | ||
|
|
fa53ff81bf | ||
|
|
2d544f877d | ||
|
|
271ff3fa1d |
@@ -857,6 +857,15 @@ needs_transform :: #force_inline proc(origin: Vec2, rotation: f32) -> bool {
|
|||||||
// ----- Anchors ------------
|
// ----- Anchors ------------
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Translate `local` — a point relative to `bounds`'s top-left — into `bounds`'s own coordinate
|
||||||
|
// space by offsetting it by the rectangle's origin. Unlike the anchor helpers above (which
|
||||||
|
// return size-relative offsets and ignore `bounds.x`/`bounds.y`), this uses the rectangle's
|
||||||
|
// position. Handy for drawing inside a sub-region whose rect you were handed — e.g. the
|
||||||
|
// `bounds` passed to a `Custom_Draw` callback: `local_to_bounds(bounds, {cx, cy})`.
|
||||||
|
bound :: #force_inline proc(bounds: Rectangle, local: Vec2) -> Vec2 {
|
||||||
|
return {bounds.x + local.x, bounds.y + local.y}
|
||||||
|
}
|
||||||
|
|
||||||
// Return Vec2 pixel offsets for use as the `origin` parameter of draw calls.
|
// Return Vec2 pixel offsets for use as the `origin` parameter of draw calls.
|
||||||
// Composable with normal vector +/- arithmetic.
|
// Composable with normal vector +/- arithmetic.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -0,0 +1,774 @@
|
|||||||
|
package quantity
|
||||||
|
|
||||||
|
import "base:intrinsics"
|
||||||
|
|
||||||
|
GRAMS_PER_POUND :: 453.59237
|
||||||
|
OUNCES_PER_POUND :: 16
|
||||||
|
GRAMS_PER_OUNCE :: GRAMS_PER_POUND / OUNCES_PER_POUND
|
||||||
|
|
||||||
|
KILO_GRAMS_PER_POUND :: GRAMS_PER_POUND / KILO
|
||||||
|
MILLI_GRAMS_PER_POUND :: GRAMS_PER_POUND * MILLI
|
||||||
|
MICRO_GRAMS_PER_POUND :: GRAMS_PER_POUND * MICRO
|
||||||
|
NANO_GRAMS_PER_POUND :: GRAMS_PER_POUND * NANO
|
||||||
|
|
||||||
|
KILO_GRAMS_PER_OUNCE :: GRAMS_PER_OUNCE / KILO
|
||||||
|
MILLI_GRAMS_PER_OUNCE :: GRAMS_PER_OUNCE * MILLI
|
||||||
|
MICRO_GRAMS_PER_OUNCE :: GRAMS_PER_OUNCE * MICRO
|
||||||
|
NANO_GRAMS_PER_OUNCE :: GRAMS_PER_OUNCE * NANO
|
||||||
|
|
||||||
|
//----- Grams ----------------------------------
|
||||||
|
Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||||
|
v: V,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_kilo_grams procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
grams_to_kilo_grams :: #force_inline proc "contextless" (
|
||||||
|
grams: Grams($V),
|
||||||
|
) -> Kilo_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Kilo_Grams(V){grams.v / KILO}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_milli_grams procedure group.
|
||||||
|
grams_to_milli_grams :: #force_inline proc "contextless" (
|
||||||
|
grams: Grams($V),
|
||||||
|
) -> Milli_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Milli_Grams(V){grams.v * MILLI}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_micro_grams procedure group.
|
||||||
|
grams_to_micro_grams :: #force_inline proc "contextless" (
|
||||||
|
grams: Grams($V),
|
||||||
|
) -> Micro_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Micro_Grams(V){grams.v * MICRO}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_nano_grams procedure group.
|
||||||
|
grams_to_nano_grams :: #force_inline proc "contextless" (
|
||||||
|
grams: Grams($V),
|
||||||
|
) -> Nano_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Nano_Grams(V){grams.v * NANO}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_pounds procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
grams_to_pounds :: #force_inline proc "contextless" (
|
||||||
|
grams: Grams($V),
|
||||||
|
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Pounds(V){grams.v / GRAMS_PER_POUND}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_ounces procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
grams_to_ounces :: #force_inline proc "contextless" (
|
||||||
|
grams: Grams($V),
|
||||||
|
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Ounces(V){grams.v / GRAMS_PER_OUNCE}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----- Kilograms ----------------------------------
|
||||||
|
Kilo_Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||||
|
v: V,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_grams procedure group.
|
||||||
|
kilo_grams_to_grams :: #force_inline proc "contextless" (
|
||||||
|
kilo_grams: Kilo_Grams($V),
|
||||||
|
) -> Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Grams(V){kilo_grams.v * KILO}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_milli_grams procedure group.
|
||||||
|
kilo_grams_to_milli_grams :: #force_inline proc "contextless" (
|
||||||
|
kilo_grams: Kilo_Grams($V),
|
||||||
|
) -> Milli_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Milli_Grams(V){kilo_grams.v * (KILO * MILLI)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_micro_grams procedure group.
|
||||||
|
kilo_grams_to_micro_grams :: #force_inline proc "contextless" (
|
||||||
|
kilo_grams: Kilo_Grams($V),
|
||||||
|
) -> Micro_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Micro_Grams(V){kilo_grams.v * (KILO * MICRO)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_nano_grams procedure group.
|
||||||
|
kilo_grams_to_nano_grams :: #force_inline proc "contextless" (
|
||||||
|
kilo_grams: Kilo_Grams($V),
|
||||||
|
) -> Nano_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Nano_Grams(V){kilo_grams.v * (KILO * NANO)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_pounds procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
kilo_grams_to_pounds :: #force_inline proc "contextless" (
|
||||||
|
kilo_grams: Kilo_Grams($V),
|
||||||
|
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Pounds(V){kilo_grams.v / KILO_GRAMS_PER_POUND}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_ounces procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
kilo_grams_to_ounces :: #force_inline proc "contextless" (
|
||||||
|
kilo_grams: Kilo_Grams($V),
|
||||||
|
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Ounces(V){kilo_grams.v / KILO_GRAMS_PER_OUNCE}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----- Milligrams ----------------------------------
|
||||||
|
Milli_Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||||
|
v: V,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_grams procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
milli_grams_to_grams :: #force_inline proc "contextless" (
|
||||||
|
milli_grams: Milli_Grams($V),
|
||||||
|
) -> Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Grams(V){milli_grams.v / MILLI}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_kilo_grams procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
milli_grams_to_kilo_grams :: #force_inline proc "contextless" (
|
||||||
|
milli_grams: Milli_Grams($V),
|
||||||
|
) -> Kilo_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Kilo_Grams(V){milli_grams.v / (KILO * MILLI)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_micro_grams procedure group.
|
||||||
|
milli_grams_to_micro_grams :: #force_inline proc "contextless" (
|
||||||
|
milli_grams: Milli_Grams($V),
|
||||||
|
) -> Micro_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Micro_Grams(V){milli_grams.v * (MICRO / MILLI)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_nano_grams procedure group.
|
||||||
|
milli_grams_to_nano_grams :: #force_inline proc "contextless" (
|
||||||
|
milli_grams: Milli_Grams($V),
|
||||||
|
) -> Nano_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Nano_Grams(V){milli_grams.v * (NANO / MILLI)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_pounds procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
milli_grams_to_pounds :: #force_inline proc "contextless" (
|
||||||
|
milli_grams: Milli_Grams($V),
|
||||||
|
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Pounds(V){milli_grams.v / MILLI_GRAMS_PER_POUND}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_ounces procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
milli_grams_to_ounces :: #force_inline proc "contextless" (
|
||||||
|
milli_grams: Milli_Grams($V),
|
||||||
|
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Ounces(V){milli_grams.v / MILLI_GRAMS_PER_OUNCE}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----- Micrograms ----------------------------------
|
||||||
|
Micro_Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||||
|
v: V,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_grams procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
micro_grams_to_grams :: #force_inline proc "contextless" (
|
||||||
|
micro_grams: Micro_Grams($V),
|
||||||
|
) -> Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Grams(V){micro_grams.v / MICRO}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_kilo_grams procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
micro_grams_to_kilo_grams :: #force_inline proc "contextless" (
|
||||||
|
micro_grams: Micro_Grams($V),
|
||||||
|
) -> Kilo_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Kilo_Grams(V){micro_grams.v / (KILO * MICRO)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_milli_grams procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
micro_grams_to_milli_grams :: #force_inline proc "contextless" (
|
||||||
|
micro_grams: Micro_Grams($V),
|
||||||
|
) -> Milli_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Milli_Grams(V){micro_grams.v / (MICRO / MILLI)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_nano_grams procedure group.
|
||||||
|
micro_grams_to_nano_grams :: #force_inline proc "contextless" (
|
||||||
|
micro_grams: Micro_Grams($V),
|
||||||
|
) -> Nano_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Nano_Grams(V){micro_grams.v * (NANO / MICRO)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_pounds procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
micro_grams_to_pounds :: #force_inline proc "contextless" (
|
||||||
|
micro_grams: Micro_Grams($V),
|
||||||
|
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Pounds(V){micro_grams.v / MICRO_GRAMS_PER_POUND}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_ounces procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
micro_grams_to_ounces :: #force_inline proc "contextless" (
|
||||||
|
micro_grams: Micro_Grams($V),
|
||||||
|
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Ounces(V){micro_grams.v / MICRO_GRAMS_PER_OUNCE}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----- Nanograms ----------------------------------
|
||||||
|
Nano_Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||||
|
v: V,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_grams procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
nano_grams_to_grams :: #force_inline proc "contextless" (
|
||||||
|
nano_grams: Nano_Grams($V),
|
||||||
|
) -> Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Grams(V){nano_grams.v / NANO}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_kilo_grams procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
nano_grams_to_kilo_grams :: #force_inline proc "contextless" (
|
||||||
|
nano_grams: Nano_Grams($V),
|
||||||
|
) -> Kilo_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Kilo_Grams(V){nano_grams.v / (KILO * NANO)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_milli_grams procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
nano_grams_to_milli_grams :: #force_inline proc "contextless" (
|
||||||
|
nano_grams: Nano_Grams($V),
|
||||||
|
) -> Milli_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Milli_Grams(V){nano_grams.v / (NANO / MILLI)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_micro_grams procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
nano_grams_to_micro_grams :: #force_inline proc "contextless" (
|
||||||
|
nano_grams: Nano_Grams($V),
|
||||||
|
) -> Micro_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Micro_Grams(V){nano_grams.v / (NANO / MICRO)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_pounds procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
nano_grams_to_pounds :: #force_inline proc "contextless" (
|
||||||
|
nano_grams: Nano_Grams($V),
|
||||||
|
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Pounds(V){nano_grams.v / NANO_GRAMS_PER_POUND}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_ounces procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
nano_grams_to_ounces :: #force_inline proc "contextless" (
|
||||||
|
nano_grams: Nano_Grams($V),
|
||||||
|
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Ounces(V){nano_grams.v / NANO_GRAMS_PER_OUNCE}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----- Pounds ----------------------------------
|
||||||
|
Pounds :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||||
|
v: V,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_grams procedure group.
|
||||||
|
pounds_to_grams :: #force_inline proc "contextless" (
|
||||||
|
pounds: Pounds($V),
|
||||||
|
) -> Grams(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Grams(V){pounds.v * GRAMS_PER_POUND}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_kilo_grams procedure group.
|
||||||
|
pounds_to_kilo_grams :: #force_inline proc "contextless" (
|
||||||
|
pounds: Pounds($V),
|
||||||
|
) -> Kilo_Grams(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Kilo_Grams(V){pounds.v * KILO_GRAMS_PER_POUND}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_milli_grams procedure group.
|
||||||
|
pounds_to_milli_grams :: #force_inline proc "contextless" (
|
||||||
|
pounds: Pounds($V),
|
||||||
|
) -> Milli_Grams(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Milli_Grams(V){pounds.v * MILLI_GRAMS_PER_POUND}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_micro_grams procedure group.
|
||||||
|
pounds_to_micro_grams :: #force_inline proc "contextless" (
|
||||||
|
pounds: Pounds($V),
|
||||||
|
) -> Micro_Grams(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Micro_Grams(V){pounds.v * MICRO_GRAMS_PER_POUND}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_nano_grams procedure group.
|
||||||
|
pounds_to_nano_grams :: #force_inline proc "contextless" (
|
||||||
|
pounds: Pounds($V),
|
||||||
|
) -> Nano_Grams(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Nano_Grams(V){pounds.v * NANO_GRAMS_PER_POUND}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_ounces procedure group.
|
||||||
|
pounds_to_ounces :: #force_inline proc "contextless" (
|
||||||
|
pounds: Pounds($V),
|
||||||
|
) -> Ounces(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Ounces(V){pounds.v * OUNCES_PER_POUND}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----- Ounces ----------------------------------
|
||||||
|
Ounces :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||||
|
v: V,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_grams procedure group.
|
||||||
|
ounces_to_grams :: #force_inline proc "contextless" (
|
||||||
|
ounces: Ounces($V),
|
||||||
|
) -> Grams(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Grams(V){ounces.v * GRAMS_PER_OUNCE}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_kilo_grams procedure group.
|
||||||
|
ounces_to_kilo_grams :: #force_inline proc "contextless" (
|
||||||
|
ounces: Ounces($V),
|
||||||
|
) -> Kilo_Grams(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Kilo_Grams(V){ounces.v * KILO_GRAMS_PER_OUNCE}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_milli_grams procedure group.
|
||||||
|
ounces_to_milli_grams :: #force_inline proc "contextless" (
|
||||||
|
ounces: Ounces($V),
|
||||||
|
) -> Milli_Grams(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Milli_Grams(V){ounces.v * MILLI_GRAMS_PER_OUNCE}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_micro_grams procedure group.
|
||||||
|
ounces_to_micro_grams :: #force_inline proc "contextless" (
|
||||||
|
ounces: Ounces($V),
|
||||||
|
) -> Micro_Grams(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Micro_Grams(V){ounces.v * MICRO_GRAMS_PER_OUNCE}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_nano_grams procedure group.
|
||||||
|
ounces_to_nano_grams :: #force_inline proc "contextless" (
|
||||||
|
ounces: Ounces($V),
|
||||||
|
) -> Nano_Grams(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Nano_Grams(V){ounces.v * NANO_GRAMS_PER_OUNCE}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_pounds procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
ounces_to_pounds :: #force_inline proc "contextless" (
|
||||||
|
ounces: Ounces($V),
|
||||||
|
) -> Pounds(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Pounds(V){ounces.v / OUNCES_PER_POUND}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
// ----- Conversion Overloads ------------------------
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
to_grams :: proc {
|
||||||
|
kilo_grams_to_grams,
|
||||||
|
milli_grams_to_grams,
|
||||||
|
micro_grams_to_grams,
|
||||||
|
nano_grams_to_grams,
|
||||||
|
pounds_to_grams,
|
||||||
|
ounces_to_grams,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_kilo_grams :: proc {
|
||||||
|
grams_to_kilo_grams,
|
||||||
|
milli_grams_to_kilo_grams,
|
||||||
|
micro_grams_to_kilo_grams,
|
||||||
|
nano_grams_to_kilo_grams,
|
||||||
|
pounds_to_kilo_grams,
|
||||||
|
ounces_to_kilo_grams,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_milli_grams :: proc {
|
||||||
|
grams_to_milli_grams,
|
||||||
|
kilo_grams_to_milli_grams,
|
||||||
|
micro_grams_to_milli_grams,
|
||||||
|
nano_grams_to_milli_grams,
|
||||||
|
pounds_to_milli_grams,
|
||||||
|
ounces_to_milli_grams,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_micro_grams :: proc {
|
||||||
|
grams_to_micro_grams,
|
||||||
|
kilo_grams_to_micro_grams,
|
||||||
|
milli_grams_to_micro_grams,
|
||||||
|
nano_grams_to_micro_grams,
|
||||||
|
pounds_to_micro_grams,
|
||||||
|
ounces_to_micro_grams,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_nano_grams :: proc {
|
||||||
|
grams_to_nano_grams,
|
||||||
|
kilo_grams_to_nano_grams,
|
||||||
|
milli_grams_to_nano_grams,
|
||||||
|
micro_grams_to_nano_grams,
|
||||||
|
pounds_to_nano_grams,
|
||||||
|
ounces_to_nano_grams,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_pounds :: proc {
|
||||||
|
grams_to_pounds,
|
||||||
|
kilo_grams_to_pounds,
|
||||||
|
milli_grams_to_pounds,
|
||||||
|
micro_grams_to_pounds,
|
||||||
|
nano_grams_to_pounds,
|
||||||
|
ounces_to_pounds,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_ounces :: proc {
|
||||||
|
grams_to_ounces,
|
||||||
|
kilo_grams_to_ounces,
|
||||||
|
milli_grams_to_ounces,
|
||||||
|
micro_grams_to_ounces,
|
||||||
|
nano_grams_to_ounces,
|
||||||
|
pounds_to_ounces,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
// ----- Tests ------------------------
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
import "core:testing"
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_grams_to_kilo_grams :: proc(t: ^testing.T) {
|
||||||
|
grams := Grams(int){12_000}
|
||||||
|
kilo_grams := to_kilo_grams(grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, kilo_grams, Kilo_Grams(int){12})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_grams_to_milli_grams :: proc(t: ^testing.T) {
|
||||||
|
grams := Grams(int){12}
|
||||||
|
milli_grams := to_milli_grams(grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, milli_grams, Milli_Grams(int){12_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_grams_to_micro_grams :: proc(t: ^testing.T) {
|
||||||
|
grams := Grams(int){12}
|
||||||
|
micro_grams := to_micro_grams(grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, micro_grams, Micro_Grams(int){12_000_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_grams_to_nano_grams :: proc(t: ^testing.T) {
|
||||||
|
grams := Grams(int){12}
|
||||||
|
nano_grams := to_nano_grams(grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, nano_grams, Nano_Grams(int){12_000_000_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_grams_to_pounds :: proc(t: ^testing.T) {
|
||||||
|
grams := Grams(f32){453.59237}
|
||||||
|
pounds := to_pounds(grams)
|
||||||
|
|
||||||
|
testing.expect(t, pounds.v > 0.99 && pounds.v < 1.01)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_grams_to_ounces :: proc(t: ^testing.T) {
|
||||||
|
grams := Grams(f32){28.349523125}
|
||||||
|
ounces := to_ounces(grams)
|
||||||
|
|
||||||
|
testing.expect(t, ounces.v > 0.99 && ounces.v < 1.01)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_kilo_grams_to_grams :: proc(t: ^testing.T) {
|
||||||
|
kilo_grams := Kilo_Grams(int){12}
|
||||||
|
grams := to_grams(kilo_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, grams, Grams(int){12_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_kilo_grams_to_milli_grams :: proc(t: ^testing.T) {
|
||||||
|
kilo_grams := Kilo_Grams(int){5}
|
||||||
|
milli_grams := to_milli_grams(kilo_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, milli_grams, Milli_Grams(int){5_000_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_kilo_grams_to_micro_grams :: proc(t: ^testing.T) {
|
||||||
|
kilo_grams := Kilo_Grams(int){5}
|
||||||
|
micro_grams := to_micro_grams(kilo_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, micro_grams, Micro_Grams(int){5_000_000_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_kilo_grams_to_nano_grams :: proc(t: ^testing.T) {
|
||||||
|
kilo_grams := Kilo_Grams(int){5}
|
||||||
|
nano_grams := to_nano_grams(kilo_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, nano_grams, Nano_Grams(int){5_000_000_000_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_kilo_grams_to_pounds :: proc(t: ^testing.T) {
|
||||||
|
kilo_grams := Kilo_Grams(f32){0.45359237}
|
||||||
|
pounds := to_pounds(kilo_grams)
|
||||||
|
|
||||||
|
testing.expect(t, pounds.v > 0.99 && pounds.v < 1.01)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_kilo_grams_to_ounces :: proc(t: ^testing.T) {
|
||||||
|
kilo_grams := Kilo_Grams(f32){0.028349523125}
|
||||||
|
ounces := to_ounces(kilo_grams)
|
||||||
|
|
||||||
|
testing.expect(t, ounces.v > 0.99 && ounces.v < 1.01)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_milli_grams_to_grams :: proc(t: ^testing.T) {
|
||||||
|
milli_grams := Milli_Grams(int){12_000}
|
||||||
|
grams := to_grams(milli_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, grams, Grams(int){12})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_milli_grams_to_kilo_grams :: proc(t: ^testing.T) {
|
||||||
|
milli_grams := Milli_Grams(int){5_000_000}
|
||||||
|
kilo_grams := to_kilo_grams(milli_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, kilo_grams, Kilo_Grams(int){5})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_milli_grams_to_micro_grams :: proc(t: ^testing.T) {
|
||||||
|
milli_grams := Milli_Grams(int){5}
|
||||||
|
micro_grams := to_micro_grams(milli_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, micro_grams, Micro_Grams(int){5_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_milli_grams_to_nano_grams :: proc(t: ^testing.T) {
|
||||||
|
milli_grams := Milli_Grams(int){5}
|
||||||
|
nano_grams := to_nano_grams(milli_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, nano_grams, Nano_Grams(int){5_000_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_milli_grams_to_pounds :: proc(t: ^testing.T) {
|
||||||
|
milli_grams := Milli_Grams(f64){453_592.37}
|
||||||
|
pounds := to_pounds(milli_grams)
|
||||||
|
|
||||||
|
testing.expect(t, pounds.v > 0.9999999 && pounds.v < 1.0000001)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_milli_grams_to_ounces :: proc(t: ^testing.T) {
|
||||||
|
milli_grams := Milli_Grams(f64){28_349.523125}
|
||||||
|
ounces := to_ounces(milli_grams)
|
||||||
|
|
||||||
|
testing.expect(t, ounces.v > 0.9999999 && ounces.v < 1.0000001)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_micro_grams_to_grams :: proc(t: ^testing.T) {
|
||||||
|
micro_grams := Micro_Grams(int){12_000_000}
|
||||||
|
grams := to_grams(micro_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, grams, Grams(int){12})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_micro_grams_to_kilo_grams :: proc(t: ^testing.T) {
|
||||||
|
micro_grams := Micro_Grams(int){5_000_000_000}
|
||||||
|
kilo_grams := to_kilo_grams(micro_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, kilo_grams, Kilo_Grams(int){5})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_micro_grams_to_milli_grams :: proc(t: ^testing.T) {
|
||||||
|
micro_grams := Micro_Grams(int){5_000}
|
||||||
|
milli_grams := to_milli_grams(micro_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, milli_grams, Milli_Grams(int){5})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_micro_grams_to_nano_grams :: proc(t: ^testing.T) {
|
||||||
|
micro_grams := Micro_Grams(int){5}
|
||||||
|
nano_grams := to_nano_grams(micro_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, nano_grams, Nano_Grams(int){5_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_micro_grams_to_pounds :: proc(t: ^testing.T) {
|
||||||
|
micro_grams := Micro_Grams(f64){453_592_370}
|
||||||
|
pounds := to_pounds(micro_grams)
|
||||||
|
|
||||||
|
testing.expect(t, pounds.v > 0.9999999 && pounds.v < 1.0000001)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_micro_grams_to_ounces :: proc(t: ^testing.T) {
|
||||||
|
micro_grams := Micro_Grams(f64){28_349_523.125}
|
||||||
|
ounces := to_ounces(micro_grams)
|
||||||
|
|
||||||
|
testing.expect(t, ounces.v > 0.9999999 && ounces.v < 1.0000001)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_nano_grams_to_grams :: proc(t: ^testing.T) {
|
||||||
|
nano_grams := Nano_Grams(int){12_000_000_000}
|
||||||
|
grams := to_grams(nano_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, grams, Grams(int){12})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_nano_grams_to_kilo_grams :: proc(t: ^testing.T) {
|
||||||
|
nano_grams := Nano_Grams(int){5_000_000_000_000}
|
||||||
|
kilo_grams := to_kilo_grams(nano_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, kilo_grams, Kilo_Grams(int){5})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_nano_grams_to_milli_grams :: proc(t: ^testing.T) {
|
||||||
|
nano_grams := Nano_Grams(int){5_000_000}
|
||||||
|
milli_grams := to_milli_grams(nano_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, milli_grams, Milli_Grams(int){5})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_nano_grams_to_micro_grams :: proc(t: ^testing.T) {
|
||||||
|
nano_grams := Nano_Grams(int){5_000}
|
||||||
|
micro_grams := to_micro_grams(nano_grams)
|
||||||
|
|
||||||
|
testing.expect_value(t, micro_grams, Micro_Grams(int){5})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_nano_grams_to_pounds :: proc(t: ^testing.T) {
|
||||||
|
nano_grams := Nano_Grams(f64){453_592_370_000}
|
||||||
|
pounds := to_pounds(nano_grams)
|
||||||
|
|
||||||
|
testing.expect(t, pounds.v > 0.9999999 && pounds.v < 1.0000001)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_nano_grams_to_ounces :: proc(t: ^testing.T) {
|
||||||
|
nano_grams := Nano_Grams(f64){28_349_523_125}
|
||||||
|
ounces := to_ounces(nano_grams)
|
||||||
|
|
||||||
|
testing.expect(t, ounces.v > 0.9999999 && ounces.v < 1.0000001)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_pounds_to_grams :: proc(t: ^testing.T) {
|
||||||
|
pounds := Pounds(f32){1}
|
||||||
|
grams := to_grams(pounds)
|
||||||
|
|
||||||
|
testing.expect(t, grams.v > 453.59 && grams.v < 453.6)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_pounds_to_kilo_grams :: proc(t: ^testing.T) {
|
||||||
|
pounds := Pounds(f32){1}
|
||||||
|
kilo_grams := to_kilo_grams(pounds)
|
||||||
|
|
||||||
|
testing.expect(t, kilo_grams.v > 0.4535 && kilo_grams.v < 0.4536)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_pounds_to_milli_grams :: proc(t: ^testing.T) {
|
||||||
|
pounds := Pounds(f64){1}
|
||||||
|
milli_grams := to_milli_grams(pounds)
|
||||||
|
|
||||||
|
testing.expect(t, milli_grams.v > 453_592.369 && milli_grams.v < 453_592.371)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_pounds_to_micro_grams :: proc(t: ^testing.T) {
|
||||||
|
pounds := Pounds(f64){1}
|
||||||
|
micro_grams := to_micro_grams(pounds)
|
||||||
|
|
||||||
|
testing.expect(t, micro_grams.v > 453_592_369.9 && micro_grams.v < 453_592_370.1)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_pounds_to_nano_grams :: proc(t: ^testing.T) {
|
||||||
|
pounds := Pounds(f64){1}
|
||||||
|
nano_grams := to_nano_grams(pounds)
|
||||||
|
|
||||||
|
testing.expect(t, nano_grams.v > 453_592_369_999.0 && nano_grams.v < 453_592_370_001.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_pounds_to_ounces :: proc(t: ^testing.T) {
|
||||||
|
pounds := Pounds(int){2}
|
||||||
|
ounces := to_ounces(pounds)
|
||||||
|
|
||||||
|
testing.expect_value(t, ounces, Ounces(int){32})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_ounces_to_grams :: proc(t: ^testing.T) {
|
||||||
|
ounces := Ounces(f32){1}
|
||||||
|
grams := to_grams(ounces)
|
||||||
|
|
||||||
|
testing.expect(t, grams.v > 28.34 && grams.v < 28.35)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_ounces_to_kilo_grams :: proc(t: ^testing.T) {
|
||||||
|
ounces := Ounces(f32){1}
|
||||||
|
kilo_grams := to_kilo_grams(ounces)
|
||||||
|
|
||||||
|
testing.expect(t, kilo_grams.v > 0.0283 && kilo_grams.v < 0.0284)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_ounces_to_milli_grams :: proc(t: ^testing.T) {
|
||||||
|
ounces := Ounces(f64){1}
|
||||||
|
milli_grams := to_milli_grams(ounces)
|
||||||
|
|
||||||
|
testing.expect(t, milli_grams.v > 28_349.523 && milli_grams.v < 28_349.524)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_ounces_to_micro_grams :: proc(t: ^testing.T) {
|
||||||
|
ounces := Ounces(f64){1}
|
||||||
|
micro_grams := to_micro_grams(ounces)
|
||||||
|
|
||||||
|
testing.expect(t, micro_grams.v > 28_349_523.124 && micro_grams.v < 28_349_523.126)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_ounces_to_nano_grams :: proc(t: ^testing.T) {
|
||||||
|
ounces := Ounces(f64){1}
|
||||||
|
nano_grams := to_nano_grams(ounces)
|
||||||
|
|
||||||
|
testing.expect(t, nano_grams.v > 28_349_523_124.0 && nano_grams.v < 28_349_523_126.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_ounces_to_pounds :: proc(t: ^testing.T) {
|
||||||
|
ounces := Ounces(int){32}
|
||||||
|
pounds := to_pounds(ounces)
|
||||||
|
|
||||||
|
testing.expect_value(t, pounds, Pounds(int){2})
|
||||||
|
}
|
||||||
@@ -10,14 +10,14 @@ Pascals :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_kilo_pascals procedure group.
|
||||||
pascals_to_kilo_pascals :: #force_inline proc "contextless" (
|
pascals_to_kilo_pascals :: #force_inline proc "contextless" (
|
||||||
pascals: Pascals($V),
|
pascals: Pascals($V),
|
||||||
) -> Kilo_Pascals(V) where intrinsics.type_is_numeric(V) {
|
) -> Kilo_Pascals(V) where intrinsics.type_is_numeric(V) {
|
||||||
return Kilo_Pascals(V){pascals.v / KILO}
|
return Kilo_Pascals(V){pascals.v / KILO}
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_torr procedure group.
|
||||||
pascals_to_torr :: #force_inline proc "contextless" (
|
pascals_to_torr :: #force_inline proc "contextless" (
|
||||||
pascals: Pascals($V),
|
pascals: Pascals($V),
|
||||||
) -> Torr(V) where intrinsics.type_is_float(V) {
|
) -> Torr(V) where intrinsics.type_is_float(V) {
|
||||||
@@ -29,13 +29,14 @@ Kilo_Pascals :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_pascals procedure group.
|
||||||
kilo_pascals_to_pascals :: #force_inline proc "contextless" (
|
kilo_pascals_to_pascals :: #force_inline proc "contextless" (
|
||||||
kilo_pascals: Kilo_Pascals($V),
|
kilo_pascals: Kilo_Pascals($V),
|
||||||
) -> Pascals(V) where intrinsics.type_is_numeric(V) {
|
) -> Pascals(V) where intrinsics.type_is_numeric(V) {
|
||||||
return Pascals(V){kilo_pascals.v * KILO}
|
return Pascals(V){kilo_pascals.v * KILO}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prefer the to_psi procedure group.
|
||||||
kilo_pascals_to_psi :: #force_inline proc "contextless" (
|
kilo_pascals_to_psi :: #force_inline proc "contextless" (
|
||||||
kilo_pascals: Kilo_Pascals($V),
|
kilo_pascals: Kilo_Pascals($V),
|
||||||
) -> Psi(V) where intrinsics.type_is_float(V) {
|
) -> Psi(V) where intrinsics.type_is_float(V) {
|
||||||
@@ -47,7 +48,7 @@ Torr :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_pascals procedure group.
|
||||||
torr_to_pascals :: #force_inline proc "contextless" (
|
torr_to_pascals :: #force_inline proc "contextless" (
|
||||||
torr: Torr($V),
|
torr: Torr($V),
|
||||||
) -> Pascals(V) where intrinsics.type_is_float(V) {
|
) -> Pascals(V) where intrinsics.type_is_float(V) {
|
||||||
@@ -59,6 +60,7 @@ Psi :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prefer the to_kilo_pascals procedure group.
|
||||||
psi_to_kilo_pascals :: #force_inline proc "contextless" (
|
psi_to_kilo_pascals :: #force_inline proc "contextless" (
|
||||||
psi: Psi($V),
|
psi: Psi($V),
|
||||||
) -> Kilo_Pascals(V) where intrinsics.type_is_float(V) {
|
) -> Kilo_Pascals(V) where intrinsics.type_is_float(V) {
|
||||||
|
|||||||
+11
-10
@@ -30,21 +30,21 @@ Kelvins :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_celsius procedure group.
|
||||||
kelvins_to_celsius :: #force_inline proc "contextless" (
|
kelvins_to_celsius :: #force_inline proc "contextless" (
|
||||||
kelvins: Kelvins($V),
|
kelvins: Kelvins($V),
|
||||||
) -> Celsius(V) where intrinsics.type_is_numeric(V) {
|
) -> Celsius(V) where intrinsics.type_is_numeric(V) {
|
||||||
return Celsius(V){kelvins.v - kelvins_celsius_offset(V)}
|
return Celsius(V){kelvins.v - kelvins_celsius_offset(V)}
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_deci_kelvins procedure group.
|
||||||
kelvins_to_deci_kelvins :: #force_inline proc "contextless" (
|
kelvins_to_deci_kelvins :: #force_inline proc "contextless" (
|
||||||
kelvins: Kelvins($V),
|
kelvins: Kelvins($V),
|
||||||
) -> Deci_Kelvins(V) where intrinsics.type_is_numeric(V) {
|
) -> Deci_Kelvins(V) where intrinsics.type_is_numeric(V) {
|
||||||
return Deci_Kelvins(V){kelvins.v * DECI}
|
return Deci_Kelvins(V){kelvins.v * DECI}
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_fahrenheit procedure group.
|
||||||
kelvins_to_fahrenheit :: #force_inline proc "contextless" (
|
kelvins_to_fahrenheit :: #force_inline proc "contextless" (
|
||||||
kelvins: Kelvins($V),
|
kelvins: Kelvins($V),
|
||||||
) -> Fahrenheit(V) where intrinsics.type_is_numeric(V) {
|
) -> Fahrenheit(V) where intrinsics.type_is_numeric(V) {
|
||||||
@@ -56,7 +56,7 @@ Deci_Kelvins :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_kelvins procedure group.
|
||||||
deci_kelvins_to_kelvins :: #force_inline proc "contextless" (
|
deci_kelvins_to_kelvins :: #force_inline proc "contextless" (
|
||||||
deci_kelvins: Deci_Kelvins($V),
|
deci_kelvins: Deci_Kelvins($V),
|
||||||
) -> Kelvins(V) where intrinsics.type_is_numeric(V) {
|
) -> Kelvins(V) where intrinsics.type_is_numeric(V) {
|
||||||
@@ -68,21 +68,22 @@ Celsius :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_kelvins procedure group.
|
||||||
celsius_to_kelvins :: #force_inline proc "contextless" (
|
celsius_to_kelvins :: #force_inline proc "contextless" (
|
||||||
degrees_celsius: Celsius($V),
|
degrees_celsius: Celsius($V),
|
||||||
) -> Kelvins(V) where intrinsics.type_is_numeric(V) {
|
) -> Kelvins(V) where intrinsics.type_is_numeric(V) {
|
||||||
return Kelvins(V){degrees_celsius.v + kelvins_celsius_offset(V)}
|
return Kelvins(V){degrees_celsius.v + kelvins_celsius_offset(V)}
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_deci_celsius procedure group.
|
||||||
celsius_to_deci_celsius :: #force_inline proc "contextless" (
|
celsius_to_deci_celsius :: #force_inline proc "contextless" (
|
||||||
degrees_celsius: Celsius($V),
|
degrees_celsius: Celsius($V),
|
||||||
) -> Deci_Celsius(V) where intrinsics.type_is_numeric(V) {
|
) -> Deci_Celsius(V) where intrinsics.type_is_numeric(V) {
|
||||||
return Deci_Celsius(V){degrees_celsius.v * DECI}
|
return Deci_Celsius(V){degrees_celsius.v * DECI}
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file", fast_math = {.Allow_Contract})
|
// Prefer the to_fahrenheit procedure group.
|
||||||
|
@(fast_math = {.Allow_Contract})
|
||||||
celsius_to_fahrenheit :: #force_inline proc "contextless" (
|
celsius_to_fahrenheit :: #force_inline proc "contextless" (
|
||||||
degrees_celsius: Celsius($V),
|
degrees_celsius: Celsius($V),
|
||||||
) -> Fahrenheit(V) where intrinsics.type_is_numeric(V) {
|
) -> Fahrenheit(V) where intrinsics.type_is_numeric(V) {
|
||||||
@@ -98,7 +99,7 @@ Deci_Celsius :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_celsius procedure group.
|
||||||
deci_celsius_to_celsius :: #force_inline proc "contextless" (
|
deci_celsius_to_celsius :: #force_inline proc "contextless" (
|
||||||
deci_degrees_celsius: Deci_Celsius($V),
|
deci_degrees_celsius: Deci_Celsius($V),
|
||||||
) -> Celsius(V) where intrinsics.type_is_numeric(V) {
|
) -> Celsius(V) where intrinsics.type_is_numeric(V) {
|
||||||
@@ -110,7 +111,7 @@ Fahrenheit :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_celsius procedure group.
|
||||||
fahrenheit_to_celsius :: #force_inline proc "contextless" (
|
fahrenheit_to_celsius :: #force_inline proc "contextless" (
|
||||||
degrees_fahrenheit: Fahrenheit($V),
|
degrees_fahrenheit: Fahrenheit($V),
|
||||||
) -> Celsius(V) where intrinsics.type_is_numeric(V) {
|
) -> Celsius(V) where intrinsics.type_is_numeric(V) {
|
||||||
@@ -121,7 +122,7 @@ fahrenheit_to_celsius :: #force_inline proc "contextless" (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_kelvins procedure group.
|
||||||
fahrenheit_to_kelvins :: #force_inline proc "contextless" (
|
fahrenheit_to_kelvins :: #force_inline proc "contextless" (
|
||||||
degrees_fahrenheit: Fahrenheit($V),
|
degrees_fahrenheit: Fahrenheit($V),
|
||||||
) -> Kelvins(V) where intrinsics.type_is_numeric(V) {
|
) -> Kelvins(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Volts :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_milli_volts procedure group.
|
||||||
volts_to_milli_volts :: #force_inline proc "contextless" (
|
volts_to_milli_volts :: #force_inline proc "contextless" (
|
||||||
volts: Volts($V),
|
volts: Volts($V),
|
||||||
) -> Milli_Volts(V) where intrinsics.type_is_numeric(V) {
|
) -> Milli_Volts(V) where intrinsics.type_is_numeric(V) {
|
||||||
@@ -19,7 +19,7 @@ Milli_Volts :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_volts procedure group.
|
||||||
milli_volts_to_volts :: #force_inline proc "contextless" (
|
milli_volts_to_volts :: #force_inline proc "contextless" (
|
||||||
milli_volts: Milli_Volts($V),
|
milli_volts: Milli_Volts($V),
|
||||||
) -> Volts(V) where intrinsics.type_is_numeric(V) {
|
) -> Volts(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
|||||||
+114
-4
@@ -3,64 +3,126 @@ package quantity
|
|||||||
import "base:intrinsics"
|
import "base:intrinsics"
|
||||||
|
|
||||||
LITERS_PER_GALLON :: 3.785411784
|
LITERS_PER_GALLON :: 3.785411784
|
||||||
|
MICRO_LITERS_PER_GALLON :: 473176473.0 / 125.0
|
||||||
|
|
||||||
//----- Liters ----------------------------------
|
//----- Liters ----------------------------------
|
||||||
Liters :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
Liters :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_milli_liters procedure group.
|
||||||
liters_to_milli_liters :: #force_inline proc "contextless" (
|
liters_to_milli_liters :: #force_inline proc "contextless" (
|
||||||
liters: Liters($V),
|
liters: Liters($V),
|
||||||
) -> Milli_Liters(V) where intrinsics.type_is_numeric(V) {
|
) -> Milli_Liters(V) where intrinsics.type_is_numeric(V) {
|
||||||
return Milli_Liters(V){liters.v * MILLI}
|
return Milli_Liters(V){liters.v * MILLI}
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_gallons procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
liters_to_gallons :: #force_inline proc "contextless" (
|
liters_to_gallons :: #force_inline proc "contextless" (
|
||||||
liters: Liters($V),
|
liters: Liters($V),
|
||||||
) -> Gallons(V) where intrinsics.type_is_float(V) {
|
) -> Gallons(V) where intrinsics.type_is_float(V) {
|
||||||
return Gallons(V){liters.v / LITERS_PER_GALLON}
|
return Gallons(V){liters.v / LITERS_PER_GALLON}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prefer the to_micro_liters procedure group.
|
||||||
|
liters_to_micro_liters :: #force_inline proc "contextless" (
|
||||||
|
liters: Liters($V),
|
||||||
|
) -> Micro_Liters(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Micro_Liters(V){liters.v * MICRO}
|
||||||
|
}
|
||||||
|
|
||||||
//----- Milliliters ----------------------------------
|
//----- Milliliters ----------------------------------
|
||||||
Milli_Liters :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
Milli_Liters :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_liters procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
milli_liters_to_liters :: #force_inline proc "contextless" (
|
milli_liters_to_liters :: #force_inline proc "contextless" (
|
||||||
milli_liters: Milli_Liters($V),
|
milli_liters: Milli_Liters($V),
|
||||||
) -> Liters(V) where intrinsics.type_is_numeric(V) {
|
) -> Liters(V) where intrinsics.type_is_numeric(V) {
|
||||||
return Liters(V){milli_liters.v / MILLI}
|
return Liters(V){milli_liters.v / MILLI}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prefer the to_micro_liters procedure group.
|
||||||
|
milli_liters_to_micro_liters :: #force_inline proc "contextless" (
|
||||||
|
milli_liters: Milli_Liters($V),
|
||||||
|
) -> Micro_Liters(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Micro_Liters(V){milli_liters.v * (MICRO / MILLI)}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----- Microliters ----------------------------------
|
||||||
|
Micro_Liters :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||||
|
v: V,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_liters procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
micro_liters_to_liters :: #force_inline proc "contextless" (
|
||||||
|
micro_liters: Micro_Liters($V),
|
||||||
|
) -> Liters(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Liters(V){micro_liters.v / MICRO}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_milli_liters procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
micro_liters_to_milli_liters :: #force_inline proc "contextless" (
|
||||||
|
micro_liters: Micro_Liters($V),
|
||||||
|
) -> Milli_Liters(V) where intrinsics.type_is_numeric(V) {
|
||||||
|
return Milli_Liters(V){micro_liters.v / (MICRO / MILLI)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the to_gallons procedure group.
|
||||||
|
@(fast_math = {.Allow_Reciprocal})
|
||||||
|
micro_liters_to_gallons :: #force_inline proc "contextless" (
|
||||||
|
micro_liters: Micro_Liters($V),
|
||||||
|
) -> Gallons(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Gallons(V){micro_liters.v / MICRO_LITERS_PER_GALLON}
|
||||||
|
}
|
||||||
|
|
||||||
//----- Gallons ----------------------------------
|
//----- Gallons ----------------------------------
|
||||||
Gallons :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
Gallons :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_liters procedure group.
|
||||||
gallons_to_liters :: #force_inline proc "contextless" (
|
gallons_to_liters :: #force_inline proc "contextless" (
|
||||||
gallons: Gallons($V),
|
gallons: Gallons($V),
|
||||||
) -> Liters(V) where intrinsics.type_is_float(V) {
|
) -> Liters(V) where intrinsics.type_is_float(V) {
|
||||||
return Liters(V){gallons.v * LITERS_PER_GALLON}
|
return Liters(V){gallons.v * LITERS_PER_GALLON}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prefer the to_micro_liters procedure group.
|
||||||
|
gallons_to_micro_liters :: #force_inline proc "contextless" (
|
||||||
|
gallons: Gallons($V),
|
||||||
|
) -> Micro_Liters(V) where intrinsics.type_is_float(V) {
|
||||||
|
return Micro_Liters(V){gallons.v * MICRO_LITERS_PER_GALLON}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
// ----- Conversion Overloads ------------------------
|
// ----- Conversion Overloads ------------------------
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
to_liters :: proc {
|
to_liters :: proc {
|
||||||
milli_liters_to_liters,
|
milli_liters_to_liters,
|
||||||
|
micro_liters_to_liters,
|
||||||
gallons_to_liters,
|
gallons_to_liters,
|
||||||
}
|
}
|
||||||
|
|
||||||
to_milli_liters :: proc {
|
to_milli_liters :: proc {
|
||||||
liters_to_milli_liters,
|
liters_to_milli_liters,
|
||||||
|
micro_liters_to_milli_liters,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_micro_liters :: proc {
|
||||||
|
liters_to_micro_liters,
|
||||||
|
milli_liters_to_micro_liters,
|
||||||
|
gallons_to_micro_liters,
|
||||||
}
|
}
|
||||||
|
|
||||||
to_gallons :: proc {
|
to_gallons :: proc {
|
||||||
liters_to_gallons,
|
liters_to_gallons,
|
||||||
|
micro_liters_to_gallons,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -99,3 +161,51 @@ test_liters_to_gallons :: proc(t: ^testing.T) {
|
|||||||
|
|
||||||
testing.expect(t, gallons.v > 0.99 && gallons.v < 1.01)
|
testing.expect(t, gallons.v > 0.99 && gallons.v < 1.01)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_liters_to_micro_liters :: proc(t: ^testing.T) {
|
||||||
|
liters := Liters(int){12}
|
||||||
|
micro_liters := to_micro_liters(liters)
|
||||||
|
|
||||||
|
testing.expect_value(t, micro_liters, Micro_Liters(int){12_000_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_micro_liters_to_liters :: proc(t: ^testing.T) {
|
||||||
|
micro_liters := Micro_Liters(int){12_000_000}
|
||||||
|
liters := to_liters(micro_liters)
|
||||||
|
|
||||||
|
testing.expect_value(t, liters, Liters(int){12})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_milli_liters_to_micro_liters :: proc(t: ^testing.T) {
|
||||||
|
milli_liters := Milli_Liters(int){5}
|
||||||
|
micro_liters := to_micro_liters(milli_liters)
|
||||||
|
|
||||||
|
testing.expect_value(t, micro_liters, Micro_Liters(int){5_000})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_micro_liters_to_milli_liters :: proc(t: ^testing.T) {
|
||||||
|
micro_liters := Micro_Liters(int){5_000}
|
||||||
|
milli_liters := to_milli_liters(micro_liters)
|
||||||
|
|
||||||
|
testing.expect_value(t, milli_liters, Milli_Liters(int){5})
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_gallons_to_micro_liters :: proc(t: ^testing.T) {
|
||||||
|
gallons := Gallons(f64){1}
|
||||||
|
micro_liters := to_micro_liters(gallons)
|
||||||
|
|
||||||
|
testing.expect(t, micro_liters.v > 3_785_411.783 && micro_liters.v < 3_785_411.785)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_micro_liters_to_gallons :: proc(t: ^testing.T) {
|
||||||
|
micro_liters := Micro_Liters(f64){3_785_411.784}
|
||||||
|
gallons := to_gallons(micro_liters)
|
||||||
|
|
||||||
|
testing.expect(t, gallons.v > 0.9999999 && gallons.v < 1.0000001)
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Liters_Per_Minute :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_gallons_per_minute procedure group.
|
||||||
liters_per_minute_to_gallons_per_minute :: #force_inline proc "contextless" (
|
liters_per_minute_to_gallons_per_minute :: #force_inline proc "contextless" (
|
||||||
liters_per_minute: Liters_Per_Minute($V),
|
liters_per_minute: Liters_Per_Minute($V),
|
||||||
) -> Gallons_Per_Minute(V) where intrinsics.type_is_float(V) {
|
) -> Gallons_Per_Minute(V) where intrinsics.type_is_float(V) {
|
||||||
@@ -19,7 +19,7 @@ Gallons_Per_Minute :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|||||||
v: V,
|
v: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
// Prefer the to_liters_per_minute procedure group.
|
||||||
gallons_per_minute_to_liters_per_minute :: #force_inline proc "contextless" (
|
gallons_per_minute_to_liters_per_minute :: #force_inline proc "contextless" (
|
||||||
gallons_per_minute: Gallons_Per_Minute($V),
|
gallons_per_minute: Gallons_Per_Minute($V),
|
||||||
) -> Liters_Per_Minute(V) where intrinsics.type_is_float(V) {
|
) -> Liters_Per_Minute(V) where intrinsics.type_is_float(V) {
|
||||||
|
|||||||
+23
-23
@@ -113,19 +113,19 @@ advance :: proc {
|
|||||||
advance_soa,
|
advance_soa,
|
||||||
}
|
}
|
||||||
|
|
||||||
append_aos :: #force_inline proc(ring: ^Ring($E), element: E) {
|
push_aos :: #force_inline proc(ring: ^Ring($E), element: E) {
|
||||||
ring.data[ring.next_write_index] = element
|
ring.data[ring.next_write_index] = element
|
||||||
advance(ring)
|
advance(ring)
|
||||||
}
|
}
|
||||||
|
|
||||||
append_soa :: #force_inline proc(ring: ^Ring_Soa($E), element: E) {
|
push_soa :: #force_inline proc(ring: ^Ring_Soa($E), element: E) {
|
||||||
ring.data[ring.next_write_index] = element
|
ring.data[ring.next_write_index] = element
|
||||||
advance(ring)
|
advance(ring)
|
||||||
}
|
}
|
||||||
|
|
||||||
append :: proc {
|
push :: proc {
|
||||||
append_aos,
|
push_aos,
|
||||||
append_soa,
|
push_soa,
|
||||||
}
|
}
|
||||||
|
|
||||||
get_aos :: #force_inline proc(ring: Ring($E), index: int) -> ^E {
|
get_aos :: #force_inline proc(ring: Ring($E), index: int) -> ^E {
|
||||||
@@ -202,7 +202,7 @@ test_ring_aos :: proc(t: ^testing.T) {
|
|||||||
defer destroy(&ring)
|
defer destroy(&ring)
|
||||||
|
|
||||||
for i in 1 ..= 5 {
|
for i in 1 ..= 5 {
|
||||||
append(&ring, i)
|
push(&ring, i)
|
||||||
log.debug("Length:", ring.len)
|
log.debug("Length:", ring.len)
|
||||||
log.debug("Start index:", start_index_aos(ring))
|
log.debug("Start index:", start_index_aos(ring))
|
||||||
log.debug("Next write index:", ring.next_write_index)
|
log.debug("Next write index:", ring.next_write_index)
|
||||||
@@ -215,7 +215,7 @@ test_ring_aos :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, start_index_aos(ring), 0)
|
testing.expect_value(t, start_index_aos(ring), 0)
|
||||||
|
|
||||||
for i in 6 ..= 15 {
|
for i in 6 ..= 15 {
|
||||||
append(&ring, i)
|
push(&ring, i)
|
||||||
log.debug("Length:", ring.len)
|
log.debug("Length:", ring.len)
|
||||||
log.debug("Start index:", start_index_aos(ring))
|
log.debug("Start index:", start_index_aos(ring))
|
||||||
log.debug("Next write index:", ring.next_write_index)
|
log.debug("Next write index:", ring.next_write_index)
|
||||||
@@ -230,7 +230,7 @@ test_ring_aos :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, start_index_aos(ring), 5)
|
testing.expect_value(t, start_index_aos(ring), 5)
|
||||||
|
|
||||||
for i in 15 ..= 25 {
|
for i in 15 ..= 25 {
|
||||||
append(&ring, i)
|
push(&ring, i)
|
||||||
log.debug("Length:", ring.len)
|
log.debug("Length:", ring.len)
|
||||||
log.debug("Start index:", start_index_aos(ring))
|
log.debug("Start index:", start_index_aos(ring))
|
||||||
log.debug("Next write index:", ring.next_write_index)
|
log.debug("Next write index:", ring.next_write_index)
|
||||||
@@ -241,7 +241,7 @@ test_ring_aos :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, get_last(ring)^, 25)
|
testing.expect_value(t, get_last(ring)^, 25)
|
||||||
|
|
||||||
clear(&ring)
|
clear(&ring)
|
||||||
append(&ring, 1)
|
push(&ring, 1)
|
||||||
testing.expect_value(t, ring.len, 1)
|
testing.expect_value(t, ring.len, 1)
|
||||||
testing.expect_value(t, get(ring, 0)^, 1)
|
testing.expect_value(t, get(ring, 0)^, 1)
|
||||||
}
|
}
|
||||||
@@ -256,7 +256,7 @@ test_ring_soa :: proc(t: ^testing.T) {
|
|||||||
defer destroy(&ring)
|
defer destroy(&ring)
|
||||||
|
|
||||||
for i in 1 ..= 5 {
|
for i in 1 ..= 5 {
|
||||||
append(&ring, Ints{i, i})
|
push(&ring, Ints{i, i})
|
||||||
log.debug("Length:", ring.len)
|
log.debug("Length:", ring.len)
|
||||||
log.debug("Start index:", start_index_soa(ring))
|
log.debug("Start index:", start_index_soa(ring))
|
||||||
log.debug("Next write index:", ring.next_write_index)
|
log.debug("Next write index:", ring.next_write_index)
|
||||||
@@ -269,7 +269,7 @@ test_ring_soa :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, start_index_soa(ring), 0)
|
testing.expect_value(t, start_index_soa(ring), 0)
|
||||||
|
|
||||||
for i in 6 ..= 15 {
|
for i in 6 ..= 15 {
|
||||||
append(&ring, Ints{i, i})
|
push(&ring, Ints{i, i})
|
||||||
log.debug("Length:", ring.len)
|
log.debug("Length:", ring.len)
|
||||||
log.debug("Start index:", start_index_soa(ring))
|
log.debug("Start index:", start_index_soa(ring))
|
||||||
log.debug("Next write index:", ring.next_write_index)
|
log.debug("Next write index:", ring.next_write_index)
|
||||||
@@ -284,7 +284,7 @@ test_ring_soa :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, start_index_soa(ring), 5)
|
testing.expect_value(t, start_index_soa(ring), 5)
|
||||||
|
|
||||||
for i in 15 ..= 25 {
|
for i in 15 ..= 25 {
|
||||||
append(&ring, Ints{i, i})
|
push(&ring, Ints{i, i})
|
||||||
log.debug("Length:", ring.len)
|
log.debug("Length:", ring.len)
|
||||||
log.debug("Start index:", start_index_soa(ring))
|
log.debug("Start index:", start_index_soa(ring))
|
||||||
log.debug("Next write index:", ring.next_write_index)
|
log.debug("Next write index:", ring.next_write_index)
|
||||||
@@ -295,7 +295,7 @@ test_ring_soa :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, get_last(ring), Ints{25, 25})
|
testing.expect_value(t, get_last(ring), Ints{25, 25})
|
||||||
|
|
||||||
clear(&ring)
|
clear(&ring)
|
||||||
append(&ring, Ints{1, 1})
|
push(&ring, Ints{1, 1})
|
||||||
testing.expect_value(t, ring.len, 1)
|
testing.expect_value(t, ring.len, 1)
|
||||||
testing.expect_value(t, get(ring, 0), Ints{1, 1})
|
testing.expect_value(t, get(ring, 0), Ints{1, 1})
|
||||||
}
|
}
|
||||||
@@ -314,7 +314,7 @@ test_ring_aos_init_from_slice :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, start_index_aos(ring), 0)
|
testing.expect_value(t, start_index_aos(ring), 0)
|
||||||
|
|
||||||
// Partial fill (3 / 7).
|
// Partial fill (3 / 7).
|
||||||
for i in 1 ..= 3 do append(&ring, i)
|
for i in 1 ..= 3 do push(&ring, i)
|
||||||
testing.expect_value(t, ring.len, 3)
|
testing.expect_value(t, ring.len, 3)
|
||||||
testing.expect_value(t, ring.next_write_index, 3)
|
testing.expect_value(t, ring.next_write_index, 3)
|
||||||
testing.expect_value(t, start_index_aos(ring), 0)
|
testing.expect_value(t, start_index_aos(ring), 0)
|
||||||
@@ -324,7 +324,7 @@ test_ring_aos_init_from_slice :: proc(t: ^testing.T) {
|
|||||||
|
|
||||||
// Fill exactly to capacity. Pushing element 7 must make len == cap
|
// Fill exactly to capacity. Pushing element 7 must make len == cap
|
||||||
// AND wrap next_write_index from 6 back to 0 in the same step.
|
// AND wrap next_write_index from 6 back to 0 in the same step.
|
||||||
for i in 4 ..= 7 do append(&ring, i)
|
for i in 4 ..= 7 do push(&ring, i)
|
||||||
testing.expect_value(t, ring.len, 7)
|
testing.expect_value(t, ring.len, 7)
|
||||||
testing.expect_value(t, ring.next_write_index, 0)
|
testing.expect_value(t, ring.next_write_index, 0)
|
||||||
testing.expect_value(t, start_index_aos(ring), 0)
|
testing.expect_value(t, start_index_aos(ring), 0)
|
||||||
@@ -333,7 +333,7 @@ test_ring_aos_init_from_slice :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, get_last(ring)^, 7)
|
testing.expect_value(t, get_last(ring)^, 7)
|
||||||
|
|
||||||
// First overwrite — oldest element shifts by one.
|
// First overwrite — oldest element shifts by one.
|
||||||
append(&ring, 8)
|
push(&ring, 8)
|
||||||
testing.expect_value(t, ring.len, 7)
|
testing.expect_value(t, ring.len, 7)
|
||||||
testing.expect_value(t, ring.next_write_index, 1)
|
testing.expect_value(t, ring.next_write_index, 1)
|
||||||
testing.expect_value(t, start_index_aos(ring), 1)
|
testing.expect_value(t, start_index_aos(ring), 1)
|
||||||
@@ -344,7 +344,7 @@ test_ring_aos_init_from_slice :: proc(t: ^testing.T) {
|
|||||||
// Stress: 3 more complete wrap cycles (21 more pushes).
|
// Stress: 3 more complete wrap cycles (21 more pushes).
|
||||||
// After 29 total pushes, ring contains the last 7 (23..=29),
|
// After 29 total pushes, ring contains the last 7 (23..=29),
|
||||||
// and next_write_index = 29 mod 7 = 1.
|
// and next_write_index = 29 mod 7 = 1.
|
||||||
for i in 9 ..= 29 do append(&ring, i)
|
for i in 9 ..= 29 do push(&ring, i)
|
||||||
testing.expect_value(t, ring.len, 7)
|
testing.expect_value(t, ring.len, 7)
|
||||||
testing.expect_value(t, ring.next_write_index, 1)
|
testing.expect_value(t, ring.next_write_index, 1)
|
||||||
testing.expect_value(t, start_index_aos(ring), 1)
|
testing.expect_value(t, start_index_aos(ring), 1)
|
||||||
@@ -360,7 +360,7 @@ test_ring_aos_init_from_slice :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, start_index_aos(ring), 0)
|
testing.expect_value(t, start_index_aos(ring), 0)
|
||||||
|
|
||||||
// Single-element edge case: get_last(len==1) routes through get(ring, 0).
|
// Single-element edge case: get_last(len==1) routes through get(ring, 0).
|
||||||
append(&ring, 42)
|
push(&ring, 42)
|
||||||
testing.expect_value(t, ring.len, 1)
|
testing.expect_value(t, ring.len, 1)
|
||||||
testing.expect_value(t, ring.next_write_index, 1)
|
testing.expect_value(t, ring.next_write_index, 1)
|
||||||
testing.expect_value(t, get(ring, 0)^, 42)
|
testing.expect_value(t, get(ring, 0)^, 42)
|
||||||
@@ -385,7 +385,7 @@ test_ring_soa_init_from_slice :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, start_index_soa(ring), 0)
|
testing.expect_value(t, start_index_soa(ring), 0)
|
||||||
|
|
||||||
// Partial fill (3 / 7).
|
// Partial fill (3 / 7).
|
||||||
for i in 1 ..= 3 do append(&ring, Ints{i, i})
|
for i in 1 ..= 3 do push(&ring, Ints{i, i})
|
||||||
testing.expect_value(t, ring.len, 3)
|
testing.expect_value(t, ring.len, 3)
|
||||||
testing.expect_value(t, ring.next_write_index, 3)
|
testing.expect_value(t, ring.next_write_index, 3)
|
||||||
testing.expect_value(t, start_index_soa(ring), 0)
|
testing.expect_value(t, start_index_soa(ring), 0)
|
||||||
@@ -395,7 +395,7 @@ test_ring_soa_init_from_slice :: proc(t: ^testing.T) {
|
|||||||
|
|
||||||
// Fill exactly to capacity. Pushing element 7 must make len == cap
|
// Fill exactly to capacity. Pushing element 7 must make len == cap
|
||||||
// AND wrap next_write_index from 6 back to 0 in the same step.
|
// AND wrap next_write_index from 6 back to 0 in the same step.
|
||||||
for i in 4 ..= 7 do append(&ring, Ints{i, i})
|
for i in 4 ..= 7 do push(&ring, Ints{i, i})
|
||||||
testing.expect_value(t, ring.len, 7)
|
testing.expect_value(t, ring.len, 7)
|
||||||
testing.expect_value(t, ring.next_write_index, 0)
|
testing.expect_value(t, ring.next_write_index, 0)
|
||||||
testing.expect_value(t, start_index_soa(ring), 0)
|
testing.expect_value(t, start_index_soa(ring), 0)
|
||||||
@@ -404,7 +404,7 @@ test_ring_soa_init_from_slice :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, get_last(ring), Ints{7, 7})
|
testing.expect_value(t, get_last(ring), Ints{7, 7})
|
||||||
|
|
||||||
// First overwrite — oldest element shifts by one.
|
// First overwrite — oldest element shifts by one.
|
||||||
append(&ring, Ints{8, 8})
|
push(&ring, Ints{8, 8})
|
||||||
testing.expect_value(t, ring.len, 7)
|
testing.expect_value(t, ring.len, 7)
|
||||||
testing.expect_value(t, ring.next_write_index, 1)
|
testing.expect_value(t, ring.next_write_index, 1)
|
||||||
testing.expect_value(t, start_index_soa(ring), 1)
|
testing.expect_value(t, start_index_soa(ring), 1)
|
||||||
@@ -415,7 +415,7 @@ test_ring_soa_init_from_slice :: proc(t: ^testing.T) {
|
|||||||
// Stress: 3 more complete wrap cycles (21 more pushes).
|
// Stress: 3 more complete wrap cycles (21 more pushes).
|
||||||
// After 29 total pushes, ring contains the last 7 (23..=29),
|
// After 29 total pushes, ring contains the last 7 (23..=29),
|
||||||
// and next_write_index = 29 mod 7 = 1.
|
// and next_write_index = 29 mod 7 = 1.
|
||||||
for i in 9 ..= 29 do append(&ring, Ints{i, i})
|
for i in 9 ..= 29 do push(&ring, Ints{i, i})
|
||||||
testing.expect_value(t, ring.len, 7)
|
testing.expect_value(t, ring.len, 7)
|
||||||
testing.expect_value(t, ring.next_write_index, 1)
|
testing.expect_value(t, ring.next_write_index, 1)
|
||||||
testing.expect_value(t, start_index_soa(ring), 1)
|
testing.expect_value(t, start_index_soa(ring), 1)
|
||||||
@@ -431,7 +431,7 @@ test_ring_soa_init_from_slice :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, start_index_soa(ring), 0)
|
testing.expect_value(t, start_index_soa(ring), 0)
|
||||||
|
|
||||||
// Single-element edge case: get_last(len==1) routes through get(ring, 0).
|
// Single-element edge case: get_last(len==1) routes through get(ring, 0).
|
||||||
append(&ring, Ints{42, 42})
|
push(&ring, Ints{42, 42})
|
||||||
testing.expect_value(t, ring.len, 1)
|
testing.expect_value(t, ring.len, 1)
|
||||||
testing.expect_value(t, ring.next_write_index, 1)
|
testing.expect_value(t, ring.next_write_index, 1)
|
||||||
testing.expect_value(t, get(ring, 0), Ints{42, 42})
|
testing.expect_value(t, get(ring, 0), Ints{42, 42})
|
||||||
|
|||||||
Vendored
+617
-41
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user