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

more precise angle computation #1205

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/stylefunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,14 +832,15 @@ export function stylefunction(
const x2 = coordinates[i + stride];
const y2 = coordinates[i + stride + 1];
const minX = Math.min(x1, x2);
const minY = Math.min(y1, y2);
const maxX = Math.max(x1, x2);
const maxY = Math.max(y1, y2);
const xM = midpoint[0];
const yM = midpoint[1];
const dotProduct =
(y2 - y1) * (xM - x1) - (x2 - x1) * (yM - y1);
if (
midpoint[0] >= minX &&
midpoint[0] <= maxX &&
midpoint[1] >= minY &&
midpoint[1] <= maxY
Math.abs(dotProduct) < 0.001 && //midpoint is aligned with the segment
xM <= maxX &&
xM >= minX //midpoint is on the segment and not outside it
) {
placementAngle = Math.atan2(y1 - y2, x2 - x1);
break;
Expand Down