mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Multi Point Lines (based on Multi Point Arrows) (#660)
* Enable multi points in lines * Stop retrieving arrow points for lines * Migrate lines to new spec during load * Clean up and refactor some code - Normalize shape dimensions during load - Rename getArrowAbsoluteBounds * Fix linter issues
This commit is contained in:
parent
f70bd0081c
commit
dab35c9033
9 changed files with 102 additions and 178 deletions
|
@ -5,17 +5,15 @@ import { Point } from "roughjs/bin/geometry";
|
|||
|
||||
// If the element is created from right to left, the width is going to be negative
|
||||
// This set of functions retrieves the absolute position of the 4 points.
|
||||
// We can't just always normalize it since we need to remember the fact that an arrow
|
||||
// is pointing left or right.
|
||||
export function getElementAbsoluteCoords(element: ExcalidrawElement) {
|
||||
if (element.type === "arrow") {
|
||||
return getArrowAbsoluteBounds(element);
|
||||
if (element.type === "arrow" || element.type === "line") {
|
||||
return getLinearElementAbsoluteBounds(element);
|
||||
}
|
||||
return [
|
||||
element.width >= 0 ? element.x : element.x + element.width, // x1
|
||||
element.height >= 0 ? element.y : element.y + element.height, // y1
|
||||
element.width >= 0 ? element.x + element.width : element.x, // x2
|
||||
element.height >= 0 ? element.y + element.height : element.y, // y2
|
||||
element.x,
|
||||
element.y,
|
||||
element.x + element.width,
|
||||
element.y + element.height,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -34,7 +32,7 @@ export function getDiamondPoints(element: ExcalidrawElement) {
|
|||
return [topX, topY, rightX, rightY, bottomX, bottomY, leftX, leftY];
|
||||
}
|
||||
|
||||
export function getArrowAbsoluteBounds(element: ExcalidrawElement) {
|
||||
export function getLinearElementAbsoluteBounds(element: ExcalidrawElement) {
|
||||
if (element.points.length < 2 || !element.shape) {
|
||||
const { minX, minY, maxX, maxY } = element.points.reduce(
|
||||
(limits, [x, y]) => {
|
||||
|
@ -58,7 +56,8 @@ export function getArrowAbsoluteBounds(element: ExcalidrawElement) {
|
|||
|
||||
const shape = element.shape as Drawable[];
|
||||
|
||||
const ops = shape[1].sets[0].ops;
|
||||
// first element is always the curve
|
||||
const ops = shape[0].sets[0].ops;
|
||||
|
||||
let currentP: Point = [0, 0];
|
||||
|
||||
|
@ -138,15 +137,6 @@ export function getArrowPoints(element: ExcalidrawElement) {
|
|||
return [x2, y2, x3, y3, x4, y4];
|
||||
}
|
||||
|
||||
export function getLinePoints(element: ExcalidrawElement) {
|
||||
const x1 = 0;
|
||||
const y1 = 0;
|
||||
const x2 = element.width;
|
||||
const y2 = element.height;
|
||||
|
||||
return [x1, y1, x2, y2];
|
||||
}
|
||||
|
||||
export function getCommonBounds(elements: readonly ExcalidrawElement[]) {
|
||||
let minX = Infinity;
|
||||
let maxX = -Infinity;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue