ensure that fixed points stay fixed (#1523)
This PR fixes points on resize as well as on create. This should help with file size for large resizes. ### Change Type - [x] `patch` — Bug Fix ### Test Plan - [ ] Unit Tests
This commit is contained in:
parent
a4fff303bf
commit
3be19ad53e
6 changed files with 19 additions and 7 deletions
|
@ -6,6 +6,7 @@ import {
|
|||
linesIntersect,
|
||||
pointInPolygon,
|
||||
setStrokePointRadii,
|
||||
toFixed,
|
||||
Vec2d,
|
||||
VecLike,
|
||||
} from '@tldraw/primitives'
|
||||
|
@ -279,8 +280,8 @@ export class DrawShapeUtil extends ShapeUtil<TLDrawShape> {
|
|||
...segment,
|
||||
points: segment.points.map(({ x, y, z }) => {
|
||||
return {
|
||||
x: scaleX * x,
|
||||
y: scaleY * y,
|
||||
x: toFixed(scaleX * x),
|
||||
y: toFixed(scaleY * y),
|
||||
z,
|
||||
}
|
||||
}),
|
||||
|
|
|
@ -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: [
|
||||
|
|
|
@ -23,8 +23,8 @@ Object {
|
|||
"z": 0.5,
|
||||
},
|
||||
Object {
|
||||
"x": 110.00000000000001,
|
||||
"y": 110.00000000000001,
|
||||
"x": 110,
|
||||
"y": 110,
|
||||
"z": 0.5,
|
||||
},
|
||||
],
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -92,5 +92,6 @@ export {
|
|||
simplify2,
|
||||
snapAngle,
|
||||
toDomPrecision,
|
||||
toFixed,
|
||||
toPrecision,
|
||||
} from './lib/utils'
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue