-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better poi index computation #109
base: master
Are you sure you want to change the base?
Conversation
flatCoordinates[offset], | ||
flatCoordinates[offset + 1] | ||
); | ||
if (squaredDistance < minSquaredDistance) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is always true.
((Math.sqrt(squaredDistance) - Math.sqrt(minSquaredDistance)) / | ||
maxDelta) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an integer?
Also, instead of max we could do xxxx | 1
and that would also avoid te infinite loop.
let totalSquaredDistance = 0; | ||
for (i = offset + stride; i < minIndex; ++i) { | ||
totalSquaredDistance += squaredDx( | ||
flatCoordinates[i - stride], | ||
flatCoordinates[i - stride + 1], | ||
flatCoordinates[i], | ||
flatCoordinates[i + 1] | ||
) | ||
} | ||
totalSquaredDistance += squaredDx( | ||
flatCoordinates[minIndex], | ||
flatCoordinates[minIndex + 1], | ||
closestPoint[0], | ||
closestPoint[1] | ||
); | ||
|
||
return { | ||
totalSquaredDistance: totalSquaredDistance, | ||
squaredDistance: minSquaredDistance, | ||
closestPoint: closestPoint, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this part can be computed by the algorithm automatically:
- from the initial coordinates;
- add 1 dimension for the distanceFromTheStartToThisPoint;
- then the assignClosest function will automatically compute the distance from the start of the track to the projected point.
minSquaredDistance = squaredDistance; | ||
minIndex = index; | ||
for (i = 0; i < stride; ++i) { | ||
closestPoint[i] = tmpPoint[i]; | ||
} | ||
closestPoint.length = stride; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could avoid these copies by defining 2 points and swapping between them appropriately:
let closestPoint = [];
let assignedPoint = [];
...
assignedPoint = assignClosest(..., assignedClosest);
if (squaredDistance < minSquaredDistance) {
minSquaredDistance = squaredDistance;
minIndex = index;
[closestPoint, assignedPoint] = [assignedPoint, closestPoint]; // swap variables
...
}
No description provided.