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
pull/1531/head
Steve Ruiz 2023-06-05 19:04:13 +01:00 zatwierdzone przez GitHub
rodzic a4fff303bf
commit 3be19ad53e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 19 dodań i 7 usunięć

Wyświetl plik

@ -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,
}
}),

Wyświetl plik

@ -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: [

Wyświetl plik

@ -23,8 +23,8 @@ Object {
"z": 0.5,
},
Object {
"x": 110.00000000000001,
"y": 110.00000000000001,
"x": 110,
"y": 110,
"z": 0.5,
},
],

Wyświetl plik

@ -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;

Wyświetl plik

@ -92,5 +92,6 @@ export {
simplify2,
snapAngle,
toDomPrecision,
toFixed,
toPrecision,
} from './lib/utils'

Wyświetl plik

@ -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)
}