mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: sharpness (#1931)
* feat: sharpness * feat: fill sharp lines, et al. * fix: rotated positioning * chore: simplify path with Q * fix: hit test inside sharp elements * make sharp / round buttons work properly * fix tsc tests * update snapshots * update snapshots * fix: sharp arrow creation error * fix merge and test * avoid type assertion * remove duplicate helper Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
930813387b
commit
41cb1fbeba
26 changed files with 841 additions and 42 deletions
|
@ -165,6 +165,9 @@ export const getArrowPoints = (
|
|||
shape: Drawable[],
|
||||
) => {
|
||||
const ops = getCurvePathOps(shape[0]);
|
||||
if (ops.length < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const data = ops[ops.length - 1].data;
|
||||
const p3 = [data[4], data[5]] as Point;
|
||||
|
@ -339,10 +342,13 @@ export const getResizedElementAbsoluteCoords = (
|
|||
);
|
||||
|
||||
const gen = rough.generator();
|
||||
const curve = gen.curve(
|
||||
points as [number, number][],
|
||||
generateRoughOptions(element),
|
||||
);
|
||||
const curve =
|
||||
element.strokeSharpness === "sharp"
|
||||
? gen.linearPath(
|
||||
points as [number, number][],
|
||||
generateRoughOptions(element),
|
||||
)
|
||||
: gen.curve(points as [number, number][], generateRoughOptions(element));
|
||||
const ops = getCurvePathOps(curve);
|
||||
const [minX, minY, maxX, maxY] = getMinMaxXYFromCurvePathOps(ops);
|
||||
return [
|
||||
|
@ -356,13 +362,17 @@ export const getResizedElementAbsoluteCoords = (
|
|||
export const getElementPointsCoords = (
|
||||
element: ExcalidrawLinearElement,
|
||||
points: readonly (readonly [number, number])[],
|
||||
sharpness: ExcalidrawElement["strokeSharpness"],
|
||||
): [number, number, number, number] => {
|
||||
// This might be computationally heavey
|
||||
const gen = rough.generator();
|
||||
const curve = gen.curve(
|
||||
points as [number, number][],
|
||||
generateRoughOptions(element),
|
||||
);
|
||||
const curve =
|
||||
sharpness === "sharp"
|
||||
? gen.linearPath(
|
||||
points as [number, number][],
|
||||
generateRoughOptions(element),
|
||||
)
|
||||
: gen.curve(points as [number, number][], generateRoughOptions(element));
|
||||
const ops = getCurvePathOps(curve);
|
||||
const [minX, minY, maxX, maxY] = getMinMaxXYFromCurvePathOps(ops);
|
||||
return [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue