mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Fix arc negative radians issue
This commit is contained in:
parent
fb113e2054
commit
b2fcf787e2
2 changed files with 20 additions and 13 deletions
|
@ -60,8 +60,14 @@ export const normalizeRadians = (angle: Radians): Radians => {
|
|||
export const cartesian2Polar = <P extends GenericPoint>([
|
||||
x,
|
||||
y,
|
||||
]: P): PolarCoords =>
|
||||
polar(Math.hypot(x, y), normalizeRadians(radians(Math.atan2(y, x))));
|
||||
]: P): PolarCoords => {
|
||||
const [radius, angle] = polar(
|
||||
Math.hypot(x, y),
|
||||
normalizeRadians(radians(Math.atan2(y, x))),
|
||||
);
|
||||
|
||||
return [radius, normalizeRadians(angle)] as PolarCoords;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert an angle in degrees into randians
|
||||
|
|
|
@ -25,7 +25,10 @@ export function arc<Point extends GenericPoint>(
|
|||
startAngle: Radians,
|
||||
endAngle: Radians,
|
||||
) {
|
||||
return { center, radius, startAngle, endAngle } as Arc<Point>;
|
||||
const start = normalizeRadians(startAngle);
|
||||
const end = normalizeRadians(endAngle);
|
||||
|
||||
return { center, radius, startAngle: start, endAngle: end } as Arc<Point>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,11 +103,10 @@ export function arcSegmentInterceptPoints<Point extends GenericPoint>(
|
|||
pointFrom(candidate[0] - a.center[0], candidate[1] - a.center[1]),
|
||||
);
|
||||
|
||||
return a.startAngle < a.endAngle
|
||||
? Math.abs(a.radius - candidateRadius) < PRECISION &&
|
||||
a.startAngle <= candidateAngle &&
|
||||
a.endAngle >= candidateAngle
|
||||
: a.startAngle <= candidateAngle || a.endAngle >= candidateAngle;
|
||||
return Math.abs(a.radius - candidateRadius) < PRECISION &&
|
||||
a.startAngle > a.endAngle
|
||||
? a.startAngle <= candidateAngle || a.endAngle >= candidateAngle
|
||||
: a.startAngle <= candidateAngle && a.endAngle >= candidateAngle;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -128,11 +130,10 @@ export function arcLineInterceptPoints<Point extends GenericPoint>(
|
|||
pointFrom(candidate[0] - a.center[0], candidate[1] - a.center[1]),
|
||||
);
|
||||
|
||||
return a.startAngle < a.endAngle
|
||||
? Math.abs(a.radius - candidateRadius) < PRECISION &&
|
||||
a.startAngle <= candidateAngle &&
|
||||
a.endAngle >= candidateAngle
|
||||
: a.startAngle <= candidateAngle || a.endAngle >= candidateAngle;
|
||||
return Math.abs(a.radius - candidateRadius) < PRECISION &&
|
||||
a.startAngle > a.endAngle
|
||||
? a.startAngle <= candidateAngle || a.endAngle >= candidateAngle
|
||||
: a.startAngle <= candidateAngle && a.endAngle >= candidateAngle;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue