2020-08-08 21:04:15 -07:00
|
|
|
import * as GA from "../ga";
|
|
|
|
import * as GAPoint from "../gapoints";
|
|
|
|
import * as GADirection from "../gadirections";
|
|
|
|
import * as GALine from "../galines";
|
|
|
|
import * as GATransform from "../gatransforms";
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2021-05-09 16:42:10 +01:00
|
|
|
import {
|
|
|
|
distance2d,
|
|
|
|
rotatePoint,
|
|
|
|
isPathALoop,
|
|
|
|
isPointInPolygon,
|
|
|
|
rotate,
|
|
|
|
} from "../math";
|
2020-08-08 21:04:15 -07:00
|
|
|
import { pointsOnBezierCurves } from "points-on-curve";
|
2020-02-15 21:03:32 +01:00
|
|
|
|
2020-04-09 01:46:47 -07:00
|
|
|
import {
|
2020-08-08 21:04:15 -07:00
|
|
|
NonDeletedExcalidrawElement,
|
|
|
|
ExcalidrawBindableElement,
|
|
|
|
ExcalidrawElement,
|
|
|
|
ExcalidrawRectangleElement,
|
|
|
|
ExcalidrawDiamondElement,
|
|
|
|
ExcalidrawTextElement,
|
|
|
|
ExcalidrawEllipseElement,
|
|
|
|
NonDeleted,
|
2021-05-09 16:42:10 +01:00
|
|
|
ExcalidrawFreeDrawElement,
|
2021-10-21 22:05:48 +02:00
|
|
|
ExcalidrawImageElement,
|
2020-08-08 21:04:15 -07:00
|
|
|
} from "./types";
|
|
|
|
|
|
|
|
import { getElementAbsoluteCoords, getCurvePathOps, Bounds } from "./bounds";
|
2020-03-14 21:48:51 -07:00
|
|
|
import { Point } from "../types";
|
2020-04-09 01:46:47 -07:00
|
|
|
import { Drawable } from "roughjs/bin/core";
|
2020-03-08 10:20:55 -07:00
|
|
|
import { AppState } from "../types";
|
|
|
|
import { getShapeForElement } from "../renderer/renderElement";
|
2021-10-21 22:05:48 +02:00
|
|
|
import { isImageElement } from "./typeChecks";
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
const isElementDraggableFromInside = (
|
2020-04-08 09:49:52 -07:00
|
|
|
element: NonDeletedExcalidrawElement,
|
2020-05-20 16:21:37 +03:00
|
|
|
): boolean => {
|
2020-05-21 12:57:54 -07:00
|
|
|
if (element.type === "arrow") {
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-09 16:42:10 +01:00
|
|
|
|
|
|
|
if (element.type === "freedraw") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-11 11:42:08 +01:00
|
|
|
const isDraggableFromInside = element.backgroundColor !== "transparent";
|
2021-05-09 16:42:10 +01:00
|
|
|
|
|
|
|
if (element.type === "line") {
|
2020-08-11 11:42:08 +01:00
|
|
|
return isDraggableFromInside && isPathALoop(element.points);
|
2020-04-09 01:46:47 -07:00
|
|
|
}
|
2021-10-21 22:05:48 +02:00
|
|
|
return isDraggableFromInside || isImageElement(element);
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|
2020-01-22 00:10:49 -05:00
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
export const hitTest = (
|
2020-04-08 09:49:52 -07:00
|
|
|
element: NonDeletedExcalidrawElement,
|
2020-03-08 10:20:55 -07:00
|
|
|
appState: AppState,
|
2020-01-06 19:34:22 +04:00
|
|
|
x: number,
|
2020-01-24 12:04:54 +02:00
|
|
|
y: number,
|
2020-05-20 16:21:37 +03:00
|
|
|
): boolean => {
|
2020-08-08 21:04:15 -07:00
|
|
|
// How many pixels off the shape boundary we still consider a hit
|
2020-11-04 17:49:15 +00:00
|
|
|
const threshold = 10 / appState.zoom.value;
|
2020-08-11 11:42:08 +01:00
|
|
|
const point: Point = [x, y];
|
|
|
|
|
|
|
|
if (isElementSelected(appState, element)) {
|
2020-08-26 17:37:44 +01:00
|
|
|
return isPointHittingElementBoundingBox(element, point, threshold);
|
2020-08-11 11:42:08 +01:00
|
|
|
}
|
|
|
|
|
2020-08-26 17:37:44 +01:00
|
|
|
return isHittingElementNotConsideringBoundingBox(element, appState, point);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const isHittingElementBoundingBoxWithoutHittingElement = (
|
|
|
|
element: NonDeletedExcalidrawElement,
|
|
|
|
appState: AppState,
|
|
|
|
x: number,
|
|
|
|
y: number,
|
|
|
|
): boolean => {
|
2020-11-04 17:49:15 +00:00
|
|
|
const threshold = 10 / appState.zoom.value;
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
!isHittingElementNotConsideringBoundingBox(element, appState, [x, y]) &&
|
|
|
|
isPointHittingElementBoundingBox(element, [x, y], threshold)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const isHittingElementNotConsideringBoundingBox = (
|
|
|
|
element: NonDeletedExcalidrawElement,
|
|
|
|
appState: AppState,
|
|
|
|
point: Point,
|
|
|
|
): boolean => {
|
2020-11-04 17:49:15 +00:00
|
|
|
const threshold = 10 / appState.zoom.value;
|
2020-08-26 17:37:44 +01:00
|
|
|
|
2020-08-09 00:51:41 -07:00
|
|
|
const check =
|
|
|
|
element.type === "text"
|
|
|
|
? isStrictlyInside
|
2020-08-11 11:42:08 +01:00
|
|
|
: isElementDraggableFromInside(element)
|
2020-08-09 00:51:41 -07:00
|
|
|
? isInsideCheck
|
|
|
|
: isNearCheck;
|
2021-05-09 16:42:10 +01:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
return hitTestPointAgainstElement({ element, point, threshold, check });
|
|
|
|
};
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-08-11 11:42:08 +01:00
|
|
|
const isElementSelected = (
|
|
|
|
appState: AppState,
|
|
|
|
element: NonDeleted<ExcalidrawElement>,
|
|
|
|
) => appState.selectedElementIds[element.id];
|
|
|
|
|
2020-08-26 17:37:44 +01:00
|
|
|
const isPointHittingElementBoundingBox = (
|
2020-08-11 11:42:08 +01:00
|
|
|
element: NonDeleted<ExcalidrawElement>,
|
|
|
|
[x, y]: Point,
|
|
|
|
threshold: number,
|
|
|
|
) => {
|
|
|
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element);
|
|
|
|
const elementCenterX = (x1 + x2) / 2;
|
|
|
|
const elementCenterY = (y1 + y2) / 2;
|
|
|
|
// reverse rotate to take element's angle into account.
|
|
|
|
const [rotatedX, rotatedY] = rotate(
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
elementCenterX,
|
|
|
|
elementCenterY,
|
|
|
|
-element.angle,
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
rotatedX > x1 - threshold &&
|
|
|
|
rotatedX < x2 + threshold &&
|
|
|
|
rotatedY > y1 - threshold &&
|
|
|
|
rotatedY < y2 + threshold
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
export const bindingBorderTest = (
|
|
|
|
element: NonDeleted<ExcalidrawBindableElement>,
|
|
|
|
{ x, y }: { x: number; y: number },
|
|
|
|
): boolean => {
|
|
|
|
const threshold = maxBindingGap(element, element.width, element.height);
|
|
|
|
const check = isOutsideCheck;
|
|
|
|
const point: Point = [x, y];
|
|
|
|
return hitTestPointAgainstElement({ element, point, threshold, check });
|
|
|
|
};
|
2020-04-02 17:40:26 +09:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
export const maxBindingGap = (
|
|
|
|
element: ExcalidrawElement,
|
|
|
|
elementWidth: number,
|
|
|
|
elementHeight: number,
|
|
|
|
): number => {
|
|
|
|
// Aligns diamonds with rectangles
|
|
|
|
const shapeRatio = element.type === "diamond" ? 1 / Math.sqrt(2) : 1;
|
|
|
|
const smallerDimension = shapeRatio * Math.min(elementWidth, elementHeight);
|
|
|
|
// We make the bindable boundary bigger for bigger elements
|
2020-12-09 15:03:25 +02:00
|
|
|
return Math.max(16, Math.min(0.25 * smallerDimension, 32));
|
2020-08-08 21:04:15 -07:00
|
|
|
};
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
type HitTestArgs = {
|
|
|
|
element: NonDeletedExcalidrawElement;
|
|
|
|
point: Point;
|
|
|
|
threshold: number;
|
|
|
|
check: (distance: number, threshold: number) => boolean;
|
|
|
|
};
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
const hitTestPointAgainstElement = (args: HitTestArgs): boolean => {
|
|
|
|
switch (args.element.type) {
|
|
|
|
case "rectangle":
|
2021-10-21 22:05:48 +02:00
|
|
|
case "image":
|
2020-08-08 21:04:15 -07:00
|
|
|
case "text":
|
|
|
|
case "diamond":
|
|
|
|
case "ellipse":
|
|
|
|
const distance = distanceToBindableElement(args.element, args.point);
|
|
|
|
return args.check(distance, args.threshold);
|
2021-05-09 16:42:10 +01:00
|
|
|
case "freedraw": {
|
|
|
|
if (
|
|
|
|
!args.check(
|
|
|
|
distanceToRectangle(args.element, args.point),
|
|
|
|
args.threshold,
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hitTestFreeDrawElement(args.element, args.point, args.threshold);
|
|
|
|
}
|
2020-08-08 21:04:15 -07:00
|
|
|
case "arrow":
|
|
|
|
case "line":
|
|
|
|
return hitTestLinear(args);
|
|
|
|
case "selection":
|
|
|
|
console.warn(
|
|
|
|
"This should not happen, we need to investigate why it does.",
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
export const distanceToBindableElement = (
|
|
|
|
element: ExcalidrawBindableElement,
|
|
|
|
point: Point,
|
|
|
|
): number => {
|
|
|
|
switch (element.type) {
|
|
|
|
case "rectangle":
|
2021-10-21 22:05:48 +02:00
|
|
|
case "image":
|
2020-08-08 21:04:15 -07:00
|
|
|
case "text":
|
|
|
|
return distanceToRectangle(element, point);
|
|
|
|
case "diamond":
|
|
|
|
return distanceToDiamond(element, point);
|
|
|
|
case "ellipse":
|
|
|
|
return distanceToEllipse(element, point);
|
|
|
|
}
|
|
|
|
};
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-08-09 00:51:41 -07:00
|
|
|
const isStrictlyInside = (distance: number, threshold: number): boolean => {
|
|
|
|
return distance < 0;
|
|
|
|
};
|
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
const isInsideCheck = (distance: number, threshold: number): boolean => {
|
|
|
|
return distance < threshold;
|
|
|
|
};
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
const isNearCheck = (distance: number, threshold: number): boolean => {
|
|
|
|
return Math.abs(distance) < threshold;
|
|
|
|
};
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
const isOutsideCheck = (distance: number, threshold: number): boolean => {
|
|
|
|
return 0 <= distance && distance < threshold;
|
|
|
|
};
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
const distanceToRectangle = (
|
2021-05-09 16:42:10 +01:00
|
|
|
element:
|
|
|
|
| ExcalidrawRectangleElement
|
|
|
|
| ExcalidrawTextElement
|
2021-10-21 22:05:48 +02:00
|
|
|
| ExcalidrawFreeDrawElement
|
|
|
|
| ExcalidrawImageElement,
|
2020-08-08 21:04:15 -07:00
|
|
|
point: Point,
|
|
|
|
): number => {
|
|
|
|
const [, pointRel, hwidth, hheight] = pointRelativeToElement(element, point);
|
2020-10-11 09:46:13 +03:00
|
|
|
return Math.max(
|
|
|
|
GAPoint.distanceToLine(pointRel, GALine.equation(0, 1, -hheight)),
|
|
|
|
GAPoint.distanceToLine(pointRel, GALine.equation(1, 0, -hwidth)),
|
|
|
|
);
|
2020-08-08 21:04:15 -07:00
|
|
|
};
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
const distanceToDiamond = (
|
|
|
|
element: ExcalidrawDiamondElement,
|
|
|
|
point: Point,
|
|
|
|
): number => {
|
|
|
|
const [, pointRel, hwidth, hheight] = pointRelativeToElement(element, point);
|
|
|
|
const side = GALine.equation(hheight, hwidth, -hheight * hwidth);
|
|
|
|
return GAPoint.distanceToLine(pointRel, side);
|
|
|
|
};
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
const distanceToEllipse = (
|
|
|
|
element: ExcalidrawEllipseElement,
|
|
|
|
point: Point,
|
|
|
|
): number => {
|
|
|
|
const [pointRel, tangent] = ellipseParamsForTest(element, point);
|
|
|
|
return -GALine.sign(tangent) * GAPoint.distanceToLine(pointRel, tangent);
|
|
|
|
};
|
2020-01-12 20:16:48 +01:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
const ellipseParamsForTest = (
|
|
|
|
element: ExcalidrawEllipseElement,
|
|
|
|
point: Point,
|
|
|
|
): [GA.Point, GA.Line] => {
|
|
|
|
const [, pointRel, hwidth, hheight] = pointRelativeToElement(element, point);
|
|
|
|
const [px, py] = GAPoint.toTuple(pointRel);
|
|
|
|
|
|
|
|
// We're working in positive quadrant, so start with `t = 45deg`, `tx=cos(t)`
|
|
|
|
let tx = 0.707;
|
|
|
|
let ty = 0.707;
|
|
|
|
|
|
|
|
const a = hwidth;
|
|
|
|
const b = hheight;
|
|
|
|
|
|
|
|
// This is a numerical method to find the params tx, ty at which
|
|
|
|
// the ellipse has the closest point to the given point
|
|
|
|
[0, 1, 2, 3].forEach((_) => {
|
|
|
|
const xx = a * tx;
|
|
|
|
const yy = b * ty;
|
|
|
|
|
|
|
|
const ex = ((a * a - b * b) * tx ** 3) / a;
|
|
|
|
const ey = ((b * b - a * a) * ty ** 3) / b;
|
|
|
|
|
|
|
|
const rx = xx - ex;
|
|
|
|
const ry = yy - ey;
|
|
|
|
|
|
|
|
const qx = px - ex;
|
|
|
|
const qy = py - ey;
|
|
|
|
|
|
|
|
const r = Math.hypot(ry, rx);
|
|
|
|
const q = Math.hypot(qy, qx);
|
|
|
|
|
|
|
|
tx = Math.min(1, Math.max(0, ((qx * r) / q + ex) / a));
|
|
|
|
ty = Math.min(1, Math.max(0, ((qy * r) / q + ey) / b));
|
|
|
|
const t = Math.hypot(ty, tx);
|
|
|
|
tx /= t;
|
|
|
|
ty /= t;
|
|
|
|
});
|
|
|
|
|
|
|
|
const closestPoint = GA.point(a * tx, b * ty);
|
2020-01-12 20:16:48 +01:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
const tangent = GALine.orthogonalThrough(pointRel, closestPoint);
|
|
|
|
return [pointRel, tangent];
|
|
|
|
};
|
|
|
|
|
2021-05-09 16:42:10 +01:00
|
|
|
const hitTestFreeDrawElement = (
|
|
|
|
element: ExcalidrawFreeDrawElement,
|
|
|
|
point: Point,
|
|
|
|
threshold: number,
|
|
|
|
): boolean => {
|
|
|
|
// Check point-distance-to-line-segment for every segment in the
|
|
|
|
// element's points (its input points, not its outline points).
|
|
|
|
// This is... okay? It's plenty fast, but the GA library may
|
|
|
|
// have a faster option.
|
|
|
|
|
|
|
|
let x: number;
|
|
|
|
let y: number;
|
|
|
|
|
|
|
|
if (element.angle === 0) {
|
|
|
|
x = point[0] - element.x;
|
|
|
|
y = point[1] - element.y;
|
|
|
|
} else {
|
|
|
|
// Counter-rotate the point around center before testing
|
|
|
|
const [minX, minY, maxX, maxY] = getElementAbsoluteCoords(element);
|
|
|
|
const rotatedPoint = rotatePoint(
|
|
|
|
point,
|
|
|
|
[minX + (maxX - minX) / 2, minY + (maxY - minY) / 2],
|
|
|
|
-element.angle,
|
|
|
|
);
|
|
|
|
x = rotatedPoint[0] - element.x;
|
|
|
|
y = rotatedPoint[1] - element.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
let [A, B] = element.points;
|
|
|
|
let P: readonly [number, number];
|
|
|
|
|
|
|
|
// For freedraw dots
|
2021-10-11 19:11:26 +01:00
|
|
|
if (
|
|
|
|
distance2d(A[0], A[1], x, y) < threshold ||
|
|
|
|
distance2d(B[0], B[1], x, y) < threshold
|
|
|
|
) {
|
|
|
|
return true;
|
2021-05-09 16:42:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// For freedraw lines
|
2021-10-11 19:11:26 +01:00
|
|
|
for (let i = 0; i < element.points.length; i++) {
|
2021-05-09 16:42:10 +01:00
|
|
|
const delta = [B[0] - A[0], B[1] - A[1]];
|
|
|
|
const length = Math.hypot(delta[1], delta[0]);
|
|
|
|
|
|
|
|
const U = [delta[0] / length, delta[1] / length];
|
|
|
|
const C = [x - A[0], y - A[1]];
|
|
|
|
const d = (C[0] * U[0] + C[1] * U[1]) / Math.hypot(U[1], U[0]);
|
|
|
|
P = [A[0] + U[0] * d, A[1] + U[1] * d];
|
|
|
|
|
|
|
|
const da = distance2d(P[0], P[1], A[0], A[1]);
|
|
|
|
const db = distance2d(P[0], P[1], B[0], B[1]);
|
|
|
|
|
|
|
|
P = db < da && da > length ? B : da < db && db > length ? A : P;
|
|
|
|
|
|
|
|
if (Math.hypot(y - P[1], x - P[0]) < threshold) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
A = B;
|
|
|
|
B = element.points[i + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
const hitTestLinear = (args: HitTestArgs): boolean => {
|
|
|
|
const { element, threshold } = args;
|
|
|
|
if (!getShapeForElement(element)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const [point, pointAbs, hwidth, hheight] = pointRelativeToElement(
|
|
|
|
args.element,
|
|
|
|
args.point,
|
|
|
|
);
|
|
|
|
const side1 = GALine.equation(0, 1, -hheight);
|
|
|
|
const side2 = GALine.equation(1, 0, -hwidth);
|
|
|
|
if (
|
|
|
|
!isInsideCheck(GAPoint.distanceToLine(pointAbs, side1), threshold) ||
|
|
|
|
!isInsideCheck(GAPoint.distanceToLine(pointAbs, side2), threshold)
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const [relX, relY] = GAPoint.toTuple(point);
|
|
|
|
|
|
|
|
const shape = getShapeForElement(element) as Drawable[];
|
|
|
|
|
|
|
|
if (args.check === isInsideCheck) {
|
|
|
|
const hit = shape.some((subshape) =>
|
2020-08-15 00:59:43 +09:00
|
|
|
hitTestCurveInside(subshape, relX, relY, element.strokeSharpness),
|
2020-01-06 19:34:22 +04:00
|
|
|
);
|
2020-08-08 21:04:15 -07:00
|
|
|
if (hit) {
|
|
|
|
return true;
|
2020-02-02 20:04:35 +02:00
|
|
|
}
|
2020-08-08 21:04:15 -07:00
|
|
|
}
|
2020-02-01 15:49:18 +04:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
// hit test all "subshapes" of the linear element
|
|
|
|
return shape.some((subshape) =>
|
|
|
|
hitTestRoughShape(subshape, relX, relY, threshold),
|
|
|
|
);
|
|
|
|
};
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
// Returns:
|
|
|
|
// 1. the point relative to the elements (x, y) position
|
|
|
|
// 2. the point relative to the element's center with positive (x, y)
|
|
|
|
// 3. half element width
|
|
|
|
// 4. half element height
|
|
|
|
//
|
|
|
|
// Note that for linear elements the (x, y) position is not at the
|
|
|
|
// top right corner of their boundary.
|
|
|
|
//
|
|
|
|
// Rectangles, diamonds and ellipses are symmetrical over axes,
|
|
|
|
// and other elements have a rectangular boundary,
|
|
|
|
// so we only need to perform hit tests for the positive quadrant.
|
|
|
|
const pointRelativeToElement = (
|
|
|
|
element: ExcalidrawElement,
|
|
|
|
pointTuple: Point,
|
|
|
|
): [GA.Point, GA.Point, number, number] => {
|
|
|
|
const point = GAPoint.from(pointTuple);
|
|
|
|
const elementCoords = getElementAbsoluteCoords(element);
|
|
|
|
const center = coordsCenter(elementCoords);
|
|
|
|
// GA has angle orientation opposite to `rotate`
|
|
|
|
const rotate = GATransform.rotation(center, element.angle);
|
|
|
|
const pointRotated = GATransform.apply(rotate, point);
|
|
|
|
const pointRelToCenter = GA.sub(pointRotated, GADirection.from(center));
|
|
|
|
const pointRelToCenterAbs = GAPoint.abs(pointRelToCenter);
|
|
|
|
const elementPos = GA.offset(element.x, element.y);
|
|
|
|
const pointRelToPos = GA.sub(pointRotated, elementPos);
|
|
|
|
const [ax, ay, bx, by] = elementCoords;
|
|
|
|
const halfWidth = (bx - ax) / 2;
|
|
|
|
const halfHeight = (by - ay) / 2;
|
|
|
|
return [pointRelToPos, pointRelToCenterAbs, halfWidth, halfHeight];
|
|
|
|
};
|
2020-04-09 01:46:47 -07:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
// Returns point in absolute coordinates
|
|
|
|
export const pointInAbsoluteCoords = (
|
|
|
|
element: ExcalidrawElement,
|
|
|
|
// Point relative to the element position
|
|
|
|
point: Point,
|
|
|
|
): Point => {
|
|
|
|
const [x, y] = point;
|
|
|
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element);
|
|
|
|
const cx = (x2 - x1) / 2;
|
|
|
|
const cy = (y2 - y1) / 2;
|
|
|
|
const [rotatedX, rotatedY] = rotate(x, y, cx, cy, element.angle);
|
|
|
|
return [element.x + rotatedX, element.y + rotatedY];
|
|
|
|
};
|
|
|
|
|
|
|
|
const relativizationToElementCenter = (
|
|
|
|
element: ExcalidrawElement,
|
|
|
|
): GA.Transform => {
|
|
|
|
const elementCoords = getElementAbsoluteCoords(element);
|
|
|
|
const center = coordsCenter(elementCoords);
|
|
|
|
// GA has angle orientation opposite to `rotate`
|
|
|
|
const rotate = GATransform.rotation(center, element.angle);
|
|
|
|
const translate = GA.reverse(
|
|
|
|
GATransform.translation(GADirection.from(center)),
|
|
|
|
);
|
|
|
|
return GATransform.compose(rotate, translate);
|
|
|
|
};
|
|
|
|
|
|
|
|
const coordsCenter = ([ax, ay, bx, by]: Bounds): GA.Point => {
|
|
|
|
return GA.point((ax + bx) / 2, (ay + by) / 2);
|
|
|
|
};
|
|
|
|
|
|
|
|
// The focus distance is the oriented ratio between the size of
|
|
|
|
// the `element` and the "focus image" of the element on which
|
|
|
|
// all focus points lie, so it's a number between -1 and 1.
|
|
|
|
// The line going through `a` and `b` is a tangent to the "focus image"
|
|
|
|
// of the element.
|
|
|
|
export const determineFocusDistance = (
|
|
|
|
element: ExcalidrawBindableElement,
|
|
|
|
// Point on the line, in absolute coordinates
|
|
|
|
a: Point,
|
|
|
|
// Another point on the line, in absolute coordinates (closer to element)
|
|
|
|
b: Point,
|
|
|
|
): number => {
|
|
|
|
const relateToCenter = relativizationToElementCenter(element);
|
|
|
|
const aRel = GATransform.apply(relateToCenter, GAPoint.from(a));
|
|
|
|
const bRel = GATransform.apply(relateToCenter, GAPoint.from(b));
|
|
|
|
const line = GALine.through(aRel, bRel);
|
|
|
|
const q = element.height / element.width;
|
|
|
|
const hwidth = element.width / 2;
|
|
|
|
const hheight = element.height / 2;
|
|
|
|
const n = line[2];
|
|
|
|
const m = line[3];
|
|
|
|
const c = line[1];
|
|
|
|
const mabs = Math.abs(m);
|
|
|
|
const nabs = Math.abs(n);
|
|
|
|
switch (element.type) {
|
|
|
|
case "rectangle":
|
2021-10-21 22:05:48 +02:00
|
|
|
case "image":
|
2020-08-08 21:04:15 -07:00
|
|
|
case "text":
|
|
|
|
return c / (hwidth * (nabs + q * mabs));
|
|
|
|
case "diamond":
|
|
|
|
return mabs < nabs ? c / (nabs * hwidth) : c / (mabs * hheight);
|
|
|
|
case "ellipse":
|
|
|
|
return c / (hwidth * Math.sqrt(n ** 2 + q ** 2 * m ** 2));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const determineFocusPoint = (
|
|
|
|
element: ExcalidrawBindableElement,
|
|
|
|
// The oriented, relative distance from the center of `element` of the
|
|
|
|
// returned focusPoint
|
|
|
|
focus: number,
|
|
|
|
adjecentPoint: Point,
|
|
|
|
): Point => {
|
|
|
|
if (focus === 0) {
|
|
|
|
const elementCoords = getElementAbsoluteCoords(element);
|
|
|
|
const center = coordsCenter(elementCoords);
|
|
|
|
return GAPoint.toTuple(center);
|
|
|
|
}
|
|
|
|
const relateToCenter = relativizationToElementCenter(element);
|
|
|
|
const adjecentPointRel = GATransform.apply(
|
|
|
|
relateToCenter,
|
|
|
|
GAPoint.from(adjecentPoint),
|
|
|
|
);
|
|
|
|
const reverseRelateToCenter = GA.reverse(relateToCenter);
|
|
|
|
let point;
|
|
|
|
switch (element.type) {
|
|
|
|
case "rectangle":
|
2021-10-21 22:05:48 +02:00
|
|
|
case "image":
|
2020-08-08 21:04:15 -07:00
|
|
|
case "text":
|
|
|
|
case "diamond":
|
|
|
|
point = findFocusPointForRectangulars(element, focus, adjecentPointRel);
|
|
|
|
break;
|
|
|
|
case "ellipse":
|
|
|
|
point = findFocusPointForEllipse(element, focus, adjecentPointRel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return GAPoint.toTuple(GATransform.apply(reverseRelateToCenter, point));
|
|
|
|
};
|
|
|
|
|
|
|
|
// Returns 2 or 0 intersection points between line going through `a` and `b`
|
|
|
|
// and the `element`, in ascending order of distance from `a`.
|
|
|
|
export const intersectElementWithLine = (
|
|
|
|
element: ExcalidrawBindableElement,
|
|
|
|
// Point on the line, in absolute coordinates
|
|
|
|
a: Point,
|
|
|
|
// Another point on the line, in absolute coordinates
|
|
|
|
b: Point,
|
|
|
|
// If given, the element is inflated by this value
|
|
|
|
gap: number = 0,
|
|
|
|
): Point[] => {
|
|
|
|
const relateToCenter = relativizationToElementCenter(element);
|
|
|
|
const aRel = GATransform.apply(relateToCenter, GAPoint.from(a));
|
|
|
|
const bRel = GATransform.apply(relateToCenter, GAPoint.from(b));
|
|
|
|
const line = GALine.through(aRel, bRel);
|
|
|
|
const reverseRelateToCenter = GA.reverse(relateToCenter);
|
|
|
|
const intersections = getSortedElementLineIntersections(
|
|
|
|
element,
|
|
|
|
line,
|
|
|
|
aRel,
|
|
|
|
gap,
|
|
|
|
);
|
|
|
|
return intersections.map((point) =>
|
|
|
|
GAPoint.toTuple(GATransform.apply(reverseRelateToCenter, point)),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const getSortedElementLineIntersections = (
|
|
|
|
element: ExcalidrawBindableElement,
|
|
|
|
// Relative to element center
|
|
|
|
line: GA.Line,
|
|
|
|
// Relative to element center
|
|
|
|
nearPoint: GA.Point,
|
|
|
|
gap: number = 0,
|
|
|
|
): GA.Point[] => {
|
|
|
|
let intersections: GA.Point[];
|
|
|
|
switch (element.type) {
|
|
|
|
case "rectangle":
|
2021-10-21 22:05:48 +02:00
|
|
|
case "image":
|
2020-08-08 21:04:15 -07:00
|
|
|
case "text":
|
|
|
|
case "diamond":
|
|
|
|
const corners = getCorners(element);
|
|
|
|
intersections = corners
|
|
|
|
.flatMap((point, i) => {
|
|
|
|
const edge: [GA.Point, GA.Point] = [point, corners[(i + 1) % 4]];
|
|
|
|
return intersectSegment(line, offsetSegment(edge, gap));
|
|
|
|
})
|
|
|
|
.concat(
|
|
|
|
corners.flatMap((point) => getCircleIntersections(point, gap, line)),
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "ellipse":
|
|
|
|
intersections = getEllipseIntersections(element, gap, line);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (intersections.length < 2) {
|
|
|
|
// Ignore the "edge" case of only intersecting with a single corner
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
const sortedIntersections = intersections.sort(
|
|
|
|
(i1, i2) =>
|
|
|
|
GAPoint.distance(i1, nearPoint) - GAPoint.distance(i2, nearPoint),
|
|
|
|
);
|
|
|
|
return [
|
|
|
|
sortedIntersections[0],
|
|
|
|
sortedIntersections[sortedIntersections.length - 1],
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
const getCorners = (
|
|
|
|
element:
|
|
|
|
| ExcalidrawRectangleElement
|
2021-10-21 22:05:48 +02:00
|
|
|
| ExcalidrawImageElement
|
2020-08-08 21:04:15 -07:00
|
|
|
| ExcalidrawDiamondElement
|
|
|
|
| ExcalidrawTextElement,
|
|
|
|
scale: number = 1,
|
|
|
|
): GA.Point[] => {
|
|
|
|
const hx = (scale * element.width) / 2;
|
|
|
|
const hy = (scale * element.height) / 2;
|
|
|
|
switch (element.type) {
|
|
|
|
case "rectangle":
|
2021-10-21 22:05:48 +02:00
|
|
|
case "image":
|
2020-08-08 21:04:15 -07:00
|
|
|
case "text":
|
|
|
|
return [
|
|
|
|
GA.point(hx, hy),
|
|
|
|
GA.point(hx, -hy),
|
|
|
|
GA.point(-hx, -hy),
|
|
|
|
GA.point(-hx, hy),
|
|
|
|
];
|
|
|
|
case "diamond":
|
|
|
|
return [
|
|
|
|
GA.point(0, hy),
|
|
|
|
GA.point(hx, 0),
|
|
|
|
GA.point(0, -hy),
|
|
|
|
GA.point(-hx, 0),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Returns intersection of `line` with `segment`, with `segment` moved by
|
|
|
|
// `gap` in its polar direction.
|
|
|
|
// If intersection conincides with second segment point returns empty array.
|
|
|
|
const intersectSegment = (
|
|
|
|
line: GA.Line,
|
|
|
|
segment: [GA.Point, GA.Point],
|
|
|
|
): GA.Point[] => {
|
|
|
|
const [a, b] = segment;
|
|
|
|
const aDist = GAPoint.distanceToLine(a, line);
|
|
|
|
const bDist = GAPoint.distanceToLine(b, line);
|
|
|
|
if (aDist * bDist >= 0) {
|
|
|
|
// The intersection is outside segment `(a, b)`
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return [GAPoint.intersect(line, GALine.through(a, b))];
|
|
|
|
};
|
|
|
|
|
|
|
|
const offsetSegment = (
|
|
|
|
segment: [GA.Point, GA.Point],
|
|
|
|
distance: number,
|
|
|
|
): [GA.Point, GA.Point] => {
|
|
|
|
const [a, b] = segment;
|
|
|
|
const offset = GATransform.translationOrthogonal(
|
|
|
|
GADirection.fromTo(a, b),
|
|
|
|
distance,
|
|
|
|
);
|
|
|
|
return [GATransform.apply(offset, a), GATransform.apply(offset, b)];
|
|
|
|
};
|
|
|
|
|
|
|
|
const getEllipseIntersections = (
|
|
|
|
element: ExcalidrawEllipseElement,
|
|
|
|
gap: number,
|
|
|
|
line: GA.Line,
|
|
|
|
): GA.Point[] => {
|
|
|
|
const a = element.width / 2 + gap;
|
|
|
|
const b = element.height / 2 + gap;
|
|
|
|
const m = line[2];
|
|
|
|
const n = line[3];
|
|
|
|
const c = line[1];
|
|
|
|
const squares = a * a * m * m + b * b * n * n;
|
|
|
|
const discr = squares - c * c;
|
|
|
|
if (squares === 0 || discr <= 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
const discrRoot = Math.sqrt(discr);
|
|
|
|
const xn = -a * a * m * c;
|
|
|
|
const yn = -b * b * n * c;
|
|
|
|
return [
|
|
|
|
GA.point(
|
|
|
|
(xn + a * b * n * discrRoot) / squares,
|
|
|
|
(yn - a * b * m * discrRoot) / squares,
|
|
|
|
),
|
|
|
|
GA.point(
|
|
|
|
(xn - a * b * n * discrRoot) / squares,
|
|
|
|
(yn + a * b * m * discrRoot) / squares,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getCircleIntersections = (
|
|
|
|
center: GA.Point,
|
|
|
|
radius: number,
|
|
|
|
line: GA.Line,
|
|
|
|
): GA.Point[] => {
|
|
|
|
if (radius === 0) {
|
|
|
|
return GAPoint.distanceToLine(line, center) === 0 ? [center] : [];
|
|
|
|
}
|
|
|
|
const m = line[2];
|
|
|
|
const n = line[3];
|
|
|
|
const c = line[1];
|
|
|
|
const [a, b] = GAPoint.toTuple(center);
|
|
|
|
const r = radius;
|
|
|
|
const squares = m * m + n * n;
|
|
|
|
const discr = r * r * squares - (m * a + n * b + c) ** 2;
|
|
|
|
if (squares === 0 || discr <= 0) {
|
|
|
|
return [];
|
2020-01-06 19:34:22 +04:00
|
|
|
}
|
2020-08-08 21:04:15 -07:00
|
|
|
const discrRoot = Math.sqrt(discr);
|
|
|
|
const xn = a * n * n - b * m * n - m * c;
|
|
|
|
const yn = b * m * m - a * m * n - n * c;
|
|
|
|
|
|
|
|
return [
|
|
|
|
GA.point((xn + n * discrRoot) / squares, (yn - m * discrRoot) / squares),
|
|
|
|
GA.point((xn - n * discrRoot) / squares, (yn + m * discrRoot) / squares),
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
// The focus point is the tangent point of the "focus image" of the
|
|
|
|
// `element`, where the tangent goes through `point`.
|
|
|
|
export const findFocusPointForEllipse = (
|
|
|
|
ellipse: ExcalidrawEllipseElement,
|
|
|
|
// Between -1 and 1 (not 0) the relative size of the "focus image" of
|
|
|
|
// the element on which the focus point lies
|
|
|
|
relativeDistance: number,
|
|
|
|
// The point for which we're trying to find the focus point, relative
|
|
|
|
// to the ellipse center.
|
|
|
|
point: GA.Point,
|
|
|
|
): GA.Point => {
|
|
|
|
const relativeDistanceAbs = Math.abs(relativeDistance);
|
|
|
|
const a = (ellipse.width * relativeDistanceAbs) / 2;
|
|
|
|
const b = (ellipse.height * relativeDistanceAbs) / 2;
|
|
|
|
|
|
|
|
const orientation = Math.sign(relativeDistance);
|
|
|
|
const [px, pyo] = GAPoint.toTuple(point);
|
|
|
|
|
|
|
|
// The calculation below can't handle py = 0
|
|
|
|
const py = pyo === 0 ? 0.0001 : pyo;
|
|
|
|
|
|
|
|
const squares = px ** 2 * b ** 2 + py ** 2 * a ** 2;
|
|
|
|
// Tangent mx + ny + 1 = 0
|
|
|
|
const m =
|
|
|
|
(-px * b ** 2 +
|
|
|
|
orientation * py * Math.sqrt(Math.max(0, squares - a ** 2 * b ** 2))) /
|
|
|
|
squares;
|
|
|
|
|
|
|
|
const n = (-m * px - 1) / py;
|
|
|
|
|
|
|
|
const x = -(a ** 2 * m) / (n ** 2 * b ** 2 + m ** 2 * a ** 2);
|
|
|
|
return GA.point(x, (-m * x - 1) / n);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const findFocusPointForRectangulars = (
|
|
|
|
element:
|
|
|
|
| ExcalidrawRectangleElement
|
2021-10-21 22:05:48 +02:00
|
|
|
| ExcalidrawImageElement
|
2020-08-08 21:04:15 -07:00
|
|
|
| ExcalidrawDiamondElement
|
|
|
|
| ExcalidrawTextElement,
|
|
|
|
// Between -1 and 1 for how far away should the focus point be relative
|
|
|
|
// to the size of the element. Sign determines orientation.
|
|
|
|
relativeDistance: number,
|
|
|
|
// The point for which we're trying to find the focus point, relative
|
|
|
|
// to the element center.
|
|
|
|
point: GA.Point,
|
|
|
|
): GA.Point => {
|
|
|
|
const relativeDistanceAbs = Math.abs(relativeDistance);
|
|
|
|
const orientation = Math.sign(relativeDistance);
|
|
|
|
const corners = getCorners(element, relativeDistanceAbs);
|
|
|
|
|
|
|
|
let maxDistance = 0;
|
|
|
|
let tangentPoint: null | GA.Point = null;
|
|
|
|
corners.forEach((corner) => {
|
|
|
|
const distance = orientation * GALine.through(point, corner)[1];
|
|
|
|
if (distance > maxDistance) {
|
|
|
|
maxDistance = distance;
|
|
|
|
tangentPoint = corner;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return tangentPoint!;
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|
2020-02-01 15:49:18 +04:00
|
|
|
|
|
|
|
const pointInBezierEquation = (
|
|
|
|
p0: Point,
|
|
|
|
p1: Point,
|
|
|
|
p2: Point,
|
|
|
|
p3: Point,
|
|
|
|
[mx, my]: Point,
|
2020-03-15 13:42:18 -07:00
|
|
|
lineThreshold: number,
|
2020-02-01 15:49:18 +04:00
|
|
|
) => {
|
|
|
|
// B(t) = p0 * (1-t)^3 + 3p1 * t * (1-t)^2 + 3p2 * t^2 * (1-t) + p3 * t^3
|
|
|
|
const equation = (t: number, idx: number) =>
|
|
|
|
Math.pow(1 - t, 3) * p3[idx] +
|
|
|
|
3 * t * Math.pow(1 - t, 2) * p2[idx] +
|
|
|
|
3 * Math.pow(t, 2) * (1 - t) * p1[idx] +
|
|
|
|
p0[idx] * Math.pow(t, 3);
|
|
|
|
|
|
|
|
// go through t in increments of 0.01
|
|
|
|
let t = 0;
|
|
|
|
while (t <= 1.0) {
|
|
|
|
const tx = equation(t, 0);
|
|
|
|
const ty = equation(t, 1);
|
|
|
|
|
|
|
|
const diff = Math.sqrt(Math.pow(tx - mx, 2) + Math.pow(ty - my, 2));
|
|
|
|
|
2020-03-15 13:42:18 -07:00
|
|
|
if (diff < lineThreshold) {
|
2020-02-01 15:49:18 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
t += 0.01;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2020-08-15 00:59:43 +09:00
|
|
|
const hitTestCurveInside = (
|
|
|
|
drawable: Drawable,
|
|
|
|
x: number,
|
|
|
|
y: number,
|
|
|
|
sharpness: ExcalidrawElement["strokeSharpness"],
|
|
|
|
) => {
|
2020-04-09 01:46:47 -07:00
|
|
|
const ops = getCurvePathOps(drawable);
|
|
|
|
const points: Point[] = [];
|
2020-08-15 00:59:43 +09:00
|
|
|
let odd = false; // select one line out of double lines
|
2020-04-09 01:46:47 -07:00
|
|
|
for (const operation of ops) {
|
|
|
|
if (operation.op === "move") {
|
2020-08-15 00:59:43 +09:00
|
|
|
odd = !odd;
|
|
|
|
if (odd) {
|
|
|
|
points.push([operation.data[0], operation.data[1]]);
|
2020-04-09 01:46:47 -07:00
|
|
|
}
|
|
|
|
} else if (operation.op === "bcurveTo") {
|
2020-08-15 00:59:43 +09:00
|
|
|
if (odd) {
|
|
|
|
points.push([operation.data[0], operation.data[1]]);
|
|
|
|
points.push([operation.data[2], operation.data[3]]);
|
|
|
|
points.push([operation.data[4], operation.data[5]]);
|
|
|
|
}
|
2020-04-09 01:46:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (points.length >= 4) {
|
2020-08-15 00:59:43 +09:00
|
|
|
if (sharpness === "sharp") {
|
|
|
|
return isPointInPolygon(points, x, y);
|
|
|
|
}
|
2020-04-20 10:43:06 -07:00
|
|
|
const polygonPoints = pointsOnBezierCurves(points as any, 10, 5);
|
2020-04-09 01:46:47 -07:00
|
|
|
return isPointInPolygon(polygonPoints, x, y);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2020-03-15 13:42:18 -07:00
|
|
|
const hitTestRoughShape = (
|
2020-04-09 01:46:47 -07:00
|
|
|
drawable: Drawable,
|
2020-03-15 13:42:18 -07:00
|
|
|
x: number,
|
|
|
|
y: number,
|
|
|
|
lineThreshold: number,
|
|
|
|
) => {
|
2020-02-01 15:49:18 +04:00
|
|
|
// read operations from first opSet
|
2020-04-09 01:46:47 -07:00
|
|
|
const ops = getCurvePathOps(drawable);
|
2020-02-01 15:49:18 +04:00
|
|
|
|
|
|
|
// set start position as (0,0) just in case
|
|
|
|
// move operation does not exist (unlikely but it is worth safekeeping it)
|
|
|
|
let currentP: Point = [0, 0];
|
|
|
|
|
|
|
|
return ops.some(({ op, data }, idx) => {
|
|
|
|
// There are only four operation types:
|
|
|
|
// move, bcurveTo, lineTo, and curveTo
|
|
|
|
if (op === "move") {
|
|
|
|
// change starting point
|
2021-11-01 15:24:05 +02:00
|
|
|
currentP = data as unknown as Point;
|
2020-02-01 15:49:18 +04:00
|
|
|
// move operation does not draw anything; so, it always
|
|
|
|
// returns false
|
|
|
|
} else if (op === "bcurveTo") {
|
|
|
|
// create points from bezier curve
|
|
|
|
// bezier curve stores data as a flattened array of three positions
|
|
|
|
// [x1, y1, x2, y2, x3, y3]
|
|
|
|
const p1 = [data[0], data[1]] as Point;
|
|
|
|
const p2 = [data[2], data[3]] as Point;
|
|
|
|
const p3 = [data[4], data[5]] as Point;
|
|
|
|
|
|
|
|
const p0 = currentP;
|
|
|
|
currentP = p3;
|
|
|
|
|
|
|
|
// check if points are on the curve
|
|
|
|
// cubic bezier curves require four parameters
|
|
|
|
// the first parameter is the last stored position (p0)
|
2020-03-15 13:42:18 -07:00
|
|
|
const retVal = pointInBezierEquation(
|
|
|
|
p0,
|
|
|
|
p1,
|
|
|
|
p2,
|
|
|
|
p3,
|
|
|
|
[x, y],
|
|
|
|
lineThreshold,
|
|
|
|
);
|
2020-02-01 15:49:18 +04:00
|
|
|
|
|
|
|
// set end point of bezier curve as the new starting point for
|
|
|
|
// upcoming operations as each operation is based on the last drawn
|
|
|
|
// position of the previous operation
|
|
|
|
return retVal;
|
|
|
|
} else if (op === "lineTo") {
|
|
|
|
// TODO: Implement this
|
|
|
|
} else if (op === "qcurveTo") {
|
|
|
|
// TODO: Implement this
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
};
|