Skip to content

Implement line2points in mapbrowser.js - #63

Merged
ohanssen merged 1 commit into
masterfrom
copilot/implement-line2points
Jul 14, 2026
Merged

Implement line2points in mapbrowser.js#63
ohanssen merged 1 commit into
masterfrom
copilot/implement-line2points

Conversation

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

line2points was a stub (/* TBD */) with no implementation.

Changes

  • Geodesic interpolation: computes initial bearing via haversine formula, then uses ol.sphere.offset to place points at exact meter intervals along the great-circle arc — avoids the distortion of linear lon/lat interpolation
  • Distance calculation: uses ol.sphere.getDistance for the total arc length between endpoints
  • Edge cases: returns [] for invalid/non-positive distance, [from] when from === to
  • Endpoint inclusion: uses Math.ceil + Math.min clamp so both from and to are always included without duplicates regardless of divisibility
// Returns [lon,lat] points spaced ~500m apart along the geodesic
const pts = mb.line2points([10.0, 59.0], [10.1, 59.1], 500);

@ohanssen
ohanssen marked this pull request as ready for review July 14, 2026 13:29
Copilot AI review requested due to automatic review settings July 14, 2026 13:29
@ohanssen
ohanssen merged commit a12eef8 into master Jul 14, 2026
1 check passed
@ohanssen
ohanssen deleted the copilot/implement-line2points branch July 14, 2026 13:29

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 implements line2points() in mapbrowser.js, replacing the previous stub with a geodesic-based interpolation that generates evenly spaced points (in meters) between two lon/lat coordinates using OpenLayers sphere utilities.

Changes:

  • Implements distance computation via ol.sphere.getDistance(from, to).
  • Computes initial bearing and uses ol.sphere.offset() to generate points at fixed meter intervals along the great-circle path.
  • Adds basic edge-case handling for invalid/non-positive distance and coincident endpoints.

💡 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