mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Ease street traffic heights through the query and camera ports
Height easing projects waypoints through the query port and keeps them beyond the camera's near plane from its pose, instead of the Cesium view matrix and scene transforms. Point maths uses new allocation-free geo helpers (distanceSquared, copyInto, lerpInto), which road selection now shares. Retention leaves the Cesium allow-list.
This commit is contained in:
1 parent
ecaa965b69
commit
0933ff49ff
7 files changed
+328
-89
No files matched your search
@@ -2,10 +2,13 @@ import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import * as Cesium from 'cesium';
|
||||
import {
|
||||
copyInto,
|
||||
distance,
|
||||
distanceSquared,
|
||||
eastNorthUp,
|
||||
fromDegrees,
|
||||
geodeticSurfaceNormal,
|
||||
lerpInto,
|
||||
rayEllipsoid,
|
||||
scaleToGeodeticSurface,
|
||||
toCartographicRadians,
|
||||
@@ -209,3 +212,36 @@ test('a ray meets the ellipsoid where Cesium picks it', () => {
|
||||
}
|
||||
assert.ok(misses > 0 && misses < 200, 'hits and misses both tried');
|
||||
});
|
||||
|
||||
test('in-place vector helpers match the default renderer bit for bit', () => {
|
||||
const a = fromDegrees(-97.7431, 30.2672, 151.25);
|
||||
const b = fromDegrees(-97.7402, 30.2691, 180.5);
|
||||
const ca = new Cesium.Cartesian3(a.x, a.y, a.z);
|
||||
const cb = new Cesium.Cartesian3(b.x, b.y, b.z);
|
||||
assert.equal(
|
||||
distanceSquared(a, b),
|
||||
Cesium.Cartesian3.distanceSquared(ca, cb),
|
||||
);
|
||||
assert.equal(
|
||||
Math.sqrt(distanceSquared(a, b)),
|
||||
Cesium.Cartesian3.distance(ca, cb),
|
||||
);
|
||||
for (const t of [0, 0.137, 0.5, 1]) {
|
||||
const out = { x: 0, y: 0, z: 0 };
|
||||
assert.equal(lerpInto(a, b, t, out), out);
|
||||
assert.deepEqual(
|
||||
{ ...out },
|
||||
{ ...Cesium.Cartesian3.lerp(ca, cb, t, new Cesium.Cartesian3()) },
|
||||
);
|
||||
}
|
||||
const into = { x: 1, y: 2, z: 3 };
|
||||
assert.equal(copyInto(a, into), into);
|
||||
assert.deepEqual(into, { x: a.x, y: a.y, z: a.z });
|
||||
// In place: lerping a point toward a target writes over it safely.
|
||||
const p = { ...a };
|
||||
lerpInto(p, b, 0.25, p);
|
||||
assert.deepEqual(
|
||||
{ ...p },
|
||||
{ ...Cesium.Cartesian3.lerp(ca, cb, 0.25, new Cesium.Cartesian3()) },
|
||||
);
|
||||
});
|
||||
@@ -20,6 +20,30 @@ export const cross = (a, b) =>
|
||||
export const magnitude = (a) => Math.sqrt(dot(a, a));
|
||||
/** Straight-line (chord) distance, not along the surface. */
|
||||
export const distance = (a, b) => magnitude(sub(a, b));
|
||||
/**
|
||||
* The squared chord distance, allocating nothing: what per-frame code
|
||||
* compares and, through `Math.sqrt`, measures with (bit for bit `distance`).
|
||||
*/
|
||||
export function distanceSquared(a, b) {
|
||||
const x = a.x - b.x,
|
||||
y = a.y - b.y,
|
||||
z = a.z - b.z;
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
/** Write `from` into `out` and return it. */
|
||||
export function copyInto(from, out) {
|
||||
out.x = from.x;
|
||||
out.y = from.y;
|
||||
out.z = from.z;
|
||||
return out;
|
||||
}
|
||||
/** Linear interpolation from `a` (t = 0) to `b` (t = 1), written into `out`. */
|
||||
export function lerpInto(a, b, t, out) {
|
||||
out.x = (1 - t) * a.x + t * b.x;
|
||||
out.y = (1 - t) * a.y + t * b.y;
|
||||
out.z = (1 - t) * a.z + t * b.z;
|
||||
return out;
|
||||
}
|
||||
export function normalize(a) {
|
||||
const m = magnitude(a);
|
||||
return vec(a.x / m, a.y / m, a.z / m);
|
||||
|
||||
Reference in new issue
Block a user