Fill a looped curve with the selected background color (#1315)

This commit is contained in:
Preet 2020-04-09 01:46:47 -07:00 committed by GitHub
parent fe6f482e96
commit 57bbc9fe55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 240 additions and 32 deletions

View file

@ -1,6 +1,6 @@
import { ExcalidrawElement, ExcalidrawLinearElement } from "./types";
import { rotate } from "../math";
import { Drawable } from "roughjs/bin/core";
import { Drawable, Op } from "roughjs/bin/core";
import { Point } from "../types";
import { getShapeForElement } from "../renderer/renderElement";
import { isLinearElement } from "./typeChecks";
@ -36,6 +36,15 @@ export function getDiamondPoints(element: ExcalidrawElement) {
return [topX, topY, rightX, rightY, bottomX, bottomY, leftX, leftY];
}
export function getCurvePathOps(shape: Drawable): Op[] {
for (const set of shape.sets) {
if (set.type === "path") {
return set.ops;
}
}
return shape.sets[0].ops;
}
export function getLinearElementAbsoluteBounds(
element: ExcalidrawLinearElement,
): [number, number, number, number] {
@ -63,7 +72,7 @@ export function getLinearElementAbsoluteBounds(
const shape = getShapeForElement(element) as Drawable[];
// first element is always the curve
const ops = shape[0].sets[0].ops;
const ops = getCurvePathOps(shape[0]);
let currentP: Point = [0, 0];
@ -128,7 +137,7 @@ export function getArrowPoints(
element: ExcalidrawLinearElement,
shape: Drawable[],
) {
const ops = shape[0].sets[0].ops;
const ops = getCurvePathOps(shape[0]);
const data = ops[ops.length - 1].data;
const p3 = [data[4], data[5]] as Point;