From 4650869988fe3592a0b2937d8b7155c0a351fdff Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Thu, 15 Jun 2023 13:42:18 +0100 Subject: [PATCH] remove `ShapeUtil.transform` (#1590) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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` --- packages/editor/api-report.md | 1 - packages/editor/src/lib/editor/Editor.ts | 3 +-- .../editor/src/lib/editor/shapes/ShapeUtil.ts | 17 +---------------- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/packages/editor/api-report.md b/packages/editor/api-report.md index 23438c534..5c2c1c8fe 100644 --- a/packages/editor/api-report.md +++ b/packages/editor/api-report.md @@ -1902,7 +1902,6 @@ export abstract class ShapeUtil { snapPoints(shape: T): Vec2d[]; toBackgroundSvg?(shape: T, font: string | undefined, colors: TLExportColors): null | Promise | SVGElement; toSvg?(shape: T, font: string | undefined, colors: TLExportColors): Promise | SVGElement; - transform(shape: T): Matrix2d; // (undocumented) readonly type: T['type']; static type: string; diff --git a/packages/editor/src/lib/editor/Editor.ts b/packages/editor/src/lib/editor/Editor.ts index 6a94eeaf5..1c6aa0765 100644 --- a/packages/editor/src/lib/editor/Editor.ts +++ b/packages/editor/src/lib/editor/Editor.ts @@ -1998,8 +1998,7 @@ export class Editor extends EventEmitter { * @public */ getTransform(shape: TLShape) { - const util = this.getShapeUtil(shape) - return util.transform(shape) + return Matrix2d.Compose(Matrix2d.Translate(shape.x, shape.y), Matrix2d.Rotate(shape.rotation)) } /** diff --git a/packages/editor/src/lib/editor/shapes/ShapeUtil.ts b/packages/editor/src/lib/editor/shapes/ShapeUtil.ts index 500df6e19..9bb7922f8 100644 --- a/packages/editor/src/lib/editor/shapes/ShapeUtil.ts +++ b/packages/editor/src/lib/editor/shapes/ShapeUtil.ts @@ -1,15 +1,12 @@ /* 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 { TLHandle, TLShape, TLShapePartial, TLUnknownShape, Vec2dModel } from '@tldraw/tlschema' import { computed, EMPTY_ARRAY } from 'signia' -import { WeakMapCache } from '../../utils/WeakMapCache' import type { Editor } from '../Editor' import { TLResizeHandle } from '../types/selection-types' import { TLExportColors } from './shared/TLExportColors' -const transforms = new WeakMapCache() - /** @public */ export interface TLShapeUtilConstructor< T extends TLUnknownShape, @@ -221,18 +218,6 @@ export abstract class ShapeUtil { return result } - /** - * Get the cached transform. Do not override this method! - * - * @param shape - The shape. - * @public - */ - transform(shape: T): Matrix2d { - return transforms.get(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! *