From 776e5a1cc8d595cb8aaa6b25e308090c8ee3af4c Mon Sep 17 00:00:00 2001 From: dwelle Date: Wed, 7 Jun 2023 18:36:31 +0200 Subject: [PATCH] feat: preserve vertices on roughness < 2 --- src/constants.ts | 8 +++++++- src/renderer/renderElement.ts | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index cb63a4d48..85da84981 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -263,6 +263,12 @@ export const ROUNDNESS = { * collaboration */ export const PRECEDING_ELEMENT_KEY = "__precedingElement__"; +export const ROUGHNESS = { + architect: 0, + artist: 1, + cartoonist: 2, +} as const; + export const DEFAULT_ELEMENT_PROPS: { strokeColor: ExcalidrawElement["strokeColor"]; backgroundColor: ExcalidrawElement["backgroundColor"]; @@ -278,7 +284,7 @@ export const DEFAULT_ELEMENT_PROPS: { fillStyle: "hachure", strokeWidth: 1, strokeStyle: "solid", - roughness: 1, + roughness: ROUGHNESS.artist, opacity: 100, locked: false, }; diff --git a/src/renderer/renderElement.ts b/src/renderer/renderElement.ts index 77ea14587..215e281c6 100644 --- a/src/renderer/renderElement.ts +++ b/src/renderer/renderElement.ts @@ -36,6 +36,7 @@ import { BOUND_TEXT_PADDING, MAX_DECIMALS_FOR_SVG_EXPORT, MIME_TYPES, + ROUGHNESS, SVG_NS, } from "../constants"; import { getStroke, StrokeOptions } from "perfect-freehand"; @@ -416,7 +417,8 @@ export const generateRoughOptions = ( hachureGap: element.strokeWidth * 4, roughness: element.roughness, stroke: element.strokeColor, - preserveVertices: continuousPath, + preserveVertices: + continuousPath || element.roughness < ROUGHNESS.cartoonist, }; switch (element.type) {