remove ShapeUtil.transform (#1590)

Removes the cached (but not really needed) local transform for shapes.
We almost never get the local transform except when getting the page
transform.

### Change Type

- [x] `major` — Breaking change


### Release Notes

- [editor] Remove `ShapeUtil.transform`
This commit is contained in:
Steve Ruiz 2023-06-15 13:42:18 +01:00 committed by GitHub
parent 519d0dd348
commit 4650869988
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 19 deletions

View file

@ -1902,7 +1902,6 @@ export abstract class ShapeUtil<T extends TLUnknownShape = TLUnknownShape> {
snapPoints(shape: T): Vec2d[]; snapPoints(shape: T): Vec2d[];
toBackgroundSvg?(shape: T, font: string | undefined, colors: TLExportColors): null | Promise<SVGElement> | SVGElement; toBackgroundSvg?(shape: T, font: string | undefined, colors: TLExportColors): null | Promise<SVGElement> | SVGElement;
toSvg?(shape: T, font: string | undefined, colors: TLExportColors): Promise<SVGElement> | SVGElement; toSvg?(shape: T, font: string | undefined, colors: TLExportColors): Promise<SVGElement> | SVGElement;
transform(shape: T): Matrix2d;
// (undocumented) // (undocumented)
readonly type: T['type']; readonly type: T['type'];
static type: string; static type: string;

View file

@ -1998,8 +1998,7 @@ export class Editor extends EventEmitter<TLEventMap> {
* @public * @public
*/ */
getTransform(shape: TLShape) { getTransform(shape: TLShape) {
const util = this.getShapeUtil(shape) return Matrix2d.Compose(Matrix2d.Translate(shape.x, shape.y), Matrix2d.Rotate(shape.rotation))
return util.transform(shape)
} }
/** /**

View file

@ -1,15 +1,12 @@
/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-unused-vars */
import { Box2d, linesIntersect, Matrix2d, VecLike } from '@tldraw/primitives' import { Box2d, linesIntersect, VecLike } from '@tldraw/primitives'
import { ComputedCache } from '@tldraw/store' import { ComputedCache } from '@tldraw/store'
import { TLHandle, TLShape, TLShapePartial, TLUnknownShape, Vec2dModel } from '@tldraw/tlschema' import { TLHandle, TLShape, TLShapePartial, TLUnknownShape, Vec2dModel } from '@tldraw/tlschema'
import { computed, EMPTY_ARRAY } from 'signia' import { computed, EMPTY_ARRAY } from 'signia'
import { WeakMapCache } from '../../utils/WeakMapCache'
import type { Editor } from '../Editor' import type { Editor } from '../Editor'
import { TLResizeHandle } from '../types/selection-types' import { TLResizeHandle } from '../types/selection-types'
import { TLExportColors } from './shared/TLExportColors' import { TLExportColors } from './shared/TLExportColors'
const transforms = new WeakMapCache<TLShape, Matrix2d>()
/** @public */ /** @public */
export interface TLShapeUtilConstructor< export interface TLShapeUtilConstructor<
T extends TLUnknownShape, T extends TLUnknownShape,
@ -221,18 +218,6 @@ export abstract class ShapeUtil<T extends TLUnknownShape = TLUnknownShape> {
return result return result
} }
/**
* Get the cached transform. Do not override this method!
*
* @param shape - The shape.
* @public
*/
transform(shape: T): Matrix2d {
return transforms.get<T>(shape, (shape) =>
Matrix2d.Compose(Matrix2d.Translate(shape.x, shape.y), Matrix2d.Rotate(shape.rotation))
)
}
/** /**
* Get the shape's (not cached) outline. Do not override this method! * Get the shape's (not cached) outline. Do not override this method!
* *