@math.gl/geometry 5.0.0-beta.10 → 5.0.0-beta.12
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/dist/arrow/index.cjs +926 -0
- package/dist/arrow/index.cjs.map +6 -0
- package/dist/arrow/index.d.ts +3 -0
- package/dist/arrow/index.d.ts.map +1 -0
- package/dist/arrow/index.js +6 -0
- package/dist/arrow/index.js.map +1 -0
- package/dist/arrow/stream-tessellate.d.ts +34 -0
- package/dist/arrow/stream-tessellate.d.ts.map +1 -0
- package/dist/arrow/stream-tessellate.js +171 -0
- package/dist/arrow/stream-tessellate.js.map +1 -0
- package/dist/arrow/tessellate.d.ts +31 -0
- package/dist/arrow/tessellate.d.ts.map +1 -0
- package/dist/arrow/tessellate.js +102 -0
- package/dist/arrow/tessellate.js.map +1 -0
- package/dist/color/index.cjs +3 -108
- package/dist/color/index.cjs.map +3 -3
- package/dist/color/index.d.ts +2 -3
- package/dist/color/index.d.ts.map +1 -1
- package/dist/color/index.js +1 -1
- package/dist/color/index.js.map +1 -1
- package/dist/culling/index.cjs +3 -1
- package/dist/culling/index.cjs.map +1 -1
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts +4 -1
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts.map +1 -1
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js +9 -2
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js.map +1 -1
- package/dist/index.cjs +735 -684
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/polygon/cut-by-grid.d.ts.map +1 -1
- package/dist/polygon/cut-by-grid.js +18 -0
- package/dist/polygon/cut-by-grid.js.map +1 -1
- package/dist/polygon/earcut.d.ts +12 -1
- package/dist/polygon/earcut.d.ts.map +1 -1
- package/dist/polygon/earcut.js +855 -630
- package/dist/polygon/earcut.js.map +1 -1
- package/dist/polygon/index.d.ts +1 -0
- package/dist/polygon/index.d.ts.map +1 -1
- package/dist/polygon/index.js.map +1 -1
- package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -1
- package/dist/polygon/subdivide-triangle-mesh.js +55 -17
- package/dist/polygon/subdivide-triangle-mesh.js.map +1 -1
- package/dist/utils/compute-vertex-normals.d.ts +2 -2
- package/dist/utils/compute-vertex-normals.d.ts.map +1 -1
- package/dist/utils/compute-vertex-normals.js +3 -4
- package/dist/utils/compute-vertex-normals.js.map +1 -1
- package/dist/utils/geometry.d.ts +11 -4
- package/dist/utils/geometry.d.ts.map +1 -1
- package/dist/utils/geometry.js +19 -2
- package/dist/utils/geometry.js.map +1 -1
- package/dist/utils/index.d.ts +1 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/mesh-processing.d.ts +16 -6
- package/dist/utils/mesh-processing.d.ts.map +1 -1
- package/dist/utils/mesh-processing.js +9 -6
- package/dist/utils/mesh-processing.js.map +1 -1
- package/dist/utils/primitive-iterator.d.ts +16 -8
- package/dist/utils/primitive-iterator.d.ts.map +1 -1
- package/dist/utils/primitive-iterator.js +32 -35
- package/dist/utils/primitive-iterator.js.map +1 -1
- package/package.json +16 -3
- package/{dist/color/color-lut-types.js → src/arrow/index.ts} +3 -2
- package/src/arrow/stream-tessellate.ts +209 -0
- package/src/arrow/tessellate.ts +133 -0
- package/src/color/index.ts +3 -3
- package/src/culling/lib/algorithms/oriented-bounding-box-quaternion.ts +8 -2
- package/src/index.ts +34 -22
- package/src/polygon/cut-by-grid.ts +18 -0
- package/src/polygon/earcut.ts +946 -668
- package/src/polygon/index.ts +1 -0
- package/src/polygon/subdivide-triangle-mesh.ts +56 -16
- package/src/utils/compute-vertex-normals.ts +5 -6
- package/src/utils/geometry.ts +32 -6
- package/src/utils/index.ts +5 -5
- package/src/utils/mesh-processing.ts +30 -14
- package/src/utils/primitive-iterator.ts +45 -43
- package/dist/color/color-lut-types.d.ts +0 -16
- package/dist/color/color-lut-types.d.ts.map +0 -1
- package/dist/color/color-lut-types.js.map +0 -1
- package/dist/color/sample-lut.d.ts +0 -13
- package/dist/color/sample-lut.d.ts.map +0 -1
- package/dist/color/sample-lut.js +0 -132
- package/dist/color/sample-lut.js.map +0 -1
- package/dist/utils/constants.d.ts +0 -52
- package/dist/utils/constants.d.ts.map +0 -1
- package/dist/utils/constants.js +0 -39
- package/dist/utils/constants.js.map +0 -1
- package/dist/utils/gl-type.d.ts +0 -17
- package/dist/utils/gl-type.d.ts.map +0 -1
- package/dist/utils/gl-type.js +0 -69
- package/dist/utils/gl-type.js.map +0 -1
- package/src/color/color-lut-types.ts +0 -19
- package/src/color/sample-lut.ts +0 -175
- package/src/utils/constants.ts +0 -42
- package/src/utils/gl-type.ts +0 -87
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {earcut} from '../polygon/earcut';
|
|
6
|
+
import type {GeoArrowColumn, GeoArrowGeometryValue} from '@math.gl/core/arrow';
|
|
7
|
+
import {getGeoArrowDimensionSize} from '@math.gl/core/arrow';
|
|
8
|
+
import {materializeGeoArrowRows} from '@math.gl/core/arrow';
|
|
9
|
+
import {assertGeoArrowResourceLimits, type GeoArrowResourceLimitOptions} from '@math.gl/core/arrow';
|
|
10
|
+
|
|
11
|
+
/** Options for polygon tessellation. */
|
|
12
|
+
export type TessellateGeoArrowPolygonsOptions = Readonly<{
|
|
13
|
+
/** Number of values emitted for each output vertex. Defaults to the input dimension. */
|
|
14
|
+
positionSize?: 2 | 3 | 4;
|
|
15
|
+
/** Value added to every source row index. */
|
|
16
|
+
sourceRowOffset?: number;
|
|
17
|
+
limits?: GeoArrowResourceLimitOptions;
|
|
18
|
+
}>;
|
|
19
|
+
|
|
20
|
+
/** Flat, renderer-ready output for polygon and multipolygon rows. */
|
|
21
|
+
export type GeoArrowTessellation = Readonly<{
|
|
22
|
+
positions: Float32Array;
|
|
23
|
+
/** Source column row for every emitted vertex. */
|
|
24
|
+
sourceRowIndices: Uint32Array;
|
|
25
|
+
indices: Uint16Array | Uint32Array;
|
|
26
|
+
sourceDimension: 2 | 3 | 4;
|
|
27
|
+
positionSize: 2 | 3 | 4;
|
|
28
|
+
rowCount: number;
|
|
29
|
+
polygonCount: number;
|
|
30
|
+
vertexCount: number;
|
|
31
|
+
triangleCount: number;
|
|
32
|
+
}>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Tessellates Polygon and MultiPolygon values with stable source-row attribution.
|
|
36
|
+
*
|
|
37
|
+
* Non-polygon members of mixed columns and geometry collections are skipped. Closing coordinates
|
|
38
|
+
* are removed before triangulation and all input descriptors remain borrowed and untouched.
|
|
39
|
+
*/
|
|
40
|
+
export function tessellateGeoArrowPolygons(
|
|
41
|
+
column: GeoArrowColumn,
|
|
42
|
+
options: TessellateGeoArrowPolygonsOptions = {}
|
|
43
|
+
): GeoArrowTessellation {
|
|
44
|
+
assertGeoArrowResourceLimits(column, options.limits);
|
|
45
|
+
const rows = materializeGeoArrowRows(column);
|
|
46
|
+
const sourceDimension = getGeoArrowDimensionSize(column.dimension);
|
|
47
|
+
const positionSize = options.positionSize || sourceDimension;
|
|
48
|
+
const sourceRowOffset = options.sourceRowOffset || 0;
|
|
49
|
+
const positions: number[] = [];
|
|
50
|
+
const sourceRowIndices: number[] = [];
|
|
51
|
+
const indices: number[] = [];
|
|
52
|
+
let polygonCount = 0;
|
|
53
|
+
|
|
54
|
+
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
|
|
55
|
+
const row = rows[rowIndex];
|
|
56
|
+
if (row) {
|
|
57
|
+
visitPolygons(row, polygon => {
|
|
58
|
+
const vertexOffset = positions.length / positionSize;
|
|
59
|
+
const flatCoordinates: number[] = [];
|
|
60
|
+
const holeIndices: number[] = [];
|
|
61
|
+
let localVertexCount = 0;
|
|
62
|
+
|
|
63
|
+
for (let ringIndex = 0; ringIndex < polygon.length; ringIndex++) {
|
|
64
|
+
const ring = removeClosingCoordinate(polygon[ringIndex]);
|
|
65
|
+
if (ring.length < 3) continue;
|
|
66
|
+
if (localVertexCount > 0) holeIndices.push(localVertexCount);
|
|
67
|
+
for (const coordinate of ring) {
|
|
68
|
+
for (let component = 0; component < sourceDimension; component++) {
|
|
69
|
+
flatCoordinates.push(coordinate[component] ?? 0);
|
|
70
|
+
}
|
|
71
|
+
for (let component = 0; component < positionSize; component++) {
|
|
72
|
+
positions.push(coordinate[component] ?? 0);
|
|
73
|
+
}
|
|
74
|
+
sourceRowIndices.push(sourceRowOffset + rowIndex);
|
|
75
|
+
localVertexCount++;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (localVertexCount >= 3) {
|
|
80
|
+
const localIndices = earcut(flatCoordinates, holeIndices, sourceDimension);
|
|
81
|
+
for (const index of localIndices) indices.push(vertexOffset + index);
|
|
82
|
+
polygonCount++;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const vertexCount = positions.length / positionSize;
|
|
89
|
+
const IndexArray = vertexCount <= 65535 ? Uint16Array : Uint32Array;
|
|
90
|
+
return {
|
|
91
|
+
positions: Float32Array.from(positions),
|
|
92
|
+
sourceRowIndices: Uint32Array.from(sourceRowIndices),
|
|
93
|
+
indices: IndexArray.from(indices),
|
|
94
|
+
sourceDimension,
|
|
95
|
+
positionSize,
|
|
96
|
+
rowCount: rows.length,
|
|
97
|
+
polygonCount,
|
|
98
|
+
vertexCount,
|
|
99
|
+
triangleCount: indices.length / 3
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function visitPolygons(
|
|
104
|
+
geometry: GeoArrowGeometryValue,
|
|
105
|
+
visitor: (polygon: readonly (readonly (readonly number[])[])[]) => void
|
|
106
|
+
): void {
|
|
107
|
+
switch (geometry.type) {
|
|
108
|
+
case 'Polygon':
|
|
109
|
+
visitor(geometry.coordinates);
|
|
110
|
+
break;
|
|
111
|
+
case 'MultiPolygon':
|
|
112
|
+
for (const polygon of geometry.coordinates) visitor(polygon);
|
|
113
|
+
break;
|
|
114
|
+
case 'GeometryCollection':
|
|
115
|
+
for (const child of geometry.geometries) visitPolygons(child, visitor);
|
|
116
|
+
break;
|
|
117
|
+
default:
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function removeClosingCoordinate(
|
|
123
|
+
ring: readonly (readonly number[])[]
|
|
124
|
+
): readonly (readonly number[])[] {
|
|
125
|
+
if (ring.length < 2) return ring;
|
|
126
|
+
const first = ring[0];
|
|
127
|
+
const last = ring[ring.length - 1];
|
|
128
|
+
if (first.length !== last.length) return ring;
|
|
129
|
+
for (let index = 0; index < first.length; index++) {
|
|
130
|
+
if (first[index] !== last[index]) return ring;
|
|
131
|
+
}
|
|
132
|
+
return ring.slice(0, -1);
|
|
133
|
+
}
|
package/src/color/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// math.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export type {ColorLUT} from '
|
|
4
|
+
|
|
5
|
+
export {createColorLUTSampler, applyColorLUT} from '@math.gl/core/color';
|
|
6
|
+
export type {ColorLUTSampler, ApplyColorLUTOptions, ColorLUT} from '@math.gl/core/color';
|
|
@@ -7,12 +7,18 @@
|
|
|
7
7
|
import {Matrix3, Quaternion, Vector3} from '@math.gl/core';
|
|
8
8
|
import {OrientedBoundingBox} from '../bounding-volumes/oriented-bounding-box';
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Return a unit rotation quaternion for the box, excluding half-axis scale.
|
|
12
|
+
* Reflected half axes use an equivalent right-handed basis without mutating the box.
|
|
13
|
+
*/
|
|
11
14
|
export function getOrientedBoundingBoxQuaternion(box: OrientedBoundingBox): Quaternion {
|
|
12
15
|
const x = new Vector3(box.halfAxes.getColumn(0)).normalize();
|
|
13
16
|
const y = new Vector3(box.halfAxes.getColumn(1)).normalize();
|
|
14
17
|
const z = new Vector3(box.halfAxes.getColumn(2)).normalize();
|
|
15
|
-
|
|
18
|
+
// Reversing one half-axis preserves the box while removing a reflection,
|
|
19
|
+
// which cannot be represented by a rotation quaternion.
|
|
20
|
+
if (box.halfAxes.determinant() < 0) z.negate();
|
|
21
|
+
return new Quaternion().fromMatrix3(new Matrix3([...x, ...y, ...z])).normalize();
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
/** Construct a box from its center, half sizes and quaternion, optionally reusing a box. */
|
package/src/index.ts
CHANGED
|
@@ -16,11 +16,17 @@ export type {HingePanel} from './lib/hinge-tree';
|
|
|
16
16
|
export {unpackIndexedGeometry} from './lib/geometry-utils';
|
|
17
17
|
|
|
18
18
|
export {BoxGeometry, CubeGeometry} from './geometries/box-geometry';
|
|
19
|
-
export type {
|
|
19
|
+
export type {
|
|
20
|
+
BoxGeometryProps,
|
|
21
|
+
CubeGeometryProps
|
|
22
|
+
} from './geometries/box-geometry';
|
|
20
23
|
export {CapsuleGeometry} from './geometries/capsule-geometry';
|
|
21
24
|
export type {CapsuleGeometryProps} from './geometries/capsule-geometry';
|
|
22
25
|
export {CylinderGeometry, ConeGeometry} from './geometries/cylinder-geometry';
|
|
23
|
-
export type {
|
|
26
|
+
export type {
|
|
27
|
+
CylinderGeometryProps,
|
|
28
|
+
ConeGeometryProps
|
|
29
|
+
} from './geometries/cylinder-geometry';
|
|
24
30
|
export {PlaneGeometry} from './geometries/plane-geometry';
|
|
25
31
|
export type {PlaneGeometryProps} from './geometries/plane-geometry';
|
|
26
32
|
export {SphereGeometry} from './geometries/sphere-geometry';
|
|
@@ -45,11 +51,6 @@ export type {
|
|
|
45
51
|
LatheGeometryProps
|
|
46
52
|
} from './parametric';
|
|
47
53
|
export {
|
|
48
|
-
GL,
|
|
49
|
-
GL_TYPE,
|
|
50
|
-
GL_PRIMITIVE,
|
|
51
|
-
GL_PRIMITIVE_MODE,
|
|
52
|
-
GLType,
|
|
53
54
|
isGeometry,
|
|
54
55
|
makeAttributeIterator,
|
|
55
56
|
makePrimitiveIterator,
|
|
@@ -77,7 +78,7 @@ export {
|
|
|
77
78
|
weldGeometry,
|
|
78
79
|
getDegenerateTriangles,
|
|
79
80
|
interpolatePackedAttributes
|
|
80
|
-
} from './utils
|
|
81
|
+
} from './utils';
|
|
81
82
|
export type {
|
|
82
83
|
TypedArray,
|
|
83
84
|
TypedArrayConstructor,
|
|
@@ -89,7 +90,7 @@ export type {
|
|
|
89
90
|
PackedAttribute,
|
|
90
91
|
AttributeInterpolationProvenance,
|
|
91
92
|
PackedAttributeInterpolationOptions
|
|
92
|
-
} from './utils
|
|
93
|
+
} from './utils';
|
|
93
94
|
export {
|
|
94
95
|
Curve,
|
|
95
96
|
LineCurve,
|
|
@@ -98,8 +99,8 @@ export {
|
|
|
98
99
|
HermiteCurve,
|
|
99
100
|
CatmullRomCurve,
|
|
100
101
|
CurveArcLength
|
|
101
|
-
} from './curves
|
|
102
|
-
export type {CurvePoint, CatmullRomCurveOptions} from './curves
|
|
102
|
+
} from './curves';
|
|
103
|
+
export type {CurvePoint, CatmullRomCurveOptions} from './curves';
|
|
103
104
|
export {
|
|
104
105
|
Polygon,
|
|
105
106
|
getPolygonSignedArea,
|
|
@@ -117,8 +118,9 @@ export {
|
|
|
117
118
|
cutPolygonByMercatorBounds,
|
|
118
119
|
subdividePolyline,
|
|
119
120
|
subdivideTriangleMesh
|
|
120
|
-
} from './polygon
|
|
121
|
+
} from './polygon';
|
|
121
122
|
export type {
|
|
123
|
+
EarcutOptions,
|
|
122
124
|
PolygonWinding,
|
|
123
125
|
WindingDirection,
|
|
124
126
|
PoleSearchBudget,
|
|
@@ -128,7 +130,7 @@ export type {
|
|
|
128
130
|
TriangleMesh,
|
|
129
131
|
SubdivideTriangleMeshOptions,
|
|
130
132
|
SubdividedTriangleMesh
|
|
131
|
-
} from './polygon
|
|
133
|
+
} from './polygon';
|
|
132
134
|
export {
|
|
133
135
|
AxisAlignedBoundingBox,
|
|
134
136
|
BoundingSphere,
|
|
@@ -153,7 +155,7 @@ export {
|
|
|
153
155
|
intersectOrientedBoxes2D,
|
|
154
156
|
getOrientedBoundingBoxQuaternion,
|
|
155
157
|
makeOrientedBoundingBoxFromQuaternion
|
|
156
|
-
} from './culling
|
|
158
|
+
} from './culling';
|
|
157
159
|
export type {
|
|
158
160
|
CullingResult,
|
|
159
161
|
ImplicitShape,
|
|
@@ -167,7 +169,7 @@ export type {
|
|
|
167
169
|
QueryPoint,
|
|
168
170
|
TriangleRayHit,
|
|
169
171
|
OrientedBox2D
|
|
170
|
-
} from './culling
|
|
172
|
+
} from './culling';
|
|
171
173
|
export {
|
|
172
174
|
validateQueryPoint,
|
|
173
175
|
validateQueryDistance,
|
|
@@ -175,8 +177,11 @@ export {
|
|
|
175
177
|
getClosestPointsOnSegments,
|
|
176
178
|
getClosestPointsSegmentTriangle
|
|
177
179
|
} from './culling/queries';
|
|
178
|
-
export type {
|
|
179
|
-
|
|
180
|
+
export type {
|
|
181
|
+
SegmentClosestPoints,
|
|
182
|
+
SegmentTriangleClosestPoints
|
|
183
|
+
} from './culling/queries';
|
|
184
|
+
export {BoxIndex, PointIndex, TriangleBVH} from './spatial-index';
|
|
180
185
|
export type {
|
|
181
186
|
BoxIndexOptions,
|
|
182
187
|
NearestIndexOptions,
|
|
@@ -191,10 +196,10 @@ export type {
|
|
|
191
196
|
TriangleRayOptions,
|
|
192
197
|
TriangleNearestOptions,
|
|
193
198
|
TriangleSegmentResult
|
|
194
|
-
} from './spatial-index
|
|
199
|
+
} from './spatial-index';
|
|
195
200
|
|
|
196
201
|
export type {
|
|
197
|
-
|
|
202
|
+
GeometryInput,
|
|
198
203
|
GeometryAttribute as UtilityGeometryAttribute
|
|
199
204
|
} from './utils/geometry';
|
|
200
205
|
|
|
@@ -223,7 +228,7 @@ export {
|
|
|
223
228
|
clampPointToBounds,
|
|
224
229
|
spheresIntersect,
|
|
225
230
|
boundsIntersectSphere
|
|
226
|
-
} from './culling
|
|
231
|
+
} from './culling';
|
|
227
232
|
export {
|
|
228
233
|
getRayPoint,
|
|
229
234
|
getClosestPointOnRay,
|
|
@@ -240,8 +245,15 @@ export {
|
|
|
240
245
|
triangleIntersectsBounds
|
|
241
246
|
} from './culling/geometric-queries';
|
|
242
247
|
export type {RaySegmentClosestPoints} from './culling/geometric-queries';
|
|
243
|
-
export {
|
|
244
|
-
|
|
248
|
+
export {
|
|
249
|
+
sampleCurveAdaptive,
|
|
250
|
+
computeParallelTransportFrames
|
|
251
|
+
} from './curves';
|
|
252
|
+
export type {
|
|
253
|
+
AdaptiveCurveOptions,
|
|
254
|
+
AdaptiveCurveSamples,
|
|
255
|
+
CurveFrames
|
|
256
|
+
} from './curves';
|
|
245
257
|
|
|
246
258
|
export {projectBounds} from './utils/project-bounds';
|
|
247
259
|
export type {
|
|
@@ -130,6 +130,7 @@ export function cutPolygonByGrid(
|
|
|
130
130
|
// Get the bounding box of the outer polygon
|
|
131
131
|
getBoundingBox(pos, size, holes[0] || pos.length, bbox);
|
|
132
132
|
cell = getGridCell(bbox[0], gridResolution, gridOffset, cell);
|
|
133
|
+
containPoint(cell, bbox[0], gridResolution);
|
|
133
134
|
const code = bitCode(bbox[1], cell);
|
|
134
135
|
|
|
135
136
|
if (code) {
|
|
@@ -258,6 +259,23 @@ function getGridCell(
|
|
|
258
259
|
return out as BoundingBox;
|
|
259
260
|
}
|
|
260
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Moves a cell by one step so that it contains `p` on its low edges and excludes it on its high edges.
|
|
264
|
+
* `getGridCell` divides by the grid resolution, and the rounded quotient can select a neighbor cell
|
|
265
|
+
* when `p` is on a cut line. Bisecting that cell again leaves one side empty.
|
|
266
|
+
*/
|
|
267
|
+
function containPoint(cell: number[], p: number[], gridResolution: number): void {
|
|
268
|
+
for (let axis = 0; axis < 2; axis++) {
|
|
269
|
+
if (p[axis] < cell[axis]) {
|
|
270
|
+
cell[axis + 2] = cell[axis];
|
|
271
|
+
cell[axis] -= gridResolution;
|
|
272
|
+
} else if (p[axis] >= cell[axis + 2]) {
|
|
273
|
+
cell[axis] = cell[axis + 2];
|
|
274
|
+
cell[axis + 2] += gridResolution;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
261
279
|
function moveToNeighborCell(cell: number[], gridResolution: number, edge: number): void {
|
|
262
280
|
if (edge & 8) {
|
|
263
281
|
// top
|