feat(preview): add continuous vehicle turn routes
This commit is contained in:
@@ -7,7 +7,7 @@ const os = require("os");
|
||||
const path = require("path");
|
||||
const { cesiumPreviewHtml } = require("./lib/area-preview");
|
||||
const { makeVehicleGltf } = require("./lib/vehicle-model");
|
||||
const { buildVehicleRoute } = require("./lib/vehicle-route");
|
||||
const { allowedTurns, buildVehicleRoute, classifyConnection } = require("./lib/vehicle-route");
|
||||
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "preview-assets-"));
|
||||
const osmPath = path.join(tempDir, "fixture.osm");
|
||||
@@ -17,15 +17,22 @@ fs.writeFileSync(osmPath, `<?xml version="1.0"?>
|
||||
<bounds minlon="120" minlat="30" maxlon="120.01" maxlat="30.01"/>
|
||||
<node id="1" lon="120.001" lat="30.001"/>
|
||||
<node id="2" lon="120.003" lat="30.001"/>
|
||||
<node id="3" lon="120.006" lat="30.001"/>
|
||||
<node id="4" lon="120.001" lat="30.003"/>
|
||||
<node id="5" lon="120.001" lat="30.007"/>
|
||||
<way id="major-road">
|
||||
<nd ref="1"/><nd ref="2"/><nd ref="3"/>
|
||||
<tag k="highway" v="primary"/><tag k="name" v="Major Road"/><tag k="oneway" v="yes"/>
|
||||
<node id="3" lon="120.005" lat="30.002"/>
|
||||
<node id="4" lon="120.007" lat="30.002"/>
|
||||
<node id="5" lon="120.009" lat="30.002"/>
|
||||
<way id="west-road">
|
||||
<nd ref="1"/><nd ref="2"/>
|
||||
<tag k="highway" v="primary"/><tag k="turn:lanes:forward" v="left|through"/>
|
||||
</way>
|
||||
<way id="minor-road">
|
||||
<nd ref="4"/><nd ref="5"/><tag k="highway" v="residential"/>
|
||||
<way id="turn-road">
|
||||
<nd ref="2"/><nd ref="3"/>
|
||||
<tag k="highway" v="residential"/><tag k="turn:lanes:forward" v="through|left"/>
|
||||
</way>
|
||||
<way id="east-road">
|
||||
<nd ref="3"/><nd ref="4"/><tag k="highway" v="residential"/>
|
||||
</way>
|
||||
<way id="oneway-spur">
|
||||
<nd ref="4"/><nd ref="5"/><tag k="highway" v="residential"/><tag k="oneway" v="yes"/>
|
||||
</way>
|
||||
<way id="footpath">
|
||||
<nd ref="1"/><nd ref="5"/><tag k="highway" v="footway"/>
|
||||
@@ -43,13 +50,22 @@ assert.deepEqual(route.bounds, {
|
||||
});
|
||||
assert.equal(route.speedMetersPerSecond, 8);
|
||||
assert.equal(route.loop, true);
|
||||
assert.equal(route.segments.length, 2);
|
||||
assert.deepEqual(route.segments.map((segment) => segment.id), ["major-road", "minor-road"]);
|
||||
assert.equal(route.segments[0].name, "Major Road");
|
||||
assert.equal(route.segments[0].oneWay, "yes");
|
||||
assert.equal(route.segments[0].laneOffsetMeters, 1.3);
|
||||
assert.notDeepEqual(route.segments[0].coordinates, route.segments[0].centerlineCoordinates);
|
||||
assert.ok(route.segments[0].lengthMeters > route.segments[1].lengthMeters);
|
||||
assert.equal(route.segments, route.routes, "legacy segments remains an alias for the new route list");
|
||||
assert.ok(route.routes.length >= 1 && route.routes.length <= 5);
|
||||
assert.ok(route.routes.every((segment) => segment.edgeIds.length >= 6));
|
||||
assert.ok(route.routes.every((segment) => segment.maneuvers.includes("u_turn")));
|
||||
assert.ok(route.routes.every((segment) => segment.maneuvers.some((value) => ["left", "right", "through"].includes(value))));
|
||||
assert.ok(route.routes.every((segment) => JSON.stringify(segment.coordinates[0]) === JSON.stringify(segment.coordinates.at(-1))));
|
||||
assert.ok(route.routes.every((segment) => !segment.edgeIds.includes("oneway-spur:backward")));
|
||||
assert.notDeepEqual(route.routes[0].coordinates, route.routes[0].centerlineCoordinates);
|
||||
assert.deepEqual(
|
||||
[...allowedTurns({ "turn:lanes:forward": "left|through;right" }, "forward")].sort(),
|
||||
["left", "right", "through"],
|
||||
);
|
||||
const incoming = { wayId: "in", coordinates: [[120, 30], [120.001, 30]] };
|
||||
assert.equal(classifyConnection(incoming, { wayId: "left", coordinates: [[120.001, 30], [120.001, 30.001]] }), "left");
|
||||
assert.equal(classifyConnection(incoming, { wayId: "right", coordinates: [[120.001, 30], [120.001, 29.999]] }), "right");
|
||||
assert.equal(classifyConnection(incoming, { wayId: "through", coordinates: [[120.001, 30], [120.002, 30]] }), "through");
|
||||
|
||||
const vehicle = makeVehicleGltf();
|
||||
assert.equal(vehicle.asset.version, "2.0");
|
||||
|
||||
Reference in New Issue
Block a user