Make it possible to limit speed on sharp corners

This commit is contained in:
Martin Asprusten
2025-07-02 22:54:16 +02:00
parent d07c040d95
commit e5a4e9d716
6 changed files with 56 additions and 17 deletions
+4 -2
View File
@@ -44,7 +44,8 @@ interface FindPathsFromNode {
dragCoefficient: number,
allowMotorways: boolean,
allowTunnels: boolean,
allowAgainstOneway: boolean
allowAgainstOneway: boolean,
limitCornerSpeed: boolean
}
export interface Endpoint {
@@ -102,7 +103,8 @@ interface SearchArea {
dragCoefficient: number,
allowMotorways: boolean,
allowTunnels: boolean,
allowAgainstOneway: boolean
allowAgainstOneway: boolean,
limitCornerSpeed: boolean
}
interface ContinueSearch {
+15 -4
View File
@@ -16,6 +16,7 @@ interface Settings {
allowMotorways: boolean,
allowTunnels: boolean,
allowAgainstOneway: boolean,
limitCornerSpeed: boolean,
cutoffDistance: number
}
@@ -27,6 +28,7 @@ const DEFAULT_DRAG_COEFFICIENT = 0.005;
const DEFAULT_ALLOW_MOTORWAYS = false;
const DEFAULT_ALLOW_TUNNELS = false;
const DEFAULT_ALLOW_AGAINST_ONE_WAY = false;
const DEFAULT_LIMIT_CORNER_SPEED = true;
const DEFAULT_CUTOFF_DISTANCE = 1000;
// Set up variables
@@ -58,6 +60,7 @@ let dragCoefficientInput = document.getElementById('drag-coefficient-input');
let allowMotorwaysInput = document.getElementById('allow-motorways-input');
let allowTunnelsInput = document.getElementById('allow-tunnels-input');
let allowAgainstOnewayInput = document.getElementById('allow-wrong-way-input');
let limitCornerSpeedInput = document.getElementById('limit-corner-speed-input');
let cutoffDistanceInput = document.getElementById('cutoff-distance-input');
@@ -79,7 +82,8 @@ routeWorker.onmessage = e => {
dragCoefficient: settings.dragCoefficient,
allowMotorways: settings.allowMotorways,
allowTunnels: settings.allowTunnels,
allowAgainstOneway: settings.allowAgainstOneway
allowAgainstOneway: settings.allowAgainstOneway,
limitCornerSpeed: settings.limitCornerSpeed
}};
routeWorker.postMessage(findPathsMessage);
} else if (message.foundPathsFromNode != null) {
@@ -137,7 +141,8 @@ routeWorker.onmessage = e => {
dragCoefficient: settings.dragCoefficient,
allowMotorways: settings.allowMotorways,
allowTunnels: settings.allowTunnels,
allowAgainstOneway: settings.allowAgainstOneway
allowAgainstOneway: settings.allowAgainstOneway,
limitCornerSpeed: settings.limitCornerSpeed
}
};
routeWorker.postMessage(requestMessage);
@@ -189,7 +194,8 @@ function setUpMapHandler() {
dragCoefficient: settings.dragCoefficient,
allowMotorways: settings.allowMotorways,
allowTunnels: settings.allowTunnels,
allowAgainstOneway: settings.allowAgainstOneway
allowAgainstOneway: settings.allowAgainstOneway,
limitCornerSpeed: settings.limitCornerSpeed
}};
routeWorker.postMessage(newRoutesMessage);
}
@@ -306,6 +312,7 @@ setUpNumberInput(dragCoefficientInput, 'drag-coefficient', DEFAULT_DRAG_COEFFICI
setUpBooleanInput(allowMotorwaysInput, 'allow-motorways', DEFAULT_ALLOW_MOTORWAYS);
setUpBooleanInput(allowTunnelsInput, 'allow-tunnels', DEFAULT_ALLOW_TUNNELS);
setUpBooleanInput(allowAgainstOnewayInput, 'allow-against-one-way', DEFAULT_ALLOW_AGAINST_ONE_WAY);
setUpBooleanInput(limitCornerSpeedInput, 'limit-corner-speed', DEFAULT_LIMIT_CORNER_SPEED);
setUpNumberInput(cutoffDistanceInput, 'cutoff-distance', DEFAULT_CUTOFF_DISTANCE);
function getSettings(): Settings {
@@ -317,6 +324,7 @@ function getSettings(): Settings {
allowMotorways: getBooleanValue(allowMotorwaysInput, DEFAULT_ALLOW_MOTORWAYS),
allowTunnels: getBooleanValue(allowTunnelsInput, DEFAULT_ALLOW_TUNNELS),
allowAgainstOneway: getBooleanValue(allowAgainstOnewayInput, DEFAULT_ALLOW_AGAINST_ONE_WAY),
limitCornerSpeed: getBooleanValue(limitCornerSpeedInput, DEFAULT_LIMIT_CORNER_SPEED),
cutoffDistance: getNumberValue(cutoffDistanceInput, DEFAULT_CUTOFF_DISTANCE)
};
}
@@ -329,6 +337,7 @@ function enableSettings(): void {
enableInput(allowMotorwaysInput);
enableInput(allowTunnelsInput);
enableInput(allowAgainstOnewayInput);
enableInput(limitCornerSpeedInput);
}
function disableSettings(): void {
@@ -339,6 +348,7 @@ function disableSettings(): void {
disableInput(allowMotorwaysInput);
disableInput(allowTunnelsInput);
disableInput(allowAgainstOnewayInput);
disableInput(limitCornerSpeedInput);
}
@@ -356,7 +366,8 @@ searchButton?.addEventListener('click', _ => {
dragCoefficient: settings.dragCoefficient,
allowMotorways: settings.allowMotorways,
allowTunnels: settings.allowTunnels,
allowAgainstOneway: settings.allowAgainstOneway
allowAgainstOneway: settings.allowAgainstOneway,
limitCornerSpeed: settings.limitCornerSpeed
}};
routeWorker.postMessage(message);
}
+3 -1
View File
@@ -102,7 +102,8 @@ onmessage = async (e) => {
message.findPathsFromNode.dragCoefficient,
message.findPathsFromNode.allowMotorways,
message.findPathsFromNode.allowTunnels,
message.findPathsFromNode.allowAgainstOneway
message.findPathsFromNode.allowAgainstOneway,
message.findPathsFromNode.limitCornerSpeed
);
let endpoints: Endpoint[] = [];
@@ -186,6 +187,7 @@ onmessage = async (e) => {
settings.allowMotorways,
settings.allowTunnels,
settings.allowAgainstOneway,
settings.limitCornerSpeed,
createCMultiPolygon(module, settings.polygons)
);