Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!intersection_indices.some(intersection_index => intersection_index === street_points.length - 1)) {
intersection_indices.push(street_points.length - 1);
}
//Make a graph out of segments of the street between the start, intersections, and end of the street,
//so that the nodes are the coordinates of the start, end, and intersection points, and the edges are
//the segments between successive nodes. Each edge is associated with the geographic distance between its nodes.
for (let i = 0; i <= intersection_indices.length - 2; i++) {
let node_a = street_points[intersection_indices[i]],
node_b = street_points[intersection_indices[i + 1]],
a_string = encodeLatLng(node_a),
b_string = encodeLatLng(node_b),
start_coords = L.A.pointToCoordinateArray(node_a),
end_coords = L.A.pointToCoordinateArray(node_b),
segment = lineSlice(start_coords, end_coords, street.toGeoJSON()),
distance = length(segment);
graph.addLink(a_string, b_string, {
distance: distance,
place: { type: "street",
id: street_id }
});
}
}
Agent.travel = function(override_speed) {
let current_coords = L.A.pointToCoordinateArray(this.trip.current_point),
sub_goal_distance = override_speed ||this.trip.speed,
sub_goal_coords = destination(current_coords, sub_goal_distance * .001,this.trip.angle).geometry.coordinates,
sub_goal_lat_lng = L.latLng(L.A.reversedCoordinates(sub_goal_coords));
let segment_to_goal = lineString([this.trip.current_point, this.trip.goal_point].map(point => L.A.pointToCoordinateArray(point))),
segment_to_sub_goal = lineString([this.trip.current_point, sub_goal_lat_lng].map(point => L.A.pointToCoordinateArray(point)));
let goal_lat_dist = Math.abs(this.trip.current_point.lat - this.trip.goal_point.lat),
goal_lng_dist = Math.abs(this.trip.current_point.lng - this.trip.goal_point.lng);
let dist_to_goal = length(segment_to_goal) * 1000,
dist_to_sub_goal = length(segment_to_sub_goal) * 1000,
leftover_after_goal;
//Check if the distance to the sub_goal is greater than the distance to the goal, and if so, make the sub_goal equal the goal
//and change the number of meters to the sub_goal to the number of meters to the goal.
if (dist_to_goal < dist_to_sub_goal) {
sub_goal_lat_lng = this.trip.goal_point,
sub_goal_distance = dist_to_goal,
leftover_after_goal = dist_to_sub_goal - dist_to_goal;
}
if (this.checkArrival(sub_goal_lat_lng, leftover_after_goal)) {
return;
}
//Lat/Lng distance between current point and sub_goal point.
Agent.travel = function(override_speed) {
let current_coords = L.A.pointToCoordinateArray(this.trip.current_point),
sub_goal_distance = override_speed ||this.trip.speed,
sub_goal_coords = destination(current_coords, sub_goal_distance * .001,this.trip.angle).geometry.coordinates,
sub_goal_lat_lng = L.latLng(L.A.reversedCoordinates(sub_goal_coords));
let segment_to_goal = lineString([this.trip.current_point, this.trip.goal_point].map(point => L.A.pointToCoordinateArray(point))),
segment_to_sub_goal = lineString([this.trip.current_point, sub_goal_lat_lng].map(point => L.A.pointToCoordinateArray(point)));
let goal_lat_dist = Math.abs(this.trip.current_point.lat - this.trip.goal_point.lat),
goal_lng_dist = Math.abs(this.trip.current_point.lng - this.trip.goal_point.lng);
let dist_to_goal = length(segment_to_goal) * 1000,
dist_to_sub_goal = length(segment_to_sub_goal) * 1000,
leftover_after_goal;
//Check if the distance to the sub_goal is greater than the distance to the goal, and if so, make the sub_goal equal the goal
//and change the number of meters to the sub_goal to the number of meters to the goal.
if (dist_to_goal < dist_to_sub_goal) {
sub_goal_lat_lng = this.trip.goal_point,
sub_goal_distance = dist_to_goal,
leftover_after_goal = dist_to_sub_goal - dist_to_goal;
}
if (this.checkArrival(sub_goal_lat_lng, leftover_after_goal)) {
return;
}
//Lat/Lng distance between current point and sub_goal point.
let sub_goal_lat_dist = Math.abs(sub_goal_lat_lng.lat - this.trip.current_point.lat),