mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(traffic): road lines stack as before: flow lines jam on top, heat-lines slow over jam
The lines were one ground primitive per bucket, added free, slow, jam for flow lines and jam, slow for heat-lines, so where roads cross the later bucket drew on top. Through the draw port they were one set in kept order (jam first), and its glow lines draw after its solid ones, which turned both stackings over. Flow lines are now set free, slow, jam; slow heat-lines go in a set made after the jam lines' set.
This commit is contained in:
1 parent
df0afa82e1
commit
4b665147e1
4 files changed
+72
-3
No files matched your search
@@ -144,3 +144,41 @@ test('heat-lines are asked for draped whatever the renderer, with no check of th
|
||||
assert.equal(items().length, 1);
|
||||
assert.equal(items()[0].mode, 'draped');
|
||||
});
|
||||
|
||||
test('lines stack as their per-bucket primitives were added: flow lines jam on top, heat-lines slow over jam', () => {
|
||||
const s = setup();
|
||||
const draw = fakeDrawPort();
|
||||
s.state._heatSet = draw.lines({ id: 'traffic:2:heat', clampTo: 'tiles' });
|
||||
s.state._heatOverSet = draw.lines({
|
||||
id: 'traffic:2:heat-over',
|
||||
clampTo: 'tiles',
|
||||
});
|
||||
const under = () => [...draw.set('traffic:2:heat').items.values()];
|
||||
const over = () => [...draw.set('traffic:2:heat-over').items.values()];
|
||||
const roads = [road(0.2, 50, 1), road(0.6, 80, 2), road(0.9, 90, 3)];
|
||||
|
||||
// Heat-lines: jam in the set made first, slow in the one made after it.
|
||||
s.rendering.rebuildHeatLines(roads);
|
||||
assert.deepEqual(
|
||||
under().map((line) => line.style.kind),
|
||||
['glow'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
over().map((line) => line.widthPx),
|
||||
[HEAT_LINE_SLOW_WIDTH],
|
||||
);
|
||||
assert.equal(s.state._heatLineCount, 2);
|
||||
|
||||
// Flow lines: one set, free first and jam last, as free, slow and jam
|
||||
// primitives were added; the slow set empties.
|
||||
s.state._showLines = true;
|
||||
s.rendering.rebuildHeatLines(roads);
|
||||
assert.deepEqual(
|
||||
under().map((line) => line.positions[0].x),
|
||||
[3, 2, 1],
|
||||
);
|
||||
assert.equal(over().length, 0);
|
||||
|
||||
s.rendering.removeHeatLines();
|
||||
assert.equal(under().length + over().length, 0);
|
||||
});
|
||||
@@ -26,6 +26,7 @@ export function createLifecycle({
|
||||
layerState._viewer = viewer;
|
||||
layerState._dotSet?.dispose();
|
||||
layerState._heatSet?.dispose();
|
||||
layerState._heatOverSet?.dispose();
|
||||
const instance = ++instances;
|
||||
const draw = drawOf(viewer);
|
||||
layerState._dotSet = draw.points({
|
||||
@@ -39,6 +40,12 @@ export function createLifecycle({
|
||||
id: `traffic:${instance}:heat`,
|
||||
clampTo: 'tiles',
|
||||
});
|
||||
// The slow heat-lines, made after the jam ones' set so they draw over
|
||||
// them, as their primitive was added after the jam lines'.
|
||||
layerState._heatOverSet = draw.lines({
|
||||
id: `traffic:${instance}:heat-over`,
|
||||
clampTo: 'tiles',
|
||||
});
|
||||
layerState._heatJam = [];
|
||||
layerState._heatLineCount = 0;
|
||||
layerState._dots = [];
|
||||
@@ -221,6 +228,8 @@ export function createLifecycle({
|
||||
layerState._dotSet = null;
|
||||
layerState._heatSet?.dispose();
|
||||
layerState._heatSet = null;
|
||||
layerState._heatOverSet?.dispose();
|
||||
layerState._heatOverSet = null;
|
||||
layerState._tileCache.clear();
|
||||
resetFlowTileCache();
|
||||
layerState._count = 0;
|
||||
|
||||
@@ -43,7 +43,10 @@ export function createRendering({
|
||||
/** Take every road line (heat-lines or flow lines) down. */
|
||||
|
||||
function removeHeatLines() {
|
||||
if (layerState._heatLineCount) layerState._heatSet?.clear();
|
||||
if (layerState._heatLineCount) {
|
||||
layerState._heatSet?.clear();
|
||||
layerState._heatOverSet?.clear();
|
||||
}
|
||||
layerState._heatJam = [];
|
||||
layerState._heatLineCount = 0;
|
||||
parts.animation.syncRenderDemand?.();
|
||||
@@ -142,7 +145,13 @@ export function createRendering({
|
||||
bucket === 'jam' ? HEAT_LINE_JAM_WIDTH : HEAT_LINE_SLOW_WIDTH;
|
||||
}
|
||||
|
||||
const items = [];
|
||||
// Drawn in the order the per-bucket primitives were added: flow lines
|
||||
// free, slow, then jam on top, in one set (in the order of its items);
|
||||
// heat-lines jam, then slow over it, in a set of their own made after
|
||||
// the jam lines' (a set draws its glow lines after its solid ones).
|
||||
const order = flowLines ? ['free', 'slow', 'jam'] : ['jam', 'slow'];
|
||||
const byBucket = { jam: [], slow: [], free: [] };
|
||||
const over = [];
|
||||
const jam = [];
|
||||
for (let i = 0; i < kept.length; i++) {
|
||||
const { road, bucket } = kept[i];
|
||||
@@ -156,12 +165,17 @@ export function createRendering({
|
||||
clampTo: flowLines ? 'both' : 'tiles',
|
||||
style: styleFor(bucket),
|
||||
};
|
||||
items.push(item);
|
||||
if (bucket === 'slow' && !flowLines && layerState._heatOverSet)
|
||||
over.push(item);
|
||||
else byBucket[bucket].push(item);
|
||||
// The steady flow lines never pulse.
|
||||
if (bucket === 'jam' && !flowLines) jam.push(item);
|
||||
}
|
||||
const items = order.flatMap((bucket) => byBucket[bucket]);
|
||||
if (items.length || layerState._heatLineCount)
|
||||
layerState._heatSet.set(items);
|
||||
if (over.length || layerState._heatOverSet?.size())
|
||||
layerState._heatOverSet.set(over);
|
||||
layerState._heatJam = jam;
|
||||
|
||||
layerState._heatLineCount = kept.length;
|
||||
|
||||
@@ -181,6 +181,14 @@ export function createState({ services, source }) {
|
||||
|
||||
layerState._heatSet = null;
|
||||
|
||||
/**
|
||||
* The slow heat-lines, a lines set made after `_heatSet` so they draw
|
||||
* over the jam ones, as before.
|
||||
* @type {object|null}
|
||||
*/
|
||||
|
||||
layerState._heatOverSet = null;
|
||||
|
||||
/** @type {Array} The jam heat-line items, recoloured as they pulse. */
|
||||
|
||||
layerState._heatJam = [];
|
||||
|
||||
Reference in new issue
Block a user