mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Take the camera viewshed colours and volume builder off Cesium
The viewshed palette is renderer colours from a new hslColor in render/color, which computes as the renderer's own fromHsl does (the CSS HSL reading now goes through it). The volume primitive builder moves, unchanged, into the camera layer's rendering part, which converts each record's palette to Cesium colours once and draws the lines and volumes with them as before. Tests check the palette against the renderer's colours exactly. cctvViewshed leaves the allow-list.
This commit is contained in:
1 parent
0f496b9ae8
commit
2443028d0f
6 files changed
+130
-73
No files matched your search
@@ -22,7 +22,6 @@
|
||||
"src/data/bhoteKoshiLocator.js",
|
||||
"src/data/cameraFraming.js",
|
||||
"src/data/cctvGizmo.js",
|
||||
"src/data/cctvViewshed.js",
|
||||
"src/data/contactTrailRenderer.js",
|
||||
"src/data/detection.js",
|
||||
"src/data/focusDeemphasis.js",
|
||||
|
||||
+15
-5
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Renderer colours (`[r, g, b, a]`, 0..1) from the CSS-style colours layers
|
||||
* keep in their palettes.
|
||||
* keep in their palettes, and from hue, saturation and lightness.
|
||||
*/
|
||||
|
||||
/** A `#rrggbb` colour at `alpha`, as a renderer colour. */
|
||||
@@ -67,10 +67,20 @@ export function cssColor(text) {
|
||||
];
|
||||
m = HSL.exec(css);
|
||||
if (!m) return null;
|
||||
const hue = (Number.parseFloat(m[1]) / 360) % 1;
|
||||
const saturation = Number.parseFloat(m[2]) / 100;
|
||||
const lightness = Number.parseFloat(m[3]) / 100;
|
||||
const alpha = Number.parseFloat(m[4] ?? '1.0');
|
||||
return hslColor(
|
||||
Number.parseFloat(m[1]) / 360,
|
||||
Number.parseFloat(m[2]) / 100,
|
||||
Number.parseFloat(m[3]) / 100,
|
||||
Number.parseFloat(m[4] ?? '1.0'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A hue, saturation and lightness colour (each 0..1; the hue wraps) as a
|
||||
* renderer colour, computed as the default renderer computes it.
|
||||
*/
|
||||
export function hslColor(hue, saturation, lightness, alpha = 1) {
|
||||
hue %= 1;
|
||||
if (saturation === 0) return [lightness, lightness, lightness, alpha];
|
||||
const m2 =
|
||||
lightness < 0.5
|
||||
|
||||
@@ -29,3 +29,18 @@ test('CSS colours read as the default renderer reads them', async () => {
|
||||
assert.equal(cssColor('not a colour'), null);
|
||||
assert.equal(cssColor(undefined), null);
|
||||
});
|
||||
|
||||
test('HSL colours read as the default renderer computes them', async () => {
|
||||
const Cesium = await import('cesium');
|
||||
const { hslColor } = await import('./color.js');
|
||||
for (const [h, s, l, a] of [
|
||||
[0, 0.85, 0.6, 0.12],
|
||||
[0.3819660112501051, 0.9, 0.65, 0.85],
|
||||
[0.7639320225002102, 0.9, 0.7, 1],
|
||||
[1.25, 0.5, 0.25, 0.4],
|
||||
[0.5, 0, 0.4, 1],
|
||||
]) {
|
||||
const c = Cesium.Color.fromHsl(h, s, l, a);
|
||||
assert.deepEqual(hslColor(h, s, l, a), [c.red, c.green, c.blue, c.alpha]);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user