Skip to content

Fix line2points() to return explicit [longitude, latitude] arrays - #65

Merged
ohanssen merged 1 commit into
masterfrom
copilot/fix-line2points-function
Jul 15, 2026
Merged

Fix line2points() to return explicit [longitude, latitude] arrays#65
ohanssen merged 1 commit into
masterfrom
copilot/fix-line2points-function

Conversation

Copilot AI commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

line2points() was previously using ol.sphere.offset() for all points including the start/end, and returning [from] directly in the zero-distance case — neither made the [longitude, latitude] format explicit, and ol.sphere.offset(from, 0, bearing) introduced unnecessary floating-point noise on the first point.

Changes

  • Zero-distance path: return [from]return [[from[0], from[1]]]
  • Start point: seeded as [[from[0], from[1]]] — exact, no ol.sphere.offset(…, 0, bearing) approximation
  • Intermediate points: ol.sphere.offset result destructured as [pt[0], pt[1]] — explicitly [longitude, latitude]
  • End point: appended as [to[0], to[1]] — exact destination, not a geodesic offset approximation of it
// Before: floating-point noise on first/last, implicit format
for (let i = 0; i <= n; i++)
    points.push(ol.sphere.offset(from, Math.min(i * distance, totalDist), bearing));

// After: exact endpoints, explicit [longitude, latitude] construction
const points = [[from[0], from[1]]];
for (let i = 1; i < n; i++) {
    const pt = ol.sphere.offset(from, i * distance, bearing);
    points.push([pt[0], pt[1]]);
}
points.push([to[0], to[1]]);

@ohanssen
ohanssen marked this pull request as ready for review July 15, 2026 11:45
Copilot AI review requested due to automatic review settings July 15, 2026 11:45
@ohanssen
ohanssen merged commit b9af801 into master Jul 15, 2026
1 check passed
@ohanssen
ohanssen deleted the copilot/fix-line2points-function branch July 15, 2026 11:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refines pol.core.MapBrowser#line2points() so it always returns explicit 2D [longitude, latitude] coordinate arrays, while avoiding unnecessary floating-point noise at the start/end points by not using ol.sphere.offset() for those endpoints.

Changes:

  • Makes the zero-distance case return an explicit [[from[0], from[1]]] instead of returning the from array directly.
  • Seeds the result with an exact copy of the start coordinate and appends an exact copy of the end coordinate.
  • Keeps intermediate points computed via ol.sphere.offset(), but pushes them as explicit [pt[0], pt[1]] arrays.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants