@perplexdotgg/bounce 1.0.0 → 1.0.2
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/build/bounce.d.ts +39501 -0
- package/build/bounce.js +17166 -0
- package/package.json +1 -1
- package/src/builders/ConvexHullBuilder.ts +0 -437
- package/src/builders/ConvexHullBuilder2d.ts +0 -344
- package/src/builders/ConvexHullBuilder3d.ts +0 -1689
- package/src/builders/HeightMapBuilder.ts +0 -414
- package/src/builders/TriangleMeshBuilder.ts +0 -92
- package/src/collision/CastShapesModule.ts +0 -184
- package/src/collision/CollideShapesModule.ts +0 -152
- package/src/collision/HeightMapCaster.ts +0 -38
- package/src/collision/HeightMapCollider.ts +0 -33
- package/src/collision/TriangleCaster.ts +0 -249
- package/src/collision/TriangleCollider.ts +0 -308
- package/src/collision/TriangleCollider2.ts +0 -379
- package/src/collision/activeEdge.ts +0 -146
- package/src/collision/cast/cast.ts +0 -139
- package/src/collision/cast/castCompoundVsCompound.ts +0 -59
- package/src/collision/cast/castCompoundVsConvex.ts +0 -116
- package/src/collision/cast/castConvexVsCompound.ts +0 -123
- package/src/collision/cast/castConvexVsConvex.ts +0 -213
- package/src/collision/cast/castConvexVsHeightMap.ts +0 -73
- package/src/collision/cast/castConvexVsTriangleMesh.ts +0 -56
- package/src/collision/cast/castRayVsCompound.ts +0 -44
- package/src/collision/cast/castRayVsConvex.ts +0 -45
- package/src/collision/cast/castRayVsHeightMap.ts +0 -58
- package/src/collision/cast/castRayVsTriangleMesh.ts +0 -58
- package/src/collision/closestPoints/closestPoints.ts +0 -23
- package/src/collision/closestPoints/computeBarycentricCoordinates2d.ts +0 -32
- package/src/collision/closestPoints/computeBarycentricCoordinates3d.ts +0 -81
- package/src/collision/closestPoints/computeClosestPointOnLine.ts +0 -30
- package/src/collision/closestPoints/computeClosestPointOnTetrahedron.ts +0 -96
- package/src/collision/closestPoints/computeClosestPointOnTriangle.ts +0 -195
- package/src/collision/closestPoints/isOriginOutsideOfPlane.ts +0 -25
- package/src/collision/closestPoints/isOriginOutsideOfTrianglePlanes.ts +0 -72
- package/src/collision/collide/collide.ts +0 -146
- package/src/collision/collide/collideCompoundVsCompound.ts +0 -60
- package/src/collision/collide/collideCompoundVsConvex.ts +0 -59
- package/src/collision/collide/collideCompoundVsHeightMap.ts +0 -73
- package/src/collision/collide/collideCompoundVsTriangleMesh.ts +0 -56
- package/src/collision/collide/collideConvexVsCompound.ts +0 -57
- package/src/collision/collide/collideConvexVsConvex.ts +0 -225
- package/src/collision/collide/collideConvexVsConvexImp.ts +0 -236
- package/src/collision/collide/collideConvexVsHeightMap.ts +0 -53
- package/src/collision/collide/collideConvexVsTriangleMesh.ts +0 -58
- package/src/collision/collide/collideHeightMapVsCompound.ts +0 -69
- package/src/collision/collide/collideHeightMapVsConvex.ts +0 -53
- package/src/collision/collide/collideSphereVsSphere.ts +0 -81
- package/src/collision/collide/collideTriangleMeshVsCompound.ts +0 -58
- package/src/collision/collide/collideTriangleMeshVsConvex.ts +0 -58
- package/src/collision/epa/EpaConvexHullBuilder.ts +0 -397
- package/src/collision/epa/StaticArray.ts +0 -154
- package/src/collision/epa/TriangleFactory.ts +0 -32
- package/src/collision/epa/arrays.ts +0 -99
- package/src/collision/epa/binaryHeap.ts +0 -82
- package/src/collision/epa/structs.ts +0 -227
- package/src/collision/gjk/GjkModule.ts +0 -864
- package/src/collision/gjk/PenetrationDepthModule.ts +0 -493
- package/src/collision/gjk/SupportPoints.ts +0 -50
- package/src/collision/imp/MinkowskiDifference.ts +0 -36
- package/src/collision/imp/computeExploredDistanceLowerUpperBound.ts +0 -40
- package/src/collision/imp/finalizeImpResult.ts +0 -69
- package/src/collision/imp/findContactImp.ts +0 -196
- package/src/collision/imp/imp.ts +0 -28
- package/src/collision/imp/incrementalMinimumDistanceExploreDirection.ts +0 -207
- package/src/collision/mpr/findPortal.ts +0 -152
- package/src/collision/mpr/mpr.ts +0 -29
- package/src/collision/mpr/updatePortal.ts +0 -52
- package/src/constraints/BaseConstraint.ts +0 -50
- package/src/constraints/ConstraintOptions.ts +0 -22
- package/src/constraints/ConstraintSolver.ts +0 -119
- package/src/constraints/DistanceConstraint.ts +0 -229
- package/src/constraints/FixedConstraint.ts +0 -203
- package/src/constraints/HingeConstraint.ts +0 -460
- package/src/constraints/PointConstraint.ts +0 -108
- package/src/constraints/components/AngleComponent.ts +0 -226
- package/src/constraints/components/AxisComponent.ts +0 -263
- package/src/constraints/components/HingeComponent.ts +0 -215
- package/src/constraints/components/Motor.ts +0 -36
- package/src/constraints/components/PointConstraintComponent.ts +0 -179
- package/src/constraints/components/RotationEulerComponent.ts +0 -139
- package/src/constraints/components/Spring.ts +0 -30
- package/src/constraints/components/SpringComponent.ts +0 -71
- package/src/constraints/types.ts +0 -6
- package/src/helpers.ts +0 -147
- package/src/index.ts +0 -50
- package/src/math/BasicTransform.ts +0 -19
- package/src/math/NumberValue.ts +0 -13
- package/src/math/isometry.ts +0 -64
- package/src/math/mat3.ts +0 -529
- package/src/math/mat4.ts +0 -588
- package/src/math/quat.ts +0 -193
- package/src/math/scalar.ts +0 -81
- package/src/math/tensor.ts +0 -17
- package/src/math/vec3.ts +0 -589
- package/src/math/vec4.ts +0 -10
- package/src/physics/Body.ts +0 -581
- package/src/physics/CollisionFilter.ts +0 -52
- package/src/physics/SleepModule.ts +0 -163
- package/src/physics/broadphase/BodyPairsModule.ts +0 -363
- package/src/physics/broadphase/BvhModule.ts +0 -237
- package/src/physics/broadphase/BvhTree.ts +0 -803
- package/src/physics/broadphase/ConstraintPairsModule.ts +0 -385
- package/src/physics/broadphase/TriangleMeshBvhTree.ts +0 -379
- package/src/physics/manifold/ContactManifold.ts +0 -227
- package/src/physics/manifold/ContactManifoldModule.ts +0 -623
- package/src/physics/manifold/Face.ts +0 -119
- package/src/physics/manifold/ManifoldCache.ts +0 -116
- package/src/physics/manifold/clipping/clipPolyVsEdge.ts +0 -131
- package/src/physics/manifold/clipping/clipPolyVsPlane.ts +0 -73
- package/src/physics/manifold/clipping/clipPolyVsPoly.ts +0 -72
- package/src/physics/narrowphase/CollideBodiesModule.ts +0 -755
- package/src/physics/solver/ContactConstraintModule.ts +0 -659
- package/src/physics/solver/ManifoldConstraint.ts +0 -420
- package/src/physics/solver/estimateCollisionResponse.ts +0 -146
- package/src/shape/Aabb.ts +0 -400
- package/src/shape/Box.ts +0 -231
- package/src/shape/Capsule.ts +0 -332
- package/src/shape/CompoundShape.ts +0 -288
- package/src/shape/Convex.ts +0 -130
- package/src/shape/ConvexHull.ts +0 -423
- package/src/shape/Cylinder.ts +0 -313
- package/src/shape/HeightMap.ts +0 -511
- package/src/shape/Line.ts +0 -14
- package/src/shape/Plane.ts +0 -116
- package/src/shape/Ray.ts +0 -81
- package/src/shape/Segment.ts +0 -25
- package/src/shape/Shape.ts +0 -77
- package/src/shape/Sphere.ts +0 -181
- package/src/shape/TransformedShape.ts +0 -51
- package/src/shape/Triangle.ts +0 -122
- package/src/shape/TriangleMesh.ts +0 -186
- package/src/types.ts +0 -1
- package/src/world.ts +0 -1335
- package/tests/BodyPairsModule.test.ts +0 -71
- package/tests/BvhTree.test.ts +0 -406
- package/tests/test.md +0 -642
- package/tests/vec3.test.ts +0 -12
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
import { PoolClass } from "monomorph";
|
|
2
|
-
import { Vec3 } from "../math/vec3";
|
|
3
|
-
import { squared } from "../math/scalar";
|
|
4
|
-
|
|
5
|
-
// TODO: this may need to change, not sure if value is too large
|
|
6
|
-
const floatEpsilon = 1e-5;
|
|
7
|
-
|
|
8
|
-
const normal = /*@__PURE__*/ Vec3.create();
|
|
9
|
-
const center = /*@__PURE__*/ Vec3.create();
|
|
10
|
-
const tempVector = /*@__PURE__*/ Vec3.create();
|
|
11
|
-
|
|
12
|
-
const p1 = /*@__PURE__*/ Vec3.create();
|
|
13
|
-
const p2 = /*@__PURE__*/ Vec3.create();
|
|
14
|
-
|
|
15
|
-
const edge = /*@__PURE__*/ Vec3.create();
|
|
16
|
-
const point = /*@__PURE__*/ Vec3.create();
|
|
17
|
-
|
|
18
|
-
const maxComponents = /*@__PURE__*/ Vec3.create();
|
|
19
|
-
const currentVertex = /*@__PURE__*/ Vec3.create();
|
|
20
|
-
const vertexA = /*@__PURE__*/ Vec3.create();
|
|
21
|
-
const vertexB = /*@__PURE__*/ Vec3.create();
|
|
22
|
-
const vertexC = /*@__PURE__*/ Vec3.create();
|
|
23
|
-
const vectorAB = /*@__PURE__*/ Vec3.create();
|
|
24
|
-
const vectorAC = /*@__PURE__*/ Vec3.create();
|
|
25
|
-
const crossAB_AC = /*@__PURE__*/ Vec3.create();
|
|
26
|
-
const furthestPoint = /*@__PURE__*/ Vec3.create();
|
|
27
|
-
|
|
28
|
-
/// Result enum that indicates how the hull got created
|
|
29
|
-
export const enum ConvexHullBuilder2dResult {
|
|
30
|
-
Success, ///< Hull building finished successfully
|
|
31
|
-
MaxVerticesReached, ///< Hull building finished successfully, but the desired accuracy was not reached because the max vertices limit was reached
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type Tuple3 = [number, number, number];
|
|
35
|
-
|
|
36
|
-
class ConvexHull2dEdge {
|
|
37
|
-
normal: Tuple3;
|
|
38
|
-
center: Tuple3;
|
|
39
|
-
conflictList: number[];
|
|
40
|
-
prevEdge?: ConvexHull2dEdge;
|
|
41
|
-
nextEdge?: ConvexHull2dEdge;
|
|
42
|
-
startIndex: number;
|
|
43
|
-
furthestPointDistanceSquared: number = 0;
|
|
44
|
-
|
|
45
|
-
constructor(startIndex: number) {
|
|
46
|
-
this.normal = [0, 0, 0];
|
|
47
|
-
this.center = [0, 0, 0];
|
|
48
|
-
this.conflictList = [];
|
|
49
|
-
this.startIndex = startIndex;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
isFacing(position: Vec3): boolean {
|
|
53
|
-
normal.x = this.normal[0];
|
|
54
|
-
normal.y = this.normal[1];
|
|
55
|
-
normal.z = this.normal[2];
|
|
56
|
-
|
|
57
|
-
center.x = this.center[0];
|
|
58
|
-
center.y = this.center[1];
|
|
59
|
-
center.z = this.center[2];
|
|
60
|
-
|
|
61
|
-
tempVector.subtractVectors(position, center);
|
|
62
|
-
return normal.dot(tempVector) > 0;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
calculateNormalAndCenter(polyhedron: PoolClass<Vec3>): void {
|
|
66
|
-
p1.copy(polyhedron.array[this.startIndex]);
|
|
67
|
-
p2.copy(polyhedron.array[this.nextEdge!.startIndex]);
|
|
68
|
-
|
|
69
|
-
// Center of edge
|
|
70
|
-
center.addVectors(p1, p2);
|
|
71
|
-
center.scale(0.5);
|
|
72
|
-
|
|
73
|
-
// Create outward pointing normal.
|
|
74
|
-
// We have two choices for the normal (which satisfies normal . edge = 0):
|
|
75
|
-
// normal1 = (-edge.y, edge.x, 0)
|
|
76
|
-
// normal2 = (edge.y, -edge.x, 0)
|
|
77
|
-
// We want (normal x edge).z > 0 so that the normal points out of the polygon. Only normal2 satisfies this condition.
|
|
78
|
-
edge.subtractVectors(p2, p1);
|
|
79
|
-
normal.x = edge.y;
|
|
80
|
-
normal.y = -edge.x;
|
|
81
|
-
normal.z = 0;
|
|
82
|
-
|
|
83
|
-
this.normal[0] = normal.x;
|
|
84
|
-
this.normal[1] = normal.y;
|
|
85
|
-
this.normal[2] = normal.z;
|
|
86
|
-
|
|
87
|
-
this.center[0] = center.x;
|
|
88
|
-
this.center[1] = center.y;
|
|
89
|
-
this.center[2] = center.z;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export class ConvexHullBuilder2d {
|
|
94
|
-
firstEdge?: ConvexHull2dEdge;
|
|
95
|
-
numEdges: number = 0;
|
|
96
|
-
|
|
97
|
-
freeEdges(): void {
|
|
98
|
-
this.firstEdge = undefined;
|
|
99
|
-
this.numEdges = 0;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
validateEdges(): void {
|
|
103
|
-
if (this.firstEdge === undefined) {
|
|
104
|
-
if (this.numEdges !== 0) {
|
|
105
|
-
throw new Error("mNumEdges is not 0");
|
|
106
|
-
}
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
let count = 0;
|
|
111
|
-
|
|
112
|
-
let edge = this.firstEdge;
|
|
113
|
-
do {
|
|
114
|
-
// Validate connectivity
|
|
115
|
-
if (edge.nextEdge!.prevEdge !== edge) {
|
|
116
|
-
throw new Error("edge->mNextEdge->mPrevEdge != edge");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (edge.prevEdge!.nextEdge !== edge) {
|
|
120
|
-
throw new Error("edge->mPrevEdge->mNextEdge != edge");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
++count;
|
|
124
|
-
edge = edge.nextEdge!;
|
|
125
|
-
} while (edge !== this.firstEdge);
|
|
126
|
-
|
|
127
|
-
// Validate that count matches
|
|
128
|
-
if (count !== this.numEdges) {
|
|
129
|
-
throw new Error("count != mNumEdges");
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
assignPointToEdge(polyhedron: PoolClass<Vec3>, positionIndex: number, edges: ConvexHull2dEdge[]): void {
|
|
134
|
-
point.copy(polyhedron.array[positionIndex]);
|
|
135
|
-
|
|
136
|
-
let bestEdge: ConvexHull2dEdge | undefined = undefined;
|
|
137
|
-
let bestDistanceSquared = 0;
|
|
138
|
-
|
|
139
|
-
// Test against all edges
|
|
140
|
-
for (const edge of edges) {
|
|
141
|
-
// Determine distance to edge
|
|
142
|
-
normal.x = edge.normal[0];
|
|
143
|
-
normal.y = edge.normal[1];
|
|
144
|
-
normal.z = edge.normal[2];
|
|
145
|
-
|
|
146
|
-
center.x = edge.center[0];
|
|
147
|
-
center.y = edge.center[1];
|
|
148
|
-
center.z = edge.center[2];
|
|
149
|
-
|
|
150
|
-
tempVector.subtractVectors(point, center);
|
|
151
|
-
const dot = normal.dot(tempVector);
|
|
152
|
-
if (dot > 0.0) {
|
|
153
|
-
const distanceSquared = (dot * dot) / normal.squaredLength();
|
|
154
|
-
if (distanceSquared > bestDistanceSquared) {
|
|
155
|
-
bestEdge = edge;
|
|
156
|
-
bestDistanceSquared = distanceSquared;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// If this point is in front of the edge, add it to the conflict list
|
|
162
|
-
if (bestEdge) {
|
|
163
|
-
if (bestDistanceSquared > bestEdge.furthestPointDistanceSquared) {
|
|
164
|
-
// This point is futher away than any others, update the distance and add point as last point
|
|
165
|
-
bestEdge.furthestPointDistanceSquared = bestDistanceSquared;
|
|
166
|
-
bestEdge.conflictList.push(positionIndex);
|
|
167
|
-
} else {
|
|
168
|
-
// Not the furthest point, add it as the before last point
|
|
169
|
-
bestEdge.conflictList.push(bestEdge.conflictList[bestEdge.conflictList.length - 1]);
|
|
170
|
-
bestEdge.conflictList[bestEdge.conflictList.length - 2] = positionIndex;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
buildConvexHull(
|
|
176
|
-
outEdges: number[],
|
|
177
|
-
index1: number,
|
|
178
|
-
index2: number,
|
|
179
|
-
index3: number,
|
|
180
|
-
polyhedron: PoolClass<Vec3>,
|
|
181
|
-
tolerance: number,
|
|
182
|
-
maxVertexCount: number
|
|
183
|
-
): ConvexHullBuilder2dResult {
|
|
184
|
-
// Clear any leftovers
|
|
185
|
-
this.freeEdges();
|
|
186
|
-
outEdges.length = 0;
|
|
187
|
-
|
|
188
|
-
// Reset flag
|
|
189
|
-
let result: ConvexHullBuilder2dResult = ConvexHullBuilder2dResult.Success;
|
|
190
|
-
|
|
191
|
-
// Determine a suitable tolerance for detecting that points are colinear
|
|
192
|
-
// Formula as per: Implementing Quickhull - Dirk Gregorius.
|
|
193
|
-
maxComponents.zero();
|
|
194
|
-
for (let i = 0; i < polyhedron.length; i++) {
|
|
195
|
-
currentVertex.copy(polyhedron.array[i]);
|
|
196
|
-
maxComponents.x = Math.max(maxComponents.x, Math.abs(currentVertex.x));
|
|
197
|
-
maxComponents.y = Math.max(maxComponents.y, Math.abs(currentVertex.y));
|
|
198
|
-
// maxComponents.z = Math.max(maxComponents.z, Math.abs(currentVertex.z));
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const colinearToleranceSquared = squared(2.0 * floatEpsilon * (maxComponents.x + maxComponents.y));
|
|
202
|
-
|
|
203
|
-
// Increase desired tolerance if accuracy doesn't allow it
|
|
204
|
-
const toleranceSquared = Math.max(colinearToleranceSquared, squared(tolerance));
|
|
205
|
-
|
|
206
|
-
// Start with the initial indices in counter clockwise order
|
|
207
|
-
vertexA.copy(polyhedron.array[index1]);
|
|
208
|
-
vertexB.copy(polyhedron.array[index2]);
|
|
209
|
-
vertexC.copy(polyhedron.array[index3]);
|
|
210
|
-
vectorAB.subtractVectors(vertexB, vertexA);
|
|
211
|
-
vectorAC.subtractVectors(vertexC, vertexA);
|
|
212
|
-
crossAB_AC.crossVectors(vectorAB, vectorAC);
|
|
213
|
-
const z = crossAB_AC.z;
|
|
214
|
-
if (z < 0.0) {
|
|
215
|
-
const tempIndex = index1;
|
|
216
|
-
index1 = index2;
|
|
217
|
-
index2 = tempIndex;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Create and link edges
|
|
221
|
-
const e1 = new ConvexHull2dEdge(index1);
|
|
222
|
-
const e2 = new ConvexHull2dEdge(index2);
|
|
223
|
-
const e3 = new ConvexHull2dEdge(index3);
|
|
224
|
-
e1.nextEdge = e2;
|
|
225
|
-
e1.prevEdge = e3;
|
|
226
|
-
e2.nextEdge = e3;
|
|
227
|
-
e2.prevEdge = e1;
|
|
228
|
-
e3.nextEdge = e1;
|
|
229
|
-
e3.prevEdge = e2;
|
|
230
|
-
this.firstEdge = e1;
|
|
231
|
-
this.numEdges = 3;
|
|
232
|
-
|
|
233
|
-
// Build the initial conflict lists
|
|
234
|
-
const edges: ConvexHull2dEdge[] = [e1, e2, e3];
|
|
235
|
-
for (const edge of edges) {
|
|
236
|
-
edge.calculateNormalAndCenter(polyhedron);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
for (let index = 0; index < polyhedron.length; ++index) {
|
|
240
|
-
if (index === index1 || index === index2 || index === index3) {
|
|
241
|
-
continue;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
this.assignPointToEdge(polyhedron, index, edges);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// Add the remaining points to the hull
|
|
248
|
-
while (true) {
|
|
249
|
-
// Check if we've reached the max amount of vertices that are allowed
|
|
250
|
-
if (this.numEdges >= maxVertexCount) {
|
|
251
|
-
result = ConvexHullBuilder2dResult.MaxVerticesReached;
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Find the edge with the furthest point on it
|
|
256
|
-
let edgeWithFurthestPoint: ConvexHull2dEdge | undefined = undefined;
|
|
257
|
-
let furthestDistanceSquared = 0.0;
|
|
258
|
-
let edge: ConvexHull2dEdge = this.firstEdge;
|
|
259
|
-
|
|
260
|
-
do {
|
|
261
|
-
if (edge.furthestPointDistanceSquared > furthestDistanceSquared) {
|
|
262
|
-
furthestDistanceSquared = edge.furthestPointDistanceSquared;
|
|
263
|
-
edgeWithFurthestPoint = edge;
|
|
264
|
-
}
|
|
265
|
-
edge = edge.nextEdge!;
|
|
266
|
-
} while (edge !== this.firstEdge);
|
|
267
|
-
|
|
268
|
-
// If there is none closer than our tolerance value, we're done
|
|
269
|
-
if (!edgeWithFurthestPoint || furthestDistanceSquared < toleranceSquared) {
|
|
270
|
-
break;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// Take the furthest point
|
|
274
|
-
const furthestPointIndex = edgeWithFurthestPoint.conflictList.pop()!;
|
|
275
|
-
furthestPoint.copy(polyhedron.array[furthestPointIndex]);
|
|
276
|
-
|
|
277
|
-
// Find the horizon of edges that need to be removed
|
|
278
|
-
let firstEdge = edgeWithFurthestPoint;
|
|
279
|
-
do {
|
|
280
|
-
const prev = firstEdge.prevEdge!;
|
|
281
|
-
if (!prev.isFacing(furthestPoint)) {
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
firstEdge = prev;
|
|
285
|
-
} while (firstEdge !== edgeWithFurthestPoint);
|
|
286
|
-
|
|
287
|
-
let lastEdge = edgeWithFurthestPoint;
|
|
288
|
-
do {
|
|
289
|
-
const next = lastEdge.nextEdge!;
|
|
290
|
-
if (!next.isFacing(furthestPoint)) {
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
lastEdge = next;
|
|
294
|
-
} while (lastEdge !== edgeWithFurthestPoint);
|
|
295
|
-
|
|
296
|
-
// Create new edges
|
|
297
|
-
const e1 = new ConvexHull2dEdge(firstEdge.startIndex);
|
|
298
|
-
const e2 = new ConvexHull2dEdge(furthestPointIndex);
|
|
299
|
-
e1.nextEdge = e2;
|
|
300
|
-
e1.prevEdge = firstEdge.prevEdge;
|
|
301
|
-
e2.prevEdge = e1;
|
|
302
|
-
e2.nextEdge = lastEdge.nextEdge;
|
|
303
|
-
e1.prevEdge!.nextEdge = e1;
|
|
304
|
-
e2.nextEdge!.prevEdge = e2;
|
|
305
|
-
this.firstEdge = e1; // We could delete mFirstEdge so just update it to the newly created edge
|
|
306
|
-
this.numEdges += 2;
|
|
307
|
-
|
|
308
|
-
// Calculate normals
|
|
309
|
-
const newEdges: ConvexHull2dEdge[] = [e1, e2];
|
|
310
|
-
for (const newEdge of newEdges) {
|
|
311
|
-
newEdge.calculateNormalAndCenter(polyhedron);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// Delete the old edges
|
|
315
|
-
while (true) {
|
|
316
|
-
const next = firstEdge.nextEdge;
|
|
317
|
-
|
|
318
|
-
// Redistribute points in conflict list
|
|
319
|
-
for (const index of firstEdge.conflictList) {
|
|
320
|
-
this.assignPointToEdge(polyhedron, index, newEdges);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// Delete the old edge
|
|
324
|
-
// delete first_edge; TODO: probably not needed in TS
|
|
325
|
-
--this.numEdges;
|
|
326
|
-
|
|
327
|
-
if (firstEdge === lastEdge) {
|
|
328
|
-
break;
|
|
329
|
-
}
|
|
330
|
-
firstEdge = next!;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// Convert the edge list to a list of indices
|
|
335
|
-
outEdges.length = 0;
|
|
336
|
-
let edge = this.firstEdge;
|
|
337
|
-
do {
|
|
338
|
-
outEdges.push(edge.startIndex);
|
|
339
|
-
edge = edge.nextEdge!;
|
|
340
|
-
} while (edge !== this.firstEdge);
|
|
341
|
-
|
|
342
|
-
return result;
|
|
343
|
-
}
|
|
344
|
-
}
|