mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
renaming
This commit is contained in:
parent
83881dff4b
commit
1acf3b93b5
1 changed files with 37 additions and 73 deletions
110
src/index.tsx
110
src/index.tsx
|
@ -171,52 +171,25 @@ function hitTest(element: ExcalidrawElement, x: number, y: number): boolean {
|
||||||
y -= element.y;
|
y -= element.y;
|
||||||
|
|
||||||
const [
|
const [
|
||||||
topEdgeX,
|
topX,
|
||||||
topEdgeY,
|
topY,
|
||||||
rightEdgeX,
|
rightX,
|
||||||
rightEdgeY,
|
rightY,
|
||||||
bottomEdgeX,
|
bottomX,
|
||||||
bottomEdgeY,
|
bottomY,
|
||||||
leftEdgeX,
|
leftX,
|
||||||
leftEdgeY
|
leftY
|
||||||
] = getDiamondPoints(element);
|
] = getDiamondPoints(element);
|
||||||
// (x1, y1) --A-- (x2, y1)
|
|
||||||
// |D |B
|
|
||||||
// (x1, y2) --C-- (x2, y2)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
distanceBetweenPointAndSegment(
|
distanceBetweenPointAndSegment(x, y, topX, topY, rightX, rightY) <
|
||||||
x,
|
lineThreshold ||
|
||||||
y,
|
distanceBetweenPointAndSegment(x, y, rightX, rightY, bottomX, bottomY) <
|
||||||
topEdgeX,
|
lineThreshold ||
|
||||||
topEdgeY,
|
distanceBetweenPointAndSegment(x, y, bottomX, bottomY, leftX, leftY) <
|
||||||
rightEdgeX,
|
lineThreshold ||
|
||||||
rightEdgeY
|
distanceBetweenPointAndSegment(x, y, leftX, leftY, topX, topY) <
|
||||||
) < lineThreshold || // A
|
lineThreshold
|
||||||
distanceBetweenPointAndSegment(
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
rightEdgeX,
|
|
||||||
rightEdgeY,
|
|
||||||
bottomEdgeX,
|
|
||||||
bottomEdgeY
|
|
||||||
) < lineThreshold || // B
|
|
||||||
distanceBetweenPointAndSegment(
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
bottomEdgeX,
|
|
||||||
bottomEdgeY,
|
|
||||||
leftEdgeX,
|
|
||||||
leftEdgeY
|
|
||||||
) < lineThreshold || // C
|
|
||||||
distanceBetweenPointAndSegment(
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
leftEdgeX,
|
|
||||||
leftEdgeY,
|
|
||||||
topEdgeX,
|
|
||||||
topEdgeY
|
|
||||||
) < lineThreshold // D ||
|
|
||||||
);
|
);
|
||||||
} else if (element.type === "arrow") {
|
} else if (element.type === "arrow") {
|
||||||
let [x1, y1, x2, y2, x3, y3, x4, y4] = getArrowPoints(element);
|
let [x1, y1, x2, y2, x3, y3, x4, y4] = getArrowPoints(element);
|
||||||
|
@ -759,25 +732,16 @@ function getArrowPoints(element: ExcalidrawElement) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDiamondPoints(element: ExcalidrawElement) {
|
function getDiamondPoints(element: ExcalidrawElement) {
|
||||||
const topEdgeX = Math.PI + element.width / 2;
|
const topX = Math.PI + element.width / 2;
|
||||||
const topEdgeY = element.height - element.height;
|
const topY = element.height - element.height;
|
||||||
const rightEdgeX = element.width;
|
const rightX = element.width;
|
||||||
const rightEdgeY = Math.PI + element.height / 2;
|
const rightY = Math.PI + element.height / 2;
|
||||||
const bottomEdgeX = topEdgeX;
|
const bottomX = topX;
|
||||||
const bottomEdgeY = element.height;
|
const bottomY = element.height;
|
||||||
const leftEdgeX = topEdgeY;
|
const leftX = topY;
|
||||||
const leftEdgeY = rightEdgeY;
|
const leftY = rightY;
|
||||||
|
|
||||||
return [
|
return [topX, topY, rightX, rightY, bottomX, bottomY, leftX, leftY];
|
||||||
topEdgeX,
|
|
||||||
topEdgeY,
|
|
||||||
rightEdgeX,
|
|
||||||
rightEdgeY,
|
|
||||||
bottomEdgeX,
|
|
||||||
bottomEdgeY,
|
|
||||||
leftEdgeX,
|
|
||||||
leftEdgeY
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateDraw(element: ExcalidrawElement) {
|
function generateDraw(element: ExcalidrawElement) {
|
||||||
|
@ -808,21 +772,21 @@ function generateDraw(element: ExcalidrawElement) {
|
||||||
} else if (element.type === "diamond") {
|
} else if (element.type === "diamond") {
|
||||||
const shape = withCustomMathRandom(element.seed, () => {
|
const shape = withCustomMathRandom(element.seed, () => {
|
||||||
const [
|
const [
|
||||||
topEdgeX,
|
topX,
|
||||||
topEdgeY,
|
topY,
|
||||||
rightEdgeX,
|
rightX,
|
||||||
rightEdgeY,
|
rightY,
|
||||||
bottomEdgeX,
|
bottomX,
|
||||||
bottomEdgeY,
|
bottomY,
|
||||||
leftEdgeX,
|
leftX,
|
||||||
leftEdgeY
|
leftY
|
||||||
] = getDiamondPoints(element);
|
] = getDiamondPoints(element);
|
||||||
return generator.polygon(
|
return generator.polygon(
|
||||||
[
|
[
|
||||||
[topEdgeX, topEdgeY],
|
[topX, topY],
|
||||||
[rightEdgeX, rightEdgeY],
|
[rightX, rightY],
|
||||||
[bottomEdgeX, bottomEdgeY],
|
[bottomX, bottomY],
|
||||||
[leftEdgeX, leftEdgeY]
|
[leftX, leftY]
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
stroke: element.strokeColor,
|
stroke: element.strokeColor,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue