@flare-engine/math 0.4.11 → 0.4.13
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 +1 -1
- package/dist/index.d.mts +24 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +24 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +175 -138
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +175 -139
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @flare-engine/math
|
|
2
2
|
|
|
3
|
-
2D math primitives for the Flare engine — `Vec2`, `Rect`, `Circle`, `Transform2D`, `Mat3`, `Color
|
|
3
|
+
2D math primitives for the Flare engine — `Vec2`, `Rect`, `Circle`, `Transform2D`, `Mat3`, `Color` (plus `argbToFloat4Into` for packed `0xAARRGGBB` ints), 35 easing functions, seeded RNG, intersection tests, angle/steering helpers (`angleDelta`, `rotateTowards`, `Vec2.turnVelocityTowardInto`, `Vec2.scaleToLengthInto`, `Vec2.perp`, `Vec2.crossSV`), weighted random picks (`weightedIndex`, `weightedIndexBy`, `weightedPick`), deterministic hash utils (`hashU32`, `seededIndex`), and timed-window reward math (`cappedBonus`, `advanceWindowedStreak`, `windowExpired`, `remainingInWindow`). Plain-object types with static method namespaces; zero-alloc forms take an `out` parameter to avoid GC pressure in game loops.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
package/dist/index.d.mts
CHANGED
|
@@ -41,7 +41,10 @@ export declare const Vec2: {
|
|
|
41
41
|
readonly crossSV: (s: number, v: Vec2, out?: Vec2) => Vec2;
|
|
42
42
|
/** Linearly interpolates between a and b (unclamped). */
|
|
43
43
|
readonly lerp: (a: Vec2, b: Vec2, t: number, out?: Vec2) => Vec2;
|
|
44
|
-
/** Spherical linear interpolation for unit vectors.
|
|
44
|
+
/** Spherical linear interpolation for unit vectors. Antiparallel inputs (angle within 1e-6 of
|
|
45
|
+
* π) have no unique shortest arc, so `a` is rotated by `t·π` turning toward `Vec2.perp(a)` —
|
|
46
|
+
* clockwise in y-down screen space — and `t = 0.5` yields `Vec2.perp(a)`. `t = 0` and `t = 1`
|
|
47
|
+
* return `a` and `b` exactly. Writes into out if provided. */
|
|
45
48
|
readonly slerp: (a: Vec2, b: Vec2, t: number, out?: Vec2) => Vec2;
|
|
46
49
|
/** Euclidean distance between two points. */
|
|
47
50
|
readonly distance: (a: Vec2, b: Vec2) => number;
|
|
@@ -164,6 +167,12 @@ export declare const Color: {
|
|
|
164
167
|
/** WCAG 2.x contrast ratio. Order-independent; range [1, 21]. */
|
|
165
168
|
readonly contrastRatio: (fg: Color, bg: Color) => number;
|
|
166
169
|
};
|
|
170
|
+
/**
|
|
171
|
+
* Unpacks a 32-bit `0xAARRGGBB` int (the `Color.toSkColor` format) into `out`
|
|
172
|
+
* as `[r, g, b, a]`, each 0-1: the layout Skia paints and `clear` take.
|
|
173
|
+
* Zero-alloc.
|
|
174
|
+
*/
|
|
175
|
+
export declare function argbToFloat4Into(out: Float32Array, argb: number): void;
|
|
167
176
|
/**
|
|
168
177
|
* Parametric curves — quadratic/cubic Bézier and Catmull-Rom — plus approximate
|
|
169
178
|
* arc length for each.
|
|
@@ -244,8 +253,14 @@ export declare function easeInOutElastic(t: number): number;
|
|
|
244
253
|
export declare function easeOutBounce(t: number): number;
|
|
245
254
|
export declare function easeInBounce(t: number): number;
|
|
246
255
|
export declare function easeInOutBounce(t: number): number;
|
|
256
|
+
/** Alias of {@link easeInBack}, kept for compatibility. A Back curve, not a damped spring. */
|
|
247
257
|
export declare function springIn(t: number): number;
|
|
258
|
+
/** Alias of {@link easeOutBack}, kept for compatibility. A Back curve, not a damped spring. */
|
|
248
259
|
export declare function springOut(t: number): number;
|
|
260
|
+
/**
|
|
261
|
+
* The Back in-out curve under a second name, kept for compatibility. A Back
|
|
262
|
+
* curve, not a damped spring.
|
|
263
|
+
*/
|
|
249
264
|
export declare function springInOut(t: number): number;
|
|
250
265
|
type EasingFn = (t: number) => number;
|
|
251
266
|
/** Returns true if point is inside rect (inclusive). */
|
|
@@ -262,7 +277,14 @@ export declare function circleVsCircle(a: Circle, b: Circle): boolean;
|
|
|
262
277
|
export declare function lineVsRect(x1: number, y1: number, x2: number, y2: number, r: Rect): boolean;
|
|
263
278
|
/** Line segment intersection with circle. */
|
|
264
279
|
export declare function lineVsCircle(x1: number, y1: number, x2: number, y2: number, c: Circle): boolean;
|
|
265
|
-
/**
|
|
280
|
+
/**
|
|
281
|
+
* Ray intersection with AABB. Returns t (distance in units of the direction's
|
|
282
|
+
* length) or null if no hit. A ray starting inside returns the exit distance.
|
|
283
|
+
*
|
|
284
|
+
* Edges are inclusive: a ray that only touches an edge or corner hits, and an
|
|
285
|
+
* axis-parallel ray running exactly along an edge hits. A zero direction
|
|
286
|
+
* (`dirX === 0 && dirY === 0`) returns null.
|
|
287
|
+
*/
|
|
266
288
|
export declare function rayVsRect(originX: number, originY: number, dirX: number, dirY: number, r: Rect): number | null;
|
|
267
289
|
/**
|
|
268
290
|
* Do two segments intersect, including collinear overlap?
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/vec2.ts","../src/rect.ts","../src/circle.ts","../src/color.ts","../src/curves.ts","../src/easings.ts","../src/intersection.ts","../src/transform2d.ts","../src/mat3.ts","../src/random.ts","../src/reward.ts","../src/scalar.ts"],"mappings":";YAGY;EAAS;EAAW;;;wBAGhB,KAAK,YAAO,aAAQ;qBAMvB;;WAEH,YAAA;;WAID,WAAA;;WAID,UAAA;;WAIE,YAAA;;WAIA,YAAA;;WAIC,aAAA;;WAKF,MAAA,GAAA,MAAI,GAAK,MAAI,MAAQ,SAAO;;WAU5B,MAAA,GAAA,MAAI,GAAK,MAAI,MAAQ,SAAO;;WAU1B,QAAA,GAAA,MAAI,WAAW,MAAQ,SAAO;;WAU1B,YAAA,GAAA,MAAI,MAAQ,SAAO;;;WAqBV,oBAAA,YAAM,YAAY,gBAAgB,KAAO,SAAO;;WAc/D,MAAA,GAAA,MAAI,GAAK;;WAKP,QAAA,GAAA,MAAI,GAAK;;;;WAOV,OAAA,GAAA,MAAI,MAAQ,SAAO;;WAYhB,UAAA,WAAM,GAAK,MAAI,MAAQ,SAAO;;WAYjC,OAAA,GAAA,MAAI,GAAK,MAAI,WAAW,MAAQ,SAAO
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/vec2.ts","../src/rect.ts","../src/circle.ts","../src/color.ts","../src/curves.ts","../src/easings.ts","../src/intersection.ts","../src/transform2d.ts","../src/mat3.ts","../src/random.ts","../src/reward.ts","../src/scalar.ts"],"mappings":";YAGY;EAAS;EAAW;;;wBAGhB,KAAK,YAAO,aAAQ;qBAMvB;;WAEH,YAAA;;WAID,WAAA;;WAID,UAAA;;WAIE,YAAA;;WAIA,YAAA;;WAIC,aAAA;;WAKF,MAAA,GAAA,MAAI,GAAK,MAAI,MAAQ,SAAO;;WAU5B,MAAA,GAAA,MAAI,GAAK,MAAI,MAAQ,SAAO;;WAU1B,QAAA,GAAA,MAAI,WAAW,MAAQ,SAAO;;WAU1B,YAAA,GAAA,MAAI,MAAQ,SAAO;;;WAqBV,oBAAA,YAAM,YAAY,gBAAgB,KAAO,SAAO;;WAc/D,MAAA,GAAA,MAAI,GAAK;;WAKP,QAAA,GAAA,MAAI,GAAK;;;;WAOV,OAAA,GAAA,MAAI,MAAQ,SAAO;;WAYhB,UAAA,WAAM,GAAK,MAAI,MAAQ,SAAO;;WAYjC,OAAA,GAAA,MAAI,GAAK,MAAI,WAAW,MAAQ,SAAO;;;;;WAetC,QAAA,GAAA,MAAI,GAAK,MAAI,WAAW,MAAQ,SAAO;;WA2CpC,WAAA,GAAA,MAAI,GAAK;;WAOP,aAAA,GAAA,MAAI,GAAK;;WAOb,SAAA,GAAA;;WAKE,WAAA,GAAA;;WAKH,QAAA,GAAA;;WAKC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B,KAChB,SAAS,MAAM,cACf,iBACC;;;;;;;wBAWa,QAAQ;;;;;;wBAYR,YAAY,cAAc;;;;;;;;;;wBC5J1B,YAAY,aAAa,cAAc;;;;;;;wBAWvC,sBACd,cACA,iBACA,eACA;;;;;;wBAWc,cAAc,iBAAiB,eAAe;;;;;wBAQ9C,kBAAkB,iBAAiB;;wBC3CnC,MAAM,eAAe,aAAa;;wBAKlC,KAAK,WAAW,WAAW;;wBAK3B,YAAY,WAAW,WAAW;;wBAOlC,IACd,eACA,eACA,eACA,gBACA;;wBASc,SAAS;;wBAKT,SAAS;;wBAKT,aAAa,WAAW,WAAW;;wBAKnC,KAAK,eAAe,aAAa;;wBAOjC,SAAS,WAAW;;wBAOpB,WAAW,eAAe,eAAe;;wBAQzC,KAAK;;;;;wBASL,WAAW,WAAW;;;wBAStB,cAAc,aAAa,gBAAgB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -41,7 +41,10 @@ export declare const Vec2: {
|
|
|
41
41
|
readonly crossSV: (s: number, v: Vec2, out?: Vec2) => Vec2;
|
|
42
42
|
/** Linearly interpolates between a and b (unclamped). */
|
|
43
43
|
readonly lerp: (a: Vec2, b: Vec2, t: number, out?: Vec2) => Vec2;
|
|
44
|
-
/** Spherical linear interpolation for unit vectors.
|
|
44
|
+
/** Spherical linear interpolation for unit vectors. Antiparallel inputs (angle within 1e-6 of
|
|
45
|
+
* π) have no unique shortest arc, so `a` is rotated by `t·π` turning toward `Vec2.perp(a)` —
|
|
46
|
+
* clockwise in y-down screen space — and `t = 0.5` yields `Vec2.perp(a)`. `t = 0` and `t = 1`
|
|
47
|
+
* return `a` and `b` exactly. Writes into out if provided. */
|
|
45
48
|
readonly slerp: (a: Vec2, b: Vec2, t: number, out?: Vec2) => Vec2;
|
|
46
49
|
/** Euclidean distance between two points. */
|
|
47
50
|
readonly distance: (a: Vec2, b: Vec2) => number;
|
|
@@ -164,6 +167,12 @@ export declare const Color: {
|
|
|
164
167
|
/** WCAG 2.x contrast ratio. Order-independent; range [1, 21]. */
|
|
165
168
|
readonly contrastRatio: (fg: Color, bg: Color) => number;
|
|
166
169
|
};
|
|
170
|
+
/**
|
|
171
|
+
* Unpacks a 32-bit `0xAARRGGBB` int (the `Color.toSkColor` format) into `out`
|
|
172
|
+
* as `[r, g, b, a]`, each 0-1: the layout Skia paints and `clear` take.
|
|
173
|
+
* Zero-alloc.
|
|
174
|
+
*/
|
|
175
|
+
export declare function argbToFloat4Into(out: Float32Array, argb: number): void;
|
|
167
176
|
/**
|
|
168
177
|
* Parametric curves — quadratic/cubic Bézier and Catmull-Rom — plus approximate
|
|
169
178
|
* arc length for each.
|
|
@@ -244,8 +253,14 @@ export declare function easeInOutElastic(t: number): number;
|
|
|
244
253
|
export declare function easeOutBounce(t: number): number;
|
|
245
254
|
export declare function easeInBounce(t: number): number;
|
|
246
255
|
export declare function easeInOutBounce(t: number): number;
|
|
256
|
+
/** Alias of {@link easeInBack}, kept for compatibility. A Back curve, not a damped spring. */
|
|
247
257
|
export declare function springIn(t: number): number;
|
|
258
|
+
/** Alias of {@link easeOutBack}, kept for compatibility. A Back curve, not a damped spring. */
|
|
248
259
|
export declare function springOut(t: number): number;
|
|
260
|
+
/**
|
|
261
|
+
* The Back in-out curve under a second name, kept for compatibility. A Back
|
|
262
|
+
* curve, not a damped spring.
|
|
263
|
+
*/
|
|
249
264
|
export declare function springInOut(t: number): number;
|
|
250
265
|
type EasingFn = (t: number) => number;
|
|
251
266
|
/** Returns true if point is inside rect (inclusive). */
|
|
@@ -262,7 +277,14 @@ export declare function circleVsCircle(a: Circle, b: Circle): boolean;
|
|
|
262
277
|
export declare function lineVsRect(x1: number, y1: number, x2: number, y2: number, r: Rect): boolean;
|
|
263
278
|
/** Line segment intersection with circle. */
|
|
264
279
|
export declare function lineVsCircle(x1: number, y1: number, x2: number, y2: number, c: Circle): boolean;
|
|
265
|
-
/**
|
|
280
|
+
/**
|
|
281
|
+
* Ray intersection with AABB. Returns t (distance in units of the direction's
|
|
282
|
+
* length) or null if no hit. A ray starting inside returns the exit distance.
|
|
283
|
+
*
|
|
284
|
+
* Edges are inclusive: a ray that only touches an edge or corner hits, and an
|
|
285
|
+
* axis-parallel ray running exactly along an edge hits. A zero direction
|
|
286
|
+
* (`dirX === 0 && dirY === 0`) returns null.
|
|
287
|
+
*/
|
|
266
288
|
export declare function rayVsRect(originX: number, originY: number, dirX: number, dirY: number, r: Rect): number | null;
|
|
267
289
|
/**
|
|
268
290
|
* Do two segments intersect, including collinear overlap?
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/vec2.ts","../src/rect.ts","../src/circle.ts","../src/color.ts","../src/curves.ts","../src/easings.ts","../src/intersection.ts","../src/transform2d.ts","../src/mat3.ts","../src/random.ts","../src/reward.ts","../src/scalar.ts"],"mappings":";YAGY;EAAS;EAAW;;;wBAGhB,KAAK,YAAO,aAAQ;qBAMvB;;WAEH,YAAA;;WAID,WAAA;;WAID,UAAA;;WAIE,YAAA;;WAIA,YAAA;;WAIC,aAAA;;WAKF,MAAA,GAAA,MAAI,GAAK,MAAI,MAAQ,SAAO;;WAU5B,MAAA,GAAA,MAAI,GAAK,MAAI,MAAQ,SAAO;;WAU1B,QAAA,GAAA,MAAI,WAAW,MAAQ,SAAO;;WAU1B,YAAA,GAAA,MAAI,MAAQ,SAAO;;;WAqBV,oBAAA,YAAM,YAAY,gBAAgB,KAAO,SAAO;;WAc/D,MAAA,GAAA,MAAI,GAAK;;WAKP,QAAA,GAAA,MAAI,GAAK;;;;WAOV,OAAA,GAAA,MAAI,MAAQ,SAAO;;WAYhB,UAAA,WAAM,GAAK,MAAI,MAAQ,SAAO;;WAYjC,OAAA,GAAA,MAAI,GAAK,MAAI,WAAW,MAAQ,SAAO
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/vec2.ts","../src/rect.ts","../src/circle.ts","../src/color.ts","../src/curves.ts","../src/easings.ts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,WAAW;;wBAKnC,KAAK,eAAe,aAAa;;wBAOjC,SAAS,WAAW;;wBAOpB,WAAW,eAAe,eAAe;;wBAQzC,KAAK;;;;;wBASL,WAAW,WAAW;;;wBAStB,cAAc,aAAa,gBAAgB"}
|
package/dist/index.js
CHANGED
|
@@ -268,6 +268,17 @@ const Color = {
|
|
|
268
268
|
return (lMax + .05) / (lMin + .05);
|
|
269
269
|
}
|
|
270
270
|
};
|
|
271
|
+
/**
|
|
272
|
+
* Unpacks a 32-bit `0xAARRGGBB` int (the `Color.toSkColor` format) into `out`
|
|
273
|
+
* as `[r, g, b, a]`, each 0-1: the layout Skia paints and `clear` take.
|
|
274
|
+
* Zero-alloc.
|
|
275
|
+
*/
|
|
276
|
+
function argbToFloat4Into(out, argb) {
|
|
277
|
+
out[0] = (argb >>> 16 & 255) / 255;
|
|
278
|
+
out[1] = (argb >>> 8 & 255) / 255;
|
|
279
|
+
out[2] = (argb & 255) / 255;
|
|
280
|
+
out[3] = (argb >>> 24 & 255) / 255;
|
|
281
|
+
}
|
|
271
282
|
// src/curves.ts
|
|
272
283
|
/**
|
|
273
284
|
* Parametric curves — quadratic/cubic Bézier and Catmull-Rom — plus approximate
|
|
@@ -532,13 +543,18 @@ function easeInBounce(t) {
|
|
|
532
543
|
function easeInOutBounce(t) {
|
|
533
544
|
return t < .5 ? .5 * easeInBounce(t * 2) : .5 * easeOutBounce(t * 2 - 1) + .5;
|
|
534
545
|
}
|
|
546
|
+
/** Alias of {@link easeInBack}, kept for compatibility. A Back curve, not a damped spring. */
|
|
535
547
|
function springIn(t) {
|
|
536
|
-
return
|
|
548
|
+
return easeInBack(t);
|
|
537
549
|
}
|
|
550
|
+
/** Alias of {@link easeOutBack}, kept for compatibility. A Back curve, not a damped spring. */
|
|
538
551
|
function springOut(t) {
|
|
539
|
-
|
|
540
|
-
return t1 * t1 * (2.70158 * t1 + 1.70158) + 1;
|
|
552
|
+
return easeOutBack(t);
|
|
541
553
|
}
|
|
554
|
+
/**
|
|
555
|
+
* The Back in-out curve under a second name, kept for compatibility. A Back
|
|
556
|
+
* curve, not a damped spring.
|
|
557
|
+
*/
|
|
542
558
|
function springInOut(t) {
|
|
543
559
|
if (t < .5) {
|
|
544
560
|
const t2 = 2 * t;
|
|
@@ -547,73 +563,127 @@ function springInOut(t) {
|
|
|
547
563
|
const t2 = 2 * t - 2;
|
|
548
564
|
return .5 * (t2 * t2 * (3.5949095 * t2 + S2) + 2);
|
|
549
565
|
}
|
|
566
|
+
// src/rect.ts
|
|
567
|
+
const Rect = {
|
|
568
|
+
/** Returns true if point is inside rect (inclusive). */
|
|
569
|
+
contains(r, p) {
|
|
570
|
+
return p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height;
|
|
571
|
+
},
|
|
572
|
+
/** Returns true if two rects overlap (share area). */
|
|
573
|
+
intersects(a, b) {
|
|
574
|
+
return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y;
|
|
575
|
+
},
|
|
576
|
+
/** Returns the overlapping rect, or null if no overlap. */
|
|
577
|
+
intersection(a, b) {
|
|
578
|
+
const x = Math.max(a.x, b.x);
|
|
579
|
+
const y = Math.max(a.y, b.y);
|
|
580
|
+
const right = Math.min(a.x + a.width, b.x + b.width);
|
|
581
|
+
const bottom = Math.min(a.y + a.height, b.y + b.height);
|
|
582
|
+
if (right <= x || bottom <= y) return null;
|
|
583
|
+
return {
|
|
584
|
+
x,
|
|
585
|
+
y,
|
|
586
|
+
width: right - x,
|
|
587
|
+
height: bottom - y
|
|
588
|
+
};
|
|
589
|
+
},
|
|
590
|
+
/** Returns the smallest rect containing both rects. */
|
|
591
|
+
union(a, b) {
|
|
592
|
+
const x = Math.min(a.x, b.x);
|
|
593
|
+
const y = Math.min(a.y, b.y);
|
|
594
|
+
const right = Math.max(a.x + a.width, b.x + b.width);
|
|
595
|
+
const bottom = Math.max(a.y + a.height, b.y + b.height);
|
|
596
|
+
return {
|
|
597
|
+
x,
|
|
598
|
+
y,
|
|
599
|
+
width: right - x,
|
|
600
|
+
height: bottom - y
|
|
601
|
+
};
|
|
602
|
+
},
|
|
603
|
+
/** Creates a rect from an array of points (bounding box). */
|
|
604
|
+
fromPoints(points) {
|
|
605
|
+
if (points.length === 0) return {
|
|
606
|
+
x: 0,
|
|
607
|
+
y: 0,
|
|
608
|
+
width: 0,
|
|
609
|
+
height: 0
|
|
610
|
+
};
|
|
611
|
+
let minX = points[0].x;
|
|
612
|
+
let minY = points[0].y;
|
|
613
|
+
let maxX = minX;
|
|
614
|
+
let maxY = minY;
|
|
615
|
+
for (let i = 1; i < points.length; i++) {
|
|
616
|
+
const p = points[i];
|
|
617
|
+
if (p.x < minX) minX = p.x;
|
|
618
|
+
if (p.y < minY) minY = p.y;
|
|
619
|
+
if (p.x > maxX) maxX = p.x;
|
|
620
|
+
if (p.y > maxY) maxY = p.y;
|
|
621
|
+
}
|
|
622
|
+
return {
|
|
623
|
+
x: minX,
|
|
624
|
+
y: minY,
|
|
625
|
+
width: maxX - minX,
|
|
626
|
+
height: maxY - minY
|
|
627
|
+
};
|
|
628
|
+
},
|
|
629
|
+
/** Returns the center point of the rect. */
|
|
630
|
+
center(r) {
|
|
631
|
+
return {
|
|
632
|
+
x: r.x + r.width * .5,
|
|
633
|
+
y: r.y + r.height * .5
|
|
634
|
+
};
|
|
635
|
+
},
|
|
636
|
+
/** Returns a new rect expanded by amount on each side. */
|
|
637
|
+
expand(r, amount) {
|
|
638
|
+
return {
|
|
639
|
+
x: r.x - amount,
|
|
640
|
+
y: r.y - amount,
|
|
641
|
+
width: r.width + amount * 2,
|
|
642
|
+
height: r.height + amount * 2
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
};
|
|
550
646
|
// src/intersection.ts
|
|
551
647
|
/** Returns true if point is inside rect (inclusive). */
|
|
552
648
|
function pointInRect(p, r) {
|
|
553
|
-
return
|
|
649
|
+
return Rect.contains(r, p);
|
|
554
650
|
}
|
|
555
651
|
/** Returns true if point is inside circle (inclusive). */
|
|
556
652
|
function pointInCircle(p, c) {
|
|
557
|
-
|
|
558
|
-
const dy = p.y - c.y;
|
|
559
|
-
return dx * dx + dy * dy <= c.radius * c.radius;
|
|
653
|
+
return Circle.contains(c, p);
|
|
560
654
|
}
|
|
561
655
|
/** Returns true if two rects overlap. */
|
|
562
656
|
function rectVsRect(a, b) {
|
|
563
|
-
return
|
|
657
|
+
return Rect.intersects(a, b);
|
|
564
658
|
}
|
|
565
659
|
/** Returns true if rect and circle overlap. */
|
|
566
660
|
function rectVsCircle(r, c) {
|
|
567
|
-
|
|
568
|
-
const closestY = c.y < r.y ? r.y : c.y > r.y + r.height ? r.y + r.height : c.y;
|
|
569
|
-
const dx = c.x - closestX;
|
|
570
|
-
const dy = c.y - closestY;
|
|
571
|
-
return dx * dx + dy * dy <= c.radius * c.radius;
|
|
661
|
+
return Circle.intersectsRect(c, r);
|
|
572
662
|
}
|
|
573
663
|
/** Returns true if two circles overlap. */
|
|
574
664
|
function circleVsCircle(a, b) {
|
|
575
|
-
|
|
576
|
-
const dy = b.y - a.y;
|
|
577
|
-
const radSum = a.radius + b.radius;
|
|
578
|
-
return dx * dx + dy * dy < radSum * radSum;
|
|
665
|
+
return Circle.intersects(a, b);
|
|
579
666
|
}
|
|
580
667
|
/** Line segment intersection with AABB. Uses Liang-Barsky algorithm. */
|
|
581
668
|
function lineVsRect(x1, y1, x2, y2, r) {
|
|
582
669
|
const dx = x2 - x1;
|
|
583
670
|
const dy = y2 - y1;
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
{
|
|
596
|
-
p: -dy,
|
|
597
|
-
q: y1 - r.y
|
|
598
|
-
},
|
|
599
|
-
{
|
|
600
|
-
p: dy,
|
|
601
|
-
q: r.y + r.height - y1
|
|
602
|
-
}
|
|
603
|
-
];
|
|
604
|
-
for (const { p, q } of edges) if (Math.abs(p) < 1e-12) {
|
|
605
|
-
if (q < 0) return false;
|
|
671
|
+
clipT[0] = 0;
|
|
672
|
+
clipT[1] = 1;
|
|
673
|
+
return clipEdge(-dx, x1 - r.x) && clipEdge(dx, r.x + r.width - x1) && clipEdge(-dy, y1 - r.y) && clipEdge(dy, r.y + r.height - y1) && clipT[0] <= clipT[1];
|
|
674
|
+
}
|
|
675
|
+
const clipT = /* @__PURE__ */ new Float64Array(2);
|
|
676
|
+
function clipEdge(p, q) {
|
|
677
|
+
if (Math.abs(p) < 1e-12) return !(q < 0);
|
|
678
|
+
const t = q / p;
|
|
679
|
+
if (p < 0) {
|
|
680
|
+
if (t > clipT[1]) return false;
|
|
681
|
+
if (t > clipT[0]) clipT[0] = t;
|
|
606
682
|
} else {
|
|
607
|
-
|
|
608
|
-
if (
|
|
609
|
-
if (t > tMax) return false;
|
|
610
|
-
if (t > tMin) tMin = t;
|
|
611
|
-
} else {
|
|
612
|
-
if (t < tMin) return false;
|
|
613
|
-
if (t < tMax) tMax = t;
|
|
614
|
-
}
|
|
683
|
+
if (t < clipT[0]) return false;
|
|
684
|
+
if (t < clipT[1]) clipT[1] = t;
|
|
615
685
|
}
|
|
616
|
-
return
|
|
686
|
+
return true;
|
|
617
687
|
}
|
|
618
688
|
/** Line segment intersection with circle. */
|
|
619
689
|
function lineVsCircle(x1, y1, x2, y2, c) {
|
|
@@ -635,16 +705,36 @@ function lineVsCircle(x1, y1, x2, y2, c) {
|
|
|
635
705
|
if (t1 < 0 && t2 > 1) return true;
|
|
636
706
|
return false;
|
|
637
707
|
}
|
|
638
|
-
/**
|
|
708
|
+
/**
|
|
709
|
+
* Ray intersection with AABB. Returns t (distance in units of the direction's
|
|
710
|
+
* length) or null if no hit. A ray starting inside returns the exit distance.
|
|
711
|
+
*
|
|
712
|
+
* Edges are inclusive: a ray that only touches an edge or corner hits, and an
|
|
713
|
+
* axis-parallel ray running exactly along an edge hits. A zero direction
|
|
714
|
+
* (`dirX === 0 && dirY === 0`) returns null.
|
|
715
|
+
*/
|
|
639
716
|
function rayVsRect(originX, originY, dirX, dirY, r) {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
717
|
+
if (dirX === 0 && dirY === 0) return null;
|
|
718
|
+
let tMin = Number.NEGATIVE_INFINITY;
|
|
719
|
+
let tMax = Number.POSITIVE_INFINITY;
|
|
720
|
+
if (dirX === 0) {
|
|
721
|
+
if (originX < r.x || originX > r.x + r.width) return null;
|
|
722
|
+
} else {
|
|
723
|
+
const invDx = 1 / dirX;
|
|
724
|
+
const tx1 = (r.x - originX) * invDx;
|
|
725
|
+
const tx2 = (r.x + r.width - originX) * invDx;
|
|
726
|
+
tMin = Math.min(tx1, tx2);
|
|
727
|
+
tMax = Math.max(tx1, tx2);
|
|
728
|
+
}
|
|
729
|
+
if (dirY === 0) {
|
|
730
|
+
if (originY < r.y || originY > r.y + r.height) return null;
|
|
731
|
+
} else {
|
|
732
|
+
const invDy = 1 / dirY;
|
|
733
|
+
const ty1 = (r.y - originY) * invDy;
|
|
734
|
+
const ty2 = (r.y + r.height - originY) * invDy;
|
|
735
|
+
tMin = Math.max(tMin, Math.min(ty1, ty2));
|
|
736
|
+
tMax = Math.min(tMax, Math.max(ty1, ty2));
|
|
737
|
+
}
|
|
648
738
|
if (tMax < 0 || tMin > tMax) return null;
|
|
649
739
|
return tMin >= 0 ? tMin : tMax;
|
|
650
740
|
}
|
|
@@ -1012,86 +1102,6 @@ function seededIndex(seed, count) {
|
|
|
1012
1102
|
if (count <= 1) return 0;
|
|
1013
1103
|
return hashU32(seed) % count;
|
|
1014
1104
|
}
|
|
1015
|
-
// src/rect.ts
|
|
1016
|
-
const Rect = {
|
|
1017
|
-
/** Returns true if point is inside rect (inclusive). */
|
|
1018
|
-
contains(r, p) {
|
|
1019
|
-
return p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height;
|
|
1020
|
-
},
|
|
1021
|
-
/** Returns true if two rects overlap (share area). */
|
|
1022
|
-
intersects(a, b) {
|
|
1023
|
-
return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y;
|
|
1024
|
-
},
|
|
1025
|
-
/** Returns the overlapping rect, or null if no overlap. */
|
|
1026
|
-
intersection(a, b) {
|
|
1027
|
-
const x = Math.max(a.x, b.x);
|
|
1028
|
-
const y = Math.max(a.y, b.y);
|
|
1029
|
-
const right = Math.min(a.x + a.width, b.x + b.width);
|
|
1030
|
-
const bottom = Math.min(a.y + a.height, b.y + b.height);
|
|
1031
|
-
if (right <= x || bottom <= y) return null;
|
|
1032
|
-
return {
|
|
1033
|
-
x,
|
|
1034
|
-
y,
|
|
1035
|
-
width: right - x,
|
|
1036
|
-
height: bottom - y
|
|
1037
|
-
};
|
|
1038
|
-
},
|
|
1039
|
-
/** Returns the smallest rect containing both rects. */
|
|
1040
|
-
union(a, b) {
|
|
1041
|
-
const x = Math.min(a.x, b.x);
|
|
1042
|
-
const y = Math.min(a.y, b.y);
|
|
1043
|
-
const right = Math.max(a.x + a.width, b.x + b.width);
|
|
1044
|
-
const bottom = Math.max(a.y + a.height, b.y + b.height);
|
|
1045
|
-
return {
|
|
1046
|
-
x,
|
|
1047
|
-
y,
|
|
1048
|
-
width: right - x,
|
|
1049
|
-
height: bottom - y
|
|
1050
|
-
};
|
|
1051
|
-
},
|
|
1052
|
-
/** Creates a rect from an array of points (bounding box). */
|
|
1053
|
-
fromPoints(points) {
|
|
1054
|
-
if (points.length === 0) return {
|
|
1055
|
-
x: 0,
|
|
1056
|
-
y: 0,
|
|
1057
|
-
width: 0,
|
|
1058
|
-
height: 0
|
|
1059
|
-
};
|
|
1060
|
-
let minX = points[0].x;
|
|
1061
|
-
let minY = points[0].y;
|
|
1062
|
-
let maxX = minX;
|
|
1063
|
-
let maxY = minY;
|
|
1064
|
-
for (let i = 1; i < points.length; i++) {
|
|
1065
|
-
const p = points[i];
|
|
1066
|
-
if (p.x < minX) minX = p.x;
|
|
1067
|
-
if (p.y < minY) minY = p.y;
|
|
1068
|
-
if (p.x > maxX) maxX = p.x;
|
|
1069
|
-
if (p.y > maxY) maxY = p.y;
|
|
1070
|
-
}
|
|
1071
|
-
return {
|
|
1072
|
-
x: minX,
|
|
1073
|
-
y: minY,
|
|
1074
|
-
width: maxX - minX,
|
|
1075
|
-
height: maxY - minY
|
|
1076
|
-
};
|
|
1077
|
-
},
|
|
1078
|
-
/** Returns the center point of the rect. */
|
|
1079
|
-
center(r) {
|
|
1080
|
-
return {
|
|
1081
|
-
x: r.x + r.width * .5,
|
|
1082
|
-
y: r.y + r.height * .5
|
|
1083
|
-
};
|
|
1084
|
-
},
|
|
1085
|
-
/** Returns a new rect expanded by amount on each side. */
|
|
1086
|
-
expand(r, amount) {
|
|
1087
|
-
return {
|
|
1088
|
-
x: r.x - amount,
|
|
1089
|
-
y: r.y - amount,
|
|
1090
|
-
width: r.width + amount * 2,
|
|
1091
|
-
height: r.height + amount * 2
|
|
1092
|
-
};
|
|
1093
|
-
}
|
|
1094
|
-
};
|
|
1095
1105
|
// src/reward.ts
|
|
1096
1106
|
/**
|
|
1097
1107
|
* Timed-window and capped-bonus math — pure, zero-alloc scoring helpers.
|
|
@@ -1378,12 +1388,38 @@ const Vec2 = {
|
|
|
1378
1388
|
y
|
|
1379
1389
|
};
|
|
1380
1390
|
},
|
|
1381
|
-
/** Spherical linear interpolation for unit vectors.
|
|
1391
|
+
/** Spherical linear interpolation for unit vectors. Antiparallel inputs (angle within 1e-6 of
|
|
1392
|
+
* π) have no unique shortest arc, so `a` is rotated by `t·π` turning toward `Vec2.perp(a)` —
|
|
1393
|
+
* clockwise in y-down screen space — and `t = 0.5` yields `Vec2.perp(a)`. `t = 0` and `t = 1`
|
|
1394
|
+
* return `a` and `b` exactly. Writes into out if provided. */
|
|
1382
1395
|
slerp(a, b, t, out) {
|
|
1383
1396
|
let d = a.x * b.x + a.y * b.y;
|
|
1384
1397
|
d = d < -1 ? -1 : d > 1 ? 1 : d;
|
|
1385
1398
|
const theta = Math.acos(d);
|
|
1386
1399
|
if (theta < 1e-6) return Vec2.lerp(a, b, t, out);
|
|
1400
|
+
if (theta > Math.PI - 1e-6) {
|
|
1401
|
+
let x = a.x;
|
|
1402
|
+
let y = a.y;
|
|
1403
|
+
if (t === 1) {
|
|
1404
|
+
x = b.x;
|
|
1405
|
+
y = b.y;
|
|
1406
|
+
} else if (t !== 0) {
|
|
1407
|
+
const phi = t * Math.PI;
|
|
1408
|
+
const c = Math.cos(phi);
|
|
1409
|
+
const s = Math.sin(phi);
|
|
1410
|
+
x = a.x * c - a.y * s;
|
|
1411
|
+
y = a.y * c + a.x * s;
|
|
1412
|
+
}
|
|
1413
|
+
if (out) {
|
|
1414
|
+
out.x = x;
|
|
1415
|
+
out.y = y;
|
|
1416
|
+
return out;
|
|
1417
|
+
}
|
|
1418
|
+
return {
|
|
1419
|
+
x,
|
|
1420
|
+
y
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1387
1423
|
const sinTheta = Math.sin(theta);
|
|
1388
1424
|
const wa = Math.sin((1 - t) * theta) / sinTheta;
|
|
1389
1425
|
const wb = Math.sin(t * theta) / sinTheta;
|
|
@@ -1496,6 +1532,7 @@ exports.Vec2 = Vec2;
|
|
|
1496
1532
|
exports.advanceWindowedStreak = advanceWindowedStreak;
|
|
1497
1533
|
exports.angleDelta = angleDelta;
|
|
1498
1534
|
exports.approxEquals = approxEquals;
|
|
1535
|
+
exports.argbToFloat4Into = argbToFloat4Into;
|
|
1499
1536
|
exports.bezier2 = bezier2;
|
|
1500
1537
|
exports.bezier2Into = bezier2Into;
|
|
1501
1538
|
exports.bezier2Length = bezier2Length;
|