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

@ -7,6 +7,7 @@ import { done } from "../components/icons";
import { t } from "../i18n";
import { register } from "./register";
import { mutateElement } from "../element/mutateElement";
import { isPathALoop } from "../math";
export const actionFinalize = register({
name: "finalize",
@ -32,6 +33,23 @@ export const actionFinalize = register({
newElements = newElements.slice(0, -1);
}
// If the multi point line closes the loop,
// set the last point to first point.
// This ensures that loop remains closed at different scales.
if (appState.multiElement.type === "line") {
if (isPathALoop(appState.multiElement.points)) {
const linePoints = appState.multiElement.points;
const firstPoint = linePoints[0];
mutateElement(appState.multiElement, {
points: linePoints.map((point, i) =>
i === linePoints.length - 1
? ([firstPoint[0], firstPoint[1]] as const)
: point,
),
});
}
}
if (!appState.elementLocked) {
appState.selectedElementIds[appState.multiElement.id] = true;
}