Skip to content
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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Better poi index computation #109

wants to merge 2 commits into from

Conversation

fredj
Copy link
Contributor

@fredj fredj commented Aug 28, 2023

No description provided.

@fredj fredj marked this pull request as draft August 28, 2023 13:33
flatCoordinates[offset],
flatCoordinates[offset + 1]
);
if (squaredDistance < minSquaredDistance) {
Copy link
Contributor

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.

Comment on lines +142 to +143
((Math.sqrt(squaredDistance) - Math.sqrt(minSquaredDistance)) /
maxDelta) |
Copy link
Contributor

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.

Comment on lines +149 to +169
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,
}
Copy link
Contributor

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.

Comment on lines +121 to +126
minSquaredDistance = squaredDistance;
minIndex = index;
for (i = 0; i < stride; ++i) {
closestPoint[i] = tmpPoint[i];
}
closestPoint.length = stride;
Copy link
Contributor

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
...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants