mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Drape glow and dash lines, reveal lines by length, and move draped lines and clamped points every frame
The Cesium draw port now drapes glow and dash lines as well as solid and flow ones, each with its own ground primitive. revealFraction is the fraction of the line's length, measured along the line. Both renderers cut there: Cesium discards fragments past the cut in the line's material, so the hidden part neither draws nor picks; the stub cuts the line before drawing and picking. A draped line whose positions change is rebuilt the same frame, on a ground primitive of its own, once terrain heights are loaded; until then it is rebuilt as before. A clamped dot whose look is unchanged is moved in place. The stub now picks lines. A new shared conformance check, draw.lines.drape, covers draped glow and dash lines, the reveal cut, a draped line growing every frame, and a clamped point moving every frame.
This commit is contained in:
1 parent
4cbfd6e12d
commit
10dcab837b
9 files changed
+1194
-167
No files matched your search
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @module geo/polyline
|
||||
* @description Where a fraction of a polyline's length falls, measured
|
||||
* straight between its ECEF positions: what a line's `revealFraction`
|
||||
* draws up to.
|
||||
*/
|
||||
|
||||
const span = (a, b) => Math.hypot(b.x - a.x, b.y - a.y, b.z - a.z);
|
||||
|
||||
/**
|
||||
* The segment a fraction of the polyline's length ends on, and how far
|
||||
* along it (`t`, 0..1): fractions past 0 and up to 1 only. Null when there
|
||||
* is no length to measure, or the fraction is outside `(0, 1]`.
|
||||
* @param {ReadonlyArray<{x: number, y: number, z: number}>} positions
|
||||
* @param {number} fraction
|
||||
* @returns {{index: number, t: number} | null}
|
||||
*/
|
||||
export function alongLength(positions, fraction) {
|
||||
if (!(fraction > 0) || fraction > 1 || positions.length < 2) return null;
|
||||
const lengths = [];
|
||||
let total = 0;
|
||||
for (let i = 0; i + 1 < positions.length; i++) {
|
||||
lengths.push(span(positions[i], positions[i + 1]));
|
||||
total += lengths[i];
|
||||
}
|
||||
if (!(total > 0)) return null;
|
||||
let left = fraction * total;
|
||||
for (let i = 0; i < lengths.length; i++) {
|
||||
if (left <= lengths[i])
|
||||
return { index: i, t: lengths[i] > 0 ? left / lengths[i] : 0 };
|
||||
left -= lengths[i];
|
||||
}
|
||||
return { index: lengths.length - 1, t: 1 };
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { alongLength } from './polyline.js';
|
||||
|
||||
const p = (x) => ({ x, y: 0, z: 0 });
|
||||
|
||||
test('alongLength finds where a fraction of a polyline’s length ends', () => {
|
||||
assert.deepEqual(alongLength([p(0), p(1), p(4)], 0.5), {
|
||||
index: 1,
|
||||
t: 1 / 3,
|
||||
});
|
||||
assert.deepEqual(alongLength([p(0), p(1), p(4)], 1), { index: 1, t: 1 });
|
||||
assert.deepEqual(alongLength([p(0), p(1), p(4)], 0.25), { index: 0, t: 1 });
|
||||
});
|
||||
|
||||
test('alongLength has nothing to say without a length or a fraction in (0, 1]', () => {
|
||||
assert.equal(alongLength([p(0), p(1)], 0), null);
|
||||
assert.equal(alongLength([p(0), p(1)], 1.5), null);
|
||||
assert.equal(alongLength([p(0), p(0)], 0.5), null);
|
||||
assert.equal(alongLength([p(0)], 0.5), null);
|
||||
});
|
||||
Reference in new issue
Block a user