@codexo/exojs-physics 0.19.0 → 0.20.0
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 +8 -73
- package/{dist/esm/debug/index.d.ts → debug.d.ts} +1 -2
- package/debug.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +17 -23
- package/dist/esm/Aabb.d.ts +0 -10
- package/dist/esm/Aabb.d.ts.map +0 -1
- package/dist/esm/Aabb.js +0 -16
- package/dist/esm/Aabb.js.map +0 -1
- package/dist/esm/Collider.d.ts +0 -107
- package/dist/esm/Collider.d.ts.map +0 -1
- package/dist/esm/Collider.js +0 -284
- package/dist/esm/Collider.js.map +0 -1
- package/dist/esm/ContactGraph.d.ts +0 -154
- package/dist/esm/ContactGraph.d.ts.map +0 -1
- package/dist/esm/ContactGraph.js +0 -383
- package/dist/esm/ContactGraph.js.map +0 -1
- package/dist/esm/ContactModifier.d.ts +0 -62
- package/dist/esm/ContactModifier.d.ts.map +0 -1
- package/dist/esm/ContactModifier.js +0 -49
- package/dist/esm/ContactModifier.js.map +0 -1
- package/dist/esm/PhysicsBody.d.ts +0 -186
- package/dist/esm/PhysicsBody.d.ts.map +0 -1
- package/dist/esm/PhysicsBody.js +0 -526
- package/dist/esm/PhysicsBody.js.map +0 -1
- package/dist/esm/PhysicsBodyComponent.d.ts +0 -45
- package/dist/esm/PhysicsBodyComponent.d.ts.map +0 -1
- package/dist/esm/PhysicsBodyComponent.js +0 -77
- package/dist/esm/PhysicsBodyComponent.js.map +0 -1
- package/dist/esm/PhysicsWorld.d.ts +0 -567
- package/dist/esm/PhysicsWorld.d.ts.map +0 -1
- package/dist/esm/PhysicsWorld.js +0 -1096
- package/dist/esm/PhysicsWorld.js.map +0 -1
- package/dist/esm/TimeStepper.d.ts +0 -40
- package/dist/esm/TimeStepper.d.ts.map +0 -1
- package/dist/esm/TimeStepper.js +0 -59
- package/dist/esm/TimeStepper.js.map +0 -1
- package/dist/esm/backend/NativePhysicsBackend.d.ts +0 -28
- package/dist/esm/backend/NativePhysicsBackend.d.ts.map +0 -1
- package/dist/esm/backend/NativePhysicsBackend.js +0 -52
- package/dist/esm/backend/NativePhysicsBackend.js.map +0 -1
- package/dist/esm/backend/PhysicsBackend.d.ts +0 -38
- package/dist/esm/backend/PhysicsBackend.d.ts.map +0 -1
- package/dist/esm/binding/BindingRegistry.d.ts +0 -48
- package/dist/esm/binding/BindingRegistry.d.ts.map +0 -1
- package/dist/esm/binding/BindingRegistry.js +0 -81
- package/dist/esm/binding/BindingRegistry.js.map +0 -1
- package/dist/esm/binding/PhysicsBinding.d.ts +0 -37
- package/dist/esm/binding/PhysicsBinding.d.ts.map +0 -1
- package/dist/esm/binding/PhysicsBinding.js +0 -54
- package/dist/esm/binding/PhysicsBinding.js.map +0 -1
- package/dist/esm/binding/nodeWorldTransform.d.ts +0 -18
- package/dist/esm/binding/nodeWorldTransform.d.ts.map +0 -1
- package/dist/esm/binding/nodeWorldTransform.js +0 -41
- package/dist/esm/binding/nodeWorldTransform.js.map +0 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +0 -84
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +0 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.js +0 -183
- package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +0 -1
- package/dist/esm/broadphase/BroadPhase.d.ts +0 -25
- package/dist/esm/broadphase/BroadPhase.d.ts.map +0 -1
- package/dist/esm/broadphase/index.d.ts +0 -3
- package/dist/esm/broadphase/index.d.ts.map +0 -1
- package/dist/esm/collision/CollisionProxy.d.ts +0 -15
- package/dist/esm/collision/CollisionProxy.d.ts.map +0 -1
- package/dist/esm/collision/Manifold.d.ts +0 -34
- package/dist/esm/collision/Manifold.d.ts.map +0 -1
- package/dist/esm/collision/Manifold.js +0 -37
- package/dist/esm/collision/Manifold.js.map +0 -1
- package/dist/esm/collision/chainAdjacency.d.ts +0 -2
- package/dist/esm/collision/chainAdjacency.d.ts.map +0 -1
- package/dist/esm/collision/chainAdjacency.js +0 -44
- package/dist/esm/collision/chainAdjacency.js.map +0 -1
- package/dist/esm/collision/dispatch.d.ts +0 -35
- package/dist/esm/collision/dispatch.d.ts.map +0 -1
- package/dist/esm/collision/dispatch.js +0 -58
- package/dist/esm/collision/dispatch.js.map +0 -1
- package/dist/esm/collision/index.d.ts +0 -5
- package/dist/esm/collision/index.d.ts.map +0 -1
- package/dist/esm/collision/narrowphase.d.ts +0 -17
- package/dist/esm/collision/narrowphase.d.ts.map +0 -1
- package/dist/esm/collision/narrowphase.js +0 -555
- package/dist/esm/collision/narrowphase.js.map +0 -1
- package/dist/esm/collision/segments.d.ts +0 -19
- package/dist/esm/collision/segments.d.ts.map +0 -1
- package/dist/esm/collision/segments.js +0 -36
- package/dist/esm/collision/segments.js.map +0 -1
- package/dist/esm/collision/sweep.d.ts +0 -35
- package/dist/esm/collision/sweep.d.ts.map +0 -1
- package/dist/esm/collision/sweep.js +0 -437
- package/dist/esm/collision/sweep.js.map +0 -1
- package/dist/esm/debug/PhysicsDebugDraw.d.ts +0 -72
- package/dist/esm/debug/PhysicsDebugDraw.d.ts.map +0 -1
- package/dist/esm/debug/PhysicsDebugDraw.js +0 -239
- package/dist/esm/debug/PhysicsDebugDraw.js.map +0 -1
- package/dist/esm/debug/index.d.ts.map +0 -1
- package/dist/esm/debug/index.js +0 -3
- package/dist/esm/events.d.ts +0 -36
- package/dist/esm/events.d.ts.map +0 -1
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -25
- package/dist/esm/joints/DistanceJoint.d.ts +0 -70
- package/dist/esm/joints/DistanceJoint.d.ts.map +0 -1
- package/dist/esm/joints/DistanceJoint.js +0 -167
- package/dist/esm/joints/DistanceJoint.js.map +0 -1
- package/dist/esm/joints/Joint.d.ts +0 -76
- package/dist/esm/joints/Joint.d.ts.map +0 -1
- package/dist/esm/joints/Joint.js +0 -62
- package/dist/esm/joints/Joint.js.map +0 -1
- package/dist/esm/joints/MouseJoint.d.ts +0 -55
- package/dist/esm/joints/MouseJoint.d.ts.map +0 -1
- package/dist/esm/joints/MouseJoint.js +0 -139
- package/dist/esm/joints/MouseJoint.js.map +0 -1
- package/dist/esm/joints/PrismaticJoint.d.ts +0 -84
- package/dist/esm/joints/PrismaticJoint.d.ts.map +0 -1
- package/dist/esm/joints/PrismaticJoint.js +0 -218
- package/dist/esm/joints/PrismaticJoint.js.map +0 -1
- package/dist/esm/joints/RevoluteJoint.d.ts +0 -77
- package/dist/esm/joints/RevoluteJoint.d.ts.map +0 -1
- package/dist/esm/joints/RevoluteJoint.js +0 -204
- package/dist/esm/joints/RevoluteJoint.js.map +0 -1
- package/dist/esm/joints/WeldJoint.d.ts +0 -60
- package/dist/esm/joints/WeldJoint.d.ts.map +0 -1
- package/dist/esm/joints/WeldJoint.js +0 -166
- package/dist/esm/joints/WeldJoint.js.map +0 -1
- package/dist/esm/joints/WheelJoint.d.ts +0 -91
- package/dist/esm/joints/WheelJoint.d.ts.map +0 -1
- package/dist/esm/joints/WheelJoint.js +0 -235
- package/dist/esm/joints/WheelJoint.js.map +0 -1
- package/dist/esm/math.d.ts +0 -29
- package/dist/esm/math.d.ts.map +0 -1
- package/dist/esm/math.js +0 -60
- package/dist/esm/math.js.map +0 -1
- package/dist/esm/physicsBuildInfo.d.ts +0 -16
- package/dist/esm/physicsBuildInfo.d.ts.map +0 -1
- package/dist/esm/physicsBuildInfo.js +0 -10
- package/dist/esm/physicsBuildInfo.js.map +0 -1
- package/dist/esm/public.d.ts +0 -34
- package/dist/esm/public.d.ts.map +0 -1
- package/dist/esm/query/QueryEngine.d.ts +0 -95
- package/dist/esm/query/QueryEngine.d.ts.map +0 -1
- package/dist/esm/query/QueryEngine.js +0 -512
- package/dist/esm/query/QueryEngine.js.map +0 -1
- package/dist/esm/query/SpatialIndex.d.ts +0 -34
- package/dist/esm/query/SpatialIndex.d.ts.map +0 -1
- package/dist/esm/shapes/AnyShape.d.ts +0 -14
- package/dist/esm/shapes/AnyShape.d.ts.map +0 -1
- package/dist/esm/shapes/BoxShape.d.ts +0 -12
- package/dist/esm/shapes/BoxShape.d.ts.map +0 -1
- package/dist/esm/shapes/BoxShape.js +0 -41
- package/dist/esm/shapes/BoxShape.js.map +0 -1
- package/dist/esm/shapes/CapsuleShape.d.ts +0 -30
- package/dist/esm/shapes/CapsuleShape.d.ts.map +0 -1
- package/dist/esm/shapes/CapsuleShape.js +0 -88
- package/dist/esm/shapes/CapsuleShape.js.map +0 -1
- package/dist/esm/shapes/ChainEdgeShape.d.ts +0 -2
- package/dist/esm/shapes/ChainEdgeShape.d.ts.map +0 -1
- package/dist/esm/shapes/ChainEdgeShape.js +0 -66
- package/dist/esm/shapes/ChainEdgeShape.js.map +0 -1
- package/dist/esm/shapes/ChainShape.d.ts +0 -46
- package/dist/esm/shapes/ChainShape.d.ts.map +0 -1
- package/dist/esm/shapes/ChainShape.js +0 -85
- package/dist/esm/shapes/ChainShape.js.map +0 -1
- package/dist/esm/shapes/CircleShape.d.ts +0 -14
- package/dist/esm/shapes/CircleShape.d.ts.map +0 -1
- package/dist/esm/shapes/CircleShape.js +0 -31
- package/dist/esm/shapes/CircleShape.js.map +0 -1
- package/dist/esm/shapes/PolygonShape.d.ts +0 -24
- package/dist/esm/shapes/PolygonShape.d.ts.map +0 -1
- package/dist/esm/shapes/PolygonShape.js +0 -153
- package/dist/esm/shapes/PolygonShape.js.map +0 -1
- package/dist/esm/shapes/SegmentShape.d.ts +0 -31
- package/dist/esm/shapes/SegmentShape.d.ts.map +0 -1
- package/dist/esm/shapes/SegmentShape.js +0 -62
- package/dist/esm/shapes/SegmentShape.js.map +0 -1
- package/dist/esm/shapes/Shape.d.ts +0 -37
- package/dist/esm/shapes/Shape.d.ts.map +0 -1
- package/dist/esm/shapes/Shape.js +0 -15
- package/dist/esm/shapes/Shape.js.map +0 -1
- package/dist/esm/shapes/convexParts.d.ts +0 -21
- package/dist/esm/shapes/convexParts.d.ts.map +0 -1
- package/dist/esm/shapes/convexParts.js +0 -26
- package/dist/esm/shapes/convexParts.js.map +0 -1
- package/dist/esm/shapes/decompose.d.ts +0 -2
- package/dist/esm/shapes/decompose.d.ts.map +0 -1
- package/dist/esm/shapes/decompose.js +0 -272
- package/dist/esm/shapes/decompose.js.map +0 -1
- package/dist/esm/shapes/index.d.ts +0 -9
- package/dist/esm/shapes/index.d.ts.map +0 -1
- package/dist/esm/solver/ContactSolver.d.ts +0 -94
- package/dist/esm/solver/ContactSolver.d.ts.map +0 -1
- package/dist/esm/solver/ContactSolver.js +0 -457
- package/dist/esm/solver/ContactSolver.js.map +0 -1
- package/dist/esm/solver/tolerances.d.ts +0 -2
- package/dist/esm/solver/tolerances.d.ts.map +0 -1
- package/dist/esm/solver/tolerances.js +0 -36
- package/dist/esm/solver/tolerances.js.map +0 -1
- package/dist/esm/sort.d.ts +0 -2
- package/dist/esm/sort.d.ts.map +0 -1
- package/dist/esm/sort.js +0 -44
- package/dist/esm/sort.js.map +0 -1
- package/dist/esm/types.d.ts +0 -35
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -26
- package/dist/esm/types.js.map +0 -1
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { Shape } from "./Shape.js";
|
|
2
|
-
|
|
3
|
-
//#region src/shapes/PolygonShape.ts
|
|
4
|
-
/** Vertices closer than this (px) are treated as coincident → degenerate. */
|
|
5
|
-
const weldEpsilon = 1e-4;
|
|
6
|
-
/**
|
|
7
|
-
* A convex polygon defined by ≥3 local-space vertices. Input vertices may be
|
|
8
|
-
* given in either winding; they are canonicalised to counter-clockwise and the
|
|
9
|
-
* outward edge normals are precomputed. Construction throws on any non-convex,
|
|
10
|
-
* degenerate, or under-specified input - there is no silent repair.
|
|
11
|
-
*
|
|
12
|
-
* Vertices and normals are exposed as flat `[x0, y0, x1, y1, ...]` arrays to keep
|
|
13
|
-
* the narrow phase allocation-free; both are frozen.
|
|
14
|
-
*/
|
|
15
|
-
var PolygonShape = class extends Shape {
|
|
16
|
-
type = "polygon";
|
|
17
|
-
/** Local-space vertices, CCW, flattened. */
|
|
18
|
-
vertices;
|
|
19
|
-
/** Outward unit edge normals (edge `i` spans vertex `i → i+1`), flattened. */
|
|
20
|
-
normals;
|
|
21
|
-
count;
|
|
22
|
-
boundingRadius;
|
|
23
|
-
massProperties;
|
|
24
|
-
constructor(vertices) {
|
|
25
|
-
super();
|
|
26
|
-
if (vertices.length < 3) throw new RangeError(`PolygonShape: needs at least 3 vertices, received ${vertices.length}.`);
|
|
27
|
-
const points = [];
|
|
28
|
-
for (const vertex of vertices) {
|
|
29
|
-
if (!Number.isFinite(vertex.x) || !Number.isFinite(vertex.y)) throw new RangeError(`PolygonShape: vertex has a non-finite component (${vertex.x}, ${vertex.y}).`);
|
|
30
|
-
const px = points.length >= 2 ? points[points.length - 2] ?? NaN : NaN;
|
|
31
|
-
const py = points.length >= 2 ? points[points.length - 1] ?? NaN : NaN;
|
|
32
|
-
if (Math.hypot(vertex.x - px, vertex.y - py) < weldEpsilon) continue;
|
|
33
|
-
points.push(vertex.x, vertex.y);
|
|
34
|
-
}
|
|
35
|
-
dropWrapAroundDuplicate(points);
|
|
36
|
-
const count = points.length / 2;
|
|
37
|
-
if (count < 3) throw new RangeError(`PolygonShape: needs at least 3 distinct vertices after welding, received ${count}.`);
|
|
38
|
-
if (signedArea(points) < 0) reverseWinding(points);
|
|
39
|
-
const signed = signedArea(points);
|
|
40
|
-
if (signed <= weldEpsilon) throw new RangeError("PolygonShape: vertices are degenerate (zero/near-zero area).");
|
|
41
|
-
const normals = computeNormals(points);
|
|
42
|
-
assertConvex(points);
|
|
43
|
-
let cx = 0;
|
|
44
|
-
let cy = 0;
|
|
45
|
-
let inertiaOrigin = 0;
|
|
46
|
-
for (let i = 0; i < count; i++) {
|
|
47
|
-
const j = (i + 1) % count;
|
|
48
|
-
const ix = points[i * 2];
|
|
49
|
-
const iy = points[i * 2 + 1];
|
|
50
|
-
const jx = points[j * 2];
|
|
51
|
-
const jy = points[j * 2 + 1];
|
|
52
|
-
const cross = ix * jy - jx * iy;
|
|
53
|
-
cx += (ix + jx) * cross;
|
|
54
|
-
cy += (iy + jy) * cross;
|
|
55
|
-
inertiaOrigin += cross * (ix * ix + ix * jx + jx * jx + iy * iy + iy * jy + jy * jy);
|
|
56
|
-
}
|
|
57
|
-
const area = signed;
|
|
58
|
-
cx /= 6 * area;
|
|
59
|
-
cy /= 6 * area;
|
|
60
|
-
this.count = count;
|
|
61
|
-
this.vertices = Object.freeze(points);
|
|
62
|
-
this.normals = Object.freeze(normals);
|
|
63
|
-
this.massProperties = Object.freeze({
|
|
64
|
-
area,
|
|
65
|
-
centroidX: cx,
|
|
66
|
-
centroidY: cy,
|
|
67
|
-
unitInertia: inertiaOrigin / 12 - area * (cx * cx + cy * cy)
|
|
68
|
-
});
|
|
69
|
-
this.boundingRadius = boundingRadiusOf(points);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
/** Strip a trailing vertex that coincides with the first (wrap-around weld). */
|
|
73
|
-
const dropWrapAroundDuplicate = (points) => {
|
|
74
|
-
if (points.length < 4) return;
|
|
75
|
-
const firstX = points[0] ?? NaN;
|
|
76
|
-
const firstY = points[1] ?? NaN;
|
|
77
|
-
const lastX = points[points.length - 2] ?? NaN;
|
|
78
|
-
const lastY = points[points.length - 1] ?? NaN;
|
|
79
|
-
if (Math.hypot(firstX - lastX, firstY - lastY) < weldEpsilon) points.length -= 2;
|
|
80
|
-
};
|
|
81
|
-
/** Signed area (positive = CCW). */
|
|
82
|
-
const signedArea = (points) => {
|
|
83
|
-
const count = points.length / 2;
|
|
84
|
-
let sum = 0;
|
|
85
|
-
for (let i = 0; i < count; i++) {
|
|
86
|
-
const j = (i + 1) % count;
|
|
87
|
-
const ix = points[i * 2];
|
|
88
|
-
const iy = points[i * 2 + 1];
|
|
89
|
-
const jx = points[j * 2];
|
|
90
|
-
const jy = points[j * 2 + 1];
|
|
91
|
-
sum += ix * jy - jx * iy;
|
|
92
|
-
}
|
|
93
|
-
return sum / 2;
|
|
94
|
-
};
|
|
95
|
-
const reverseWinding = (points) => {
|
|
96
|
-
const count = points.length / 2;
|
|
97
|
-
for (let i = 0; i < Math.floor(count / 2); i++) {
|
|
98
|
-
const j = count - 1 - i;
|
|
99
|
-
const ix = points[i * 2];
|
|
100
|
-
const iy = points[i * 2 + 1];
|
|
101
|
-
const jx = points[j * 2];
|
|
102
|
-
const jy = points[j * 2 + 1];
|
|
103
|
-
points[i * 2] = jx;
|
|
104
|
-
points[i * 2 + 1] = jy;
|
|
105
|
-
points[j * 2] = ix;
|
|
106
|
-
points[j * 2 + 1] = iy;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
/** Outward unit normals for a CCW polygon: normal of edge `i→i+1` is `(eY, -eX)`. */
|
|
110
|
-
const computeNormals = (points) => {
|
|
111
|
-
const count = points.length / 2;
|
|
112
|
-
const normals = [];
|
|
113
|
-
for (let i = 0; i < count; i++) {
|
|
114
|
-
const j = (i + 1) % count;
|
|
115
|
-
const ix = points[i * 2];
|
|
116
|
-
const iy = points[i * 2 + 1];
|
|
117
|
-
const jx = points[j * 2];
|
|
118
|
-
const jy = points[j * 2 + 1];
|
|
119
|
-
const ex = jx - ix;
|
|
120
|
-
const ey = jy - iy;
|
|
121
|
-
const length = Math.hypot(ex, ey);
|
|
122
|
-
normals.push(ey / length, -ex / length);
|
|
123
|
-
}
|
|
124
|
-
return normals;
|
|
125
|
-
};
|
|
126
|
-
/** Throw unless every interior turn has the same (CCW) orientation. */
|
|
127
|
-
const assertConvex = (points) => {
|
|
128
|
-
const count = points.length / 2;
|
|
129
|
-
for (let i = 0; i < count; i++) {
|
|
130
|
-
const a = i;
|
|
131
|
-
const b = (i + 1) % count;
|
|
132
|
-
const c = (i + 2) % count;
|
|
133
|
-
const ax = points[a * 2];
|
|
134
|
-
const ay = points[a * 2 + 1];
|
|
135
|
-
const bx = points[b * 2];
|
|
136
|
-
const by = points[b * 2 + 1];
|
|
137
|
-
const cx = points[c * 2];
|
|
138
|
-
const cy = points[c * 2 + 1];
|
|
139
|
-
const e1x = bx - ax;
|
|
140
|
-
const e1y = by - ay;
|
|
141
|
-
const e2x = cx - bx;
|
|
142
|
-
if (e1x * (cy - by) - e1y * e2x <= 0) throw new RangeError("PolygonShape: vertices are not strictly convex (or contain collinear edges).");
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
const boundingRadiusOf = (points) => {
|
|
146
|
-
let max = 0;
|
|
147
|
-
for (let i = 0; i < points.length; i += 2) max = Math.max(max, Math.hypot(points[i], points[i + 1]));
|
|
148
|
-
return max;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
//#endregion
|
|
152
|
-
export { PolygonShape };
|
|
153
|
-
//# sourceMappingURL=PolygonShape.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PolygonShape.js","names":[],"sources":["../../../src/shapes/PolygonShape.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport type { ShapeMassProperties } from './Shape';\nimport { Shape } from './Shape';\n\n/** Vertices closer than this (px) are treated as coincident → degenerate. */\nconst weldEpsilon = 1e-4;\n\n/**\n * A convex polygon defined by ≥3 local-space vertices. Input vertices may be\n * given in either winding; they are canonicalised to counter-clockwise and the\n * outward edge normals are precomputed. Construction throws on any non-convex,\n * degenerate, or under-specified input - there is no silent repair.\n *\n * Vertices and normals are exposed as flat `[x0, y0, x1, y1, ...]` arrays to keep\n * the narrow phase allocation-free; both are frozen.\n */\nexport class PolygonShape extends Shape {\n public readonly type = 'polygon' as const;\n\n /** Local-space vertices, CCW, flattened. */\n public readonly vertices: readonly number[];\n\n /** Outward unit edge normals (edge `i` spans vertex `i → i+1`), flattened. */\n public readonly normals: readonly number[];\n\n public readonly count: number;\n public readonly boundingRadius: number;\n public readonly massProperties: ShapeMassProperties;\n\n public constructor(vertices: ReadonlyArray<Readonly<PointLike>>) {\n super();\n\n if (vertices.length < 3) {\n throw new RangeError(`PolygonShape: needs at least 3 vertices, received ${vertices.length}.`);\n }\n\n const points: number[] = [];\n\n for (const vertex of vertices) {\n if (!Number.isFinite(vertex.x) || !Number.isFinite(vertex.y)) {\n throw new RangeError(`PolygonShape: vertex has a non-finite component (${vertex.x}, ${vertex.y}).`);\n }\n\n // Reject coincident consecutive (and wrap-around) vertices.\n const px = points.length >= 2 ? (points[points.length - 2] ?? NaN) : NaN;\n const py = points.length >= 2 ? (points[points.length - 1] ?? NaN) : NaN;\n\n if (Math.hypot(vertex.x - px, vertex.y - py) < weldEpsilon) {\n continue;\n }\n\n points.push(vertex.x, vertex.y);\n }\n\n // Drop a wrap-around duplicate (last ≈ first).\n dropWrapAroundDuplicate(points);\n\n const count = points.length / 2;\n\n if (count < 3) {\n throw new RangeError(`PolygonShape: needs at least 3 distinct vertices after welding, received ${count}.`);\n }\n\n // Canonicalise to CCW (positive signed area). Screen space is +Y down, so a\n // mathematically CCW polygon appears clockwise - the math stays consistent.\n if (signedArea(points) < 0) {\n reverseWinding(points);\n }\n\n const signed = signedArea(points);\n\n if (signed <= weldEpsilon) {\n throw new RangeError('PolygonShape: vertices are degenerate (zero/near-zero area).');\n }\n\n const normals = computeNormals(points);\n\n assertConvex(points);\n\n // Area, centroid and inertia via the standard polygon integrals.\n let cx = 0;\n let cy = 0;\n let inertiaOrigin = 0;\n\n for (let i = 0; i < count; i++) {\n const j = (i + 1) % count;\n // Indices are provably in-bounds (0..count-1 over a length-2*count array);\n // the `!` is zero-cost; a violation would surface as NaN, not a silent 0.\n const ix = points[i * 2]!;\n const iy = points[i * 2 + 1]!;\n const jx = points[j * 2]!;\n const jy = points[j * 2 + 1]!;\n const cross = ix * jy - jx * iy;\n\n cx += (ix + jx) * cross;\n cy += (iy + jy) * cross;\n inertiaOrigin += cross * (ix * ix + ix * jx + jx * jx + iy * iy + iy * jy + jy * jy);\n }\n\n const area = signed;\n cx /= 6 * area;\n cy /= 6 * area;\n\n this.count = count;\n this.vertices = Object.freeze(points);\n this.normals = Object.freeze(normals);\n this.massProperties = Object.freeze({\n area,\n centroidX: cx,\n centroidY: cy,\n // ∫ r² dA about the origin, then shifted to the centroid (parallel axis).\n unitInertia: inertiaOrigin / 12 - area * (cx * cx + cy * cy),\n });\n this.boundingRadius = boundingRadiusOf(points);\n\n // The vertex/normal arrays are frozen; the instance itself is not, so\n // BoxShape (and any future convex helper) can extend this class.\n }\n}\n\n/** Strip a trailing vertex that coincides with the first (wrap-around weld). */\nconst dropWrapAroundDuplicate = (points: number[]): void => {\n if (points.length < 4) {\n return;\n }\n\n const firstX = points[0] ?? NaN;\n const firstY = points[1] ?? NaN;\n const lastX = points[points.length - 2] ?? NaN;\n const lastY = points[points.length - 1] ?? NaN;\n\n if (Math.hypot(firstX - lastX, firstY - lastY) < weldEpsilon) {\n points.length -= 2;\n }\n};\n\n/** Signed area (positive = CCW). */\nconst signedArea = (points: number[]): number => {\n const count = points.length / 2;\n let sum = 0;\n\n for (let i = 0; i < count; i++) {\n const j = (i + 1) % count;\n const ix = points[i * 2]!;\n const iy = points[i * 2 + 1]!;\n const jx = points[j * 2]!;\n const jy = points[j * 2 + 1]!;\n sum += ix * jy - jx * iy;\n }\n\n return sum / 2;\n};\n\nconst reverseWinding = (points: number[]): void => {\n const count = points.length / 2;\n\n for (let i = 0; i < Math.floor(count / 2); i++) {\n const j = count - 1 - i;\n const ix = points[i * 2]!;\n const iy = points[i * 2 + 1]!;\n const jx = points[j * 2]!;\n const jy = points[j * 2 + 1]!;\n\n points[i * 2] = jx;\n points[i * 2 + 1] = jy;\n points[j * 2] = ix;\n points[j * 2 + 1] = iy;\n }\n};\n\n/** Outward unit normals for a CCW polygon: normal of edge `i→i+1` is `(eY, -eX)`. */\nconst computeNormals = (points: number[]): number[] => {\n const count = points.length / 2;\n const normals: number[] = [];\n\n for (let i = 0; i < count; i++) {\n const j = (i + 1) % count;\n const ix = points[i * 2]!;\n const iy = points[i * 2 + 1]!;\n const jx = points[j * 2]!;\n const jy = points[j * 2 + 1]!;\n const ex = jx - ix;\n const ey = jy - iy;\n const length = Math.hypot(ex, ey);\n\n normals.push(ey / length, -ex / length);\n }\n\n return normals;\n};\n\n/** Throw unless every interior turn has the same (CCW) orientation. */\nconst assertConvex = (points: number[]): void => {\n const count = points.length / 2;\n\n for (let i = 0; i < count; i++) {\n const a = i;\n const b = (i + 1) % count;\n const c = (i + 2) % count;\n const ax = points[a * 2]!;\n const ay = points[a * 2 + 1]!;\n const bx = points[b * 2]!;\n const by = points[b * 2 + 1]!;\n const cx = points[c * 2]!;\n const cy = points[c * 2 + 1]!;\n const e1x = bx - ax;\n const e1y = by - ay;\n const e2x = cx - bx;\n const e2y = cy - by;\n\n // CCW polygon ⇒ every cross product must be ≥ 0 (strictly > 0 for no collinear run).\n if (e1x * e2y - e1y * e2x <= 0) {\n throw new RangeError('PolygonShape: vertices are not strictly convex (or contain collinear edges).');\n }\n }\n};\n\nconst boundingRadiusOf = (points: number[]): number => {\n let max = 0;\n\n for (let i = 0; i < points.length; i += 2) {\n max = Math.max(max, Math.hypot(points[i]!, points[i + 1]!));\n }\n\n return max;\n};\n"],"mappings":";;;;AAMA,MAAM,cAAc;;;;;;;;;;AAWpB,IAAa,eAAb,cAAkC,MAAM;CACtC,AAAgB,OAAO;;CAGvB,AAAgB;;CAGhB,AAAgB;CAEhB,AAAgB;CAChB,AAAgB;CAChB,AAAgB;CAEhB,AAAO,YAAY,UAA8C;EAC/D,MAAM;EAEN,IAAI,SAAS,SAAS,GACpB,MAAM,IAAI,WAAW,qDAAqD,SAAS,OAAO,EAAE;EAG9F,MAAM,SAAmB,CAAC;EAE1B,KAAK,MAAM,UAAU,UAAU;GAC7B,IAAI,CAAC,OAAO,SAAS,OAAO,CAAC,KAAK,CAAC,OAAO,SAAS,OAAO,CAAC,GACzD,MAAM,IAAI,WAAW,oDAAoD,OAAO,EAAE,IAAI,OAAO,EAAE,GAAG;GAIpG,MAAM,K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,
|
|
4
|
-
* one-off walls, the geometry a body may not cross.
|
|
5
|
-
*
|
|
6
|
-
* It has no interior, so {@link Shape.massProperties} is `null` and the shape
|
|
7
|
-
* contributes collision only - a `dynamic` body needs at least one mass-bearing
|
|
8
|
-
* collider alongside it.
|
|
9
|
-
*
|
|
10
|
-
* A segment blocks from **both** sides. There is no inside for it to be outside
|
|
11
|
-
* of, and a one-sided segment would be a gameplay rule in a geometry costume:
|
|
12
|
-
* express that with the world's `contactModifier`, which decides per contact and
|
|
13
|
-
* per step whether it is solved.
|
|
14
|
-
*
|
|
15
|
-
* Being zero-thickness makes it the worst case for discrete detection - a body
|
|
16
|
-
* that crosses it entirely within one fixed step misses it. Continuous collision
|
|
17
|
-
* covers a fast body against a segment; a fast segment is not swept.
|
|
18
|
-
*/
|
|
19
|
-
export declare class SegmentShape extends Shape {
|
|
20
|
-
readonly type: 'segment';
|
|
21
|
-
/** Local endpoints, flattened - the same layout a polygon uses. */
|
|
22
|
-
readonly vertices: readonly number[];
|
|
23
|
-
/** The two opposite outward unit normals, flattened. */
|
|
24
|
-
readonly normals: readonly number[];
|
|
25
|
-
readonly length: number;
|
|
26
|
-
readonly boundingRadius: number;
|
|
27
|
-
/** Always `null`: a boundary has no interior and therefore no mass. */
|
|
28
|
-
readonly massProperties: null;
|
|
29
|
-
constructor(x0: number, y0: number, x1: number, y1: number);
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=SegmentShape.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentShape.d.ts","sourceRoot":"","sources":["../../../src/shapes/SegmentShape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKhC;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAG,SAAS,CAAU;IAE1C,mEAAmE;IACnE,SAAgB,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAE5C,wDAAwD;IACxD,SAAgB,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAE3C,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,cAAc,EAAE,MAAM,CAAC;IAEvC,uEAAuE;IACvE,SAAgB,cAAc,OAAQ;IAEtC,YAAmB,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EA8BhE;CACF"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Shape } from "./Shape.js";
|
|
2
|
-
|
|
3
|
-
//#region src/shapes/SegmentShape.ts
|
|
4
|
-
/** Segments shorter than this (px) have no well-defined orientation. */
|
|
5
|
-
const minimumLength = .001;
|
|
6
|
-
/**
|
|
7
|
-
* A zero-thickness boundary between two local-space endpoints: level edges,
|
|
8
|
-
* one-off walls, the geometry a body may not cross.
|
|
9
|
-
*
|
|
10
|
-
* It has no interior, so {@link Shape.massProperties} is `null` and the shape
|
|
11
|
-
* contributes collision only - a `dynamic` body needs at least one mass-bearing
|
|
12
|
-
* collider alongside it.
|
|
13
|
-
*
|
|
14
|
-
* A segment blocks from **both** sides. There is no inside for it to be outside
|
|
15
|
-
* of, and a one-sided segment would be a gameplay rule in a geometry costume:
|
|
16
|
-
* express that with the world's `contactModifier`, which decides per contact and
|
|
17
|
-
* per step whether it is solved.
|
|
18
|
-
*
|
|
19
|
-
* Being zero-thickness makes it the worst case for discrete detection - a body
|
|
20
|
-
* that crosses it entirely within one fixed step misses it. Continuous collision
|
|
21
|
-
* covers a fast body against a segment; a fast segment is not swept.
|
|
22
|
-
*/
|
|
23
|
-
var SegmentShape = class SegmentShape extends Shape {
|
|
24
|
-
type = "segment";
|
|
25
|
-
/** Local endpoints, flattened - the same layout a polygon uses. */
|
|
26
|
-
vertices;
|
|
27
|
-
/** The two opposite outward unit normals, flattened. */
|
|
28
|
-
normals;
|
|
29
|
-
length;
|
|
30
|
-
boundingRadius;
|
|
31
|
-
/** Always `null`: a boundary has no interior and therefore no mass. */
|
|
32
|
-
massProperties = null;
|
|
33
|
-
constructor(x0, y0, x1, y1) {
|
|
34
|
-
super();
|
|
35
|
-
if (!Number.isFinite(x0) || !Number.isFinite(y0) || !Number.isFinite(x1) || !Number.isFinite(y1)) throw new RangeError(`SegmentShape: endpoints must be finite, received (${x0}, ${y0}) and (${x1}, ${y1}).`);
|
|
36
|
-
const ex = x1 - x0;
|
|
37
|
-
const ey = y1 - y0;
|
|
38
|
-
const length = Math.hypot(ex, ey);
|
|
39
|
-
if (length < minimumLength) throw new RangeError(`SegmentShape: the endpoints are coincident (length ${length}).`);
|
|
40
|
-
const nx = ey / length;
|
|
41
|
-
const ny = -ex / length;
|
|
42
|
-
this.length = length;
|
|
43
|
-
this.vertices = Object.freeze([
|
|
44
|
-
x0,
|
|
45
|
-
y0,
|
|
46
|
-
x1,
|
|
47
|
-
y1
|
|
48
|
-
]);
|
|
49
|
-
this.normals = Object.freeze([
|
|
50
|
-
nx,
|
|
51
|
-
ny,
|
|
52
|
-
-nx,
|
|
53
|
-
-ny
|
|
54
|
-
]);
|
|
55
|
-
this.boundingRadius = Math.max(Math.hypot(x0, y0), Math.hypot(x1, y1));
|
|
56
|
-
if (new.target === SegmentShape) Object.freeze(this);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
//#endregion
|
|
61
|
-
export { SegmentShape };
|
|
62
|
-
//# sourceMappingURL=SegmentShape.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentShape.js","names":[],"sources":["../../../src/shapes/SegmentShape.ts"],"sourcesContent":["import { Shape } from './Shape';\n\n/** Segments shorter than this (px) have no well-defined orientation. */\nconst minimumLength = 1e-3;\n\n/**\n * A zero-thickness boundary between two local-space endpoints: level edges,\n * one-off walls, the geometry a body may not cross.\n *\n * It has no interior, so {@link Shape.massProperties} is `null` and the shape\n * contributes collision only - a `dynamic` body needs at least one mass-bearing\n * collider alongside it.\n *\n * A segment blocks from **both** sides. There is no inside for it to be outside\n * of, and a one-sided segment would be a gameplay rule in a geometry costume:\n * express that with the world's `contactModifier`, which decides per contact and\n * per step whether it is solved.\n *\n * Being zero-thickness makes it the worst case for discrete detection - a body\n * that crosses it entirely within one fixed step misses it. Continuous collision\n * covers a fast body against a segment; a fast segment is not swept.\n */\nexport class SegmentShape extends Shape {\n public readonly type = 'segment' as const;\n\n /** Local endpoints, flattened - the same layout a polygon uses. */\n public readonly vertices: readonly number[];\n\n /** The two opposite outward unit normals, flattened. */\n public readonly normals: readonly number[];\n\n public readonly length: number;\n public readonly boundingRadius: number;\n\n /** Always `null`: a boundary has no interior and therefore no mass. */\n public readonly massProperties = null;\n\n public constructor(x0: number, y0: number, x1: number, y1: number) {\n super();\n\n if (!Number.isFinite(x0) || !Number.isFinite(y0) || !Number.isFinite(x1) || !Number.isFinite(y1)) {\n throw new RangeError(`SegmentShape: endpoints must be finite, received (${x0}, ${y0}) and (${x1}, ${y1}).`);\n }\n\n const ex = x1 - x0;\n const ey = y1 - y0;\n const length = Math.hypot(ex, ey);\n\n if (length < minimumLength) {\n throw new RangeError(`SegmentShape: the endpoints are coincident (length ${length}).`);\n }\n\n // Same convention as PolygonShape: the outward normal of the counter-clockwise\n // edge i → i+1 is (eY, -eX). A two-vertex ring has two opposite edges.\n const nx = ey / length;\n const ny = -ex / length;\n\n this.length = length;\n this.vertices = Object.freeze([x0, y0, x1, y1]);\n this.normals = Object.freeze([nx, ny, -nx, -ny]);\n this.boundingRadius = Math.max(Math.hypot(x0, y0), Math.hypot(x1, y1));\n\n // A subclass still has its own fields to write, so it freezes itself once\n // its constructor is done.\n if (new.target === SegmentShape) {\n Object.freeze(this);\n }\n }\n}\n"],"mappings":";;;;AAGA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;AAmBtB,IAAa,eAAb,MAAa,qBAAqB,MAAM;CACtC,AAAgB,OAAO;;CAGvB,AAAgB;;CAGhB,AAAgB;CAEhB,AAAgB;CAChB,AAAgB;;CAGhB,AAAgB,iBAAiB;CAEjC,AAAO,YAAY,IAAY,IAAY,IAAY,IAAY;EACjE,MAAM;EAEN,IAAI,CAAC,OAAO,SAAS,EAAE,KAAK,CAAC,OAAO,SAAS,EAAE,KAAK,CAAC,OAAO,SAAS,EAAE,KAAK,CAAC,OAAO,SAAS,EAAE,GAC7F,MAAM,IAAI,WAAW,qDAAqD,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,GAAG,GAAG;EAG5G,MAAM,KAAK,KAAK;EAChB,MAAM,KAAK,KAAK;EAChB,MAAM,SAAS,KAAK,MAAM,IAAI,EAAE;EAEhC,IAAI,SAAS,eACX,MAAM,IAAI,WAAW,sDAAsD,OAAO,GAAG;EAKvF,MAAM,KAAK,KAAK;EAChB,MAAM,KAAK,CAAC,KAAK;EAEjB,KAAK,SAAS;EACd,KAAK,WAAW,OAAO,OAAO;GAAC;GAAI;GAAI;GAAI;EAAE,CAAC;EAC9C,KAAK,UAAU,OAAO,OAAO;GAAC;GAAI;GAAI,CAAC;GAAI,CAAC;EAAE,CAAC;EAC/C,KAAK,iBAAiB,KAAK,IAAI,KAAK,MAAM,IAAI,EAAE,GAAG,KAAK,MAAM,IAAI,EAAE,CAAC;EAIrE,IAAI,eAAe,cACjB,OAAO,OAAO,IAAI;CAEtB;AACF"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/** Discriminant for the concrete shape kinds supported in the MVP. */
|
|
2
|
-
export type ShapeType = 'circle' | 'capsule' | 'segment' | 'polygon' | 'chain';
|
|
3
|
-
/**
|
|
4
|
-
* Area-based mass properties of a solid shape, from which a {@link Collider}'s
|
|
5
|
-
* density derives the owning body's mass and rotational inertia. Computed once
|
|
6
|
-
* at shape construction and frozen.
|
|
7
|
-
*/
|
|
8
|
-
export interface ShapeMassProperties {
|
|
9
|
-
/** Surface area in px². `mass = density × area`. */
|
|
10
|
-
readonly area: number;
|
|
11
|
-
/** X of the area centroid in local space. */
|
|
12
|
-
readonly centroidX: number;
|
|
13
|
-
/** Y of the area centroid in local space. */
|
|
14
|
-
readonly centroidY: number;
|
|
15
|
-
/**
|
|
16
|
-
* Second moment of area about the centroid (∫ r² dA). Multiplying by density
|
|
17
|
-
* yields the shape's rotational inertia contribution about its centroid.
|
|
18
|
-
*/
|
|
19
|
-
readonly unitInertia: number;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Immutable local-space collision geometry. A `Shape` carries no transform - a
|
|
23
|
-
* {@link Collider} positions it in a body.
|
|
24
|
-
*
|
|
25
|
-
* Having an interior is a capability, not a given: solid shapes expose
|
|
26
|
-
* {@link massProperties}, while boundary geometry (a segment, a chain of edges)
|
|
27
|
-
* reports `null` and contributes nothing to the owning body's mass. Read the
|
|
28
|
-
* property rather than assuming an area exists.
|
|
29
|
-
*/
|
|
30
|
-
export declare abstract class Shape {
|
|
31
|
-
abstract readonly type: ShapeType;
|
|
32
|
-
/** Radius of the smallest circle about the local origin enclosing the shape. */
|
|
33
|
-
abstract readonly boundingRadius: number;
|
|
34
|
-
/** Area-based mass properties, or `null` for boundary geometry with no interior. */
|
|
35
|
-
abstract readonly massProperties: ShapeMassProperties | null;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=Shape.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Shape.d.ts","sourceRoot":"","sources":["../../../src/shapes/Shape.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAE/E;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;GAQG;AACH,8BAAsB,KAAK;IACzB,kBAAyB,IAAI,EAAE,SAAS,CAAC;IAEzC,gFAAgF;IAChF,kBAAyB,cAAc,EAAE,MAAM,CAAC;IAEhD,oFAAoF;IACpF,kBAAyB,cAAc,EAAE,mBAAmB,GAAG,IAAI,CAAC;CACrE"}
|
package/dist/esm/shapes/Shape.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//#region src/shapes/Shape.ts
|
|
2
|
-
/**
|
|
3
|
-
* Immutable local-space collision geometry. A `Shape` carries no transform - a
|
|
4
|
-
* {@link Collider} positions it in a body.
|
|
5
|
-
*
|
|
6
|
-
* Having an interior is a capability, not a given: solid shapes expose
|
|
7
|
-
* {@link massProperties}, while boundary geometry (a segment, a chain of edges)
|
|
8
|
-
* reports `null` and contributes nothing to the owning body's mass. Read the
|
|
9
|
-
* property rather than assuming an area exists.
|
|
10
|
-
*/
|
|
11
|
-
var Shape = class {};
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
export { Shape };
|
|
15
|
-
//# sourceMappingURL=Shape.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Shape.js","names":[],"sources":["../../../src/shapes/Shape.ts"],"sourcesContent":["/** Discriminant for the concrete shape kinds supported in the MVP. */\nexport type ShapeType = 'circle' | 'capsule' | 'segment' | 'polygon' | 'chain';\n\n/**\n * Area-based mass properties of a solid shape, from which a {@link Collider}'s\n * density derives the owning body's mass and rotational inertia. Computed once\n * at shape construction and frozen.\n */\nexport interface ShapeMassProperties {\n /** Surface area in px². `mass = density × area`. */\n readonly area: number;\n /** X of the area centroid in local space. */\n readonly centroidX: number;\n /** Y of the area centroid in local space. */\n readonly centroidY: number;\n /**\n * Second moment of area about the centroid (∫ r² dA). Multiplying by density\n * yields the shape's rotational inertia contribution about its centroid.\n */\n readonly unitInertia: number;\n}\n\n/**\n * Immutable local-space collision geometry. A `Shape` carries no transform - a\n * {@link Collider} positions it in a body.\n *\n * Having an interior is a capability, not a given: solid shapes expose\n * {@link massProperties}, while boundary geometry (a segment, a chain of edges)\n * reports `null` and contributes nothing to the owning body's mass. Read the\n * property rather than assuming an area exists.\n */\nexport abstract class Shape {\n public abstract readonly type: ShapeType;\n\n /** Radius of the smallest circle about the local origin enclosing the shape. */\n public abstract readonly boundingRadius: number;\n\n /** Area-based mass properties, or `null` for boundary geometry with no interior. */\n public abstract readonly massProperties: ShapeMassProperties | null;\n}\n"],"mappings":";;;;;;;;;;AA+BA,IAAsB,QAAtB,MAA4B,CAQ5B"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { PointLike } from '@codexo/exojs';
|
|
2
|
-
import { PolygonShape } from './PolygonShape';
|
|
3
|
-
/**
|
|
4
|
-
* Turn one possibly-concave outline into the convex solver shapes that
|
|
5
|
-
* represent it. Attach all of them to a single body: together they are the
|
|
6
|
-
* original area, and a `PolygonShape` stays exactly one convex shape rather
|
|
7
|
-
* than secretly standing for several.
|
|
8
|
-
*
|
|
9
|
-
* The number of shapes and their order follow from the current decomposition
|
|
10
|
-
* and are not a stable contract; the preserved properties are the area, the
|
|
11
|
-
* centre of mass and the rotational inertia of the compound.
|
|
12
|
-
*
|
|
13
|
-
* An already-convex outline yields exactly one shape, so a caller that does not
|
|
14
|
-
* know whether its input is convex can route everything through here.
|
|
15
|
-
*
|
|
16
|
-
* @throws RangeError on a non-finite coordinate, on fewer than three distinct
|
|
17
|
-
* non-collinear vertices, on a self-intersecting outline, or when a part comes
|
|
18
|
-
* out too degenerate for {@link PolygonShape}.
|
|
19
|
-
*/
|
|
20
|
-
export declare const toConvexPolygonShapes: (vertices: ReadonlyArray<Readonly<PointLike>>) => PolygonShape[];
|
|
21
|
-
//# sourceMappingURL=convexParts.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convexParts.d.ts","sourceRoot":"","sources":["../../../src/shapes/convexParts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qBAAqB,aAAc,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,KAAG,YAAY,EAC3B,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { PolygonShape } from "./PolygonShape.js";
|
|
2
|
-
import { decomposeToConvexParts } from "./decompose.js";
|
|
3
|
-
|
|
4
|
-
//#region src/shapes/convexParts.ts
|
|
5
|
-
/**
|
|
6
|
-
* Turn one possibly-concave outline into the convex solver shapes that
|
|
7
|
-
* represent it. Attach all of them to a single body: together they are the
|
|
8
|
-
* original area, and a `PolygonShape` stays exactly one convex shape rather
|
|
9
|
-
* than secretly standing for several.
|
|
10
|
-
*
|
|
11
|
-
* The number of shapes and their order follow from the current decomposition
|
|
12
|
-
* and are not a stable contract; the preserved properties are the area, the
|
|
13
|
-
* centre of mass and the rotational inertia of the compound.
|
|
14
|
-
*
|
|
15
|
-
* An already-convex outline yields exactly one shape, so a caller that does not
|
|
16
|
-
* know whether its input is convex can route everything through here.
|
|
17
|
-
*
|
|
18
|
-
* @throws RangeError on a non-finite coordinate, on fewer than three distinct
|
|
19
|
-
* non-collinear vertices, on a self-intersecting outline, or when a part comes
|
|
20
|
-
* out too degenerate for {@link PolygonShape}.
|
|
21
|
-
*/
|
|
22
|
-
const toConvexPolygonShapes = (vertices) => decomposeToConvexParts(vertices).map((part) => new PolygonShape(part));
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
export { toConvexPolygonShapes };
|
|
26
|
-
//# sourceMappingURL=convexParts.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convexParts.js","names":[],"sources":["../../../src/shapes/convexParts.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { decomposeToConvexParts } from './decompose';\nimport { PolygonShape } from './PolygonShape';\n\n/**\n * Turn one possibly-concave outline into the convex solver shapes that\n * represent it. Attach all of them to a single body: together they are the\n * original area, and a `PolygonShape` stays exactly one convex shape rather\n * than secretly standing for several.\n *\n * The number of shapes and their order follow from the current decomposition\n * and are not a stable contract; the preserved properties are the area, the\n * centre of mass and the rotational inertia of the compound.\n *\n * An already-convex outline yields exactly one shape, so a caller that does not\n * know whether its input is convex can route everything through here.\n *\n * @throws RangeError on a non-finite coordinate, on fewer than three distinct\n * non-collinear vertices, on a self-intersecting outline, or when a part comes\n * out too degenerate for {@link PolygonShape}.\n */\nexport const toConvexPolygonShapes = (vertices: ReadonlyArray<Readonly<PointLike>>): PolygonShape[] =>\n decomposeToConvexParts(vertices).map(part => new PolygonShape(part));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,yBAAyB,aACpC,uBAAuB,QAAQ,CAAC,CAAC,KAAI,SAAQ,IAAI,aAAa,IAAI,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decompose.d.ts","sourceRoot":"","sources":["../../../src/shapes/decompose.ts"],"names":[],"mappings":""}
|