Skip to content

Better poi index computation#109

Draft
fredj wants to merge 2 commits into
masterfrom
poi_indexes
Draft

Better poi index computation#109
fredj wants to merge 2 commits into
masterfrom
poi_indexes

Conversation

@fredj

@fredj fredj commented Aug 28, 2023

Copy link
Copy Markdown
Member

No description provided.

@fredj fredj marked this pull request as draft August 28, 2023 13:33
Comment thread src/closest.ts
flatCoordinates[offset],
flatCoordinates[offset + 1]
);
if (squaredDistance < minSquaredDistance) {

Copy link
Copy Markdown
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 thread src/closest.ts
Comment on lines +142 to +143
((Math.sqrt(squaredDistance) - Math.sqrt(minSquaredDistance)) /
maxDelta) |

Copy link
Copy Markdown
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 thread src/closest.ts
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
Copy Markdown
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 thread src/closest.ts
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
Copy Markdown
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