Fix linting

This commit is contained in:
Mathias Krafft 2025-04-07 13:59:50 +00:00
parent ac37d0a5be
commit 37412cd68a
2 changed files with 59 additions and 31 deletions

View file

@ -245,18 +245,20 @@ export const isPointWithinBounds = <P extends GlobalPoint | LocalPoint>(
export const perpendicularDistance = <P extends GlobalPoint | LocalPoint>(
p: P,
start: P,
end: P):
number => {
end: P,
): number => {
const dx = end[0] - start[0];
const dy = end[1] - start[1];
if (dx === 0 && dy === 0) {
return Math.hypot(p[0] - start[0], p[1] - start[1]);
}
// Equation of line distance
const numerator = Math.abs(dy * p[0] - dx * p[1] + end[0] * start[1] - end[1] * start[0]);
const numerator = Math.abs(
dy * p[0] - dx * p[1] + end[0] * start[1] - end[1] * start[0],
);
const denom = Math.hypot(dx, dy);
return numerator / denom;
}
};
/** * Calculates the angle between three points in degrees.
* The angle is calculated at the first point (p0) using the second (p1) and third (p2) points.
@ -266,7 +268,7 @@ export const perpendicularDistance = <P extends GlobalPoint | LocalPoint>(
* @param p1 The vertex point where the angle is calculated.
* @param p2 The second point used to form the angle.
* @returns The angle in degrees between the three points.
**/
**/
export const angleBetween = <P extends GlobalPoint | LocalPoint>(
p0: P,
p1: P,
@ -276,8 +278,12 @@ export const angleBetween = <P extends GlobalPoint | LocalPoint>(
const v2 = vectorFromPoint(p1, p2);
// dot and cross product
const magnitude1 = Math.hypot(v1[0], v1[1]), magnitude2 = Math.hypot(v2[0], v2[1]);
if (magnitude1 === 0 || magnitude2 === 0) return 0 as Degrees;
const magnitude1 = Math.hypot(v1[0], v1[1]);
const magnitude2 = Math.hypot(v2[0], v2[1]);
if (magnitude1 === 0 || magnitude2 === 0) {
return 0 as Degrees;
}
const dot = vectorDot(v1, v2);
@ -287,4 +293,4 @@ export const angleBetween = <P extends GlobalPoint | LocalPoint>(
const rad = Math.acos(cos) as Radians;
return radiansToDegrees(rad);
}
};