@flare-engine/physics 0.4.17 → 0.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -0
- package/dist/index.d.mts +142 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +142 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +769 -212
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +759 -213
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/collider.ts","../src/raycast.ts","../src/shape.ts","../src/spatial-index.ts","../src/collision-world.ts","../src/solid-grid.ts"],"sourcesContent":["import type { Shape } from './shape.js';\n\n/** Collider component data attached to an ECS entity. */\nexport interface Collider {\n /** The collision shape. */\n shape: Shape;\n /** If true, generates trigger events but no physical response. */\n isTrigger: boolean;\n /** Collision layer bitmask — which layer this collider belongs to. */\n layer: number;\n /** Collision mask — which layers this collider can interact with. */\n mask: number;\n}\n\n/** Create a collider with default settings. */\nexport function createCollider(shape: Shape, opts?: Partial<Omit<Collider, 'shape'>>): Collider {\n return {\n shape,\n isTrigger: opts?.isTrigger ?? false,\n layer: opts?.layer ?? 1,\n mask: opts?.mask ?? 0xffffffff,\n };\n}\n","import type { Vec2 } from '@flare-engine/math';\nimport type { Shape } from './shape.js';\n\n/** Result of a raycast hit. */\nexport interface RaycastHit {\n /** The entity that was hit. */\n entity: number;\n /** Distance from ray origin to hit point. */\n distance: number;\n /** World-space hit point. */\n point: Vec2;\n /** Surface normal at hit point. */\n normal: Vec2;\n}\n\n/** Entity entry for raycast — position + shape. */\nexport interface RaycastTarget {\n entity: number;\n shape: Shape;\n x: number;\n y: number;\n}\n\n/** Scratch record `raycast()` hands to `rayVsShapeInto` per candidate. */\nconst scratchHit: RaycastHit = {\n entity: -1,\n distance: 0,\n point: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n};\n\n/**\n * Cast a ray against a list of targets. Returns the closest hit, or null.\n *\n * The returned hit is a fresh object — the caller may keep it; later calls do\n * not overwrite it. Among targets at equal distance the first in `targets` wins.\n * @param ox Ray origin X\n * @param oy Ray origin Y\n * @param dx Ray direction X (should be normalized)\n * @param dy Ray direction Y (should be normalized)\n * @param maxDist Maximum raycast distance\n * @param targets Array of entities to test against\n */\nexport function raycast(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n targets: readonly RaycastTarget[],\n): RaycastHit | null {\n // Every later hit overwrites the scratch, so the best candidate so far is\n // held in locals and only the winner becomes an object.\n let found = false;\n let entity = -1;\n let distance = 0;\n let px = 0;\n let py = 0;\n let nx = 0;\n let ny = 0;\n\n for (let i = 0; i < targets.length; i++) {\n const t = targets[i]!;\n const hit = rayVsShapeInto(ox, oy, dx, dy, maxDist, t.entity, t.shape, t.x, t.y, scratchHit);\n if (hit !== null && (!found || hit.distance < distance)) {\n found = true;\n entity = hit.entity;\n distance = hit.distance;\n px = hit.point.x;\n py = hit.point.y;\n nx = hit.normal.x;\n ny = hit.normal.y;\n }\n }\n\n if (!found) return null;\n return { entity, distance, point: { x: px, y: py }, normal: { x: nx, y: ny } };\n}\n\n/**\n * Zero-alloc ray-vs-shape test: writes into `out` and returns it, or returns\n * `null` without touching `out`.\n *\n * This is the single implementation of the ray math. `raycast()` above and\n * `CollisionWorld.raycast` both run every candidate through it into a scratch\n * record, so neither allocates per candidate tested.\n */\nexport function rayVsShapeInto(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n shape: Shape,\n x: number,\n y: number,\n out: RaycastHit,\n): RaycastHit | null {\n if (shape.type === 'aabb') {\n return rayVsAABBInto(ox, oy, dx, dy, maxDist, entity, x, y, shape.hw, shape.hh, out);\n }\n return rayVsCircleInto(ox, oy, dx, dy, maxDist, entity, x, y, shape.radius, out);\n}\n\nfunction rayVsAABBInto(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n bx: number,\n by: number,\n hw: number,\n hh: number,\n out: RaycastHit,\n): RaycastHit | null {\n if (dx === 0 && dy === 0) return null;\n\n // A ray parallel to an axis never crosses that slab's planes: it is inside\n // the slab for all t or for none. Scaling by an infinite inverse instead\n // gives 0 * Infinity = NaN when the origin sits exactly on a plane.\n let tMinX = Number.NEGATIVE_INFINITY;\n let tMaxX = Number.POSITIVE_INFINITY;\n if (dx === 0) {\n if (ox < bx - hw || ox > bx + hw) return null;\n } else {\n const invDx = 1 / dx;\n const tx1 = (bx - hw - ox) * invDx;\n const tx2 = (bx + hw - ox) * invDx;\n tMinX = Math.min(tx1, tx2);\n tMaxX = Math.max(tx1, tx2);\n }\n\n let tMinY = Number.NEGATIVE_INFINITY;\n let tMaxY = Number.POSITIVE_INFINITY;\n if (dy === 0) {\n if (oy < by - hh || oy > by + hh) return null;\n } else {\n const invDy = 1 / dy;\n const ty1 = (by - hh - oy) * invDy;\n const ty2 = (by + hh - oy) * invDy;\n tMinY = Math.min(ty1, ty2);\n tMaxY = Math.max(ty1, ty2);\n }\n\n const tMin = Math.max(tMinX, tMinY);\n const tMax = Math.min(tMaxX, tMaxY);\n if (tMax < 0 || tMin > tMax) return null;\n\n const t = tMin < 0 ? tMax : tMin;\n if (t > maxDist || t < 0) return null;\n\n out.entity = entity;\n out.distance = t;\n out.point.x = ox + dx * t;\n out.point.y = oy + dy * t;\n if (tMinX > tMinY) {\n out.normal.x = dx < 0 ? 1 : -1;\n out.normal.y = 0;\n } else {\n out.normal.x = 0;\n out.normal.y = dy < 0 ? 1 : -1;\n }\n return out;\n}\n\nfunction rayVsCircleInto(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n cx: number,\n cy: number,\n radius: number,\n out: RaycastHit,\n): RaycastHit | null {\n const fx = ox - cx;\n const fy = oy - cy;\n const a = dx * dx + dy * dy;\n if (a < 1e-12) return null; // Zero-length direction\n\n const b = 2 * (fx * dx + fy * dy);\n const c = fx * fx + fy * fy - radius * radius;\n const discriminant = b * b - 4 * a * c;\n if (discriminant < 0) return null;\n\n const sqrtDisc = Math.sqrt(discriminant);\n let t = (-b - sqrtDisc) / (2 * a);\n // If the entry point is behind the origin, try the exit point.\n if (t < 0) t = (-b + sqrtDisc) / (2 * a);\n if (t < 0 || t > maxDist) return null;\n\n const px = ox + dx * t;\n const py = oy + dy * t;\n const nx = px - cx;\n const ny = py - cy;\n const len = Math.sqrt(nx * nx + ny * ny);\n\n out.entity = entity;\n out.distance = t;\n out.point.x = px;\n out.point.y = py;\n out.normal.x = len > 0 ? nx / len : 0;\n out.normal.y = len > 0 ? ny / len : 0;\n return out;\n}\n","import type { Rect } from '@flare-engine/math';\n\n/** AABB shape — axis-aligned bounding box. */\nexport interface AABBShape {\n readonly type: 'aabb';\n /** Half-width. */\n readonly hw: number;\n /** Half-height. */\n readonly hh: number;\n}\n\n/** Circle shape. */\nexport interface CircleShape {\n readonly type: 'circle';\n readonly radius: number;\n}\n\n/** Union of supported physics shapes. */\nexport type Shape = AABBShape | CircleShape;\n\n/** Create an AABB shape from width and height. */\nexport function AABB(width: number, height: number): AABBShape {\n return { type: 'aabb', hw: width * 0.5, hh: height * 0.5 };\n}\n\n/** Create a circle shape from radius. */\nexport function CircleShape(radius: number): CircleShape {\n return { type: 'circle', radius };\n}\n\n/** Compute the bounding rect of a shape at a given position. */\nexport function shapeBounds(shape: Shape, x: number, y: number): Rect {\n if (shape.type === 'aabb') {\n return { x: x - shape.hw, y: y - shape.hh, width: shape.hw * 2, height: shape.hh * 2 };\n }\n return {\n x: x - shape.radius,\n y: y - shape.radius,\n width: shape.radius * 2,\n height: shape.radius * 2,\n };\n}\n\n/** Zero-alloc variant — writes the shape bounds into the provided output rect. */\nexport function shapeBoundsInto(shape: Shape, x: number, y: number, out: Rect): Rect {\n if (shape.type === 'aabb') {\n out.x = x - shape.hw;\n out.y = y - shape.hh;\n out.width = shape.hw * 2;\n out.height = shape.hh * 2;\n return out;\n }\n out.x = x - shape.radius;\n out.y = y - shape.radius;\n out.width = shape.radius * 2;\n out.height = shape.radius * 2;\n return out;\n}\n\n/** Test overlap between two positioned shapes. Returns true if overlapping. */\nexport function shapeOverlap(\n shapeA: Shape,\n ax: number,\n ay: number,\n shapeB: Shape,\n bx: number,\n by: number,\n): boolean {\n if (shapeA.type === 'aabb' && shapeB.type === 'aabb') {\n return aabbVsAabb(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.hw, shapeB.hh);\n }\n if (shapeA.type === 'circle' && shapeB.type === 'circle') {\n return circleVsCircle(ax, ay, shapeA.radius, bx, by, shapeB.radius);\n }\n // Mixed: one AABB, one circle\n if (shapeA.type === 'aabb' && shapeB.type === 'circle') {\n return aabbVsCircle(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.radius);\n }\n return aabbVsCircle(\n bx,\n by,\n (shapeB as AABBShape).hw,\n (shapeB as AABBShape).hh,\n ax,\n ay,\n (shapeA as CircleShape).radius,\n );\n}\n\nfunction aabbVsAabb(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n bx: number,\n by: number,\n bhw: number,\n bhh: number,\n): boolean {\n return Math.abs(ax - bx) < ahw + bhw && Math.abs(ay - by) < ahh + bhh;\n}\n\nfunction circleVsCircle(\n ax: number,\n ay: number,\n ar: number,\n bx: number,\n by: number,\n br: number,\n): boolean {\n const dx = bx - ax;\n const dy = by - ay;\n const radSum = ar + br;\n return dx * dx + dy * dy < radSum * radSum;\n}\n\nfunction aabbVsCircle(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n cx: number,\n cy: number,\n cr: number,\n): boolean {\n const left = ax - ahw;\n const right = ax + ahw;\n const top = ay - ahh;\n const bottom = ay + ahh;\n const closestX = cx < left ? left : cx > right ? right : cx;\n const closestY = cy < top ? top : cy > bottom ? bottom : cy;\n const dx = cx - closestX;\n const dy = cy - closestY;\n const distSq = dx * dx + dy * dy;\n // Strict, like aabbVsAabb and circleVsCircle: exactly-touching shapes do not\n // collide. A centre on or inside the box collides when the radius is positive;\n // a zero radius counts only strictly inside, as a zero-size box does.\n if (distSq > 0) return distSq < cr * cr;\n return cr > 0 || (cx > left && cx < right && cy > top && cy < bottom);\n}\n\n/**\n * Minimum translation vector: the shortest push that separates two overlapping\n * shapes.\n *\n * `shapeOverlap` answers *whether* two shapes collide and nothing more, which\n * leaves a detection-only consumer with no way to resolve the collision. This is\n * that missing step: `out.x`/`out.y` are a unit axis and `out.depth` is how far\n * along it `b` must move to just stop touching `a`.\n *\n * Returns `null` when the shapes are not overlapping, leaving `out` untouched so\n * a caller may reuse one buffer across many pairs.\n *\n * The degenerate concentric case (identical centres) has no meaningful axis;\n * `(1, 0)` is returned so the caller still gets a usable separation instead of\n * `NaN` from normalising a zero vector.\n */\nexport interface Overlap {\n /** Unit separation axis, pointing from `a` toward `b`. */\n x: number;\n y: number;\n /** Penetration depth along that axis. */\n depth: number;\n}\n\n/** A fresh, zeroed overlap record. Allocate once outside the loop and reuse. */\nexport function createOverlap(): Overlap {\n return { x: 0, y: 0, depth: 0 };\n}\n\nexport function overlapInto(\n shapeA: Shape,\n ax: number,\n ay: number,\n shapeB: Shape,\n bx: number,\n by: number,\n out: Overlap,\n): Overlap | null {\n if (shapeA.type === 'aabb' && shapeB.type === 'aabb') {\n return aabbAabbOverlap(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.hw, shapeB.hh, out);\n }\n if (shapeA.type === 'circle' && shapeB.type === 'circle') {\n return circleCircleOverlap(ax, ay, shapeA.radius, bx, by, shapeB.radius, out);\n }\n if (shapeA.type === 'aabb' && shapeB.type === 'circle') {\n return aabbCircleOverlap(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.radius, out, false);\n }\n // Circle vs AABB — solve as AABB vs circle, then flip the axis so it still\n // points from `a` to `b`.\n return aabbCircleOverlap(\n bx,\n by,\n (shapeB as AABBShape).hw,\n (shapeB as AABBShape).hh,\n ax,\n ay,\n (shapeA as CircleShape).radius,\n out,\n true,\n );\n}\n\n/** Minimum translation vector. Allocates — see `overlapInto` for the hot path. */\nexport function overlap(\n shapeA: Shape,\n ax: number,\n ay: number,\n shapeB: Shape,\n bx: number,\n by: number,\n): Overlap | null {\n return overlapInto(shapeA, ax, ay, shapeB, bx, by, createOverlap());\n}\n\nfunction aabbAabbOverlap(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n bx: number,\n by: number,\n bhw: number,\n bhh: number,\n out: Overlap,\n): Overlap | null {\n const dx = bx - ax;\n const dy = by - ay;\n const overlapX = ahw + bhw - Math.abs(dx);\n if (overlapX <= 0) return null;\n const overlapY = ahh + bhh - Math.abs(dy);\n if (overlapY <= 0) return null;\n\n // The minimum translation is along whichever axis is least penetrated.\n if (overlapX < overlapY) {\n out.x = dx < 0 ? -1 : 1;\n out.y = 0;\n out.depth = overlapX;\n } else {\n out.x = 0;\n out.y = dy < 0 ? -1 : 1;\n out.depth = overlapY;\n }\n return out;\n}\n\nfunction circleCircleOverlap(\n ax: number,\n ay: number,\n ar: number,\n bx: number,\n by: number,\n br: number,\n out: Overlap,\n): Overlap | null {\n const dx = bx - ax;\n const dy = by - ay;\n const radSum = ar + br;\n const distSq = dx * dx + dy * dy;\n if (distSq >= radSum * radSum) return null;\n\n const dist = Math.sqrt(distSq);\n if (dist === 0) {\n // Concentric: no meaningful axis, so pick one rather than divide by zero.\n out.x = 1;\n out.y = 0;\n out.depth = radSum;\n return out;\n }\n out.x = dx / dist;\n out.y = dy / dist;\n out.depth = radSum - dist;\n return out;\n}\n\nfunction aabbCircleOverlap(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n cx: number,\n cy: number,\n cr: number,\n out: Overlap,\n flip: boolean,\n): Overlap | null {\n const left = ax - ahw;\n const right = ax + ahw;\n const top = ay - ahh;\n const bottom = ay + ahh;\n const closestX = cx < left ? left : cx > right ? right : cx;\n const closestY = cy < top ? top : cy > bottom ? bottom : cy;\n const dx = cx - closestX;\n const dy = cy - closestY;\n const distSq = dx * dx + dy * dy;\n\n if (distSq > 0) {\n // Centre outside the box: separate along the closest-point normal.\n if (distSq >= cr * cr) return null;\n const dist = Math.sqrt(distSq);\n const nx = dx / dist;\n const ny = dy / dist;\n out.x = flip ? -nx : nx;\n out.y = flip ? -ny : ny;\n out.depth = cr - dist;\n return out;\n }\n\n // Centre inside the box: push out through the nearest face.\n const toLeft = cx - left;\n const toRight = right - cx;\n const toTop = cy - top;\n const toBottom = bottom - cy;\n let nx = -1;\n let ny = 0;\n let depth = toLeft;\n if (toRight < depth) {\n nx = 1;\n ny = 0;\n depth = toRight;\n }\n if (toTop < depth) {\n nx = 0;\n ny = -1;\n depth = toTop;\n }\n if (toBottom < depth) {\n nx = 0;\n ny = 1;\n depth = toBottom;\n }\n // Zero radius on the boundary is exactly touching, not overlapping.\n if (depth + cr <= 0) return null;\n out.x = flip ? -nx : nx;\n out.y = flip ? -ny : ny;\n out.depth = depth + cr;\n return out;\n}\n","import type { Rect } from '@flare-engine/math';\n\n// Internal entry: bounding rect (minX, minY, maxX, maxY) plus a per-query stamp\n// for zero-alloc dedup.\ninterface _Entry<T> {\n readonly item: T;\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n _stamp: number;\n}\n\n// Uniform grid cell size in world units. Tuned for typical game-object sizes (16–64 px).\nconst CELL = 64;\n\n// Packed cell-key encoding. Supports cell coords in [-32768, 32767],\n// i.e. world coordinates ±2 097 152. All keys fit within Number.MAX_SAFE_INTEGER.\nconst KEY_RANGE = 65536; // 2^16\nconst KEY_OFFSET = 32768; // 2^15\n\nfunction _key(cx: number, cy: number): number {\n return (cx + KEY_OFFSET) * KEY_RANGE + (cy + KEY_OFFSET);\n}\n\n// Inclusive min cell that contains world coordinate v.\nfunction _cMin(v: number): number {\n return Math.floor(v / CELL);\n}\n\n// Inclusive max cell that contains world coordinate v (exclusive-end: a coord\n// falling exactly on a cell boundary is NOT part of the adjacent cell — matches\n// the strict-inequality overlap semantics of query()).\nfunction _cMax(v: number): number {\n return Math.ceil(v / CELL) - 1;\n}\n\n// Supported cell-coordinate range for the packed key above.\nconst MIN_CELL = -KEY_OFFSET;\nconst MAX_CELL = KEY_OFFSET - 1;\n\n// Bounds a derived cell coordinate to the packed-key range. Without this, a\n// non-finite world coordinate (±Infinity — an unbounded raycast maxDist, or an\n// entity parked at Infinity) makes cxMin/cxMax/cyMin/cyMax infinite, and\n// `for (cx = cxMin; cx <= cxMax; cx++)` never exits: once cx itself is\n// Infinity, `cx <= Infinity` stays true and `cx++` is a no-op, so the loop\n// spins forever pushing/reading the same bucket (unbounded memory growth on\n// the link side). NaN is left untouched: every comparison against NaN is\n// false, so the loop already runs zero times, which is the existing (safe)\n// behaviour for a degenerate direction like `0 * Infinity`.\nfunction _clampCell(c: number): number {\n if (c > MAX_CELL) return MAX_CELL;\n if (c < MIN_CELL) return MIN_CELL;\n return c;\n}\n\n/**\n * Uniform spatial-hash broadphase.\n * `insert`, `remove`, and `update` are O(cells touched) — O(1) for typical entities.\n * `query` walks only the cells overlapping the given rect; result order is unspecified.\n * Zero-alloc in the query hot-path: duplicate suppression uses a monotone stamp counter,\n * not a per-call Set.\n */\nexport class SpatialIndex<T> {\n private _data: _Entry<T>[] = [];\n private _slots = new Map<T, number>(); // item → dense-array slot\n private _cells = new Map<number, _Entry<T>[]>(); // packed cell key → bucket\n private _gen = 0; // monotone query-generation counter\n\n /** Number of items in the index. */\n get size(): number {\n return this._data.length;\n }\n\n /**\n * Insert an item with a bounding rect. Inserting an item already in the index\n * replaces its bounds (upsert) — same as `update`.\n */\n insert(item: T, bounds: Rect): void {\n if (this._slots.has(item)) {\n this.update(item, bounds);\n return;\n }\n const entry: _Entry<T> = {\n item,\n minX: bounds.x,\n minY: bounds.y,\n maxX: bounds.x + bounds.width,\n maxY: bounds.y + bounds.height,\n _stamp: 0,\n };\n this._slots.set(item, this._data.length);\n this._data.push(entry);\n this._link(entry);\n }\n\n /** Remove an item. Returns false when the item was not present. */\n remove(item: T): boolean {\n const slot = this._slots.get(item);\n if (slot === undefined) return false;\n const entry = this._data[slot]!;\n this._unlink(entry);\n this._slots.delete(item);\n // Swap-remove: plug the hole with the last element.\n const last = this._data.pop()!;\n if (slot < this._data.length) {\n this._data[slot] = last;\n this._slots.set(last.item, slot);\n }\n return true;\n }\n\n /** Update the bounds for an existing item. No-op when the item is absent. */\n update(item: T, bounds: Rect): void {\n const slot = this._slots.get(item);\n if (slot === undefined) return;\n const entry = this._data[slot]!;\n this._unlink(entry);\n entry.minX = bounds.x;\n entry.minY = bounds.y;\n entry.maxX = bounds.x + bounds.width;\n entry.maxY = bounds.y + bounds.height;\n this._link(entry);\n }\n\n /**\n * Query all items whose bounds overlap the given rect.\n * Result order is unspecified. Appends to `result` when provided and returns it.\n */\n query(bounds: Rect, result?: T[]): T[] {\n const out = result ?? [];\n const gen = ++this._gen;\n\n const qMinX = bounds.x;\n const qMinY = bounds.y;\n const qMaxX = bounds.x + bounds.width;\n const qMaxY = bounds.y + bounds.height;\n\n const cxMin = _clampCell(_cMin(qMinX));\n const cxMax = _clampCell(_cMax(qMaxX));\n const cyMin = _clampCell(_cMin(qMinY));\n const cyMax = _clampCell(_cMax(qMaxY));\n\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const bucket = this._cells.get(_key(cx, cy));\n if (bucket === undefined) continue;\n for (let i = 0; i < bucket.length; i++) {\n const e = bucket[i]!;\n if (e._stamp === gen) continue; // already emitted this query\n e._stamp = gen;\n if (e.maxX > qMinX && e.minX < qMaxX && e.maxY > qMinY && e.minY < qMaxY) {\n out.push(e.item);\n }\n }\n }\n }\n return out;\n }\n\n /** Remove all items. */\n clear(): void {\n this._data.length = 0;\n this._slots.clear();\n this._cells.clear();\n }\n\n // Register entry in all grid cells it overlaps.\n private _link(entry: _Entry<T>): void {\n const cxMin = _clampCell(_cMin(entry.minX));\n const cxMax = _clampCell(_cMax(entry.maxX));\n const cyMin = _clampCell(_cMin(entry.minY));\n const cyMax = _clampCell(_cMax(entry.maxY));\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const k = _key(cx, cy);\n let b = this._cells.get(k);\n if (b === undefined) {\n b = [];\n this._cells.set(k, b);\n }\n b.push(entry);\n }\n }\n }\n\n // Remove entry from all grid cells it currently occupies.\n private _unlink(entry: _Entry<T>): void {\n const cxMin = _clampCell(_cMin(entry.minX));\n const cxMax = _clampCell(_cMax(entry.maxX));\n const cyMin = _clampCell(_cMin(entry.minY));\n const cyMax = _clampCell(_cMax(entry.maxY));\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const b = this._cells.get(_key(cx, cy));\n if (b === undefined) continue;\n const i = b.indexOf(entry);\n if (i !== -1) {\n // Swap-remove within the bucket.\n const last = b.pop()!;\n if (i < b.length) b[i] = last;\n }\n }\n }\n }\n}\n","import { Signal } from '@flare-engine/events';\nimport type { Rect } from '@flare-engine/math';\nimport type { Collider } from './collider.js';\nimport type { RaycastHit } from './raycast.js';\nimport { rayVsShapeInto } from './raycast.js';\nimport type { Shape } from './shape.js';\nimport { shapeBoundsInto, shapeOverlap } from './shape.js';\nimport { SpatialIndex } from './spatial-index.js';\n\n/** Collision pair data emitted by collision signals. */\nexport interface CollisionPair {\n readonly entityA: number;\n readonly entityB: number;\n}\n\n/** Per-entity collision data stored in the world. */\ninterface CollisionEntry {\n entity: number;\n shape: Shape;\n x: number;\n y: number;\n isTrigger: boolean;\n layer: number;\n mask: number;\n}\n\n// Packed pair-key layout: `lo * ENTITY_SHIFT + hi`, lo = min(a,b), hi = max(a,b).\n// 2^26 fits within Number.MAX_SAFE_INTEGER for 26+26 bits → max entity id ~67M.\nconst ENTITY_SHIFT = 2 ** 26;\n\n/** Padding applied to a ray's query AABB — see `CollisionWorld.raycast`. */\nconst RAY_BOUNDS_PAD = 1e-6;\n\nfunction encodePair(a: number, b: number): number {\n const lo = a < b ? a : b;\n const hi = a < b ? b : a;\n return lo * ENTITY_SHIFT + hi;\n}\n\nfunction decodeLo(key: number): number {\n return Math.floor(key / ENTITY_SHIFT);\n}\n\nfunction decodeHi(key: number): number {\n return key - Math.floor(key / ENTITY_SHIFT) * ENTITY_SHIFT;\n}\n\n/**\n * AABB collision world. Manages entities with shapes, detects overlaps each step,\n * and emits collision/trigger signals.\n */\nexport class CollisionWorld {\n readonly onCollisionStart = new Signal<CollisionPair>();\n readonly onCollisionEnd = new Signal<CollisionPair>();\n readonly onTriggerEnter = new Signal<CollisionPair>();\n readonly onTriggerExit = new Signal<CollisionPair>();\n\n private entries = new Map<number, CollisionEntry>();\n private spatial = new SpatialIndex<number>();\n /**\n * Two pre-allocated pair buffers — swapped each step (no per-frame allocation).\n * Keys are packed numbers via `encodePair(a, b)`.\n */\n private pairBufA = new Set<number>();\n private pairBufB = new Set<number>();\n private activePairs: Set<number> = this.pairBufA;\n /** Reusable query result buffer. */\n private queryBuf: number[] = [];\n /** Reusable bounds rect — avoids per-entity Rect allocation in step(). */\n private boundsBuf: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n /**\n * Add an entity with a shape. Positional twin of `addCollider`, and re-adding\n * follows the same rules.\n */\n add(\n entity: number,\n shape: Shape,\n x: number,\n y: number,\n isTrigger = false,\n layer = 1,\n mask = 0xffffffff,\n ): void {\n const entry: CollisionEntry = { entity, shape, x, y, isTrigger, layer, mask };\n const previous = this.entries.get(entity);\n this.entries.set(entity, entry);\n shapeBoundsInto(shape, x, y, this.boundsBuf);\n if (previous === undefined) {\n this.spatial.insert(entity, this.boundsBuf);\n return;\n }\n this.spatial.update(entity, this.boundsBuf);\n if (previous.isTrigger === isTrigger) return;\n\n // A pair is a trigger pair when either side is a trigger, so flipping this\n // side changes the kind only of pairs whose other side is solid. End those\n // now in their old family; the next step starts them in the new one.\n for (const key of this.activePairs) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n if (lo !== entity && hi !== entity) continue;\n const other = this.entries.get(lo === entity ? hi : lo);\n if (other?.isTrigger) continue;\n this.activePairs.delete(key);\n this.emitPair(lo, hi, previous, other, false);\n }\n }\n\n /**\n * Add an entity from a `Collider`. Its `shape`, `isTrigger`, `layer` and `mask`\n * are copied at add time — later edits to the collider do not reach the world;\n * re-add to change them. Re-adding an existing entity replaces its data.\n *\n * A re-add that flips `isTrigger` ends, during this call, every active pair\n * whose kind that changes, with the exit signal of its old kind\n * (`onTriggerExit` or `onCollisionEnd`). If the shapes still overlap, the next\n * `step` starts the pair again with the enter signal of its new kind. A pair\n * whose other side is a trigger stays a trigger pair and is left alone.\n */\n addCollider(entity: number, collider: Collider, x: number, y: number): void {\n this.add(entity, collider.shape, x, y, collider.isTrigger, collider.layer, collider.mask);\n }\n\n /** Remove an entity from the world. Emits exit signals for any active pairs. */\n remove(entity: number): void {\n const entry = this.entries.get(entity);\n if (!entry) return;\n\n this.entries.delete(entity);\n this.spatial.remove(entity);\n\n // Fire exit signals for all active pairs involving this entity\n for (const key of this.activePairs) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n if (lo !== entity && hi !== entity) continue;\n this.activePairs.delete(key);\n const otherEntity = lo === entity ? hi : lo;\n this.emitPair(lo, hi, entry, this.entries.get(otherEntity), false);\n }\n }\n\n /** Update an entity's position. */\n setPosition(entity: number, x: number, y: number): void {\n const entry = this.entries.get(entity);\n if (!entry) return;\n entry.x = x;\n entry.y = y;\n shapeBoundsInto(entry.shape, x, y, this.boundsBuf);\n this.spatial.update(entity, this.boundsBuf);\n }\n\n /** Number of entities in the world. */\n get size(): number {\n return this.entries.size;\n }\n\n /** Number of broadphase records (one per live entity after add/remove). Diagnostic for broadphase growth. */\n get broadphaseSize(): number {\n return this.spatial.size;\n }\n\n /** Run one collision detection step. */\n step(): void {\n const newPairs = this.activePairs === this.pairBufA ? this.pairBufB : this.pairBufA;\n newPairs.clear();\n\n for (const entryA of this.entries.values()) {\n const entityA = entryA.entity;\n shapeBoundsInto(entryA.shape, entryA.x, entryA.y, this.boundsBuf);\n this.queryBuf.length = 0;\n this.spatial.query(this.boundsBuf, this.queryBuf);\n\n for (let i = 0; i < this.queryBuf.length; i++) {\n const entityB = this.queryBuf[i]!;\n if (entityB <= entityA) continue; // Avoid self and duplicates\n\n const entryB = this.entries.get(entityB);\n if (!entryB) continue;\n\n // Layer/mask filtering\n if ((entryA.layer & entryB.mask) === 0 && (entryB.layer & entryA.mask) === 0) continue;\n\n // Narrowphase\n if (!shapeOverlap(entryA.shape, entryA.x, entryA.y, entryB.shape, entryB.x, entryB.y)) {\n continue;\n }\n\n newPairs.add(encodePair(entityA, entityB));\n }\n }\n\n // Enter/start events — pair objects are allocated here only on state transitions.\n for (const key of newPairs) {\n if (!this.activePairs.has(key)) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n this.emitPair(lo, hi, this.entries.get(lo), this.entries.get(hi), true);\n }\n }\n\n // Exit/end events\n for (const key of this.activePairs) {\n if (!newPairs.has(key)) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n this.emitPair(lo, hi, this.entries.get(lo), this.entries.get(hi), false);\n }\n }\n\n this.activePairs = newPairs;\n }\n\n /**\n * The one place that decides trigger vs collision for a pair and emits its\n * enter or exit signal. `a` and `b` are the pair's two entries in either\n * order. They are passed in rather than looked up because in `remove` the\n * removed entity is already gone from `entries`.\n */\n private emitPair(\n lo: number,\n hi: number,\n a: CollisionEntry | undefined,\n b: CollisionEntry | undefined,\n entering: boolean,\n ): void {\n const pair: CollisionPair = { entityA: lo, entityB: hi };\n if (a?.isTrigger || b?.isTrigger) {\n if (entering) this.onTriggerEnter.emit(pair);\n else this.onTriggerExit.emit(pair);\n } else if (entering) {\n this.onCollisionStart.emit(pair);\n } else {\n this.onCollisionEnd.emit(pair);\n }\n }\n\n /** Zero-alloc collider bounds — writes the AABB of entity's shape into `out`. Returns null when entity is absent. */\n getColliderBoundsInto(entity: number, out: Rect): Rect | null {\n const entry = this.entries.get(entity);\n if (!entry) return null;\n shapeBoundsInto(entry.shape, entry.x, entry.y, out);\n return out;\n }\n\n /** Allocating convenience wrapper — returns a fresh Rect or null when entity is absent. */\n getColliderBounds(entity: number): Rect | null {\n const entry = this.entries.get(entity);\n if (!entry) return null;\n return shapeBoundsInto(entry.shape, entry.x, entry.y, { x: 0, y: 0, width: 0, height: 0 });\n }\n\n /** Remove all entities. */\n clear(): void {\n this.entries.clear();\n this.spatial.clear();\n this.pairBufA.clear();\n this.pairBufB.clear();\n this.activePairs = this.pairBufA;\n }\n\n /** Reused across raycasts — see `raycast`. */\n private raycastBounds: Rect = { x: 0, y: 0, width: 0, height: 0 };\n private raycastCandidates: number[] = [];\n private raycastHit: RaycastHit = {\n entity: -1,\n distance: 0,\n point: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n };\n\n /**\n * Cast a ray against the colliders in this world.\n *\n * The standalone `raycast()` export tests a caller-supplied target array, so\n * it neither sees the world's colliders nor benefits from the broadphase — an\n * O(n) scan sitting beside an O(1) index. This walks only the cells the ray's\n * bounding box touches.\n *\n * `mask` is a layer bitmask filtered against each collider's `layer`, using the\n * bits colliders already carry; it defaults to every layer. Triggers are\n * included — a ray asking \"what is over there\" wants them.\n *\n * The returned record is **reused between calls**: read it, or copy what you\n * need, before casting again. That is what keeps a per-frame ray allocation-\n * free; the standalone helper by contrast returns a fresh hit from each call\n * that hits, which the caller may keep.\n *\n * `maxDist` must be finite — this requires a bounded ray, not the\n * `Number.POSITIVE_INFINITY` \"unbounded ray\" idiom some engines accept. The\n * broadphase below is a uniform grid: an infinite `maxDist` derives an\n * infinite cell range and never terminates the walk. Pass a large finite\n * bound instead (e.g. the map's diagonal) to cast \"until it leaves the\n * populated area\". A non-finite `maxDist` returns `null`.\n */\n raycast(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n mask = 0xffffffff,\n ): RaycastHit | null {\n if (!Number.isFinite(maxDist)) return null;\n\n // Bounding box of the whole ray — the broadphase is rect-based, so this is\n // a conservative prefilter, not the intersection test itself.\n const ex = ox + dx * maxDist;\n const ey = oy + dy * maxDist;\n const minX = ox < ex ? ox : ex;\n const minY = oy < ey ? oy : ey;\n // Padded so the rect always has non-zero extent on both axes. An axis-\n // aligned ray is otherwise degenerate — a horizontal ray has height 0 — and\n // SpatialIndex derives its cell range with an exclusive end (`_cMax` is\n // `ceil(v / CELL) - 1`), so a zero-height rect yields cyMin 0 > cyMax -1 and\n // the cell loop never runs. The broadphase is a conservative prefilter\n // anyway, so over-including by a hair costs nothing: the exact ray test\n // below rejects the extras.\n this.raycastBounds.x = minX - RAY_BOUNDS_PAD;\n this.raycastBounds.y = minY - RAY_BOUNDS_PAD;\n this.raycastBounds.width = Math.abs(ex - ox) + RAY_BOUNDS_PAD * 2;\n this.raycastBounds.height = Math.abs(ey - oy) + RAY_BOUNDS_PAD * 2;\n\n this.raycastCandidates.length = 0;\n this.spatial.query(this.raycastBounds, this.raycastCandidates);\n\n let bestDist = Number.POSITIVE_INFINITY;\n let found = false;\n for (let i = 0; i < this.raycastCandidates.length; i++) {\n const entry = this.entries.get(this.raycastCandidates[i]!);\n if (entry === undefined) continue;\n if ((entry.layer & mask) === 0) continue;\n const hit = rayVsShapeInto(\n ox,\n oy,\n dx,\n dy,\n maxDist,\n entry.entity,\n entry.shape,\n entry.x,\n entry.y,\n this.scratchHit,\n );\n if (hit !== null && hit.distance < bestDist) {\n bestDist = hit.distance;\n found = true;\n this.raycastHit.entity = hit.entity;\n this.raycastHit.distance = hit.distance;\n this.raycastHit.point.x = hit.point.x;\n this.raycastHit.point.y = hit.point.y;\n this.raycastHit.normal.x = hit.normal.x;\n this.raycastHit.normal.y = hit.normal.y;\n }\n }\n return found ? this.raycastHit : null;\n }\n\n /** Scratch record handed to `rayVsShapeInto` per candidate. */\n private scratchHit: RaycastHit = {\n entity: -1,\n distance: 0,\n point: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n };\n}\n","import type { Vec2 } from '@flare-engine/math';\n\n/**\n * Minimal structural type for a solid tile position in grid coordinates.\n * `TileCollider[]` from `@flare-engine/tilemap` is structurally assignable here\n * so callers can pass `extractColliders(map)` directly — no tilemap dep needed.\n */\nexport interface SolidTile {\n readonly row: number;\n readonly col: number;\n}\n\n/**\n * How `isBlockedAABB` treats cells outside the grid.\n * `'solid'` — the map edge is a wall; any box that leaves the map is blocked.\n * `'open'` — cells outside the grid are empty, so a body can walk off the map;\n * use it for seams between adjacent region maps.\n */\nexport type SolidGridOutside = 'solid' | 'open';\n\nexport interface SolidGridOptions {\n /** Defaults to `'solid'`. */\n readonly outside?: SolidGridOutside;\n}\n\n/**\n * Precomputed solid-tile lookup used by `isBlockedAABB` and `moveAndSlideInto`.\n * `solid` has `width * height` cells indexed `row * width + col`; non-zero means\n * solid. Build once per map load via `buildSolidGrid`.\n */\nexport interface SolidGrid {\n readonly width: number;\n readonly height: number;\n readonly tileSize: number;\n readonly solid: Uint8Array;\n readonly outside: SolidGridOutside;\n}\n\n/**\n * Build a `SolidGrid` from a list of solid tile positions.\n * Input is structurally typed (`readonly SolidTile[]`) so the caller does not\n * need to import `@flare-engine/tilemap` — physics stays tilemap-free.\n */\nexport function buildSolidGrid(\n width: number,\n height: number,\n tileSize: number,\n tiles: readonly SolidTile[],\n options?: SolidGridOptions,\n): SolidGrid {\n const solid = new Uint8Array(width * height);\n for (const t of tiles) {\n solid[t.row * width + t.col] = 1;\n }\n return { width, height, tileSize, solid, outside: options?.outside ?? 'solid' };\n}\n\n/**\n * Half-open boundary constant: the AABB is treated as [min, max) so a box\n * whose max edge lands exactly on a tile boundary does NOT overlap that tile.\n */\nconst EDGE = 1e-4;\n\n/**\n * Returns `true` when an axis-aligned box centered at (`x`, `y`) with\n * half-extents (`halfW`, `halfH`) overlaps a solid tile. Leaving the map\n * blocks only when the grid was built with `outside: 'solid'` (the default);\n * with `'open'` the out-of-grid cells are empty and only the in-grid cells the\n * box overlaps are tested. Uses half-open EDGE semantics on max edges.\n */\nexport function isBlockedAABB(\n grid: SolidGrid,\n x: number,\n y: number,\n halfW: number,\n halfH: number,\n): boolean {\n const ts = grid.tileSize;\n let minCol = Math.floor((x - halfW) / ts);\n let maxCol = Math.floor((x + halfW - EDGE) / ts);\n let minRow = Math.floor((y - halfH) / ts);\n let maxRow = Math.floor((y + halfH - EDGE) / ts);\n if (minCol < 0 || minRow < 0 || maxCol >= grid.width || maxRow >= grid.height) {\n if (grid.outside === 'solid') return true;\n // Clamp to the in-grid cells; a box fully outside yields an empty range.\n if (minCol < 0) minCol = 0;\n if (minRow < 0) minRow = 0;\n if (maxCol >= grid.width) maxCol = grid.width - 1;\n if (maxRow >= grid.height) maxRow = grid.height - 1;\n }\n for (let row = minRow; row <= maxRow; row++) {\n for (let col = minCol; col <= maxCol; col++) {\n if (grid.solid[row * grid.width + col] !== 0) {\n return true;\n }\n }\n }\n return false;\n}\n\n/**\n * Whether the cell at (`col`, `row`) is solid. Coordinates that name no cell\n * (out of range, or not an integer) follow the grid's own `outside` rule, like\n * `isBlockedAABB` at the map edge: solid on an `outside: 'solid'` grid, empty\n * on an `'open'` one. Zero-alloc.\n */\nexport function isSolidAt(grid: SolidGrid, col: number, row: number): boolean {\n if (!isCell(grid, col, row)) return grid.outside === 'solid';\n return grid.solid[row * grid.width + col] !== 0;\n}\n\n/**\n * Mark the cell at (`col`, `row`) solid or empty, for a door or a breakable\n * wall. Returns `true` when the cell was written, `false` (and writes nothing)\n * when the coordinates are out of range or not integers. Zero-alloc.\n */\nexport function setSolidAt(grid: SolidGrid, col: number, row: number, solid: boolean): boolean {\n if (!isCell(grid, col, row)) return false;\n grid.solid[row * grid.width + col] = solid ? 1 : 0;\n return true;\n}\n\nfunction isCell(grid: SolidGrid, col: number, row: number): boolean {\n return (\n Number.isInteger(col) &&\n Number.isInteger(row) &&\n col >= 0 &&\n col < grid.width &&\n row >= 0 &&\n row < grid.height\n );\n}\n\n/**\n * Axis-separated slide movement. Attempts to move by (`dx`, `dy`); each axis\n * is applied independently so a blocked diagonal input slides along the wall.\n * The y-check uses the already-updated x position.\n * Zero-alloc: writes result into the provided `out` Vec2 and returns it.\n */\nexport function moveAndSlideInto(\n grid: SolidGrid,\n x: number,\n y: number,\n dx: number,\n dy: number,\n halfW: number,\n halfH: number,\n out: Vec2,\n): Vec2 {\n let nx = x;\n let ny = y;\n if (dx !== 0 && !isBlockedAABB(grid, nx + dx, ny, halfW, halfH)) nx += dx;\n if (dy !== 0 && !isBlockedAABB(grid, nx, ny + dy, halfW, halfH)) ny += dy;\n out.x = nx;\n out.y = ny;\n return out;\n}\n"],"mappings":";;;AAeA,SAAgB,eAAe,OAAc,MAAmD;CAC9F,OAAO;EACL;EACA,WAAW,MAAM,aAAa;EAC9B,OAAO,MAAM,SAAS;EACtB,MAAM,MAAM,QAAQ;CACtB;AACF;;;ACEA,MAAM,aAAyB;CAC7B,QAAQ;CACR,UAAU;CACV,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE;CACpB,QAAQ;EAAE,GAAG;EAAG,GAAG;CAAE;AACvB;;;;;;;;;;;;;AAcA,SAAgB,QACd,IACA,IACA,IACA,IACA,SACA,SACmB;CAGnB,IAAI,QAAQ;CACZ,IAAI,SAAS;CACb,IAAI,WAAW;CACf,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CAET,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;EACvC,MAAM,IAAI,QAAQ;EAClB,MAAM,MAAM,eAAe,IAAI,IAAI,IAAI,IAAI,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,UAAU;EAC3F,IAAI,QAAQ,SAAS,CAAC,SAAS,IAAI,WAAW,WAAW;GACvD,QAAQ;GACR,SAAS,IAAI;GACb,WAAW,IAAI;GACf,KAAK,IAAI,MAAM;GACf,KAAK,IAAI,MAAM;GACf,KAAK,IAAI,OAAO;GAChB,KAAK,IAAI,OAAO;EAClB;CACF;CAEA,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO;EAAE;EAA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M,KAAK;AAEf;;;;;;;AAQA,SAAgB,iBACd,MACA,GACA,GACA,IACA,IACA,OACA,OACA,KACM;CACN,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,OAAO,KAAK,CAAC,cAAc,MAAM,KAAK,IAAI,IAAI,OAAO,KAAK,GAAG,MAAM;CACvE,IAAI,OAAO,KAAK,CAAC,cAAc,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,GAAG,MAAM;CACvE,IAAI,IAAI;CACR,IAAI,IAAI;CACR,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/collider.ts","../src/cells.ts","../src/collision-grid.ts","../src/raycast.ts","../src/shape.ts","../src/collision-world.ts","../src/mask.ts","../src/solid-grid.ts","../src/spatial-index.ts"],"sourcesContent":["import type { Shape } from './shape.js';\n\n/** Collider component data attached to an ECS entity. */\nexport interface Collider {\n /** The collision shape. */\n shape: Shape;\n /** If true, generates trigger events but no physical response. */\n isTrigger: boolean;\n /** Collision layer bitmask — which layer this collider belongs to. */\n layer: number;\n /** Collision mask — which layers this collider can interact with. */\n mask: number;\n}\n\n/** Create a collider with default settings. */\nexport function createCollider(shape: Shape, opts?: Partial<Omit<Collider, 'shape'>>): Collider {\n return {\n shape,\n isTrigger: opts?.isTrigger ?? false,\n layer: opts?.layer ?? 1,\n mask: opts?.mask ?? 0xffffffff,\n };\n}\n","// Uniform-grid cell arithmetic shared by SpatialIndex and CollisionWorld's\n// broadphase. Internal — not exported from the package.\n\n// Uniform grid cell size in world units. Tuned for typical game-object sizes (16–64 px).\n// It is fixed: neither SpatialIndex nor CollisionWorld takes a cell-size option. In a world\n// of one unit per tile, every collider shares a few cells, and a query or a step becomes a\n// scan of all of them. Scale world units so a typical collider spans tens of units.\nconst CELL = 64;\n\n// Packed cell-key encoding. Supports cell coords in [-32768, 32767],\n// i.e. world coordinates ±2 097 152. All keys fit within Number.MAX_SAFE_INTEGER.\nconst KEY_RANGE = 65536; // 2^16\nconst KEY_OFFSET = 32768; // 2^15\n\nexport function cellKey(cx: number, cy: number): number {\n return (cx + KEY_OFFSET) * KEY_RANGE + (cy + KEY_OFFSET);\n}\n\n// Supported cell-coordinate range for the packed key above.\nconst MIN_CELL = -KEY_OFFSET;\nconst MAX_CELL = KEY_OFFSET - 1;\n\n// Bounds a derived cell coordinate to the packed-key range. Without this, a\n// non-finite world coordinate (±Infinity — an unbounded raycast maxDist, or an\n// entity parked at Infinity) makes cxMin/cxMax/cyMin/cyMax infinite, and\n// `for (cx = cxMin; cx <= cxMax; cx++)` never exits: once cx itself is\n// Infinity, `cx <= Infinity` stays true and `cx++` is a no-op, so the loop\n// spins forever pushing/reading the same bucket (unbounded memory growth on\n// the link side). NaN is left untouched: every comparison against NaN is\n// false, so the loop already runs zero times, which is the existing (safe)\n// behaviour for a degenerate direction like `0 * Infinity`.\nfunction clampCell(c: number): number {\n if (c > MAX_CELL) return MAX_CELL;\n if (c < MIN_CELL) return MIN_CELL;\n return c;\n}\n\n/** Inclusive first cell, clamped, that contains world coordinate `v`. */\nexport function cellMin(v: number): number {\n return clampCell(Math.floor(v / CELL));\n}\n\n/**\n * Inclusive last cell, clamped, for a range ending at world coordinate `v`.\n * Exclusive-end: a coord falling exactly on a cell boundary is NOT part of the\n * adjacent cell — matches the strict-inequality overlap semantics of a query.\n */\nexport function cellMax(v: number): number {\n return clampCell(Math.ceil(v / CELL) - 1);\n}\n","import { cellKey, cellMax, cellMin } from './cells.js';\nimport type { Shape } from './shape.js';\n\n// CollisionWorld's broadphase: the same uniform grid as SpatialIndex, but it\n// links the world's entries directly and, inside each cell, keeps them grouped\n// by (layer, mask). A step can then reject a whole group with one layer/mask\n// test — no lookup per candidate, and no walk through bodies that cannot pair\n// with the one it is querying from. Internal — not exported from the package.\n\n/** Per-entity collision data stored in the world, with its grid bookkeeping. */\nexport interface CollisionEntry {\n readonly entity: number;\n shape: Shape;\n x: number;\n y: number;\n isTrigger: boolean;\n layer: number;\n mask: number;\n // Bounding rect of `shape` at (x, y), as last handed to the grid.\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n // Clamped cell range the entry is linked into. NaN when a bound is NaN —\n // such an entry is linked nowhere and never compares equal, so it relinks.\n cxMin: number;\n cxMax: number;\n cyMin: number;\n cyMax: number;\n /** How many leading slots of `cells` / `groups` / `at` are live. */\n cellCount: number;\n /**\n * The cells the entry is linked into, column by column: slot\n * `(cx - cxMin) * rows + (cy - cyMin)`, rows = cyMax - cyMin + 1.\n * Grown, never reallocated.\n */\n readonly cells: GridCell[];\n /** The group holding the entry in `cells[i]`. */\n readonly groups: CellGroup[];\n /** The entry's position in `groups[i].items`. */\n readonly at: number[];\n stamp: number;\n}\n\n/**\n * The entries of one cell that share a `layer` and a `mask`. Every entry of a\n * group passes or fails the layer/mask test against a given body together, so\n * the test is made once per group and is exact — there is nothing cached about\n * a group that a removal or a re-add could leave out of date.\n */\nexport interface CellGroup {\n layer: number;\n mask: number;\n /** Position in the owning cell's `groups`. */\n index: number;\n readonly items: CollisionEntry[];\n}\n\nexport interface GridCell {\n readonly cx: number;\n readonly cy: number;\n /** Non-empty groups only. */\n readonly groups: CellGroup[];\n}\n\nexport interface CollisionGrid {\n // Packed cell key → cell. Named as SpatialIndex names its own map: the\n // cell-walk tests bound both through the same private field.\n readonly _cells: Map<number, GridCell>;\n /** Emptied groups, reused so a body entering a cell allocates nothing once warm. */\n readonly freeGroups: CellGroup[];\n /** Monotone stamp source for duplicate suppression across cells. */\n gen: number;\n /** Number of entries placed and not yet removed. */\n size: number;\n}\n\nexport function createCollisionGrid(): CollisionGrid {\n return { _cells: new Map(), freeGroups: [], gen: 0, size: 0 };\n}\n\nfunction groupFor(grid: CollisionGrid, cell: GridCell, layer: number, mask: number): CellGroup {\n const groups = cell.groups;\n for (let g = 0; g < groups.length; g++) {\n const group = groups[g]!;\n if (group.layer === layer && group.mask === mask) return group;\n }\n let group = grid.freeGroups.pop();\n if (group === undefined) {\n group = { layer, mask, index: groups.length, items: [] };\n } else {\n group.layer = layer;\n group.mask = mask;\n group.index = groups.length;\n }\n groups.push(group);\n return group;\n}\n\nfunction link(grid: CollisionGrid, e: CollisionEntry): void {\n const { cxMin, cxMax, cyMin, cyMax } = e;\n let n = 0;\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const k = cellKey(cx, cy);\n let cell = grid._cells.get(k);\n if (cell === undefined) {\n cell = { cx, cy, groups: [] };\n grid._cells.set(k, cell);\n }\n const group = groupFor(grid, cell, e.layer, e.mask);\n e.cells[n] = cell;\n e.groups[n] = group;\n e.at[n] = group.items.length;\n n++;\n group.items.push(e);\n }\n }\n e.cellCount = n;\n}\n\n/**\n * Take an entry out of every cell it is linked into. O(1) per cell: the last\n * entry of the group takes the vacated position, and its own record of where\n * it sits in that cell is corrected to match. A group left empty leaves its\n * cell the same way and goes back to the free list.\n *\n * `layer` and `mask` decide which group holds an entry, so they may only be\n * rewritten while it is unlinked; follow with `gridRelink`.\n */\nexport function gridUnlink(grid: CollisionGrid, e: CollisionEntry): void {\n for (let n = 0; n < e.cellCount; n++) {\n const cell = e.cells[n]!;\n const group = e.groups[n]!;\n const items = group.items;\n const last = items.pop()!;\n if (last !== e) {\n const i = e.at[n]!;\n items[i] = last;\n last.at[(cell.cx - last.cxMin) * (last.cyMax - last.cyMin + 1) + (cell.cy - last.cyMin)] = i;\n } else if (items.length === 0) {\n const lastGroup = cell.groups.pop()!;\n if (lastGroup !== group) {\n cell.groups[group.index] = lastGroup;\n lastGroup.index = group.index;\n }\n grid.freeGroups.push(group);\n }\n }\n e.cellCount = 0;\n}\n\nfunction setBounds(\n e: CollisionEntry,\n minX: number,\n minY: number,\n maxX: number,\n maxY: number,\n): void {\n e.minX = minX;\n e.minY = minY;\n e.maxX = maxX;\n e.maxY = maxY;\n e.cxMin = cellMin(minX);\n e.cxMax = cellMax(maxX);\n e.cyMin = cellMin(minY);\n e.cyMax = cellMax(maxY);\n}\n\n/** Link a new entry at the given bounds. */\nexport function gridInsert(\n grid: CollisionGrid,\n e: CollisionEntry,\n minX: number,\n minY: number,\n maxX: number,\n maxY: number,\n): void {\n grid.size++;\n setBounds(e, minX, minY, maxX, maxY);\n link(grid, e);\n}\n\n/** Link an entry `gridUnlink` took out, at the given bounds. */\nexport function gridRelink(\n grid: CollisionGrid,\n e: CollisionEntry,\n minX: number,\n minY: number,\n maxX: number,\n maxY: number,\n): void {\n setBounds(e, minX, minY, maxX, maxY);\n link(grid, e);\n}\n\n/** Move an entry whose layer and mask are unchanged. Touches no bucket while it stays in the same cells. */\nexport function gridMove(\n grid: CollisionGrid,\n e: CollisionEntry,\n minX: number,\n minY: number,\n maxX: number,\n maxY: number,\n): void {\n const cxMin = cellMin(minX);\n const cxMax = cellMax(maxX);\n const cyMin = cellMin(minY);\n const cyMax = cellMax(maxY);\n if (cxMin === e.cxMin && cxMax === e.cxMax && cyMin === e.cyMin && cyMax === e.cyMax) {\n e.minX = minX;\n e.minY = minY;\n e.maxX = maxX;\n e.maxY = maxY;\n return;\n }\n gridUnlink(grid, e);\n setBounds(e, minX, minY, maxX, maxY);\n link(grid, e);\n}\n\nexport function gridRemove(grid: CollisionGrid, e: CollisionEntry): void {\n gridUnlink(grid, e);\n grid.size--;\n}\n\nexport function gridClear(grid: CollisionGrid): void {\n grid._cells.clear();\n grid.freeGroups.length = 0;\n grid.size = 0;\n}\n\n/** Append every entry whose bounds overlap the rect to `out`, each once. Order is unspecified. */\nexport function gridQuery(\n grid: CollisionGrid,\n minX: number,\n minY: number,\n maxX: number,\n maxY: number,\n out: CollisionEntry[],\n): void {\n const gen = ++grid.gen;\n const cxMin = cellMin(minX);\n const cxMax = cellMax(maxX);\n const cyMin = cellMin(minY);\n const cyMax = cellMax(maxY);\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const cell = grid._cells.get(cellKey(cx, cy));\n if (cell === undefined) continue;\n const groups = cell.groups;\n for (let g = 0; g < groups.length; g++) {\n const items = groups[g]!.items;\n for (let i = 0; i < items.length; i++) {\n const e = items[i]!;\n if (e.stamp === gen) continue;\n e.stamp = gen;\n if (e.maxX > minX && e.minX < maxX && e.maxY > minY && e.minY < maxY) out.push(e);\n }\n }\n }\n }\n}\n","import type { Vec2 } from '@flare-engine/math';\nimport type { Shape } from './shape.js';\n\n/** Result of a raycast hit. */\nexport interface RaycastHit {\n /** The entity that was hit. */\n entity: number;\n /** Distance from ray origin to hit point. */\n distance: number;\n /** World-space hit point. */\n point: Vec2;\n /** Surface normal at hit point. */\n normal: Vec2;\n}\n\n/** Entity entry for raycast — position + shape. */\nexport interface RaycastTarget {\n entity: number;\n shape: Shape;\n x: number;\n y: number;\n}\n\n/** Scratch record `raycast()` hands to `rayVsShapeInto` per candidate. */\nconst scratchHit: RaycastHit = {\n entity: -1,\n distance: 0,\n point: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n};\n\n/**\n * Cast a ray against a list of targets. Returns the closest hit, or null.\n *\n * The returned hit is a fresh object — the caller may keep it; later calls do\n * not overwrite it. Among targets at equal distance the first in `targets` wins.\n *\n * A ray that starts inside a collider hits that collider at its exit\n * distance, not at 0. The hit's `normal` is then the outward normal of the\n * face the ray entered through behind its origin for a box, and the outward\n * normal at the exit point for a circle. To skip the collider a ray starts in,\n * leave it out of `targets`, or start the ray just past its edge: a ray that\n * starts exactly on the edge still hits it, at distance 0.\n * @param ox Ray origin X\n * @param oy Ray origin Y\n * @param dx Ray direction X (should be normalized)\n * @param dy Ray direction Y (should be normalized)\n * @param maxDist Maximum raycast distance\n * @param targets Array of entities to test against\n */\nexport function raycast(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n targets: readonly RaycastTarget[],\n): RaycastHit | null {\n // Every later hit overwrites the scratch, so the best candidate so far is\n // held in locals and only the winner becomes an object.\n let found = false;\n let entity = -1;\n let distance = 0;\n let px = 0;\n let py = 0;\n let nx = 0;\n let ny = 0;\n\n for (let i = 0; i < targets.length; i++) {\n const t = targets[i]!;\n const hit = rayVsShapeInto(ox, oy, dx, dy, maxDist, t.entity, t.shape, t.x, t.y, scratchHit);\n if (hit !== null && (!found || hit.distance < distance)) {\n found = true;\n entity = hit.entity;\n distance = hit.distance;\n px = hit.point.x;\n py = hit.point.y;\n nx = hit.normal.x;\n ny = hit.normal.y;\n }\n }\n\n if (!found) return null;\n return { entity, distance, point: { x: px, y: py }, normal: { x: nx, y: ny } };\n}\n\n/**\n * Zero-alloc ray-vs-shape test: writes into `out` and returns it, or returns\n * `null` without touching `out`.\n *\n * This is the single implementation of the ray math. `raycast()` above and\n * `CollisionWorld.raycast` both run every candidate through it into a scratch\n * record, so neither allocates per candidate tested.\n */\nexport function rayVsShapeInto(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n shape: Shape,\n x: number,\n y: number,\n out: RaycastHit,\n): RaycastHit | null {\n if (shape.type === 'aabb') {\n return rayVsAABBInto(ox, oy, dx, dy, maxDist, entity, x, y, shape.hw, shape.hh, out);\n }\n return rayVsCircleInto(ox, oy, dx, dy, maxDist, entity, x, y, shape.radius, out);\n}\n\nfunction rayVsAABBInto(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n bx: number,\n by: number,\n hw: number,\n hh: number,\n out: RaycastHit,\n): RaycastHit | null {\n if (dx === 0 && dy === 0) return null;\n\n // A ray parallel to an axis never crosses that slab's planes: it is inside\n // the slab for all t or for none. Scaling by an infinite inverse instead\n // gives 0 * Infinity = NaN when the origin sits exactly on a plane.\n let tMinX = Number.NEGATIVE_INFINITY;\n let tMaxX = Number.POSITIVE_INFINITY;\n if (dx === 0) {\n if (ox < bx - hw || ox > bx + hw) return null;\n } else {\n const invDx = 1 / dx;\n const tx1 = (bx - hw - ox) * invDx;\n const tx2 = (bx + hw - ox) * invDx;\n tMinX = Math.min(tx1, tx2);\n tMaxX = Math.max(tx1, tx2);\n }\n\n let tMinY = Number.NEGATIVE_INFINITY;\n let tMaxY = Number.POSITIVE_INFINITY;\n if (dy === 0) {\n if (oy < by - hh || oy > by + hh) return null;\n } else {\n const invDy = 1 / dy;\n const ty1 = (by - hh - oy) * invDy;\n const ty2 = (by + hh - oy) * invDy;\n tMinY = Math.min(ty1, ty2);\n tMaxY = Math.max(ty1, ty2);\n }\n\n const tMin = Math.max(tMinX, tMinY);\n const tMax = Math.min(tMaxX, tMaxY);\n if (tMax < 0 || tMin > tMax) return null;\n\n const t = tMin < 0 ? tMax : tMin;\n if (t > maxDist || t < 0) return null;\n\n out.entity = entity;\n out.distance = t;\n out.point.x = ox + dx * t;\n out.point.y = oy + dy * t;\n if (tMinX > tMinY) {\n out.normal.x = dx < 0 ? 1 : -1;\n out.normal.y = 0;\n } else {\n out.normal.x = 0;\n out.normal.y = dy < 0 ? 1 : -1;\n }\n return out;\n}\n\nfunction rayVsCircleInto(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n cx: number,\n cy: number,\n radius: number,\n out: RaycastHit,\n): RaycastHit | null {\n const fx = ox - cx;\n const fy = oy - cy;\n const a = dx * dx + dy * dy;\n if (a < 1e-12) return null; // Zero-length direction\n\n const b = 2 * (fx * dx + fy * dy);\n const c = fx * fx + fy * fy - radius * radius;\n const discriminant = b * b - 4 * a * c;\n if (discriminant < 0) return null;\n\n const sqrtDisc = Math.sqrt(discriminant);\n let t = (-b - sqrtDisc) / (2 * a);\n // If the entry point is behind the origin, try the exit point.\n if (t < 0) t = (-b + sqrtDisc) / (2 * a);\n if (t < 0 || t > maxDist) return null;\n\n const px = ox + dx * t;\n const py = oy + dy * t;\n const nx = px - cx;\n const ny = py - cy;\n const len = Math.sqrt(nx * nx + ny * ny);\n\n out.entity = entity;\n out.distance = t;\n out.point.x = px;\n out.point.y = py;\n out.normal.x = len > 0 ? nx / len : 0;\n out.normal.y = len > 0 ? ny / len : 0;\n return out;\n}\n","import type { Rect } from '@flare-engine/math';\n\n/** AABB shape — axis-aligned bounding box. */\nexport interface AABBShape {\n readonly type: 'aabb';\n /** Half-width. */\n readonly hw: number;\n /** Half-height. */\n readonly hh: number;\n}\n\n/** Circle shape. */\nexport interface CircleShape {\n readonly type: 'circle';\n readonly radius: number;\n}\n\n/** Union of supported physics shapes. */\nexport type Shape = AABBShape | CircleShape;\n\n/** Create an AABB shape from width and height. */\nexport function AABB(width: number, height: number): AABBShape {\n return { type: 'aabb', hw: width * 0.5, hh: height * 0.5 };\n}\n\n/** Create a circle shape from radius. */\nexport function CircleShape(radius: number): CircleShape {\n return { type: 'circle', radius };\n}\n\n/** Compute the bounding rect of a shape at a given position. */\nexport function shapeBounds(shape: Shape, x: number, y: number): Rect {\n if (shape.type === 'aabb') {\n return { x: x - shape.hw, y: y - shape.hh, width: shape.hw * 2, height: shape.hh * 2 };\n }\n return {\n x: x - shape.radius,\n y: y - shape.radius,\n width: shape.radius * 2,\n height: shape.radius * 2,\n };\n}\n\n/** Zero-alloc variant — writes the shape bounds into the provided output rect. */\nexport function shapeBoundsInto(shape: Shape, x: number, y: number, out: Rect): Rect {\n if (shape.type === 'aabb') {\n out.x = x - shape.hw;\n out.y = y - shape.hh;\n out.width = shape.hw * 2;\n out.height = shape.hh * 2;\n return out;\n }\n out.x = x - shape.radius;\n out.y = y - shape.radius;\n out.width = shape.radius * 2;\n out.height = shape.radius * 2;\n return out;\n}\n\n/** Test overlap between two positioned shapes. Returns true if overlapping. */\nexport function shapeOverlap(\n shapeA: Shape,\n ax: number,\n ay: number,\n shapeB: Shape,\n bx: number,\n by: number,\n): boolean {\n if (shapeA.type === 'aabb' && shapeB.type === 'aabb') {\n return aabbVsAabb(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.hw, shapeB.hh);\n }\n if (shapeA.type === 'circle' && shapeB.type === 'circle') {\n return circleVsCircle(ax, ay, shapeA.radius, bx, by, shapeB.radius);\n }\n // Mixed: one AABB, one circle\n if (shapeA.type === 'aabb' && shapeB.type === 'circle') {\n return aabbVsCircle(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.radius);\n }\n return aabbVsCircle(\n bx,\n by,\n (shapeB as AABBShape).hw,\n (shapeB as AABBShape).hh,\n ax,\n ay,\n (shapeA as CircleShape).radius,\n );\n}\n\nfunction aabbVsAabb(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n bx: number,\n by: number,\n bhw: number,\n bhh: number,\n): boolean {\n return Math.abs(ax - bx) < ahw + bhw && Math.abs(ay - by) < ahh + bhh;\n}\n\nfunction circleVsCircle(\n ax: number,\n ay: number,\n ar: number,\n bx: number,\n by: number,\n br: number,\n): boolean {\n const dx = bx - ax;\n const dy = by - ay;\n const radSum = ar + br;\n return dx * dx + dy * dy < radSum * radSum;\n}\n\nfunction aabbVsCircle(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n cx: number,\n cy: number,\n cr: number,\n): boolean {\n const left = ax - ahw;\n const right = ax + ahw;\n const top = ay - ahh;\n const bottom = ay + ahh;\n const closestX = cx < left ? left : cx > right ? right : cx;\n const closestY = cy < top ? top : cy > bottom ? bottom : cy;\n const dx = cx - closestX;\n const dy = cy - closestY;\n const distSq = dx * dx + dy * dy;\n // Strict, like aabbVsAabb and circleVsCircle: exactly-touching shapes do not\n // collide. A centre on or inside the box collides when the radius is positive;\n // a zero radius counts only strictly inside, as a zero-size box does.\n if (distSq > 0) return distSq < cr * cr;\n return cr > 0 || (cx > left && cx < right && cy > top && cy < bottom);\n}\n\n/**\n * Minimum translation vector: the shortest push that separates two overlapping\n * shapes.\n *\n * `shapeOverlap` answers *whether* two shapes collide and nothing more, which\n * leaves a detection-only consumer with no way to resolve the collision. This is\n * that missing step: `out.x`/`out.y` are a unit axis and `out.depth` is how far\n * along it `b` must move to just stop touching `a`.\n *\n * Returns `null` when the shapes are not overlapping, leaving `out` untouched so\n * a caller may reuse one buffer across many pairs.\n *\n * The degenerate concentric case (identical centres) has no meaningful axis;\n * `(1, 0)` is returned so the caller still gets a usable separation instead of\n * `NaN` from normalising a zero vector.\n */\nexport interface Overlap {\n /** Unit separation axis, pointing from `a` toward `b`. */\n x: number;\n y: number;\n /** Penetration depth along that axis. */\n depth: number;\n}\n\n/** A fresh, zeroed overlap record. Allocate once outside the loop and reuse. */\nexport function createOverlap(): Overlap {\n return { x: 0, y: 0, depth: 0 };\n}\n\nexport function overlapInto(\n shapeA: Shape,\n ax: number,\n ay: number,\n shapeB: Shape,\n bx: number,\n by: number,\n out: Overlap,\n): Overlap | null {\n if (shapeA.type === 'aabb' && shapeB.type === 'aabb') {\n return aabbAabbOverlap(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.hw, shapeB.hh, out);\n }\n if (shapeA.type === 'circle' && shapeB.type === 'circle') {\n return circleCircleOverlap(ax, ay, shapeA.radius, bx, by, shapeB.radius, out);\n }\n if (shapeA.type === 'aabb' && shapeB.type === 'circle') {\n return aabbCircleOverlap(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.radius, out, false);\n }\n // Circle vs AABB — solve as AABB vs circle, then flip the axis so it still\n // points from `a` to `b`.\n return aabbCircleOverlap(\n bx,\n by,\n (shapeB as AABBShape).hw,\n (shapeB as AABBShape).hh,\n ax,\n ay,\n (shapeA as CircleShape).radius,\n out,\n true,\n );\n}\n\n/** Minimum translation vector. Allocates — see `overlapInto` for the hot path. */\nexport function overlap(\n shapeA: Shape,\n ax: number,\n ay: number,\n shapeB: Shape,\n bx: number,\n by: number,\n): Overlap | null {\n return overlapInto(shapeA, ax, ay, shapeB, bx, by, createOverlap());\n}\n\nfunction aabbAabbOverlap(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n bx: number,\n by: number,\n bhw: number,\n bhh: number,\n out: Overlap,\n): Overlap | null {\n const dx = bx - ax;\n const dy = by - ay;\n const overlapX = ahw + bhw - Math.abs(dx);\n if (overlapX <= 0) return null;\n const overlapY = ahh + bhh - Math.abs(dy);\n if (overlapY <= 0) return null;\n\n // The minimum translation is along whichever axis is least penetrated.\n if (overlapX < overlapY) {\n out.x = dx < 0 ? -1 : 1;\n out.y = 0;\n out.depth = overlapX;\n } else {\n out.x = 0;\n out.y = dy < 0 ? -1 : 1;\n out.depth = overlapY;\n }\n return out;\n}\n\nfunction circleCircleOverlap(\n ax: number,\n ay: number,\n ar: number,\n bx: number,\n by: number,\n br: number,\n out: Overlap,\n): Overlap | null {\n const dx = bx - ax;\n const dy = by - ay;\n const radSum = ar + br;\n const distSq = dx * dx + dy * dy;\n if (distSq >= radSum * radSum) return null;\n\n const dist = Math.sqrt(distSq);\n if (dist === 0) {\n // Concentric: no meaningful axis, so pick one rather than divide by zero.\n out.x = 1;\n out.y = 0;\n out.depth = radSum;\n return out;\n }\n out.x = dx / dist;\n out.y = dy / dist;\n out.depth = radSum - dist;\n return out;\n}\n\nfunction aabbCircleOverlap(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n cx: number,\n cy: number,\n cr: number,\n out: Overlap,\n flip: boolean,\n): Overlap | null {\n const left = ax - ahw;\n const right = ax + ahw;\n const top = ay - ahh;\n const bottom = ay + ahh;\n const closestX = cx < left ? left : cx > right ? right : cx;\n const closestY = cy < top ? top : cy > bottom ? bottom : cy;\n const dx = cx - closestX;\n const dy = cy - closestY;\n const distSq = dx * dx + dy * dy;\n\n if (distSq > 0) {\n // Centre outside the box: separate along the closest-point normal.\n if (distSq >= cr * cr) return null;\n const dist = Math.sqrt(distSq);\n const nx = dx / dist;\n const ny = dy / dist;\n out.x = flip ? -nx : nx;\n out.y = flip ? -ny : ny;\n out.depth = cr - dist;\n return out;\n }\n\n // Centre inside the box: push out through the nearest face.\n const toLeft = cx - left;\n const toRight = right - cx;\n const toTop = cy - top;\n const toBottom = bottom - cy;\n let nx = -1;\n let ny = 0;\n let depth = toLeft;\n if (toRight < depth) {\n nx = 1;\n ny = 0;\n depth = toRight;\n }\n if (toTop < depth) {\n nx = 0;\n ny = -1;\n depth = toTop;\n }\n if (toBottom < depth) {\n nx = 0;\n ny = 1;\n depth = toBottom;\n }\n // Zero radius on the boundary is exactly touching, not overlapping.\n if (depth + cr <= 0) return null;\n out.x = flip ? -nx : nx;\n out.y = flip ? -ny : ny;\n out.depth = depth + cr;\n return out;\n}\n","import { Signal } from '@flare-engine/events';\nimport type { Rect } from '@flare-engine/math';\nimport type { Collider } from './collider.js';\nimport {\n type CollisionEntry,\n createCollisionGrid,\n gridClear,\n gridInsert,\n gridMove,\n gridQuery,\n gridRelink,\n gridRemove,\n gridUnlink,\n} from './collision-grid.js';\nimport type { RaycastHit } from './raycast.js';\nimport { rayVsShapeInto } from './raycast.js';\nimport type { Shape } from './shape.js';\nimport { shapeBoundsInto, shapeOverlap } from './shape.js';\n\n/** Collision pair data emitted by collision signals. */\nexport interface CollisionPair {\n readonly entityA: number;\n readonly entityB: number;\n}\n\n// Packed pair-key layout: `lo * ENTITY_SHIFT + hi`, lo = min(a,b), hi = max(a,b).\n// 2^26 fits within Number.MAX_SAFE_INTEGER for 26+26 bits → max entity id ~67M.\nconst ENTITY_SHIFT = 2 ** 26;\n\n/** Padding applied to a ray's query AABB — see `CollisionWorld.raycast`. */\nconst RAY_BOUNDS_PAD = 1e-6;\n\nfunction encodePair(a: number, b: number): number {\n const lo = a < b ? a : b;\n const hi = a < b ? b : a;\n return lo * ENTITY_SHIFT + hi;\n}\n\nfunction decodeLo(key: number): number {\n return Math.floor(key / ENTITY_SHIFT);\n}\n\nfunction decodeHi(key: number): number {\n return key - Math.floor(key / ENTITY_SHIFT) * ENTITY_SHIFT;\n}\n\n/**\n * AABB collision world. Manages entities with shapes, detects overlaps each step,\n * and emits collision/trigger signals.\n *\n * The broadphase is a uniform grid of fixed 64-world-unit cells, with no option to\n * change it. It suits colliders of roughly 16-64 units. In a world of one unit per\n * tile, colliders crowd a few cells and `step` and `raycast` approach a scan of\n * every collider, so scale world units up to match.\n */\nexport class CollisionWorld {\n readonly onCollisionStart = new Signal<CollisionPair>();\n readonly onCollisionEnd = new Signal<CollisionPair>();\n readonly onTriggerEnter = new Signal<CollisionPair>();\n readonly onTriggerExit = new Signal<CollisionPair>();\n\n private entries = new Map<number, CollisionEntry>();\n private spatial = createCollisionGrid();\n /**\n * Two pre-allocated pair buffers — swapped each step (no per-frame allocation).\n * Keys are packed numbers via `encodePair(a, b)`.\n */\n private pairBufA = new Set<number>();\n private pairBufB = new Set<number>();\n private activePairs: Set<number> = this.pairBufA;\n /** Reusable bounds rect — avoids a Rect allocation per add / setPosition. */\n private boundsBuf: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n /**\n * Add an entity with a shape. Positional twin of `addCollider`, and re-adding\n * follows the same rules.\n */\n add(\n entity: number,\n shape: Shape,\n x: number,\n y: number,\n isTrigger = false,\n layer = 1,\n mask = 0xffffffff,\n ): void {\n const b = shapeBoundsInto(shape, x, y, this.boundsBuf);\n const existing = this.entries.get(entity);\n if (existing === undefined) {\n const entry: CollisionEntry = {\n entity,\n shape,\n x,\n y,\n isTrigger,\n layer,\n mask,\n minX: 0,\n minY: 0,\n maxX: 0,\n maxY: 0,\n cxMin: 0,\n cxMax: 0,\n cyMin: 0,\n cyMax: 0,\n cellCount: 0,\n cells: [],\n groups: [],\n at: [],\n stamp: 0,\n };\n this.entries.set(entity, entry);\n gridInsert(this.spatial, entry, b.x, b.y, b.x + b.width, b.y + b.height);\n return;\n }\n\n // A re-add rewrites the entry the grid already links. It is unlinked first\n // and relinked after, even when it stays in the same cells: the grid files\n // an entry under its layer and mask, and both may be changing here.\n const wasTrigger = existing.isTrigger;\n gridUnlink(this.spatial, existing);\n existing.shape = shape;\n existing.x = x;\n existing.y = y;\n existing.isTrigger = isTrigger;\n existing.layer = layer;\n existing.mask = mask;\n gridRelink(this.spatial, existing, b.x, b.y, b.x + b.width, b.y + b.height);\n if (wasTrigger === isTrigger) return;\n\n // A pair is a trigger pair when either side is a trigger, so flipping this\n // side changes the kind only of pairs whose other side is solid. End those\n // now in their old family; the next step starts them in the new one.\n for (const key of this.activePairs) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n if (lo !== entity && hi !== entity) continue;\n const other = this.entries.get(lo === entity ? hi : lo);\n if (other?.isTrigger) continue;\n this.activePairs.delete(key);\n this.emitPair(lo, hi, wasTrigger, false);\n }\n }\n\n /**\n * Add an entity from a `Collider`. Its `shape`, `isTrigger`, `layer` and `mask`\n * are copied at add time — later edits to the collider do not reach the world;\n * re-add to change them. Re-adding an existing entity replaces its data.\n *\n * A re-add that flips `isTrigger` ends, during this call, every active pair\n * whose kind that changes, with the exit signal of its old kind\n * (`onTriggerExit` or `onCollisionEnd`). If the shapes still overlap, the next\n * `step` starts the pair again with the enter signal of its new kind. A pair\n * whose other side is a trigger stays a trigger pair and is left alone.\n */\n addCollider(entity: number, collider: Collider, x: number, y: number): void {\n this.add(entity, collider.shape, x, y, collider.isTrigger, collider.layer, collider.mask);\n }\n\n /** Remove an entity from the world. Emits exit signals for any active pairs. */\n remove(entity: number): void {\n const entry = this.entries.get(entity);\n if (!entry) return;\n\n this.entries.delete(entity);\n gridRemove(this.spatial, entry);\n\n // Fire exit signals for all active pairs involving this entity\n for (const key of this.activePairs) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n if (lo !== entity && hi !== entity) continue;\n this.activePairs.delete(key);\n const other = this.entries.get(lo === entity ? hi : lo);\n // The removed entry is passed in: it is already gone from `entries`.\n this.emitPair(lo, hi, entry.isTrigger || other?.isTrigger === true, false);\n }\n }\n\n /** Update an entity's position. */\n setPosition(entity: number, x: number, y: number): void {\n const entry = this.entries.get(entity);\n if (!entry) return;\n entry.x = x;\n entry.y = y;\n const b = shapeBoundsInto(entry.shape, x, y, this.boundsBuf);\n gridMove(this.spatial, entry, b.x, b.y, b.x + b.width, b.y + b.height);\n }\n\n /** Number of entities in the world. */\n get size(): number {\n return this.entries.size;\n }\n\n /** Number of broadphase records (one per live entity after add/remove). Diagnostic for broadphase growth. */\n get broadphaseSize(): number {\n return this.spatial.size;\n }\n\n /** Run one collision detection step. */\n step(): void {\n const newPairs = this.activePairs === this.pairBufA ? this.pairBufB : this.pairBufA;\n newPairs.clear();\n const grid = this.spatial;\n\n // A pair is recorded from its lower id, so `a` only looks for higher ids.\n for (const a of this.entries.values()) {\n const entityA = a.entity;\n const layerA = a.layer;\n const maskA = a.mask;\n const cells = a.cells;\n const cellCount = a.cellCount;\n // Two bodies can share several cells; one cell needs no duplicate check.\n const gen = cellCount > 1 ? ++grid.gen : 0;\n\n for (let c = 0; c < cellCount; c++) {\n const groups = cells[c]!.groups;\n for (let g = 0; g < groups.length; g++) {\n const group = groups[g]!;\n // Layer/mask filtering, once for the whole group: every body in it\n // carries exactly this layer and mask, so a group that fails holds\n // no pair for `a`, and one that passes is walked in full.\n if ((layerA & group.mask) === 0 && (group.layer & maskA) === 0) continue;\n\n const items = group.items;\n for (let i = 0; i < items.length; i++) {\n const b = items[i]!;\n if (b.entity <= entityA) continue; // Avoid self and duplicates\n\n if (cellCount > 1) {\n if (b.stamp === gen) continue;\n b.stamp = gen;\n }\n\n // Bounding boxes (strictly overlapping), then narrowphase\n const boxes = b.maxX > a.minX && b.minX < a.maxX && b.maxY > a.minY && b.minY < a.maxY;\n if (!boxes) continue;\n if (!shapeOverlap(a.shape, a.x, a.y, b.shape, b.x, b.y)) continue;\n\n newPairs.add(encodePair(entityA, b.entity));\n }\n }\n }\n }\n\n // Enter/start events — pair objects are allocated here only on state transitions.\n for (const key of newPairs) {\n if (!this.activePairs.has(key)) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n this.emitPair(lo, hi, this.isTriggerPair(lo, hi), true);\n }\n }\n\n // Exit/end events\n for (const key of this.activePairs) {\n if (!newPairs.has(key)) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n this.emitPair(lo, hi, this.isTriggerPair(lo, hi), false);\n }\n }\n\n this.activePairs = newPairs;\n }\n\n /** A pair is a trigger pair when either of its entities is a trigger. */\n private isTriggerPair(lo: number, hi: number): boolean {\n return this.entries.get(lo)?.isTrigger === true || this.entries.get(hi)?.isTrigger === true;\n }\n\n /**\n * The one place that emits a pair's enter or exit signal, in the trigger or\n * the collision family. `trigger` is passed in rather than looked up because\n * `remove` and a re-add classify by data `entries` no longer holds: the\n * removed entry, and the `isTrigger` the entity had before the re-add.\n */\n private emitPair(lo: number, hi: number, trigger: boolean, entering: boolean): void {\n const pair: CollisionPair = { entityA: lo, entityB: hi };\n if (trigger) {\n if (entering) this.onTriggerEnter.emit(pair);\n else this.onTriggerExit.emit(pair);\n } else if (entering) {\n this.onCollisionStart.emit(pair);\n } else {\n this.onCollisionEnd.emit(pair);\n }\n }\n\n /** Zero-alloc collider bounds — writes the AABB of entity's shape into `out`. Returns null when entity is absent. */\n getColliderBoundsInto(entity: number, out: Rect): Rect | null {\n const entry = this.entries.get(entity);\n if (!entry) return null;\n shapeBoundsInto(entry.shape, entry.x, entry.y, out);\n return out;\n }\n\n /** Allocating convenience wrapper — returns a fresh Rect or null when entity is absent. */\n getColliderBounds(entity: number): Rect | null {\n const entry = this.entries.get(entity);\n if (!entry) return null;\n return shapeBoundsInto(entry.shape, entry.x, entry.y, { x: 0, y: 0, width: 0, height: 0 });\n }\n\n /** Remove all entities. */\n clear(): void {\n this.entries.clear();\n gridClear(this.spatial);\n this.pairBufA.clear();\n this.pairBufB.clear();\n this.activePairs = this.pairBufA;\n }\n\n /** Reused across raycasts — see `raycast`. */\n private raycastCandidates: CollisionEntry[] = [];\n private raycastHit: RaycastHit = {\n entity: -1,\n distance: 0,\n point: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n };\n\n /**\n * Cast a ray against the colliders in this world.\n *\n * The standalone `raycast()` export tests a caller-supplied target array, so\n * it neither sees the world's colliders nor benefits from the broadphase — an\n * O(n) scan sitting beside an O(1) index. This walks only the cells the ray's\n * bounding box touches.\n *\n * `mask` is a layer bitmask filtered against each collider's `layer`, using the\n * bits colliders already carry; it defaults to every layer. Triggers are\n * included — a ray asking \"what is over there\" wants them.\n *\n * A ray that starts inside a collider hits that collider at its exit\n * distance, not at 0. The hit's `normal` is then the outward normal of the\n * face the ray entered through behind its origin for a box, and the outward\n * normal at the exit point for a circle. To skip the collider a ray starts in,\n * put it on a layer `mask` leaves out, or start the ray just past its edge: a\n * ray that starts exactly on the edge still hits it, at distance 0.\n *\n * The returned record is **reused between calls**: read it, or copy what you\n * need, before casting again. That is what keeps a per-frame ray allocation-\n * free; the standalone helper by contrast returns a fresh hit from each call\n * that hits, which the caller may keep.\n *\n * `maxDist` must be finite — this requires a bounded ray, not the\n * `Number.POSITIVE_INFINITY` \"unbounded ray\" idiom some engines accept. The\n * broadphase below is a uniform grid: an infinite `maxDist` derives an\n * infinite cell range and never terminates the walk. Pass a large finite\n * bound instead (e.g. the map's diagonal) to cast \"until it leaves the\n * populated area\". A non-finite `maxDist` returns `null`.\n */\n raycast(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n mask = 0xffffffff,\n ): RaycastHit | null {\n if (!Number.isFinite(maxDist)) return null;\n\n // Bounding box of the whole ray — the broadphase is rect-based, so this is\n // a conservative prefilter, not the intersection test itself.\n const ex = ox + dx * maxDist;\n const ey = oy + dy * maxDist;\n const minX = ox < ex ? ox : ex;\n const minY = oy < ey ? oy : ey;\n // Padded so the rect always has non-zero extent on both axes. An axis-\n // aligned ray is otherwise degenerate — a horizontal ray has height 0 — and\n // SpatialIndex derives its cell range with an exclusive end (`_cMax` is\n // `ceil(v / CELL) - 1`), so a zero-height rect yields cyMin 0 > cyMax -1 and\n // the cell loop never runs. The broadphase is a conservative prefilter\n // anyway, so over-including by a hair costs nothing: the exact ray test\n // below rejects the extras.\n const qMinX = minX - RAY_BOUNDS_PAD;\n const qMinY = minY - RAY_BOUNDS_PAD;\n const qMaxX = qMinX + (Math.abs(ex - ox) + RAY_BOUNDS_PAD * 2);\n const qMaxY = qMinY + (Math.abs(ey - oy) + RAY_BOUNDS_PAD * 2);\n\n const candidates = this.raycastCandidates;\n candidates.length = 0;\n gridQuery(this.spatial, qMinX, qMinY, qMaxX, qMaxY, candidates);\n\n let bestDist = Number.POSITIVE_INFINITY;\n let found = false;\n for (let i = 0; i < candidates.length; i++) {\n const entry = candidates[i]!;\n if ((entry.layer & mask) === 0) continue;\n const hit = rayVsShapeInto(\n ox,\n oy,\n dx,\n dy,\n maxDist,\n entry.entity,\n entry.shape,\n entry.x,\n entry.y,\n this.scratchHit,\n );\n if (hit !== null && hit.distance < bestDist) {\n bestDist = hit.distance;\n found = true;\n this.raycastHit.entity = hit.entity;\n this.raycastHit.distance = hit.distance;\n this.raycastHit.point.x = hit.point.x;\n this.raycastHit.point.y = hit.point.y;\n this.raycastHit.normal.x = hit.normal.x;\n this.raycastHit.normal.y = hit.normal.y;\n }\n }\n return found ? this.raycastHit : null;\n }\n\n /** Scratch record handed to `rayVsShapeInto` per candidate. */\n private scratchHit: RaycastHit = {\n entity: -1,\n distance: 0,\n point: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n };\n}\n","import type { Rect } from '@flare-engine/math';\n\n/**\n * A pixel mask: the bounds of its solid region inside a sprite frame, in frame\n * px from the frame's top-left corner, and its rows as 32-bit words —\n * `Math.ceil(w / 32)` per row, top row first. Bit `c & 31` of word `c >>> 5`\n * holds column `c` of the bounds; a set bit is solid. `x` / `y` are the offset\n * that lets a mask sit anywhere relative to its pose's pivot.\n *\n * It is not a member of the `Shape` union and `CollisionWorld` does not take\n * one: keep a box collider for the broadphase and refine its pairs with the\n * `mask…` functions.\n */\nexport interface MaskShape {\n readonly x: number;\n readonly y: number;\n readonly w: number;\n readonly h: number;\n readonly words: ArrayLike<number>;\n}\n\n/**\n * Where a mask is in the world: the entity's position (`x`, `y`), the cosine\n * and sine of its turn (radians, clockwise with y down, as a sprite is turned\n * about its anchor), the pivot (`px`, `py`) in frame px — the point of the\n * frame that sits on the position — and `unit`, world units per px (above 0).\n */\nexport interface MaskPose {\n x: number;\n y: number;\n cos: number;\n sin: number;\n px: number;\n py: number;\n unit: number;\n}\n\n/** An unturned pose at the origin: pivot at the frame's corner, 1 unit per px. */\nexport function createMaskPose(): MaskPose {\n return { x: 0, y: 0, cos: 1, sin: 0, px: 0, py: 0, unit: 1 };\n}\n\n/**\n * Build a mask from rows of text, top row first: `#` is solid, any other\n * character clear. The bounds are the whole drawing — as wide as the longest\n * row — placed at (`x`, `y`) in the frame. Allocates; call at load.\n */\nexport function createMaskShape(rows: readonly string[], x = 0, y = 0): MaskShape {\n let w = 0;\n for (const row of rows) w = Math.max(w, row.length);\n const stride = (w + 31) >>> 5;\n const words = new Uint32Array(rows.length * stride);\n for (let r = 0; r < rows.length; r++) {\n const row = rows[r]!;\n for (let c = 0; c < row.length; c++) {\n if (row[c] === '#') words[r * stride + (c >>> 5)]! |= 1 << (c & 31);\n }\n }\n return { x, y, w, h: rows.length, words };\n}\n\nfunction has(m: MaskShape, col: number, row: number): boolean {\n const cx = col - m.x;\n const cy = row - m.y;\n if (cx < 0 || cy < 0 || cx >= m.w || cy >= m.h) return false;\n const word = m.words[cy * ((m.w + 31) >>> 5) + (cx >>> 5)] ?? 0;\n return ((word >>> (cx & 31)) & 1) === 1;\n}\n\n/**\n * Whether the pixel at frame column `col`, row `row` (integers) is solid;\n * outside the bounds nothing is. With `erode`, solid only when its four\n * neighbours are solid too: the mask eroded by 1 px. Zero-alloc.\n */\nexport function isMaskSolidAt(m: MaskShape, col: number, row: number, erode = false): boolean {\n if (!has(m, col, row)) return false;\n if (!erode) return true;\n return (\n has(m, col - 1, row) && has(m, col + 1, row) && has(m, col, row - 1) && has(m, col, row + 1)\n );\n}\n\n/** The frame px of a world point, by the inverse turn. */\nconst LOCAL = { x: 0, y: 0 };\nfunction toLocal(p: MaskPose, wx: number, wy: number): void {\n const dx = wx - p.x;\n const dy = wy - p.y;\n LOCAL.x = (dx * p.cos + dy * p.sin) / p.unit + p.px;\n LOCAL.y = (-dx * p.sin + dy * p.cos) / p.unit + p.py;\n}\n\n/**\n * The world bounding box of a posed mask's bounds rectangle: for a turned mask,\n * the axis-aligned box around the turned rectangle. It bounds every solid pixel\n * but is not shrunk to them. Zero-alloc — writes `out` and returns it.\n */\nexport function maskBoundsInto(m: MaskShape, p: MaskPose, out: Rect): Rect {\n const lx = m.x + m.w / 2 - p.px;\n const ly = m.y + m.h / 2 - p.py;\n const ac = Math.abs(p.cos);\n const as = Math.abs(p.sin);\n const hw = ((m.w * ac + m.h * as) / 2) * p.unit;\n const hh = ((m.w * as + m.h * ac) / 2) * p.unit;\n out.x = p.x + (lx * p.cos - ly * p.sin) * p.unit - hw;\n out.y = p.y + (lx * p.sin + ly * p.cos) * p.unit - hh;\n out.width = hw * 2;\n out.height = hh * 2;\n return out;\n}\n\n/** Allocating twin of `maskBoundsInto`. */\nexport function maskBounds(m: MaskShape, p: MaskPose): Rect {\n return maskBoundsInto(m, p, { x: 0, y: 0, width: 0, height: 0 });\n}\n\n/**\n * Whether a world box, centre (`cx`, `cy`) and half extents (`hw`, `hh`),\n * overlaps a solid pixel. Touching an edge is not overlapping. `erode` tests\n * the mask eroded by 1 px.\n *\n * The box is axis-aligned in the world, so against a turned mask it is tested\n * by its bounding box in the mask's frame: exact for a turn that is a multiple\n * of a quarter, generous by the box's corners for any other. Zero-alloc.\n */\nexport function maskOverlapsBox(\n m: MaskShape,\n p: MaskPose,\n cx: number,\n cy: number,\n hw: number,\n hh: number,\n erode = false,\n): boolean {\n toLocal(p, cx, cy);\n const ac = Math.abs(p.cos);\n const as = Math.abs(p.sin);\n const lhw = (hw * ac + hh * as) / p.unit;\n const lhh = (hw * as + hh * ac) / p.unit;\n const x0 = LOCAL.x - lhw;\n const x1 = LOCAL.x + lhw;\n const y0 = LOCAL.y - lhh;\n const y1 = LOCAL.y + lhh;\n const c0 = Math.max(m.x, Math.floor(x0));\n const c1 = Math.min(m.x + m.w - 1, Math.ceil(x1) - 1);\n const r0 = Math.max(m.y, Math.floor(y0));\n const r1 = Math.min(m.y + m.h - 1, Math.ceil(y1) - 1);\n for (let r = r0; r <= r1; r++) {\n if (!(r < y1 && r + 1 > y0)) continue;\n for (let c = c0; c <= c1; c++) {\n if (c < x1 && c + 1 > x0 && isMaskSolidAt(m, c, r, erode)) return true;\n }\n }\n return false;\n}\n\n/** The most samples one sweep takes, so a runaway segment cannot stall a frame. */\nconst SWEEP_MAX = 256;\n\n/**\n * Whether a box swept from (`x0`, `y0`) to (`x1`, `y1`) overlaps a solid pixel\n * anywhere along the segment, so a fast body cannot skip a 1 px feature. It is\n * `maskOverlapsBox` sampled along the segment, both ends included: samples are\n * at most half a px apart, and at most the box's smaller non-zero half extent.\n * A sweep is capped at 257 samples; a segment too long for that spacing is\n * sampled more coarsely and can miss. Zero-alloc.\n */\nexport function maskOverlapsSweptBox(\n m: MaskShape,\n p: MaskPose,\n x0: number,\n y0: number,\n x1: number,\n y1: number,\n hw: number,\n hh: number,\n): boolean {\n const len = Math.hypot(x1 - x0, y1 - y0);\n let step = 0.5 * p.unit;\n if (hw > 0 && hw < step) step = hw;\n if (hh > 0 && hh < step) step = hh;\n const n = Math.min(SWEEP_MAX, Math.ceil(len / step));\n for (let i = 0; i <= n; i++) {\n const t = n === 0 ? 1 : i / n;\n if (maskOverlapsBox(m, p, x0 + (x1 - x0) * t, y0 + (y1 - y0) * t, hw, hh)) return true;\n }\n return false;\n}\n\n/**\n * Whether a world circle overlaps a solid pixel. The circle is taken into the\n * mask's frame, where it is still a circle, and tested against each pixel's\n * square, so the result is exact at any turn. Strict, like `shapeOverlap`:\n * touching is not overlapping, and a zero radius hits only strictly inside a\n * pixel. Zero-alloc.\n */\nexport function maskOverlapsCircle(\n m: MaskShape,\n p: MaskPose,\n cx: number,\n cy: number,\n radius: number,\n): boolean {\n toLocal(p, cx, cy);\n const lx = LOCAL.x;\n const ly = LOCAL.y;\n const lr = radius / p.unit;\n const rr = lr * lr;\n const c0 = Math.max(m.x, Math.floor(lx - lr));\n const c1 = Math.min(m.x + m.w - 1, Math.ceil(lx + lr) - 1);\n const r0 = Math.max(m.y, Math.floor(ly - lr));\n const r1 = Math.min(m.y + m.h - 1, Math.ceil(ly + lr) - 1);\n for (let r = r0; r <= r1; r++) {\n const dy = ly < r ? r - ly : ly > r + 1 ? ly - r - 1 : 0;\n for (let c = c0; c <= c1; c++) {\n if (!has(m, c, r)) continue;\n const dx = lx < c ? c - lx : lx > c + 1 ? lx - c - 1 : 0;\n const dd = dx * dx + dy * dy;\n if (dd > 0 ? dd < rr : lr > 0 || (lx > c && lx < c + 1 && ly > r && ly < r + 1)) return true;\n }\n }\n return false;\n}\n\nconst BOUNDS: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n/**\n * Whether a solid pixel of `a` overlaps a solid pixel of `b`. Each pose may be\n * turned and scaled independently. Every solid pixel of one mask inside the\n * other's world bounds is taken into the other's frame as a turned square and\n * tested against the solid pixels there by separating axes, so pixels are\n * compared as the squares they are, not by bounding boxes: exact up to\n * floating-point rounding. Touching is not overlapping; for masks at different\n * turns a contact within rounding of touching can read either way.\n *\n * Cost grows with the pixels of both masks inside the overlap of their bounds\n * — this is the narrow phase for a pair a box broadphase already passed.\n * Zero-alloc.\n */\nexport function maskOverlapsMask(a: MaskShape, pa: MaskPose, b: MaskShape, pb: MaskPose): boolean {\n // Walk the mask with fewer pixels; the result is the same either way.\n return a.w * a.h <= b.w * b.h ? pixelsOverlap(a, pa, b, pb) : pixelsOverlap(b, pb, a, pa);\n}\n\nfunction pixelsOverlap(a: MaskShape, pa: MaskPose, b: MaskShape, pb: MaskPose): boolean {\n // The pixels of `a` that can reach `b`: those under b's world bounds, taken\n // into a's frame as a bounding box.\n maskBoundsInto(b, pb, BOUNDS);\n const bhw = BOUNDS.width / 2;\n const bhh = BOUNDS.height / 2;\n toLocal(pa, BOUNDS.x + bhw, BOUNDS.y + bhh);\n const lhw = (bhw * Math.abs(pa.cos) + bhh * Math.abs(pa.sin)) / pa.unit;\n const lhh = (bhw * Math.abs(pa.sin) + bhh * Math.abs(pa.cos)) / pa.unit;\n const c0 = Math.max(a.x, Math.floor(LOCAL.x - lhw));\n const c1 = Math.min(a.x + a.w - 1, Math.ceil(LOCAL.x + lhw) - 1);\n const r0 = Math.max(a.y, Math.floor(LOCAL.y - lhh));\n const r1 = Math.min(a.y + a.h - 1, Math.ceil(LOCAL.y + lhh) - 1);\n if (c0 > c1 || r0 > r1) return false;\n\n // a's frame to b's: a turn by the difference of the two turns, scaled by the\n // ratio of the units, about the two pivots.\n const k = pa.unit / pb.unit;\n const cosR = pa.cos * pb.cos + pa.sin * pb.sin;\n const sinR = pa.sin * pb.cos - pa.cos * pb.sin;\n const mc = cosR * k;\n const ms = sinR * k;\n toLocal(pb, pa.x, pa.y);\n const tx = LOCAL.x - (mc * pa.px - ms * pa.py);\n const ty = LOCAL.y - (ms * pa.px + mc * pa.py);\n // An a pixel in b's frame is a square of half side `half` turned by R; a b\n // pixel is an unturned unit square. `ext` is the reach of the turned square\n // on b's axes plus the b pixel's half; `own` the same on the square's axes.\n const half = k / 2;\n const spread = Math.abs(cosR) + Math.abs(sinR);\n const ext = half * spread + 0.5;\n const own = half + 0.5 * spread;\n const bc0 = b.x;\n const bc1 = b.x + b.w - 1;\n const br0 = b.y;\n const br1 = b.y + b.h - 1;\n\n for (let r = r0; r <= r1; r++) {\n for (let c = c0; c <= c1; c++) {\n if (!has(a, c, r)) continue;\n const bx = tx + mc * (c + 0.5) - ms * (r + 0.5);\n const by = ty + ms * (c + 0.5) + mc * (r + 0.5);\n const q0 = Math.max(bc0, Math.floor(bx - ext));\n const q1 = Math.min(bc1, Math.ceil(bx + ext) - 1);\n const s0 = Math.max(br0, Math.floor(by - ext));\n const s1 = Math.min(br1, Math.ceil(by + ext) - 1);\n for (let s = s0; s <= s1; s++) {\n const dy = s + 0.5 - by;\n if (!(Math.abs(dy) < ext)) continue;\n for (let q = q0; q <= q1; q++) {\n const dx = q + 0.5 - bx;\n if (\n Math.abs(dx) < ext &&\n Math.abs(dx * cosR + dy * sinR) < own &&\n Math.abs(dy * cosR - dx * sinR) < own &&\n has(b, q, s)\n ) {\n return true;\n }\n }\n }\n }\n }\n return false;\n}\n\n/**\n * The distance along a world ray from (`ox`, `oy`), unit direction (`dx`,\n * `dy`), to the first solid pixel it enters, at most `len`; `0` when it starts\n * inside one; `-1` when it meets none. A grid walk over the mask's pixels in\n * its own frame, so the distance is exact at any turn. Zero-alloc.\n *\n * Unlike `rayVsShapeInto` it reports a distance only — no point, no normal —\n * and a ray starting inside a solid pixel reads `0` rather than its exit.\n */\nexport function rayVsMask(\n m: MaskShape,\n p: MaskPose,\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n len: number,\n): number {\n toLocal(p, ox, oy);\n const lx = LOCAL.x;\n const ly = LOCAL.y;\n const ldx = dx * p.cos + dy * p.sin;\n const ldy = -dx * p.sin + dy * p.cos;\n // Clip to the mask's bounds: the slab test, in px along the ray.\n let t0 = 0;\n let t1 = len / p.unit;\n if (ldx === 0) {\n if (lx < m.x || lx >= m.x + m.w) return -1;\n } else {\n const ta = (m.x - lx) / ldx;\n const tb = (m.x + m.w - lx) / ldx;\n t0 = Math.max(t0, Math.min(ta, tb));\n t1 = Math.min(t1, Math.max(ta, tb));\n }\n if (ldy === 0) {\n if (ly < m.y || ly >= m.y + m.h) return -1;\n } else {\n const ta = (m.y - ly) / ldy;\n const tb = (m.y + m.h - ly) / ldy;\n t0 = Math.max(t0, Math.min(ta, tb));\n t1 = Math.min(t1, Math.max(ta, tb));\n }\n if (t0 > t1) return -1;\n // Step into the first pixel a hair, so a ray starting on an edge is in the pixel ahead.\n const sx = lx + ldx * t0;\n const sy = ly + ldy * t0;\n let c = Math.min(m.x + m.w - 1, Math.max(m.x, Math.floor(sx + ldx * 1e-9)));\n let r = Math.min(m.y + m.h - 1, Math.max(m.y, Math.floor(sy + ldy * 1e-9)));\n const stepC = ldx > 0 ? 1 : -1;\n const stepR = ldy > 0 ? 1 : -1;\n const dtC = ldx === 0 ? Number.POSITIVE_INFINITY : Math.abs(1 / ldx);\n const dtR = ldy === 0 ? Number.POSITIVE_INFINITY : Math.abs(1 / ldy);\n let nextC = ldx === 0 ? Number.POSITIVE_INFINITY : t0 + ((ldx > 0 ? c + 1 : c) - sx) / ldx;\n let nextR = ldy === 0 ? Number.POSITIVE_INFINITY : t0 + ((ldy > 0 ? r + 1 : r) - sy) / ldy;\n let t = t0;\n const cells = m.w + m.h + 2;\n for (let i = 0; i < cells && t <= t1; i++) {\n if (has(m, c, r)) return t * p.unit;\n if (nextC < nextR) {\n t = nextC;\n nextC += dtC;\n c += stepC;\n } else {\n t = nextR;\n nextR += dtR;\n r += stepR;\n }\n if (c < m.x || c >= m.x + m.w || r < m.y || r >= m.y + m.h) return -1;\n }\n return -1;\n}\n\n/**\n * Where a beam filling the world rect [`x0`, `x1`] × [`y0`, `y1`] and\n * travelling along one axis — (`dirX`, `dirY`) is one of (0, -1), (0, 1),\n * (1, 0) and (-1, 0) — first meets the mask: the near edge of the nearest\n * solid pixel that overlaps the rect, as a world coordinate on the beam's\n * axis. `NaN` when no solid pixel overlaps it. A turned pixel counts by its\n * bounding box. Visits every pixel of the mask. Zero-alloc.\n */\nexport function maskStripStop(\n m: MaskShape,\n p: MaskPose,\n x0: number,\n y0: number,\n x1: number,\n y1: number,\n dirX: number,\n dirY: number,\n): number {\n let stop = Number.NaN;\n const u = p.unit;\n // A pixel's bounding box is square at any turn.\n const h = ((Math.abs(p.cos) + Math.abs(p.sin)) * u) / 2;\n const far = dirY < 0 || (dirY === 0 && dirX < 0);\n for (let r = m.y; r < m.y + m.h; r++) {\n for (let c = m.x; c < m.x + m.w; c++) {\n if (!has(m, c, r)) continue;\n const lx = c + 0.5 - p.px;\n const ly = r + 0.5 - p.py;\n const wx = p.x + (lx * p.cos - ly * p.sin) * u;\n const wy = p.y + (lx * p.sin + ly * p.cos) * u;\n if (!(wx - h < x1 && wx + h > x0 && wy - h < y1 && wy + h > y0)) continue;\n const edge = dirY < 0 ? wy + h : dirY > 0 ? wy - h : dirX > 0 ? wx - h : wx + h;\n if (Number.isNaN(stop)) stop = edge;\n else stop = far ? Math.max(stop, edge) : Math.min(stop, edge);\n }\n }\n return stop;\n}\n","import type { Vec2 } from '@flare-engine/math';\n\n/**\n * Minimal structural type for a solid tile position in grid coordinates.\n * `TileCollider[]` from `@flare-engine/tilemap` is structurally assignable here\n * so callers can pass `extractColliders(map)` directly — no tilemap dep needed.\n */\nexport interface SolidTile {\n readonly row: number;\n readonly col: number;\n}\n\n/**\n * How `isBlockedAABB` treats cells outside the grid.\n * `'solid'` — the map edge is a wall; any box that leaves the map is blocked.\n * `'open'` — cells outside the grid are empty, so a body can walk off the map;\n * use it for seams between adjacent region maps.\n */\nexport type SolidGridOutside = 'solid' | 'open';\n\nexport interface SolidGridOptions {\n /** Defaults to `'solid'`. */\n readonly outside?: SolidGridOutside;\n}\n\n/**\n * Precomputed solid-tile lookup used by `isBlockedAABB` and `moveAndSlideInto`.\n * `solid` has `width * height` cells indexed `row * width + col`; non-zero means\n * solid. Build once per map load via `buildSolidGrid`.\n */\nexport interface SolidGrid {\n readonly width: number;\n readonly height: number;\n readonly tileSize: number;\n readonly solid: Uint8Array;\n readonly outside: SolidGridOutside;\n}\n\n/**\n * Build a `SolidGrid` from a list of solid tile positions.\n * Input is structurally typed (`readonly SolidTile[]`) so the caller does not\n * need to import `@flare-engine/tilemap` — physics stays tilemap-free.\n */\nexport function buildSolidGrid(\n width: number,\n height: number,\n tileSize: number,\n tiles: readonly SolidTile[],\n options?: SolidGridOptions,\n): SolidGrid {\n const solid = new Uint8Array(width * height);\n for (const t of tiles) {\n solid[t.row * width + t.col] = 1;\n }\n return { width, height, tileSize, solid, outside: options?.outside ?? 'solid' };\n}\n\n/**\n * Half-open boundary constant: the AABB is treated as [min, max) so a box\n * whose max edge lands exactly on a tile boundary does NOT overlap that tile.\n */\nconst EDGE = 1e-4;\n\n/**\n * Returns `true` when an axis-aligned box centered at (`x`, `y`) with\n * half-extents (`halfW`, `halfH`) overlaps a solid tile. Leaving the map\n * blocks only when the grid was built with `outside: 'solid'` (the default);\n * with `'open'` the out-of-grid cells are empty and only the in-grid cells the\n * box overlaps are tested. Uses half-open EDGE semantics on max edges.\n */\nexport function isBlockedAABB(\n grid: SolidGrid,\n x: number,\n y: number,\n halfW: number,\n halfH: number,\n): boolean {\n const ts = grid.tileSize;\n let minCol = Math.floor((x - halfW) / ts);\n let maxCol = Math.floor((x + halfW - EDGE) / ts);\n let minRow = Math.floor((y - halfH) / ts);\n let maxRow = Math.floor((y + halfH - EDGE) / ts);\n if (minCol < 0 || minRow < 0 || maxCol >= grid.width || maxRow >= grid.height) {\n if (grid.outside === 'solid') return true;\n // Clamp to the in-grid cells; a box fully outside yields an empty range.\n if (minCol < 0) minCol = 0;\n if (minRow < 0) minRow = 0;\n if (maxCol >= grid.width) maxCol = grid.width - 1;\n if (maxRow >= grid.height) maxRow = grid.height - 1;\n }\n for (let row = minRow; row <= maxRow; row++) {\n for (let col = minCol; col <= maxCol; col++) {\n if (grid.solid[row * grid.width + col] !== 0) {\n return true;\n }\n }\n }\n return false;\n}\n\n/**\n * Whether the cell at (`col`, `row`) is solid. Coordinates that name no cell\n * (out of range, or not an integer) follow the grid's own `outside` rule, like\n * `isBlockedAABB` at the map edge: solid on an `outside: 'solid'` grid, empty\n * on an `'open'` one. Zero-alloc.\n */\nexport function isSolidAt(grid: SolidGrid, col: number, row: number): boolean {\n if (!isCell(grid, col, row)) return grid.outside === 'solid';\n return grid.solid[row * grid.width + col] !== 0;\n}\n\n/**\n * Mark the cell at (`col`, `row`) solid or empty, for a door or a breakable\n * wall. Returns `true` when the cell was written, `false` (and writes nothing)\n * when the coordinates are out of range or not integers. Zero-alloc.\n */\nexport function setSolidAt(grid: SolidGrid, col: number, row: number, solid: boolean): boolean {\n if (!isCell(grid, col, row)) return false;\n grid.solid[row * grid.width + col] = solid ? 1 : 0;\n return true;\n}\n\nfunction isCell(grid: SolidGrid, col: number, row: number): boolean {\n return (\n Number.isInteger(col) &&\n Number.isInteger(row) &&\n col >= 0 &&\n col < grid.width &&\n row >= 0 &&\n row < grid.height\n );\n}\n\n/**\n * Axis-separated slide movement. Attempts to move by (`dx`, `dy`); each axis\n * is applied independently so a blocked diagonal input slides along the wall.\n * The y-check uses the already-updated x position.\n * Zero-alloc: writes result into the provided `out` Vec2 and returns it.\n */\nexport function moveAndSlideInto(\n grid: SolidGrid,\n x: number,\n y: number,\n dx: number,\n dy: number,\n halfW: number,\n halfH: number,\n out: Vec2,\n): Vec2 {\n let nx = x;\n let ny = y;\n if (dx !== 0 && !isBlockedAABB(grid, nx + dx, ny, halfW, halfH)) nx += dx;\n if (dy !== 0 && !isBlockedAABB(grid, nx, ny + dy, halfW, halfH)) ny += dy;\n out.x = nx;\n out.y = ny;\n return out;\n}\n","import type { Rect } from '@flare-engine/math';\nimport { cellKey, cellMax, cellMin } from './cells.js';\n\n// Internal entry: bounding rect (minX, minY, maxX, maxY) plus a per-query stamp\n// for zero-alloc dedup.\ninterface _Entry<T> {\n readonly item: T;\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n // The clamped cell range the entry is linked into. Cached so an update can\n // tell \"same cells\" without touching a bucket. A NaN bound leaves NaN here,\n // which equals nothing — such an entry is linked nowhere and always relinks.\n cxMin: number;\n cxMax: number;\n cyMin: number;\n cyMax: number;\n // This entry's position inside the bucket of each cell it occupies, indexed\n // `(cx - cxMin) * rows + (cy - cyMin)` with rows = cyMax - cyMin + 1. Lets\n // unlink swap-remove without searching the bucket. Grown, never reallocated.\n readonly _at: number[];\n _stamp: number;\n}\n\n/**\n * Uniform spatial-hash broadphase.\n * `insert`, `remove`, and `update` are O(cells touched) — O(1) for typical entities.\n * `query` walks only the cells overlapping the given rect; result order is unspecified.\n * Zero-alloc in the query hot-path: duplicate suppression uses a monotone stamp counter,\n * not a per-call Set.\n */\nexport class SpatialIndex<T> {\n private _data: _Entry<T>[] = [];\n private _slots = new Map<T, number>(); // item → dense-array slot\n private _cells = new Map<number, _Entry<T>[]>(); // packed cell key → bucket\n private _gen = 0; // monotone query-generation counter\n\n /** Number of items in the index. */\n get size(): number {\n return this._data.length;\n }\n\n /**\n * Insert an item with a bounding rect. Inserting an item already in the index\n * replaces its bounds (upsert) — same as `update`.\n */\n insert(item: T, bounds: Rect): void {\n if (this._slots.has(item)) {\n this.update(item, bounds);\n return;\n }\n const maxX = bounds.x + bounds.width;\n const maxY = bounds.y + bounds.height;\n const entry: _Entry<T> = {\n item,\n minX: bounds.x,\n minY: bounds.y,\n maxX,\n maxY,\n cxMin: cellMin(bounds.x),\n cxMax: cellMax(maxX),\n cyMin: cellMin(bounds.y),\n cyMax: cellMax(maxY),\n _at: [],\n _stamp: 0,\n };\n this._slots.set(item, this._data.length);\n this._data.push(entry);\n this._link(entry);\n }\n\n /** Remove an item. Returns false when the item was not present. */\n remove(item: T): boolean {\n const slot = this._slots.get(item);\n if (slot === undefined) return false;\n const entry = this._data[slot]!;\n this._unlink(entry);\n this._slots.delete(item);\n // Swap-remove: plug the hole with the last element.\n const last = this._data.pop()!;\n if (slot < this._data.length) {\n this._data[slot] = last;\n this._slots.set(last.item, slot);\n }\n return true;\n }\n\n /** Update the bounds for an existing item. No-op when the item is absent. */\n update(item: T, bounds: Rect): void {\n const slot = this._slots.get(item);\n if (slot === undefined) return;\n const entry = this._data[slot]!;\n const maxX = bounds.x + bounds.width;\n const maxY = bounds.y + bounds.height;\n entry.minX = bounds.x;\n entry.minY = bounds.y;\n entry.maxX = maxX;\n entry.maxY = maxY;\n\n const cxMin = cellMin(bounds.x);\n const cxMax = cellMax(maxX);\n const cyMin = cellMin(bounds.y);\n const cyMax = cellMax(maxY);\n // Same cells: the buckets already hold this entry, and a query reads the\n // bounds refreshed above.\n if (\n cxMin === entry.cxMin &&\n cxMax === entry.cxMax &&\n cyMin === entry.cyMin &&\n cyMax === entry.cyMax\n ) {\n return;\n }\n this._unlink(entry);\n entry.cxMin = cxMin;\n entry.cxMax = cxMax;\n entry.cyMin = cyMin;\n entry.cyMax = cyMax;\n this._link(entry);\n }\n\n /**\n * Query all items whose bounds overlap the given rect.\n * Result order is unspecified. Appends to `result` when provided and returns it.\n */\n query(bounds: Rect, result?: T[]): T[] {\n const out = result ?? [];\n const gen = ++this._gen;\n\n const qMinX = bounds.x;\n const qMinY = bounds.y;\n const qMaxX = bounds.x + bounds.width;\n const qMaxY = bounds.y + bounds.height;\n\n const cxMin = cellMin(qMinX);\n const cxMax = cellMax(qMaxX);\n const cyMin = cellMin(qMinY);\n const cyMax = cellMax(qMaxY);\n\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const bucket = this._cells.get(cellKey(cx, cy));\n if (bucket === undefined) continue;\n for (let i = 0; i < bucket.length; i++) {\n const e = bucket[i]!;\n if (e._stamp === gen) continue; // already emitted this query\n e._stamp = gen;\n if (e.maxX > qMinX && e.minX < qMaxX && e.maxY > qMinY && e.minY < qMaxY) {\n out.push(e.item);\n }\n }\n }\n }\n return out;\n }\n\n /** Remove all items. */\n clear(): void {\n this._data.length = 0;\n this._slots.clear();\n this._cells.clear();\n }\n\n // Register entry in every cell of its cached range, recording where in each\n // bucket it landed.\n private _link(entry: _Entry<T>): void {\n const { cxMin, cxMax, cyMin, cyMax, _at } = entry;\n let n = 0;\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const k = cellKey(cx, cy);\n let b = this._cells.get(k);\n if (b === undefined) {\n b = [];\n this._cells.set(k, b);\n }\n _at[n++] = b.length;\n b.push(entry);\n }\n }\n }\n\n // Remove entry from every cell of its cached range. O(1) per cell: the last\n // entry of the bucket takes the vacated position, and its own record of where\n // it sits in this cell is corrected to match.\n private _unlink(entry: _Entry<T>): void {\n const { cxMin, cxMax, cyMin, cyMax, _at } = entry;\n let n = 0;\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const i = _at[n++]!;\n const b = this._cells.get(cellKey(cx, cy));\n if (b === undefined) continue;\n const last = b.pop()!;\n if (last === entry) continue;\n b[i] = last;\n last._at[(cx - last.cxMin) * (last.cyMax - last.cyMin + 1) + (cy - last.cyMin)] =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O,QAAQ;EAC5C,IAAI,IAAI;EACR,KAAK,IAAI,KAAK,OAAO,MAAM,OAAO,MAChC,KAAK,IAAI,KAAK,OAAO,MAAM,OAAO,MAAM;GACtC,MAAM,IAAI,IAAI;GACd,MAAM,IAAI,KAAK,OAAO,IAAI,QAAQ,IAAI,EAAE,CAAC;GACzC,IAAI,MAAM,KAAA,GAAW;GACrB,MAAM,OAAO,EAAE,IAAI;GACnB,IAAI,SAAS,OAAO;GACpB,EAAE,KAAK;GACP,KAAK,KAAK,KAAK,KAAK,UAAU,KAAK,QAAQ,KAAK,QAAQ,MAAM,KAAK,KAAK,UAAU;EACpF;CAEJ;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flare-engine/physics",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.19",
|
|
4
4
|
"description": "AABB collision, spatial index, raycasting",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"flare-engine",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"typecheck": "tsc --noEmit"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@flare-engine/events": "^0.4.
|
|
50
|
-
"@flare-engine/math": "^0.4.
|
|
49
|
+
"@flare-engine/events": "^0.4.19",
|
|
50
|
+
"@flare-engine/math": "^0.4.19"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=20"
|