diff --git a/packages/editor/src/lib/app/shapeutils/DrawShapeUtil/DrawShapeUtil.tsx b/packages/editor/src/lib/app/shapeutils/DrawShapeUtil/DrawShapeUtil.tsx index be0acbcab..b876f7a89 100644 --- a/packages/editor/src/lib/app/shapeutils/DrawShapeUtil/DrawShapeUtil.tsx +++ b/packages/editor/src/lib/app/shapeutils/DrawShapeUtil/DrawShapeUtil.tsx @@ -6,6 +6,7 @@ import { linesIntersect, pointInPolygon, setStrokePointRadii, + toFixed, Vec2d, VecLike, } from '@tldraw/primitives' @@ -279,8 +280,8 @@ export class DrawShapeUtil extends ShapeUtil { ...segment, points: segment.points.map(({ x, y, z }) => { return { - x: scaleX * x, - y: scaleY * y, + x: toFixed(scaleX * x), + y: toFixed(scaleY * y), z, } }), diff --git a/packages/editor/src/lib/app/tools/DrawShapeTool/children/Drawing.ts b/packages/editor/src/lib/app/tools/DrawShapeTool/children/Drawing.ts index acd9cbc92..5656a6640 100644 --- a/packages/editor/src/lib/app/tools/DrawShapeTool/children/Drawing.ts +++ b/packages/editor/src/lib/app/tools/DrawShapeTool/children/Drawing.ts @@ -1,4 +1,4 @@ -import { Matrix2d, snapAngle, Vec2d } from '@tldraw/primitives' +import { Matrix2d, snapAngle, toFixed, Vec2d } from '@tldraw/primitives' import { createShapeId, TLDrawShape, @@ -607,8 +607,8 @@ export class Drawing extends StateNode { { id: newShapeId, type: this.shapeType, - x: currentPagePoint.x, - y: currentPagePoint.y, + x: toFixed(currentPagePoint.x), + y: toFixed(currentPagePoint.y), props: { isPen: this.isPen, segments: [ diff --git a/packages/editor/src/lib/test/tools/__snapshots__/resizing.test.ts.snap b/packages/editor/src/lib/test/tools/__snapshots__/resizing.test.ts.snap index 5cf806c3a..fdfc17492 100644 --- a/packages/editor/src/lib/test/tools/__snapshots__/resizing.test.ts.snap +++ b/packages/editor/src/lib/test/tools/__snapshots__/resizing.test.ts.snap @@ -23,8 +23,8 @@ Object { "z": 0.5, }, Object { - "x": 110.00000000000001, - "y": 110.00000000000001, + "x": 110, + "y": 110, "z": 0.5, }, ], diff --git a/packages/primitives/api-report.md b/packages/primitives/api-report.md index 78aabaaf7..4a31f2a1c 100644 --- a/packages/primitives/api-report.md +++ b/packages/primitives/api-report.md @@ -631,6 +631,9 @@ export const TAU: number; // @public export function toDomPrecision(v: number): number; +// @public (undocumented) +export function toFixed(v: number): number; + // @public export function toPrecision(n: number, precision?: number): number; diff --git a/packages/primitives/src/index.ts b/packages/primitives/src/index.ts index 33198a342..615303cf8 100644 --- a/packages/primitives/src/index.ts +++ b/packages/primitives/src/index.ts @@ -92,5 +92,6 @@ export { simplify2, snapAngle, toDomPrecision, + toFixed, toPrecision, } from './lib/utils' diff --git a/packages/primitives/src/lib/utils.ts b/packages/primitives/src/lib/utils.ts index 598bb3c3d..9bcd2f875 100644 --- a/packages/primitives/src/lib/utils.ts +++ b/packages/primitives/src/lib/utils.ts @@ -667,3 +667,10 @@ export function getHeight(pts: VecLike[]) { export function toDomPrecision(v: number) { return +v.toFixed(4) } + +/** + * @public + */ +export function toFixed(v: number) { + return +v.toFixed(2) +}