1
0
Fork 0

gipy: more lost speedup + scale bugfix

master
frederic wagner 2022-11-20 12:04:49 +01:00
parent 7685d347fd
commit adc83746ad
1 changed files with 20 additions and 31 deletions

View File

@ -251,7 +251,8 @@ class Status {
this.projected_point = projection; // save this info for display this.projected_point = projection; // save this info for display
let distance_to_projection = this.position.distance(projection); let distance_to_projection = this.position.distance(projection);
if (distance_to_projection > 50) { if (distance_to_projection > 50) {
this.scale_factor = Math.min(66.0 / distance_to_projection, 40000.0); this.scale_factor =
Math.min(66.0 / distance_to_projection, 1.0) * 40000.0;
return true; return true;
} else { } else {
this.scale_factor = 40000.0; this.scale_factor = 40000.0;
@ -525,20 +526,6 @@ class Path {
return r != 0; return r != 0;
} }
// execute op on all segments.
// start is index of first wanted segment
// end is 1 after index of last wanted segment
on_segments(op, start, end) {
let previous_point = null;
for (let i = start; i < end + 1; i++) {
let point = new Point(this.points[2 * i], this.points[2 * i + 1]);
if (previous_point !== null) {
op(previous_point, point, i);
}
previous_point = point;
}
}
// return point at given index // return point at given index
point(index) { point(index) {
let lon = this.points[2 * index]; let lon = this.points[2 * index];
@ -564,9 +551,11 @@ class Path {
// we are going to compute two min distances, one for each direction. // we are going to compute two min distances, one for each direction.
let indices = [0, 0]; let indices = [0, 0];
let mins = [Number.MAX_VALUE, Number.MAX_VALUE]; let mins = [Number.MAX_VALUE, Number.MAX_VALUE];
this.on_segments(
function (p1, p2, i) { let p1 = new Point(this.points[2 * start], this.points[2 * start + 1]);
// we use the dot product to figure out if oriented correctly for (let i = start + 1; i < end + 1; i++) {
let p2 = new Point(this.points[2 * i], this.points[2 * i + 1]);
let closest_point = point.closest_segment_point(p1, p2); let closest_point = point.closest_segment_point(p1, p2);
let distance = point.length_squared(closest_point); let distance = point.length_squared(closest_point);
@ -577,10 +566,10 @@ class Path {
mins[orientation] = distance; mins[orientation] = distance;
indices[orientation] = i - 1; indices[orientation] = i - 1;
} }
},
start, p1 = p2;
end }
);
// by default correct orientation (0) wins // by default correct orientation (0) wins
// but if other one is really closer, return other one // but if other one is really closer, return other one
if (mins[1] < mins[0] / 100.0) { if (mins[1] < mins[0] / 100.0) {