@pirireis/webglobeplugins 0.16.4 → 0.17.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/Math/angle-calculation.js +1 -0
- package/Math/arc.js +92 -2
- package/Math/circle-cdf-points.js +2 -2
- package/Math/circle.js +2 -2
- package/Math/contour/quadtreecontours.js +300 -0
- package/Math/finite-line-2d.js +58 -0
- package/Math/juction/arc-plane.js +67 -12
- package/Math/juction/line-sphere.js +6 -6
- package/Math/juction/plane-plane.js +4 -6
- package/Math/methods.js +5 -5
- package/Math/templete-shapes/grid-visually-equal.js +0 -1
- package/Math/tessellation/earcut/adapters.js +37 -0
- package/Math/tessellation/hybrid-triangle-tessellation-meta.js +123 -0
- package/Math/tessellation/methods.js +46 -0
- package/Math/tessellation/shred-input.js +18 -0
- package/Math/tessellation/tile-merger.js +56 -0
- package/Math/tessellation/tiler.js +50 -0
- package/Math/tessellation/triangle-tessellation-meta.js +516 -0
- package/Math/tessellation/triangle-tessellation.js +14 -0
- package/Math/tessellation/zoom-catch.js +1 -0
- package/Math/vec3.js +26 -1
- package/compass-rose/compass-text-writer.js +39 -33
- package/constants.js +3 -0
- package/{util/heatwavedatamanager → heatwave}/datamanager.js +1 -1
- package/heatwave/{plugins/heatwaveglobeshell.js → heatwave.js} +8 -6
- package/heatwave/index.js +5 -3
- package/heatwave/{isobar/plugin.js → isobar.js} +6 -5
- package/{util/heatwavedatamanager → heatwave}/texture-point-sampler.js +24 -3
- package/package.json +7 -3
- package/programs/arrowfield/{object.js → arrow-field.js} +1 -1
- package/programs/arrowfield/logic.js +1 -1
- package/programs/data2legend/density-to-legend.js +24 -29
- package/programs/data2legend/point-to-density-texture.js +14 -17
- package/programs/float2legendwithratio/logic.js +2 -2
- package/programs/float2legendwithratio/object.js +1 -1
- package/programs/helpers/{blender/program.js → blender.js} +1 -1
- package/programs/helpers/{fadeaway/logic.js → fadeaway.js} +11 -2
- package/programs/index.js +20 -9
- package/programs/line-on-globe/circle-accurate-3d.js +12 -14
- package/programs/line-on-globe/circle-accurate-flat.js +0 -1
- package/programs/line-on-globe/degree-padding-around-circle-3d.js +13 -15
- package/programs/line-on-globe/lines-color-instanced-flat.js +15 -18
- package/programs/line-on-globe/naive-accurate-flexible.js +0 -1
- package/programs/picking/pickable-polygon-renderer.js +1 -1
- package/programs/picking/pickable-renderer.js +2 -2
- package/programs/point-on-globe/element-globe-surface-glow.js +2 -2
- package/programs/point-on-globe/element-point-glow.js +1 -1
- package/programs/point-on-globe/square-pixel-point.js +1 -1
- package/programs/polygon-on-globe/texture-dem-triangle-test-plugin-triangle.js +204 -0
- package/programs/polygon-on-globe/texture-dem-triangle-test-plugin.js +31 -10
- package/programs/polygon-on-globe/texture-dem-triangles.js +81 -12
- package/programs/rings/partial-ring/piece-of-pie.js +26 -29
- package/programs/totems/camerauniformblock.js +34 -45
- package/programs/two-d/pixel-padding-for-compass.js +14 -24
- package/programs/vectorfields/logics/drawrectangleparticles.js +1 -2
- package/programs/vectorfields/logics/pixelbased.js +1 -2
- package/programs/vectorfields/pingpongbuffermanager.js +1 -1
- package/range-tools-on-terrain/bearing-line/adapters.js +1 -1
- package/range-tools-on-terrain/circle-line-chain/adapters.js +0 -5
- package/range-tools-on-terrain/circle-line-chain/plugin.js +1 -1
- package/range-tools-on-terrain/range-ring/plugin.js +4 -6
- package/semiplugins/lightweight/line-plugin.js +0 -1
- package/semiplugins/shape-on-terrain/arc-plugin.js +5 -7
- package/semiplugins/shape-on-terrain/circle-plugin.js +2 -2
- package/semiplugins/shape-on-terrain/padding-1-degree.js +1 -2
- package/semiplugins/shell/bbox-renderer/index.js +2 -0
- package/{programs/globeshell/wiggle → semiplugins/shell/bbox-renderer}/logic.js +101 -102
- package/{programs/globeshell/wiggle → semiplugins/shell/bbox-renderer}/object.js +6 -7
- package/semiplugins/utility/container-plugin.js +94 -0
- package/semiplugins/utility/object-pass-container-plugin.js +80 -0
- package/{point-heat-map → tracks/point-heat-map}/adaptors/timetracksplugin-format-to-this.js +1 -1
- package/{point-heat-map → tracks/point-heat-map}/plugin-webworker.js +3 -3
- package/{point-heat-map → tracks/point-heat-map}/point-to-heat-map-flow.js +11 -14
- package/{point-tracks → tracks/point-tracks}/plugin.js +5 -5
- package/{timetracks → tracks/timetracks}/adaptors-line-strip.js +1 -1
- package/{timetracks → tracks/timetracks}/program-line-strip.js +49 -49
- package/{timetracks → tracks/timetracks}/programpoint-line-strip.js +16 -13
- package/types.js +6 -0
- package/util/account/bufferoffsetmanager.js +1 -1
- package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +9 -95
- package/util/gl-util/uniform-block/manager.js +4 -5
- package/util/gl-util/uniform-block/types.js +0 -7
- package/util/index.js +10 -13
- package/util/picking/fence.js +16 -18
- package/util/picking/picker-displayer.js +4 -6
- package/util/programs/{shapesonglobe.js → draw-from-pixel-coords.js} +4 -7
- package/util/programs/draw-texture-on-canvas.js +1 -1
- package/util/programs/texturetoglobe.js +3 -3
- package/util/shaderfunctions/geometrytransformations.js +6 -0
- package/util/webglobe/rasteroverlay.js +1 -0
- package/vectorfield/arrowfield/index.js +3 -0
- package/{arrowfield → vectorfield/arrowfield}/plugin.js +2 -2
- package/{waveparticles → vectorfield/waveparticles}/plugin.js +12 -12
- package/{wind → vectorfield/wind}/index.js +1 -1
- package/{wind → vectorfield/wind}/plugin.js +32 -32
- package/write-text/attached-text-writer.js +9 -1
- package/write-text/context-text3.js +0 -1
- package/write-text/objectarraylabels/index.js +2 -0
- package/Math/mesh/mapbox-delaunay.js +0 -544
- package/arrowfield/index.js +0 -3
- package/bearing-line/index.js +0 -2
- package/bearing-line/plugin.js +0 -444
- package/circle-line-chain/chain-list-map.js +0 -201
- package/circle-line-chain/plugin.js +0 -411
- package/circle-line-chain/util.js +0 -1
- package/compassrose/compassrose.js +0 -293
- package/compassrose/index.js +0 -2
- package/index.js +0 -12
- package/partialrings/buffer-manager.js +0 -75
- package/partialrings/index.js +0 -2
- package/partialrings/plugin.js +0 -128
- package/partialrings/program.js +0 -279
- package/programs/arrowfield/index.js +0 -2
- package/programs/globe-util/is-globe-moved.js +0 -19
- package/programs/globeshell/index.js +0 -2
- package/programs/globeshell/wiggle/index.js +0 -2
- package/programs/helpers/blender/index.js +0 -1
- package/programs/helpers/fadeaway/index.js +0 -2
- package/programs/helpers/fadeaway/object.js +0 -14
- package/programs/helpers/index.js +0 -2
- package/programs/rings/distancering/circleflatprogram.js +0 -116
- package/programs/rings/distancering/circlepaddingfreeangleprogram.js +0 -326
- package/programs/rings/distancering/circlepaddysharedbuffer.js +0 -368
- package/programs/rings/distancering/index.js +0 -6
- package/programs/rings/distancering/paddyflatprogram.js +0 -127
- package/programs/rings/distancering/paddyflatprogram2d.js +0 -129
- package/programs/rings/distancering/paddyflatprogram3d.js +0 -128
- package/programs/two-d/pixel-circle.js +0 -1
- package/programs/vectorfields/index.js +0 -3
- package/rangerings/enum.js +0 -2
- package/rangerings/index.js +0 -5
- package/rangerings/plugin.js +0 -543
- package/rangerings/rangeringangletext.js +0 -326
- package/rangerings/ring-account.js +0 -112
- package/timetracks/index.js +0 -1
- package/util/build-strategy/general-strategy.js +0 -62
- package/util/gl-util/uniform-block/shader.js +0 -1
- package/util/heatwavedatamanager/index.js +0 -2
- package/util/heatwavedatamanager/pointcoordsmeta.js +0 -22
- package/util/jshelpers/data-filler.js +0 -17
- package/util/jshelpers/equality.js +0 -18
- package/util/jshelpers/index.js +0 -2
- package/util/jshelpers/timefilters.js +0 -30
- package/util/programs/index.js +0 -1
- package/util/surface-line-data/arc-bboxes.js +0 -25
- package/util/surface-line-data/arcs-to-cuts.js +0 -50
- package/util/surface-line-data/cut-arc.js +0 -1
- package/util/surface-line-data/flow.js +0 -28
- package/util/surface-line-data/rbush-manager.js +0 -1
- package/util/surface-line-data/web-worker.js +0 -1
- package/write-text/context-text3old.js +0 -152
- package/write-text/index.js +0 -1
- package/write-text/writer-plugin.js +0 -8
- /package/{heatwave/isobar/quadtreecontours.js → Math/contour/quadtreecontours1.js} +0 -0
- /package/{util/surface-line-data → Math/tessellation}/types.js +0 -0
- /package/pin/{pin-object-array.js → pin-object-array1.js} +0 -0
- /package/pin/{pin-point-totem.js → pin-point-totem1.js} +0 -0
- /package/{circle-line-chain/init.js → programs/polygon-on-globe/partial-tesselation.js} +0 -0
- /package/{point-heat-map → tracks/point-heat-map}/index.js +0 -0
- /package/{point-tracks → tracks/point-tracks}/key-methods.js +0 -0
- /package/{timetracks → tracks/timetracks}/plugin-line-strip.js +0 -0
- /package/{arrowfield → vectorfield/arrowfield}/adaptor.js +0 -0
- /package/{waveparticles → vectorfield/waveparticles}/adaptor.js +0 -0
- /package/{waveparticles → vectorfield/waveparticles}/index.js +0 -0
- /package/{wind → vectorfield/wind}/imagetovectorfieldandmagnitude.js +0 -0
- /package/{wind → vectorfield/wind}/vectorfieldimage.js +0 -0
- /package/write-text/{context-text.js → context-textDELETE.js} +0 -0
- /package/{heatwave/isobar → write-text/objectarraylabels}/objectarraylabels.js +0 -0
package/Math/arc.js
CHANGED
|
@@ -10,6 +10,15 @@ const _originPlane = /*@__PURE__*/ planeCreate(vec3create(0, 0, 1), 0);
|
|
|
10
10
|
// dont change distance of _originPlane
|
|
11
11
|
const _rotationQuaternion = /*@__PURE__*/ quaternionCreate();
|
|
12
12
|
const _longLat = /*@__PURE__*/ [0, 0];
|
|
13
|
+
// Normalize angles to [0, 2π)
|
|
14
|
+
function normalizeLon(angle) {
|
|
15
|
+
while (angle < 0)
|
|
16
|
+
angle += 2 * Math.PI;
|
|
17
|
+
while (angle >= 2 * Math.PI)
|
|
18
|
+
angle -= 2 * Math.PI;
|
|
19
|
+
return angle;
|
|
20
|
+
}
|
|
21
|
+
;
|
|
13
22
|
function create(p0, p1) {
|
|
14
23
|
const normal = vec3create(0, 0, 0);
|
|
15
24
|
cross(normal, p0, p1);
|
|
@@ -25,7 +34,6 @@ function create(p0, p1) {
|
|
|
25
34
|
// Handle opposite points case
|
|
26
35
|
const tempPlane = planeCreate(vec3create(), 0);
|
|
27
36
|
_oppositePointsHandle(p0, p1, normal, tempPlane);
|
|
28
|
-
vec3copy(coverPlaneNormal, tempPlane.normal);
|
|
29
37
|
distance = tempPlane.distance;
|
|
30
38
|
}
|
|
31
39
|
return {
|
|
@@ -43,6 +51,7 @@ function set(out, p0, p1) {
|
|
|
43
51
|
vec3copy(out.p0, p0);
|
|
44
52
|
vec3copy(out.p1, p1);
|
|
45
53
|
cross(out.normal, p0, p1);
|
|
54
|
+
normalize(out.normal, out.normal); // ← ADD THIS LINE - normalize the normal vector!
|
|
46
55
|
vec3set(_0vector, p0[0] + p1[0], p0[1] + p1[1], p0[2] + p1[2]);
|
|
47
56
|
const ls = lengthSquared(_0vector);
|
|
48
57
|
if (ls > EPSILON) {
|
|
@@ -52,6 +61,8 @@ function set(out, p0, p1) {
|
|
|
52
61
|
else {
|
|
53
62
|
_oppositePointsHandle(p0, p1, out.normal, out.coverPlane);
|
|
54
63
|
}
|
|
64
|
+
// Also update coverAngle to match what create() does
|
|
65
|
+
out.coverAngle = Math.acos(dot(p0, p1));
|
|
55
66
|
}
|
|
56
67
|
function copy(out, a) {
|
|
57
68
|
vec3copy(out.p0, a.p0);
|
|
@@ -119,6 +130,7 @@ function _oppositePointsHandle(p0, p1, outNormal, outCoverPlane) {
|
|
|
119
130
|
}
|
|
120
131
|
planeFromPoints({ normal: outNormal, distance: 0 }, p0, _0vector, p1);
|
|
121
132
|
cross(outCoverPlane.normal, outNormal, p0);
|
|
133
|
+
normalize(outCoverPlane.normal, outCoverPlane.normal);
|
|
122
134
|
}
|
|
123
135
|
function _populatePointsWithClosestPointInsideArc(out, arc, count, closestPoint) {
|
|
124
136
|
// two parts divided by closest point will be populated seperately
|
|
@@ -199,4 +211,82 @@ function _distanceSampling(out, count, inArc, cameraPosition = vec3create(0, 0,
|
|
|
199
211
|
out[finalIndex * 2 + 1] = _longLat[1];
|
|
200
212
|
}
|
|
201
213
|
}
|
|
202
|
-
|
|
214
|
+
function calculateZLimitPoint(inArc, out) {
|
|
215
|
+
// The arc's plane is perpendicular to the equator, so the arc is on the equator.
|
|
216
|
+
// All points have z=0, so there's no unique z-limit point.
|
|
217
|
+
if (Math.abs(inArc.normal[2]) > 1 - EPSILON) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
// The Z-limit points of a great circle are the two points on it that are
|
|
221
|
+
// closest to the North and South poles. Their 3D coordinates can be
|
|
222
|
+
// calculated from the normal vector of the great circle's plane.
|
|
223
|
+
const nz = inArc.normal[2];
|
|
224
|
+
const n_xy_len = Math.sqrt(inArc.normal[0] * inArc.normal[0] + inArc.normal[1] * inArc.normal[1]);
|
|
225
|
+
// Candidate 1: Highest Z value (closest to North Pole)
|
|
226
|
+
const p_max_z = vec3.create(-inArc.normal[0] * nz / n_xy_len, -inArc.normal[1] * nz / n_xy_len, n_xy_len);
|
|
227
|
+
// Candidate 2: Lowest Z value (closest to South Pole)
|
|
228
|
+
const p_min_z = vec3.create(inArc.normal[0] * nz / n_xy_len, inArc.normal[1] * nz / n_xy_len, -n_xy_len);
|
|
229
|
+
// Now, we check if either of these points lie on the given arc segment.
|
|
230
|
+
// A point is on the shorter arc if its projection onto the cover plane's
|
|
231
|
+
// normal is on the positive side.
|
|
232
|
+
const d_max = dot(p_max_z, inArc.coverPlane.normal);
|
|
233
|
+
const d_min = dot(p_min_z, inArc.coverPlane.normal);
|
|
234
|
+
if (d_max >= inArc.coverPlane.distance - EPSILON) {
|
|
235
|
+
vec3.copy(out, p_max_z);
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
if (d_min >= inArc.coverPlane.distance - EPSILON) {
|
|
239
|
+
vec3.copy(out, p_min_z);
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
function doesArcPassThroughMeridian(inArc, meridians) {
|
|
245
|
+
const result = new Array(meridians.length).fill(false);
|
|
246
|
+
// Get longitude angles for p0 and p1
|
|
247
|
+
const p0Lon = Math.atan2(inArc.p0[1], inArc.p0[0]);
|
|
248
|
+
const p1Lon = Math.atan2(inArc.p1[1], inArc.p1[0]);
|
|
249
|
+
if (inArc.p0[2] >= 1 - EPSILON || inArc.p1[2] >= 1 - EPSILON) {
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
const p0LonNorm = normalizeLon(p0Lon);
|
|
253
|
+
const p1LonNorm = normalizeLon(p1Lon);
|
|
254
|
+
// Determine if we're taking the shorter or longer arc
|
|
255
|
+
let startLon = p0LonNorm;
|
|
256
|
+
let endLon = p1LonNorm;
|
|
257
|
+
// Calculate the angular difference both ways
|
|
258
|
+
const diff1 = normalizeLon(endLon - startLon);
|
|
259
|
+
// Take the shorter path (great circle property)
|
|
260
|
+
const takeShorterPath = diff1 <= Math.PI;
|
|
261
|
+
if (!takeShorterPath) {
|
|
262
|
+
// Swap start and end for the shorter path
|
|
263
|
+
[startLon, endLon] = [endLon, startLon];
|
|
264
|
+
}
|
|
265
|
+
for (let i = 0; i < meridians.length; i++) {
|
|
266
|
+
const meridian = normalizeLon(meridians[i]);
|
|
267
|
+
// Check if meridian is between start and end longitudes
|
|
268
|
+
if (takeShorterPath) {
|
|
269
|
+
if (startLon <= endLon) {
|
|
270
|
+
// Normal case: no wraparound
|
|
271
|
+
result[i] = meridian >= startLon && meridian <= endLon;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
// Wraparound case: arc crosses 0°/360°
|
|
275
|
+
result[i] = meridian >= startLon || meridian <= endLon;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
// Taking the longer path
|
|
280
|
+
if (startLon <= endLon) {
|
|
281
|
+
// Arc goes the long way around
|
|
282
|
+
result[i] = meridian <= startLon || meridian >= endLon;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
// Normal case for long path
|
|
286
|
+
result[i] = meridian >= endLon && meridian <= startLon;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
292
|
+
export { create, set, copy, clone, isPointOn, equals, closestPoint, populatePoints, calculateZLimitPoint, doesArcPassThroughMeridian };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RADIAN } from "./methods";
|
|
2
2
|
function createCummulativeTemplate(numberOfPoints, strength, denseRatio = 0.5 // Ratio of points to be densely packed at the start.
|
|
3
3
|
) {
|
|
4
4
|
// Handle edge cases for the number of points.
|
|
@@ -60,7 +60,7 @@ function globeFindPointByPolar(out, globe, centerLong, centerLat, radius, ratios
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
function globeFindPointByPolarHalfCircle(out, globe, centerLong, centerLat, radius, rotation, ratios) {
|
|
63
|
-
const rotCentigrade = rotation /
|
|
63
|
+
const rotCentigrade = rotation / RADIAN + 720;
|
|
64
64
|
for (let i = 0; i < ratios.length; i++) {
|
|
65
65
|
const point = globe.Math.FindPointByPolar(centerLong, centerLat, radius, (ratios[i] * 180 + rotCentigrade) % 360);
|
|
66
66
|
out[i * 2] = point.long;
|
package/Math/circle.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RADIAN } from './methods';
|
|
2
2
|
import { subtract, normalize, dot, fromLongLatToUnitVector, copy, multiplyScalar, clone } from './vec3';
|
|
3
3
|
const _0vec3 = [0, 0, 0];
|
|
4
4
|
function closestAzimuthAngle(circleProperties, point) {
|
|
@@ -15,7 +15,7 @@ function closestAzimuthAngle(circleProperties, point) {
|
|
|
15
15
|
}
|
|
16
16
|
function createCircleClosestAzimuthAngleProperties(circle) {
|
|
17
17
|
const normal = Array(3);
|
|
18
|
-
fromLongLatToUnitVector(normal, [circle.center[0] *
|
|
18
|
+
fromLongLatToUnitVector(normal, [circle.center[0] * RADIAN, circle.center[1] * RADIAN]);
|
|
19
19
|
const N = clone(normal);
|
|
20
20
|
const distance = dot([0, 0, 1], normal);
|
|
21
21
|
multiplyScalar(N, N, distance);
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// © 2019 3D Robotics. License: Apache-2.0
|
|
2
|
+
const OUTSIDE = 0;
|
|
3
|
+
const ABOVE = 1;
|
|
4
|
+
const BELOW = 2;
|
|
5
|
+
const WITHIN = 3;
|
|
6
|
+
// Build mipmap layer N from layer N+1
|
|
7
|
+
function mipmapReduce({ min, max, width, height, scale }) {
|
|
8
|
+
const outWidth = Math.ceil(width / 2);
|
|
9
|
+
const outHeight = Math.ceil(height / 2);
|
|
10
|
+
function reduceWith(data, reduce) {
|
|
11
|
+
const out = new Float32Array(outWidth * outHeight);
|
|
12
|
+
let x;
|
|
13
|
+
let y;
|
|
14
|
+
for (y = 0; y < Math.floor(height / 2); y++) {
|
|
15
|
+
for (x = 0; x < Math.floor(width / 2); x++) {
|
|
16
|
+
out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 0) * width + (x * 2 + 1)], data[(y * 2 + 1) * width + (x * 2 + 0)], data[(y * 2 + 1) * width + (x * 2 + 1)]);
|
|
17
|
+
}
|
|
18
|
+
if (x < outWidth) {
|
|
19
|
+
out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 1) * width + (x * 2 + 0)]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (y < outHeight) {
|
|
23
|
+
for (x = 0; x < Math.floor(width / 2); x++) {
|
|
24
|
+
out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 0) * width + (x * 2 + 1)]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//@ts-ignore
|
|
28
|
+
if (x < outWidth && y < outHeight) {
|
|
29
|
+
//@ts-ignore
|
|
30
|
+
out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)]);
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
function minFinite(...args) {
|
|
35
|
+
let r = Infinity;
|
|
36
|
+
for (let i = 0; i < args.length; i++) {
|
|
37
|
+
const v = args[i];
|
|
38
|
+
if (v < r)
|
|
39
|
+
r = v;
|
|
40
|
+
}
|
|
41
|
+
return r;
|
|
42
|
+
}
|
|
43
|
+
function maxFinite(...args) {
|
|
44
|
+
let r = -Infinity;
|
|
45
|
+
for (let i = 0; i < args.length; i++) {
|
|
46
|
+
const v = args[i];
|
|
47
|
+
if (v > r)
|
|
48
|
+
r = v;
|
|
49
|
+
}
|
|
50
|
+
return r;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
min: reduceWith(min, minFinite),
|
|
54
|
+
max: reduceWith(max, maxFinite),
|
|
55
|
+
width: outWidth,
|
|
56
|
+
height: outHeight,
|
|
57
|
+
scale: scale * 2,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
class ContourMipmap {
|
|
61
|
+
levels;
|
|
62
|
+
constructor(raster, width, height) {
|
|
63
|
+
// Bottom mipmap layer is just the raster: at each pixel the minimum and maximum are the same
|
|
64
|
+
this.levels = [{ min: raster, max: raster, width, height, scale: 1 }];
|
|
65
|
+
while (this.levels[0].width > 1 || this.levels[0].height > 1) {
|
|
66
|
+
this.levels.unshift(mipmapReduce(this.levels[0]));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Get the minimum elevation in the mipmap
|
|
70
|
+
min() { return this.levels[0].min[0]; }
|
|
71
|
+
// Get the maximum elevation in the mipmap
|
|
72
|
+
max() { return this.levels[0].max[0]; }
|
|
73
|
+
// Get an array of contour levels for a specified contour interval
|
|
74
|
+
intervals(interval) {
|
|
75
|
+
if (interval <= 0)
|
|
76
|
+
throw new Error('Contour interval must be positive');
|
|
77
|
+
const min = this.min();
|
|
78
|
+
const max = this.max();
|
|
79
|
+
const levels = [];
|
|
80
|
+
let level = Math.ceil(min / interval) * interval;
|
|
81
|
+
while (level < max) {
|
|
82
|
+
levels.push(level);
|
|
83
|
+
level += interval;
|
|
84
|
+
}
|
|
85
|
+
return levels;
|
|
86
|
+
}
|
|
87
|
+
// Walk the quadtree for a specified contour level, and pass quadtree nodes
|
|
88
|
+
// and contour line segments to the callbacks. This is used for visualizing
|
|
89
|
+
// the quadtree; in most cases you should use .contour() instead, which
|
|
90
|
+
// assembles the line segments into lines and rings.
|
|
91
|
+
evaluateContour(contourLevel, { maxMipmapLevel }, addLine, addNode) {
|
|
92
|
+
maxMipmapLevel = maxMipmapLevel || this.levels.length - 1;
|
|
93
|
+
// Test the mipmap at the given coordinate and level, returning whether the contour line is ABOVE, BELOW, or WITHIN this mipmap cell
|
|
94
|
+
// If the mipmap is out of bounds or NaN at that point, OUTSIDE is returned.
|
|
95
|
+
const evaluate = (l, x, y) => {
|
|
96
|
+
const ml = this.levels[l];
|
|
97
|
+
const i = ml.width * y + x;
|
|
98
|
+
if (x >= ml.width || y >= ml.height || !Number.isFinite(ml.min[i]) || !Number.isFinite(ml.max[i]))
|
|
99
|
+
return OUTSIDE;
|
|
100
|
+
if (ml.min[i] >= contourLevel)
|
|
101
|
+
return ABOVE;
|
|
102
|
+
if (ml.max[i] < contourLevel)
|
|
103
|
+
return BELOW;
|
|
104
|
+
// If we've reached the maximum mipmap level, arbitrarily decide that cells that contain
|
|
105
|
+
// the contour elevation go inside the contour line.
|
|
106
|
+
if (l >= maxMipmapLevel)
|
|
107
|
+
return ABOVE;
|
|
108
|
+
return WITHIN;
|
|
109
|
+
};
|
|
110
|
+
// Add any vertical contour lines that exist between passed mipmap cell and
|
|
111
|
+
// its horizontal neighbor to the right. If the line exists at this mipmap
|
|
112
|
+
// level, it is added directly, otherwise split the edge and recurse at a
|
|
113
|
+
// more detailed mipmap level.
|
|
114
|
+
const edgeH = (l, x, y) => {
|
|
115
|
+
const e1 = evaluate(l, x, y);
|
|
116
|
+
const e2 = evaluate(l, x + 1, y);
|
|
117
|
+
if (e1 === ABOVE && e2 === BELOW) {
|
|
118
|
+
addLine(l, x + 1, y + 1, x + 1, y);
|
|
119
|
+
}
|
|
120
|
+
else if (e2 === ABOVE && e1 === BELOW) {
|
|
121
|
+
// reverse order of coordinates compared to case above so that lines
|
|
122
|
+
// go counterclockwise around the region above the contour value
|
|
123
|
+
addLine(l, x + 1, y, x + 1, y + 1);
|
|
124
|
+
}
|
|
125
|
+
else if (e1 === WITHIN || e2 === WITHIN) {
|
|
126
|
+
edgeH(l + 1, x * 2 + 1, y * 2 + 0);
|
|
127
|
+
edgeH(l + 1, x * 2 + 1, y * 2 + 1);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
// Like edgeH, but for horizontal contour lines between the passed cell
|
|
131
|
+
// and its vertical neighbor below.
|
|
132
|
+
const edgeV = (l, x, y) => {
|
|
133
|
+
const e1 = evaluate(l, x, y);
|
|
134
|
+
const e2 = evaluate(l, x, y + 1);
|
|
135
|
+
if (e1 === ABOVE && e2 === BELOW) {
|
|
136
|
+
addLine(l, x, y + 1, x + 1, y + 1);
|
|
137
|
+
}
|
|
138
|
+
else if (e2 === ABOVE && e1 === BELOW) {
|
|
139
|
+
addLine(l, x + 1, y + 1, x, y + 1);
|
|
140
|
+
}
|
|
141
|
+
else if (e1 === WITHIN || e2 === WITHIN) {
|
|
142
|
+
edgeV(l + 1, x * 2 + 0, y * 2 + 1);
|
|
143
|
+
edgeV(l + 1, x * 2 + 1, y * 2 + 1);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
// Add all contour lines within a mipmap cell.
|
|
147
|
+
// It recurses into the four quadrants of the cell, and also uses edgeH and
|
|
148
|
+
// edgeV to add the contour lines that exist between quadrants.
|
|
149
|
+
const node = (l, x, y) => {
|
|
150
|
+
const e = evaluate(l, x, y);
|
|
151
|
+
if (e === WITHIN) {
|
|
152
|
+
node(l + 1, x * 2 + 0, y * 2 + 0);
|
|
153
|
+
node(l + 1, x * 2 + 1, y * 2 + 0);
|
|
154
|
+
node(l + 1, x * 2 + 0, y * 2 + 1);
|
|
155
|
+
node(l + 1, x * 2 + 1, y * 2 + 1);
|
|
156
|
+
edgeH(l + 1, x * 2 + 0, y * 2 + 0);
|
|
157
|
+
edgeV(l + 1, x * 2 + 0, y * 2 + 0);
|
|
158
|
+
edgeH(l + 1, x * 2 + 0, y * 2 + 1);
|
|
159
|
+
edgeV(l + 1, x * 2 + 1, y * 2 + 0);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
if (addNode)
|
|
163
|
+
addNode(l, x, y, e);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
node(0, 0, 0);
|
|
167
|
+
}
|
|
168
|
+
// Generate a contour line for a specified value
|
|
169
|
+
//
|
|
170
|
+
// level: Value in the input array at which to draw a contour line
|
|
171
|
+
// opts: {
|
|
172
|
+
// maxMipmapLevel: Maximum recursion depth in the mipmap. As if you rescaled
|
|
173
|
+
// the input to a maximum dimension of 2^n pixels.
|
|
174
|
+
// (default unlimited)
|
|
175
|
+
// minPoints: Lines and rings with fewer points are removed. (default 0)
|
|
176
|
+
// smoothKernelWidth: Width of the rectangular filter for smoothing (default 2)
|
|
177
|
+
// smoothCycles: Number of iterations of smoothing (default 2)
|
|
178
|
+
// }
|
|
179
|
+
//
|
|
180
|
+
// Returns an array of lines, where each line is an array of [x, y] pairs.
|
|
181
|
+
contour(level, { maxMipmapLevel, smoothKernelWidth = 2, smoothCycles = 2, minPoints = 0 } = {}) {
|
|
182
|
+
// Use the quadtree algorithm to generate line segments that make up the contour
|
|
183
|
+
const segments = [];
|
|
184
|
+
this.evaluateContour(level, { maxMipmapLevel }, (l, x1, y1, x2, y2) => {
|
|
185
|
+
const scale = this.levels[l].scale;
|
|
186
|
+
const start = [scale * x1, scale * y1];
|
|
187
|
+
const end = [scale * x2, scale * y2];
|
|
188
|
+
segments.push({ start, end });
|
|
189
|
+
});
|
|
190
|
+
segments.sort((a, b) => key(a.start) - key(b.start));
|
|
191
|
+
// .. and then join them together into rings
|
|
192
|
+
// An arbitrary function to use a 2D point as a Map key
|
|
193
|
+
function key(a) { return a[0] + a[1] * 65536; }
|
|
194
|
+
const fragmentStart = new Map();
|
|
195
|
+
const fragmentEnd = new Map();
|
|
196
|
+
const rings = [];
|
|
197
|
+
segments.forEach(({ start, end }) => {
|
|
198
|
+
const a = fragmentEnd.get(key(start));
|
|
199
|
+
const b = fragmentStart.get(key(end));
|
|
200
|
+
if (a && b) {
|
|
201
|
+
fragmentEnd.delete(key(start));
|
|
202
|
+
fragmentStart.delete(key(end));
|
|
203
|
+
if (a === b) {
|
|
204
|
+
// Close a ring
|
|
205
|
+
a.push(end);
|
|
206
|
+
rings.push(a);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// Join two lines together
|
|
210
|
+
const c = a.concat(b);
|
|
211
|
+
fragmentStart.set(key(c[0]), c);
|
|
212
|
+
fragmentEnd.set(key(c[c.length - 1]), c);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else if (a) {
|
|
216
|
+
// Extend an existing line from the end
|
|
217
|
+
fragmentEnd.delete(key(start));
|
|
218
|
+
a.push(end);
|
|
219
|
+
fragmentEnd.set(key(end), a);
|
|
220
|
+
}
|
|
221
|
+
else if (b) {
|
|
222
|
+
// Extend an existing line from the start
|
|
223
|
+
fragmentStart.delete(key(end));
|
|
224
|
+
b.unshift(start);
|
|
225
|
+
fragmentStart.set(key(start), b);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
// New line doesn't connect to any existing line
|
|
229
|
+
const c = [start, end];
|
|
230
|
+
fragmentStart.set(key(start), c);
|
|
231
|
+
fragmentEnd.set(key(end), c);
|
|
232
|
+
}
|
|
233
|
+
if (fragmentStart.size !== fragmentEnd.size) {
|
|
234
|
+
console.error(`Contour remaining fragment size mismatch ${fragmentStart.size} ${fragmentEnd.size}`);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
const smoothOpts = {
|
|
238
|
+
kernelWidth: smoothKernelWidth,
|
|
239
|
+
cycles: smoothCycles,
|
|
240
|
+
};
|
|
241
|
+
// Closed rings and any unclosed line strings
|
|
242
|
+
return [...rings, ...fragmentStart.values()]
|
|
243
|
+
.filter(l => l.length >= minPoints && l.length >= smoothKernelWidth * 2)
|
|
244
|
+
.map(l => smooth(l, smoothOpts));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Smooth a line by repeatedly applying a rectangular filter to approximate
|
|
248
|
+
// a gaussian filter. It detects closed loops and preserves them.
|
|
249
|
+
// The line is passed as an array of `[x, y]` pairs.
|
|
250
|
+
//
|
|
251
|
+
// kernelWidth: Width of the rectangular filter kernel
|
|
252
|
+
// cycles: Number of times to apply the kernel
|
|
253
|
+
function smooth(line, { kernelWidth = 2, cycles = 2 }) {
|
|
254
|
+
const isLoop = line[0][0] === line[line.length - 1][0] && line[0][1] === line[line.length - 1][1];
|
|
255
|
+
let pointAt;
|
|
256
|
+
if (isLoop) {
|
|
257
|
+
pointAt = (i) => line[(i + line.length) % line.length];
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
pointAt = (i) => line[Math.min(Math.max(i, 0), line.length - 1)];
|
|
261
|
+
}
|
|
262
|
+
const sc = 1.0 / (kernelWidth * 2);
|
|
263
|
+
for (let cycle = 0; cycle < cycles; cycle++) {
|
|
264
|
+
let px = 0;
|
|
265
|
+
let py = 0;
|
|
266
|
+
if (isLoop) {
|
|
267
|
+
for (let i = line.length - kernelWidth; i < line.length; i++) {
|
|
268
|
+
px += line[i][0];
|
|
269
|
+
py += line[i][1];
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
px = line[0][0] * kernelWidth;
|
|
274
|
+
py = line[0][1] * kernelWidth;
|
|
275
|
+
}
|
|
276
|
+
for (let i = 0; i < kernelWidth; i++) {
|
|
277
|
+
px += line[i][0];
|
|
278
|
+
py += line[i][1];
|
|
279
|
+
}
|
|
280
|
+
const res = line.slice();
|
|
281
|
+
for (let i = 0; i < line.length; i++) {
|
|
282
|
+
res[i] = [px * sc, py * sc];
|
|
283
|
+
px += pointAt(i + kernelWidth)[0] - pointAt(i - kernelWidth)[0];
|
|
284
|
+
py += pointAt(i + kernelWidth)[1] - pointAt(i - kernelWidth)[1];
|
|
285
|
+
}
|
|
286
|
+
if (isLoop) {
|
|
287
|
+
// Keep the loop closed
|
|
288
|
+
res[res.length - 1] = res[0].slice();
|
|
289
|
+
}
|
|
290
|
+
line = res;
|
|
291
|
+
}
|
|
292
|
+
return line;
|
|
293
|
+
}
|
|
294
|
+
function scaleParameters(minLongitude, minLatitude, maxLongitude, maxLatitude, width, height) {
|
|
295
|
+
const scaleX = (maxLongitude - minLongitude) / width;
|
|
296
|
+
const scaleY = (maxLatitude - minLatitude) / height;
|
|
297
|
+
return { scaleX, scaleY };
|
|
298
|
+
}
|
|
299
|
+
export default ContourMipmap;
|
|
300
|
+
export { scaleParameters };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
function junctionPoint(out, inLine, origin, slope) {
|
|
2
|
+
const x0 = inLine[0];
|
|
3
|
+
const y0 = inLine[1];
|
|
4
|
+
const x1 = inLine[0];
|
|
5
|
+
const y1 = inLine[1];
|
|
6
|
+
const m1 = (y1 - y0) / (x1 - x0); // slope of line
|
|
7
|
+
const b1 = y0 - m1 * x0; // y-intercept of line
|
|
8
|
+
const m2 = slope;
|
|
9
|
+
const b2 = origin[1] - m2 * origin[0]; // y-intercept of line
|
|
10
|
+
if (m1 === m2) {
|
|
11
|
+
return 0; // parallel lines
|
|
12
|
+
}
|
|
13
|
+
const x = (b2 - b1) / (m1 - m2);
|
|
14
|
+
const y = m1 * x + b1;
|
|
15
|
+
// check if point is within line segment
|
|
16
|
+
if (x < Math.min(x0, x1) || x > Math.max(x0, x1) ||
|
|
17
|
+
y < Math.min(y0, y1) || y > Math.max(y0, y1)) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
out[0] = x;
|
|
21
|
+
out[1] = y;
|
|
22
|
+
return 1;
|
|
23
|
+
}
|
|
24
|
+
export function junctionVerticalOrHorizontalLines(out, inLine1, value, isVertical) {
|
|
25
|
+
const x0 = inLine1[0];
|
|
26
|
+
const y0 = inLine1[1];
|
|
27
|
+
const x1 = inLine1[0];
|
|
28
|
+
const y1 = inLine1[1];
|
|
29
|
+
if (isVertical) {
|
|
30
|
+
// vertical line x = value
|
|
31
|
+
const m1 = (y1 - y0) / (x1 - x0);
|
|
32
|
+
const b1 = y0 - m1 * x0;
|
|
33
|
+
const y = m1 * value + b1;
|
|
34
|
+
// check if point is within line segment
|
|
35
|
+
if (y < Math.min(y0, y1) || y > Math.max(y0, y1)) {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
out[0] = value;
|
|
39
|
+
out[1] = y;
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// horizontal line y = value
|
|
44
|
+
const m1 = (y1 - y0) / (x1 - x0);
|
|
45
|
+
const b1 = y0 - m1 * x0;
|
|
46
|
+
if (m1 === 0) {
|
|
47
|
+
return 0; // parallel lines
|
|
48
|
+
}
|
|
49
|
+
const x = (value - b1) / m1;
|
|
50
|
+
// check if point is within line segment
|
|
51
|
+
if (x < Math.min(x0, x1) || x > Math.max(x0, x1)) {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
out[0] = x;
|
|
55
|
+
out[1] = value;
|
|
56
|
+
return 1;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EPSILON } from "../constants";
|
|
2
|
-
import { create as vec3create, copy as vec3copy, dot, distanceSquared, } from "../vec3";
|
|
2
|
+
import { create as vec3create, copy as vec3copy, dot, distanceSquared, copy, normalize } from "../vec3";
|
|
3
3
|
import { create as lineCreate } from "../line";
|
|
4
4
|
import { create as planeCreate, distanceToPoint, getUnitSphereRadiusAngle } from "../plane";
|
|
5
5
|
import { copy as arcCopy, set as arcSet } from "../arc";
|
|
6
|
-
import {
|
|
6
|
+
import { planePlaneJunction } from "./plane-plane";
|
|
7
7
|
import { lineSphereIntersection } from "./line-sphere";
|
|
8
8
|
const _intersectionLine = /*@__PURE__*/ lineCreate();
|
|
9
9
|
const _originPlane = /*@__PURE__*/ planeCreate();
|
|
@@ -39,9 +39,9 @@ export function arcSlice(out, inArc, junctionPlane) {
|
|
|
39
39
|
}
|
|
40
40
|
// plane-plane intersection line should be calculated for the rest of the calculations
|
|
41
41
|
vec3copy(_originPlane.normal, inArc.normal);
|
|
42
|
-
const isPlaneJunctions =
|
|
42
|
+
const isPlaneJunctions = planePlaneJunction(_intersectionLine, _originPlane, junctionPlane);
|
|
43
43
|
if (!isPlaneJunctions) { // case C: planes are parallel.
|
|
44
|
-
if (junctionPlane.distance <= 0) {
|
|
44
|
+
if (junctionPlane.distance <= 0) { // same direction
|
|
45
45
|
arcCopy(out[0], inArc);
|
|
46
46
|
return 1; // No intersection
|
|
47
47
|
}
|
|
@@ -53,23 +53,35 @@ export function arcSlice(out, inArc, junctionPlane) {
|
|
|
53
53
|
// calculate the intersection points
|
|
54
54
|
const isSphereIntersection = lineSphereIntersection(_intersectionPoints, _intersectionLine, _originSphere);
|
|
55
55
|
if (!isSphereIntersection) {
|
|
56
|
-
// other edge caes should be covered by now
|
|
57
56
|
return 0; // No intersection
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
58
|
+
// ← ADD NORMALIZATION HERE
|
|
59
|
+
normalize(_intersectionPoints[0], _intersectionPoints[0]);
|
|
60
|
+
normalize(_intersectionPoints[1], _intersectionPoints[1]);
|
|
61
|
+
const i0IsCovered = distanceToPoint(inArc.coverPlane, _intersectionPoints[0]) > EPSILON;
|
|
62
|
+
const i1IsCovered = distanceToPoint(inArc.coverPlane, _intersectionPoints[1]) > EPSILON;
|
|
63
|
+
const p0IsVisible = distanceToPoint(junctionPlane, inArc.p0) > EPSILON;
|
|
64
|
+
const p1IsVisible = distanceToPoint(junctionPlane, inArc.p1) > EPSILON;
|
|
63
65
|
if (!p0IsVisible && !p1IsVisible && !i0IsCovered && !i1IsCovered) {
|
|
64
66
|
return 0; // No intersection
|
|
65
67
|
}
|
|
66
68
|
if (i0IsCovered && i1IsCovered && p0IsVisible && p1IsVisible) {
|
|
67
69
|
// calculate which points are closer
|
|
70
|
+
if (dot(inArc.coverPlane.normal, junctionPlane.normal) > 1 - EPSILON) {
|
|
71
|
+
arcCopy(out[0], inArc);
|
|
72
|
+
return 1;
|
|
73
|
+
}
|
|
74
|
+
else if (dot(inArc.coverPlane.normal, junctionPlane.normal) < -1 + EPSILON) {
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
// Determine which intersection point is closer to p0
|
|
68
78
|
const p0i0DistanceSquared = distanceSquared(inArc.p0, _intersectionPoints[0]);
|
|
69
79
|
const p0i1DistanceSquared = distanceSquared(inArc.p0, _intersectionPoints[1]);
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
arcSet(out[
|
|
80
|
+
const closerToP0 = p0i0DistanceSquared < p0i1DistanceSquared ? 0 : 1;
|
|
81
|
+
// The visible portion is from p0 to the closer intersection point
|
|
82
|
+
arcSet(out[0], inArc.p0, _intersectionPoints[closerToP0]);
|
|
83
|
+
// The second arc goes from the farther point to p1
|
|
84
|
+
arcSet(out[1], _intersectionPoints[1 - closerToP0], inArc.p1);
|
|
73
85
|
return 2;
|
|
74
86
|
}
|
|
75
87
|
if (i0IsCovered && i1IsCovered) {
|
|
@@ -86,3 +98,46 @@ export function arcSlice(out, inArc, junctionPlane) {
|
|
|
86
98
|
arcSet(out[0], p0IsVisible ? inArc.p0 : inArc.p1, i0IsCovered ? _intersectionPoints[0] : _intersectionPoints[1]);
|
|
87
99
|
return 1;
|
|
88
100
|
}
|
|
101
|
+
function showArc(arc) {
|
|
102
|
+
return `Arc: p0(${arc.p0[0].toFixed(2)}, ${arc.p0[1].toFixed(2)}, ${arc.p0[2]}) - p1(${arc.p1[0]}, ${arc.p1[1].toFixed(2)}, ${arc.p1[2].toFixed(2)})`;
|
|
103
|
+
}
|
|
104
|
+
function showPlane(plane) {
|
|
105
|
+
return `Plane: n(${plane.normal[0].toFixed(2)}, ${plane.normal[1].toFixed(2)}, ${plane.normal[2].toFixed(2)}) d(${plane.distance.toFixed(2)})`;
|
|
106
|
+
}
|
|
107
|
+
export function pointsOnArc(inArc, junctionPlane, out) {
|
|
108
|
+
// case A: junction plane is too far
|
|
109
|
+
if (Math.abs(junctionPlane.distance) > 1) {
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
// Calculate plane-plane intersection
|
|
113
|
+
vec3copy(_originPlane.normal, inArc.normal);
|
|
114
|
+
const isPlaneJunctions = planePlaneJunction(_intersectionLine, _originPlane, junctionPlane);
|
|
115
|
+
// case B: planes are parallel
|
|
116
|
+
if (!isPlaneJunctions) {
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
// Calculate intersection points with unit sphere
|
|
120
|
+
const isSphereIntersection = lineSphereIntersection(_intersectionPoints, _intersectionLine, _originSphere);
|
|
121
|
+
// case C: intersection line does not intersect the unit sphere
|
|
122
|
+
if (!isSphereIntersection) {
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
// Check which intersection points are covered by the arc
|
|
126
|
+
const i0IsCovered = distanceToPoint(inArc.coverPlane, _intersectionPoints[0]) > -EPSILON;
|
|
127
|
+
const i1IsCovered = distanceToPoint(inArc.coverPlane, _intersectionPoints[1]) > -EPSILON;
|
|
128
|
+
// Check which endpoints are visible
|
|
129
|
+
let count = 0;
|
|
130
|
+
// Add covered intersection points
|
|
131
|
+
if (i0IsCovered) {
|
|
132
|
+
copy(out[count], _intersectionPoints[0]);
|
|
133
|
+
count++;
|
|
134
|
+
}
|
|
135
|
+
if (Math.abs(Math.abs(junctionPlane.distance) - 1) < EPSILON) {
|
|
136
|
+
return count; // Tangent case, only one intersection point
|
|
137
|
+
}
|
|
138
|
+
if (i1IsCovered) {
|
|
139
|
+
copy(out[count], _intersectionPoints[1]);
|
|
140
|
+
count++;
|
|
141
|
+
}
|
|
142
|
+
return count;
|
|
143
|
+
}
|
|
@@ -3,18 +3,18 @@ import { at } from "../line";
|
|
|
3
3
|
const _0vector = /*@__PURE__*/ create(0, 0, 0);
|
|
4
4
|
export function lineSphereIntersection(out, inLine, inSphere) {
|
|
5
5
|
subtract(_0vector, inLine.origin, inSphere.center);
|
|
6
|
+
const dirLengthSq = lengthSquared(inLine.direction);
|
|
7
|
+
const dot_ = dot(_0vector, inLine.direction);
|
|
6
8
|
const distanceSquared = lengthSquared(_0vector);
|
|
7
9
|
const radiusSquared = inSphere.radius * inSphere.radius;
|
|
8
|
-
const
|
|
9
|
-
const dotSquared = dot_ * dot_;
|
|
10
|
-
const discriminant = dotSquared + radiusSquared - distanceSquared;
|
|
10
|
+
const discriminant = dot_ * dot_ - dirLengthSq * (distanceSquared - radiusSquared);
|
|
11
11
|
if (discriminant < 0) {
|
|
12
12
|
return false; // no intersection
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
const
|
|
16
|
-
const t1 = -dot_ -
|
|
17
|
-
const t2 = -dot_ +
|
|
15
|
+
const sqrtDiscriminant = Math.sqrt(discriminant);
|
|
16
|
+
const t1 = (-dot_ - sqrtDiscriminant) / dirLengthSq;
|
|
17
|
+
const t2 = (-dot_ + sqrtDiscriminant) / dirLengthSq;
|
|
18
18
|
at(out[0], inLine, t1);
|
|
19
19
|
at(out[1], inLine, t2);
|
|
20
20
|
return true;
|