diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-06-17 20:59:45 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-06-17 21:19:43 +0200 |
| commit | 4b9e966ca7e8a9291f307850f715820e122d69fd (patch) | |
| tree | 94b08c865c882f93ff9c0c6aa7a507d47bcc67bf /src/main/kotlin/util/math | |
| parent | 775933d516db10dbcc1cbbe405defa7b6e0c5a6a (diff) | |
| download | Firmament-4b9e966ca7e8a9291f307850f715820e122d69fd.tar.gz Firmament-4b9e966ca7e8a9291f307850f715820e122d69fd.tar.bz2 Firmament-4b9e966ca7e8a9291f307850f715820e122d69fd.zip | |
feat: Add macro wheels
Diffstat (limited to 'src/main/kotlin/util/math')
| -rw-r--r-- | src/main/kotlin/util/math/Projections.kt | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main/kotlin/util/math/Projections.kt b/src/main/kotlin/util/math/Projections.kt new file mode 100644 index 0000000..359b21b --- /dev/null +++ b/src/main/kotlin/util/math/Projections.kt @@ -0,0 +1,46 @@ +package moe.nea.firmament.util.math + +import kotlin.math.absoluteValue +import kotlin.math.cos +import kotlin.math.sin +import net.minecraft.util.math.Vec2f +import moe.nea.firmament.util.render.wrapAngle + +object Projections { + object Two { + val ε = 1e-6 + val π = moe.nea.firmament.util.render.π + val τ = 2 * π + + fun isNullish(float: Float) = float.absoluteValue < ε + + fun xInterceptOfLine(origin: Vec2f, direction: Vec2f): Vec2f? { + if (isNullish(direction.x)) + return Vec2f(origin.x, 0F) + if (isNullish(direction.y)) + return null + + val slope = direction.y / direction.x + return Vec2f(origin.x - origin.y / slope, 0F) + } + + fun interceptAlongCardinal(distanceFromAxis: Float, slope: Float): Float? { + if (isNullish(slope)) + return null + return -distanceFromAxis / slope + } + + fun projectAngleOntoUnitBox(angleRadians: Double): Vec2f { + val angleRadians = wrapAngle(angleRadians) + val cx = cos(angleRadians) + val cy = sin(angleRadians) + + val ex = 1 / cx.absoluteValue + val ey = 1 / cy.absoluteValue + + val e = minOf(ex, ey) + + return Vec2f((cx * e).toFloat(), (cy * e).toFloat()) + } + } +} |
