support ellipse
This commit is contained in:
parent
4d1b31a171
commit
16db74cedd
@ -730,7 +730,6 @@ export const isHittingContainerStroke = (
|
|||||||
container: ExcalidrawTextContainer,
|
container: ExcalidrawTextContainer,
|
||||||
zoom: number,
|
zoom: number,
|
||||||
) => {
|
) => {
|
||||||
const threshold = 10 / zoom;
|
|
||||||
const bounds = getElementBounds(container);
|
const bounds = getElementBounds(container);
|
||||||
const topLeft = [bounds[0], bounds[1]];
|
const topLeft = [bounds[0], bounds[1]];
|
||||||
const topRight = [bounds[2], bounds[1]];
|
const topRight = [bounds[2], bounds[1]];
|
||||||
@ -739,8 +738,32 @@ export const isHittingContainerStroke = (
|
|||||||
|
|
||||||
const strokeWidth = container.strokeWidth;
|
const strokeWidth = container.strokeWidth;
|
||||||
if (container.type === "ellipse") {
|
if (container.type === "ellipse") {
|
||||||
|
const threshold = 10 * zoom;
|
||||||
|
const h = (topLeft[0] + topRight[0]) / 2;
|
||||||
|
const k = (topLeft[1] + bottomLeft[1]) / 2;
|
||||||
|
let a = container.width / 2 + threshold;
|
||||||
|
let b = container.height / 2 + threshold;
|
||||||
|
const checkPointOnOuterEllipse =
|
||||||
|
Math.pow(x - h, 2) / Math.pow(a, 2) + Math.pow(y - k, 2) / Math.pow(b, 2);
|
||||||
|
|
||||||
|
a = container.width / 2 - strokeWidth - threshold;
|
||||||
|
b = container.height / 2 - strokeWidth - threshold;
|
||||||
|
|
||||||
|
const checkPointOnInnerEllipse =
|
||||||
|
Math.pow(x - h, 2) / Math.pow(a, 2) + Math.pow(y - k, 2) / Math.pow(b, 2);
|
||||||
|
|
||||||
|
// The expression evaluates to 1 means point is on ellipse,
|
||||||
|
// < 1 means inside ellipse and > 1 means outside ellipse
|
||||||
|
if (
|
||||||
|
checkPointOnInnerEllipse === 1 ||
|
||||||
|
checkPointOnOuterEllipse === 1 ||
|
||||||
|
(checkPointOnInnerEllipse > 1 && checkPointOnOuterEllipse < 1)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const threshold = 10 / zoom;
|
||||||
|
|
||||||
// Left Stroke
|
// Left Stroke
|
||||||
if (
|
if (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user