summaryrefslogtreecommitdiff
path: root/composeApp/src/commonMain/kotlin/coffee/liz/ecs/Vec.kt
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2025-10-26 17:25:13 -0700
committerElizabeth Hunt <me@liz.coffee>2025-10-26 17:25:13 -0700
commit395aa7d1c312e495517701be11c21425d9a5838e (patch)
tree4ad184b082838c56149cc1d1efe191cfd3d0679b /composeApp/src/commonMain/kotlin/coffee/liz/ecs/Vec.kt
parent64f825465de9fa30c4dfe2707067efdb96110db8 (diff)
downloadabstraction-engine-kt-395aa7d1c312e495517701be11c21425d9a5838e.tar.gz
abstraction-engine-kt-395aa7d1c312e495517701be11c21425d9a5838e.zip
Checkpoint
Diffstat (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/ecs/Vec.kt')
-rw-r--r--composeApp/src/commonMain/kotlin/coffee/liz/ecs/Vec.kt33
1 files changed, 33 insertions, 0 deletions
diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/Vec.kt b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/Vec.kt
new file mode 100644
index 0000000..0b771e4
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/Vec.kt
@@ -0,0 +1,33 @@
+package coffee.liz.ecs
+
+/**
+ * Rectangle in cartesian space.
+ */
+data class Rect(
+ val topLeft: Vec2,
+ val dimensions: Vec2
+) {
+ fun overlaps(other: Rect): Boolean {
+ val xOverlap = topLeft.x <= other.topLeft.x + other.dimensions.x &&
+ topLeft.x + dimensions.x >= other.topLeft.x
+ val yOverlap = topLeft.y <= other.topLeft.y + other.dimensions.y &&
+ topLeft.y + dimensions.y >= other.topLeft.y
+ return xOverlap && yOverlap
+ }
+}
+
+/**
+ * Cartesian point.
+ */
+data class Vec2(
+ val x: Float,
+ val y: Float
+) {
+ fun plus(other: Vec2): Vec2 = Vec2(x + other.x, y + other.y)
+ fun minus(other: Vec2): Vec2 = Vec2(x - other.x, y - other.y)
+ fun times(scalar: Float): Vec2 = Vec2(x * scalar, y * scalar)
+ fun div(scalar: Float): Vec2 = Vec2(x / scalar, y / scalar)
+ fun distanceTo(other: Vec2): Float = (this.minus(other)).length()
+ fun normalize(): Vec2 = this.div(length())
+ fun length(): Float = kotlin.math.sqrt(x * x + y * y)
+} \ No newline at end of file