From 395aa7d1c312e495517701be11c21425d9a5838e Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 26 Oct 2025 17:25:13 -0700 Subject: Checkpoint --- .../src/commonMain/kotlin/coffee/liz/ecs/Vec.kt | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 composeApp/src/commonMain/kotlin/coffee/liz/ecs/Vec.kt (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/ecs/Vec.kt') 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 -- cgit v1.2.3-70-g09d2