mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Write a line that moves by as many points into the points it draws
An undraped line in the polyline collection that moved was given a new array of Cartesians, one new object a point. One that moves by as many points, not geodesic, now has its new positions written into the points its polyline draws, which the polyline then takes again: the range ring's fronts, stepping out every interval, make no new points.
This commit is contained in:
1 parent
9743993f8e
commit
241c8dde64
2 files changed
+85
-2
No files matched your search
@@ -2833,7 +2833,10 @@ export function createCesiumDraw({
|
|||||||
// would have the collection rewrite its vertices.
|
// would have the collection rewrite its vertices.
|
||||||
const drawn = was.polyline.positions;
|
const drawn = was.polyline.positions;
|
||||||
const unmoved = drawnAt(drawn, item.positions);
|
const unmoved = drawnAt(drawn, item.positions);
|
||||||
const positions = unmoved ? drawn : linePositions(item);
|
// One that moves by as many points (a front stepping out) is written
|
||||||
|
// into the points it has, which the polyline then takes again.
|
||||||
|
const positions =
|
||||||
|
unmoved || rewrite(drawn, item) ? drawn : linePositions(item);
|
||||||
if (!unmoved) was.polyline.positions = positions;
|
if (!unmoved) was.polyline.positions = positions;
|
||||||
was.polyline.show = show;
|
was.polyline.show = show;
|
||||||
if (recolour) paintLine(was.polyline.material, item.style);
|
if (recolour) paintLine(was.polyline.material, item.style);
|
||||||
@@ -2844,6 +2847,31 @@ export function createCesiumDraw({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a line's new positions into `drawn`, the Cartesians a polyline
|
||||||
|
* draws (made by `linePositions`), when they are as many and convert one
|
||||||
|
* for one (not geodesic): true if written, else false, writing nothing.
|
||||||
|
*/
|
||||||
|
function rewrite(drawn, item) {
|
||||||
|
if (item.mode === 'geodesic' || !Array.isArray(drawn)) return false;
|
||||||
|
const positions = item.positions;
|
||||||
|
if (positions instanceof Float64Array) {
|
||||||
|
if (positions.length !== drawn.length * 3) return false;
|
||||||
|
for (let i = 0; i < drawn.length; i++)
|
||||||
|
Cesium.Cartesian3.fromElements(
|
||||||
|
positions[i * 3],
|
||||||
|
positions[i * 3 + 1],
|
||||||
|
positions[i * 3 + 2],
|
||||||
|
drawn[i],
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (positions.length !== drawn.length) return false;
|
||||||
|
for (let i = 0; i < drawn.length; i++)
|
||||||
|
toCartesianInto(positions[i], drawn[i]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether `positions` (an item's, ECEF points or packed triples) are the
|
* Whether `positions` (an item's, ECEF points or packed triples) are the
|
||||||
* Cartesians a polyline already draws. False for any given by longitude
|
* Cartesians a polyline already draws. False for any given by longitude
|
||||||
|
|||||||
@@ -2282,7 +2282,7 @@ test('the context layer draws its static range ring as a haloed line on a viewer
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Small moves keep the ring; one past 250 m moves it.
|
// Small moves keep the ring; one past 250 m moves it.
|
||||||
const first = core.positions[0];
|
const first = Cesium.Cartesian3.clone(core.positions[0]);
|
||||||
rendering.renderVisual(subject(0.001));
|
rendering.renderVisual(subject(0.001));
|
||||||
assert.ok(Cesium.Cartesian3.equals(linesOf()[0].positions[0], first));
|
assert.ok(Cesium.Cartesian3.equals(linesOf()[0].positions[0], first));
|
||||||
rendering.renderVisual(subject(0.01));
|
rendering.renderVisual(subject(0.01));
|
||||||
@@ -3009,6 +3009,61 @@ test('an outlined solid line draws one outline material, recoloured in place, an
|
|||||||
s.set.dispose();
|
s.set.dispose();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
test('a line that moves by as many points is written into the points it draws; by more, it takes new ones', () =>
|
||||||
|
withImageClasses(() => {
|
||||||
|
const s = settlingSet();
|
||||||
|
const style = {
|
||||||
|
kind: 'solid',
|
||||||
|
color: [0, 0.5, 1, 1],
|
||||||
|
outline: { color: [0, 0, 0, 1], widthPx: 1 },
|
||||||
|
};
|
||||||
|
const front = (positions) => ({
|
||||||
|
id: 'front',
|
||||||
|
positions,
|
||||||
|
widthPx: 4,
|
||||||
|
mode: '3d',
|
||||||
|
style,
|
||||||
|
});
|
||||||
|
const at = (...heights) =>
|
||||||
|
heights.map((h) => ({ ...Cesium.Cartesian3.fromDegrees(0, 0, h) }));
|
||||||
|
// Beside a line that settles, as the ring's fronts are not.
|
||||||
|
s.set.set([front(at(10, 20, 30)), settleStem('a', 200)]);
|
||||||
|
const polylines = s.polylines();
|
||||||
|
let line = null;
|
||||||
|
for (let i = 0; i < polylines.length; i++)
|
||||||
|
if (polylines.get(i).id?.id === 'front') line = polylines.get(i);
|
||||||
|
const points = line.positions;
|
||||||
|
const objects = [...points];
|
||||||
|
s.set.upsert([front(at(40, 50, 60))]);
|
||||||
|
assert.equal(line.positions, points, 'the same points');
|
||||||
|
assert.deepEqual(line.positions, objects, 'each the same object');
|
||||||
|
const heights = () =>
|
||||||
|
line.positions.map((p) =>
|
||||||
|
Math.round(Cesium.Cartographic.fromCartesian(p).height),
|
||||||
|
);
|
||||||
|
assert.deepEqual(heights(), [40, 50, 60]);
|
||||||
|
// Packed triples are written in too.
|
||||||
|
const packed = new Float64Array(9);
|
||||||
|
at(70, 80, 90).forEach((p, i) => packed.set([p.x, p.y, p.z], i * 3));
|
||||||
|
s.set.upsert([front(packed)]);
|
||||||
|
assert.equal(line.positions, points);
|
||||||
|
assert.deepEqual(heights(), [70, 80, 90]);
|
||||||
|
// As longitudes and latitudes, converted into the same points.
|
||||||
|
s.set.upsert([
|
||||||
|
front([
|
||||||
|
{ lon: 0, lat: 0, height: 1 },
|
||||||
|
{ lon: 0, lat: 0, height: 2 },
|
||||||
|
{ lon: 0, lat: 0, height: 3 },
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
assert.equal(line.positions, points);
|
||||||
|
assert.deepEqual(heights(), [1, 2, 3]);
|
||||||
|
s.set.upsert([front(at(5, 6, 7, 8))]);
|
||||||
|
assert.notEqual(line.positions, points, 'more points: new ones');
|
||||||
|
assert.deepEqual(heights(), [5, 6, 7, 8]);
|
||||||
|
s.set.dispose();
|
||||||
|
}));
|
||||||
|
|
||||||
test('a line under half a pixel wide, which the collection does not draw, never settles', () =>
|
test('a line under half a pixel wide, which the collection does not draw, never settles', () =>
|
||||||
withImageClasses(() => {
|
withImageClasses(() => {
|
||||||
const s = settlingSet();
|
const s = settlingSet();
|
||||||
|
|||||||
Reference in new issue
Block a user