feat: preserve vertices on roughness < 2

This commit is contained in:
dwelle 2023-06-07 18:36:31 +02:00
parent 84bd9bd4ff
commit 776e5a1cc8
2 changed files with 10 additions and 2 deletions

View File

@ -263,6 +263,12 @@ export const ROUNDNESS = {
* collaboration */ * collaboration */
export const PRECEDING_ELEMENT_KEY = "__precedingElement__"; export const PRECEDING_ELEMENT_KEY = "__precedingElement__";
export const ROUGHNESS = {
architect: 0,
artist: 1,
cartoonist: 2,
} as const;
export const DEFAULT_ELEMENT_PROPS: { export const DEFAULT_ELEMENT_PROPS: {
strokeColor: ExcalidrawElement["strokeColor"]; strokeColor: ExcalidrawElement["strokeColor"];
backgroundColor: ExcalidrawElement["backgroundColor"]; backgroundColor: ExcalidrawElement["backgroundColor"];
@ -278,7 +284,7 @@ export const DEFAULT_ELEMENT_PROPS: {
fillStyle: "hachure", fillStyle: "hachure",
strokeWidth: 1, strokeWidth: 1,
strokeStyle: "solid", strokeStyle: "solid",
roughness: 1, roughness: ROUGHNESS.artist,
opacity: 100, opacity: 100,
locked: false, locked: false,
}; };

View File

@ -36,6 +36,7 @@ import {
BOUND_TEXT_PADDING, BOUND_TEXT_PADDING,
MAX_DECIMALS_FOR_SVG_EXPORT, MAX_DECIMALS_FOR_SVG_EXPORT,
MIME_TYPES, MIME_TYPES,
ROUGHNESS,
SVG_NS, SVG_NS,
} from "../constants"; } from "../constants";
import { getStroke, StrokeOptions } from "perfect-freehand"; import { getStroke, StrokeOptions } from "perfect-freehand";
@ -416,7 +417,8 @@ export const generateRoughOptions = (
hachureGap: element.strokeWidth * 4, hachureGap: element.strokeWidth * 4,
roughness: element.roughness, roughness: element.roughness,
stroke: element.strokeColor, stroke: element.strokeColor,
preserveVertices: continuousPath, preserveVertices:
continuousPath || element.roughness < ROUGHNESS.cartoonist,
}; };
switch (element.type) { switch (element.type) {