Skip to content

Commit

Permalink
Merge pull request #1205 from leyan/icon-rotation
Browse files Browse the repository at this point in the history
more precise angle computation
  • Loading branch information
ahocevar authored Oct 20, 2024
2 parents a4ff0cb + ae56027 commit ef96821
Showing 1 changed file with 7 additions and 6 deletions.
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

0 comments on commit ef96821

Please sign in to comment.