From 6b1005ef71a63613a09606310f666487547d5f23 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Wed, 3 Jan 2024 12:13:15 +0000 Subject: [PATCH] [tech debt] Primitives renaming party / cleanup (#2396) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR: - renames Vec2d to Vec - renames Vec2dModel to VecModel - renames Box2d to Box - renames Box2dModel to BoxModel - renames Matrix2d to Mat - renames Matrix2dModel to MatModel - removes unused primitive helpers - removes unused exports - removes a few redundant tests in dgreensp ### Change Type - [x] `major` — Breaking change ### Release Notes - renames Vec2d to Vec - renames Vec2dModel to VecModel - renames Box2d to Box - renames Box2dModel to BoxModel - renames Matrix2d to Mat - renames Matrix2dModel to MatModel - removes unused primitive helpers --- apps/examples/e2e/tests/test-text.spec.ts | 28 +- .../examples/floaty-window/FloatyExample.tsx | 4 +- .../ScreenshotTool/childStates/Dragging.ts | 6 +- .../screenshot-tool/ScreenshotToolExample.tsx | 8 +- .../SpeechBubble/SpeechBubbleUtil.tsx | 14 +- .../speech-bubble/SpeechBubble/helpers.tsx | 54 +- .../things-on-the-canvas/OnTheCanvas.tsx | 4 +- packages/editor/api-report.md | 671 +-- packages/editor/api/api.json | 4494 +++++++++-------- packages/editor/src/index.ts | 53 +- packages/editor/src/lib/components/Canvas.tsx | 12 +- packages/editor/src/lib/components/Shape.tsx | 4 +- .../src/lib/components/ShapeIndicator.tsx | 2 +- .../default-components/DefaultBrush.tsx | 4 +- .../DefaultCollaboratorHint.tsx | 12 +- .../default-components/DefaultCursor.tsx | 4 +- .../DefaultSelectionBackground.tsx | 4 +- .../DefaultSelectionForeground.tsx | 4 +- .../src/lib/config/TLSessionStateSnapshot.ts | 2 +- packages/editor/src/lib/editor/Editor.ts | 260 +- .../editor/derivations/arrowBindingsIndex.ts | 2 +- .../src/lib/editor/managers/ClickManager.ts | 10 +- .../lib/editor/managers/ScribbleManager.ts | 10 +- .../src/lib/editor/managers/SnapManager.ts | 114 +- .../src/lib/editor/managers/TextManager.ts | 8 +- .../src/lib/editor/managers/TickManager.ts | 8 +- .../editor/managers/getRecordManager.test.ts | 25 - .../lib/editor/managers/getRecordManager.ts | 28 - .../editor/src/lib/editor/shapes/ShapeUtil.ts | 10 +- .../editor/shapes/group/DashedOutlineBox.tsx | 4 +- .../editor/shapes/shared/arrow/arrow-types.ts | 2 +- .../shapes/shared/arrow/curved-arrow.ts | 168 +- .../lib/editor/shapes/shared/arrow/shared.ts | 24 +- .../shapes/shared/arrow/straight-arrow.ts | 69 +- .../src/lib/editor/shapes/shared/resizeBox.ts | 12 +- .../lib/editor/shapes/shared/resizeScaled.ts | 42 - .../BaseBoxShapeTool/children/Pointing.ts | 4 +- .../src/lib/editor/types/event-types.ts | 12 +- .../src/lib/editor/types/external-content.ts | 2 +- .../editor/src/lib/editor/types/misc-types.ts | 4 +- .../src/lib/editor/types/selection-types.ts | 2 +- .../editor/src/lib/hooks/useGestureEvents.ts | 10 +- packages/editor/src/lib/hooks/useTransform.ts | 2 +- .../editor/src/lib/primitives/Box.test.ts | 24 + .../src/lib/primitives/{Box2d.ts => Box.ts} | 124 +- .../editor/src/lib/primitives/Box2d.test.ts | 24 - .../editor/src/lib/primitives/Mat.test.ts | 46 + .../lib/primitives/{Matrix2d.ts => Mat.ts} | 119 +- .../src/lib/primitives/Matrix2d.test.ts | 46 - .../editor/src/lib/primitives/Vec.test.ts | 373 ++ .../src/lib/primitives/{Vec2d.ts => Vec.ts} | 208 +- .../editor/src/lib/primitives/Vec2d.test.ts | 379 -- .../src/lib/primitives/geometry/Arc2d.ts | 30 +- .../lib/primitives/geometry/Circle2d.test.ts | 42 +- .../src/lib/primitives/geometry/Circle2d.ts | 22 +- .../lib/primitives/geometry/CubicBezier2d.ts | 28 +- .../lib/primitives/geometry/CubicSpline2d.ts | 20 +- .../src/lib/primitives/geometry/Edge2d.ts | 24 +- .../src/lib/primitives/geometry/Ellipse2d.ts | 14 +- .../src/lib/primitives/geometry/Geometry2d.ts | 38 +- .../src/lib/primitives/geometry/Group2d.ts | 18 +- .../src/lib/primitives/geometry/Point2d.ts | 12 +- .../src/lib/primitives/geometry/Polygon2d.ts | 4 +- .../src/lib/primitives/geometry/Polyline2d.ts | 12 +- .../lib/primitives/geometry/Rectangle2d.ts | 14 +- .../src/lib/primitives/geometry/Stadium2d.ts | 18 +- .../primitives/geometry/geometry-constants.ts | 4 +- .../editor/src/lib/primitives/intersect.ts | 20 +- packages/editor/src/lib/primitives/utils.ts | 426 +- packages/editor/src/lib/utils/debug-flags.ts | 3 +- .../editor/src/lib/utils/edgeScrolling.ts | 2 +- .../src/lib/utils/getSvgPathFromPoints.ts | 2 +- .../reordering/dgreensp/dgreensp.test.ts | 84 +- .../lib/utils/reordering/dgreensp/dgreensp.ts | 44 +- .../lib/utils/reordering/dgreensp/index.ts | 2 - .../src/lib/utils/reordering/reordering.ts | 2 +- packages/editor/src/lib/utils/rotation.ts | 16 +- packages/tldraw/api-report.md | 24 +- packages/tldraw/api/api.json | 31 +- .../lib/canvas/TldrawSelectionForeground.tsx | 4 +- .../src/lib/defaultExternalContentHandlers.ts | 8 +- .../lib/shapes/arrow/ArrowShapeTool.test.ts | 14 +- .../lib/shapes/arrow/ArrowShapeUtil.test.ts | 4 +- .../src/lib/shapes/arrow/ArrowShapeUtil.tsx | 54 +- .../src/lib/shapes}/arrow/arrowheads.ts | 73 +- .../tldraw/src/lib/shapes/arrow/arrowpaths.ts | 49 + .../src/lib/shapes/draw/DrawShapeUtil.tsx | 4 +- .../tldraw/src/lib/shapes/draw/getPath.ts | 10 +- .../src/lib/shapes/draw/toolStates/Drawing.ts | 57 +- .../src/lib/shapes/geo/GeoShapeUtil.tsx | 125 +- .../tldraw/src/lib/shapes/geo/cloudOutline.ts | 96 +- .../shapes/geo/components/DashStyleCloud.tsx | 14 +- .../geo/components/DashStylePolygon.tsx | 10 +- .../geo/components/DrawStyleEllipse.tsx | 10 +- .../geo/components/DrawStylePolygon.tsx | 28 +- .../src/lib/shapes/geo/toolStates/Pointing.ts | 9 +- .../src/lib/shapes/image/ImageShapeUtil.tsx | 12 +- .../src/lib/shapes/line/LineShapeUtil.tsx | 4 +- .../src/lib/shapes/line/components/svg.ts | 4 +- .../lib/shapes/line/toolStates/Pointing.ts | 14 +- .../src/lib/shapes/shared/TextLabel.tsx | 4 +- .../shared/createTextSvgElementFromSpans.ts | 8 +- .../lib/shapes/shared/freehand/getStroke.ts | 4 +- .../shared/freehand/getStrokeOutlinePoints.ts | 82 +- .../shapes/shared/freehand/getStrokePoints.ts | 26 +- .../src/lib/shapes/shared/freehand/svgInk.ts | 28 +- .../src/lib/shapes/shared/freehand/types.ts | 8 +- .../shapes/shared/getTextLabelSvgElement.ts | 4 +- .../src/lib/shapes/shared/legacyProps.ts | 6 +- .../src/lib/shapes/shared/polygon-helpers.ts | 34 +- .../tldraw/src/lib/shapes/shared/resizeBox.ts | 15 +- .../src/lib/shapes/shared/resizeScaled.ts | 10 +- .../lib/shapes/shared/rotated-box-shadow.ts | 4 +- .../src/lib/shapes/text/TextShapeUtil.tsx | 12 +- .../tools/HandTool/childStates/Dragging.ts | 4 +- .../tools/SelectTool/DragAndDropManager.ts | 4 +- .../tools/SelectTool/childStates/Brushing.ts | 24 +- .../childStates/Crop/children/Idle.ts | 6 +- .../childStates/Crop/children/crop_helpers.ts | 4 +- .../tools/SelectTool/childStates/Cropping.ts | 10 +- .../SelectTool/childStates/DraggingHandle.ts | 14 +- .../lib/tools/SelectTool/childStates/Idle.ts | 8 +- .../tools/SelectTool/childStates/Resizing.ts | 26 +- .../tools/SelectTool/childStates/Rotating.ts | 9 +- .../childStates/ScribbleBrushing.ts | 4 +- .../SelectTool/childStates/Translating.ts | 34 +- .../SelectTool/children/DraggingHandle.ts | 14 +- .../ZoomTool/childStates/ZoomBrushing.ts | 6 +- .../ui/components/NavigationZone/Minimap.tsx | 20 +- .../NavigationZone/MinimapManager.ts | 26 +- .../hooks/clipboard/pasteExcalidrawContent.ts | 28 +- .../tldraw/src/lib/ui/hooks/useActions.tsx | 26 +- .../tldraw/src/lib/utils/frames/frames.ts | 14 +- .../src/lib/utils/tldr/buildFromV1Document.ts | 8 +- packages/tldraw/src/test/TestEditor.ts | 36 +- .../test/__snapshots__/groups.test.ts.snap | 10 +- .../tldraw/src/test/arrows-megabus.test.ts | 4 +- .../src/test/commands/alignShapes.test.tsx | 24 +- packages/tldraw/src/test/commands/pan.test.ts | 6 +- .../tldraw/src/test/commands/penmode.test.ts | 4 +- .../src/test/commands/zoomToBounds.test.ts | 10 +- packages/tldraw/src/test/flipShapes.test.ts | 6 +- packages/tldraw/src/test/groups.test.ts | 18 +- packages/tldraw/src/test/resizeBox.test.ts | 10 +- packages/tldraw/src/test/resizing.test.ts | 36 +- packages/tldraw/src/test/rotating.test.ts | 48 +- packages/tldraw/src/test/roundedBox.ts | 6 +- .../tldraw/src/test/testutils/roundedBox.ts | 6 +- packages/tldraw/src/test/translating.test.ts | 14 +- packages/tlschema/api-report.md | 32 +- packages/tlschema/api/api.json | 94 +- packages/tlschema/src/index.ts | 8 +- packages/tlschema/src/misc/TLScribble.ts | 6 +- packages/tlschema/src/misc/geometry-types.ts | 8 +- packages/tlschema/src/records/TLInstance.ts | 14 +- packages/tlschema/src/records/TLPresence.ts | 10 +- packages/tlschema/src/shapes/TLArrowShape.ts | 4 +- packages/tlschema/src/shapes/TLDrawShape.ts | 4 +- packages/tlschema/src/shapes/TLImageShape.ts | 6 +- 159 files changed, 4757 insertions(+), 5319 deletions(-) delete mode 100644 packages/editor/src/lib/editor/managers/getRecordManager.test.ts delete mode 100644 packages/editor/src/lib/editor/managers/getRecordManager.ts delete mode 100644 packages/editor/src/lib/editor/shapes/shared/resizeScaled.ts create mode 100644 packages/editor/src/lib/primitives/Box.test.ts rename packages/editor/src/lib/primitives/{Box2d.ts => Box.ts} (82%) delete mode 100644 packages/editor/src/lib/primitives/Box2d.test.ts create mode 100644 packages/editor/src/lib/primitives/Mat.test.ts rename packages/editor/src/lib/primitives/{Matrix2d.ts => Mat.ts} (62%) delete mode 100644 packages/editor/src/lib/primitives/Matrix2d.test.ts create mode 100644 packages/editor/src/lib/primitives/Vec.test.ts rename packages/editor/src/lib/primitives/{Vec2d.ts => Vec.ts} (59%) delete mode 100644 packages/editor/src/lib/primitives/Vec2d.test.ts delete mode 100644 packages/editor/src/lib/utils/reordering/dgreensp/index.ts rename packages/{editor/src/lib/editor/shapes/shared => tldraw/src/lib/shapes}/arrow/arrowheads.ts (50%) create mode 100644 packages/tldraw/src/lib/shapes/arrow/arrowpaths.ts diff --git a/apps/examples/e2e/tests/test-text.spec.ts b/apps/examples/e2e/tests/test-text.spec.ts index 1b19449f4..8d51f98ca 100644 --- a/apps/examples/e2e/tests/test-text.spec.ts +++ b/apps/examples/e2e/tests/test-text.spec.ts @@ -1,5 +1,5 @@ import test, { Page, expect } from '@playwright/test' -import { Box2dModel, Editor } from '@tldraw/tldraw' +import { BoxModel, Editor } from '@tldraw/tldraw' import { setupPage } from '../shared-e2e' export function sleep(ms: number) { @@ -29,7 +29,7 @@ const measureTextSpansOptions = { textAlign: 'start' as 'start' | 'middle' | 'end', } -function formatLines(spans: { box: Box2dModel; text: string }[]) { +function formatLines(spans: { box: BoxModel; text: string }[]) { const lines = [] let currentLine: string[] | null = null @@ -85,7 +85,7 @@ test.describe('text measurement', () => { test('should get a single text span', async () => { const spans = await page.evaluate< - { text: string; box: Box2dModel }[], + { text: string; box: BoxModel }[], typeof measureTextSpansOptions >( async (options) => editor.textMeasure.measureTextSpans('testing', options), @@ -97,7 +97,7 @@ test.describe('text measurement', () => { test('should wrap a word when it has to', async () => { const spans = await page.evaluate< - { text: string; box: Box2dModel }[], + { text: string; box: BoxModel }[], typeof measureTextSpansOptions >( async (options) => editor.textMeasure.measureTextSpans('testing', { ...options, width: 50 }), @@ -109,7 +109,7 @@ test.describe('text measurement', () => { test('should preserve whitespace at line breaks', async () => { const spans = await page.evaluate< - { text: string; box: Box2dModel }[], + { text: string; box: BoxModel }[], typeof measureTextSpansOptions >( async (options) => editor.textMeasure.measureTextSpans('testing testing', options), @@ -121,7 +121,7 @@ test.describe('text measurement', () => { test('should preserve whitespace at the end of wrapped lines', async () => { const spans = await page.evaluate< - { text: string; box: Box2dModel }[], + { text: string; box: BoxModel }[], typeof measureTextSpansOptions >( async (options) => editor.textMeasure.measureTextSpans('testing testing ', options), @@ -136,7 +136,7 @@ test.describe('text measurement', () => { test('preserves whitespace at the end of unwrapped lines', async () => { const spans = await page.evaluate< - { text: string; box: Box2dModel }[], + { text: string; box: BoxModel }[], typeof measureTextSpansOptions >( async (options) => @@ -149,7 +149,7 @@ test.describe('text measurement', () => { test('preserves whitespace at the start of an unwrapped line', async () => { const spans = await page.evaluate< - { text: string; box: Box2dModel }[], + { text: string; box: BoxModel }[], typeof measureTextSpansOptions >( async (options) => @@ -162,7 +162,7 @@ test.describe('text measurement', () => { test('should place starting whitespace on its own line if it has to', async () => { const spans = await page.evaluate< - { text: string; box: Box2dModel }[], + { text: string; box: BoxModel }[], typeof measureTextSpansOptions >( async (options) => editor.textMeasure.measureTextSpans(' testing testing', options), @@ -174,7 +174,7 @@ test.describe('text measurement', () => { test('should handle multiline text', async () => { const spans = await page.evaluate< - { text: string; box: Box2dModel }[], + { text: string; box: BoxModel }[], typeof measureTextSpansOptions >( async (options) => @@ -192,7 +192,7 @@ test.describe('text measurement', () => { test('should break long strings of text', async () => { const spans = await page.evaluate< - { text: string; box: Box2dModel }[], + { text: string; box: BoxModel }[], typeof measureTextSpansOptions >( async (options) => @@ -212,7 +212,7 @@ test.describe('text measurement', () => { test('should return an empty array if the text is empty', async () => { const spans = await page.evaluate< - { text: string; box: Box2dModel }[], + { text: string; box: BoxModel }[], typeof measureTextSpansOptions >(async (options) => editor.textMeasure.measureTextSpans('', options), measureTextSpansOptions) @@ -221,7 +221,7 @@ test.describe('text measurement', () => { test('should handle trailing newlines', async () => { const spans = await page.evaluate< - { text: string; box: Box2dModel }[], + { text: string; box: BoxModel }[], typeof measureTextSpansOptions >( async (options) => editor.textMeasure.measureTextSpans('hi\n\n\n', options), @@ -233,7 +233,7 @@ test.describe('text measurement', () => { test('should handle only newlines', async () => { const spans = await page.evaluate< - { text: string; box: Box2dModel }[], + { text: string; box: BoxModel }[], typeof measureTextSpansOptions >( async (options) => editor.textMeasure.measureTextSpans('\n\n\n', options), diff --git a/apps/examples/src/examples/floaty-window/FloatyExample.tsx b/apps/examples/src/examples/floaty-window/FloatyExample.tsx index 9789662ba..c461126c0 100644 --- a/apps/examples/src/examples/floaty-window/FloatyExample.tsx +++ b/apps/examples/src/examples/floaty-window/FloatyExample.tsx @@ -1,4 +1,4 @@ -import { Tldraw, Vec2d, useContainer, useEditor } from '@tldraw/tldraw' +import { Tldraw, Vec, useContainer, useEditor } from '@tldraw/tldraw' import '@tldraw/tldraw/tldraw.css' import { useEffect } from 'react' @@ -32,7 +32,7 @@ function SneakyFloatyHook() { if (sx !== x || sy !== y) { x = sx y = sy - editor.setCamera(new Vec2d(-x, -y)) + editor.setCamera(new Vec(-x, -y)) } } diff --git a/apps/examples/src/examples/screenshot-tool/ScreenshotTool/childStates/Dragging.ts b/apps/examples/src/examples/screenshot-tool/ScreenshotTool/childStates/Dragging.ts index f00e91cc6..7841f9fec 100644 --- a/apps/examples/src/examples/screenshot-tool/ScreenshotTool/childStates/Dragging.ts +++ b/apps/examples/src/examples/screenshot-tool/ScreenshotTool/childStates/Dragging.ts @@ -1,4 +1,4 @@ -import { Box2d, StateNode, atom, copyAs, exportAs } from '@tldraw/tldraw' +import { Box, StateNode, atom, copyAs, exportAs } from '@tldraw/tldraw' // There's a guide at the bottom of this file! @@ -6,7 +6,7 @@ export class ScreenshotDragging extends StateNode { static override id = 'dragging' // [1] - screenshotBox = atom('screenshot brush', new Box2d()) + screenshotBox = atom('screenshot brush', new Box()) // [2] override onEnter = () => { @@ -30,7 +30,7 @@ export class ScreenshotDragging extends StateNode { inputs: { shiftKey, altKey, originPagePoint, currentPagePoint }, } = this.editor - const box = Box2d.FromPoints([originPagePoint, currentPagePoint]) + const box = Box.FromPoints([originPagePoint, currentPagePoint]) if (shiftKey) { if (box.w > box.h * (16 / 9)) { diff --git a/apps/examples/src/examples/screenshot-tool/ScreenshotToolExample.tsx b/apps/examples/src/examples/screenshot-tool/ScreenshotToolExample.tsx index 0c379fa88..e0cf1bfe2 100644 --- a/apps/examples/src/examples/screenshot-tool/ScreenshotToolExample.tsx +++ b/apps/examples/src/examples/screenshot-tool/ScreenshotToolExample.tsx @@ -1,10 +1,10 @@ import { - Box2d, + Box, TLEditorComponents, TLUiAssetUrlOverrides, TLUiOverrides, Tldraw, - Vec2d, + Vec, toolbarItem, useEditor, useValue, @@ -69,11 +69,11 @@ function ScreenshotBox() { // "page space", i.e. uneffected by scale, and relative to the tldraw // page's top left corner. const zoomLevel = editor.getZoomLevel() - const { x, y } = Vec2d.Sub( + const { x, y } = Vec.Sub( editor.pageToScreen({ x: box.x, y: box.y }), editor.getViewportScreenBounds() ) - return new Box2d(x, y, box.w * zoomLevel, box.h * zoomLevel) + return new Box(x, y, box.w * zoomLevel, box.h * zoomLevel) }, [editor] ) diff --git a/apps/examples/src/examples/speech-bubble/SpeechBubble/SpeechBubbleUtil.tsx b/apps/examples/src/examples/speech-bubble/SpeechBubble/SpeechBubbleUtil.tsx index 41dd55f00..de55a1392 100644 --- a/apps/examples/src/examples/speech-bubble/SpeechBubble/SpeechBubbleUtil.tsx +++ b/apps/examples/src/examples/speech-bubble/SpeechBubble/SpeechBubbleUtil.tsx @@ -12,7 +12,7 @@ import { TLOnBeforeUpdateHandler, TLOnHandleChangeHandler, TLOnResizeHandler, - Vec2d, + Vec, deepCopy, getDefaultColorTheme, resizeBox, @@ -128,21 +128,21 @@ export class SpeechBubbleUtil extends ShapeUtil { const MIN_DISTANCE = slantedLength / 5 const MAX_DISTANCE = slantedLength / 1.5 - const handleInShapeSpace = new Vec2d(handles.handle.x * w, handles.handle.y * h) + const handleInShapeSpace = new Vec(handles.handle.x * w, handles.handle.y * h) const distanceToIntersection = handleInShapeSpace.dist(segmentsIntersection) - const center = new Vec2d(w / 2, h / 2) - const vHandle = Vec2d.Sub(handleInShapeSpace, center).uni() + const center = new Vec(w / 2, h / 2) + const vHandle = Vec.Sub(handleInShapeSpace, center).uni() let newPoint = handleInShapeSpace if (insideShape) { - newPoint = Vec2d.Add(segmentsIntersection, vHandle.mul(MIN_DISTANCE)) + newPoint = Vec.Add(segmentsIntersection, vHandle.mul(MIN_DISTANCE)) } else { if (distanceToIntersection <= MIN_DISTANCE) { - newPoint = Vec2d.Add(segmentsIntersection, vHandle.mul(MIN_DISTANCE)) + newPoint = Vec.Add(segmentsIntersection, vHandle.mul(MIN_DISTANCE)) } else if (distanceToIntersection >= MAX_DISTANCE) { - newPoint = Vec2d.Add(segmentsIntersection, vHandle.mul(MAX_DISTANCE)) + newPoint = Vec.Add(segmentsIntersection, vHandle.mul(MAX_DISTANCE)) } } diff --git a/apps/examples/src/examples/speech-bubble/SpeechBubble/helpers.tsx b/apps/examples/src/examples/speech-bubble/SpeechBubble/helpers.tsx index 5aa3992d1..8bb3618ca 100644 --- a/apps/examples/src/examples/speech-bubble/SpeechBubble/helpers.tsx +++ b/apps/examples/src/examples/speech-bubble/SpeechBubble/helpers.tsx @@ -1,19 +1,19 @@ -import { Vec2d, VecLike, lerp, pointInPolygon } from '@tldraw/tldraw' +import { Vec, VecLike, lerp, pointInPolygon } from '@tldraw/tldraw' import { SpeechBubbleShape } from './SpeechBubbleUtil' -export const getSpeechBubbleVertices = (shape: SpeechBubbleShape): Vec2d[] => { +export const getSpeechBubbleVertices = (shape: SpeechBubbleShape): Vec[] => { const { w, h, handles } = shape.props - const handleInShapeSpace = new Vec2d(handles.handle.x * w, handles.handle.y * h) + const handleInShapeSpace = new Vec(handles.handle.x * w, handles.handle.y * h) - const [tl, tr, br, bl] = [new Vec2d(0, 0), new Vec2d(w, 0), new Vec2d(w, h), new Vec2d(0, h)] + const [tl, tr, br, bl] = [new Vec(0, 0), new Vec(w, 0), new Vec(w, h), new Vec(0, h)] const offsetH = w / 10 const offsetV = h / 10 const { adjustedIntersection, intersectionSegmentIndex } = getHandleIntersectionPoint(shape) - let vertices: Vec2d[] + let vertices: Vec[] // Inject the tail segments into the geometry of the shape switch (intersectionSegmentIndex) { @@ -21,9 +21,9 @@ export const getSpeechBubbleVertices = (shape: SpeechBubbleShape): Vec2d[] => { // top vertices = [ tl, - new Vec2d(adjustedIntersection.x - offsetH, adjustedIntersection.y), - new Vec2d(handleInShapeSpace.x, handleInShapeSpace.y), - new Vec2d(adjustedIntersection.x + offsetH, adjustedIntersection.y), + new Vec(adjustedIntersection.x - offsetH, adjustedIntersection.y), + new Vec(handleInShapeSpace.x, handleInShapeSpace.y), + new Vec(adjustedIntersection.x + offsetH, adjustedIntersection.y), tr, br, bl, @@ -34,9 +34,9 @@ export const getSpeechBubbleVertices = (shape: SpeechBubbleShape): Vec2d[] => { vertices = [ tl, tr, - new Vec2d(adjustedIntersection.x, adjustedIntersection.y - offsetV), - new Vec2d(handleInShapeSpace.x, handleInShapeSpace.y), - new Vec2d(adjustedIntersection.x, adjustedIntersection.y + offsetV), + new Vec(adjustedIntersection.x, adjustedIntersection.y - offsetV), + new Vec(handleInShapeSpace.x, handleInShapeSpace.y), + new Vec(adjustedIntersection.x, adjustedIntersection.y + offsetV), br, bl, ] @@ -47,9 +47,9 @@ export const getSpeechBubbleVertices = (shape: SpeechBubbleShape): Vec2d[] => { tl, tr, br, - new Vec2d(adjustedIntersection.x + offsetH, adjustedIntersection.y), - new Vec2d(handleInShapeSpace.x, handleInShapeSpace.y), - new Vec2d(adjustedIntersection.x - offsetH, adjustedIntersection.y), + new Vec(adjustedIntersection.x + offsetH, adjustedIntersection.y), + new Vec(handleInShapeSpace.x, handleInShapeSpace.y), + new Vec(adjustedIntersection.x - offsetH, adjustedIntersection.y), bl, ] break @@ -60,9 +60,9 @@ export const getSpeechBubbleVertices = (shape: SpeechBubbleShape): Vec2d[] => { tr, br, bl, - new Vec2d(adjustedIntersection.x, adjustedIntersection.y + offsetV), - new Vec2d(handleInShapeSpace.x, handleInShapeSpace.y), - new Vec2d(adjustedIntersection.x, adjustedIntersection.y - offsetV), + new Vec(adjustedIntersection.x, adjustedIntersection.y + offsetV), + new Vec(handleInShapeSpace.x, handleInShapeSpace.y), + new Vec(adjustedIntersection.x, adjustedIntersection.y - offsetV), ] break default: @@ -74,10 +74,10 @@ export const getSpeechBubbleVertices = (shape: SpeechBubbleShape): Vec2d[] => { export function getHandleIntersectionPoint(shape: SpeechBubbleShape) { const { w, h, handles } = shape.props - const handleInShapeSpace = new Vec2d(handles.handle.x * w, handles.handle.y * h) + const handleInShapeSpace = new Vec(handles.handle.x * w, handles.handle.y * h) - const center = new Vec2d(w / 2, h / 2) - const corners = [new Vec2d(0, 0), new Vec2d(w, 0), new Vec2d(w, h), new Vec2d(0, h)] + const center = new Vec(w / 2, h / 2) + const corners = [new Vec(0, 0), new Vec(w, 0), new Vec(w, h), new Vec(0, h)] const segments = [ [corners[0], corners[1]], [corners[1], corners[2]], @@ -85,8 +85,8 @@ export function getHandleIntersectionPoint(shape: SpeechBubbleShape) { [corners[3], corners[0]], ] - let segmentsIntersection: Vec2d | null = null - let intersectionSegment: Vec2d[] | null = null + let segmentsIntersection: Vec | null = null + let intersectionSegment: Vec[] | null = null // If the point inside of the box's corners? const insideShape = pointInPolygon(handleInShapeSpace, corners) @@ -94,7 +94,7 @@ export function getHandleIntersectionPoint(shape: SpeechBubbleShape) { // We want to be sure we get an intersection, so if the point is // inside the shape, push it away from the center by a big distance const pointToCheck = insideShape - ? Vec2d.Add(handleInShapeSpace, Vec2d.Sub(handleInShapeSpace, center).uni().mul(1000000)) + ? Vec.Add(handleInShapeSpace, Vec.Sub(handleInShapeSpace, center).uni().mul(1000000)) : handleInShapeSpace // Test each segment for an intersection @@ -120,11 +120,11 @@ export function getHandleIntersectionPoint(shape: SpeechBubbleShape) { const intersectionSegmentIndex = segments.indexOf(intersectionSegment) // a normalised vector from start to end, so this can work in any direction - const unit = Vec2d.Sub(end, start).uni() + const unit = Vec.Sub(end, start).uni() // Where is the intersection relative to the start? - const totalDistance = Vec2d.Dist(start, end) - const distance = Vec2d.Dist(segmentsIntersection, start) + const totalDistance = Vec.Dist(start, end) + const distance = Vec.Dist(segmentsIntersection, start) // make it stick to the middle const middleRelative = mapRange(0, totalDistance, -1, 1, distance) // absolute -> -1 to 1 @@ -170,7 +170,7 @@ function intersectLineSegmentLineSegment(a1: VecLike, a2: VecLike, b1: VecLike, const ua = ua_t / u_b const ub = ub_t / u_b if (0 <= ua && ua <= 1 && 0 <= ub && ub <= 1) { - return Vec2d.AddXY(a1, ua * AVx, ua * AVy) + return Vec.AddXY(a1, ua * AVx, ua * AVy) } } diff --git a/apps/examples/src/examples/things-on-the-canvas/OnTheCanvas.tsx b/apps/examples/src/examples/things-on-the-canvas/OnTheCanvas.tsx index c4dcd00bb..13602a10d 100644 --- a/apps/examples/src/examples/things-on-the-canvas/OnTheCanvas.tsx +++ b/apps/examples/src/examples/things-on-the-canvas/OnTheCanvas.tsx @@ -4,7 +4,7 @@ import { TLEditorComponents, track, useEditor, - Vec2d, + Vec, } from '@tldraw/tldraw' import '@tldraw/tldraw/tldraw.css' import { useState } from 'react' @@ -62,7 +62,7 @@ const MyComponentInFront = track(() => { if (!selectionRotatedPageBounds) return null - const pageCoordinates = Vec2d.Sub( + const pageCoordinates = Vec.Sub( editor.pageToScreen(selectionRotatedPageBounds.point), editor.getViewportScreenBounds() ) diff --git a/packages/editor/api-report.md b/packages/editor/api-report.md index 0a01dfb56..913ef6934 100644 --- a/packages/editor/api-report.md +++ b/packages/editor/api-report.md @@ -8,7 +8,7 @@ import { Atom } from '@tldraw/state'; import { atom } from '@tldraw/state'; -import { Box2dModel } from '@tldraw/tlschema'; +import { BoxModel } from '@tldraw/tlschema'; import { ComponentType } from 'react'; import { Computed } from '@tldraw/state'; import { computed } from '@tldraw/state'; @@ -71,12 +71,9 @@ import { useComputed } from '@tldraw/state'; import { useQuickReactor } from '@tldraw/state'; import { useReactor } from '@tldraw/state'; import { useValue } from '@tldraw/state'; -import { Vec2dModel } from '@tldraw/tlschema'; +import { VecModel } from '@tldraw/tlschema'; import { whyAmIRunning } from '@tldraw/state'; -// @public -export function angleDelta(a0: number, a1: number): number; - // @internal (undocumented) export const ANIMATION_MEDIUM_MS = 320; @@ -97,10 +94,10 @@ export function approximately(a: number, b: number, precision?: number): boolean // @public (undocumented) export class Arc2d extends Geometry2d { constructor(config: Omit & { - center: Vec2d; + center: Vec; radius: number; - start: Vec2d; - end: Vec2d; + start: Vec; + end: Vec; sweepFlag: number; largeArcFlag: number; }); @@ -109,23 +106,23 @@ export class Arc2d extends Geometry2d { // (undocumented) angleStart: number; // (undocumented) - _center: Vec2d; + _center: Vec; // (undocumented) - end: Vec2d; + end: Vec; // (undocumented) - getVertices(): Vec2d[]; + getVertices(): Vec[]; // (undocumented) - hitTestLineSegment(A: Vec2d, B: Vec2d, _zoom: number): boolean; + hitTestLineSegment(A: Vec, B: Vec, _zoom: number): boolean; // (undocumented) length: number; // (undocumented) measure: number; // (undocumented) - nearestPoint(point: Vec2d): Vec2d; + nearestPoint(point: Vec): Vec; // (undocumented) radius: number; // (undocumented) - start: Vec2d; + start: Vec; } // @public @@ -161,58 +158,58 @@ export abstract class BaseBoxShapeUtil extends Sha } // @public (undocumented) -export class Box2d { +export class Box { constructor(x?: number, y?: number, w?: number, h?: number); // (undocumented) get aspectRatio(): number; // (undocumented) - get center(): Vec2d; - set center(v: Vec2d); + get center(): Vec; + set center(v: Vec); // (undocumented) - clone(): Box2d; + clone(): Box; // (undocumented) - static Collides: (A: Box2d, B: Box2d) => boolean; + static Collides: (A: Box, B: Box) => boolean; // (undocumented) - collides(B: Box2d): boolean; + collides(B: Box): boolean; // (undocumented) - static Common: (boxes: Box2d[]) => Box2d; + static Common: (boxes: Box[]) => Box; // (undocumented) - static Contains: (A: Box2d, B: Box2d) => boolean; + static Contains: (A: Box, B: Box) => boolean; // (undocumented) - contains(B: Box2d): boolean; + contains(B: Box): boolean; // (undocumented) - static ContainsPoint: (A: Box2d, B: VecLike, margin?: number) => boolean; + static ContainsPoint: (A: Box, B: VecLike, margin?: number) => boolean; // (undocumented) containsPoint(V: VecLike, margin?: number): boolean; // (undocumented) - get corners(): Vec2d[]; + get corners(): Vec[]; // (undocumented) - static Equals(a: Box2d | Box2dModel, b: Box2d | Box2dModel): boolean; + static Equals(a: Box | BoxModel, b: Box | BoxModel): boolean; // (undocumented) - equals(other: Box2d | Box2dModel): boolean; + equals(other: Box | BoxModel): boolean; // (undocumented) - static Expand(A: Box2d, B: Box2d): Box2d; + static Expand(A: Box, B: Box): Box; // (undocumented) - expand(A: Box2d): this; + expand(A: Box): this; // (undocumented) - static ExpandBy(A: Box2d, n: number): Box2d; + static ExpandBy(A: Box, n: number): Box; // (undocumented) expandBy(n: number): this; // (undocumented) - static From(box: Box2dModel): Box2d; + static From(box: BoxModel): Box; // (undocumented) - static FromPoints(points: VecLike[]): Box2d; + static FromPoints(points: VecLike[]): Box; // (undocumented) - getHandlePoint(handle: SelectionCorner | SelectionEdge): Vec2d; + getHandlePoint(handle: SelectionCorner | SelectionEdge): Vec; // (undocumented) h: number; // (undocumented) get height(): number; set height(n: number); // (undocumented) - static Includes: (A: Box2d, B: Box2d) => boolean; + static Includes: (A: Box, B: Box) => boolean; // (undocumented) - includes(B: Box2d): boolean; + includes(B: Box): boolean; // (undocumented) get maxX(): number; // (undocumented) @@ -228,11 +225,11 @@ export class Box2d { get minY(): number; set minY(n: number); // (undocumented) - get point(): Vec2d; - set point(val: Vec2d); + get point(): Vec; + set point(val: Vec); // (undocumented) - static Resize(box: Box2d, handle: SelectionCorner | SelectionEdge | string, dx: number, dy: number, isAspectRatioLocked?: boolean): { - box: Box2d; + static Resize(box: Box, handle: SelectionCorner | SelectionEdge | string, dx: number, dy: number, isAspectRatioLocked?: boolean): { + box: Box; scaleX: number; scaleY: number; }; @@ -243,25 +240,25 @@ export class Box2d { // (undocumented) set(x?: number, y?: number, w?: number, h?: number): this; // (undocumented) - setTo(B: Box2d): this; + setTo(B: Box): this; // (undocumented) - static Sides: (A: Box2d, inset?: number) => Vec2d[][]; + static Sides: (A: Box, inset?: number) => Vec[][]; // (undocumented) - get sides(): Array<[Vec2d, Vec2d]>; + get sides(): Array<[Vec, Vec]>; // (undocumented) - get size(): Vec2d; + get size(): Vec; // (undocumented) - get snapPoints(): Vec2d[]; + get snapPoints(): Vec[]; // (undocumented) snapToGrid(size: number): void; // (undocumented) toFixed(): this; // (undocumented) - toJson(): Box2dModel; + toJson(): BoxModel; // (undocumented) translate(delta: VecLike): this; // (undocumented) - union(box: Box2dModel): this; + union(box: BoxModel): this; // (undocumented) w: number; // (undocumented) @@ -272,13 +269,13 @@ export class Box2d { // (undocumented) y: number; // (undocumented) - static ZeroFix(other: Box2d | Box2dModel): Box2d; + static ZeroFix(other: Box | BoxModel): Box; // (undocumented) zeroFix(): this; } // @public (undocumented) -export type BoxLike = Box2d | Box2dModel; +export type BoxLike = Box | BoxModel; // @internal (undocumented) export const CAMERA_SLIDE_FRICTION = 0.09; @@ -300,7 +297,7 @@ export class Circle2d extends Geometry2d { isFilled: boolean; }); // (undocumented) - _center: Vec2d; + _center: Vec; // (undocumented) config: Omit & { x?: number; @@ -309,13 +306,13 @@ export class Circle2d extends Geometry2d { isFilled: boolean; }; // (undocumented) - getBounds(): Box2d; + getBounds(): Box; // (undocumented) - getVertices(): Vec2d[]; + getVertices(): Vec[]; // (undocumented) - hitTestLineSegment(A: Vec2d, B: Vec2d, _zoom: number): boolean; + hitTestLineSegment(A: Vec, B: Vec, _zoom: number): boolean; // (undocumented) - nearestPoint(point: Vec2d): Vec2d; + nearestPoint(point: Vec): Vec; // (undocumented) radius: number; // (undocumented) @@ -357,44 +354,44 @@ export function createTLUser(opts?: { // @public (undocumented) export class CubicBezier2d extends Polyline2d { constructor(config: Omit & { - start: Vec2d; - cp1: Vec2d; - cp2: Vec2d; - end: Vec2d; + start: Vec; + cp1: Vec; + cp2: Vec; + end: Vec; }); // (undocumented) - a: Vec2d; + a: Vec; // (undocumented) - b: Vec2d; + b: Vec; // (undocumented) - c: Vec2d; + c: Vec; // (undocumented) - d: Vec2d; + d: Vec; // (undocumented) - getVertices(): Vec2d[]; + getVertices(): Vec[]; // (undocumented) - midPoint(): Vec2d; + midPoint(): Vec; // (undocumented) - nearestPoint(A: Vec2d): Vec2d; + nearestPoint(A: Vec): Vec; } // @public (undocumented) export class CubicSpline2d extends Geometry2d { constructor(config: Omit & { - points: Vec2d[]; + points: Vec[]; }); // (undocumented) - getVertices(): Vec2d[]; + getVertices(): Vec[]; // (undocumented) - hitTestLineSegment(A: Vec2d, B: Vec2d, zoom: number): boolean; + hitTestLineSegment(A: Vec, B: Vec, zoom: number): boolean; // (undocumented) get length(): number; // (undocumented) _length?: number; // (undocumented) - nearestPoint(A: Vec2d): Vec2d; + nearestPoint(A: Vec): Vec; // (undocumented) - points: Vec2d[]; + points: Vec[]; // (undocumented) get segments(): CubicBezier2d[]; // (undocumented) @@ -442,7 +439,7 @@ export const DefaultCollaboratorHint: TLCollaboratorHintComponent; // @public (undocumented) export const DefaultCursor: NamedExoticComponent< { className?: string | undefined; -point: null | Vec2dModel; +point: null | VecModel; zoom: number; color?: string | undefined; name: null | string; @@ -528,30 +525,30 @@ export const EASINGS: { // @public (undocumented) export class Edge2d extends Geometry2d { constructor(config: { - start: Vec2d; - end: Vec2d; + start: Vec; + end: Vec; isSnappable?: boolean; }); // (undocumented) - d: Vec2d; + d: Vec; // (undocumented) - end: Vec2d; + end: Vec; // (undocumented) - getVertices(): Vec2d[]; + getVertices(): Vec[]; // (undocumented) - hitTestLineSegment(A: Vec2d, B: Vec2d, _zoom: number): boolean; + hitTestLineSegment(A: Vec, B: Vec, _zoom: number): boolean; // (undocumented) get length(): number; // (undocumented) _length?: number; // (undocumented) - midPoint(): Vec2d; + midPoint(): Vec; // (undocumented) - nearestPoint(point: Vec2d): Vec2d; + nearestPoint(point: Vec): Vec; // (undocumented) - start: Vec2d; + start: Vec; // (undocumented) - u: Vec2d; + u: Vec; // (undocumented) ul: number; } @@ -663,7 +660,7 @@ export class Editor extends EventEmitter { getCrashingError(): unknown; getCroppingShapeId(): null | TLShapeId; getCurrentPage(): TLPage; - getCurrentPageBounds(): Box2d | undefined; + getCurrentPageBounds(): Box | undefined; getCurrentPageId(): TLPageId; getCurrentPageRenderingShapesSorted(): TLShape[]; getCurrentPageShapeIds(): Set; @@ -696,10 +693,10 @@ export class Editor extends EventEmitter { getPageShapeIds(page: TLPage | TLPageId): Set; getPageStates(): TLInstancePageState[]; getPath(): string; - getPointInParentSpace(shape: TLShape | TLShapeId, point: VecLike): Vec2d; - getPointInShapeSpace(shape: TLShape | TLShapeId, point: VecLike): Vec2d; - getRenderingBounds(): Box2d; - getRenderingBoundsExpanded(): Box2d; + getPointInParentSpace(shape: TLShape | TLShapeId, point: VecLike): Vec; + getPointInShapeSpace(shape: TLShape | TLShapeId, point: VecLike): Vec; + getRenderingBounds(): Box; + getRenderingBoundsExpanded(): Box; getRenderingShapes(): { id: TLShapeId; shape: TLShape; @@ -708,13 +705,13 @@ export class Editor extends EventEmitter { backgroundIndex: number; opacity: number; isCulled: boolean; - maskedPageBounds: Box2d | undefined; + maskedPageBounds: Box | undefined; }[]; getSelectedShapeAtPoint(point: VecLike): TLShape | undefined; getSelectedShapeIds(): TLShapeId[]; getSelectedShapes(): TLShape[]; - getSelectionPageBounds(): Box2d | null; - getSelectionRotatedPageBounds(): Box2d | undefined; + getSelectionPageBounds(): Box | null; + getSelectionRotatedPageBounds(): Box | undefined; getSelectionRotation(): number; getShape(shape: TLParentId | TLShape): T | undefined; getShapeAncestors(shape: TLShape | TLShapeId, acc?: TLShape[]): TLShape[]; @@ -730,14 +727,14 @@ export class Editor extends EventEmitter { getShapeClipPath(shape: TLShape | TLShapeId): string | undefined; getShapeGeometry(shape: TLShape | TLShapeId): T; getShapeHandles(shape: T | T['id']): TLHandle[] | undefined; - getShapeLocalTransform(shape: TLShape | TLShapeId): Matrix2d; + getShapeLocalTransform(shape: TLShape | TLShapeId): Mat; getShapeMask(shape: TLShape | TLShapeId): undefined | VecLike[]; - getShapeMaskedPageBounds(shape: TLShape | TLShapeId): Box2d | undefined; - getShapeOutlineSegments(shape: T | T['id']): Vec2d[][]; - getShapePageBounds(shape: TLShape | TLShapeId): Box2d | undefined; - getShapePageTransform(shape: TLShape | TLShapeId): Matrix2d; + getShapeMaskedPageBounds(shape: TLShape | TLShapeId): Box | undefined; + getShapeOutlineSegments(shape: T | T['id']): Vec[][]; + getShapePageBounds(shape: TLShape | TLShapeId): Box | undefined; + getShapePageTransform(shape: TLShape | TLShapeId): Mat; getShapeParent(shape?: TLShape | TLShapeId): TLShape | undefined; - getShapeParentTransform(shape: TLShape | TLShapeId): Matrix2d; + getShapeParentTransform(shape: TLShape | TLShapeId): Mat; getShapesAtPoint(point: VecLike, opts?: { margin?: number | undefined; hitInside?: boolean | undefined; @@ -756,21 +753,21 @@ export class Editor extends EventEmitter { // @internal (undocumented) getStyleForNextShape(style: StyleProp): T; getSvg(shapes: TLShape[] | TLShapeId[], opts?: Partial): Promise; - getViewportPageBounds(): Box2d; - getViewportPageCenter(): Vec2d; - getViewportScreenBounds(): Box2d; - getViewportScreenCenter(): Vec2d; + getViewportPageBounds(): Box; + getViewportPageCenter(): Vec; + getViewportScreenBounds(): Box; + getViewportScreenCenter(): Vec; getZoomLevel(): number; groupShapes(shapes: TLShape[] | TLShapeId[], groupId?: TLShapeId): this; hasAncestor(shape: TLShape | TLShapeId | undefined, ancestorId: TLShapeId): boolean; readonly history: HistoryManager; inputs: { - originPagePoint: Vec2d; - originScreenPoint: Vec2d; - previousPagePoint: Vec2d; - previousScreenPoint: Vec2d; - currentPagePoint: Vec2d; - currentScreenPoint: Vec2d; + originPagePoint: Vec; + originScreenPoint: Vec; + previousPagePoint: Vec; + previousScreenPoint: Vec; + currentPagePoint: Vec; + currentScreenPoint: Vec; keys: Set; buttons: Set; isPen: boolean; @@ -782,7 +779,7 @@ export class Editor extends EventEmitter { isPinching: boolean; isEditing: boolean; isPanning: boolean; - pointerVelocity: Vec2d; + pointerVelocity: Vec; }; interrupt(): this; isAncestorSelected(shape: TLShape | TLShapeId): boolean; @@ -828,7 +825,7 @@ export class Editor extends EventEmitter { renamePage(page: TLPage | TLPageId, name: string, historyOptions?: TLCommandHistoryOptions): this; renderingBoundsMargin: number; reparentShapes(shapes: TLShape[] | TLShapeId[], parentId: TLParentId, insertIndex?: string): this; - resetZoom(point?: Vec2d, animation?: TLAnimationOptions): this; + resetZoom(point?: Vec, animation?: TLAnimationOptions): this; resizeShape(shape: TLShape | TLShapeId, scale: VecLike, options?: TLResizeShapeOptions): this; readonly root: RootState; rotateShapesBy(shapes: TLShape[] | TLShapeId[], delta: number): this; @@ -897,9 +894,9 @@ export class Editor extends EventEmitter { updateViewportScreenBounds(center?: boolean): this; readonly user: UserPreferencesManager; visitDescendants(parent: TLPage | TLParentId | TLShape, visitor: (id: TLShapeId) => false | void): this; - zoomIn(point?: Vec2d, animation?: TLAnimationOptions): this; - zoomOut(point?: Vec2d, animation?: TLAnimationOptions): this; - zoomToBounds(bounds: Box2d, targetZoom?: number, animation?: TLAnimationOptions): this; + zoomIn(point?: Vec, animation?: TLAnimationOptions): this; + zoomOut(point?: Vec, animation?: TLAnimationOptions): this; + zoomToBounds(bounds: Box, targetZoom?: number, animation?: TLAnimationOptions): this; zoomToContent(): this; zoomToFit(animation?: TLAnimationOptions): this; zoomToSelection(animation?: TLAnimationOptions): this; @@ -921,24 +918,21 @@ export class Ellipse2d extends Geometry2d { // (undocumented) _edges?: Edge2d[]; // (undocumented) - getBounds(): Box2d; + getBounds(): Box; // (undocumented) getVertices(): any[]; // (undocumented) h: number; // (undocumented) - hitTestLineSegment(A: Vec2d, B: Vec2d, zoom: number): boolean; + hitTestLineSegment(A: Vec, B: Vec, zoom: number): boolean; // (undocumented) - nearestPoint(A: Vec2d): Vec2d; + nearestPoint(A: Vec): Vec; // (undocumented) w: number; } export { EMPTY_ARRAY } -// @public (undocumented) -export const EPSILON: number; - // @public (undocumented) export class ErrorBoundary extends React_3.Component>, TLErrorBoundaryState> { // (undocumented) @@ -986,25 +980,25 @@ export abstract class Geometry2d { // (undocumented) _area: number | undefined; // (undocumented) - get bounds(): Box2d; + get bounds(): Box; // (undocumented) - _bounds: Box2d | undefined; + _bounds: Box | undefined; // (undocumented) - get center(): Vec2d; + get center(): Vec; // (undocumented) - distanceToLineSegment(A: Vec2d, B: Vec2d): number; + distanceToLineSegment(A: Vec, B: Vec): number; // (undocumented) - distanceToPoint(point: Vec2d, hitInside?: boolean): number; + distanceToPoint(point: Vec, hitInside?: boolean): number; // (undocumented) getArea(): number; // (undocumented) - getBounds(): Box2d; + getBounds(): Box; // (undocumented) - abstract getVertices(): Vec2d[]; + abstract getVertices(): Vec[]; // (undocumented) - hitTestLineSegment(A: Vec2d, B: Vec2d, distance?: number): boolean; + hitTestLineSegment(A: Vec, B: Vec, distance?: number): boolean; // (undocumented) - hitTestPoint(point: Vec2d, margin?: number, hitInside?: boolean): boolean; + hitTestPoint(point: Vec, margin?: number, hitInside?: boolean): boolean; // (undocumented) isClosed: boolean; // (undocumented) @@ -1012,45 +1006,34 @@ export abstract class Geometry2d { // (undocumented) isLabel: boolean; // (undocumented) - isPointInBounds(point: Vec2d, margin?: number): boolean; + isPointInBounds(point: Vec, margin?: number): boolean; // (undocumented) isSnappable: boolean; // (undocumented) - abstract nearestPoint(point: Vec2d): Vec2d; + abstract nearestPoint(point: Vec): Vec; // (undocumented) - nearestPointOnLineSegment(A: Vec2d, B: Vec2d): Vec2d; + nearestPointOnLineSegment(A: Vec, B: Vec): Vec; // (undocumented) - get snapPoints(): Vec2d[]; + get snapPoints(): Vec[]; // (undocumented) - _snapPoints: undefined | Vec2d[]; + _snapPoints: undefined | Vec[]; // (undocumented) toSimpleSvgPath(): string; // (undocumented) - get vertices(): Vec2d[]; + get vertices(): Vec[]; // (undocumented) - _vertices: undefined | Vec2d[]; + _vertices: undefined | Vec[]; } -// @public -export function getArcLength(C: VecLike, r: number, A: VecLike, B: VecLike): number; - -// @public (undocumented) -export function getArrowheadPathForType(info: TLArrowInfo, side: 'end' | 'start', strokeWidth: number): string | undefined; - // @public (undocumented) export function getArrowTerminalsInArrowSpace(editor: Editor, shape: TLArrowShape): { - start: Vec2d; - end: Vec2d; + start: Vec; + end: Vec; }; // @public (undocumented) export function getCursor(cursor: TLCursorType, rotation?: number, color?: string): string; -// @public -export function getCurvedArrowHandlePath(info: TLArrowInfo & { - isStraight: false; -}): string; - // @public (undocumented) export function getFreshUserPreferences(): TLUserPreferences; @@ -1094,40 +1077,19 @@ export function getPointerInfo(e: PointerEvent | React.PointerEvent): { }; // @public -export function getPointOnCircle(cx: number, cy: number, r: number, a: number): Vec2d; +export function getPointOnCircle(cx: number, cy: number, r: number, a: number): Vec; // @public (undocumented) -export function getPolygonVertices(width: number, height: number, sides: number): Vec2d[]; +export function getPolygonVertices(width: number, height: number, sides: number): Vec[]; // @internal (undocumented) export function getRotationSnapshot({ editor }: { editor: Editor; }): null | TLRotationSnapshot; -// @public -export function getSolidCurvedArrowPath(info: TLArrowInfo & { - isStraight: false; -}): string; - -// @public (undocumented) -export function getSolidStraightArrowPath(info: TLArrowInfo & { - isStraight: true; -}): string; - -// @public -export const getStarBounds: (sides: number, w: number, h: number) => Box2d; - -// @public (undocumented) -export function getStraightArrowHandlePath(info: TLArrowInfo & { - isStraight: true; -}): string; - // @public export function getSvgPathFromPoints(points: VecLike[], closed?: boolean): string; -// @public -export function getSweep(C: VecLike, A: VecLike, B: VecLike): number; - // @public (undocumented) export function getUserPreferences(): TLUserPreferences; @@ -1146,17 +1108,17 @@ export class Group2d extends Geometry2d { // (undocumented) children: Geometry2d[]; // (undocumented) - distanceToPoint(point: Vec2d, hitInside?: boolean): number; + distanceToPoint(point: Vec, hitInside?: boolean): number; // (undocumented) getArea(): number; // (undocumented) - getVertices(): Vec2d[]; + getVertices(): Vec[]; // (undocumented) - hitTestLineSegment(A: Vec2d, B: Vec2d, zoom: number): boolean; + hitTestLineSegment(A: Vec, B: Vec, zoom: number): boolean; // (undocumented) - hitTestPoint(point: Vec2d, margin: number, hitInside: boolean): boolean; + hitTestPoint(point: Vec, margin: number, hitInside: boolean): boolean; // (undocumented) - nearestPoint(point: Vec2d): Vec2d; + nearestPoint(point: Vec): Vec; // (undocumented) toSimpleSvgPath(): string; } @@ -1185,6 +1147,9 @@ export class GroupShapeUtil extends ShapeUtil { static type: "group"; } +// @public (undocumented) +export const HALF_PI: number; + // @public export function hardReset({ shouldReload }?: { shouldReload?: boolean | undefined; @@ -1205,24 +1170,36 @@ export function HTMLContainer({ children, className, ...rest }: HTMLContainerPro // @public (undocumented) export type HTMLContainerProps = React_3.HTMLAttributes; +// @public +export function intersectCircleCircle(c1: VecLike, r1: number, c2: VecLike, r2: number): Vec[]; + +// @public +export function intersectCirclePolygon(c: VecLike, r: number, points: VecLike[]): null | VecLike[]; + +// @public +export function intersectCirclePolyline(c: VecLike, r: number, points: VecLike[]): null | VecLike[]; + +// @public +export function intersectLineSegmentCircle(a1: VecLike, a2: VecLike, c: VecLike, r: number): null | VecLike[]; + +// @public +export function intersectLineSegmentLineSegment(a1: VecLike, a2: VecLike, b1: VecLike, b2: VecLike): null | Vec; + // @public export function intersectLineSegmentPolygon(a1: VecLike, a2: VecLike, points: VecLike[]): null | VecLike[]; // @public export function intersectLineSegmentPolyline(a1: VecLike, a2: VecLike, points: VecLike[]): null | VecLike[]; +// @public +export function intersectPolygonBounds(points: VecLike[], bounds: Box): null | VecLike[]; + // @public export function intersectPolygonPolygon(polygonA: VecLike[], polygonB: VecLike[]): null | VecLike[]; -// @public -export function isAngleBetween(a: number, b: number, c: number): boolean; - // @public export const isSafeFloat: (n: number) => boolean; -// @public -export function lerpAngles(a0: number, a1: number, t: number): number; - // @public (undocumented) export function linesIntersect(A: VecLike, B: VecLike, C: VecLike, D: VecLike): boolean; @@ -1234,29 +1211,26 @@ export function LoadingScreen({ children }: { // @public export function loadSessionStateSnapshotIntoStore(store: TLStore, snapshot: TLSessionStateSnapshot): void; -// @public -export function longAngleDist(a0: number, a1: number): number; - // @public (undocumented) export function loopToHtmlElement(elm: Element): HTMLElement; // @public (undocumented) -export class Matrix2d { +export class Mat { constructor(a: number, b: number, c: number, d: number, e: number, f: number); // (undocumented) a: number; // (undocumented) - static Absolute(m: MatLike): Matrix2dModel; + static Absolute(m: MatLike): MatModel; // (undocumented) - static applyToBounds(m: MatLike, box: Box2d): Box2d; + static applyToBounds(m: MatLike, box: Box): Box; // (undocumented) - applyToPoint(point: VecLike): Vec2d; + applyToPoint(point: VecLike): Vec; // (undocumented) - static applyToPoint(m: MatLike, point: VecLike): Vec2d; + static applyToPoint(m: MatLike, point: VecLike): Vec; // (undocumented) - applyToPoints(points: VecLike[]): Vec2d[]; + applyToPoints(points: VecLike[]): Vec[]; // (undocumented) - static applyToPoints(m: MatLike, points: VecLike[]): Vec2d[]; + static applyToPoints(m: MatLike, points: VecLike[]): Vec[]; // (undocumented) static applyToXY(m: MatLike, x: number, y: number): number[]; // (undocumented) @@ -1264,60 +1238,78 @@ export class Matrix2d { // (undocumented) c: number; // (undocumented) - static Cast(m: MatLike): Matrix2d; + static Cast(m: MatLike): Mat; // (undocumented) - clone(): Matrix2d; + clone(): Mat; // (undocumented) - static Compose(...matrices: MatLike[]): Matrix2d; + static Compose(...matrices: MatLike[]): Mat; // (undocumented) d: number; // (undocumented) - static Decompose(m: MatLike): MatrixInfo; + static Decompose(m: MatLike): { + x: number; + y: number; + scaleX: number; + scaleY: number; + rotation: number; + }; // (undocumented) - decompose(): MatrixInfo; + decompose(): { + x: number; + y: number; + scaleX: number; + scaleY: number; + rotation: number; + }; // (undocumented) - decomposed(): MatrixInfo; + decomposed(): { + x: number; + y: number; + scaleX: number; + scaleY: number; + rotation: number; + }; // (undocumented) e: number; // (undocumented) - equals(m: Matrix2d | Matrix2dModel): boolean; + equals(m: Mat | MatModel): boolean; // (undocumented) f: number; // (undocumented) - static From(m: MatLike): Matrix2d; + static From(m: MatLike): Mat; // (undocumented) - static Identity(): Matrix2d; + static Identity(): Mat; // (undocumented) identity(): this; // (undocumented) - static Inverse(m: Matrix2dModel): Matrix2dModel; + static Inverse(m: MatModel): MatModel; // (undocumented) invert(): this; // (undocumented) - static Multiply(m1: Matrix2dModel, m2: Matrix2dModel): Matrix2dModel; + static Multiply(m1: MatModel, m2: MatModel): MatModel; // (undocumented) - multiply(m: Matrix2d | Matrix2dModel): this; + multiply(m: Mat | MatModel): this; // (undocumented) - static Point(m: MatLike): Vec2d; + static Point(m: MatLike): Vec; // (undocumented) - point(): Vec2d; + point(): Vec; // (undocumented) - static Rotate(r: number, cx?: number, cy?: number): Matrix2d; + static Rotate(r: number, cx?: number, cy?: number): Mat; // (undocumented) - rotate(r: number, cx?: number, cy?: number): Matrix2d; + rotate(r: number, cx?: number, cy?: number): Mat; // (undocumented) static Rotation(m: MatLike): number; // (undocumented) rotation(): number; // (undocumented) static Scale: { - (x: number, y: number): Matrix2dModel; - (x: number, y: number, cx: number, cy: number): Matrix2dModel; + (x: number, y: number): MatModel; + (x: number, y: number, cx: number, cy: number): MatModel; }; // (undocumented) scale(x: number, y: number): this; // (undocumented) - setTo(model: Matrix2dModel): this; + setTo(model: MatModel): this; // (undocumented) static Smooth(m: MatLike, precision?: number): MatLike; // (undocumented) @@ -1325,13 +1317,16 @@ export class Matrix2d { // (undocumented) static toCssString(m: MatLike): string; // (undocumented) - static Translate(x: number, y: number): Matrix2d; + static Translate(x: number, y: number): Mat; // (undocumented) - translate(x: number, y: number): Matrix2d; + translate(x: number, y: number): Mat; } // @public (undocumented) -export interface Matrix2dModel { +export type MatLike = Mat | MatModel; + +// @public (undocumented) +export interface MatModel { // (undocumented) a: number; // (undocumented) @@ -1388,30 +1383,25 @@ export const PI: number; // @public (undocumented) export const PI2: number; -// @public -export function pointInBounds(A: VecLike, b: Box2d): boolean; - -// @public -export function pointInCircle(A: VecLike, C: VecLike, r: number): boolean; - -// @public -export function pointInEllipse(A: VecLike, C: VecLike, rx: number, ry: number, rotation?: number): boolean; +// @public (undocumented) +export class Point2d extends Geometry2d { + constructor(config: Omit & { + margin: number; + point: Vec; + }); + // (undocumented) + getVertices(): Vec[]; + // (undocumented) + hitTestLineSegment(A: Vec, B: Vec, margin: number): boolean; + // (undocumented) + nearestPoint(): Vec; + // (undocumented) + point: Vec; +} // @public export function pointInPolygon(A: VecLike, points: VecLike[]): boolean; -// @public -export function pointInPolyline(A: VecLike, points: VecLike[], distance?: number): boolean; - -// @public -export function pointInRect(A: VecLike, point: VecLike, size: VecLike): boolean; - -// @public -export function pointNearToLineSegment(A: VecLike, p1: VecLike, p2: VecLike, distance?: number): boolean; - -// @public -export function pointNearToPolyline(A: VecLike, points: VecLike[], distance?: number): boolean; - // @public (undocumented) export type PointsSnapLine = { id: string; @@ -1422,7 +1412,7 @@ export type PointsSnapLine = { // @public (undocumented) export class Polygon2d extends Polyline2d { constructor(config: Omit & { - points: Vec2d[]; + points: Vec[]; }); } @@ -1432,20 +1422,20 @@ export function polygonsIntersect(a: VecLike[], b: VecLike[]): boolean; // @public (undocumented) export class Polyline2d extends Geometry2d { constructor(config: Omit & { - points: Vec2d[]; + points: Vec[]; }); // (undocumented) - getVertices(): Vec2d[]; + getVertices(): Vec[]; // (undocumented) - hitTestLineSegment(A: Vec2d, B: Vec2d, zoom: number): boolean; + hitTestLineSegment(A: Vec, B: Vec, zoom: number): boolean; // (undocumented) get length(): number; // (undocumented) _length?: number; // (undocumented) - nearestPoint(A: Vec2d): Vec2d; + nearestPoint(A: Vec): Vec; // (undocumented) - points: Vec2d[]; + points: Vec[]; // (undocumented) get segments(): Edge2d[]; // (undocumented) @@ -1505,7 +1495,7 @@ export class Rectangle2d extends Polygon2d { height: number; }); // (undocumented) - getBounds(): Box2d; + getBounds(): Box; // (undocumented) h: number; // (undocumented) @@ -1527,12 +1517,12 @@ export type RequiredKeys = Partial> & Pick { abstract getDefaultProps(): Shape['props']; abstract getGeometry(shape: Shape): Geometry2d; getHandles?(shape: Shape): TLHandle[]; - getOutlineSegments(shape: Shape): Vec2d[][]; + getOutlineSegments(shape: Shape): Vec[][]; hideResizeHandles: TLShapeUtilFlag; hideRotateHandle: TLShapeUtilFlag; hideSelectionBoundsBg: TLShapeUtilFlag; @@ -1713,16 +1703,16 @@ export class SnapManager { // (undocumented) getLines(): SnapLine[]; // (undocumented) - getOutlinesInPageSpace(): Vec2d[][]; + getOutlinesInPageSpace(): Vec[][]; // (undocumented) getSnappablePoints(): SnapPoint[]; // (undocumented) getSnappableShapes(): GapNode[]; // (undocumented) getSnappingHandleDelta({ handlePoint, additionalSegments, }: { - handlePoint: Vec2d; - additionalSegments: Vec2d[][]; - }): null | Vec2d; + handlePoint: Vec; + additionalSegments: Vec[][]; + }): null | Vec; // (undocumented) getSnapPointsCache(): ComputedCache; // (undocumented) @@ -1736,8 +1726,8 @@ export class SnapManager { setLines(lines: SnapLine[]): void; // (undocumented) snapResize({ initialSelectionPageBounds, dragDelta, handle: originalHandle, isAspectRatioLocked, isResizingFromCenter, }: { - initialSelectionPageBounds: Box2d; - dragDelta: Vec2d; + initialSelectionPageBounds: Box; + dragDelta: Vec; handle: SelectionCorner | SelectionEdge; isAspectRatioLocked: boolean; isResizingFromCenter: boolean; @@ -1746,8 +1736,8 @@ export class SnapManager { snapTranslate({ lockedAxis, initialSelectionPageBounds, initialSelectionSnapPoints, dragDelta, }: { lockedAxis: 'x' | 'y' | null; initialSelectionSnapPoints: SnapPoint[]; - initialSelectionPageBounds: Box2d; - dragDelta: Vec2d; + initialSelectionPageBounds: Box; + dragDelta: Vec; }): SnapData; } @@ -1780,7 +1770,7 @@ export class Stadium2d extends Ellipse2d { height: number; }; // (undocumented) - getVertices(): Vec2d[]; + getVertices(): Vec[]; } // @public (undocumented) @@ -1890,7 +1880,13 @@ export interface SvgExportDef { export const TAB_ID: string; // @public (undocumented) -export const TAU: number; +export type TLAfterChangeHandler = (prev: R, next: R, source: 'remote' | 'user') => void; + +// @public (undocumented) +export type TLAfterCreateHandler = (record: R, source: 'remote' | 'user') => void; + +// @public (undocumented) +export type TLAfterDeleteHandler = (record: R, source: 'remote' | 'user') => void; // @public (undocumented) export type TLAnimationOptions = Partial<{ @@ -1901,6 +1897,47 @@ export type TLAnimationOptions = Partial<{ // @public (undocumented) export type TLAnyShapeUtilConstructor = TLShapeUtilConstructor; +// @public (undocumented) +export interface TLArcInfo { + // (undocumented) + center: VecLike; + // (undocumented) + largeArcFlag: number; + // (undocumented) + length: number; + // (undocumented) + radius: number; + // (undocumented) + size: number; + // (undocumented) + sweepFlag: number; +} + +// @public (undocumented) +export type TLArrowInfo = { + isStraight: false; + start: TLArrowPoint; + end: TLArrowPoint; + middle: VecLike; + handleArc: TLArcInfo; + bodyArc: TLArcInfo; + isValid: boolean; +} | { + isStraight: true; + start: TLArrowPoint; + end: TLArrowPoint; + middle: VecLike; + isValid: boolean; + length: number; +}; + +// @public (undocumented) +export type TLArrowPoint = { + handle: VecLike; + point: VecLike; + arrowhead: TLArrowShapeArrowheadStyle; +}; + // @public (undocumented) export type TLBackgroundComponent = ComponentType; @@ -1922,9 +1959,21 @@ export interface TLBaseEventInfo { type: UiEventType; } +// @public (undocumented) +export type TLBatchCompleteHandler = () => void; + +// @public (undocumented) +export type TLBeforeChangeHandler = (prev: R, next: R, source: 'remote' | 'user') => R; + +// @public (undocumented) +export type TLBeforeCreateHandler = (record: R, source: 'remote' | 'user') => R; + +// @public (undocumented) +export type TLBeforeDeleteHandler = (record: R, source: 'remote' | 'user') => false | void; + // @public (undocumented) export type TLBrushComponent = ComponentType<{ - brush: Box2dModel; + brush: BoxModel; color?: string; opacity?: number; className?: string; @@ -1958,8 +2007,8 @@ export type TLCLickEventName = 'double_click' | 'quadruple_click' | 'triple_clic // @public (undocumented) export type TLCollaboratorHintComponent = ComponentType<{ className?: string; - point: Vec2dModel; - viewport: Box2d; + point: VecModel; + viewport: Box; zoom: number; opacity?: number; color: string; @@ -2006,7 +2055,7 @@ export interface TLContent { // @public (undocumented) export type TLCursorComponent = ComponentType<{ className?: string; - point: null | Vec2dModel; + point: null | VecModel; zoom: number; color?: string; name: null | string; @@ -2346,8 +2395,8 @@ export type TLPinchEvent = (info: TLPinchEventInfo) => void; export type TLPinchEventInfo = TLBaseEventInfo & { type: 'pinch'; name: TLPinchEventName; - point: Vec2dModel; - delta: Vec2dModel; + point: VecModel; + delta: VecModel; }; // @public (undocumented) @@ -2391,12 +2440,12 @@ export type TLResizeHandle = SelectionCorner | SelectionEdge; // @public export type TLResizeInfo = { - newPoint: Vec2d; + newPoint: Vec; handle: TLResizeHandle; mode: TLResizeMode; scaleX: number; scaleY: number; - initialBounds: Box2d; + initialBounds: Box; initialShape: T; }; @@ -2405,7 +2454,7 @@ export type TLResizeMode = 'resize_bounds' | 'scale_shape'; // @public (undocumented) export type TLResizeShapeOptions = Partial<{ - initialBounds: Box2d; + initialBounds: Box; scaleOrigin: VecLike; scaleAxisRotation: number; initialShape: TLShape; @@ -2416,12 +2465,12 @@ export type TLResizeShapeOptions = Partial<{ // @public export type TLRotationSnapshot = { - selectionPageCenter: Vec2d; + selectionPageCenter: Vec; initialCursorAngle: number; initialSelectionRotation: number; shapeSnapshots: { shape: TLShape; - initialPagePoint: Vec2d; + initialPagePoint: Vec; }[]; }; @@ -2436,13 +2485,13 @@ export type TLScribbleComponent = ComponentType<{ // @public (undocumented) export type TLSelectionBackgroundComponent = React_3.ComponentType<{ - bounds: Box2d; + bounds: Box; rotation: number; }>; // @public (undocumented) export type TLSelectionForegroundComponent = ComponentType<{ - bounds: Box2d; + bounds: Box; rotation: number; }>; @@ -2573,7 +2622,7 @@ export type TLSvgDefsComponent = React.ComponentType; // @public (undocumented) export type TLSvgOptions = { - bounds: Box2d; + bounds: Box; scale: number; background: boolean; padding: number; @@ -2614,8 +2663,8 @@ export type TLWheelEvent = (info: TLWheelEventInfo) => void; export type TLWheelEventInfo = TLBaseEventInfo & { type: 'wheel'; name: 'wheel'; - delta: Vec2dModel; - point: Vec2dModel; + delta: VecModel; + point: VecModel; }; // @public @@ -2709,22 +2758,22 @@ export function useTransform(ref: React.RefObject, x?: export { useValue } // @public (undocumented) -export class Vec2d { +export class Vec { constructor(x?: number, y?: number, z?: number); // (undocumented) - static Abs(A: VecLike): Vec2d; + static Abs(A: VecLike): Vec; // (undocumented) abs(): this; // (undocumented) - static Add(A: VecLike, B: VecLike): Vec2d; + static Add(A: VecLike, B: VecLike): Vec; // (undocumented) add(V: VecLike): this; // (undocumented) - static AddScalar(A: VecLike, n: number): Vec2d; + static AddScalar(A: VecLike, n: number): Vec; // (undocumented) addScalar(n: number): this; // (undocumented) - static AddXY(A: VecLike, x: number, y: number): Vec2d; + static AddXY(A: VecLike, x: number, y: number): Vec; // (undocumented) addXY(x: number, y: number): this; // (undocumented) @@ -2732,23 +2781,23 @@ export class Vec2d { // (undocumented) angle(B: VecLike): number; // (undocumented) - static Average(arr: VecLike[]): Vec2d; + static Average(arr: VecLike[]): Vec; // (undocumented) - static Cast(A: VecLike): Vec2d; + static Cast(A: VecLike): Vec; // (undocumented) - static Clamp(A: Vec2d, min: number, max?: number): Vec2d; + static Clamp(A: Vec, min: number, max?: number): Vec; // (undocumented) clamp(min: number, max?: number): this; // (undocumented) static Clockwise(A: VecLike, B: VecLike, C: VecLike): boolean; // (undocumented) - clone(): Vec2d; + clone(): Vec; // (undocumented) static Cpr(A: VecLike, B: VecLike): number; // (undocumented) cpr(V: VecLike): number; // (undocumented) - static Cross(A: VecLike, V: VecLike): Vec2d; + static Cross(A: VecLike, V: VecLike): Vec; // (undocumented) cross(V: VecLike): this; // (undocumented) @@ -2764,11 +2813,11 @@ export class Vec2d { // (undocumented) static DistanceToLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): number; // (undocumented) - static Div(A: VecLike, t: number): Vec2d; + static Div(A: VecLike, t: number): Vec; // (undocumented) div(t: number): this; // (undocumented) - static DivV(A: VecLike, B: VecLike): Vec2d; + static DivV(A: VecLike, B: VecLike): Vec; // (undocumented) divV(V: VecLike): this; // (undocumented) @@ -2784,11 +2833,11 @@ export class Vec2d { // (undocumented) equalsXY(x: number, y: number): boolean; // (undocumented) - static From({ x, y, z }: Vec2dModel): Vec2d; + static From({ x, y, z }: VecModel): Vec; // (undocumented) - static FromAngle(r: number, length?: number): Vec2d; + static FromAngle(r: number, length?: number): Vec; // (undocumented) - static FromArray(v: number[]): Vec2d; + static FromArray(v: number[]): Vec; // (undocumented) static Len(A: VecLike): number; // (undocumented) @@ -2798,41 +2847,41 @@ export class Vec2d { // (undocumented) len2(): number; // (undocumented) - static Lrp(A: VecLike, B: VecLike, t: number): Vec2d; + static Lrp(A: VecLike, B: VecLike, t: number): Vec; // (undocumented) - lrp(B: VecLike, t: number): Vec2d; + lrp(B: VecLike, t: number): Vec; // (undocumented) - static Max(A: VecLike, B: VecLike): Vec2d; + static Max(A: VecLike, B: VecLike): Vec; // (undocumented) - static Med(A: VecLike, B: VecLike): Vec2d; + static Med(A: VecLike, B: VecLike): Vec; // (undocumented) - static Min(A: VecLike, B: VecLike): Vec2d; + static Min(A: VecLike, B: VecLike): Vec; // (undocumented) - static Mul(A: VecLike, t: number): Vec2d; + static Mul(A: VecLike, t: number): Vec; // (undocumented) mul(t: number): this; // (undocumented) - static MulV(A: VecLike, B: VecLike): Vec2d; + static MulV(A: VecLike, B: VecLike): Vec; // (undocumented) mulV(V: VecLike): this; // (undocumented) - static NearestPointOnLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp?: boolean): Vec2d; - static NearestPointOnLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): Vec2d; + static NearestPointOnLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp?: boolean): Vec; + static NearestPointOnLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): Vec; // (undocumented) - static Neg(A: VecLike): Vec2d; + static Neg(A: VecLike): Vec; // (undocumented) neg(): this; // (undocumented) norm(): this; // (undocumented) - static Nudge(A: VecLike, B: VecLike, distance: number): Vec2d; + static Nudge(A: VecLike, B: VecLike, distance: number): Vec; // (undocumented) nudge(B: VecLike, distance: number): this; // (undocumented) - static Per(A: VecLike): Vec2d; + static Per(A: VecLike): Vec; // (undocumented) per(): this; - static PointsBetween(A: Vec2dModel, B: Vec2dModel, steps?: number): Vec2d[]; + static PointsBetween(A: VecModel, B: VecModel, steps?: number): Vec[]; // (undocumented) get pressure(): number; // (undocumented) @@ -2840,17 +2889,17 @@ export class Vec2d { // (undocumented) pry(V: VecLike): number; // (undocumented) - static Rescale(A: VecLike, n: number): Vec2d; + static Rescale(A: VecLike, n: number): Vec; // (undocumented) - static Rot(A: VecLike, r?: number): Vec2d; + static Rot(A: VecLike, r?: number): Vec; // (undocumented) rot(r: number): this; // (undocumented) - static RotWith(A: VecLike, C: VecLike, r: number): Vec2d; + static RotWith(A: VecLike, C: VecLike, r: number): Vec; // (undocumented) rotWith(C: VecLike, r: number): this; // (undocumented) - static ScaleWithOrigin(A: VecLike, scale: number, origin: VecLike): Vec2d; + static ScaleWithOrigin(A: VecLike, scale: number, origin: VecLike): Vec; // (undocumented) set(x?: number, y?: number, z?: number): this; // (undocumented) @@ -2860,27 +2909,27 @@ export class Vec2d { // (undocumented) slope(B: VecLike): number; // (undocumented) - static Snap(A: VecLike, step?: number): Vec2d; + static Snap(A: VecLike, step?: number): Vec; // (undocumented) - static SnapToGrid(A: VecLike, gridSize?: number): Vec2d; + static SnapToGrid(A: VecLike, gridSize?: number): Vec; // (undocumented) snapToGrid(gridSize: number): this; // (undocumented) - static Sub(A: VecLike, B: VecLike): Vec2d; + static Sub(A: VecLike, B: VecLike): Vec; // (undocumented) sub(V: VecLike): this; // (undocumented) - static SubScalar(A: VecLike, n: number): Vec2d; + static SubScalar(A: VecLike, n: number): Vec; // (undocumented) subScalar(n: number): this; // (undocumented) - static SubXY(A: VecLike, x: number, y: number): Vec2d; + static SubXY(A: VecLike, x: number, y: number): Vec; // (undocumented) subXY(x: number, y: number): this; // (undocumented) - static Tan(A: VecLike, B: VecLike): Vec2d; + static Tan(A: VecLike, B: VecLike): Vec; // (undocumented) - tan(V: VecLike): Vec2d; + tan(V: VecLike): Vec; // (undocumented) static ToAngle(A: VecLike): number; // (undocumented) @@ -2890,9 +2939,9 @@ export class Vec2d { // (undocumented) toArray(): number[]; // (undocumented) - static ToFixed(A: VecLike, n?: number): Vec2d; + static ToFixed(A: VecLike, n?: number): Vec; // (undocumented) - toFixed(): Vec2d; + toFixed(): Vec; // (undocumented) static ToJson(A: VecLike): { x: number; @@ -2900,15 +2949,15 @@ export class Vec2d { z: number | undefined; }; // (undocumented) - toJson(): Vec2dModel; + toJson(): VecModel; // (undocumented) static ToString(A: VecLike): string; // (undocumented) toString(): string; // (undocumented) - static Uni(A: VecLike): Vec2d; + static Uni(A: VecLike): Vec; // (undocumented) - uni(): Vec2d; + uni(): Vec; // (undocumented) x: number; // (undocumented) @@ -2918,7 +2967,7 @@ export class Vec2d { } // @public (undocumented) -export type VecLike = Vec2d | Vec2dModel; +export type VecLike = Vec | VecModel; // @public (undocumented) export class WeakMapCache { diff --git a/packages/editor/api/api.json b/packages/editor/api/api.json index 9155c4b35..437e1d580 100644 --- a/packages/editor/api/api.json +++ b/packages/editor/api/api.json @@ -172,67 +172,6 @@ "name": "", "preserveMemberOrder": false, "members": [ - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!angleDelta:function(1)", - "docComment": "/**\n * Get the short distance between two angles.\n *\n * @param a0 - The first angle.\n *\n * @param a1 - The second angle.\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function angleDelta(a0: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ", a1: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "a0", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "a1", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - } - ], - "name": "angleDelta" - }, { "kind": "Function", "canonicalReference": "@tldraw/editor!approximately:function(1)", @@ -346,8 +285,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -395,8 +334,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -404,8 +343,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -413,8 +352,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -510,8 +449,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -541,8 +480,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -577,8 +516,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -586,8 +525,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -719,8 +658,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -728,8 +667,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -799,8 +738,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -1303,24 +1242,24 @@ }, { "kind": "Class", - "canonicalReference": "@tldraw/editor!Box2d:class", + "canonicalReference": "@tldraw/editor!Box:class", "docComment": "/**\n * @public\n */\n", "excerptTokens": [ { "kind": "Content", - "text": "export declare class Box2d " + "text": "export declare class Box " } ], - "fileUrlPath": "packages/editor/src/lib/primitives/Box2d.ts", + "fileUrlPath": "packages/editor/src/lib/primitives/Box.ts", "releaseTag": "Public", "isAbstract": false, - "name": "Box2d", + "name": "Box", "preserveMemberOrder": false, "members": [ { "kind": "Constructor", - "canonicalReference": "@tldraw/editor!Box2d:constructor(1)", - "docComment": "/**\n * Constructs a new instance of the `Box2d` class\n */\n", + "canonicalReference": "@tldraw/editor!Box:constructor(1)", + "docComment": "/**\n * Constructs a new instance of the `Box` class\n */\n", "excerptTokens": [ { "kind": "Content", @@ -1399,7 +1338,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#aspectRatio:member", + "canonicalReference": "@tldraw/editor!Box#aspectRatio:member", "docComment": "", "excerptTokens": [ { @@ -1429,7 +1368,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#center:member", + "canonicalReference": "@tldraw/editor!Box#center:member", "docComment": "", "excerptTokens": [ { @@ -1438,8 +1377,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -1447,8 +1386,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -1469,7 +1408,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#clone:member(1)", + "canonicalReference": "@tldraw/editor!Box#clone:member(1)", "docComment": "", "excerptTokens": [ { @@ -1478,8 +1417,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1501,7 +1440,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#collides:member(1)", + "canonicalReference": "@tldraw/editor!Box#collides:member(1)", "docComment": "", "excerptTokens": [ { @@ -1510,8 +1449,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1550,7 +1489,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d.Collides:member", + "canonicalReference": "@tldraw/editor!Box.Collides:member", "docComment": "", "excerptTokens": [ { @@ -1563,8 +1502,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1572,8 +1511,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1598,7 +1537,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d.Common:member", + "canonicalReference": "@tldraw/editor!Box.Common:member", "docComment": "", "excerptTokens": [ { @@ -1611,8 +1550,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1620,8 +1559,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1642,7 +1581,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#contains:member(1)", + "canonicalReference": "@tldraw/editor!Box#contains:member(1)", "docComment": "", "excerptTokens": [ { @@ -1651,8 +1590,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1691,7 +1630,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d.Contains:member", + "canonicalReference": "@tldraw/editor!Box.Contains:member", "docComment": "", "excerptTokens": [ { @@ -1704,8 +1643,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1713,8 +1652,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1739,7 +1678,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#containsPoint:member(1)", + "canonicalReference": "@tldraw/editor!Box#containsPoint:member(1)", "docComment": "", "excerptTokens": [ { @@ -1804,7 +1743,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d.ContainsPoint:member", + "canonicalReference": "@tldraw/editor!Box.ContainsPoint:member", "docComment": "", "excerptTokens": [ { @@ -1817,8 +1756,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1852,7 +1791,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#corners:member", + "canonicalReference": "@tldraw/editor!Box#corners:member", "docComment": "", "excerptTokens": [ { @@ -1861,8 +1800,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -1887,7 +1826,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#equals:member(1)", + "canonicalReference": "@tldraw/editor!Box#equals:member(1)", "docComment": "", "excerptTokens": [ { @@ -1896,8 +1835,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1905,8 +1844,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -1945,7 +1884,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d.Equals:member(1)", + "canonicalReference": "@tldraw/editor!Box.Equals:member(1)", "docComment": "", "excerptTokens": [ { @@ -1954,8 +1893,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1963,8 +1902,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -1972,8 +1911,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -1981,8 +1920,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -2029,7 +1968,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#expand:member(1)", + "canonicalReference": "@tldraw/editor!Box#expand:member(1)", "docComment": "", "excerptTokens": [ { @@ -2038,8 +1977,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -2078,7 +2017,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d.Expand:member(1)", + "canonicalReference": "@tldraw/editor!Box.Expand:member(1)", "docComment": "", "excerptTokens": [ { @@ -2087,8 +2026,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -2096,8 +2035,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -2105,8 +2044,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -2145,7 +2084,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#expandBy:member(1)", + "canonicalReference": "@tldraw/editor!Box#expandBy:member(1)", "docComment": "", "excerptTokens": [ { @@ -2193,7 +2132,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d.ExpandBy:member(1)", + "canonicalReference": "@tldraw/editor!Box.ExpandBy:member(1)", "docComment": "", "excerptTokens": [ { @@ -2202,8 +2141,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -2219,8 +2158,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -2259,7 +2198,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d.From:member(1)", + "canonicalReference": "@tldraw/editor!Box.From:member(1)", "docComment": "", "excerptTokens": [ { @@ -2268,8 +2207,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -2277,8 +2216,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -2309,7 +2248,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d.FromPoints:member(1)", + "canonicalReference": "@tldraw/editor!Box.FromPoints:member(1)", "docComment": "", "excerptTokens": [ { @@ -2331,8 +2270,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -2363,7 +2302,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#getHandlePoint:member(1)", + "canonicalReference": "@tldraw/editor!Box#getHandlePoint:member(1)", "docComment": "", "excerptTokens": [ { @@ -2390,8 +2329,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -2422,7 +2361,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#h:member", + "canonicalReference": "@tldraw/editor!Box#h:member", "docComment": "", "excerptTokens": [ { @@ -2452,7 +2391,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#height:member", + "canonicalReference": "@tldraw/editor!Box#height:member", "docComment": "", "excerptTokens": [ { @@ -2482,7 +2421,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#includes:member(1)", + "canonicalReference": "@tldraw/editor!Box#includes:member(1)", "docComment": "", "excerptTokens": [ { @@ -2491,8 +2430,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -2531,7 +2470,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d.Includes:member", + "canonicalReference": "@tldraw/editor!Box.Includes:member", "docComment": "", "excerptTokens": [ { @@ -2544,8 +2483,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -2553,8 +2492,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -2579,7 +2518,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#maxX:member", + "canonicalReference": "@tldraw/editor!Box#maxX:member", "docComment": "", "excerptTokens": [ { @@ -2609,7 +2548,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#maxY:member", + "canonicalReference": "@tldraw/editor!Box#maxY:member", "docComment": "", "excerptTokens": [ { @@ -2639,7 +2578,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#midX:member", + "canonicalReference": "@tldraw/editor!Box#midX:member", "docComment": "", "excerptTokens": [ { @@ -2669,7 +2608,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#midY:member", + "canonicalReference": "@tldraw/editor!Box#midY:member", "docComment": "", "excerptTokens": [ { @@ -2699,7 +2638,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#minX:member", + "canonicalReference": "@tldraw/editor!Box#minX:member", "docComment": "", "excerptTokens": [ { @@ -2729,7 +2668,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#minY:member", + "canonicalReference": "@tldraw/editor!Box#minY:member", "docComment": "", "excerptTokens": [ { @@ -2759,7 +2698,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#point:member", + "canonicalReference": "@tldraw/editor!Box#point:member", "docComment": "", "excerptTokens": [ { @@ -2768,8 +2707,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -2777,8 +2716,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -2799,7 +2738,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#resize:member(1)", + "canonicalReference": "@tldraw/editor!Box#resize:member(1)", "docComment": "", "excerptTokens": [ { @@ -2893,7 +2832,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d.Resize:member(1)", + "canonicalReference": "@tldraw/editor!Box.Resize:member(1)", "docComment": "", "excerptTokens": [ { @@ -2902,8 +2841,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -2961,8 +2900,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -3029,7 +2968,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#scale:member(1)", + "canonicalReference": "@tldraw/editor!Box#scale:member(1)", "docComment": "", "excerptTokens": [ { @@ -3077,7 +3016,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#set:member(1)", + "canonicalReference": "@tldraw/editor!Box#set:member(1)", "docComment": "", "excerptTokens": [ { @@ -3173,7 +3112,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#setTo:member(1)", + "canonicalReference": "@tldraw/editor!Box#setTo:member(1)", "docComment": "", "excerptTokens": [ { @@ -3182,8 +3121,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -3222,7 +3161,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#sides:member", + "canonicalReference": "@tldraw/editor!Box#sides:member", "docComment": "", "excerptTokens": [ { @@ -3240,8 +3179,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -3249,8 +3188,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -3275,7 +3214,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d.Sides:member", + "canonicalReference": "@tldraw/editor!Box.Sides:member", "docComment": "", "excerptTokens": [ { @@ -3288,8 +3227,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -3297,8 +3236,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -3323,7 +3262,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#size:member", + "canonicalReference": "@tldraw/editor!Box#size:member", "docComment": "", "excerptTokens": [ { @@ -3332,8 +3271,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -3354,7 +3293,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#snapPoints:member", + "canonicalReference": "@tldraw/editor!Box#snapPoints:member", "docComment": "", "excerptTokens": [ { @@ -3363,8 +3302,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -3389,7 +3328,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#snapToGrid:member(1)", + "canonicalReference": "@tldraw/editor!Box#snapToGrid:member(1)", "docComment": "", "excerptTokens": [ { @@ -3437,7 +3376,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#toFixed:member(1)", + "canonicalReference": "@tldraw/editor!Box#toFixed:member(1)", "docComment": "", "excerptTokens": [ { @@ -3468,7 +3407,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#toJson:member(1)", + "canonicalReference": "@tldraw/editor!Box#toJson:member(1)", "docComment": "", "excerptTokens": [ { @@ -3477,8 +3416,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -3500,7 +3439,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#translate:member(1)", + "canonicalReference": "@tldraw/editor!Box#translate:member(1)", "docComment": "", "excerptTokens": [ { @@ -3549,7 +3488,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#union:member(1)", + "canonicalReference": "@tldraw/editor!Box#union:member(1)", "docComment": "", "excerptTokens": [ { @@ -3558,8 +3497,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -3598,7 +3537,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#w:member", + "canonicalReference": "@tldraw/editor!Box#w:member", "docComment": "", "excerptTokens": [ { @@ -3628,7 +3567,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#width:member", + "canonicalReference": "@tldraw/editor!Box#width:member", "docComment": "", "excerptTokens": [ { @@ -3658,7 +3597,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#x:member", + "canonicalReference": "@tldraw/editor!Box#x:member", "docComment": "", "excerptTokens": [ { @@ -3688,7 +3627,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Box2d#y:member", + "canonicalReference": "@tldraw/editor!Box#y:member", "docComment": "", "excerptTokens": [ { @@ -3718,7 +3657,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d#zeroFix:member(1)", + "canonicalReference": "@tldraw/editor!Box#zeroFix:member(1)", "docComment": "", "excerptTokens": [ { @@ -3749,7 +3688,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Box2d.ZeroFix:member(1)", + "canonicalReference": "@tldraw/editor!Box.ZeroFix:member(1)", "docComment": "", "excerptTokens": [ { @@ -3758,8 +3697,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -3767,8 +3706,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -3776,8 +3715,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -3820,8 +3759,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -3829,15 +3768,15 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", "text": ";" } ], - "fileUrlPath": "packages/editor/src/lib/primitives/Box2d.ts", + "fileUrlPath": "packages/editor/src/lib/primitives/Box.ts", "releaseTag": "Public", "name": "BoxLike", "typeTokenRange": { @@ -3972,8 +3911,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -4093,8 +4032,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -4125,8 +4064,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -4161,8 +4100,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -4170,8 +4109,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -4243,8 +4182,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -4252,8 +4191,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -4916,8 +4855,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -4925,8 +4864,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -4934,8 +4873,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -4943,8 +4882,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -4980,8 +4919,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5011,8 +4950,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5042,8 +4981,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5073,8 +5012,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5104,8 +5043,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5140,8 +5079,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5172,8 +5111,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5181,8 +5120,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5337,8 +5276,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5374,8 +5313,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5410,8 +5349,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5419,8 +5358,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5522,8 +5461,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5531,8 +5470,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5572,8 +5511,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -5830,8 +5769,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -6276,8 +6215,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -6285,8 +6224,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -6322,8 +6261,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -6353,8 +6292,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -6384,8 +6323,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -6420,8 +6359,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -6429,8 +6368,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -6532,8 +6471,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -6564,8 +6503,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -6573,8 +6512,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -6614,8 +6553,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -6645,8 +6584,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -9042,7 +8981,7 @@ { "kind": "Reference", "text": "TLArrowInfo", - "canonicalReference": "@tldraw/editor!~TLArrowInfo:type" + "canonicalReference": "@tldraw/editor!TLArrowInfo:type" }, { "kind": "Content", @@ -9627,8 +9566,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -11029,8 +10968,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -11105,8 +11044,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -11154,8 +11093,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -11186,8 +11125,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -11258,8 +11197,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -11420,8 +11359,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -11456,8 +11395,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -12073,8 +12012,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -12199,8 +12138,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -12261,8 +12200,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -12337,8 +12276,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -12400,8 +12339,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -12522,8 +12461,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -13270,8 +13209,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -13302,8 +13241,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -13334,8 +13273,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -13366,8 +13305,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -13626,8 +13565,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -13635,8 +13574,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -13644,8 +13583,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -13653,8 +13592,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -13662,8 +13601,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -13671,8 +13610,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -13698,8 +13637,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -15528,8 +15467,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -18650,8 +18589,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -18716,8 +18655,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -18782,8 +18721,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -19185,8 +19124,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -19278,8 +19217,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -19287,8 +19226,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -19360,8 +19299,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -19369,8 +19308,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -19436,29 +19375,6 @@ }, "implementsTokenRanges": [] }, - { - "kind": "Variable", - "canonicalReference": "@tldraw/editor!EPSILON:var", - "docComment": "/**\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "EPSILON: " - }, - { - "kind": "Content", - "text": "number" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "isReadonly": true, - "releaseTag": "Public", - "name": "EPSILON", - "variableTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - } - }, { "kind": "Class", "canonicalReference": "@tldraw/editor!ErrorBoundary:class", @@ -19955,8 +19871,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -19994,8 +19910,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20033,8 +19949,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20131,8 +20047,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -20162,8 +20078,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20193,8 +20109,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20202,8 +20118,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20259,8 +20175,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20355,8 +20271,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -20387,8 +20303,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20423,8 +20339,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20432,8 +20348,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20505,8 +20421,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20676,8 +20592,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20771,8 +20687,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20780,8 +20696,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20821,8 +20737,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20830,8 +20746,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20839,8 +20755,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20888,8 +20804,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20954,8 +20870,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -20981,180 +20897,6 @@ ], "implementsTokenRanges": [] }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!getArcLength:function(1)", - "docComment": "/**\n * Get the length of an arc between two points on a circle's perimeter.\n *\n * @param C - The circle's center as [x, y].\n *\n * @param r - The circle's radius.\n *\n * @param A - The first point.\n *\n * @param B - The second point.\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function getArcLength(C: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", r: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ", A: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", B: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 9, - "endIndex": 10 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "C", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "r", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - }, - { - "parameterName": "A", - "parameterTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, - "isOptional": false - }, - { - "parameterName": "B", - "parameterTypeTokenRange": { - "startIndex": 7, - "endIndex": 8 - }, - "isOptional": false - } - ], - "name": "getArcLength" - }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!getArrowheadPathForType:function(1)", - "docComment": "/**\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function getArrowheadPathForType(info: " - }, - { - "kind": "Reference", - "text": "TLArrowInfo", - "canonicalReference": "@tldraw/editor!~TLArrowInfo:type" - }, - { - "kind": "Content", - "text": ", side: " - }, - { - "kind": "Content", - "text": "'end' | 'start'" - }, - { - "kind": "Content", - "text": ", strokeWidth: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "string | undefined" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/editor/shapes/shared/arrow/arrowheads.ts", - "returnTypeTokenRange": { - "startIndex": 7, - "endIndex": 8 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "info", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "side", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - }, - { - "parameterName": "strokeWidth", - "parameterTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, - "isOptional": false - } - ], - "name": "getArrowheadPathForType" - }, { "kind": "Function", "canonicalReference": "@tldraw/editor!getArrowTerminalsInArrowSpace:function(1)", @@ -21188,8 +20930,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -21197,8 +20939,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -21314,56 +21056,6 @@ ], "name": "getCursor" }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!getCurvedArrowHandlePath:function(1)", - "docComment": "/**\n * Get a solid path for a curved arrow's handles.\n *\n * @param info - The arrow info.\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function getCurvedArrowHandlePath(info: " - }, - { - "kind": "Reference", - "text": "TLArrowInfo", - "canonicalReference": "@tldraw/editor!~TLArrowInfo:type" - }, - { - "kind": "Content", - "text": " & {\n isStraight: false;\n}" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "string" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/editor/shapes/shared/arrow/curved-arrow.ts", - "returnTypeTokenRange": { - "startIndex": 4, - "endIndex": 5 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "info", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 3 - }, - "isOptional": false - } - ], - "name": "getCurvedArrowHandlePath" - }, { "kind": "Function", "canonicalReference": "@tldraw/editor!getFreshUserPreferences:function(1)", @@ -21963,8 +21655,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -22049,8 +21741,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -22096,184 +21788,6 @@ ], "name": "getPolygonVertices" }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!getSolidCurvedArrowPath:function(1)", - "docComment": "/**\n * Get a solid path for a curved arrow's body.\n *\n * @param info - The arrow info.\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function getSolidCurvedArrowPath(info: " - }, - { - "kind": "Reference", - "text": "TLArrowInfo", - "canonicalReference": "@tldraw/editor!~TLArrowInfo:type" - }, - { - "kind": "Content", - "text": " & {\n isStraight: false;\n}" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "string" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/editor/shapes/shared/arrow/curved-arrow.ts", - "returnTypeTokenRange": { - "startIndex": 4, - "endIndex": 5 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "info", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 3 - }, - "isOptional": false - } - ], - "name": "getSolidCurvedArrowPath" - }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!getSolidStraightArrowPath:function(1)", - "docComment": "/**\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function getSolidStraightArrowPath(info: " - }, - { - "kind": "Reference", - "text": "TLArrowInfo", - "canonicalReference": "@tldraw/editor!~TLArrowInfo:type" - }, - { - "kind": "Content", - "text": " & {\n isStraight: true;\n}" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "string" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/editor/shapes/shared/arrow/straight-arrow.ts", - "returnTypeTokenRange": { - "startIndex": 4, - "endIndex": 5 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "info", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 3 - }, - "isOptional": false - } - ], - "name": "getSolidStraightArrowPath" - }, - { - "kind": "Variable", - "canonicalReference": "@tldraw/editor!getStarBounds:var", - "docComment": "/**\n * Gets the width/height of a star given its input bounds.\n *\n * @param sides - Number of sides\n *\n * @param w - T target width\n *\n * @param h - Target height\n *\n * @returns Box2d\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "getStarBounds: " - }, - { - "kind": "Content", - "text": "(sides: number, w: number, h: number) => " - }, - { - "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "isReadonly": true, - "releaseTag": "Public", - "name": "getStarBounds", - "variableTypeTokenRange": { - "startIndex": 1, - "endIndex": 3 - } - }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!getStraightArrowHandlePath:function(1)", - "docComment": "/**\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function getStraightArrowHandlePath(info: " - }, - { - "kind": "Reference", - "text": "TLArrowInfo", - "canonicalReference": "@tldraw/editor!~TLArrowInfo:type" - }, - { - "kind": "Content", - "text": " & {\n isStraight: true;\n}" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "string" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/editor/shapes/shared/arrow/straight-arrow.ts", - "returnTypeTokenRange": { - "startIndex": 4, - "endIndex": 5 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "info", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 3 - }, - "isOptional": false - } - ], - "name": "getStraightArrowHandlePath" - }, { "kind": "Function", "canonicalReference": "@tldraw/editor!getSvgPathFromPoints:function(1)", @@ -22340,86 +21854,6 @@ ], "name": "getSvgPathFromPoints" }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!getSweep:function(1)", - "docComment": "/**\n * Get the \"sweep\" or short distance between two points on a circle's perimeter.\n *\n * @param C - The center of the circle.\n *\n * @param A - The first point.\n *\n * @param B - The second point.\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function getSweep(C: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", A: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", B: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 7, - "endIndex": 8 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "C", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "A", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - }, - { - "parameterName": "B", - "parameterTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, - "isOptional": false - } - ], - "name": "getSweep" - }, { "kind": "Function", "canonicalReference": "@tldraw/editor!getUserPreferences:function(1)", @@ -22598,8 +22032,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -22694,8 +22128,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -22730,8 +22164,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -22739,8 +22173,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -22812,8 +22246,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -22893,8 +22327,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -22902,8 +22336,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -23422,6 +22856,29 @@ }, "implementsTokenRanges": [] }, + { + "kind": "Variable", + "canonicalReference": "@tldraw/editor!HALF_PI:var", + "docComment": "/**\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "HALF_PI: " + }, + { + "kind": "Content", + "text": "number" + } + ], + "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", + "isReadonly": true, + "releaseTag": "Public", + "name": "HALF_PI", + "variableTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, { "kind": "Function", "canonicalReference": "@tldraw/editor!hardReset:function(1)", @@ -23614,6 +23071,497 @@ "endIndex": 5 } }, + { + "kind": "Function", + "canonicalReference": "@tldraw/editor!intersectCircleCircle:function(1)", + "docComment": "/**\n * Find the intersections between a circle and a circle.\n *\n * @param c1 - The first circle's center.\n *\n * @param r1 - The first circle's radius.\n *\n * @param c2 - The second circle's center.\n *\n * @param r2 - The second circle's radius.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export declare function intersectCircleCircle(c1: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ", r1: " + }, + { + "kind": "Content", + "text": "number" + }, + { + "kind": "Content", + "text": ", c2: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ", r2: " + }, + { + "kind": "Content", + "text": "number" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Reference", + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" + }, + { + "kind": "Content", + "text": "[]" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/primitives/intersect.ts", + "returnTypeTokenRange": { + "startIndex": 9, + "endIndex": 11 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "c1", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "isOptional": false + }, + { + "parameterName": "r1", + "parameterTypeTokenRange": { + "startIndex": 3, + "endIndex": 4 + }, + "isOptional": false + }, + { + "parameterName": "c2", + "parameterTypeTokenRange": { + "startIndex": 5, + "endIndex": 6 + }, + "isOptional": false + }, + { + "parameterName": "r2", + "parameterTypeTokenRange": { + "startIndex": 7, + "endIndex": 8 + }, + "isOptional": false + } + ], + "name": "intersectCircleCircle" + }, + { + "kind": "Function", + "canonicalReference": "@tldraw/editor!intersectCirclePolygon:function(1)", + "docComment": "/**\n * Find the intersections between a circle and a bounding box.\n *\n * @param c - The circle's center.\n *\n * @param r - The circle's radius.\n *\n * @param points - The points in the polygon.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export declare function intersectCirclePolygon(c: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ", r: " + }, + { + "kind": "Content", + "text": "number" + }, + { + "kind": "Content", + "text": ", points: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": "[]" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Content", + "text": "null | " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": "[]" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/primitives/intersect.ts", + "returnTypeTokenRange": { + "startIndex": 8, + "endIndex": 11 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "c", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "isOptional": false + }, + { + "parameterName": "r", + "parameterTypeTokenRange": { + "startIndex": 3, + "endIndex": 4 + }, + "isOptional": false + }, + { + "parameterName": "points", + "parameterTypeTokenRange": { + "startIndex": 5, + "endIndex": 7 + }, + "isOptional": false + } + ], + "name": "intersectCirclePolygon" + }, + { + "kind": "Function", + "canonicalReference": "@tldraw/editor!intersectCirclePolyline:function(1)", + "docComment": "/**\n * Find the intersections between a circle and a bounding box.\n *\n * @param c - The circle's center.\n *\n * @param r - The circle's radius.\n *\n * @param points - The points in the polyline.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export declare function intersectCirclePolyline(c: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ", r: " + }, + { + "kind": "Content", + "text": "number" + }, + { + "kind": "Content", + "text": ", points: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": "[]" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Content", + "text": "null | " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": "[]" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/primitives/intersect.ts", + "returnTypeTokenRange": { + "startIndex": 8, + "endIndex": 11 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "c", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "isOptional": false + }, + { + "parameterName": "r", + "parameterTypeTokenRange": { + "startIndex": 3, + "endIndex": 4 + }, + "isOptional": false + }, + { + "parameterName": "points", + "parameterTypeTokenRange": { + "startIndex": 5, + "endIndex": 7 + }, + "isOptional": false + } + ], + "name": "intersectCirclePolyline" + }, + { + "kind": "Function", + "canonicalReference": "@tldraw/editor!intersectLineSegmentCircle:function(1)", + "docComment": "/**\n * Find the intersections between a line segment and a circle.\n *\n * @param a1 - The segment's first point.\n *\n * @param a2 - The segment's second point.\n *\n * @param c - The circle's center.\n *\n * @param r - The circle's radius.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export declare function intersectLineSegmentCircle(a1: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ", a2: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ", c: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ", r: " + }, + { + "kind": "Content", + "text": "number" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Content", + "text": "null | " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": "[]" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/primitives/intersect.ts", + "returnTypeTokenRange": { + "startIndex": 9, + "endIndex": 12 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "a1", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "isOptional": false + }, + { + "parameterName": "a2", + "parameterTypeTokenRange": { + "startIndex": 3, + "endIndex": 4 + }, + "isOptional": false + }, + { + "parameterName": "c", + "parameterTypeTokenRange": { + "startIndex": 5, + "endIndex": 6 + }, + "isOptional": false + }, + { + "parameterName": "r", + "parameterTypeTokenRange": { + "startIndex": 7, + "endIndex": 8 + }, + "isOptional": false + } + ], + "name": "intersectLineSegmentCircle" + }, + { + "kind": "Function", + "canonicalReference": "@tldraw/editor!intersectLineSegmentLineSegment:function(1)", + "docComment": "/**\n * Find the intersection between a line segment and a line segment.\n *\n * @param a1 - The first segment's first point.\n *\n * @param a2 - The first segment's second point.\n *\n * @param b1 - The second segment's first point.\n *\n * @param b2 - The second segment's second point.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export declare function intersectLineSegmentLineSegment(a1: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ", a2: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ", b1: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ", b2: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Content", + "text": "null | " + }, + { + "kind": "Reference", + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/primitives/intersect.ts", + "returnTypeTokenRange": { + "startIndex": 9, + "endIndex": 11 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "a1", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "isOptional": false + }, + { + "parameterName": "a2", + "parameterTypeTokenRange": { + "startIndex": 3, + "endIndex": 4 + }, + "isOptional": false + }, + { + "parameterName": "b1", + "parameterTypeTokenRange": { + "startIndex": 5, + "endIndex": 6 + }, + "isOptional": false + }, + { + "parameterName": "b2", + "parameterTypeTokenRange": { + "startIndex": 7, + "endIndex": 8 + }, + "isOptional": false + } + ], + "name": "intersectLineSegmentLineSegment" + }, { "kind": "Function", "canonicalReference": "@tldraw/editor!intersectLineSegmentPolygon:function(1)", @@ -23800,6 +23748,82 @@ ], "name": "intersectLineSegmentPolyline" }, + { + "kind": "Function", + "canonicalReference": "@tldraw/editor!intersectPolygonBounds:function(1)", + "docComment": "/**\n * Find the intersections between a polygon and a bounding box.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export declare function intersectPolygonBounds(points: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": "[]" + }, + { + "kind": "Content", + "text": ", bounds: " + }, + { + "kind": "Reference", + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Content", + "text": "null | " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": "[]" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/primitives/intersect.ts", + "returnTypeTokenRange": { + "startIndex": 6, + "endIndex": 9 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "points", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 3 + }, + "isOptional": false + }, + { + "parameterName": "bounds", + "parameterTypeTokenRange": { + "startIndex": 4, + "endIndex": 5 + }, + "isOptional": false + } + ], + "name": "intersectPolygonBounds" + }, { "kind": "Function", "canonicalReference": "@tldraw/editor!intersectPolygonPolygon:function(1)", @@ -23880,83 +23904,6 @@ ], "name": "intersectPolygonPolygon" }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!isAngleBetween:function(1)", - "docComment": "/**\n * Is angle c between angles a and b?\n *\n * @param a - The first angle.\n *\n * @param b - The second angle.\n *\n * @param c - The third angle.\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function isAngleBetween(a: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ", b: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ", c: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "boolean" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 7, - "endIndex": 8 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "a", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "b", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - }, - { - "parameterName": "c", - "parameterTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, - "isOptional": false - } - ], - "name": "isAngleBetween" - }, { "kind": "Variable", "canonicalReference": "@tldraw/editor!isSafeFloat:var", @@ -23980,83 +23927,6 @@ "endIndex": 2 } }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!lerpAngles:function(1)", - "docComment": "/**\n * Interpolate an angle between two angles.\n *\n * @param a0 - The first angle.\n *\n * @param a1 - The second angle.\n *\n * @param t - The interpolation value.\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function lerpAngles(a0: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ", a1: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ", t: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 7, - "endIndex": 8 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "a0", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "a1", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - }, - { - "parameterName": "t", - "parameterTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, - "isOptional": false - } - ], - "name": "lerpAngles" - }, { "kind": "Function", "canonicalReference": "@tldraw/editor!linesIntersect:function(1)", @@ -24263,67 +24133,6 @@ ], "name": "loadSessionStateSnapshotIntoStore" }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!longAngleDist:function(1)", - "docComment": "/**\n * Get the long angle distance between two angles.\n *\n * @param a0 - The first angle.\n *\n * @param a1 - The second angle.\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function longAngleDist(a0: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ", a1: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "a0", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "a1", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - } - ], - "name": "longAngleDist" - }, { "kind": "Function", "canonicalReference": "@tldraw/editor!loopToHtmlElement:function(1)", @@ -24373,24 +24182,24 @@ }, { "kind": "Class", - "canonicalReference": "@tldraw/editor!Matrix2d:class", + "canonicalReference": "@tldraw/editor!Mat:class", "docComment": "/**\n * @public\n */\n", "excerptTokens": [ { "kind": "Content", - "text": "export declare class Matrix2d " + "text": "export declare class Mat " } ], - "fileUrlPath": "packages/editor/src/lib/primitives/Matrix2d.ts", + "fileUrlPath": "packages/editor/src/lib/primitives/Mat.ts", "releaseTag": "Public", "isAbstract": false, - "name": "Matrix2d", + "name": "Mat", "preserveMemberOrder": false, "members": [ { "kind": "Constructor", - "canonicalReference": "@tldraw/editor!Matrix2d:constructor(1)", - "docComment": "/**\n * Constructs a new instance of the `Matrix2d` class\n */\n", + "canonicalReference": "@tldraw/editor!Mat:constructor(1)", + "docComment": "/**\n * Constructs a new instance of the `Mat` class\n */\n", "excerptTokens": [ { "kind": "Content", @@ -24501,7 +24310,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Matrix2d#a:member", + "canonicalReference": "@tldraw/editor!Mat#a:member", "docComment": "", "excerptTokens": [ { @@ -24531,7 +24340,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.Absolute:member(1)", + "canonicalReference": "@tldraw/editor!Mat.Absolute:member(1)", "docComment": "", "excerptTokens": [ { @@ -24541,7 +24350,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -24549,8 +24358,8 @@ }, { "kind": "Reference", - "text": "Matrix2dModel", - "canonicalReference": "@tldraw/editor!Matrix2dModel:interface" + "text": "MatModel", + "canonicalReference": "@tldraw/editor!MatModel:interface" }, { "kind": "Content", @@ -24581,7 +24390,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.applyToBounds:member(1)", + "canonicalReference": "@tldraw/editor!Mat.applyToBounds:member(1)", "docComment": "", "excerptTokens": [ { @@ -24591,7 +24400,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -24599,8 +24408,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -24608,8 +24417,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -24648,7 +24457,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#applyToPoint:member(1)", + "canonicalReference": "@tldraw/editor!Mat#applyToPoint:member(1)", "docComment": "", "excerptTokens": [ { @@ -24666,8 +24475,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -24698,7 +24507,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.applyToPoint:member(1)", + "canonicalReference": "@tldraw/editor!Mat.applyToPoint:member(1)", "docComment": "", "excerptTokens": [ { @@ -24708,7 +24517,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -24725,8 +24534,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -24765,7 +24574,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#applyToPoints:member(1)", + "canonicalReference": "@tldraw/editor!Mat#applyToPoints:member(1)", "docComment": "", "excerptTokens": [ { @@ -24787,8 +24596,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -24823,7 +24632,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.applyToPoints:member(1)", + "canonicalReference": "@tldraw/editor!Mat.applyToPoints:member(1)", "docComment": "", "excerptTokens": [ { @@ -24833,7 +24642,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -24854,8 +24663,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -24898,7 +24707,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.applyToXY:member(1)", + "canonicalReference": "@tldraw/editor!Mat.applyToXY:member(1)", "docComment": "", "excerptTokens": [ { @@ -24908,7 +24717,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -24979,7 +24788,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Matrix2d#b:member", + "canonicalReference": "@tldraw/editor!Mat#b:member", "docComment": "", "excerptTokens": [ { @@ -25009,7 +24818,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Matrix2d#c:member", + "canonicalReference": "@tldraw/editor!Mat#c:member", "docComment": "", "excerptTokens": [ { @@ -25039,7 +24848,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.Cast:member(1)", + "canonicalReference": "@tldraw/editor!Mat.Cast:member(1)", "docComment": "", "excerptTokens": [ { @@ -25049,7 +24858,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -25057,8 +24866,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -25089,7 +24898,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#clone:member(1)", + "canonicalReference": "@tldraw/editor!Mat#clone:member(1)", "docComment": "", "excerptTokens": [ { @@ -25098,8 +24907,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -25121,7 +24930,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.Compose:member(1)", + "canonicalReference": "@tldraw/editor!Mat.Compose:member(1)", "docComment": "", "excerptTokens": [ { @@ -25131,7 +24940,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -25143,8 +24952,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -25175,7 +24984,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Matrix2d#d:member", + "canonicalReference": "@tldraw/editor!Mat#d:member", "docComment": "", "excerptTokens": [ { @@ -25205,7 +25014,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#decompose:member(1)", + "canonicalReference": "@tldraw/editor!Mat#decompose:member(1)", "docComment": "", "excerptTokens": [ { @@ -25213,9 +25022,8 @@ "text": "decompose(): " }, { - "kind": "Reference", - "text": "MatrixInfo", - "canonicalReference": "@tldraw/editor!~MatrixInfo:interface" + "kind": "Content", + "text": "{\n x: number;\n y: number;\n scaleX: number;\n scaleY: number;\n rotation: number;\n }" }, { "kind": "Content", @@ -25237,7 +25045,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.Decompose:member(1)", + "canonicalReference": "@tldraw/editor!Mat.Decompose:member(1)", "docComment": "", "excerptTokens": [ { @@ -25247,16 +25055,15 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", "text": "): " }, { - "kind": "Reference", - "text": "MatrixInfo", - "canonicalReference": "@tldraw/editor!~MatrixInfo:interface" + "kind": "Content", + "text": "{\n x: number;\n y: number;\n scaleX: number;\n scaleY: number;\n rotation: number;\n }" }, { "kind": "Content", @@ -25287,7 +25094,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#decomposed:member(1)", + "canonicalReference": "@tldraw/editor!Mat#decomposed:member(1)", "docComment": "", "excerptTokens": [ { @@ -25295,9 +25102,8 @@ "text": "decomposed(): " }, { - "kind": "Reference", - "text": "MatrixInfo", - "canonicalReference": "@tldraw/editor!~MatrixInfo:interface" + "kind": "Content", + "text": "{\n x: number;\n y: number;\n scaleX: number;\n scaleY: number;\n rotation: number;\n }" }, { "kind": "Content", @@ -25319,7 +25125,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Matrix2d#e:member", + "canonicalReference": "@tldraw/editor!Mat#e:member", "docComment": "", "excerptTokens": [ { @@ -25349,7 +25155,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#equals:member(1)", + "canonicalReference": "@tldraw/editor!Mat#equals:member(1)", "docComment": "", "excerptTokens": [ { @@ -25358,8 +25164,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -25367,8 +25173,8 @@ }, { "kind": "Reference", - "text": "Matrix2dModel", - "canonicalReference": "@tldraw/editor!Matrix2dModel:interface" + "text": "MatModel", + "canonicalReference": "@tldraw/editor!MatModel:interface" }, { "kind": "Content", @@ -25407,7 +25213,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Matrix2d#f:member", + "canonicalReference": "@tldraw/editor!Mat#f:member", "docComment": "", "excerptTokens": [ { @@ -25437,7 +25243,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.From:member(1)", + "canonicalReference": "@tldraw/editor!Mat.From:member(1)", "docComment": "", "excerptTokens": [ { @@ -25447,7 +25253,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -25455,8 +25261,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -25487,7 +25293,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#identity:member(1)", + "canonicalReference": "@tldraw/editor!Mat#identity:member(1)", "docComment": "", "excerptTokens": [ { @@ -25518,7 +25324,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.Identity:member(1)", + "canonicalReference": "@tldraw/editor!Mat.Identity:member(1)", "docComment": "", "excerptTokens": [ { @@ -25527,8 +25333,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -25550,7 +25356,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.Inverse:member(1)", + "canonicalReference": "@tldraw/editor!Mat.Inverse:member(1)", "docComment": "", "excerptTokens": [ { @@ -25559,8 +25365,8 @@ }, { "kind": "Reference", - "text": "Matrix2dModel", - "canonicalReference": "@tldraw/editor!Matrix2dModel:interface" + "text": "MatModel", + "canonicalReference": "@tldraw/editor!MatModel:interface" }, { "kind": "Content", @@ -25568,8 +25374,8 @@ }, { "kind": "Reference", - "text": "Matrix2dModel", - "canonicalReference": "@tldraw/editor!Matrix2dModel:interface" + "text": "MatModel", + "canonicalReference": "@tldraw/editor!MatModel:interface" }, { "kind": "Content", @@ -25600,7 +25406,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#invert:member(1)", + "canonicalReference": "@tldraw/editor!Mat#invert:member(1)", "docComment": "", "excerptTokens": [ { @@ -25631,7 +25437,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#multiply:member(1)", + "canonicalReference": "@tldraw/editor!Mat#multiply:member(1)", "docComment": "", "excerptTokens": [ { @@ -25640,8 +25446,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -25649,8 +25455,8 @@ }, { "kind": "Reference", - "text": "Matrix2dModel", - "canonicalReference": "@tldraw/editor!Matrix2dModel:interface" + "text": "MatModel", + "canonicalReference": "@tldraw/editor!MatModel:interface" }, { "kind": "Content", @@ -25689,7 +25495,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.Multiply:member(1)", + "canonicalReference": "@tldraw/editor!Mat.Multiply:member(1)", "docComment": "", "excerptTokens": [ { @@ -25698,8 +25504,8 @@ }, { "kind": "Reference", - "text": "Matrix2dModel", - "canonicalReference": "@tldraw/editor!Matrix2dModel:interface" + "text": "MatModel", + "canonicalReference": "@tldraw/editor!MatModel:interface" }, { "kind": "Content", @@ -25707,8 +25513,8 @@ }, { "kind": "Reference", - "text": "Matrix2dModel", - "canonicalReference": "@tldraw/editor!Matrix2dModel:interface" + "text": "MatModel", + "canonicalReference": "@tldraw/editor!MatModel:interface" }, { "kind": "Content", @@ -25716,8 +25522,8 @@ }, { "kind": "Reference", - "text": "Matrix2dModel", - "canonicalReference": "@tldraw/editor!Matrix2dModel:interface" + "text": "MatModel", + "canonicalReference": "@tldraw/editor!MatModel:interface" }, { "kind": "Content", @@ -25756,7 +25562,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#point:member(1)", + "canonicalReference": "@tldraw/editor!Mat#point:member(1)", "docComment": "", "excerptTokens": [ { @@ -25765,8 +25571,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -25788,7 +25594,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.Point:member(1)", + "canonicalReference": "@tldraw/editor!Mat.Point:member(1)", "docComment": "", "excerptTokens": [ { @@ -25798,7 +25604,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -25806,8 +25612,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -25838,7 +25644,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#rotate:member(1)", + "canonicalReference": "@tldraw/editor!Mat#rotate:member(1)", "docComment": "", "excerptTokens": [ { @@ -25871,8 +25677,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -25919,7 +25725,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.Rotate:member(1)", + "canonicalReference": "@tldraw/editor!Mat.Rotate:member(1)", "docComment": "", "excerptTokens": [ { @@ -25952,8 +25758,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -26000,7 +25806,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#rotation:member(1)", + "canonicalReference": "@tldraw/editor!Mat#rotation:member(1)", "docComment": "", "excerptTokens": [ { @@ -26031,7 +25837,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.Rotation:member(1)", + "canonicalReference": "@tldraw/editor!Mat.Rotation:member(1)", "docComment": "", "excerptTokens": [ { @@ -26041,7 +25847,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -26080,7 +25886,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#scale:member(1)", + "canonicalReference": "@tldraw/editor!Mat#scale:member(1)", "docComment": "", "excerptTokens": [ { @@ -26144,7 +25950,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Matrix2d.Scale:member", + "canonicalReference": "@tldraw/editor!Mat.Scale:member", "docComment": "", "excerptTokens": [ { @@ -26157,8 +25963,8 @@ }, { "kind": "Reference", - "text": "Matrix2dModel", - "canonicalReference": "@tldraw/editor!Matrix2dModel:interface" + "text": "MatModel", + "canonicalReference": "@tldraw/editor!MatModel:interface" }, { "kind": "Content", @@ -26166,8 +25972,8 @@ }, { "kind": "Reference", - "text": "Matrix2dModel", - "canonicalReference": "@tldraw/editor!Matrix2dModel:interface" + "text": "MatModel", + "canonicalReference": "@tldraw/editor!MatModel:interface" }, { "kind": "Content", @@ -26192,7 +25998,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#setTo:member(1)", + "canonicalReference": "@tldraw/editor!Mat#setTo:member(1)", "docComment": "", "excerptTokens": [ { @@ -26201,8 +26007,8 @@ }, { "kind": "Reference", - "text": "Matrix2dModel", - "canonicalReference": "@tldraw/editor!Matrix2dModel:interface" + "text": "MatModel", + "canonicalReference": "@tldraw/editor!MatModel:interface" }, { "kind": "Content", @@ -26241,7 +26047,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.Smooth:member(1)", + "canonicalReference": "@tldraw/editor!Mat.Smooth:member(1)", "docComment": "", "excerptTokens": [ { @@ -26251,7 +26057,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -26268,7 +26074,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -26307,7 +26113,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#toCssString:member(1)", + "canonicalReference": "@tldraw/editor!Mat#toCssString:member(1)", "docComment": "", "excerptTokens": [ { @@ -26338,7 +26144,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.toCssString:member(1)", + "canonicalReference": "@tldraw/editor!Mat.toCssString:member(1)", "docComment": "", "excerptTokens": [ { @@ -26348,7 +26154,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -26387,7 +26193,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d#translate:member(1)", + "canonicalReference": "@tldraw/editor!Mat#translate:member(1)", "docComment": "", "excerptTokens": [ { @@ -26412,8 +26218,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -26452,7 +26258,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Matrix2d.Translate:member(1)", + "canonicalReference": "@tldraw/editor!Mat.Translate:member(1)", "docComment": "", "excerptTokens": [ { @@ -26477,8 +26283,8 @@ }, { "kind": "Reference", - "text": "Matrix2d", - "canonicalReference": "@tldraw/editor!Matrix2d:class" + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" }, { "kind": "Content", @@ -26519,23 +26325,59 @@ "implementsTokenRanges": [] }, { - "kind": "Interface", - "canonicalReference": "@tldraw/editor!Matrix2dModel:interface", + "kind": "TypeAlias", + "canonicalReference": "@tldraw/editor!MatLike:type", "docComment": "/**\n * @public\n */\n", "excerptTokens": [ { "kind": "Content", - "text": "export interface Matrix2dModel " + "text": "export type MatLike = " + }, + { + "kind": "Reference", + "text": "Mat", + "canonicalReference": "@tldraw/editor!Mat:class" + }, + { + "kind": "Content", + "text": " | " + }, + { + "kind": "Reference", + "text": "MatModel", + "canonicalReference": "@tldraw/editor!MatModel:interface" + }, + { + "kind": "Content", + "text": ";" } ], - "fileUrlPath": "packages/editor/src/lib/primitives/Matrix2d.ts", + "fileUrlPath": "packages/editor/src/lib/primitives/Mat.ts", "releaseTag": "Public", - "name": "Matrix2dModel", + "name": "MatLike", + "typeTokenRange": { + "startIndex": 1, + "endIndex": 4 + } + }, + { + "kind": "Interface", + "canonicalReference": "@tldraw/editor!MatModel:interface", + "docComment": "/**\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface MatModel " + } + ], + "fileUrlPath": "packages/editor/src/lib/primitives/Mat.ts", + "releaseTag": "Public", + "name": "MatModel", "preserveMemberOrder": false, "members": [ { "kind": "PropertySignature", - "canonicalReference": "@tldraw/editor!Matrix2dModel#a:member", + "canonicalReference": "@tldraw/editor!MatModel#a:member", "docComment": "", "excerptTokens": [ { @@ -26562,7 +26404,7 @@ }, { "kind": "PropertySignature", - "canonicalReference": "@tldraw/editor!Matrix2dModel#b:member", + "canonicalReference": "@tldraw/editor!MatModel#b:member", "docComment": "", "excerptTokens": [ { @@ -26589,7 +26431,7 @@ }, { "kind": "PropertySignature", - "canonicalReference": "@tldraw/editor!Matrix2dModel#c:member", + "canonicalReference": "@tldraw/editor!MatModel#c:member", "docComment": "", "excerptTokens": [ { @@ -26616,7 +26458,7 @@ }, { "kind": "PropertySignature", - "canonicalReference": "@tldraw/editor!Matrix2dModel#d:member", + "canonicalReference": "@tldraw/editor!MatModel#d:member", "docComment": "", "excerptTokens": [ { @@ -26643,7 +26485,7 @@ }, { "kind": "PropertySignature", - "canonicalReference": "@tldraw/editor!Matrix2dModel#e:member", + "canonicalReference": "@tldraw/editor!MatModel#e:member", "docComment": "", "excerptTokens": [ { @@ -26670,7 +26512,7 @@ }, { "kind": "PropertySignature", - "canonicalReference": "@tldraw/editor!Matrix2dModel#f:member", + "canonicalReference": "@tldraw/editor!MatModel#f:member", "docComment": "", "excerptTokens": [ { @@ -26913,257 +26755,272 @@ } }, { - "kind": "Function", - "canonicalReference": "@tldraw/editor!pointInBounds:function(1)", - "docComment": "/**\n * Get whether a point is inside of a bounds.\n *\n * @param A - The point to check.\n *\n * @param b - The bounds to check.\n *\n * @returns Boolean\n *\n * @public\n */\n", + "kind": "Class", + "canonicalReference": "@tldraw/editor!Point2d:class", + "docComment": "/**\n * @public\n */\n", "excerptTokens": [ { "kind": "Content", - "text": "export declare function pointInBounds(A: " + "text": "export declare class Point2d extends " }, { "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" + "text": "Geometry2d", + "canonicalReference": "@tldraw/editor!Geometry2d:class" }, { "kind": "Content", - "text": ", b: " - }, - { - "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "boolean" - }, - { - "kind": "Content", - "text": ";" + "text": " " } ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, + "fileUrlPath": "packages/editor/src/lib/primitives/geometry/Point2d.ts", "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ + "isAbstract": false, + "name": "Point2d", + "preserveMemberOrder": false, + "members": [ { - "parameterName": "A", - "parameterTypeTokenRange": { + "kind": "Constructor", + "canonicalReference": "@tldraw/editor!Point2d:constructor(1)", + "docComment": "/**\n * Constructs a new instance of the `Point2d` class\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "constructor(config: " + }, + { + "kind": "Reference", + "text": "Omit", + "canonicalReference": "!Omit:type" + }, + { + "kind": "Content", + "text": "<" + }, + { + "kind": "Reference", + "text": "Geometry2dOptions", + "canonicalReference": "@tldraw/editor!~Geometry2dOptions:interface" + }, + { + "kind": "Content", + "text": ", 'isClosed' | 'isFilled'> & {\n margin: number;\n point: " + }, + { + "kind": "Reference", + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" + }, + { + "kind": "Content", + "text": ";\n }" + }, + { + "kind": "Content", + "text": ");" + } + ], + "releaseTag": "Public", + "isProtected": false, + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "config", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 7 + }, + "isOptional": false + } + ] + }, + { + "kind": "Method", + "canonicalReference": "@tldraw/editor!Point2d#getVertices:member(1)", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "getVertices(): " + }, + { + "kind": "Reference", + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" + }, + { + "kind": "Content", + "text": "[]" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isStatic": false, + "returnTypeTokenRange": { "startIndex": 1, - "endIndex": 2 + "endIndex": 3 }, - "isOptional": false + "releaseTag": "Public", + "isProtected": false, + "overloadIndex": 1, + "parameters": [], + "isOptional": false, + "isAbstract": false, + "name": "getVertices" }, { - "parameterName": "b", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - } - ], - "name": "pointInBounds" - }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!pointInCircle:function(1)", - "docComment": "/**\n * Get whether a point is inside of a circle.\n *\n * @param A - The point to check.\n *\n * @param C - The circle's center point as [x, y].\n *\n * @param r - The circle's radius.\n *\n * @returns Boolean\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function pointInCircle(A: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", C: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", r: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "boolean" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 7, - "endIndex": 8 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "A", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "C", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - }, - { - "parameterName": "r", - "parameterTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, - "isOptional": false - } - ], - "name": "pointInCircle" - }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!pointInEllipse:function(1)", - "docComment": "/**\n * Get whether a point is inside of an ellipse.\n *\n * @param point - The point to check.\n *\n * @param center - The ellipse's center point as [x, y].\n *\n * @param rx - The ellipse's x radius.\n *\n * @param ry - The ellipse's y radius.\n *\n * @param rotation - The ellipse's rotation.\n *\n * @returns Boolean\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function pointInEllipse(A: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", C: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", rx: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ", ry: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": ", rotation?: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "boolean" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 11, - "endIndex": 12 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "A", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "C", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - }, - { - "parameterName": "rx", - "parameterTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, - "isOptional": false - }, - { - "parameterName": "ry", - "parameterTypeTokenRange": { + "kind": "Method", + "canonicalReference": "@tldraw/editor!Point2d#hitTestLineSegment:member(1)", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "hitTestLineSegment(A: " + }, + { + "kind": "Reference", + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" + }, + { + "kind": "Content", + "text": ", B: " + }, + { + "kind": "Reference", + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" + }, + { + "kind": "Content", + "text": ", margin: " + }, + { + "kind": "Content", + "text": "number" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Content", + "text": "boolean" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isStatic": false, + "returnTypeTokenRange": { "startIndex": 7, "endIndex": 8 }, - "isOptional": false + "releaseTag": "Public", + "isProtected": false, + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "A", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "isOptional": false + }, + { + "parameterName": "B", + "parameterTypeTokenRange": { + "startIndex": 3, + "endIndex": 4 + }, + "isOptional": false + }, + { + "parameterName": "margin", + "parameterTypeTokenRange": { + "startIndex": 5, + "endIndex": 6 + }, + "isOptional": false + } + ], + "isOptional": false, + "isAbstract": false, + "name": "hitTestLineSegment" }, { - "parameterName": "rotation", - "parameterTypeTokenRange": { - "startIndex": 9, - "endIndex": 10 + "kind": "Method", + "canonicalReference": "@tldraw/editor!Point2d#nearestPoint:member(1)", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "nearestPoint(): " + }, + { + "kind": "Reference", + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isStatic": false, + "returnTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 }, - "isOptional": true + "releaseTag": "Public", + "isProtected": false, + "overloadIndex": 1, + "parameters": [], + "isOptional": false, + "isAbstract": false, + "name": "nearestPoint" + }, + { + "kind": "Property", + "canonicalReference": "@tldraw/editor!Point2d#point:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "point: " + }, + { + "kind": "Reference", + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "point", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "isStatic": false, + "isProtected": false, + "isAbstract": false } ], - "name": "pointInEllipse" + "extendsTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "implementsTokenRanges": [] }, { "kind": "Function", @@ -27232,348 +27089,6 @@ ], "name": "pointInPolygon" }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!pointInPolyline:function(1)", - "docComment": "/**\n * Hit test a point and a polyline using a minimum distance.\n *\n * @param A - The point to check.\n *\n * @param points - The points that make up the polyline.\n *\n * @param distance - The mininum distance that qualifies a hit.\n *\n * @returns Boolean\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function pointInPolyline(A: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", points: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": "[]" - }, - { - "kind": "Content", - "text": ", distance?: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "boolean" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 8, - "endIndex": 9 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "A", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "points", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 5 - }, - "isOptional": false - }, - { - "parameterName": "distance", - "parameterTypeTokenRange": { - "startIndex": 6, - "endIndex": 7 - }, - "isOptional": true - } - ], - "name": "pointInPolyline" - }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!pointInRect:function(1)", - "docComment": "/**\n * Get whether a point is inside of a rectangle.\n *\n * @param A - The point to check.\n *\n * @param point - The rectangle's top left point as [x, y].\n *\n * @param size - The rectangle's size as [width, height].\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function pointInRect(A: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", point: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", size: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "boolean" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 7, - "endIndex": 8 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "A", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "point", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - }, - { - "parameterName": "size", - "parameterTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, - "isOptional": false - } - ], - "name": "pointInRect" - }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!pointNearToLineSegment:function(1)", - "docComment": "/**\n * Get whether a point is within a certain distance from a line segment.\n *\n * @param A - The point to check.\n *\n * @param p1 - The polyline's first point.\n *\n * @param p2 - The polyline's second point.\n *\n * @param distance - The mininum distance that qualifies a hit.\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function pointNearToLineSegment(A: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", p1: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", p2: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", distance?: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "boolean" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 9, - "endIndex": 10 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "A", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "p1", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 4 - }, - "isOptional": false - }, - { - "parameterName": "p2", - "parameterTypeTokenRange": { - "startIndex": 5, - "endIndex": 6 - }, - "isOptional": false - }, - { - "parameterName": "distance", - "parameterTypeTokenRange": { - "startIndex": 7, - "endIndex": 8 - }, - "isOptional": true - } - ], - "name": "pointNearToLineSegment" - }, - { - "kind": "Function", - "canonicalReference": "@tldraw/editor!pointNearToPolyline:function(1)", - "docComment": "/**\n * Get whether a point is within a certain distance from a polyline.\n *\n * @param A - The point to check.\n *\n * @param points - The points that make up the polyline.\n *\n * @param distance - The mininum distance that qualifies a hit.\n *\n * @public\n */\n", - "excerptTokens": [ - { - "kind": "Content", - "text": "export declare function pointNearToPolyline(A: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": ", points: " - }, - { - "kind": "Reference", - "text": "VecLike", - "canonicalReference": "@tldraw/editor!VecLike:type" - }, - { - "kind": "Content", - "text": "[]" - }, - { - "kind": "Content", - "text": ", distance?: " - }, - { - "kind": "Content", - "text": "number" - }, - { - "kind": "Content", - "text": "): " - }, - { - "kind": "Content", - "text": "boolean" - }, - { - "kind": "Content", - "text": ";" - } - ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "returnTypeTokenRange": { - "startIndex": 8, - "endIndex": 9 - }, - "releaseTag": "Public", - "overloadIndex": 1, - "parameters": [ - { - "parameterName": "A", - "parameterTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 - }, - "isOptional": false - }, - { - "parameterName": "points", - "parameterTypeTokenRange": { - "startIndex": 3, - "endIndex": 5 - }, - "isOptional": false - }, - { - "parameterName": "distance", - "parameterTypeTokenRange": { - "startIndex": 6, - "endIndex": 7 - }, - "isOptional": true - } - ], - "name": "pointNearToPolyline" - }, { "kind": "TypeAlias", "canonicalReference": "@tldraw/editor!PointsSnapLine:type", @@ -27663,8 +27178,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -27886,8 +27401,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -27923,8 +27438,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -27959,8 +27474,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -27968,8 +27483,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -28071,8 +27586,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -28080,8 +27595,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -28121,8 +27636,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -29082,8 +28597,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -29448,8 +28963,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -29475,8 +28990,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -29597,7 +29112,7 @@ "text": "{\n readonly top_left_rotate: \"top_left\";\n readonly top_right_rotate: \"top_right\";\n readonly bottom_right_rotate: \"bottom_right\";\n readonly bottom_left_rotate: \"bottom_left\";\n readonly mobile_rotate: \"top_left\";\n}" } ], - "fileUrlPath": "packages/editor/src/lib/primitives/Box2d.ts", + "fileUrlPath": "packages/editor/src/lib/primitives/Box.ts", "isReadonly": true, "releaseTag": "Public", "name": "ROTATE_CORNER_TO_SELECTION_CORNER", @@ -29624,7 +29139,7 @@ "text": ";" } ], - "fileUrlPath": "packages/editor/src/lib/primitives/Box2d.ts", + "fileUrlPath": "packages/editor/src/lib/primitives/Box.ts", "releaseTag": "Public", "name": "RotateCorner", "typeTokenRange": { @@ -29668,7 +29183,7 @@ "text": ";" } ], - "fileUrlPath": "packages/editor/src/lib/primitives/Box2d.ts", + "fileUrlPath": "packages/editor/src/lib/primitives/Box.ts", "returnTypeTokenRange": { "startIndex": 5, "endIndex": 6 @@ -29736,7 +29251,7 @@ "text": ";" } ], - "fileUrlPath": "packages/editor/src/lib/primitives/Box2d.ts", + "fileUrlPath": "packages/editor/src/lib/primitives/Box.ts", "releaseTag": "Public", "name": "SelectionCorner", "typeTokenRange": { @@ -29762,7 +29277,7 @@ "text": ";" } ], - "fileUrlPath": "packages/editor/src/lib/primitives/Box2d.ts", + "fileUrlPath": "packages/editor/src/lib/primitives/Box.ts", "releaseTag": "Public", "name": "SelectionEdge", "typeTokenRange": { @@ -29798,7 +29313,7 @@ "text": ";" } ], - "fileUrlPath": "packages/editor/src/lib/primitives/Box2d.ts", + "fileUrlPath": "packages/editor/src/lib/primitives/Box.ts", "releaseTag": "Public", "name": "SelectionHandle", "typeTokenRange": { @@ -30793,8 +30308,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -32479,8 +31994,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -32591,8 +32106,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -32600,8 +32115,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -32617,8 +32132,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -32862,8 +32377,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -32871,8 +32386,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -32956,8 +32471,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -32965,8 +32480,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -33346,8 +32861,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -35127,26 +34642,147 @@ } }, { - "kind": "Variable", - "canonicalReference": "@tldraw/editor!TAU:var", + "kind": "TypeAlias", + "canonicalReference": "@tldraw/editor!TLAfterChangeHandler:type", "docComment": "/**\n * @public\n */\n", "excerptTokens": [ { "kind": "Content", - "text": "TAU: " + "text": "export type TLAfterChangeHandler = " + }, + { + "kind": "Content", + "text": "(prev: R, next: R, source: 'remote' | 'user') => void" + }, + { + "kind": "Content", + "text": ";" } ], - "fileUrlPath": "packages/editor/src/lib/primitives/utils.ts", - "isReadonly": true, + "fileUrlPath": "packages/editor/src/lib/editor/managers/SideEffectManager.ts", "releaseTag": "Public", - "name": "TAU", - "variableTypeTokenRange": { - "startIndex": 1, - "endIndex": 2 + "name": "TLAfterChangeHandler", + "typeParameters": [ + { + "typeParameterName": "R", + "constraintTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "defaultTypeTokenRange": { + "startIndex": 0, + "endIndex": 0 + } + } + ], + "typeTokenRange": { + "startIndex": 3, + "endIndex": 4 + } + }, + { + "kind": "TypeAlias", + "canonicalReference": "@tldraw/editor!TLAfterCreateHandler:type", + "docComment": "/**\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export type TLAfterCreateHandler = " + }, + { + "kind": "Content", + "text": "(record: R, source: 'remote' | 'user') => void" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/editor/managers/SideEffectManager.ts", + "releaseTag": "Public", + "name": "TLAfterCreateHandler", + "typeParameters": [ + { + "typeParameterName": "R", + "constraintTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "defaultTypeTokenRange": { + "startIndex": 0, + "endIndex": 0 + } + } + ], + "typeTokenRange": { + "startIndex": 3, + "endIndex": 4 + } + }, + { + "kind": "TypeAlias", + "canonicalReference": "@tldraw/editor!TLAfterDeleteHandler:type", + "docComment": "/**\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export type TLAfterDeleteHandler = " + }, + { + "kind": "Content", + "text": "(record: R, source: 'remote' | 'user') => void" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/editor/managers/SideEffectManager.ts", + "releaseTag": "Public", + "name": "TLAfterDeleteHandler", + "typeParameters": [ + { + "typeParameterName": "R", + "constraintTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "defaultTypeTokenRange": { + "startIndex": 0, + "endIndex": 0 + } + } + ], + "typeTokenRange": { + "startIndex": 3, + "endIndex": 4 } }, { @@ -35211,6 +34847,338 @@ "endIndex": 3 } }, + { + "kind": "Interface", + "canonicalReference": "@tldraw/editor!TLArcInfo:interface", + "docComment": "/**\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface TLArcInfo " + } + ], + "fileUrlPath": "packages/editor/src/lib/editor/shapes/shared/arrow/arrow-types.ts", + "releaseTag": "Public", + "name": "TLArcInfo", + "preserveMemberOrder": false, + "members": [ + { + "kind": "PropertySignature", + "canonicalReference": "@tldraw/editor!TLArcInfo#center:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "center: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "center", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@tldraw/editor!TLArcInfo#largeArcFlag:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "largeArcFlag: " + }, + { + "kind": "Content", + "text": "number" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "largeArcFlag", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@tldraw/editor!TLArcInfo#length:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "length: " + }, + { + "kind": "Content", + "text": "number" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "length", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@tldraw/editor!TLArcInfo#radius:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "radius: " + }, + { + "kind": "Content", + "text": "number" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "radius", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@tldraw/editor!TLArcInfo#size:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "size: " + }, + { + "kind": "Content", + "text": "number" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "size", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@tldraw/editor!TLArcInfo#sweepFlag:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "sweepFlag: " + }, + { + "kind": "Content", + "text": "number" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "sweepFlag", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + } + ], + "extendsTokenRanges": [] + }, + { + "kind": "TypeAlias", + "canonicalReference": "@tldraw/editor!TLArrowInfo:type", + "docComment": "/**\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export type TLArrowInfo = " + }, + { + "kind": "Content", + "text": "{\n isStraight: false;\n start: " + }, + { + "kind": "Reference", + "text": "TLArrowPoint", + "canonicalReference": "@tldraw/editor!TLArrowPoint:type" + }, + { + "kind": "Content", + "text": ";\n end: " + }, + { + "kind": "Reference", + "text": "TLArrowPoint", + "canonicalReference": "@tldraw/editor!TLArrowPoint:type" + }, + { + "kind": "Content", + "text": ";\n middle: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ";\n handleArc: " + }, + { + "kind": "Reference", + "text": "TLArcInfo", + "canonicalReference": "@tldraw/editor!TLArcInfo:interface" + }, + { + "kind": "Content", + "text": ";\n bodyArc: " + }, + { + "kind": "Reference", + "text": "TLArcInfo", + "canonicalReference": "@tldraw/editor!TLArcInfo:interface" + }, + { + "kind": "Content", + "text": ";\n isValid: boolean;\n} | {\n isStraight: true;\n start: " + }, + { + "kind": "Reference", + "text": "TLArrowPoint", + "canonicalReference": "@tldraw/editor!TLArrowPoint:type" + }, + { + "kind": "Content", + "text": ";\n end: " + }, + { + "kind": "Reference", + "text": "TLArrowPoint", + "canonicalReference": "@tldraw/editor!TLArrowPoint:type" + }, + { + "kind": "Content", + "text": ";\n middle: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ";\n isValid: boolean;\n length: number;\n}" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/editor/shapes/shared/arrow/arrow-types.ts", + "releaseTag": "Public", + "name": "TLArrowInfo", + "typeTokenRange": { + "startIndex": 1, + "endIndex": 18 + } + }, + { + "kind": "TypeAlias", + "canonicalReference": "@tldraw/editor!TLArrowPoint:type", + "docComment": "/**\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export type TLArrowPoint = " + }, + { + "kind": "Content", + "text": "{\n handle: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ";\n point: " + }, + { + "kind": "Reference", + "text": "VecLike", + "canonicalReference": "@tldraw/editor!VecLike:type" + }, + { + "kind": "Content", + "text": ";\n arrowhead: " + }, + { + "kind": "Reference", + "text": "TLArrowShapeArrowheadStyle", + "canonicalReference": "@tldraw/tlschema!TLArrowShapeArrowheadStyle:type" + }, + { + "kind": "Content", + "text": ";\n}" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/editor/shapes/shared/arrow/arrow-types.ts", + "releaseTag": "Public", + "name": "TLArrowPoint", + "typeTokenRange": { + "startIndex": 1, + "endIndex": 8 + } + }, { "kind": "TypeAlias", "canonicalReference": "@tldraw/editor!TLBackgroundComponent:type", @@ -35396,6 +35364,176 @@ ], "extendsTokenRanges": [] }, + { + "kind": "TypeAlias", + "canonicalReference": "@tldraw/editor!TLBatchCompleteHandler:type", + "docComment": "/**\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export type TLBatchCompleteHandler = " + }, + { + "kind": "Content", + "text": "() => void" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/editor/managers/SideEffectManager.ts", + "releaseTag": "Public", + "name": "TLBatchCompleteHandler", + "typeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "TypeAlias", + "canonicalReference": "@tldraw/editor!TLBeforeChangeHandler:type", + "docComment": "/**\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export type TLBeforeChangeHandler = " + }, + { + "kind": "Content", + "text": "(prev: R, next: R, source: 'remote' | 'user') => R" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/editor/managers/SideEffectManager.ts", + "releaseTag": "Public", + "name": "TLBeforeChangeHandler", + "typeParameters": [ + { + "typeParameterName": "R", + "constraintTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "defaultTypeTokenRange": { + "startIndex": 0, + "endIndex": 0 + } + } + ], + "typeTokenRange": { + "startIndex": 3, + "endIndex": 4 + } + }, + { + "kind": "TypeAlias", + "canonicalReference": "@tldraw/editor!TLBeforeCreateHandler:type", + "docComment": "/**\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export type TLBeforeCreateHandler = " + }, + { + "kind": "Content", + "text": "(record: R, source: 'remote' | 'user') => R" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/editor/managers/SideEffectManager.ts", + "releaseTag": "Public", + "name": "TLBeforeCreateHandler", + "typeParameters": [ + { + "typeParameterName": "R", + "constraintTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "defaultTypeTokenRange": { + "startIndex": 0, + "endIndex": 0 + } + } + ], + "typeTokenRange": { + "startIndex": 3, + "endIndex": 4 + } + }, + { + "kind": "TypeAlias", + "canonicalReference": "@tldraw/editor!TLBeforeDeleteHandler:type", + "docComment": "/**\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export type TLBeforeDeleteHandler = " + }, + { + "kind": "Content", + "text": "(record: R, source: 'remote' | 'user') => false | void" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "packages/editor/src/lib/editor/managers/SideEffectManager.ts", + "releaseTag": "Public", + "name": "TLBeforeDeleteHandler", + "typeParameters": [ + { + "typeParameterName": "R", + "constraintTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "defaultTypeTokenRange": { + "startIndex": 0, + "endIndex": 0 + } + } + ], + "typeTokenRange": { + "startIndex": 3, + "endIndex": 4 + } + }, { "kind": "TypeAlias", "canonicalReference": "@tldraw/editor!TLBrushComponent:type", @@ -35416,8 +35554,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -35632,8 +35770,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -35641,8 +35779,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -35997,8 +36135,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -39615,8 +39753,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -39624,8 +39762,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -39907,8 +40045,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -39934,8 +40072,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -40013,8 +40151,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -40041,7 +40179,7 @@ { "kind": "Reference", "text": "MatLike", - "canonicalReference": "@tldraw/editor!~MatLike:type" + "canonicalReference": "@tldraw/editor!MatLike:type" }, { "kind": "Content", @@ -40093,8 +40231,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -40111,8 +40249,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -40191,8 +40329,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -40231,8 +40369,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -41388,8 +41526,8 @@ }, { "kind": "Reference", - "text": "Box2d", - "canonicalReference": "@tldraw/editor!Box2d:class" + "text": "Box", + "canonicalReference": "@tldraw/editor!Box:class" }, { "kind": "Content", @@ -41767,8 +41905,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -41776,8 +41914,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -42624,24 +42762,24 @@ }, { "kind": "Class", - "canonicalReference": "@tldraw/editor!Vec2d:class", + "canonicalReference": "@tldraw/editor!Vec:class", "docComment": "/**\n * @public\n */\n", "excerptTokens": [ { "kind": "Content", - "text": "export declare class Vec2d " + "text": "export declare class Vec " } ], - "fileUrlPath": "packages/editor/src/lib/primitives/Vec2d.ts", + "fileUrlPath": "packages/editor/src/lib/primitives/Vec.ts", "releaseTag": "Public", "isAbstract": false, - "name": "Vec2d", + "name": "Vec", "preserveMemberOrder": false, "members": [ { "kind": "Constructor", - "canonicalReference": "@tldraw/editor!Vec2d:constructor(1)", - "docComment": "/**\n * Constructs a new instance of the `Vec2d` class\n */\n", + "canonicalReference": "@tldraw/editor!Vec:constructor(1)", + "docComment": "/**\n * Constructs a new instance of the `Vec` class\n */\n", "excerptTokens": [ { "kind": "Content", @@ -42704,7 +42842,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#abs:member(1)", + "canonicalReference": "@tldraw/editor!Vec#abs:member(1)", "docComment": "", "excerptTokens": [ { @@ -42735,7 +42873,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Abs:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Abs:member(1)", "docComment": "", "excerptTokens": [ { @@ -42753,8 +42891,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -42785,7 +42923,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#add:member(1)", + "canonicalReference": "@tldraw/editor!Vec#add:member(1)", "docComment": "", "excerptTokens": [ { @@ -42834,7 +42972,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Add:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Add:member(1)", "docComment": "", "excerptTokens": [ { @@ -42861,8 +42999,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -42901,7 +43039,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#addScalar:member(1)", + "canonicalReference": "@tldraw/editor!Vec#addScalar:member(1)", "docComment": "", "excerptTokens": [ { @@ -42949,7 +43087,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.AddScalar:member(1)", + "canonicalReference": "@tldraw/editor!Vec.AddScalar:member(1)", "docComment": "", "excerptTokens": [ { @@ -42975,8 +43113,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -43015,7 +43153,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#addXY:member(1)", + "canonicalReference": "@tldraw/editor!Vec#addXY:member(1)", "docComment": "", "excerptTokens": [ { @@ -43079,7 +43217,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.AddXY:member(1)", + "canonicalReference": "@tldraw/editor!Vec.AddXY:member(1)", "docComment": "", "excerptTokens": [ { @@ -43113,8 +43251,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -43161,7 +43299,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#angle:member(1)", + "canonicalReference": "@tldraw/editor!Vec#angle:member(1)", "docComment": "", "excerptTokens": [ { @@ -43210,7 +43348,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Angle:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Angle:member(1)", "docComment": "", "excerptTokens": [ { @@ -43276,7 +43414,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Average:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Average:member(1)", "docComment": "", "excerptTokens": [ { @@ -43298,8 +43436,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -43330,7 +43468,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Cast:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Cast:member(1)", "docComment": "", "excerptTokens": [ { @@ -43348,8 +43486,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -43380,7 +43518,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#clamp:member(1)", + "canonicalReference": "@tldraw/editor!Vec#clamp:member(1)", "docComment": "", "excerptTokens": [ { @@ -43444,7 +43582,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Clamp:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Clamp:member(1)", "docComment": "", "excerptTokens": [ { @@ -43453,8 +43591,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -43478,8 +43616,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -43526,7 +43664,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Clockwise:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Clockwise:member(1)", "docComment": "", "excerptTokens": [ { @@ -43609,7 +43747,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#clone:member(1)", + "canonicalReference": "@tldraw/editor!Vec#clone:member(1)", "docComment": "", "excerptTokens": [ { @@ -43618,8 +43756,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -43641,7 +43779,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#cpr:member(1)", + "canonicalReference": "@tldraw/editor!Vec#cpr:member(1)", "docComment": "", "excerptTokens": [ { @@ -43690,7 +43828,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Cpr:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Cpr:member(1)", "docComment": "", "excerptTokens": [ { @@ -43756,7 +43894,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#cross:member(1)", + "canonicalReference": "@tldraw/editor!Vec#cross:member(1)", "docComment": "", "excerptTokens": [ { @@ -43805,7 +43943,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Cross:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Cross:member(1)", "docComment": "", "excerptTokens": [ { @@ -43832,8 +43970,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -43872,7 +44010,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#dist:member(1)", + "canonicalReference": "@tldraw/editor!Vec#dist:member(1)", "docComment": "", "excerptTokens": [ { @@ -43921,7 +44059,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Dist:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Dist:member(1)", "docComment": "", "excerptTokens": [ { @@ -43987,7 +44125,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Dist2:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Dist2:member(1)", "docComment": "", "excerptTokens": [ { @@ -44053,7 +44191,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#distanceToLineSegment:member(1)", + "canonicalReference": "@tldraw/editor!Vec#distanceToLineSegment:member(1)", "docComment": "", "excerptTokens": [ { @@ -44119,7 +44257,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.DistanceToLineSegment:member(1)", + "canonicalReference": "@tldraw/editor!Vec.DistanceToLineSegment:member(1)", "docComment": "", "excerptTokens": [ { @@ -44218,7 +44356,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.DistanceToLineThroughPoint:member(1)", + "canonicalReference": "@tldraw/editor!Vec.DistanceToLineThroughPoint:member(1)", "docComment": "", "excerptTokens": [ { @@ -44301,7 +44439,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#div:member(1)", + "canonicalReference": "@tldraw/editor!Vec#div:member(1)", "docComment": "", "excerptTokens": [ { @@ -44349,7 +44487,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Div:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Div:member(1)", "docComment": "", "excerptTokens": [ { @@ -44375,8 +44513,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -44415,7 +44553,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#divV:member(1)", + "canonicalReference": "@tldraw/editor!Vec#divV:member(1)", "docComment": "", "excerptTokens": [ { @@ -44464,7 +44602,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.DivV:member(1)", + "canonicalReference": "@tldraw/editor!Vec.DivV:member(1)", "docComment": "", "excerptTokens": [ { @@ -44491,8 +44629,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -44531,7 +44669,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#dpr:member(1)", + "canonicalReference": "@tldraw/editor!Vec#dpr:member(1)", "docComment": "", "excerptTokens": [ { @@ -44580,7 +44718,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Dpr:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Dpr:member(1)", "docComment": "", "excerptTokens": [ { @@ -44646,7 +44784,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#equals:member(1)", + "canonicalReference": "@tldraw/editor!Vec#equals:member(1)", "docComment": "", "excerptTokens": [ { @@ -44695,7 +44833,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Equals:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Equals:member(1)", "docComment": "", "excerptTokens": [ { @@ -44761,7 +44899,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#equalsXY:member(1)", + "canonicalReference": "@tldraw/editor!Vec#equalsXY:member(1)", "docComment": "", "excerptTokens": [ { @@ -44825,7 +44963,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.EqualsXY:member(1)", + "canonicalReference": "@tldraw/editor!Vec.EqualsXY:member(1)", "docComment": "", "excerptTokens": [ { @@ -44906,7 +45044,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.From:member(1)", + "canonicalReference": "@tldraw/editor!Vec.From:member(1)", "docComment": "", "excerptTokens": [ { @@ -44915,8 +45053,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -44924,8 +45062,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -44956,7 +45094,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.FromAngle:member(1)", + "canonicalReference": "@tldraw/editor!Vec.FromAngle:member(1)", "docComment": "", "excerptTokens": [ { @@ -44981,8 +45119,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -45021,7 +45159,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.FromArray:member(1)", + "canonicalReference": "@tldraw/editor!Vec.FromArray:member(1)", "docComment": "", "excerptTokens": [ { @@ -45038,8 +45176,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -45070,7 +45208,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#len:member(1)", + "canonicalReference": "@tldraw/editor!Vec#len:member(1)", "docComment": "", "excerptTokens": [ { @@ -45101,7 +45239,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Len:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Len:member(1)", "docComment": "", "excerptTokens": [ { @@ -45150,7 +45288,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#len2:member(1)", + "canonicalReference": "@tldraw/editor!Vec#len2:member(1)", "docComment": "", "excerptTokens": [ { @@ -45181,7 +45319,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Len2:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Len2:member(1)", "docComment": "", "excerptTokens": [ { @@ -45230,7 +45368,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#lrp:member(1)", + "canonicalReference": "@tldraw/editor!Vec#lrp:member(1)", "docComment": "", "excerptTokens": [ { @@ -45256,8 +45394,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -45296,7 +45434,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Lrp:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Lrp:member(1)", "docComment": "", "excerptTokens": [ { @@ -45331,8 +45469,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -45379,7 +45517,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Max:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Max:member(1)", "docComment": "", "excerptTokens": [ { @@ -45406,8 +45544,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -45446,7 +45584,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Med:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Med:member(1)", "docComment": "", "excerptTokens": [ { @@ -45473,8 +45611,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -45513,7 +45651,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Min:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Min:member(1)", "docComment": "", "excerptTokens": [ { @@ -45540,8 +45678,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -45580,7 +45718,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#mul:member(1)", + "canonicalReference": "@tldraw/editor!Vec#mul:member(1)", "docComment": "", "excerptTokens": [ { @@ -45628,7 +45766,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Mul:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Mul:member(1)", "docComment": "", "excerptTokens": [ { @@ -45654,8 +45792,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -45694,7 +45832,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#mulV:member(1)", + "canonicalReference": "@tldraw/editor!Vec#mulV:member(1)", "docComment": "", "excerptTokens": [ { @@ -45743,7 +45881,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.MulV:member(1)", + "canonicalReference": "@tldraw/editor!Vec.MulV:member(1)", "docComment": "", "excerptTokens": [ { @@ -45770,8 +45908,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -45810,7 +45948,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.NearestPointOnLineSegment:member(1)", + "canonicalReference": "@tldraw/editor!Vec.NearestPointOnLineSegment:member(1)", "docComment": "", "excerptTokens": [ { @@ -45854,8 +45992,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -45910,7 +46048,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.NearestPointOnLineThroughPoint:member(1)", + "canonicalReference": "@tldraw/editor!Vec.NearestPointOnLineThroughPoint:member(1)", "docComment": "/**\n * Get the nearest point on a line with a known unit vector that passes through point A\n * ```ts\n * Vec.nearestPointOnLineThroughPoint(A, u, Point)\n * ```\n *\n * @param A - Any point on the line\n *\n * @param u - The unit vector for the line.\n *\n * @param P - A point not on the line to test.\n */\n", "excerptTokens": [ { @@ -45946,8 +46084,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -45994,7 +46132,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#neg:member(1)", + "canonicalReference": "@tldraw/editor!Vec#neg:member(1)", "docComment": "", "excerptTokens": [ { @@ -46025,7 +46163,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Neg:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Neg:member(1)", "docComment": "", "excerptTokens": [ { @@ -46043,8 +46181,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -46075,7 +46213,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#norm:member(1)", + "canonicalReference": "@tldraw/editor!Vec#norm:member(1)", "docComment": "", "excerptTokens": [ { @@ -46106,7 +46244,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#nudge:member(1)", + "canonicalReference": "@tldraw/editor!Vec#nudge:member(1)", "docComment": "", "excerptTokens": [ { @@ -46171,7 +46309,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Nudge:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Nudge:member(1)", "docComment": "", "excerptTokens": [ { @@ -46206,8 +46344,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -46254,7 +46392,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#per:member(1)", + "canonicalReference": "@tldraw/editor!Vec#per:member(1)", "docComment": "", "excerptTokens": [ { @@ -46285,7 +46423,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Per:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Per:member(1)", "docComment": "", "excerptTokens": [ { @@ -46303,8 +46441,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -46335,7 +46473,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.PointsBetween:member(1)", + "canonicalReference": "@tldraw/editor!Vec.PointsBetween:member(1)", "docComment": "/**\n * Get an array of points (with simulated pressure) between two points.\n *\n * @param A - The first point.\n *\n * @param B - The second point.\n *\n * @param steps - The number of points to return.\n */\n", "excerptTokens": [ { @@ -46344,8 +46482,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -46353,8 +46491,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -46370,8 +46508,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -46422,7 +46560,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Vec2d#pressure:member", + "canonicalReference": "@tldraw/editor!Vec#pressure:member", "docComment": "", "excerptTokens": [ { @@ -46452,7 +46590,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#pry:member(1)", + "canonicalReference": "@tldraw/editor!Vec#pry:member(1)", "docComment": "", "excerptTokens": [ { @@ -46501,7 +46639,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Pry:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Pry:member(1)", "docComment": "", "excerptTokens": [ { @@ -46567,7 +46705,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Rescale:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Rescale:member(1)", "docComment": "", "excerptTokens": [ { @@ -46593,8 +46731,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -46633,7 +46771,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#rot:member(1)", + "canonicalReference": "@tldraw/editor!Vec#rot:member(1)", "docComment": "", "excerptTokens": [ { @@ -46681,7 +46819,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Rot:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Rot:member(1)", "docComment": "", "excerptTokens": [ { @@ -46707,8 +46845,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -46747,7 +46885,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#rotWith:member(1)", + "canonicalReference": "@tldraw/editor!Vec#rotWith:member(1)", "docComment": "", "excerptTokens": [ { @@ -46812,7 +46950,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.RotWith:member(1)", + "canonicalReference": "@tldraw/editor!Vec.RotWith:member(1)", "docComment": "", "excerptTokens": [ { @@ -46847,8 +46985,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -46895,7 +47033,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.ScaleWithOrigin:member(1)", + "canonicalReference": "@tldraw/editor!Vec.ScaleWithOrigin:member(1)", "docComment": "", "excerptTokens": [ { @@ -46930,8 +47068,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -46978,7 +47116,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#set:member(1)", + "canonicalReference": "@tldraw/editor!Vec#set:member(1)", "docComment": "", "excerptTokens": [ { @@ -47058,7 +47196,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#setTo:member(1)", + "canonicalReference": "@tldraw/editor!Vec#setTo:member(1)", "docComment": "", "excerptTokens": [ { @@ -47107,7 +47245,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#slope:member(1)", + "canonicalReference": "@tldraw/editor!Vec#slope:member(1)", "docComment": "", "excerptTokens": [ { @@ -47156,7 +47294,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Slope:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Slope:member(1)", "docComment": "", "excerptTokens": [ { @@ -47222,7 +47360,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Snap:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Snap:member(1)", "docComment": "", "excerptTokens": [ { @@ -47248,8 +47386,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -47288,7 +47426,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#snapToGrid:member(1)", + "canonicalReference": "@tldraw/editor!Vec#snapToGrid:member(1)", "docComment": "", "excerptTokens": [ { @@ -47336,7 +47474,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.SnapToGrid:member(1)", + "canonicalReference": "@tldraw/editor!Vec.SnapToGrid:member(1)", "docComment": "", "excerptTokens": [ { @@ -47362,8 +47500,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -47402,7 +47540,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#sub:member(1)", + "canonicalReference": "@tldraw/editor!Vec#sub:member(1)", "docComment": "", "excerptTokens": [ { @@ -47451,7 +47589,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Sub:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Sub:member(1)", "docComment": "", "excerptTokens": [ { @@ -47478,8 +47616,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -47518,7 +47656,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#subScalar:member(1)", + "canonicalReference": "@tldraw/editor!Vec#subScalar:member(1)", "docComment": "", "excerptTokens": [ { @@ -47566,7 +47704,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.SubScalar:member(1)", + "canonicalReference": "@tldraw/editor!Vec.SubScalar:member(1)", "docComment": "", "excerptTokens": [ { @@ -47592,8 +47730,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -47632,7 +47770,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#subXY:member(1)", + "canonicalReference": "@tldraw/editor!Vec#subXY:member(1)", "docComment": "", "excerptTokens": [ { @@ -47696,7 +47834,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.SubXY:member(1)", + "canonicalReference": "@tldraw/editor!Vec.SubXY:member(1)", "docComment": "", "excerptTokens": [ { @@ -47730,8 +47868,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -47778,7 +47916,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#tan:member(1)", + "canonicalReference": "@tldraw/editor!Vec#tan:member(1)", "docComment": "", "excerptTokens": [ { @@ -47796,8 +47934,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -47828,7 +47966,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Tan:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Tan:member(1)", "docComment": "", "excerptTokens": [ { @@ -47855,8 +47993,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -47895,7 +48033,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#toAngle:member(1)", + "canonicalReference": "@tldraw/editor!Vec#toAngle:member(1)", "docComment": "", "excerptTokens": [ { @@ -47926,7 +48064,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.ToAngle:member(1)", + "canonicalReference": "@tldraw/editor!Vec.ToAngle:member(1)", "docComment": "", "excerptTokens": [ { @@ -47975,7 +48113,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#toArray:member(1)", + "canonicalReference": "@tldraw/editor!Vec#toArray:member(1)", "docComment": "", "excerptTokens": [ { @@ -48006,7 +48144,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.ToArray:member(1)", + "canonicalReference": "@tldraw/editor!Vec.ToArray:member(1)", "docComment": "", "excerptTokens": [ { @@ -48055,7 +48193,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#toFixed:member(1)", + "canonicalReference": "@tldraw/editor!Vec#toFixed:member(1)", "docComment": "", "excerptTokens": [ { @@ -48064,8 +48202,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -48087,7 +48225,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.ToFixed:member(1)", + "canonicalReference": "@tldraw/editor!Vec.ToFixed:member(1)", "docComment": "", "excerptTokens": [ { @@ -48113,8 +48251,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -48153,7 +48291,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#toJson:member(1)", + "canonicalReference": "@tldraw/editor!Vec#toJson:member(1)", "docComment": "", "excerptTokens": [ { @@ -48162,8 +48300,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -48185,7 +48323,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.ToJson:member(1)", + "canonicalReference": "@tldraw/editor!Vec.ToJson:member(1)", "docComment": "", "excerptTokens": [ { @@ -48234,7 +48372,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#toString:member(1)", + "canonicalReference": "@tldraw/editor!Vec#toString:member(1)", "docComment": "", "excerptTokens": [ { @@ -48265,7 +48403,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.ToString:member(1)", + "canonicalReference": "@tldraw/editor!Vec.ToString:member(1)", "docComment": "", "excerptTokens": [ { @@ -48314,7 +48452,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d#uni:member(1)", + "canonicalReference": "@tldraw/editor!Vec#uni:member(1)", "docComment": "", "excerptTokens": [ { @@ -48323,8 +48461,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -48346,7 +48484,7 @@ }, { "kind": "Method", - "canonicalReference": "@tldraw/editor!Vec2d.Uni:member(1)", + "canonicalReference": "@tldraw/editor!Vec.Uni:member(1)", "docComment": "", "excerptTokens": [ { @@ -48364,8 +48502,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -48396,7 +48534,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Vec2d#x:member", + "canonicalReference": "@tldraw/editor!Vec#x:member", "docComment": "", "excerptTokens": [ { @@ -48426,7 +48564,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Vec2d#y:member", + "canonicalReference": "@tldraw/editor!Vec#y:member", "docComment": "", "excerptTokens": [ { @@ -48456,7 +48594,7 @@ }, { "kind": "Property", - "canonicalReference": "@tldraw/editor!Vec2d#z:member", + "canonicalReference": "@tldraw/editor!Vec#z:member", "docComment": "", "excerptTokens": [ { @@ -48498,8 +48636,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -48507,15 +48645,15 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", "text": ";" } ], - "fileUrlPath": "packages/editor/src/lib/primitives/Vec2d.ts", + "fileUrlPath": "packages/editor/src/lib/primitives/Vec.ts", "releaseTag": "Public", "name": "VecLike", "typeTokenRange": { diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.ts index 73027b5f8..21fd7b4cf 100644 --- a/packages/editor/src/index.ts +++ b/packages/editor/src/index.ts @@ -145,6 +145,15 @@ export { type TLEditorOptions, type TLResizeShapeOptions, } from './lib/editor/Editor' +export type { + TLAfterChangeHandler, + TLAfterCreateHandler, + TLAfterDeleteHandler, + TLBatchCompleteHandler, + TLBeforeChangeHandler, + TLBeforeCreateHandler, + TLBeforeDeleteHandler, +} from './lib/editor/managers/SideEffectManager' export { SnapManager, type GapsSnapLine, @@ -181,16 +190,12 @@ export { type TLShapeUtilFlag, } from './lib/editor/shapes/ShapeUtil' export { GroupShapeUtil } from './lib/editor/shapes/group/GroupShapeUtil' -export { getArrowheadPathForType } from './lib/editor/shapes/shared/arrow/arrowheads' export { - getCurvedArrowHandlePath, - getSolidCurvedArrowPath, -} from './lib/editor/shapes/shared/arrow/curved-arrow' + type TLArcInfo, + type TLArrowInfo, + type TLArrowPoint, +} from './lib/editor/shapes/shared/arrow/arrow-types' export { getArrowTerminalsInArrowSpace } from './lib/editor/shapes/shared/arrow/shared' -export { - getSolidStraightArrowPath, - getStraightArrowHandlePath, -} from './lib/editor/shapes/shared/arrow/straight-arrow' export { resizeBox, type ResizeBoxOptions } from './lib/editor/shapes/shared/resizeBox' export { BaseBoxShapeTool } from './lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool' export { StateNode, type TLStateNodeConstructor } from './lib/editor/tools/StateNode' @@ -259,7 +264,7 @@ export { useSelectionEvents } from './lib/hooks/useSelectionEvents' export { useTLStore } from './lib/hooks/useTLStore' export { useTransform } from './lib/hooks/useTransform' export { - Box2d, + Box, ROTATE_CORNER_TO_SELECTION_CORNER, rotateSelectionHandle, type BoxLike, @@ -267,9 +272,9 @@ export { type SelectionCorner, type SelectionEdge, type SelectionHandle, -} from './lib/primitives/Box2d' -export { Matrix2d, type Matrix2dModel } from './lib/primitives/Matrix2d' -export { Vec2d, type VecLike } from './lib/primitives/Vec2d' +} from './lib/primitives/Box' +export { Mat, type MatLike, type MatModel } from './lib/primitives/Mat' +export { Vec, type VecLike } from './lib/primitives/Vec' export { EASINGS } from './lib/primitives/easings' export { Arc2d } from './lib/primitives/geometry/Arc2d' export { Circle2d } from './lib/primitives/geometry/Circle2d' @@ -279,24 +284,29 @@ export { Edge2d } from './lib/primitives/geometry/Edge2d' export { Ellipse2d } from './lib/primitives/geometry/Ellipse2d' export { Geometry2d } from './lib/primitives/geometry/Geometry2d' export { Group2d } from './lib/primitives/geometry/Group2d' +export { Point2d } from './lib/primitives/geometry/Point2d' export { Polygon2d } from './lib/primitives/geometry/Polygon2d' export { Polyline2d } from './lib/primitives/geometry/Polyline2d' export { Rectangle2d } from './lib/primitives/geometry/Rectangle2d' export { Stadium2d } from './lib/primitives/geometry/Stadium2d' export { + intersectCircleCircle, + intersectCirclePolygon, + intersectCirclePolyline, + intersectLineSegmentCircle, + intersectLineSegmentLineSegment, intersectLineSegmentPolygon, intersectLineSegmentPolyline, + intersectPolygonBounds, intersectPolygonPolygon, linesIntersect, polygonsIntersect, } from './lib/primitives/intersect' export { - EPSILON, + HALF_PI, PI, PI2, SIN, - TAU, - angleDelta, approximately, areAnglesCompatible, average, @@ -305,24 +315,11 @@ export { clampRadians, clockwiseAngleDist, degreesToRadians, - getArcLength, getPointOnCircle, getPolygonVertices, - getStarBounds, - getSweep, - isAngleBetween, isSafeFloat, - lerpAngles, - longAngleDist, perimeterOfEllipse, - pointInBounds, - pointInCircle, - pointInEllipse, pointInPolygon, - pointInPolyline, - pointInRect, - pointNearToLineSegment, - pointNearToPolyline, precise, radiansToDegrees, rangeIntersection, diff --git a/packages/editor/src/lib/components/Canvas.tsx b/packages/editor/src/lib/components/Canvas.tsx index b04890e76..4fccbbc26 100644 --- a/packages/editor/src/lib/components/Canvas.tsx +++ b/packages/editor/src/lib/components/Canvas.tsx @@ -12,7 +12,7 @@ import { useFixSafariDoubleTapZoomPencilEvents } from '../hooks/useFixSafariDoub import { useGestureEvents } from '../hooks/useGestureEvents' import { useHandleEvents } from '../hooks/useHandleEvents' import { useScreenBounds } from '../hooks/useScreenBounds' -import { Matrix2d } from '../primitives/Matrix2d' +import { Mat } from '../primitives/Mat' import { toDomPrecision } from '../primitives/utils' import { debugFlags } from '../utils/debug-flags' import { GeometryDebuggingView } from './GeometryDebuggingView' @@ -273,7 +273,7 @@ function HandlesWrapper() { return ( - + {handlesToDisplay.map((handle) => { return ( editor.getSelectionRotation(), [ editor, @@ -535,7 +535,7 @@ export function SelectionForegroundWrapper() { return } -export function SelectionBackgroundWrapper() { +function SelectionBackgroundWrapper() { const editor = useEditor() const selectionRotation = useValue('selection rotation', () => editor.getSelectionRotation(), [ editor, @@ -550,13 +550,13 @@ export function SelectionBackgroundWrapper() { return } -export function OnTheCanvasWrapper() { +function OnTheCanvasWrapper() { const { OnTheCanvas } = useEditorComponents() if (!OnTheCanvas) return null return } -export function InFrontOfTheCanvasWrapper() { +function InFrontOfTheCanvasWrapper() { const { InFrontOfTheCanvas } = useEditorComponents() if (!InFrontOfTheCanvas) return null return diff --git a/packages/editor/src/lib/components/Shape.tsx b/packages/editor/src/lib/components/Shape.tsx index f74a24819..3e1f772f4 100644 --- a/packages/editor/src/lib/components/Shape.tsx +++ b/packages/editor/src/lib/components/Shape.tsx @@ -5,7 +5,7 @@ import { ShapeUtil } from '../editor/shapes/ShapeUtil' import { nearestMultiple } from '../hooks/useDPRMultiple' import { useEditor } from '../hooks/useEditor' import { useEditorComponents } from '../hooks/useEditorComponents' -import { Matrix2d } from '../primitives/Matrix2d' +import { Mat } from '../primitives/Mat' import { toDomPrecision } from '../primitives/utils' import { OptionalErrorBoundary } from './ErrorBoundary' @@ -56,7 +56,7 @@ export const Shape = track(function Shape({ if (!shape) return // probably the shape was just deleted const pageTransform = editor.getShapePageTransform(id) - const transform = Matrix2d.toCssString(pageTransform) + const transform = Mat.toCssString(pageTransform) setProperty('transform', transform) }, [editor, setProperty] diff --git a/packages/editor/src/lib/components/ShapeIndicator.tsx b/packages/editor/src/lib/components/ShapeIndicator.tsx index f1b14db26..8b92fc595 100644 --- a/packages/editor/src/lib/components/ShapeIndicator.tsx +++ b/packages/editor/src/lib/components/ShapeIndicator.tsx @@ -24,7 +24,7 @@ const EvenInnererIndicator = ({ shape, util }: { shape: TLShape; util: ShapeUtil return useStateTracking('Indicator:' + shape.type, () => util.indicator(shape)) } -export const InnerIndicator = ({ editor, id }: { editor: Editor; id: TLShapeId }) => { +const InnerIndicator = ({ editor, id }: { editor: Editor; id: TLShapeId }) => { const shape = useValue('shape', () => new ShapeWithPropsEquality(editor.store.get(id)), [ editor, id, diff --git a/packages/editor/src/lib/components/default-components/DefaultBrush.tsx b/packages/editor/src/lib/components/default-components/DefaultBrush.tsx index cfd935278..99d434ef1 100644 --- a/packages/editor/src/lib/components/default-components/DefaultBrush.tsx +++ b/packages/editor/src/lib/components/default-components/DefaultBrush.tsx @@ -1,11 +1,11 @@ -import { Box2dModel } from '@tldraw/tlschema' +import { BoxModel } from '@tldraw/tlschema' import { ComponentType, useRef } from 'react' import { useTransform } from '../../hooks/useTransform' import { toDomPrecision } from '../../primitives/utils' /** @public */ export type TLBrushComponent = ComponentType<{ - brush: Box2dModel + brush: BoxModel color?: string opacity?: number className?: string diff --git a/packages/editor/src/lib/components/default-components/DefaultCollaboratorHint.tsx b/packages/editor/src/lib/components/default-components/DefaultCollaboratorHint.tsx index 32efb0c6e..30256b132 100644 --- a/packages/editor/src/lib/components/default-components/DefaultCollaboratorHint.tsx +++ b/packages/editor/src/lib/components/default-components/DefaultCollaboratorHint.tsx @@ -1,16 +1,16 @@ -import { Vec2dModel } from '@tldraw/tlschema' +import { VecModel } from '@tldraw/tlschema' import classNames from 'classnames' import { ComponentType, useRef } from 'react' import { useTransform } from '../../hooks/useTransform' -import { Box2d } from '../../primitives/Box2d' -import { Vec2d } from '../../primitives/Vec2d' +import { Box } from '../../primitives/Box' +import { Vec } from '../../primitives/Vec' import { clamp } from '../../primitives/utils' /** @public */ export type TLCollaboratorHintComponent = ComponentType<{ className?: string - point: Vec2dModel - viewport: Box2d + point: VecModel + viewport: Box zoom: number opacity?: number color: string @@ -32,7 +32,7 @@ export const DefaultCollaboratorHint: TLCollaboratorHintComponent = ({ clamp(point.x, viewport.minX + 5 / zoom, viewport.maxX - 5 / zoom), clamp(point.y, viewport.minY + 5 / zoom, viewport.maxY - 5 / zoom), 1 / zoom, - Vec2d.Angle(viewport.center, point) + Vec.Angle(viewport.center, point) ) return ( diff --git a/packages/editor/src/lib/components/default-components/DefaultCursor.tsx b/packages/editor/src/lib/components/default-components/DefaultCursor.tsx index e762ca312..d55f4f9ce 100644 --- a/packages/editor/src/lib/components/default-components/DefaultCursor.tsx +++ b/packages/editor/src/lib/components/default-components/DefaultCursor.tsx @@ -1,4 +1,4 @@ -import { Vec2dModel } from '@tldraw/tlschema' +import { VecModel } from '@tldraw/tlschema' import classNames from 'classnames' import { ComponentType, memo, useRef } from 'react' import { useTransform } from '../../hooks/useTransform' @@ -6,7 +6,7 @@ import { useTransform } from '../../hooks/useTransform' /** @public */ export type TLCursorComponent = ComponentType<{ className?: string - point: Vec2dModel | null + point: VecModel | null zoom: number color?: string name: string | null diff --git a/packages/editor/src/lib/components/default-components/DefaultSelectionBackground.tsx b/packages/editor/src/lib/components/default-components/DefaultSelectionBackground.tsx index 7b3b8ec7d..f3a20de9e 100644 --- a/packages/editor/src/lib/components/default-components/DefaultSelectionBackground.tsx +++ b/packages/editor/src/lib/components/default-components/DefaultSelectionBackground.tsx @@ -1,11 +1,11 @@ import * as React from 'react' import { useTransform } from '../../hooks/useTransform' -import { Box2d } from '../../primitives/Box2d' +import { Box } from '../../primitives/Box' import { toDomPrecision } from '../../primitives/utils' /** @public */ export type TLSelectionBackgroundComponent = React.ComponentType<{ - bounds: Box2d + bounds: Box rotation: number }> diff --git a/packages/editor/src/lib/components/default-components/DefaultSelectionForeground.tsx b/packages/editor/src/lib/components/default-components/DefaultSelectionForeground.tsx index 72ca6dc54..059476f29 100644 --- a/packages/editor/src/lib/components/default-components/DefaultSelectionForeground.tsx +++ b/packages/editor/src/lib/components/default-components/DefaultSelectionForeground.tsx @@ -3,12 +3,12 @@ import classNames from 'classnames' import { ComponentType, useRef } from 'react' import { useEditor } from '../../hooks/useEditor' import { useTransform } from '../../hooks/useTransform' -import { Box2d } from '../../primitives/Box2d' +import { Box } from '../../primitives/Box' import { toDomPrecision } from '../../primitives/utils' /** @public */ export type TLSelectionForegroundComponent = ComponentType<{ - bounds: Box2d + bounds: Box rotation: number }> diff --git a/packages/editor/src/lib/config/TLSessionStateSnapshot.ts b/packages/editor/src/lib/config/TLSessionStateSnapshot.ts index 0d879f821..cd309f1d9 100644 --- a/packages/editor/src/lib/config/TLSessionStateSnapshot.ts +++ b/packages/editor/src/lib/config/TLSessionStateSnapshot.ts @@ -75,7 +75,7 @@ const Versions = { Initial: 0, } as const -export const CURRENT_SESSION_STATE_SNAPSHOT_VERSION = Versions.Initial +const CURRENT_SESSION_STATE_SNAPSHOT_VERSION = Versions.Initial /** * The state of the editor instance, not including any document state. diff --git a/packages/editor/src/lib/editor/Editor.ts b/packages/editor/src/lib/editor/Editor.ts index 25d9aab91..e4b45852c 100644 --- a/packages/editor/src/lib/editor/Editor.ts +++ b/packages/editor/src/lib/editor/Editor.ts @@ -76,9 +76,9 @@ import { SVG_PADDING, ZOOMS, } from '../constants' -import { Box2d } from '../primitives/Box2d' -import { MatLike, Matrix2d, Matrix2dModel } from '../primitives/Matrix2d' -import { Vec2d, VecLike } from '../primitives/Vec2d' +import { Box } from '../primitives/Box' +import { Mat, MatLike, MatModel } from '../primitives/Mat' +import { Vec, VecLike } from '../primitives/Vec' import { EASINGS } from '../primitives/easings' import { Geometry2d } from '../primitives/geometry/Geometry2d' import { Group2d } from '../primitives/geometry/Group2d' @@ -140,7 +140,7 @@ export type TLAnimationOptions = Partial<{ /** @public */ export type TLResizeShapeOptions = Partial<{ - initialBounds: Box2d + initialBounds: Box scaleOrigin: VecLike scaleAxisRotation: number initialShape: TLShape @@ -1630,11 +1630,11 @@ export class Editor extends EventEmitter { * * @public */ - @computed getSelectionPageBounds(): Box2d | null { + @computed getSelectionPageBounds(): Box | null { const selectedShapeIds = this.getCurrentPageState().selectedShapeIds if (selectedShapeIds.length === 0) return null - return Box2d.Common(compact(selectedShapeIds.map((id) => this.getShapePageBounds(id)))) + return Box.Common(compact(selectedShapeIds.map((id) => this.getShapePageBounds(id)))) } /** @@ -1665,7 +1665,7 @@ export class Editor extends EventEmitter { * @readonly * @public */ - @computed getSelectionRotatedPageBounds(): Box2d | undefined { + @computed getSelectionRotatedPageBounds(): Box | undefined { const selectedShapeIds = this.getSelectedShapeIds() if (selectedShapeIds.length === 0) { @@ -1685,14 +1685,14 @@ export class Editor extends EventEmitter { } // need to 'un-rotate' all the outlines of the existing nodes so we can fit them inside a box - const boxFromRotatedVertices = Box2d.FromPoints( + const boxFromRotatedVertices = Box.FromPoints( this.getSelectedShapeIds() .flatMap((id) => { const pageTransform = this.getShapePageTransform(id) if (!pageTransform) return [] return pageTransform.applyToPoints(this.getShapeGeometry(id).vertices) }) - .map((p) => Vec2d.Rot(p, -selectionRotation)) + .map((p) => Vec.Rot(p, -selectionRotation)) ) // now position box so that it's top-left corner is in the right place boxFromRotatedVertices.point = boxFromRotatedVertices.point.rot(selectionRotation) @@ -2124,7 +2124,7 @@ export class Editor extends EventEmitter { if (animation) { const { width, height } = this.getViewportScreenBounds() - return this._animateToViewport(new Box2d(-x, -y, width / z, height / z), animation) + return this._animateToViewport(new Box(-x, -y, width / z, height / z), animation) } else { this._setCamera({ x, y, z }) } @@ -2200,7 +2200,7 @@ export class Editor extends EventEmitter { const ids = [...this.getCurrentPageShapeIds()] if (ids.length <= 0) return this - const pageBounds = Box2d.Common(compact(ids.map((id) => this.getShapePageBounds(id)))) + const pageBounds = Box.Common(compact(ids.map((id) => this.getShapePageBounds(id)))) this.zoomToBounds(pageBounds, undefined, animation) return this } @@ -2349,7 +2349,7 @@ export class Editor extends EventEmitter { if (!this.getInstanceState().canMoveCamera) return this if (ids.length <= 0) return this - const selectionBounds = Box2d.Common(compact(ids.map((id) => this.getShapePageBounds(id)))) + const selectionBounds = Box.Common(compact(ids.map((id) => this.getShapePageBounds(id)))) const viewportPageBounds = this.getViewportPageBounds() @@ -2407,7 +2407,7 @@ export class Editor extends EventEmitter { * * @public */ - zoomToBounds(bounds: Box2d, targetZoom?: number, animation?: TLAnimationOptions): this { + zoomToBounds(bounds: Box, targetZoom?: number, animation?: TLAnimationOptions): this { if (!this.getInstanceState().canMoveCamera) return this const viewportScreenBounds = this.getViewportScreenBounds() @@ -2473,8 +2473,8 @@ export class Editor extends EventEmitter { elapsed: number duration: number easing: (t: number) => number - start: Box2d - end: Box2d + start: Box + end: Box } /** @internal */ @@ -2510,7 +2510,7 @@ export class Editor extends EventEmitter { } /** @internal */ - private _animateToViewport(targetViewportPage: Box2d, opts = {} as TLAnimationOptions) { + private _animateToViewport(targetViewportPage: Box, opts = {} as TLAnimationOptions) { const { duration = 0, easing = EASINGS.easeInOutCubic } = opts const animationSpeed = this.user.getAnimationSpeed() const viewportPageBounds = this.getViewportPageBounds() @@ -2579,7 +2579,7 @@ export class Editor extends EventEmitter { const moveCamera = (elapsed: number) => { const { x: cx, y: cy, z: cz } = this.getCamera() - const movementVec = Vec2d.Mul(direction, (currentSpeed * elapsed) / cz) + const movementVec = Vec.Mul(direction, (currentSpeed * elapsed) / cz) // Apply friction currentSpeed *= 1 - friction @@ -2709,7 +2709,7 @@ export class Editor extends EventEmitter { if (!container) return this const rect = container.getBoundingClientRect() - const screenBounds = new Box2d( + const screenBounds = new Box( rect.left || rect.x, rect.top || rect.y, Math.max(rect.width, 1), @@ -2761,7 +2761,7 @@ export class Editor extends EventEmitter { */ @computed getViewportScreenBounds() { const { x, y, w, h } = this.getInstanceState().screenBounds - return new Box2d(x, y, w, h) + return new Box(x, y, w, h) } /** @@ -2780,7 +2780,7 @@ export class Editor extends EventEmitter { @computed getViewportPageBounds() { const { w, h } = this.getViewportScreenBounds() const { x: cx, y: cy, z: cz } = this.getCamera() - return new Box2d(-cx, -cy, w / cz, h / cz) + return new Box(-cx, -cy, w / cz, h / cz) } /** @@ -2898,10 +2898,10 @@ export class Editor extends EventEmitter { // Get the bounds of the follower (me) and the leader (them) const { center, width, height } = this.getViewportPageBounds() - const leaderScreen = Box2d.From(leaderPresence.screenBounds) + const leaderScreen = Box.From(leaderPresence.screenBounds) const leaderWidth = leaderScreen.width / leaderPresence.camera.z const leaderHeight = leaderScreen.height / leaderPresence.camera.z - const leaderCenter = new Vec2d( + const leaderCenter = new Vec( leaderWidth / 2 - leaderPresence.camera.x, leaderHeight / 2 - leaderPresence.camera.y ) @@ -2924,10 +2924,10 @@ export class Editor extends EventEmitter { // Figure out where to move the camera const displacement = leaderCenter.sub(center) - const targetCenter = Vec2d.Add(center, Vec2d.Mul(displacement, chaseProportion)) + const targetCenter = Vec.Add(center, Vec.Mul(displacement, chaseProportion)) // Now let's assess whether we've caught up to the leader or not - const distance = Vec2d.Sub(targetCenter, center).len() + const distance = Vec.Sub(targetCenter, center).len() const zoomChange = Math.abs(targetZoom - this.getCamera().z) // If we're chasing the leader... @@ -3049,7 +3049,7 @@ export class Editor extends EventEmitter { backgroundIndex: number opacity: number isCulled: boolean - maskedPageBounds: Box2d | undefined + maskedPageBounds: Box | undefined }[] = [] let nextIndex = MAX_SHAPES_PER_PAGE * 2 @@ -3165,7 +3165,7 @@ export class Editor extends EventEmitter { } /** @internal */ - private readonly _renderingBounds = atom('rendering viewport', new Box2d()) + private readonly _renderingBounds = atom('rendering viewport', new Box()) /** * The current rendering bounds in the current page space, expanded slightly. Used for determining which shapes @@ -3178,7 +3178,7 @@ export class Editor extends EventEmitter { } /** @internal */ - private readonly _renderingBoundsExpanded = atom('rendering viewport expanded', new Box2d()) + private readonly _renderingBoundsExpanded = atom('rendering viewport expanded', new Box()) /** * Update the rendering bounds. This should be called when the viewport has stopped changing, such @@ -3791,7 +3791,7 @@ export class Editor extends EventEmitter { } /** @internal */ - @computed private _getShapeOutlineSegmentsCache(): ComputedCache { + @computed private _getShapeOutlineSegmentsCache(): ComputedCache { return this.store.createComputedCache('outline-segments', (shape) => { return this.getShapeUtil(shape).getOutlineSegments(shape) }) @@ -3810,7 +3810,7 @@ export class Editor extends EventEmitter { * * @public */ - getShapeOutlineSegments(shape: T | T['id']): Vec2d[][] { + getShapeOutlineSegments(shape: T | T['id']): Vec[][] { return ( this._getShapeOutlineSegmentsCache().get(typeof shape === 'string' ? shape : shape.id) ?? EMPTY_ARRAY @@ -3855,11 +3855,11 @@ export class Editor extends EventEmitter { * * @public */ - getShapeLocalTransform(shape: TLShape | TLShapeId): Matrix2d { + getShapeLocalTransform(shape: TLShape | TLShapeId): Mat { const id = typeof shape === 'string' ? shape : shape.id const freshShape = this.getShape(id) if (!freshShape) throw Error('Editor.getTransform: shape not found') - return Matrix2d.Identity().translate(freshShape.x, freshShape.y).rotate(freshShape.rotation) + return Mat.Identity().translate(freshShape.x, freshShape.y).rotate(freshShape.rotation) } /** @@ -3867,8 +3867,8 @@ export class Editor extends EventEmitter { * * @internal */ - @computed private _getShapePageTransformCache(): ComputedCache { - return this.store.createComputedCache('pageTransformCache', (shape) => { + @computed private _getShapePageTransformCache(): ComputedCache { + return this.store.createComputedCache('pageTransformCache', (shape) => { if (isPageId(shape.parentId)) { return this.getShapeLocalTransform(shape) } @@ -3878,8 +3878,8 @@ export class Editor extends EventEmitter { // In the future we should look at creating a store update mechanism that understands and preserves // ordering. const parentTransform = - this._getShapePageTransformCache().get(shape.parentId) ?? Matrix2d.Identity() - return Matrix2d.Compose(parentTransform, this.getShapeLocalTransform(shape)!) + this._getShapePageTransformCache().get(shape.parentId) ?? Mat.Identity() + return Mat.Compose(parentTransform, this.getShapeLocalTransform(shape)!) }) } @@ -3895,11 +3895,11 @@ export class Editor extends EventEmitter { * * @public */ - getShapeParentTransform(shape: TLShape | TLShapeId): Matrix2d { + getShapeParentTransform(shape: TLShape | TLShapeId): Mat { const id = typeof shape === 'string' ? shape : shape.id const freshShape = this.getShape(id) - if (!freshShape || isPageId(freshShape.parentId)) return Matrix2d.Identity() - return this._getShapePageTransformCache().get(freshShape.parentId) ?? Matrix2d.Identity() + if (!freshShape || isPageId(freshShape.parentId)) return Mat.Identity() + return this._getShapePageTransformCache().get(freshShape.parentId) ?? Mat.Identity() } /** @@ -3915,20 +3915,20 @@ export class Editor extends EventEmitter { * * @public */ - getShapePageTransform(shape: TLShape | TLShapeId): Matrix2d { + getShapePageTransform(shape: TLShape | TLShapeId): Mat { const id = typeof shape === 'string' ? shape : this.getShape(shape)!.id - return this._getShapePageTransformCache().get(id) ?? Matrix2d.Identity() + return this._getShapePageTransformCache().get(id) ?? Mat.Identity() } /** @internal */ - @computed private _getShapePageBoundsCache(): ComputedCache { - return this.store.createComputedCache('pageBoundsCache', (shape) => { + @computed private _getShapePageBoundsCache(): ComputedCache { + return this.store.createComputedCache('pageBoundsCache', (shape) => { const pageTransform = this._getShapePageTransformCache().get(shape.id) - if (!pageTransform) return new Box2d() + if (!pageTransform) return new Box() - const result = Box2d.FromPoints( - Matrix2d.applyToPoints(pageTransform, this.getShapeGeometry(shape).vertices) + const result = Box.FromPoints( + Mat.applyToPoints(pageTransform, this.getShapeGeometry(shape).vertices) ) return result @@ -3948,7 +3948,7 @@ export class Editor extends EventEmitter { * * @public */ - getShapePageBounds(shape: TLShape | TLShapeId): Box2d | undefined { + getShapePageBounds(shape: TLShape | TLShapeId): Box | undefined { return this._getShapePageBoundsCache().get(typeof shape === 'string' ? shape : shape.id) } @@ -3968,7 +3968,7 @@ export class Editor extends EventEmitter { const pageTransform = this._getShapePageTransformCache().get(shape.id) if (!pageTransform) return undefined - const localMask = Matrix2d.applyToPoints(Matrix2d.Inverse(pageTransform), pageMask) + const localMask = Mat.applyToPoints(Mat.Inverse(pageTransform), pageMask) return `polygon(${localMask.map((p) => `${p.x}px ${p.y}px`).join(',')})` }) @@ -3994,7 +3994,7 @@ export class Editor extends EventEmitter { } /** @internal */ - @computed private _getShapeMaskCache(): ComputedCache { + @computed private _getShapeMaskCache(): ComputedCache { return this.store.createComputedCache('pageMaskCache', (shape) => { if (isPageId(shape.parentId)) return undefined @@ -4005,7 +4005,7 @@ export class Editor extends EventEmitter { if (frameAncestors.length === 0) return undefined const pageMask = frameAncestors - .map((s) => + .map((s) => // Apply the frame transform to the frame outline to get the frame outline in the current page space this._getShapePageTransformCache() .get(s.id)! @@ -4015,7 +4015,7 @@ export class Editor extends EventEmitter { if (!(b && acc)) return undefined const intersection = intersectPolygonPolygon(acc, b) if (intersection) { - return intersection.map(Vec2d.Cast) + return intersection.map(Vec.Cast) } return [] }) @@ -4057,7 +4057,7 @@ export class Editor extends EventEmitter { * * @public */ - getShapeMaskedPageBounds(shape: TLShapeId | TLShape): Box2d | undefined { + getShapeMaskedPageBounds(shape: TLShapeId | TLShape): Box | undefined { if (typeof shape !== 'string') shape = shape.id const pageBounds = this._getShapePageBoundsCache().get(shape) if (!pageBounds) return @@ -4066,12 +4066,12 @@ export class Editor extends EventEmitter { if (pageMask.length === 0) return undefined const { corners } = pageBounds - if (corners.every((p, i) => Vec2d.Equals(p, pageMask[i]))) return pageBounds.clone() + if (corners.every((p, i) => Vec.Equals(p, pageMask[i]))) return pageBounds.clone() // todo: find out why intersect polygon polygon for identical polygons produces zero w/h intersections const intersection = intersectPolygonPolygon(pageMask, corners) if (!intersection) return - return Box2d.FromPoints(intersection) + return Box.FromPoints(intersection) } return pageBounds @@ -4217,8 +4217,8 @@ export class Editor extends EventEmitter { * * @public */ - @computed getCurrentPageBounds(): Box2d | undefined { - let commonBounds: Box2d | undefined + @computed getCurrentPageBounds(): Box | undefined { + let commonBounds: Box | undefined this.getCurrentPageShapeIds().forEach((shapeId) => { const bounds = this.getShapeMaskedPageBounds(shapeId) @@ -4504,7 +4504,7 @@ export class Editor extends EventEmitter { * * @public */ - getPointInShapeSpace(shape: TLShape | TLShapeId, point: VecLike): Vec2d { + getPointInShapeSpace(shape: TLShape | TLShapeId, point: VecLike): Vec { const id = typeof shape === 'string' ? shape : shape.id return this._getShapePageTransformCache().get(id)!.clone().invert().applyToPoint(point) } @@ -4522,14 +4522,14 @@ export class Editor extends EventEmitter { * * @public */ - getPointInParentSpace(shape: TLShapeId | TLShape, point: VecLike): Vec2d { + getPointInParentSpace(shape: TLShapeId | TLShape, point: VecLike): Vec { const id = typeof shape === 'string' ? shape : shape.id const freshShape = this.getShape(id) - if (!freshShape) return new Vec2d(0, 0) - if (isPageId(freshShape.parentId)) return Vec2d.From(point) + if (!freshShape) return new Vec(0, 0) + if (isPageId(freshShape.parentId)) return Vec.From(point) const parentTransform = this.getShapePageTransform(freshShape.parentId) - if (!parentTransform) return Vec2d.From(point) + if (!parentTransform) return Vec.From(point) return parentTransform.clone().invert().applyToPoint(point) } @@ -4769,7 +4769,7 @@ export class Editor extends EventEmitter { const changes: TLShapePartial[] = [] const parentTransform = isPageId(parentId) - ? Matrix2d.Identity() + ? Mat.Identity() : this.getShapePageTransform(parentId)! const parentPageRotation = parentTransform.rotation() @@ -5095,7 +5095,7 @@ export class Editor extends EventEmitter { throw Error(`Could not find a shape with the id ${id}.`) } - const localDelta = Vec2d.Cast(offset) + const localDelta = Vec.Cast(offset) const parentTransform = this.getShapeParentTransform(shape) if (parentTransform) localDelta.rot(-parentTransform.rotation()) @@ -5177,7 +5177,7 @@ export class Editor extends EventEmitter { if (offset && initialIds.has(id)) { const parentTransform = this.getShapeParentTransform(shape) - const vec = new Vec2d(offset.x, offset.y).rot(-parentTransform!.rotation()) + const vec = new Vec(offset.x, offset.y).rot(-parentTransform!.rotation()) ox = vec.x oy = vec.y } @@ -5250,9 +5250,9 @@ export class Editor extends EventEmitter { : getCurvedArrowInfo(this, newShape) if (info?.isValid && infoAfter?.isValid && !getIsArrowStraight(shape)) { - const mpA = Vec2d.Med(info.start.handle, info.end.handle) - const distA = Vec2d.Dist(info.middle, mpA) - const distB = Vec2d.Dist(infoAfter.middle, mpA) + const mpA = Vec.Med(info.start.handle, info.end.handle) + const distA = Vec.Dist(info.middle, mpA) + const distB = Vec.Dist(infoAfter.middle, mpA) if (newShape.props.bend < 0) { newShape.props.bend += distB - distA } else { @@ -5566,7 +5566,7 @@ export class Editor extends EventEmitter { .flat() ) - const scaleOriginPage = Box2d.Common( + const scaleOriginPage = Box.Common( compact(shapesToFlip.map((id) => this.getShapePageBounds(id))) ).center @@ -5718,7 +5718,7 @@ export class Editor extends EventEmitter { const parent = this.getShapeParent(shape) const localDelta = parent - ? Vec2d.Rot(delta, -this.getShapePageTransform(parent)!.decompose().rotation) + ? Vec.Rot(delta, -this.getShapePageTransform(parent)!.decompose().rotation) : delta const translateStartChanges = this.getShapeUtil(shape).onTranslateStart?.(shape) @@ -5780,11 +5780,11 @@ export class Editor extends EventEmitter { return true }) ) - const shapePageBounds: Record = {} - const nextShapePageBounds: Record = {} + const shapePageBounds: Record = {} + const nextShapePageBounds: Record = {} let shape: TLShape, - bounds: Box2d, + bounds: Box, area = 0 for (let i = 0; i < shapesToPack.length; i++) { @@ -5795,7 +5795,7 @@ export class Editor extends EventEmitter { area += bounds.width * bounds.height } - const commonBounds = Box2d.Common(compact(Object.values(shapePageBounds))) + const commonBounds = Box.Common(compact(Object.values(shapePageBounds))) const maxWidth = commonBounds.width @@ -5806,12 +5806,12 @@ export class Editor extends EventEmitter { const startWidth = Math.max(Math.ceil(Math.sqrt(area / 0.95)), maxWidth) // first shape fills the width and is infinitely tall - const spaces: Box2d[] = [new Box2d(commonBounds.x, commonBounds.y, startWidth, Infinity)] + const spaces: Box[] = [new Box(commonBounds.x, commonBounds.y, startWidth, Infinity)] let width = 0 let height = 0 - let space: Box2d - let last: Box2d + let space: Box + let last: Box for (let i = 0; i < shapesToPack.length; i++) { shape = shapesToPack[i] @@ -5846,7 +5846,7 @@ export class Editor extends EventEmitter { } else { // split the space into two spaces spaces.push( - new Box2d( + new Box( space.x + (bounds.width + gap), space.y, space.width - (bounds.width + gap), @@ -5860,10 +5860,10 @@ export class Editor extends EventEmitter { } } - const commonAfter = Box2d.Common(Object.values(nextShapePageBounds)) - const centerDelta = Vec2d.Sub(commonBounds.center, commonAfter.center) + const commonAfter = Box.Common(Object.values(nextShapePageBounds)) + const centerDelta = Vec.Sub(commonBounds.center, commonAfter.center) - let nextBounds: Box2d + let nextBounds: Box const changes: TLShapePartial[] = [] @@ -5872,7 +5872,7 @@ export class Editor extends EventEmitter { bounds = shapePageBounds[shape.id] nextBounds = nextShapePageBounds[shape.id] - const delta = Vec2d.Sub(nextBounds.point, bounds.point).add(centerDelta) + const delta = Vec.Sub(nextBounds.point, bounds.point).add(centerDelta) const parentTransform = this.getShapeParentTransform(shape) if (parentTransform) delta.rot(-parentTransform.rotation()) @@ -5933,7 +5933,7 @@ export class Editor extends EventEmitter { const shapePageBounds = Object.fromEntries( shapesToAlign.map((shape) => [shape.id, this.getShapePageBounds(shape)]) ) - const commonBounds = Box2d.Common(compact(Object.values(shapePageBounds))) + const commonBounds = Box.Common(compact(Object.values(shapePageBounds))) const changes: TLShapePartial[] = [] @@ -5972,7 +5972,7 @@ export class Editor extends EventEmitter { const parent = this.getShapeParent(shape) const localDelta = parent - ? Vec2d.Rot(delta, -this.getShapePageTransform(parent)!.decompose().rotation) + ? Vec.Rot(delta, -this.getShapePageTransform(parent)!.decompose().rotation) : delta const translateChanges = this.getShapeUtil(shape).onTranslateStart?.(shape) @@ -6066,7 +6066,7 @@ export class Editor extends EventEmitter { const parent = this.getShapeParent(shape) const localDelta = parent - ? Vec2d.Rot(delta, -this.getShapePageTransform(parent)!.rotation()) + ? Vec.Rot(delta, -this.getShapePageTransform(parent)!.rotation()) : delta const translateStartChanges = this.getShapeUtil(shape).onTranslateStart?.(shape) @@ -6114,7 +6114,7 @@ export class Editor extends EventEmitter { const shapesToStretch = compact(ids.map((id) => this.getShape(id))) // always fresh shapes const shapeBounds = Object.fromEntries(ids.map((id) => [id, this.getShapeGeometry(id).bounds])) const shapePageBounds = Object.fromEntries(ids.map((id) => [id, this.getShapePageBounds(id)!])) - const commonBounds = Box2d.Common(compact(Object.values(shapePageBounds))) + const commonBounds = Box.Common(compact(Object.values(shapePageBounds))) switch (operation) { case 'vertical': { @@ -6124,16 +6124,16 @@ export class Editor extends EventEmitter { if (pageRotation % PI2) continue const bounds = shapeBounds[shape.id] const pageBounds = shapePageBounds[shape.id] - const localOffset = new Vec2d(0, commonBounds.minY - pageBounds.minY) + const localOffset = new Vec(0, commonBounds.minY - pageBounds.minY) const parentTransform = this.getShapeParentTransform(shape) if (parentTransform) localOffset.rot(-parentTransform.rotation()) - const { x, y } = Vec2d.Add(localOffset, shape) + const { x, y } = Vec.Add(localOffset, shape) this.updateShapes([{ id: shape.id, type: shape.type, x, y }], { squashing: true }) - const scale = new Vec2d(1, commonBounds.height / pageBounds.height) + const scale = new Vec(1, commonBounds.height / pageBounds.height) this.resizeShape(shape.id, scale, { initialBounds: bounds, - scaleOrigin: new Vec2d(pageBounds.center.x, commonBounds.minY), + scaleOrigin: new Vec(pageBounds.center.x, commonBounds.minY), scaleAxisRotation: 0, }) } @@ -6147,16 +6147,16 @@ export class Editor extends EventEmitter { const pageBounds = shapePageBounds[shape.id] const pageRotation = this.getShapePageTransform(shape)!.rotation() if (pageRotation % PI2) continue - const localOffset = new Vec2d(commonBounds.minX - pageBounds.minX, 0) + const localOffset = new Vec(commonBounds.minX - pageBounds.minX, 0) const parentTransform = this.getShapeParentTransform(shape) if (parentTransform) localOffset.rot(-parentTransform.rotation()) - const { x, y } = Vec2d.Add(localOffset, shape) + const { x, y } = Vec.Add(localOffset, shape) this.updateShapes([{ id: shape.id, type: shape.type, x, y }], { squashing: true }) - const scale = new Vec2d(commonBounds.width / pageBounds.width, 1) + const scale = new Vec(commonBounds.width / pageBounds.width, 1) this.resizeShape(shape.id, scale, { initialBounds: bounds, - scaleOrigin: new Vec2d(commonBounds.minX, pageBounds.center.y), + scaleOrigin: new Vec(commonBounds.minX, pageBounds.center.y), scaleAxisRotation: 0, }) } @@ -6186,8 +6186,8 @@ export class Editor extends EventEmitter { const id = typeof shape === 'string' ? shape : shape.id if (this.getInstanceState().isReadonly) return this - if (!Number.isFinite(scale.x)) scale = new Vec2d(1, scale.y) - if (!Number.isFinite(scale.y)) scale = new Vec2d(scale.x, 1) + if (!Number.isFinite(scale.x)) scale = new Vec(1, scale.y) + if (!Number.isFinite(scale.y)) scale = new Vec(scale.x, 1) const initialShape = options.initialShape ?? this.getShape(id) if (!initialShape) return this @@ -6196,7 +6196,7 @@ export class Editor extends EventEmitter { if (!scaleOrigin) return this const pageTransform = options.initialPageTransform - ? Matrix2d.Cast(options.initialPageTransform) + ? Mat.Cast(options.initialPageTransform) : this.getShapePageTransform(id) if (!pageTransform) return this @@ -6229,16 +6229,16 @@ export class Editor extends EventEmitter { if (util.isAspectRatioLocked(initialShape)) { if (Math.abs(scale.x) > Math.abs(scale.y)) { - scale = new Vec2d(scale.x, Math.sign(scale.y) * Math.abs(scale.x)) + scale = new Vec(scale.x, Math.sign(scale.y) * Math.abs(scale.x)) } else { - scale = new Vec2d(Math.sign(scale.x) * Math.abs(scale.y), scale.y) + scale = new Vec(Math.sign(scale.x) * Math.abs(scale.y), scale.y) } } if (util.onResize && util.canResize(initialShape)) { // get the model changes from the shape util const newPagePoint = this._scalePagePoint( - Matrix2d.applyToPoint(pageTransform, new Vec2d(0, 0)), + Mat.applyToPoint(pageTransform, new Vec(0, 0)), scaleOrigin, scale, scaleAxisRotation @@ -6247,7 +6247,7 @@ export class Editor extends EventEmitter { const newLocalPoint = this.getPointInParentSpace(initialShape.id, newPagePoint) // resize the shape's local bounding box - const myScale = new Vec2d(scale.x, scale.y) + const myScale = new Vec(scale.x, scale.y) // the shape is aligned with the rest of the shapes in the selection, but may be // 90deg offset from the main rotation of the selection, in which case // we need to flip the width and height scale factors @@ -6260,7 +6260,7 @@ export class Editor extends EventEmitter { // adjust initial model for situations where the parent has moved during the resize // e.g. groups - const initialPagePoint = Matrix2d.applyToPoint(pageTransform, new Vec2d()) + const initialPagePoint = Mat.applyToPoint(pageTransform, new Vec()) // need to adjust the shape's x and y points in case the parent has moved since start of resizing const { x, y } = this.getPointInParentSpace(initialShape.id, initialPagePoint) @@ -6290,7 +6290,7 @@ export class Editor extends EventEmitter { { squashing: true } ) } else { - const initialPageCenter = Matrix2d.applyToPoint(pageTransform, initialBounds.center) + const initialPageCenter = Mat.applyToPoint(pageTransform, initialBounds.center) // get the model changes from the shape util const newPageCenter = this._scalePagePoint( initialPageCenter, @@ -6305,7 +6305,7 @@ export class Editor extends EventEmitter { ) const newPageCenterInParentSpace = this.getPointInParentSpace(initialShape.id, newPageCenter) - const delta = Vec2d.Sub(newPageCenterInParentSpace, initialPageCenterInParentSpace) + const delta = Vec.Sub(newPageCenterInParentSpace, initialPageCenterInParentSpace) // apply the changes to the model this.updateShapes( [ @@ -6330,13 +6330,13 @@ export class Editor extends EventEmitter { scale: VecLike, scaleAxisRotation: number ) { - const relativePoint = Vec2d.RotWith(point, scaleOrigin, -scaleAxisRotation).sub(scaleOrigin) + const relativePoint = Vec.RotWith(point, scaleOrigin, -scaleAxisRotation).sub(scaleOrigin) // calculate the new point position relative to the scale origin - const newRelativePagePoint = Vec2d.MulV(relativePoint, scale) + const newRelativePagePoint = Vec.MulV(relativePoint, scale) // and rotate it back to page coords to get the new page point of the resized shape - const destination = Vec2d.Add(newRelativePagePoint, scaleOrigin).rotWith( + const destination = Vec.Add(newRelativePagePoint, scaleOrigin).rotWith( scaleOrigin, scaleAxisRotation ) @@ -6349,7 +6349,7 @@ export class Editor extends EventEmitter { id: TLShapeId, scale: VecLike, options: { - initialBounds: Box2d + initialBounds: Box scaleOrigin: VecLike scaleAxisRotation: number initialShape: TLShape @@ -6362,7 +6362,7 @@ export class Editor extends EventEmitter { // and then after applying the scale to the shape we also rotate it if required and translate it so that it's center // point ends up in the right place. - const shapeScale = new Vec2d(scale.x, scale.y) + const shapeScale = new Vec(scale.x, scale.y) // // make sure we are constraining aspect ratio, and using the smallest scale axis to avoid shapes getting bigger // // than the selection bounding box @@ -6381,14 +6381,14 @@ export class Editor extends EventEmitter { // then if the shape is flipped in one axis only, we need to apply an extra rotation // to make sure the shape is mirrored correctly if (Math.sign(scale.x) * Math.sign(scale.y) < 0) { - let { rotation } = Matrix2d.Decompose(options.initialPageTransform) + let { rotation } = Mat.Decompose(options.initialPageTransform) rotation -= 2 * rotation this.updateShapes([{ id, type, rotation }], { squashing: true }) } // Next we need to translate the shape so that it's center point ends up in the right place. // To do that we first need to calculate the center point of the shape in the current page space before the scale was applied. - const preScaleShapePageCenter = Matrix2d.applyToPoint( + const preScaleShapePageCenter = Mat.applyToPoint( options.initialPageTransform, options.initialBounds.center ) @@ -6407,10 +6407,10 @@ export class Editor extends EventEmitter { const currentPageCenter = pageBounds.center const shapePageTransformOrigin = pageTransform.point() if (!currentPageCenter || !shapePageTransformOrigin) return this - const pageDelta = Vec2d.Sub(postScaleShapePageCenter, currentPageCenter) + const pageDelta = Vec.Sub(postScaleShapePageCenter, currentPageCenter) // and finally figure out what the shape's new position should be - const postScaleShapePagePoint = Vec2d.Add(shapePageTransformOrigin, pageDelta) + const postScaleShapePagePoint = Vec.Add(shapePageTransformOrigin, pageDelta) const { x, y } = this.getPointInParentSpace(id, postScaleShapePagePoint) this.updateShapes([{ id, type, x, y }], { squashing: true }) @@ -6819,7 +6819,7 @@ export class Editor extends EventEmitter { const shapesToGroup = compact(this._getUnlockedShapeIds(ids).map((id) => this.getShape(id))) const sortedShapeIds = shapesToGroup.sort(sortByIndex).map((s) => s.id) - const pageBounds = Box2d.Common(compact(shapesToGroup.map((id) => this.getShapePageBounds(id)))) + const pageBounds = Box.Common(compact(shapesToGroup.map((id) => this.getShapePageBounds(id)))) const { x, y } = pageBounds.point @@ -7610,7 +7610,7 @@ export class Editor extends EventEmitter { if (!ids) return if (ids.length === 0) return - const pageTransforms: Record = {} + const pageTransforms: Record = {} let shapesForContent = dedupe( ids @@ -7687,9 +7687,9 @@ export class Editor extends EventEmitter { : getCurvedArrowInfo(this, shape) if (info?.isValid && infoAfter?.isValid && !getIsArrowStraight(shape)) { - const mpA = Vec2d.Med(info.start.handle, info.end.handle) - const distA = Vec2d.Dist(info.middle, mpA) - const distB = Vec2d.Dist(infoAfter.middle, mpA) + const mpA = Vec.Med(info.start.handle, info.end.handle) + const distA = Vec.Dist(info.middle, mpA) + const distB = Vec.Dist(infoAfter.middle, mpA) if (shape.props.bend < 0) { shape.props.bend += distB - distA } else { @@ -8007,19 +8007,19 @@ export class Editor extends EventEmitter { } const newCreatedShapes = newShapes.map((s) => this.getShape(s.id)!) - const bounds = Box2d.Common(newCreatedShapes.map((s) => this.getShapePageBounds(s)!)) + const bounds = Box.Common(newCreatedShapes.map((s) => this.getShapePageBounds(s)!)) if (point === undefined) { if (!isPageId(pasteParentId)) { // Put the shapes in the middle of the (on screen) parent const shape = this.getShape(pasteParentId)! - point = Matrix2d.applyToPoint( + point = Mat.applyToPoint( this.getShapePageTransform(shape), this.getShapeGeometry(shape).bounds.center ) } else { const viewportPageBounds = this.getViewportPageBounds() - if (preservePosition || viewportPageBounds.includes(Box2d.From(bounds))) { + if (preservePosition || viewportPageBounds.includes(Box.From(bounds))) { // Otherwise, put shapes where they used to be point = bounds.center } else { @@ -8047,17 +8047,17 @@ export class Editor extends EventEmitter { } } - const pageCenter = Box2d.Common( + const pageCenter = Box.Common( compact(rootShapes.map(({ id }) => this.getShapePageBounds(id))) ).center - const offset = Vec2d.Sub(point, pageCenter) + const offset = Vec.Sub(point, pageCenter) this.updateShapes( rootShapes.map(({ id }) => { const s = this.getShape(id)! const localRotation = this.getShapeParentTransform(id).decompose().rotation - const localDelta = Vec2d.Rot(offset, -localRotation) + const localDelta = Vec.Rot(offset, -localRotation) return { id: s.id, type: s.type, x: s.x + localDelta.x, y: s.y + localDelta.y } }) @@ -8301,17 +8301,17 @@ export class Editor extends EventEmitter { */ inputs = { /** The most recent pointer down's position in the current page space. */ - originPagePoint: new Vec2d(), + originPagePoint: new Vec(), /** The most recent pointer down's position in screen space. */ - originScreenPoint: new Vec2d(), + originScreenPoint: new Vec(), /** The previous pointer position in the current page space. */ - previousPagePoint: new Vec2d(), + previousPagePoint: new Vec(), /** The previous pointer position in screen space. */ - previousScreenPoint: new Vec2d(), + previousScreenPoint: new Vec(), /** The most recent pointer position in the current page space. */ - currentPagePoint: new Vec2d(), + currentPagePoint: new Vec(), /** The most recent pointer position in screen space. */ - currentScreenPoint: new Vec2d(), + currentScreenPoint: new Vec(), /** A set containing the currently pressed keys. */ keys: new Set(), /** A set containing the currently pressed buttons. */ @@ -8335,7 +8335,7 @@ export class Editor extends EventEmitter { /** Whether the user is panning. */ isPanning: false, /** Velocity of mouse pointer, in pixels per millisecond */ - pointerVelocity: new Vec2d(), + pointerVelocity: new Vec(), } /** @@ -8777,7 +8777,7 @@ export class Editor extends EventEmitter { if (this.inputs.isPanning && this.inputs.isPointing) { // Handle panning const { currentScreenPoint, previousScreenPoint } = this.inputs - this.pan(Vec2d.Sub(currentScreenPoint, previousScreenPoint)) + this.pan(Vec.Sub(currentScreenPoint, previousScreenPoint)) return } diff --git a/packages/editor/src/lib/editor/derivations/arrowBindingsIndex.ts b/packages/editor/src/lib/editor/derivations/arrowBindingsIndex.ts index 76c66697b..553c4a88e 100644 --- a/packages/editor/src/lib/editor/derivations/arrowBindingsIndex.ts +++ b/packages/editor/src/lib/editor/derivations/arrowBindingsIndex.ts @@ -2,7 +2,7 @@ import { Computed, RESET_VALUE, computed, isUninitialized } from '@tldraw/state' import { TLArrowShape, TLShape, TLShapeId } from '@tldraw/tlschema' import { Editor } from '../Editor' -export type TLArrowBindingsIndex = Record< +type TLArrowBindingsIndex = Record< TLShapeId, undefined | { arrowId: TLShapeId; handleId: 'start' | 'end' }[] > diff --git a/packages/editor/src/lib/editor/managers/ClickManager.ts b/packages/editor/src/lib/editor/managers/ClickManager.ts index 05b973a0c..ef2c11111 100644 --- a/packages/editor/src/lib/editor/managers/ClickManager.ts +++ b/packages/editor/src/lib/editor/managers/ClickManager.ts @@ -4,7 +4,7 @@ import { DRAG_DISTANCE, MULTI_CLICK_DURATION, } from '../../constants' -import { Vec2d } from '../../primitives/Vec2d' +import { Vec } from '../../primitives/Vec' import { uniqueId } from '../../utils/uniqueId' import type { Editor } from '../Editor' import { TLClickEventInfo, TLPointerEventInfo } from '../types/event-types' @@ -26,9 +26,9 @@ export class ClickManager { private _clickTimeout?: any - private _clickScreenPoint?: Vec2d + private _clickScreenPoint?: Vec - private _previousScreenPoint?: Vec2d + private _previousScreenPoint?: Vec private _getClickTimeout = (state: TLClickState, id = uniqueId()) => { this._clickId = id @@ -103,7 +103,7 @@ export class ClickManager { transformPointerDownEvent = (info: TLPointerEventInfo): TLPointerEventInfo | TLClickEventInfo => { if (!this._clickState) return info - this._clickScreenPoint = Vec2d.From(info.point) + this._clickScreenPoint = Vec.From(info.point) if ( this._previousScreenPoint && @@ -173,7 +173,7 @@ export class ClickManager { transformPointerUpEvent = (info: TLPointerEventInfo): TLPointerEventInfo | TLClickEventInfo => { if (!this._clickState) return info - this._clickScreenPoint = Vec2d.From(info.point) + this._clickScreenPoint = Vec.From(info.point) switch (this._clickState) { case 'pendingTriple': { diff --git a/packages/editor/src/lib/editor/managers/ScribbleManager.ts b/packages/editor/src/lib/editor/managers/ScribbleManager.ts index 2127e0862..11c45bfe2 100644 --- a/packages/editor/src/lib/editor/managers/ScribbleManager.ts +++ b/packages/editor/src/lib/editor/managers/ScribbleManager.ts @@ -1,5 +1,5 @@ -import { TLScribble, Vec2dModel } from '@tldraw/tlschema' -import { Vec2d } from '../../primitives/Vec2d' +import { TLScribble, VecModel } from '@tldraw/tlschema' +import { Vec } from '../../primitives/Vec' import { uniqueId } from '../../utils/uniqueId' import { Editor } from '../Editor' import { TLTickEvent } from '../types/event-types' @@ -9,8 +9,8 @@ type ScribbleItem = { scribble: TLScribble timeoutMs: number delayRemaining: number - prev: null | Vec2dModel - next: null | Vec2dModel + prev: null | VecModel + next: null | VecModel } /** @public */ @@ -87,7 +87,7 @@ export class ScribbleManager { if (!item) throw Error(`Scribble with id ${id} not found`) const { prev } = item const point = { x, y, z: 0.5 } - if (!prev || Vec2d.Dist(prev, point) >= 1) { + if (!prev || Vec.Dist(prev, point) >= 1) { item.next = point } return item diff --git a/packages/editor/src/lib/editor/managers/SnapManager.ts b/packages/editor/src/lib/editor/managers/SnapManager.ts index e12926af4..03e528f8e 100644 --- a/packages/editor/src/lib/editor/managers/SnapManager.ts +++ b/packages/editor/src/lib/editor/managers/SnapManager.ts @@ -1,17 +1,17 @@ import { atom, computed, EMPTY_ARRAY } from '@tldraw/state' -import { TLGroupShape, TLParentId, TLShape, TLShapeId, Vec2dModel } from '@tldraw/tlschema' +import { TLGroupShape, TLParentId, TLShape, TLShapeId, VecModel } from '@tldraw/tlschema' import { dedupe, deepCopy } from '@tldraw/utils' import { - Box2d, + Box, flipSelectionHandleX, flipSelectionHandleY, isSelectionCorner, SelectionCorner, SelectionEdge, -} from '../../primitives/Box2d' -import { Matrix2d } from '../../primitives/Matrix2d' +} from '../../primitives/Box' +import { Mat } from '../../primitives/Mat' import { rangeIntersection, rangesOverlap } from '../../primitives/utils' -import { Vec2d, VecLike } from '../../primitives/Vec2d' +import { Vec, VecLike } from '../../primitives/Vec' import { uniqueId } from '../../utils/uniqueId' import type { Editor } from '../Editor' @@ -36,16 +36,6 @@ export type GapsSnapLine = { /** @public */ export type SnapLine = PointsSnapLine | GapsSnapLine -export type SnapInteractionType = - | { - type: 'translate' - lockedAxis: 'x' | 'y' | null - initialSelectionSnapPoints: Vec2d[] - } - | { - type: 'resize' - } - /** @public */ export interface SnapPoint { id: string @@ -82,7 +72,7 @@ type NearestSnap = type GapNode = { id: TLShapeId - pageBounds: Box2d + pageBounds: Box isClosed: boolean } @@ -108,14 +98,14 @@ type Gap = { // ◄─────────────────────────► startNode: GapNode endNode: GapNode - startEdge: [Vec2d, Vec2d] - endEdge: [Vec2d, Vec2d] + startEdge: [Vec, Vec] + endEdge: [Vec, Vec] length: number breadthIntersection: [number, number] } interface SnapData { - nudge: Vec2d + nudge: Vec } const round = (x: number) => { @@ -235,7 +225,7 @@ export class SnapManager { if (!pageTransfrorm) return undefined const snapPoints = this.editor.getShapeGeometry(shape).snapPoints return snapPoints.map((point, i) => { - const { x, y } = Matrix2d.applyToPoint(pageTransfrorm, point) + const { x, y } = Mat.applyToPoint(pageTransfrorm, point) return { x, y, id: `${shape.id}:${i}` } }) }) @@ -336,12 +326,12 @@ export class SnapManager { startNode, endNode, startEdge: [ - new Vec2d(startNode.pageBounds.maxX, startNode.pageBounds.minY), - new Vec2d(startNode.pageBounds.maxX, startNode.pageBounds.maxY), + new Vec(startNode.pageBounds.maxX, startNode.pageBounds.minY), + new Vec(startNode.pageBounds.maxX, startNode.pageBounds.maxY), ], endEdge: [ - new Vec2d(endNode.pageBounds.minX, endNode.pageBounds.minY), - new Vec2d(endNode.pageBounds.minX, endNode.pageBounds.maxY), + new Vec(endNode.pageBounds.minX, endNode.pageBounds.minY), + new Vec(endNode.pageBounds.minX, endNode.pageBounds.maxY), ], length: endNode.pageBounds.minX - startNode.pageBounds.maxX, breadthIntersection: rangeIntersection( @@ -380,12 +370,12 @@ export class SnapManager { startNode, endNode, startEdge: [ - new Vec2d(startNode.pageBounds.minX, startNode.pageBounds.maxY), - new Vec2d(startNode.pageBounds.maxX, startNode.pageBounds.maxY), + new Vec(startNode.pageBounds.minX, startNode.pageBounds.maxY), + new Vec(startNode.pageBounds.maxX, startNode.pageBounds.maxY), ], endEdge: [ - new Vec2d(endNode.pageBounds.minX, endNode.pageBounds.minY), - new Vec2d(endNode.pageBounds.maxX, endNode.pageBounds.minY), + new Vec(endNode.pageBounds.minX, endNode.pageBounds.minY), + new Vec(endNode.pageBounds.maxX, endNode.pageBounds.minY), ], length: endNode.pageBounds.minY - startNode.pageBounds.maxY, breadthIntersection: rangeIntersection( @@ -410,8 +400,8 @@ export class SnapManager { }: { lockedAxis: 'x' | 'y' | null initialSelectionSnapPoints: SnapPoint[] - initialSelectionPageBounds: Box2d - dragDelta: Vec2d + initialSelectionPageBounds: Box + dragDelta: Vec }): SnapData { const snapThreshold = this.getSnapThreshold() const visibleSnapPointsNotInSelection = this.getSnappablePoints() @@ -428,7 +418,7 @@ export class SnapManager { const nearestSnapsX: NearestSnap[] = [] const nearestSnapsY: NearestSnap[] = [] - const minOffset = new Vec2d(snapThreshold, snapThreshold) + const minOffset = new Vec(snapThreshold, snapThreshold) this.collectPointSnaps({ minOffset, @@ -446,7 +436,7 @@ export class SnapManager { }) // at the same time, calculate how far we need to nudge the shape to 'snap' to the target point(s) - const nudge = new Vec2d( + const nudge = new Vec( lockedAxis === 'x' ? 0 : nearestSnapsX[0]?.nudge ?? 0, lockedAxis === 'y' ? 0 : nearestSnapsY[0]?.nudge ?? 0 ) @@ -501,7 +491,7 @@ export class SnapManager { if (isClosed) outline.push(outline[0]) const pageTransform = this.editor.getShapePageTransform(id) if (!pageTransform) throw Error('No page transform') - return Matrix2d.applyToPoints(pageTransform, outline) + return Mat.applyToPoints(pageTransform, outline) }) } @@ -509,16 +499,16 @@ export class SnapManager { handlePoint, additionalSegments, }: { - handlePoint: Vec2d - additionalSegments: Vec2d[][] - }): Vec2d | null { + handlePoint: Vec + additionalSegments: Vec[][] + }): Vec | null { const snapThreshold = this.getSnapThreshold() const outlinesInPageSpace = this.getOutlinesInPageSpace() // Find the nearest point that is within the snap threshold let minDistance = snapThreshold - let nearestPoint: Vec2d | null = null - let C: Vec2dModel, D: Vec2dModel, nearest: Vec2d, distance: number + let nearestPoint: Vec | null = null + let C: VecModel, D: VecModel, nearest: Vec, distance: number const allSegments = [...outlinesInPageSpace, ...additionalSegments] for (const outline of allSegments) { @@ -526,8 +516,8 @@ export class SnapManager { C = outline[i] D = outline[i + 1] - nearest = Vec2d.NearestPointOnLineSegment(C, D, handlePoint) - distance = Vec2d.Dist(handlePoint, nearest) + nearest = Vec.NearestPointOnLineSegment(C, D, handlePoint) + distance = Vec.Dist(handlePoint, nearest) if (isNaN(distance)) continue if (distance < minDistance) { @@ -547,7 +537,7 @@ export class SnapManager { }, ]) - return Vec2d.Sub(nearestPoint, handlePoint) + return Vec.Sub(nearestPoint, handlePoint) } return null @@ -561,9 +551,9 @@ export class SnapManager { isResizingFromCenter, }: { // the page bounds when the pointer went down, before any dragging - initialSelectionPageBounds: Box2d + initialSelectionPageBounds: Box // how far the pointer has been dragged - dragDelta: Vec2d + dragDelta: Vec handle: SelectionCorner | SelectionEdge isAspectRatioLocked: boolean @@ -576,7 +566,7 @@ export class SnapManager { box: unsnappedResizedPageBounds, scaleX, scaleY, - } = Box2d.Resize( + } = Box.Resize( initialSelectionPageBounds, originalHandle, isResizingFromCenter ? dragDelta.x * 2 : dragDelta.x, @@ -607,7 +597,7 @@ export class SnapManager { const nearestSnapsX: NearestPointsSnap[] = [] const nearestSnapsY: NearestPointsSnap[] = [] - const minOffset = new Vec2d(snapThreshold, snapThreshold) + const minOffset = new Vec(snapThreshold, snapThreshold) this.collectPointSnaps({ minOffset, @@ -618,7 +608,7 @@ export class SnapManager { }) // at the same time, calculate how far we need to nudge the shape to 'snap' to the target point(s) - const nudge = new Vec2d( + const nudge = new Vec( isXLocked ? 0 : nearestSnapsX[0]?.nudge ?? 0, isYLocked ? 0 : nearestSnapsY[0]?.nudge ?? 0 ) @@ -657,10 +647,10 @@ export class SnapManager { // now resize the box after nudging, calculate the snaps again, and return the snap lines to match // the fully resized box - const snappedDelta = Vec2d.Add(dragDelta, nudge) + const snappedDelta = Vec.Add(dragDelta, nudge) // first figure out the new bounds of the selection - const { box: snappedResizedPageBounds } = Box2d.Resize( + const { box: snappedResizedPageBounds } = Box.Resize( initialSelectionPageBounds, originalHandle, isResizingFromCenter ? snappedDelta.x * 2 : snappedDelta.x, @@ -706,7 +696,7 @@ export class SnapManager { }: { selectionSnapPoints: SnapPoint[] otherNodeSnapPoints: SnapPoint[] - minOffset: Vec2d + minOffset: Vec nearestSnapsX: NearestSnap[] nearestSnapsY: NearestSnap[] }) { @@ -714,7 +704,7 @@ export class SnapManager { // which are closest to it in each axis for (const thisSnapPoint of selectionSnapPoints) { for (const otherSnapPoint of otherNodeSnapPoints) { - const offset = Vec2d.Sub(thisSnapPoint, otherSnapPoint) + const offset = Vec.Sub(thisSnapPoint, otherSnapPoint) const offsetX = Math.abs(offset.x) const offsetY = Math.abs(offset.y) @@ -756,8 +746,8 @@ export class SnapManager { nearestSnapsX, nearestSnapsY, }: { - selectionPageBounds: Box2d - minOffset: Vec2d + selectionPageBounds: Box + minOffset: Vec nearestSnapsX: NearestSnap[] nearestSnapsY: NearestSnap[] }) { @@ -1078,10 +1068,10 @@ export class SnapManager { type: 'points', points: dedupe( snapGroup - .map((snap) => Vec2d.From(snap.otherPoint)) + .map((snap) => Vec.From(snap.otherPoint)) // be sure to nudge over the selection snap points - .concat(snapGroup.map((snap) => Vec2d.From(snap.thisPoint))), - (a: Vec2d, b: Vec2d) => a.equals(b) + .concat(snapGroup.map((snap) => Vec.From(snap.thisPoint))), + (a: Vec, b: Vec) => a.equals(b) ), })) } @@ -1091,13 +1081,13 @@ export class SnapManager { nearestSnapsX, nearestSnapsY, }: { - selectionPageBounds: Box2d + selectionPageBounds: Box nearestSnapsX: NearestSnap[] nearestSnapsY: NearestSnap[] }): GapsSnapLine[] { const { vertical, horizontal } = this.getVisibleGaps() - const selectionSides: Record = { + const selectionSides: Record = { top: selectionPageBounds.sides[0], right: selectionPageBounds.sides[1], // need bottom and left to be sorted asc, which .sides is not. @@ -1175,7 +1165,7 @@ export class SnapManager { startEdge: selectionSides.right, endEdge: startEdge.map((v) => v.clone().addXY(-startNode.pageBounds.width, 0) - ) as [Vec2d, Vec2d], + ) as [Vec, Vec], }, { startEdge, endEdge }, ...findAdjacentGaps( @@ -1198,7 +1188,7 @@ export class SnapManager { { startEdge: endEdge.map((v) => v.clone().addXY(snap.gap.endNode.pageBounds.width, 0) - ) as [Vec2d, Vec2d], + ) as [Vec, Vec], endEdge: selectionSides.left, }, ], @@ -1279,7 +1269,7 @@ export class SnapManager { startEdge: selectionSides.bottom, endEdge: startEdge.map((v) => v.clone().addXY(0, -startNode.pageBounds.height) - ) as [Vec2d, Vec2d], + ) as [Vec, Vec], }, { startEdge, endEdge }, ...findAdjacentGaps( @@ -1302,7 +1292,7 @@ export class SnapManager { { startEdge: endEdge.map((v) => v.clone().addXY(0, endNode.pageBounds.height) - ) as [Vec2d, Vec2d], + ) as [Vec, Vec], endEdge: selectionSides.top, }, ], @@ -1320,7 +1310,7 @@ export class SnapManager { function getResizeSnapPointsForHandle( handle: SelectionCorner | SelectionEdge | 'any', - selectionPageBounds: Box2d + selectionPageBounds: Box ): SnapPoint[] { const { minX, maxX, minY, maxY } = selectionPageBounds const result: SnapPoint[] = [] diff --git a/packages/editor/src/lib/editor/managers/TextManager.ts b/packages/editor/src/lib/editor/managers/TextManager.ts index 47430cd47..c03071efd 100644 --- a/packages/editor/src/lib/editor/managers/TextManager.ts +++ b/packages/editor/src/lib/editor/managers/TextManager.ts @@ -1,4 +1,4 @@ -import { Box2dModel, TLDefaultHorizontalAlignStyle } from '@tldraw/tlschema' +import { BoxModel, TLDefaultHorizontalAlignStyle } from '@tldraw/tlschema' import { uniqueId } from '../../utils/uniqueId' import { Editor } from '../Editor' @@ -72,7 +72,7 @@ export class TextManager { minWidth?: string padding: string } - ): Box2dModel => { + ): BoxModel => { const elm = this.getTextElement() elm.setAttribute('dir', 'ltr') @@ -103,7 +103,7 @@ export class TextManager { measureElementTextNodeSpans( element: HTMLElement, { shouldTruncateToFirstLine = false }: { shouldTruncateToFirstLine?: boolean } = {} - ): { spans: { box: Box2dModel; text: string }[]; didTruncate: boolean } { + ): { spans: { box: BoxModel; text: string }[]; didTruncate: boolean } { const spans = [] // Measurements of individual spans are relative to the containing element @@ -195,7 +195,7 @@ export class TextManager { measureTextSpans( textToMeasure: string, opts: TLMeasureTextSpanOpts - ): { text: string; box: Box2dModel }[] { + ): { text: string; box: BoxModel }[] { if (textToMeasure === '') return [] const shouldTruncateToFirstLine = diff --git a/packages/editor/src/lib/editor/managers/TickManager.ts b/packages/editor/src/lib/editor/managers/TickManager.ts index 4943eaf92..f1bc83363 100644 --- a/packages/editor/src/lib/editor/managers/TickManager.ts +++ b/packages/editor/src/lib/editor/managers/TickManager.ts @@ -1,4 +1,4 @@ -import { Vec2d } from '../../primitives/Vec2d' +import { Vec } from '../../primitives/Vec' import { Editor } from '../Editor' export class TickManager { @@ -48,7 +48,7 @@ export class TickManager { cancelAnimationFrame(this.raf) } - private prevPoint = new Vec2d() + private prevPoint = new Vec() private updatePointerVelocity = (elapsed: number) => { const { @@ -60,11 +60,11 @@ export class TickManager { if (elapsed === 0) return - const delta = Vec2d.Sub(currentScreenPoint, prevPoint) + const delta = Vec.Sub(currentScreenPoint, prevPoint) this.prevPoint = currentScreenPoint.clone() const length = delta.len() - const direction = length ? delta.div(length) : new Vec2d(0, 0) + const direction = length ? delta.div(length) : new Vec(0, 0) // consider adjusting this with an easing rather than a linear interpolation const next = pointerVelocity.clone().lrp(direction.mul(length / elapsed), 0.5) diff --git a/packages/editor/src/lib/editor/managers/getRecordManager.test.ts b/packages/editor/src/lib/editor/managers/getRecordManager.test.ts deleted file mode 100644 index a684f6bf3..000000000 --- a/packages/editor/src/lib/editor/managers/getRecordManager.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { atom } from '@tldraw/state' -import { getAtomManager } from './getRecordManager' - -describe('atom manager', () => { - it('manages an atom object', () => { - const cb = jest.fn() - const A = atom('abc', { a: 1, b: 2, c: 3 }) - const manager = getAtomManager(A, cb) - - expect(A.lastChangedEpoch).toBe(0) - - manager.a = 2 - expect(manager.a).toBe(2) - expect(A.lastChangedEpoch).toBe(1) - - manager.b = 4 - expect(manager.b).toBe(4) - expect(A.lastChangedEpoch).toBe(2) - - manager.b - expect(A.get()).toMatchObject({ a: 2, b: 4, c: 3 }) - - expect(cb).toHaveBeenCalledTimes(2) - }) -}) diff --git a/packages/editor/src/lib/editor/managers/getRecordManager.ts b/packages/editor/src/lib/editor/managers/getRecordManager.ts deleted file mode 100644 index 2ce9bca8e..000000000 --- a/packages/editor/src/lib/editor/managers/getRecordManager.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Atom, computed } from '@tldraw/state' - -export function getAtomManager( - atom: Atom, - transform?: (prev: T, next: T) => T -): T { - const update = (value: Partial) => { - const curr = atom.get() - const next = { ...curr, ...value } - const final = transform?.(atom.get(), atom.get()) ?? next - atom.set(final) - } - - return Object.defineProperties( - {} as T, - Object.keys(atom.get()).reduce((acc, key) => { - acc[key as keyof T] = computed(atom, key, { - get() { - return atom.get()[key as keyof T] - }, - set(value: T[keyof T]) { - update({ [key]: value } as any) - }, - }) - return acc - }, {} as { [key in keyof T]: PropertyDescriptor }) - ) -} diff --git a/packages/editor/src/lib/editor/shapes/ShapeUtil.ts b/packages/editor/src/lib/editor/shapes/ShapeUtil.ts index 07ea80799..766555a48 100644 --- a/packages/editor/src/lib/editor/shapes/ShapeUtil.ts +++ b/packages/editor/src/lib/editor/shapes/ShapeUtil.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import { Migrations } from '@tldraw/store' import { ShapeProps, TLHandle, TLShape, TLShapePartial, TLUnknownShape } from '@tldraw/tlschema' -import { Box2d } from '../../primitives/Box2d' -import { Vec2d } from '../../primitives/Vec2d' +import { Box } from '../../primitives/Box' +import { Vec } from '../../primitives/Vec' import { Geometry2d } from '../../primitives/geometry/Geometry2d' import type { Editor } from '../Editor' import { SvgExportContext } from '../types/SvgExportContext' @@ -214,7 +214,7 @@ export abstract class ShapeUtil { * @param shape - The shape. * @public */ - getOutlineSegments(shape: Shape): Vec2d[][] { + getOutlineSegments(shape: Shape): Vec[][] { return [this.editor.getShapeGeometry(shape).vertices] } @@ -554,12 +554,12 @@ export type TLResizeMode = 'scale_shape' | 'resize_bounds' * @public */ export type TLResizeInfo = { - newPoint: Vec2d + newPoint: Vec handle: TLResizeHandle mode: TLResizeMode scaleX: number scaleY: number - initialBounds: Box2d + initialBounds: Box initialShape: T } diff --git a/packages/editor/src/lib/editor/shapes/group/DashedOutlineBox.tsx b/packages/editor/src/lib/editor/shapes/group/DashedOutlineBox.tsx index 725ad0b6f..d55a501e0 100644 --- a/packages/editor/src/lib/editor/shapes/group/DashedOutlineBox.tsx +++ b/packages/editor/src/lib/editor/shapes/group/DashedOutlineBox.tsx @@ -1,9 +1,9 @@ import { useValue } from '@tldraw/state' import { useEditor } from '../../../hooks/useEditor' -import { Box2d } from '../../../primitives/Box2d' +import { Box } from '../../../primitives/Box' import { getPerfectDashProps } from '../shared/getPerfectDashProps' -export function DashedOutlineBox({ bounds, className }: { bounds: Box2d; className: string }) { +export function DashedOutlineBox({ bounds, className }: { bounds: Box; className: string }) { const editor = useEditor() const zoomLevel = useValue('zoom level', () => editor.getZoomLevel(), [editor]) diff --git a/packages/editor/src/lib/editor/shapes/shared/arrow/arrow-types.ts b/packages/editor/src/lib/editor/shapes/shared/arrow/arrow-types.ts index 3cfe3b580..dbcba62a8 100644 --- a/packages/editor/src/lib/editor/shapes/shared/arrow/arrow-types.ts +++ b/packages/editor/src/lib/editor/shapes/shared/arrow/arrow-types.ts @@ -1,5 +1,5 @@ import { TLArrowShapeArrowheadStyle } from '@tldraw/tlschema' -import { VecLike } from '../../../../primitives/Vec2d' +import { VecLike } from '../../../../primitives/Vec' /** @public */ export type TLArrowPoint = { diff --git a/packages/editor/src/lib/editor/shapes/shared/arrow/curved-arrow.ts b/packages/editor/src/lib/editor/shapes/shared/arrow/curved-arrow.ts index 3194b46eb..352eac392 100644 --- a/packages/editor/src/lib/editor/shapes/shared/arrow/curved-arrow.ts +++ b/packages/editor/src/lib/editor/shapes/shared/arrow/curved-arrow.ts @@ -1,7 +1,6 @@ import { TLArrowShape } from '@tldraw/tlschema' -import { Box2d } from '../../../../primitives/Box2d' -import { Matrix2d } from '../../../../primitives/Matrix2d' -import { Vec2d, VecLike } from '../../../../primitives/Vec2d' +import { Mat } from '../../../../primitives/Mat' +import { Vec, VecLike } from '../../../../primitives/Vec' import { intersectCirclePolygon, intersectCirclePolyline } from '../../../../primitives/intersect' import { PI, @@ -37,9 +36,9 @@ export function getCurvedArrowInfo( const terminalsInArrowSpace = getArrowTerminalsInArrowSpace(editor, shape) - const med = Vec2d.Med(terminalsInArrowSpace.start, terminalsInArrowSpace.end) // point between start and end - const u = Vec2d.Sub(terminalsInArrowSpace.end, terminalsInArrowSpace.start).uni() // unit vector between start and end - const middle = Vec2d.Add(med, u.per().mul(-bend)) // middle handle + const med = Vec.Med(terminalsInArrowSpace.start, terminalsInArrowSpace.end) // point between start and end + const u = Vec.Sub(terminalsInArrowSpace.end, terminalsInArrowSpace.start).uni() // unit vector between start and end + const middle = Vec.Add(med, u.per().mul(-bend)) // middle handle const startShapeInfo = getBoundShapeInfoForTerminal(editor, shape.props.start) const endShapeInfo = getBoundShapeInfoForTerminal(editor, shape.props.end) @@ -50,7 +49,7 @@ export function getCurvedArrowInfo( const b = terminalsInArrowSpace.end.clone() const c = middle.clone() - if (Vec2d.Equals(a, b)) { + if (Vec.Equals(a, b)) { return { isStraight: true, start: { @@ -73,8 +72,8 @@ export function getCurvedArrowInfo( const distFn = isClockwise ? clockwiseAngleDist : counterClockwiseAngleDist const handleArc = getArcInfo(a, b, c) - const handle_aCA = Vec2d.Angle(handleArc.center, a) - const handle_aCB = Vec2d.Angle(handleArc.center, b) + const handle_aCA = Vec.Angle(handleArc.center, a) + const handle_aCB = Vec.Angle(handleArc.center, b) const handle_dAB = distFn(handle_aCA, handle_aCB) if ( @@ -98,15 +97,15 @@ export function getCurvedArrowInfo( let minLength = MIN_ARROW_LENGTH if (startShapeInfo && !startShapeInfo.isExact) { - const startInPageSpace = Matrix2d.applyToPoint(arrowPageTransform, tempA) - const centerInPageSpace = Matrix2d.applyToPoint(arrowPageTransform, handleArc.center) - const endInPageSpace = Matrix2d.applyToPoint(arrowPageTransform, tempB) + const startInPageSpace = Mat.applyToPoint(arrowPageTransform, tempA) + const centerInPageSpace = Mat.applyToPoint(arrowPageTransform, handleArc.center) + const endInPageSpace = Mat.applyToPoint(arrowPageTransform, tempB) - const inverseTransform = Matrix2d.Inverse(startShapeInfo.transform) + const inverseTransform = Mat.Inverse(startShapeInfo.transform) - const startInStartShapeLocalSpace = Matrix2d.applyToPoint(inverseTransform, startInPageSpace) - const centerInStartShapeLocalSpace = Matrix2d.applyToPoint(inverseTransform, centerInPageSpace) - const endInStartShapeLocalSpace = Matrix2d.applyToPoint(inverseTransform, endInPageSpace) + const startInStartShapeLocalSpace = Mat.applyToPoint(inverseTransform, startInPageSpace) + const centerInStartShapeLocalSpace = Mat.applyToPoint(inverseTransform, centerInPageSpace) + const endInStartShapeLocalSpace = Mat.applyToPoint(inverseTransform, endInPageSpace) const { isClosed } = startShapeInfo const fn = isClosed ? intersectCirclePolygon : intersectCirclePolyline @@ -148,7 +147,7 @@ export function getCurvedArrowInfo( if (point) { tempA.setTo( - editor.getPointInShapeSpace(shape, Matrix2d.applyToPoint(startShapeInfo.transform, point)) + editor.getPointInShapeSpace(shape, Mat.applyToPoint(startShapeInfo.transform, point)) ) startShapeInfo.didIntersect = true @@ -167,15 +166,15 @@ export function getCurvedArrowInfo( if (endShapeInfo && !endShapeInfo.isExact) { // get points in shape's coordinates? - const startInPageSpace = Matrix2d.applyToPoint(arrowPageTransform, tempA) - const endInPageSpace = Matrix2d.applyToPoint(arrowPageTransform, tempB) - const centerInPageSpace = Matrix2d.applyToPoint(arrowPageTransform, handleArc.center) + const startInPageSpace = Mat.applyToPoint(arrowPageTransform, tempA) + const endInPageSpace = Mat.applyToPoint(arrowPageTransform, tempB) + const centerInPageSpace = Mat.applyToPoint(arrowPageTransform, handleArc.center) - const inverseTransform = Matrix2d.Inverse(endShapeInfo.transform) + const inverseTransform = Mat.Inverse(endShapeInfo.transform) - const startInEndShapeLocalSpace = Matrix2d.applyToPoint(inverseTransform, startInPageSpace) - const centerInEndShapeLocalSpace = Matrix2d.applyToPoint(inverseTransform, centerInPageSpace) - const endInEndShapeLocalSpace = Matrix2d.applyToPoint(inverseTransform, endInPageSpace) + const startInEndShapeLocalSpace = Mat.applyToPoint(inverseTransform, startInPageSpace) + const centerInEndShapeLocalSpace = Mat.applyToPoint(inverseTransform, centerInPageSpace) + const endInEndShapeLocalSpace = Mat.applyToPoint(inverseTransform, endInPageSpace) const isClosed = endShapeInfo.isClosed const fn = isClosed ? intersectCirclePolygon : intersectCirclePolyline @@ -222,7 +221,7 @@ export function getCurvedArrowInfo( if (point) { // Set b to target local point -> page point -> shape local point tempB.setTo( - editor.getPointInShapeSpace(shape, Matrix2d.applyToPoint(endShapeInfo.transform, point)) + editor.getPointInShapeSpace(shape, Mat.applyToPoint(endShapeInfo.transform, point)) ) endShapeInfo.didIntersect = true @@ -239,8 +238,8 @@ export function getCurvedArrowInfo( // Apply arrowhead offsets - let aCA = Vec2d.Angle(handleArc.center, tempA) // angle center -> a - let aCB = Vec2d.Angle(handleArc.center, tempB) // angle center -> b + let aCA = Vec.Angle(handleArc.center, tempA) // angle center -> a + let aCB = Vec.Angle(handleArc.center, tempB) // angle center -> b let dAB = distFn(aCA, aCB) // angle distance between a and b let lAB = dAB * handleArc.radius // length of arc between a and b @@ -252,17 +251,17 @@ export function getCurvedArrowInfo( if (offsetA !== 0) { const n = (offsetA / lAB) * (isClockwise ? 1 : -1) - const u = Vec2d.FromAngle(aCA + dAB * n) + const u = Vec.FromAngle(aCA + dAB * n) tA.setTo(handleArc.center).add(u.mul(handleArc.radius)) } if (offsetB !== 0) { const n = (offsetB / lAB) * (isClockwise ? -1 : 1) - const u = Vec2d.FromAngle(aCB + dAB * n) + const u = Vec.FromAngle(aCB + dAB * n) tB.setTo(handleArc.center).add(u.mul(handleArc.radius)) } - const distAB = Vec2d.Dist(tA, tB) + const distAB = Vec.Dist(tA, tB) if (distAB < minLength) { if (offsetA !== 0 && offsetB !== 0) { offsetA *= -1.5 @@ -278,20 +277,20 @@ export function getCurvedArrowInfo( if (offsetA !== 0) { const n = (offsetA / lAB) * (isClockwise ? 1 : -1) - const u = Vec2d.FromAngle(aCA + dAB * n) + const u = Vec.FromAngle(aCA + dAB * n) tempA.setTo(handleArc.center).add(u.mul(handleArc.radius)) } if (offsetB !== 0) { const n = (offsetB / lAB) * (isClockwise ? -1 : 1) - const u = Vec2d.FromAngle(aCB + dAB * n) + const u = Vec.FromAngle(aCB + dAB * n) tempB.setTo(handleArc.center).add(u.mul(handleArc.radius)) } // Did we miss intersections? This happens when we have overlapping shapes. if (startShapeInfo && endShapeInfo && !startShapeInfo.isExact && !endShapeInfo.isExact) { - aCA = Vec2d.Angle(handleArc.center, tempA) // angle center -> a - aCB = Vec2d.Angle(handleArc.center, tempB) // angle center -> b + aCA = Vec.Angle(handleArc.center, tempA) // angle center -> a + aCB = Vec.Angle(handleArc.center, tempB) // angle center -> b dAB = distFn(aCA, aCB) // angle distance between a and b lAB = dAB * handleArc.radius // length of arc between a and b const relationship = getBoundShapeRelationships( @@ -314,7 +313,7 @@ export function getCurvedArrowInfo( distFn(handle_aCA, aCA) > distFn(handle_aCA, aCB) ) { const n = Math.min(0.9, MIN_ARROW_LENGTH / lAB) * (isClockwise ? 1 : -1) - const u = Vec2d.FromAngle(aCA + dAB * n) + const u = Vec.FromAngle(aCA + dAB * n) tempB.setTo(handleArc.center).add(u.mul(handleArc.radius)) } } @@ -359,87 +358,6 @@ export function getCurvedArrowInfo( } } -/** - * Get a solid path for a curved arrow's handles. - * - * @param info - The arrow info. - * @public - */ -export function getCurvedArrowHandlePath(info: TLArrowInfo & { isStraight: false }) { - const { - start, - end, - handleArc: { radius, largeArcFlag, sweepFlag }, - } = info - return `M${start.handle.x},${start.handle.y} A${radius} ${radius} 0 ${largeArcFlag} ${sweepFlag} ${end.handle.x},${end.handle.y}` -} - -/** - * Get a solid path for a curved arrow's body. - * - * @param info - The arrow info. - * @public - */ -export function getSolidCurvedArrowPath(info: TLArrowInfo & { isStraight: false }) { - const { - start, - end, - bodyArc: { radius, largeArcFlag, sweepFlag }, - } = info - return `M${start.point.x},${start.point.y} A${radius} ${radius} 0 ${largeArcFlag} ${sweepFlag} ${end.point.x},${end.point.y}` -} - -/** - * Get a point along an arc. - * - * @param center - The arc's center. - * @param radius - The arc's radius. - * @param startAngle - The start point of the arc. - * @param size - The size of the arc. - * @param t - The point along the arc to get. - */ -export function getPointOnArc( - center: VecLike, - radius: number, - startAngle: number, - size: number, - t: number -) { - const angle = startAngle + size * t - return new Vec2d(center.x + radius * Math.cos(angle), center.y + radius * Math.sin(angle)) -} - -/** - * Get a bounding box for an arc. - * - * @param center - The arc's center. - * @param radius - The arc's radius. - * @param start - The start point of the arc. - * @param size - The size of the arc. - */ -export function getArcBoundingBox(center: VecLike, radius: number, start: VecLike, size: number) { - let minX = Infinity - let minY = Infinity - let maxX = -Infinity - let maxY = -Infinity - - const startAngle = Vec2d.Angle(center, start) - - // Test 20 points along the arc - for (let i = 0; i < 20; i++) { - const angle = startAngle + size * (i / 19) - const x = center.x + radius * Math.cos(angle) - const y = center.y + radius * Math.sin(angle) - - minX = Math.min(x, minX) - minY = Math.min(y, minY) - maxX = Math.max(x, maxX) - maxY = Math.max(y, maxY) - } - - return new Box2d(minX, minY, maxX - minX, maxY - minY) -} - /** * Get info about an arc formed by three points. * @@ -447,7 +365,7 @@ export function getArcBoundingBox(center: VecLike, radius: number, start: VecLik * @param b - The end of the arc * @param c - A point on the arc */ -export function getArcInfo(a: VecLike, b: VecLike, c: VecLike): TLArcInfo { +function getArcInfo(a: VecLike, b: VecLike, c: VecLike): TLArcInfo { // find a circle from the three points const u = -2 * (a.x * (b.y - c.y) - a.y * (b.x - c.x) + b.x * c.y - c.x * b.y) @@ -464,10 +382,10 @@ export function getArcInfo(a: VecLike, b: VecLike, c: VecLike): TLArcInfo { u, } - const radius = Vec2d.Dist(center, a) + const radius = Vec.Dist(center, a) // Whether to draw the arc clockwise or counter-clockwise (are the points clockwise?) - const sweepFlag = +Vec2d.Clockwise(a, c, b) + const sweepFlag = +Vec.Clockwise(a, c, b) // The base angle of the arc in radians const ab = Math.hypot(a.y - b.y, a.x - b.x) @@ -498,19 +416,19 @@ export function getArcInfo(a: VecLike, b: VecLike, c: VecLike): TLArcInfo { function placeCenterHandle( center: VecLike, radius: number, - tempA: Vec2d, - tempB: Vec2d, - tempC: Vec2d, + tempA: Vec, + tempB: Vec, + tempC: Vec, originalArcLength: number, isClockwise: boolean ) { - const aCA = Vec2d.Angle(center, tempA) // angle center -> a - const aCB = Vec2d.Angle(center, tempB) // angle center -> b + const aCA = Vec.Angle(center, tempA) // angle center -> a + const aCB = Vec.Angle(center, tempB) // angle center -> b let dAB = clockwiseAngleDist(aCA, aCB) // angle distance between a and b if (!isClockwise) dAB = PI2 - dAB const n = 0.5 * (isClockwise ? 1 : -1) - const u = Vec2d.FromAngle(aCA + dAB * n) + const u = Vec.FromAngle(aCA + dAB * n) tempC.setTo(center).add(u.mul(radius)) if (dAB > originalArcLength) { diff --git a/packages/editor/src/lib/editor/shapes/shared/arrow/shared.ts b/packages/editor/src/lib/editor/shapes/shared/arrow/shared.ts index 729b29483..a42559ddb 100644 --- a/packages/editor/src/lib/editor/shapes/shared/arrow/shared.ts +++ b/packages/editor/src/lib/editor/shapes/shared/arrow/shared.ts @@ -1,6 +1,6 @@ import { TLArrowShape, TLArrowShapeTerminal, TLShape, TLShapeId } from '@tldraw/tlschema' -import { Matrix2d } from '../../../../primitives/Matrix2d' -import { Vec2d } from '../../../../primitives/Vec2d' +import { Mat } from '../../../../primitives/Mat' +import { Vec } from '../../../../primitives/Vec' import { Group2d } from '../../../../primitives/geometry/Group2d' import { Editor } from '../../../Editor' @@ -13,8 +13,8 @@ export type BoundShapeInfo = { didIntersect: boolean isExact: boolean isClosed: boolean - transform: Matrix2d - outline: Vec2d[] + transform: Mat + outline: Vec[] } export function getBoundShapeInfoForTerminal( @@ -45,36 +45,36 @@ export function getBoundShapeInfoForTerminal( } } -export function getArrowTerminalInArrowSpace( +function getArrowTerminalInArrowSpace( editor: Editor, - arrowPageTransform: Matrix2d, + arrowPageTransform: Mat, terminal: TLArrowShapeTerminal, forceImprecise: boolean ) { if (terminal.type === 'point') { - return Vec2d.From(terminal) + return Vec.From(terminal) } const boundShape = editor.getShape(terminal.boundShapeId) if (!boundShape) { // this can happen in multiplayer contexts where the shape is being deleted - return new Vec2d(0, 0) + return new Vec(0, 0) } else { // Find the actual local point of the normalized terminal on // the bound shape and transform it to page space, then transform // it to arrow space const { point, size } = editor.getShapeGeometry(boundShape).bounds - const shapePoint = Vec2d.Add( + const shapePoint = Vec.Add( point, - Vec2d.MulV( + Vec.MulV( // if the parent is the bound shape, then it's ALWAYS precise terminal.isPrecise || forceImprecise ? terminal.normalizedAnchor : { x: 0.5, y: 0.5 }, size ) ) - const pagePoint = Matrix2d.applyToPoint(editor.getShapePageTransform(boundShape)!, shapePoint) - const arrowPoint = Matrix2d.applyToPoint(Matrix2d.Inverse(arrowPageTransform), pagePoint) + const pagePoint = Mat.applyToPoint(editor.getShapePageTransform(boundShape)!, shapePoint) + const arrowPoint = Mat.applyToPoint(Mat.Inverse(arrowPageTransform), pagePoint) return arrowPoint } } diff --git a/packages/editor/src/lib/editor/shapes/shared/arrow/straight-arrow.ts b/packages/editor/src/lib/editor/shapes/shared/arrow/straight-arrow.ts index 838f63181..65e791699 100644 --- a/packages/editor/src/lib/editor/shapes/shared/arrow/straight-arrow.ts +++ b/packages/editor/src/lib/editor/shapes/shared/arrow/straight-arrow.ts @@ -1,7 +1,6 @@ import { TLArrowShape } from '@tldraw/tlschema' -import { Box2d } from '../../../../primitives/Box2d' -import { Matrix2d, Matrix2dModel } from '../../../../primitives/Matrix2d' -import { Vec2d, VecLike } from '../../../../primitives/Vec2d' +import { Mat, MatModel } from '../../../../primitives/Mat' +import { Vec, VecLike } from '../../../../primitives/Vec' import { intersectLineSegmentPolygon, intersectLineSegmentPolyline, @@ -25,9 +24,9 @@ export function getStraightArrowInfo(editor: Editor, shape: TLArrowShape): TLArr const a = terminalsInArrowSpace.start.clone() const b = terminalsInArrowSpace.end.clone() - const c = Vec2d.Med(a, b) + const c = Vec.Med(a, b) - if (Vec2d.Equals(a, b)) { + if (Vec.Equals(a, b)) { return { isStraight: true, start: { @@ -46,7 +45,7 @@ export function getStraightArrowInfo(editor: Editor, shape: TLArrowShape): TLArr } } - const uAB = Vec2d.Sub(b, a).uni() + const uAB = Vec.Sub(b, a).uni() // Update the arrowhead points using intersections with the bound shapes, if any. @@ -110,8 +109,8 @@ export function getStraightArrowInfo(editor: Editor, shape: TLArrowShape): TLArr } } - const u = Vec2d.Sub(b, a).uni() - const didFlip = !Vec2d.Equals(u, uAB) + const u = Vec.Sub(b, a).uni() + const didFlip = !Vec.Equals(u, uAB) // If the arrow is bound non-exact to a start shape and the // start point has an arrowhead, then offset the start point @@ -151,7 +150,7 @@ export function getStraightArrowInfo(editor: Editor, shape: TLArrowShape): TLArr const tA = a.clone().add(u.clone().mul(offsetA * (didFlip ? -1 : 1))) const tB = b.clone().sub(u.clone().mul(offsetB * (didFlip ? -1 : 1))) - const distAB = Vec2d.Dist(tA, tB) + const distAB = Vec.Dist(tA, tB) if (distAB < minLength) { if (offsetA !== 0 && offsetB !== 0) { @@ -179,14 +178,14 @@ export function getStraightArrowInfo(editor: Editor, shape: TLArrowShape): TLArr if (startShapeInfo && endShapeInfo) { // If we have two bound shapes...then make the arrow a short arrow from // the start point towards where the end point should be. - b.setTo(Vec2d.Add(a, u.clone().mul(-MIN_ARROW_LENGTH))) + b.setTo(Vec.Add(a, u.clone().mul(-MIN_ARROW_LENGTH))) } - c.setTo(Vec2d.Med(terminalsInArrowSpace.start, terminalsInArrowSpace.end)) + c.setTo(Vec.Med(terminalsInArrowSpace.start, terminalsInArrowSpace.end)) } else { - c.setTo(Vec2d.Med(a, b)) + c.setTo(Vec.Med(a, b)) } - const length = Vec2d.Dist(a, b) + const length = Vec.Dist(a, b) return { isStraight: true, @@ -208,9 +207,9 @@ export function getStraightArrowInfo(editor: Editor, shape: TLArrowShape): TLArr /** Get an intersection point from A -> B with bound shape (target) from shape (arrow). */ function updateArrowheadPointWithBoundShape( - point: Vec2d, - opposite: Vec2d, - arrowPageTransform: Matrix2dModel, + point: Vec, + opposite: Vec, + arrowPageTransform: MatModel, targetShapeInfo?: BoundShapeInfo ) { if (targetShapeInfo === undefined) { @@ -224,12 +223,12 @@ function updateArrowheadPointWithBoundShape( } // From and To in page space - const pageFrom = Matrix2d.applyToPoint(arrowPageTransform, opposite) - const pageTo = Matrix2d.applyToPoint(arrowPageTransform, point) + const pageFrom = Mat.applyToPoint(arrowPageTransform, opposite) + const pageTo = Mat.applyToPoint(arrowPageTransform, point) // From and To in local space of the target shape - const targetFrom = Matrix2d.applyToPoint(Matrix2d.Inverse(targetShapeInfo.transform), pageFrom) - const targetTo = Matrix2d.applyToPoint(Matrix2d.Inverse(targetShapeInfo.transform), pageTo) + const targetFrom = Mat.applyToPoint(Mat.Inverse(targetShapeInfo.transform), pageFrom) + const targetTo = Mat.applyToPoint(Mat.Inverse(targetShapeInfo.transform), pageTo) const isClosed = targetShapeInfo.isClosed const fn = isClosed ? intersectLineSegmentPolygon : intersectLineSegmentPolyline @@ -240,7 +239,7 @@ function updateArrowheadPointWithBoundShape( if (intersection !== null) { targetInt = - intersection.sort((p1, p2) => Vec2d.Dist(p1, targetFrom) - Vec2d.Dist(p2, targetFrom))[0] ?? + intersection.sort((p1, p2) => Vec.Dist(p1, targetFrom) - Vec.Dist(p2, targetFrom))[0] ?? (isClosed ? undefined : targetTo) } @@ -249,34 +248,10 @@ function updateArrowheadPointWithBoundShape( return } - const pageInt = Matrix2d.applyToPoint(targetShapeInfo.transform, targetInt) - const arrowInt = Matrix2d.applyToPoint(Matrix2d.Inverse(arrowPageTransform), pageInt) + const pageInt = Mat.applyToPoint(targetShapeInfo.transform, targetInt) + const arrowInt = Mat.applyToPoint(Mat.Inverse(arrowPageTransform), pageInt) point.setTo(arrowInt) targetShapeInfo.didIntersect = true } - -/** @public */ -export function getStraightArrowHandlePath(info: TLArrowInfo & { isStraight: true }) { - return getArrowPath(info.start.handle, info.end.handle) -} - -/** @public */ -export function getSolidStraightArrowPath(info: TLArrowInfo & { isStraight: true }) { - return getArrowPath(info.start.point, info.end.point) -} - -function getArrowPath(start: VecLike, end: VecLike) { - return `M${start.x},${start.y}L${end.x},${end.y}` -} - -/** @public */ -export function getStraightArrowBoundingBox(start: VecLike, end: VecLike) { - return new Box2d( - Math.min(start.x, end.x), - Math.min(start.y, end.y), - Math.abs(start.x - end.x), - Math.abs(start.y - end.y) - ) -} diff --git a/packages/editor/src/lib/editor/shapes/shared/resizeBox.ts b/packages/editor/src/lib/editor/shapes/shared/resizeBox.ts index 2c03cd4e3..d7b3fc07e 100644 --- a/packages/editor/src/lib/editor/shapes/shared/resizeBox.ts +++ b/packages/editor/src/lib/editor/shapes/shared/resizeBox.ts @@ -1,6 +1,6 @@ -import { Vec2dModel } from '@tldraw/tlschema' -import { Box2d } from '../../../primitives/Box2d' -import { Vec2d } from '../../../primitives/Vec2d' +import { VecModel } from '@tldraw/tlschema' +import { Box } from '../../../primitives/Box' +import { Vec } from '../../../primitives/Vec' import { TLResizeHandle } from '../../types/selection-types' import { TLBaseBoxShape } from '../BaseBoxShapeUtil' import { TLResizeMode } from '../ShapeUtil' @@ -17,12 +17,12 @@ export type ResizeBoxOptions = Partial<{ export function resizeBox( shape: TLBaseBoxShape, info: { - newPoint: Vec2dModel + newPoint: VecModel handle: TLResizeHandle mode: TLResizeMode scaleX: number scaleY: number - initialBounds: Box2d + initialBounds: Box initialShape: TLBaseBoxShape }, opts = {} as ResizeBoxOptions @@ -33,7 +33,7 @@ export function resizeBox( let w = shape.props.w * scaleX let h = shape.props.h * scaleY - const offset = new Vec2d(0, 0) + const offset = new Vec(0, 0) if (w > 0) { if (w < minWidth) { diff --git a/packages/editor/src/lib/editor/shapes/shared/resizeScaled.ts b/packages/editor/src/lib/editor/shapes/shared/resizeScaled.ts deleted file mode 100644 index 48ac4e561..000000000 --- a/packages/editor/src/lib/editor/shapes/shared/resizeScaled.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { TLShape, Vec2dModel } from '@tldraw/tlschema' -import { Box2d } from '../../../primitives/Box2d' -import { Vec2d } from '../../../primitives/Vec2d' - -export function resizeScaled( - shape: Extract, - { - initialBounds, - scaleX, - scaleY, - newPoint, - }: { - newPoint: Vec2dModel - initialBounds: Box2d - scaleX: number - scaleY: number - } -) { - // Compute the new scale (to apply to the scale prop) - const scaleDelta = Math.max(0.01, Math.min(Math.abs(scaleX), Math.abs(scaleY))) - - // Compute the offset (if flipped X or flipped Y) - const offset = new Vec2d(0, 0) - - if (scaleX < 0) { - offset.x = -(initialBounds.width * scaleDelta) - } - if (scaleY < 0) { - offset.y = -(initialBounds.height * scaleDelta) - } - - // Apply the offset to the new point - const { x, y } = Vec2d.Add(newPoint, offset.rot(shape.rotation)) - - return { - x, - y, - props: { - scale: scaleDelta * shape.props.scale, - }, - } -} diff --git a/packages/editor/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts b/packages/editor/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts index a34f14676..f9339d06d 100644 --- a/packages/editor/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +++ b/packages/editor/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts @@ -1,5 +1,5 @@ import { createShapeId } from '@tldraw/tlschema' -import { Vec2d } from '../../../../primitives/Vec2d' +import { Vec } from '../../../../primitives/Vec' import { TLBaseBoxShape } from '../../../shapes/BaseBoxShapeUtil' import { TLEventHandlers } from '../../../types/event-types' import { StateNode } from '../../StateNode' @@ -96,7 +96,7 @@ export class Pointing extends StateNode { const shape = this.editor.getShape(id)! const { w, h } = this.editor.getShapeUtil(shape).getDefaultProps() as TLBaseBoxShape['props'] - const delta = new Vec2d(w / 2, h / 2) + const delta = new Vec(w / 2, h / 2) const parentTransform = this.editor.getShapeParentTransform(shape) if (parentTransform) delta.rot(-parentTransform.rotation()) diff --git a/packages/editor/src/lib/editor/types/event-types.ts b/packages/editor/src/lib/editor/types/event-types.ts index 5ae0b20a1..55ba4c9a6 100644 --- a/packages/editor/src/lib/editor/types/event-types.ts +++ b/packages/editor/src/lib/editor/types/event-types.ts @@ -1,5 +1,5 @@ -import { TLHandle, TLShape, Vec2dModel } from '@tldraw/tlschema' -import { VecLike } from '../../primitives/Vec2d' +import { TLHandle, TLShape, VecModel } from '@tldraw/tlschema' +import { VecLike } from '../../primitives/Vec' import { TLSelectionHandle } from './selection-types' /** @public */ @@ -80,16 +80,16 @@ export type TLKeyboardEventInfo = TLBaseEventInfo & { export type TLPinchEventInfo = TLBaseEventInfo & { type: 'pinch' name: TLPinchEventName - point: Vec2dModel - delta: Vec2dModel + point: VecModel + delta: VecModel } /** @public */ export type TLWheelEventInfo = TLBaseEventInfo & { type: 'wheel' name: 'wheel' - delta: Vec2dModel - point: Vec2dModel + delta: VecModel + point: VecModel } /** @public */ diff --git a/packages/editor/src/lib/editor/types/external-content.ts b/packages/editor/src/lib/editor/types/external-content.ts index 6418158ec..38fcc74fb 100644 --- a/packages/editor/src/lib/editor/types/external-content.ts +++ b/packages/editor/src/lib/editor/types/external-content.ts @@ -1,5 +1,5 @@ import { EmbedDefinition } from '@tldraw/tlschema' -import { VecLike } from '../../primitives/Vec2d' +import { VecLike } from '../../primitives/Vec' import { TLContent } from './clipboard-types' /** @public */ diff --git a/packages/editor/src/lib/editor/types/misc-types.ts b/packages/editor/src/lib/editor/types/misc-types.ts index 402a7bfc6..6851e726d 100644 --- a/packages/editor/src/lib/editor/types/misc-types.ts +++ b/packages/editor/src/lib/editor/types/misc-types.ts @@ -1,4 +1,4 @@ -import { Box2d } from '../../primitives/Box2d' +import { Box } from '../../primitives/Box' /** @public */ export type RequiredKeys = Partial> & Pick @@ -7,7 +7,7 @@ export type OptionalKeys = Omit & Partial /** @public */ export type TLSvgOptions = { - bounds: Box2d + bounds: Box scale: number background: boolean padding: number diff --git a/packages/editor/src/lib/editor/types/selection-types.ts b/packages/editor/src/lib/editor/types/selection-types.ts index 49c2aceb0..b578f5739 100644 --- a/packages/editor/src/lib/editor/types/selection-types.ts +++ b/packages/editor/src/lib/editor/types/selection-types.ts @@ -1,4 +1,4 @@ -import { RotateCorner, SelectionCorner, SelectionEdge } from '../../primitives/Box2d' +import { RotateCorner, SelectionCorner, SelectionEdge } from '../../primitives/Box' /** @public */ export type TLSelectionHandle = SelectionCorner | SelectionEdge | RotateCorner diff --git a/packages/editor/src/lib/hooks/useGestureEvents.ts b/packages/editor/src/lib/hooks/useGestureEvents.ts index 0671ebd29..84d21ff3f 100644 --- a/packages/editor/src/lib/hooks/useGestureEvents.ts +++ b/packages/editor/src/lib/hooks/useGestureEvents.ts @@ -2,7 +2,7 @@ import type { AnyHandlerEventTypes, EventTypes, GestureKey, Handler } from '@use import { createUseGesture, pinchAction, wheelAction } from '@use-gesture/react' import * as React from 'react' import { TLWheelEventInfo } from '../editor/types/event-types' -import { Vec2d } from '../primitives/Vec2d' +import { Vec } from '../primitives/Vec' import { preventDefault } from '../utils/dom' import { normalizeWheel } from '../utils/normalizeWheel' import { useEditor } from './useEditor' @@ -122,7 +122,7 @@ export function useGestureEvents(ref: React.RefObject) { type: 'wheel', name: 'wheel', delta, - point: new Vec2d(event.clientX, event.clientY).sub({ + point: new Vec(event.clientX, event.clientY).sub({ x: container.left, y: container.top, }), @@ -138,8 +138,8 @@ export function useGestureEvents(ref: React.RefObject) { let initZoom = 1 // the browser's zoom level when the pinch starts let currZoom = 1 // the current zoom level according to the pinch gesture recognizer let currDistanceBetweenFingers = 0 - const initPointBetweenFingers = new Vec2d() - const prevPointBetweenFingers = new Vec2d() + const initPointBetweenFingers = new Vec() + const prevPointBetweenFingers = new Vec() const onPinchStart: PinchHandler = (gesture) => { const elm = ref.current @@ -186,7 +186,7 @@ export function useGestureEvents(ref: React.RefObject) { // How far have the two touch points moved towards or away from eachother? const touchDistance = Math.abs(currDistanceBetweenFingers - initDistanceBetweenFingers) // How far has the point between the touches moved? - const originDistance = Vec2d.Dist(initPointBetweenFingers, prevPointBetweenFingers) + const originDistance = Vec.Dist(initPointBetweenFingers, prevPointBetweenFingers) switch (pinchState) { case 'not sure': { diff --git a/packages/editor/src/lib/hooks/useTransform.ts b/packages/editor/src/lib/hooks/useTransform.ts index a82e261c2..0fd3a4490 100644 --- a/packages/editor/src/lib/hooks/useTransform.ts +++ b/packages/editor/src/lib/hooks/useTransform.ts @@ -1,5 +1,5 @@ import { useLayoutEffect } from 'react' -import { VecLike } from '../primitives/Vec2d' +import { VecLike } from '../primitives/Vec' /** @public */ export function useTransform( diff --git a/packages/editor/src/lib/primitives/Box.test.ts b/packages/editor/src/lib/primitives/Box.test.ts new file mode 100644 index 000000000..4923f00c6 --- /dev/null +++ b/packages/editor/src/lib/primitives/Box.test.ts @@ -0,0 +1,24 @@ +import { Box } from './Box' +import { Vec } from './Vec' + +describe('Box', () => { + it('Creates a box', () => { + const mat3 = new Box(0, 0, 100, 100) + expect(mat3).toMatchObject({ + x: 0, + y: 0, + w: 100, + h: 100, + }) + }) + + it('can have the point set with a Vec', () => { + const box = new Box(0, 0, 100, 100) + + expect(box).toMatchObject({ x: 0, y: 0 }) + + box.point = new Vec(19, 23) + + expect(box).toMatchObject({ x: 19, y: 23 }) + }) +}) diff --git a/packages/editor/src/lib/primitives/Box2d.ts b/packages/editor/src/lib/primitives/Box.ts similarity index 82% rename from packages/editor/src/lib/primitives/Box2d.ts rename to packages/editor/src/lib/primitives/Box.ts index 072f65442..a0be4385d 100644 --- a/packages/editor/src/lib/primitives/Box2d.ts +++ b/packages/editor/src/lib/primitives/Box.ts @@ -1,9 +1,9 @@ -import { Box2dModel } from '@tldraw/tlschema' -import { Vec2d, VecLike } from './Vec2d' +import { BoxModel } from '@tldraw/tlschema' +import { Vec, VecLike } from './Vec' import { PI, PI2, toPrecision } from './utils' /** @public */ -export type BoxLike = Box2dModel | Box2d +export type BoxLike = BoxModel | Box /** @public */ export type SelectionEdge = 'top' | 'right' | 'bottom' | 'left' @@ -23,7 +23,7 @@ export type RotateCorner = | 'mobile_rotate' /** @public */ -export class Box2d { +export class Box { constructor(x = 0, y = 0, w = 0, h = 0) { this.x = x this.y = y @@ -38,11 +38,11 @@ export class Box2d { // eslint-disable-next-line no-restricted-syntax get point() { - return new Vec2d(this.x, this.y) + return new Vec(this.x, this.y) } // eslint-disable-next-line no-restricted-syntax - set point(val: Vec2d) { + set point(val: Vec) { this.x = val.x this.y = val.y } @@ -114,11 +114,11 @@ export class Box2d { // eslint-disable-next-line no-restricted-syntax get center() { - return new Vec2d(this.midX, this.midY) + return new Vec(this.midX, this.midY) } // eslint-disable-next-line no-restricted-syntax - set center(v: Vec2d) { + set center(v: Vec) { this.minX = v.x - this.width / 2 this.minY = v.y - this.height / 2 } @@ -126,26 +126,26 @@ export class Box2d { // eslint-disable-next-line no-restricted-syntax get corners() { return [ - new Vec2d(this.minX, this.minY), - new Vec2d(this.maxX, this.minY), - new Vec2d(this.maxX, this.maxY), - new Vec2d(this.minX, this.maxY), + new Vec(this.minX, this.minY), + new Vec(this.maxX, this.minY), + new Vec(this.maxX, this.maxY), + new Vec(this.minX, this.maxY), ] } // eslint-disable-next-line no-restricted-syntax get snapPoints() { return [ - new Vec2d(this.minX, this.minY), - new Vec2d(this.maxX, this.minY), - new Vec2d(this.maxX, this.maxY), - new Vec2d(this.minX, this.maxY), + new Vec(this.minX, this.minY), + new Vec(this.maxX, this.minY), + new Vec(this.maxX, this.maxY), + new Vec(this.minX, this.maxY), this.center, ] } // eslint-disable-next-line no-restricted-syntax - get sides(): Array<[Vec2d, Vec2d]> { + get sides(): Array<[Vec, Vec]> { const { corners } = this return [ [corners[0], corners[1]], @@ -156,8 +156,8 @@ export class Box2d { } // eslint-disable-next-line no-restricted-syntax - get size(): Vec2d { - return new Vec2d(this.w, this.h) + get size(): Vec { + return new Vec(this.w, this.h) } toFixed() { @@ -168,7 +168,7 @@ export class Box2d { return this } - setTo(B: Box2d) { + setTo(B: Box) { this.x = B.x this.y = B.y this.w = B.w @@ -184,7 +184,7 @@ export class Box2d { return this } - expand(A: Box2d) { + expand(A: Box) { const minX = Math.min(this.minX, A.minX) const minY = Math.min(this.minY, A.minY) const maxX = Math.max(this.maxX, A.maxX) @@ -215,7 +215,7 @@ export class Box2d { clone() { const { x, y, w, h } = this - return new Box2d(x, y, w, h) + return new Box(x, y, w, h) } translate(delta: VecLike) { @@ -235,44 +235,44 @@ export class Box2d { this.height = Math.max(1, maxY - minY) } - collides(B: Box2d) { - return Box2d.Collides(this, B) + collides(B: Box) { + return Box.Collides(this, B) } - contains(B: Box2d) { - return Box2d.Contains(this, B) + contains(B: Box) { + return Box.Contains(this, B) } - includes(B: Box2d) { - return Box2d.Includes(this, B) + includes(B: Box) { + return Box.Includes(this, B) } containsPoint(V: VecLike, margin = 0) { - return Box2d.ContainsPoint(this, V, margin) + return Box.ContainsPoint(this, V, margin) } getHandlePoint(handle: SelectionCorner | SelectionEdge) { switch (handle) { case 'top_left': - return new Vec2d(this.minX, this.minY) + return new Vec(this.minX, this.minY) case 'top_right': - return new Vec2d(this.maxX, this.minY) + return new Vec(this.maxX, this.minY) case 'bottom_left': - return new Vec2d(this.minX, this.maxY) + return new Vec(this.minX, this.maxY) case 'bottom_right': - return new Vec2d(this.maxX, this.maxY) + return new Vec(this.maxX, this.maxY) case 'top': - return new Vec2d(this.midX, this.minY) + return new Vec(this.midX, this.minY) case 'right': - return new Vec2d(this.maxX, this.midY) + return new Vec(this.maxX, this.midY) case 'bottom': - return new Vec2d(this.midX, this.maxY) + return new Vec(this.midX, this.maxY) case 'left': - return new Vec2d(this.minX, this.midY) + return new Vec(this.minX, this.midY) } } - toJson(): Box2dModel { + toJson(): BoxModel { return { x: this.minX, y: this.minY, w: this.w, h: this.h } } @@ -336,7 +336,7 @@ export class Box2d { this.height = Math.abs(b1y - b0y) } - union(box: Box2dModel) { + union(box: BoxModel) { const minX = Math.min(this.minX, box.x) const minY = Math.min(this.minY, box.y) const maxX = Math.max(this.maxX, box.w + box.x) @@ -350,12 +350,12 @@ export class Box2d { return this } - static From(box: Box2dModel) { - return new Box2d(box.x, box.y, box.w, box.h) + static From(box: BoxModel) { + return new Box(box.x, box.y, box.w, box.h) } static FromPoints(points: VecLike[]) { - if (points.length === 0) return new Box2d() + if (points.length === 0) return new Box() let minX = Infinity let minY = Infinity let maxX = -Infinity @@ -369,35 +369,35 @@ export class Box2d { maxY = Math.max(point.y, maxY) } - return new Box2d(minX, minY, maxX - minX, maxY - minY) + return new Box(minX, minY, maxX - minX, maxY - minY) } - static Expand(A: Box2d, B: Box2d) { + static Expand(A: Box, B: Box) { const minX = Math.min(B.minX, A.minX) const minY = Math.min(B.minY, A.minY) const maxX = Math.max(B.maxX, A.maxX) const maxY = Math.max(B.maxY, A.maxY) - return new Box2d(minX, minY, maxX - minX, maxY - minY) + return new Box(minX, minY, maxX - minX, maxY - minY) } - static ExpandBy(A: Box2d, n: number) { - return new Box2d(A.minX - n, A.minY - n, A.width + n * 2, A.height + n * 2) + static ExpandBy(A: Box, n: number) { + return new Box(A.minX - n, A.minY - n, A.width + n * 2, A.height + n * 2) } - static Collides = (A: Box2d, B: Box2d) => { + static Collides = (A: Box, B: Box) => { return !(A.maxX < B.minX || A.minX > B.maxX || A.maxY < B.minY || A.minY > B.maxY) } - static Contains = (A: Box2d, B: Box2d) => { + static Contains = (A: Box, B: Box) => { return A.minX < B.minX && A.minY < B.minY && A.maxY > B.maxY && A.maxX > B.maxX } - static Includes = (A: Box2d, B: Box2d) => { - return Box2d.Collides(A, B) || Box2d.Contains(A, B) + static Includes = (A: Box, B: Box) => { + return Box.Collides(A, B) || Box.Contains(A, B) } - static ContainsPoint = (A: Box2d, B: VecLike, margin = 0) => { + static ContainsPoint = (A: Box, B: VecLike, margin = 0) => { return !( B.x < A.minX - margin || B.y < A.minY - margin || @@ -406,7 +406,7 @@ export class Box2d { ) } - static Common = (boxes: Box2d[]): Box2d => { + static Common = (boxes: Box[]): Box => { let minX = Infinity let minY = Infinity let maxX = -Infinity @@ -420,10 +420,10 @@ export class Box2d { maxY = Math.max(maxY, B.maxY) } - return new Box2d(minX, minY, maxX - minX, maxY - minY) + return new Box(minX, minY, maxX - minX, maxY - minY) } - static Sides = (A: Box2d, inset = 0) => { + static Sides = (A: Box, inset = 0) => { const { corners } = A if (inset) { // TODO: Inset the corners by the inset amount. @@ -438,7 +438,7 @@ export class Box2d { } static Resize( - box: Box2d, + box: Box, handle: SelectionCorner | SelectionEdge | string, dx: number, dy: number, @@ -550,7 +550,7 @@ export class Box2d { b0y = t } - const final = new Box2d(b0x, b0y, Math.abs(b1x - b0x), Math.abs(b1y - b0y)) + const final = new Box(b0x, b0y, Math.abs(b1x - b0x), Math.abs(b1y - b0y)) return { box: final, @@ -559,11 +559,11 @@ export class Box2d { } } - equals(other: Box2d | Box2dModel) { - return Box2d.Equals(this, other) + equals(other: Box | BoxModel) { + return Box.Equals(this, other) } - static Equals(a: Box2d | Box2dModel, b: Box2d | Box2dModel) { + static Equals(a: Box | BoxModel, b: Box | BoxModel) { return b.x === a.x && b.y === a.y && b.w === a.w && b.h === a.h } @@ -573,8 +573,8 @@ export class Box2d { return this } - static ZeroFix(other: Box2d | Box2dModel) { - return new Box2d(other.x, other.y, Math.max(1, other.w), Math.max(1, other.h)) + static ZeroFix(other: Box | BoxModel) { + return new Box(other.x, other.y, Math.max(1, other.w), Math.max(1, other.h)) } } diff --git a/packages/editor/src/lib/primitives/Box2d.test.ts b/packages/editor/src/lib/primitives/Box2d.test.ts deleted file mode 100644 index b79f7d05e..000000000 --- a/packages/editor/src/lib/primitives/Box2d.test.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Box2d } from './Box2d' -import { Vec2d } from './Vec2d' - -describe('Box2d', () => { - it('Creates a box', () => { - const mat3 = new Box2d(0, 0, 100, 100) - expect(mat3).toMatchObject({ - x: 0, - y: 0, - w: 100, - h: 100, - }) - }) - - it('can have the point set with a vec2d', () => { - const box = new Box2d(0, 0, 100, 100) - - expect(box).toMatchObject({ x: 0, y: 0 }) - - box.point = new Vec2d(19, 23) - - expect(box).toMatchObject({ x: 19, y: 23 }) - }) -}) diff --git a/packages/editor/src/lib/primitives/Mat.test.ts b/packages/editor/src/lib/primitives/Mat.test.ts new file mode 100644 index 000000000..d1fcbdfd9 --- /dev/null +++ b/packages/editor/src/lib/primitives/Mat.test.ts @@ -0,0 +1,46 @@ +import { Mat } from './Mat' + +describe('Mat', () => { + it('Creates a matrix', () => { + const mat3 = new Mat(1.0, 0.0, 0.0, 1.0, 0.0, 0.0) + expect(mat3).toMatchObject(Mat.Identity()) + }) + + it('Multiplies a matrix', () => { + const m1 = new Mat(1, 2, 3, 4, 5, 6) + const m2 = new Mat(1, 2, 3, 4, 5, 6) + expect(m1.multiply(m2)).toMatchObject({ + a: 7, + b: 10, + c: 15, + d: 22, + e: 28, + f: 40, + }) + }) + + it('Composes matrices', () => { + const m1 = new Mat(1, 2, 3, 4, 5, 6) + const m2 = new Mat(1, 2, 3, 4, 5, 6) + expect(Mat.Compose(m1, m2)).toMatchObject({ + a: 7, + b: 10, + c: 15, + d: 22, + e: 28, + f: 40, + }) + }) + + it('Inverts a matrix', () => { + const m1 = new Mat(1, 2, 3, 4, 5, 6) + expect(m1.invert()).toMatchObject({ + a: -2, + b: 1, + c: 1.5, + d: -0.5, + e: 1, + f: -2, + }) + }) +}) diff --git a/packages/editor/src/lib/primitives/Matrix2d.ts b/packages/editor/src/lib/primitives/Mat.ts similarity index 62% rename from packages/editor/src/lib/primitives/Matrix2d.ts rename to packages/editor/src/lib/primitives/Mat.ts index 136a4862b..c895ded76 100644 --- a/packages/editor/src/lib/primitives/Matrix2d.ts +++ b/packages/editor/src/lib/primitives/Mat.ts @@ -1,21 +1,12 @@ -import { Box2d } from './Box2d' -import { clampRadians, TAU, toDomPrecision } from './utils' -import { Vec2d, VecLike } from './Vec2d' +import { Box } from './Box' +import { clampRadians, HALF_PI, toDomPrecision } from './utils' +import { Vec, VecLike } from './Vec' /** @public */ -export type MatLike = Matrix2dModel | Matrix2d +export type MatLike = MatModel | Mat /** @public */ -export interface MatrixInfo { - x: number - y: number - scaleX: number - scaleY: number - rotation: number -} - -/** @public */ -export interface Matrix2dModel { +export interface MatModel { a: number b: number c: number @@ -25,11 +16,11 @@ export interface Matrix2dModel { } // function getIdentity() { -// return new Matrix2d(1.0, 0.0, 0.0, 1.0, 0.0, 0.0) +// return new Mat(1.0, 0.0, 0.0, 1.0, 0.0, 0.0) // } /** @public */ -export class Matrix2d { +export class Mat { constructor(a: number, b: number, c: number, d: number, e: number, f: number) { this.a = a this.b = b @@ -46,7 +37,7 @@ export class Matrix2d { e = 0.0 f = 0.0 - equals(m: Matrix2d | Matrix2dModel) { + equals(m: Mat | MatModel) { return ( this.a === m.a && this.b === m.b && @@ -67,8 +58,8 @@ export class Matrix2d { return this } - multiply(m: Matrix2d | Matrix2dModel) { - const m2: Matrix2dModel = m + multiply(m: Mat | MatModel) { + const m2: MatModel = m const { a, b, c, d, e, f } = this this.a = a * m2.a + c * m2.b this.c = a * m2.c + c * m2.d @@ -81,16 +72,16 @@ export class Matrix2d { rotate(r: number, cx?: number, cy?: number) { if (r === 0) return this - if (cx === undefined) return this.multiply(Matrix2d.Rotate(r)) - return this.translate(cx, cy!).multiply(Matrix2d.Rotate(r)).translate(-cx, -cy!) + if (cx === undefined) return this.multiply(Mat.Rotate(r)) + return this.translate(cx, cy!).multiply(Mat.Rotate(r)).translate(-cx, -cy!) } - translate(x: number, y: number): Matrix2d { - return this.multiply(Matrix2d.Translate(x, y!)) + translate(x: number, y: number): Mat { + return this.multiply(Mat.Translate(x, y!)) } scale(x: number, y: number) { - return this.multiply(Matrix2d.Scale(x, y)) + return this.multiply(Mat.Scale(x, y)) } invert() { @@ -106,85 +97,77 @@ export class Matrix2d { } applyToPoint(point: VecLike) { - return Matrix2d.applyToPoint(this, point) + return Mat.applyToPoint(this, point) } applyToPoints(points: VecLike[]) { - return Matrix2d.applyToPoints(this, points) + return Mat.applyToPoints(this, points) } rotation() { - return Matrix2d.Rotation(this) + return Mat.Rotation(this) } point() { - return Matrix2d.Point(this) + return Mat.Point(this) } decomposed() { - return Matrix2d.Decompose(this) + return Mat.Decompose(this) } toCssString() { - return Matrix2d.toCssString(this) + return Mat.toCssString(this) } - setTo(model: Matrix2dModel) { + setTo(model: MatModel) { Object.assign(this, model) return this } decompose() { - return Matrix2d.Decompose(this) + return Mat.Decompose(this) } clone() { - return new Matrix2d(this.a, this.b, this.c, this.d, this.e, this.f) + return new Mat(this.a, this.b, this.c, this.d, this.e, this.f) } /* --------------------- Static --------------------- */ static Identity() { - return new Matrix2d(1.0, 0.0, 0.0, 1.0, 0.0, 0.0) + return new Mat(1.0, 0.0, 0.0, 1.0, 0.0, 0.0) } static Translate(x: number, y: number) { - return new Matrix2d(1.0, 0.0, 0.0, 1.0, x, y) + return new Mat(1.0, 0.0, 0.0, 1.0, x, y) } static Rotate(r: number, cx?: number, cy?: number) { - if (r === 0) return Matrix2d.Identity() + if (r === 0) return Mat.Identity() const cosAngle = Math.cos(r) const sinAngle = Math.sin(r) - const rotationMatrix2d = new Matrix2d(cosAngle, sinAngle, -sinAngle, cosAngle, 0.0, 0.0) + const rotationMatrix = new Mat(cosAngle, sinAngle, -sinAngle, cosAngle, 0.0, 0.0) - if (cx === undefined) return rotationMatrix2d + if (cx === undefined) return rotationMatrix - return Matrix2d.Compose( - Matrix2d.Translate(cx, cy!), - rotationMatrix2d, - Matrix2d.Translate(-cx, -cy!) - ) + return Mat.Compose(Mat.Translate(cx, cy!), rotationMatrix, Mat.Translate(-cx, -cy!)) } static Scale: { - (x: number, y: number): Matrix2dModel - (x: number, y: number, cx: number, cy: number): Matrix2dModel + (x: number, y: number): MatModel + (x: number, y: number, cx: number, cy: number): MatModel } = (x: number, y: number, cx?: number, cy?: number) => { - const scaleMatrix2d = new Matrix2d(x, 0, 0, y, 0, 0) + const scaleMatrix = new Mat(x, 0, 0, y, 0, 0) - if (cx === undefined) return scaleMatrix2d + if (cx === undefined) return scaleMatrix - return Matrix2d.Compose( - Matrix2d.Translate(cx, cy!), - scaleMatrix2d, - Matrix2d.Translate(-cx, -cy!) - ) + return Mat.Compose(Mat.Translate(cx, cy!), scaleMatrix, Mat.Translate(-cx, -cy!)) } - static Multiply(m1: Matrix2dModel, m2: Matrix2dModel): Matrix2dModel { + static Multiply(m1: MatModel, m2: MatModel): MatModel { return { a: m1.a * m2.a + m1.c * m2.b, c: m1.a * m2.c + m1.c * m2.d, @@ -195,7 +178,7 @@ export class Matrix2d { } } - static Inverse(m: Matrix2dModel): Matrix2dModel { + static Inverse(m: MatModel): MatModel { const denom = m.a * m.d - m.b * m.c return { a: m.d / denom, @@ -207,7 +190,7 @@ export class Matrix2d { } } - static Absolute(m: MatLike): Matrix2dModel { + static Absolute(m: MatLike): MatModel { const denom = m.a * m.d - m.b * m.c return { a: m.d / denom, @@ -220,7 +203,7 @@ export class Matrix2d { } static Compose(...matrices: MatLike[]) { - const matrix = Matrix2d.Identity() + const matrix = Mat.Identity() for (let i = 0, n = matrices.length; i < n; i++) { matrix.multiply(matrices[i]) } @@ -228,7 +211,7 @@ export class Matrix2d { } static Point(m: MatLike) { - return new Vec2d(m.e, m.f) + return new Vec(m.e, m.f) } static Rotation(m: MatLike): number { @@ -239,7 +222,7 @@ export class Matrix2d { rotation = Math.acos(m.a / hypotAc) * (m.c > 0 ? -1 : 1) } else if (m.b !== 0 || m.d !== 0) { const hypotBd = Math.hypot(m.b, m.d) - rotation = TAU + Math.acos(m.b / hypotBd) * (m.d > 0 ? -1 : 1) + rotation = HALF_PI + Math.acos(m.b / hypotBd) * (m.d > 0 ? -1 : 1) } else { rotation = 0 } @@ -247,7 +230,7 @@ export class Matrix2d { return clampRadians(rotation) } - static Decompose(m: MatLike): MatrixInfo { + static Decompose(m: MatLike) { let scaleX, scaleY, rotation if (m.a !== 0 || m.c !== 0) { @@ -259,7 +242,7 @@ export class Matrix2d { const hypotBd = Math.hypot(m.b, m.d) scaleX = (m.a * m.d - m.b * m.c) / hypotBd scaleY = hypotBd - rotation = TAU + Math.acos(m.b / hypotBd) * (m.d > 0 ? -1 : 1) + rotation = HALF_PI + Math.acos(m.b / hypotBd) * (m.d > 0 ? -1 : 1) } else { scaleX = 0 scaleY = 0 @@ -292,7 +275,7 @@ export class Matrix2d { } static applyToPoint(m: MatLike, point: VecLike) { - return new Vec2d( + return new Vec( m.a * point.x + m.c * point.y + m.e, m.b * point.x + m.d * point.y + m.f, point.z @@ -303,28 +286,28 @@ export class Matrix2d { return [m.a * x + m.c * y + m.e, m.b * x + m.d * y + m.f] } - static applyToPoints(m: MatLike, points: VecLike[]): Vec2d[] { + static applyToPoints(m: MatLike, points: VecLike[]): Vec[] { return points.map( (point) => - new Vec2d(m.a * point.x + m.c * point.y + m.e, m.b * point.x + m.d * point.y + m.f, point.z) + new Vec(m.a * point.x + m.c * point.y + m.e, m.b * point.x + m.d * point.y + m.f, point.z) ) } - static applyToBounds(m: MatLike, box: Box2d) { - return new Box2d(m.e + box.minX, m.f + box.minY, box.width, box.height) + static applyToBounds(m: MatLike, box: Box) { + return new Box(m.e + box.minX, m.f + box.minY, box.width, box.height) } static From(m: MatLike) { - return new Matrix2d(m.a, m.b, m.c, m.d, m.e, m.f) + return new Mat(m.a, m.b, m.c, m.d, m.e, m.f) } static Cast(m: MatLike) { - return m instanceof Matrix2d ? m : Matrix2d.From(m) + return m instanceof Mat ? m : Mat.From(m) } } /** @public */ -export function decomposeMatrix2d(m: MatLike) { +export function decomposeMatrix(m: MatLike) { return { x: m.e, y: m.f, diff --git a/packages/editor/src/lib/primitives/Matrix2d.test.ts b/packages/editor/src/lib/primitives/Matrix2d.test.ts deleted file mode 100644 index 0346328f5..000000000 --- a/packages/editor/src/lib/primitives/Matrix2d.test.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Matrix2d } from './Matrix2d' - -describe('Matrix2d', () => { - it('Creates a matrix', () => { - const mat3 = new Matrix2d(1.0, 0.0, 0.0, 1.0, 0.0, 0.0) - expect(mat3).toMatchObject(Matrix2d.Identity()) - }) - - it('Multiplies a matrix', () => { - const m1 = new Matrix2d(1, 2, 3, 4, 5, 6) - const m2 = new Matrix2d(1, 2, 3, 4, 5, 6) - expect(m1.multiply(m2)).toMatchObject({ - a: 7, - b: 10, - c: 15, - d: 22, - e: 28, - f: 40, - }) - }) - - it('Composes matrices', () => { - const m1 = new Matrix2d(1, 2, 3, 4, 5, 6) - const m2 = new Matrix2d(1, 2, 3, 4, 5, 6) - expect(Matrix2d.Compose(m1, m2)).toMatchObject({ - a: 7, - b: 10, - c: 15, - d: 22, - e: 28, - f: 40, - }) - }) - - it('Inverts a matrix', () => { - const m1 = new Matrix2d(1, 2, 3, 4, 5, 6) - expect(m1.invert()).toMatchObject({ - a: -2, - b: 1, - c: 1.5, - d: -0.5, - e: 1, - f: -2, - }) - }) -}) diff --git a/packages/editor/src/lib/primitives/Vec.test.ts b/packages/editor/src/lib/primitives/Vec.test.ts new file mode 100644 index 000000000..884271284 --- /dev/null +++ b/packages/editor/src/lib/primitives/Vec.test.ts @@ -0,0 +1,373 @@ +import { Vec } from './Vec' + +describe('iteratable', () => { + it('Constructs', () => { + const v = new Vec(1, 2) + const { x, y } = v + expect(x).toBeCloseTo(1) + expect(y).toBeCloseTo(2) + }) +}) + +describe('Vec.Clamp', () => { + it('Clamps a vector between a range.', () => { + expect(Vec.Clamp(new Vec(9, 5), 7, 10)).toMatchObject(new Vec(9, 7)) + expect(Vec.Clamp(new Vec(-9, 5), 0, 10)).toMatchObject(new Vec(0, 5)) + }) +}) + +describe('Vec.Clamp', () => { + it('Clamps a vector between a range.', () => { + expect(Vec.Clamp(new Vec(9, 5), 7, 10)).toMatchObject(new Vec(9, 7)) + expect(Vec.Clamp(new Vec(-9, 5), 0, 10)).toMatchObject(new Vec(0, 5)) + }) + it('Clamps a vector between a range.', () => { + expect(Vec.Clamp(new Vec(9, 5), 10)).toMatchObject(new Vec(10, 10)) + expect(Vec.Clamp(new Vec(-9, 5), 10)).toMatchObject(new Vec(10, 10)) + }) +}) + +describe('Vec.Neg', () => { + it('Negates a vector.', () => { + expect(Vec.Neg(new Vec(9, 5))).toMatchObject(new Vec(-9, -5)) + expect(Vec.Neg(new Vec(-9, 0))).toMatchObject(new Vec(9, -0)) + }) +}) + +describe('Vec.Add', () => { + it('Adds two vectors.', () => { + expect(Vec.Add(new Vec(9, 5), new Vec(2, 1))).toMatchObject(new Vec(11, 6)) + expect(Vec.Add(new Vec(-9, 5), new Vec(2, -1))).toMatchObject(new Vec(-7, 4)) + }) +}) + +describe('Vec.AddScalar', () => { + it('Adds a scalar to a vector.', () => { + expect(Vec.AddScalar(new Vec(9, 5), 2)).toMatchObject(new Vec(11, 7)) + expect(Vec.AddScalar(new Vec(-9, 5), 2)).toMatchObject(new Vec(-7, 7)) + }) +}) + +describe('Vec.Sub', () => { + it('Subtracts two vectors.', () => { + expect(Vec.Sub(new Vec(9, 5), new Vec(2, 1))).toMatchObject(new Vec(7, 4)) + expect(Vec.Sub(new Vec(-9, 5), new Vec(2, -1))).toMatchObject(new Vec(-11, 6)) + }) +}) + +describe('Vec.SubScalar', () => { + it('Subtracts a scalar from a vector.', () => { + expect(Vec.SubScalar(new Vec(9, 5), 2)).toMatchObject(new Vec(7, 3)) + expect(Vec.SubScalar(new Vec(-9, 5), 2)).toMatchObject(new Vec(-11, 3)) + }) +}) + +describe('Vec.Mul', () => { + it('Get a vector multiplied by a scalar.', () => { + expect(Vec.Mul(new Vec(9, 9), 3)).toMatchObject(new Vec(27, 27)) + expect(Vec.Mul(new Vec(10, 10), 2)).toMatchObject(new Vec(20, 20)) + }) +}) + +describe('Vec.DivV', () => { + it('Get a vector multiplied by a vector.', () => { + expect(Vec.MulV(new Vec(16, 12), new Vec(2, 4))).toMatchObject(new Vec(32, 48)) + expect(Vec.MulV(new Vec(5, 15), new Vec(5, 3))).toMatchObject(new Vec(25, 45)) + }) +}) + +describe('Vec.Div', () => { + it('Get a vector divided by a scalar.', () => { + expect(Vec.Div(new Vec(9, 9), 3)).toMatchObject(new Vec(3, 3)) + expect(Vec.Div(new Vec(10, 10), 2)).toMatchObject(new Vec(5, 5)) + }) +}) + +describe('Vec.DivV', () => { + it('Get a vector divided by a vector.', () => { + expect(Vec.DivV(new Vec(16, 12), new Vec(2, 4))).toMatchObject(new Vec(8, 3)) + expect(Vec.DivV(new Vec(5, 15), new Vec(5, 3))).toMatchObject(new Vec(1, 5)) + }) +}) + +describe('Vec.Per', () => { + it('Gets the perpendicular rotation of a vector.', () => { + expect(Vec.Per(new Vec(1, -1))).toMatchObject(new Vec(-1, -1)) + expect(Vec.Per(new Vec(-1, 1))).toMatchObject(new Vec(1, 1)) + }) +}) + +describe('Vec.Dpr', () => { + it('Gets the dot product of two vectors.', () => { + expect(Vec.Dpr(new Vec(1, 0), new Vec(1, 0))).toEqual(1) + expect(Vec.Dpr(new Vec(1, 0), new Vec(0, 0))).toEqual(0) + expect(Vec.Dpr(new Vec(1, 0), new Vec(-1, 0))).toEqual(-1) + }) +}) + +describe('Vec.Cpr', () => { + it('Gets the cross product (outer product) of two vectors.', () => { + expect(Vec.Cpr(new Vec(0, 1), new Vec(1, 1))).toEqual(-1) + expect(Vec.Cpr(new Vec(1, 1), new Vec(1, 1))).toEqual(0) + expect(Vec.Cpr(new Vec(1, 1), new Vec(0, 1))).toEqual(1) + }) +}) + +describe('Vec.Len2', () => { + it('Gets the length of a vector squared.', () => { + expect(Vec.Len2(new Vec(0, 0))).toEqual(0) + expect(Vec.Len2(new Vec(0, 1))).toEqual(1) + expect(Vec.Len2(new Vec(1, 1))).toEqual(2) + }) +}) + +describe('Vec.Len', () => { + it('Gets the length of a vector.', () => { + expect(Vec.Len(new Vec(0, 0))).toEqual(0) + expect(Vec.Len(new Vec(0, 1))).toEqual(1) + expect(Vec.Len(new Vec(1, 1))).toEqual(1.4142135623730951) + }) +}) + +describe('Vec.Pry', () => { + it('Projects a vector A over vector B.', () => { + expect(Vec.Pry(new Vec(0, 0), new Vec(0, 10))).toEqual(0) + expect(Vec.Pry(new Vec(0, 0), new Vec(10, 10))).toEqual(0) + expect(Vec.Pry(new Vec(10, 10), new Vec(0, 10))).toEqual(10) + expect(Vec.Pry(new Vec(10, 10), new Vec(10, 10))).toEqual(14.14213562373095) + }) +}) + +describe('Vec.Uni', () => { + it('Gets the normalized vector.', () => { + expect(Vec.Uni(new Vec(0, 10))).toMatchObject(new Vec(0, 1)) + expect(Vec.Uni(new Vec(10, 10))).toMatchObject(new Vec(0.7071067811865475, 0.7071067811865475)) + }) +}) + +describe('Vec.Tan', () => { + it('Gets the tangent between two vectors.', () => { + expect(Vec.Tan(new Vec(0, 0), new Vec(0, 10))).toMatchObject(new Vec(0, -1)) + expect(Vec.Tan(new Vec(0, 0), new Vec(10, 10))).toMatchObject( + new Vec(-0.7071067811865475, -0.7071067811865475) + ) + }) +}) + +describe('Vec.Dist2', () => { + it('Finds the squared distance between two points.', () => { + expect(Vec.Dist2(new Vec(0, 0), new Vec(0, 10))).toEqual(100) + expect(Vec.Dist2(new Vec(0, 0), new Vec(10, 10))).toEqual(200) + }) +}) + +describe('Vec.Dist', () => { + it('Finds the distance between two points.', () => { + expect(Vec.Dist(new Vec(0, 0), new Vec(0, 10))).toEqual(10) + expect(Vec.Dist(new Vec(0, 0), new Vec(10, 10))).toEqual(14.142135623730951) + }) +}) + +// describe('Vec.Ang2', () => { +// it('Finds the angle in radians between two vectors.', () => { +// expect(Vec.Ang2(new Vec(1, 0), new Vec(0, 1))).toEqual(Math.PI / 2) +// }) +// }) + +// describe('Vec.Ang3', () => { +// it('Gets the angle of ∠ABC', () => { +// expect(Vec.Ang3([5, 0], new Vec(0, 0), new Vec(0, 5))).toEqual(Math.PI / 2) +// expect(Vec.Ang3(new Vec(1, 0), new Vec(0, 0), new Vec(0, 1))).toEqual(Math.PI / 2) +// }) +// }) + +describe('Vec.Angle', () => { + it('Finds the angle in radians between two points.', () => { + expect(Vec.Angle(new Vec(0, 0), new Vec(10, 10))).toEqual(Math.PI / 4) + expect(Vec.Angle(new Vec(0, 0), new Vec(10, 0))).toEqual(0) + expect(Vec.Angle(new Vec(0, 0), new Vec(0, 10))).toEqual(Math.PI / 2) + }) +}) + +describe('Vec.Med', () => { + it('Finds the midpoint between two vectors.', () => { + expect(Vec.Med(new Vec(0, 0), new Vec(10, 10))).toMatchObject(new Vec(5, 5)) + expect(Vec.Med(new Vec(0, 0), new Vec(10, 0))).toMatchObject(new Vec(5, 0)) + expect(Vec.Med(new Vec(0, 0), new Vec(0, 10))).toMatchObject(new Vec(0, 5)) + expect(Vec.Med(new Vec(-100, 0), new Vec(0, 100))).toMatchObject(new Vec(-50, 50)) + }) +}) + +describe('Vec.Rot', () => { + it('Rotates a vector by a rotation in radians.', () => { + const { x, y } = Vec.Rot(new Vec(1, 0), Math.PI / 4) + expect(x).toBeCloseTo(0.7, 1) + expect(y).toBeCloseTo(0.7, 1) + }) +}) + +describe('Vec.RotWith', () => { + it('Rotates a vector around a second vector by a rotation in radians.', () => { + expect(Vec.RotWith(new Vec(1, 0), new Vec(0, 0), Math.PI / 4)).toMatchObject( + new Vec(0.7071067811865476, 0.7071067811865475) + ) + }) +}) + +describe('Vec.Equals', () => { + it('Gets whether two vectors are identical.', () => { + expect(Vec.Equals(new Vec(1, 2), new Vec(1, 2))).toEqual(true) + expect(Vec.Equals(new Vec(1, 2), new Vec(1, 3))).toEqual(false) + expect(Vec.Equals(new Vec(-0, 2), new Vec(0, 2))).toEqual(true) + }) +}) + +describe('Vec.Int', () => { + it('Interpolate from A to B', () => { + expect(Vec.Lrp(new Vec(0, 0), new Vec(10, 10), 0.5)).toMatchObject(new Vec(5, 5)) + expect(Vec.Lrp(new Vec(0, 0), new Vec(10, 10), 2)).toMatchObject(new Vec(20, 20)) + }) +}) + +describe('Vec.Rescale', () => { + it('Rescales a vector by a scalar', () => { + expect(Vec.Rescale(new Vec(5, 0), 1)).toMatchObject(new Vec(1, 0)) + expect(Vec.Rescale(new Vec(5, 0), 2)).toMatchObject(new Vec(2, 0)) + expect(Vec.Rescale(new Vec(0.5, 0.25), 2)).toEqual( + new Vec(1.7888543819998317, 0.8944271909999159) + ) + }) +}) + +describe('Vec.IsClockwise', () => { + it('Gets whether point A and point B wind clockwise around point C.', () => { + expect(Vec.Clockwise(new Vec(0, 0), new Vec(5, 5), new Vec(0, 5))).toEqual(true) + expect(Vec.Clockwise(new Vec(5, 5), new Vec(0, 0), new Vec(0, 5))).toEqual(false) + expect(Vec.Clockwise(new Vec(0, 10), new Vec(0, 0), new Vec(0, 5))).toEqual(false) + }) +}) + +describe('Vec.ToFixed', () => { + it('Rounds a vector to the a given precision.', () => { + expect(Vec.ToFixed(new Vec(1.2345, 5.678), 1)).toMatchObject(new Vec(1.2, 5.7)) + expect(Vec.ToFixed(new Vec(1.2345, 5.678), 2)).toMatchObject(new Vec(1.23, 5.68)) + }) +}) + +describe('Vec.Snap', () => { + it('Snaps a vector to the nearest increment provided.', () => { + expect(Vec.Snap(new Vec(10.5, 28), 10)).toMatchObject(new Vec(10, 30)) + }) +}) + +describe('Vec.NearestPointOnLineThroughPoint', () => { + it('Gets the distance from a point to a line that passes through a given point.', () => { + expect( + Vec.NearestPointOnLineThroughPoint(new Vec(0, 0), new Vec(0, 1), new Vec(5, 5)) + ).toMatchObject(new Vec(0, 5)) + }) +}) + +describe('Vec.DistanceToLineThroughPoint', () => { + it('Gets the distance from a point to a line that passes through a given point.', () => { + expect(Vec.DistanceToLineThroughPoint(new Vec(0, 0), new Vec(0, 1), new Vec(5, 5))).toEqual(5) + }) +}) + +describe('Vec.NearestPointOnLineSegment', () => { + it('Gets the distance from a point to a line segment.', () => { + expect( + Vec.NearestPointOnLineSegment(new Vec(0, 0), new Vec(0, 10), new Vec(5, 5)) + ).toMatchObject(new Vec(0, 5)) + }) +}) + +describe('Vec.DistanceToLineSegment', () => { + it('Gets the distance from a point to a line segment.', () => { + expect(Vec.DistanceToLineSegment(new Vec(0, 0), new Vec(0, 10), new Vec(5, 5))).toEqual(5) + }) +}) + +describe('Vec.Nudge', () => { + it('Pushes a point towards another point by a given distance.', () => { + expect(Vec.Nudge(new Vec(0, 0), new Vec(0, 10), 5)).toMatchObject(new Vec(0, 5)) + }) +}) + +// describe('Vec.NudgeAtVector', () => { +// it('Pushes a point in a given direction vector by a given distance.', () => { +// expect(Vec.NudgeAtVector(new Vec(0, 0), new Vec(0.5, 0.75), 10)).toEqual( +// new Vec(5, 7.5) +// ) +// }) +// }) + +// describe('Vec.NudgeAtAngle', () => { +// it('Pushes a point in a given angle by a given distance.', () => { +// expect(Vec.NudgeAtAngle(new Vec(0, 0), Math.PI / 8, 10)).toEqual( +// new Vec(9.238795325112868, 3.826834323650898) +// ) +// }) +// }) + +// describe('Vec.PointsBetween', () => { +// it('Interpolates points between two points.', () => { +// expect(Vec.PointsBetween(new Vec(0, 0), [100, 100], 10)).toMatchObject(new Vec2)( +// new Vec(0, 0, 1), +// new Vec(11.11111111111111, 11.11111111111111, 0.8888888888888888), +// new Vec(22.22222222222222, 22.22222222222222, 0.7777777777777778), +// new Vec(33.33333333333333, 33.33333333333333, 0.6666666666666667), +// new Vec(44.44444444444444, 44.44444444444444, 0.5555555555555556), +// new Vec(55.55555555555556, 55.55555555555556, 0.5555555555555556), +// new Vec(66.66666666666666, 66.66666666666666, 0.6666666666666666), +// new Vec(77.77777777777779, 77.77777777777779, 0.7777777777777778), +// new Vec(88.88888888888889, 88.88888888888889, 0.8888888888888888), +// new Vec(100, 100, 1), +// ]) +// }) +// }) + +describe('Vec.Slope', () => { + it('Gets a slope from a vector.', () => { + expect(Vec.Slope(new Vec(0, 0), new Vec(100, 100))).toEqual(1) + expect(Vec.Slope(new Vec(0, 0), new Vec(50, 100))).toEqual(2) + expect(Vec.Slope(new Vec(0, 0), new Vec(-50, 100))).toEqual(-2) + expect(Vec.Slope(new Vec(123, 456), new Vec(789, 24))).toEqual(-0.6486486486486487) + }) +}) + +describe('Vec.ToAngle', () => { + it('Gets an angle from a vector.', () => { + expect(Vec.ToAngle(new Vec(1, 0.5))).toEqual(0.4636476090008061) + }) +}) + +describe('Vec.Max', () => { + it('Gets the minimum of the given vectors', () => { + expect(Vec.Max(new Vec(4, 1), new Vec(3, 2))).toMatchObject(new Vec(4, 2)) + expect(Vec.Max(new Vec(3, 2), new Vec(4, 1))).toMatchObject(new Vec(4, 2)) + }) +}) + +describe('Vec.Min', () => { + it('Gets the minimum of the given vectors', () => { + expect(Vec.Min(new Vec(4, 1), new Vec(3, 2))).toMatchObject(new Vec(3, 1)) + expect(Vec.Min(new Vec(3, 2), new Vec(4, 1))).toMatchObject(new Vec(3, 1)) + }) +}) + +describe('Vec.snapToGrid', () => { + it('snaps to the nearest given increment, mutating the original vector and returning it', () => { + expect(new Vec(25, 29).snapToGrid(8)).toMatchObject(new Vec(24, 32)) + expect(new Vec(25, 29).snapToGrid(8)).toMatchObject(new Vec(24, 32)) + expect(new Vec(25, 29).snapToGrid(3)).toMatchObject(new Vec(24, 30)) + expect(new Vec(25, 29).snapToGrid(10)).toMatchObject(new Vec(30, 30)) + expect(new Vec(12, 49).snapToGrid(10)).toMatchObject(new Vec(10, 50)) + + expect(Vec.SnapToGrid(new Vec(25, 29))).toMatchObject(new Vec(24, 32)) + expect(Vec.SnapToGrid(new Vec(25, 29), 8)).toMatchObject(new Vec(24, 32)) + expect(Vec.SnapToGrid(new Vec(25, 29), 3)).toMatchObject(new Vec(24, 30)) + expect(Vec.SnapToGrid(new Vec(25, 29), 10)).toMatchObject(new Vec(30, 30)) + expect(Vec.SnapToGrid(new Vec(12, 49), 10)).toMatchObject(new Vec(10, 50)) + }) +}) diff --git a/packages/editor/src/lib/primitives/Vec2d.ts b/packages/editor/src/lib/primitives/Vec.ts similarity index 59% rename from packages/editor/src/lib/primitives/Vec2d.ts rename to packages/editor/src/lib/primitives/Vec.ts index 4c512a44d..874a986e4 100644 --- a/packages/editor/src/lib/primitives/Vec2d.ts +++ b/packages/editor/src/lib/primitives/Vec.ts @@ -1,11 +1,11 @@ -import { Vec2dModel } from '@tldraw/tlschema' +import { VecModel } from '@tldraw/tlschema' import { EASINGS } from './easings' /** @public */ -export type VecLike = Vec2d | Vec2dModel +export type VecLike = Vec | VecModel /** @public */ -export class Vec2d { +export class Vec { constructor(public x = 0, public y = 0, public z = 1) {} // eslint-disable-next-line no-restricted-syntax @@ -48,9 +48,9 @@ export class Vec2d { return this } - clone(): Vec2d { + clone(): Vec { const { x, y, z } = this - return new Vec2d(x, y, z) + return new Vec(x, y, z) } sub(V: VecLike) { @@ -138,7 +138,7 @@ export class Vec2d { } nudge(B: VecLike, distance: number) { - const tan = Vec2d.Tan(B, this) + const tan = Vec.Tan(B, this) return this.add(tan.mul(distance)) } @@ -157,23 +157,23 @@ export class Vec2d { } dpr(V: VecLike): number { - return Vec2d.Dpr(this, V) + return Vec.Dpr(this, V) } cpr(V: VecLike) { - return Vec2d.Cpr(this, V) + return Vec.Cpr(this, V) } len2(): number { - return Vec2d.Len2(this) + return Vec.Len2(this) } len(): number { - return Vec2d.Len(this) + return Vec.Len(this) } pry(V: VecLike): number { - return Vec2d.Pry(this, V) + return Vec.Pry(this, V) } per() { @@ -184,23 +184,23 @@ export class Vec2d { } uni() { - return Vec2d.Uni(this) + return Vec.Uni(this) } - tan(V: VecLike): Vec2d { - return Vec2d.Tan(this, V) + tan(V: VecLike): Vec { + return Vec.Tan(this, V) } dist(V: VecLike): number { - return Vec2d.Dist(this, V) + return Vec.Dist(this, V) } distanceToLineSegment(A: VecLike, B: VecLike): number { - return Vec2d.DistanceToLineSegment(A, B, this) + return Vec.DistanceToLineSegment(A, B, this) } slope(B: VecLike): number { - return Vec2d.Slope(this, B) + return Vec.Slope(this, B) } snapToGrid(gridSize: number) { @@ -210,25 +210,25 @@ export class Vec2d { } angle(B: VecLike): number { - return Vec2d.Angle(this, B) + return Vec.Angle(this, B) } toAngle() { - return Vec2d.ToAngle(this) + return Vec.ToAngle(this) } - lrp(B: VecLike, t: number): Vec2d { + lrp(B: VecLike, t: number): Vec { this.x = this.x + (B.x - this.x) * t this.y = this.y + (B.y - this.y) * t return this } equals(B: VecLike) { - return Vec2d.Equals(this, B) + return Vec.Equals(this, B) } equalsXY(x: number, y: number) { - return Vec2d.EqualsXY(this, x, y) + return Vec.EqualsXY(this, x, y) } norm() { @@ -239,75 +239,75 @@ export class Vec2d { } toFixed() { - return Vec2d.ToFixed(this) + return Vec.ToFixed(this) } toString() { - return Vec2d.ToString(Vec2d.ToFixed(this)) + return Vec.ToString(Vec.ToFixed(this)) } - toJson(): Vec2dModel { - return Vec2d.ToJson(this) + toJson(): VecModel { + return Vec.ToJson(this) } toArray(): number[] { - return Vec2d.ToArray(this) + return Vec.ToArray(this) } - static Add(A: VecLike, B: VecLike): Vec2d { - return new Vec2d(A.x + B.x, A.y + B.y) + static Add(A: VecLike, B: VecLike): Vec { + return new Vec(A.x + B.x, A.y + B.y) } - static AddXY(A: VecLike, x: number, y: number): Vec2d { - return new Vec2d(A.x + x, A.y + y) + static AddXY(A: VecLike, x: number, y: number): Vec { + return new Vec(A.x + x, A.y + y) } - static Sub(A: VecLike, B: VecLike): Vec2d { - return new Vec2d(A.x - B.x, A.y - B.y) + static Sub(A: VecLike, B: VecLike): Vec { + return new Vec(A.x - B.x, A.y - B.y) } - static SubXY(A: VecLike, x: number, y: number): Vec2d { - return new Vec2d(A.x - x, A.y - y) + static SubXY(A: VecLike, x: number, y: number): Vec { + return new Vec(A.x - x, A.y - y) } - static AddScalar(A: VecLike, n: number): Vec2d { - return new Vec2d(A.x + n, A.y + n) + static AddScalar(A: VecLike, n: number): Vec { + return new Vec(A.x + n, A.y + n) } - static SubScalar(A: VecLike, n: number): Vec2d { - return new Vec2d(A.x - n, A.y - n) + static SubScalar(A: VecLike, n: number): Vec { + return new Vec(A.x - n, A.y - n) } - static Div(A: VecLike, t: number): Vec2d { - return new Vec2d(A.x / t, A.y / t) + static Div(A: VecLike, t: number): Vec { + return new Vec(A.x / t, A.y / t) } - static Mul(A: VecLike, t: number): Vec2d { - return new Vec2d(A.x * t, A.y * t) + static Mul(A: VecLike, t: number): Vec { + return new Vec(A.x * t, A.y * t) } - static DivV(A: VecLike, B: VecLike): Vec2d { - return new Vec2d(A.x / B.x, A.y / B.y) + static DivV(A: VecLike, B: VecLike): Vec { + return new Vec(A.x / B.x, A.y / B.y) } - static MulV(A: VecLike, B: VecLike): Vec2d { - return new Vec2d(A.x * B.x, A.y * B.y) + static MulV(A: VecLike, B: VecLike): Vec { + return new Vec(A.x * B.x, A.y * B.y) } - static Neg(A: VecLike): Vec2d { - return new Vec2d(-A.x, -A.y) + static Neg(A: VecLike): Vec { + return new Vec(-A.x, -A.y) } - static Per(A: VecLike): Vec2d { - return new Vec2d(A.y, -A.x) + static Per(A: VecLike): Vec { + return new Vec(A.y, -A.x) } static Dist2(A: VecLike, B: VecLike): number { - return Vec2d.Sub(A, B).len2() + return Vec.Sub(A, B).len2() } - static Abs(A: VecLike): Vec2d { - return new Vec2d(Math.abs(A.x), Math.abs(A.y)) + static Abs(A: VecLike): Vec { + return new Vec(Math.abs(A.x), Math.abs(A.y)) } static Dist(A: VecLike, B: VecLike): number { @@ -319,7 +319,7 @@ export class Vec2d { } static Cross(A: VecLike, V: VecLike) { - return new Vec2d( + return new Vec( A.y * V.z! - A.z! * V.y, A.z! * V.x - A.x * V.z! // A.z = A.x * V.y - A.y * V.x @@ -339,45 +339,45 @@ export class Vec2d { } static Pry(A: VecLike, B: VecLike): number { - return Vec2d.Dpr(A, B) / Vec2d.Len(B) + return Vec.Dpr(A, B) / Vec.Len(B) } static Uni(A: VecLike) { - return Vec2d.Div(A, Vec2d.Len(A)) + return Vec.Div(A, Vec.Len(A)) } - static Tan(A: VecLike, B: VecLike): Vec2d { - return Vec2d.Uni(Vec2d.Sub(A, B)) + static Tan(A: VecLike, B: VecLike): Vec { + return Vec.Uni(Vec.Sub(A, B)) } - static Min(A: VecLike, B: VecLike): Vec2d { - return new Vec2d(Math.min(A.x, B.x), Math.min(A.y, B.y)) + static Min(A: VecLike, B: VecLike): Vec { + return new Vec(Math.min(A.x, B.x), Math.min(A.y, B.y)) } - static Max(A: VecLike, B: VecLike): Vec2d { - return new Vec2d(Math.max(A.x, B.x), Math.max(A.y, B.y)) + static Max(A: VecLike, B: VecLike): Vec { + return new Vec(Math.max(A.x, B.x), Math.max(A.y, B.y)) } - static From({ x, y, z = 1 }: Vec2dModel) { - return new Vec2d(x, y, z) + static From({ x, y, z = 1 }: VecModel) { + return new Vec(x, y, z) } - static FromArray(v: number[]): Vec2d { - return new Vec2d(v[0], v[1]) + static FromArray(v: number[]): Vec { + return new Vec(v[0], v[1]) } - static Rot(A: VecLike, r = 0): Vec2d { + static Rot(A: VecLike, r = 0): Vec { const s = Math.sin(r) const c = Math.cos(r) - return new Vec2d(A.x * c - A.y * s, A.x * s + A.y * c) + return new Vec(A.x * c - A.y * s, A.x * s + A.y * c) } - static RotWith(A: VecLike, C: VecLike, r: number): Vec2d { + static RotWith(A: VecLike, C: VecLike, r: number): Vec { const x = A.x - C.x const y = A.y - C.y const s = Math.sin(r) const c = Math.cos(r) - return new Vec2d(C.x + (x * c - y * s), C.y + (x * s + y * c)) + return new Vec(C.x + (x * c - y * s), C.y + (x * s + y * c)) } /** @@ -391,41 +391,41 @@ export class Vec2d { * @param u - The unit vector for the line. * @param P - A point not on the line to test. */ - static NearestPointOnLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): Vec2d { - return Vec2d.Mul(u, Vec2d.Sub(P, A).pry(u)).add(A) + static NearestPointOnLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): Vec { + return Vec.Mul(u, Vec.Sub(P, A).pry(u)).add(A) } - static NearestPointOnLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp = true): Vec2d { - const u = Vec2d.Tan(B, A) - const C = Vec2d.Add(A, Vec2d.Mul(u, Vec2d.Sub(P, A).pry(u))) + static NearestPointOnLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp = true): Vec { + const u = Vec.Tan(B, A) + const C = Vec.Add(A, Vec.Mul(u, Vec.Sub(P, A).pry(u))) // todo: fix error P is B or A, which leads to a NaN value if (clamp) { - if (C.x < Math.min(A.x, B.x)) return Vec2d.Cast(A.x < B.x ? A : B) - if (C.x > Math.max(A.x, B.x)) return Vec2d.Cast(A.x > B.x ? A : B) - if (C.y < Math.min(A.y, B.y)) return Vec2d.Cast(A.y < B.y ? A : B) - if (C.y > Math.max(A.y, B.y)) return Vec2d.Cast(A.y > B.y ? A : B) + if (C.x < Math.min(A.x, B.x)) return Vec.Cast(A.x < B.x ? A : B) + if (C.x > Math.max(A.x, B.x)) return Vec.Cast(A.x > B.x ? A : B) + if (C.y < Math.min(A.y, B.y)) return Vec.Cast(A.y < B.y ? A : B) + if (C.y > Math.max(A.y, B.y)) return Vec.Cast(A.y > B.y ? A : B) } return C } static DistanceToLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): number { - return Vec2d.Dist(P, Vec2d.NearestPointOnLineThroughPoint(A, u, P)) + return Vec.Dist(P, Vec.NearestPointOnLineThroughPoint(A, u, P)) } static DistanceToLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp = true): number { - return Vec2d.Dist(P, Vec2d.NearestPointOnLineSegment(A, B, P, clamp)) + return Vec.Dist(P, Vec.NearestPointOnLineSegment(A, B, P, clamp)) } static Snap(A: VecLike, step = 1) { - return new Vec2d(Math.round(A.x / step) * step, Math.round(A.y / step) * step) + return new Vec(Math.round(A.x / step) * step, Math.round(A.y / step) * step) } - static Cast(A: VecLike): Vec2d { - if (A instanceof Vec2d) return A - return Vec2d.From(A) + static Cast(A: VecLike): Vec { + if (A instanceof Vec) return A + return Vec.From(A) } static Slope(A: VecLike, B: VecLike): number { @@ -437,12 +437,12 @@ export class Vec2d { return Math.atan2(B.y - A.y, B.x - A.x) } - static Lrp(A: VecLike, B: VecLike, t: number): Vec2d { - return Vec2d.Sub(B, A).mul(t).add(A) + static Lrp(A: VecLike, B: VecLike, t: number): Vec { + return Vec.Sub(B, A).mul(t).add(A) } - static Med(A: VecLike, B: VecLike): Vec2d { - return new Vec2d((A.x + B.x) / 2, (A.y + B.y) / 2) + static Med(A: VecLike, B: VecLike): Vec { + return new Vec((A.x + B.x) / 2, (A.y + B.y) / 2) } static Equals(A: VecLike, B: VecLike): boolean { @@ -458,20 +458,20 @@ export class Vec2d { } static Rescale(A: VecLike, n: number) { - const l = Vec2d.Len(A) - return new Vec2d((n * A.x) / l, (n * A.y) / l) + const l = Vec.Len(A) + return new Vec((n * A.x) / l, (n * A.y) / l) } static ScaleWithOrigin(A: VecLike, scale: number, origin: VecLike) { - return Vec2d.Sub(A, origin).mul(scale).add(origin) + return Vec.Sub(A, origin).mul(scale).add(origin) } static ToFixed(A: VecLike, n = 2) { - return new Vec2d(+A.x.toFixed(n), +A.y.toFixed(n), +A.z!.toFixed(n)) + return new Vec(+A.x.toFixed(n), +A.y.toFixed(n), +A.z!.toFixed(n)) } static Nudge(A: VecLike, B: VecLike, distance: number) { - return Vec2d.Add(A, Vec2d.Tan(B, A).mul(distance)) + return Vec.Add(A, Vec.Tan(B, A).mul(distance)) } static ToString(A: VecLike) { @@ -486,7 +486,7 @@ export class Vec2d { } static FromAngle(r: number, length = 1) { - return new Vec2d(Math.cos(r) * length, Math.sin(r) * length) + return new Vec(Math.cos(r) * length, Math.sin(r) * length) } static ToArray(A: VecLike) { @@ -500,19 +500,19 @@ export class Vec2d { static Average(arr: VecLike[]) { const len = arr.length - const avg = new Vec2d(0, 0) + const avg = new Vec(0, 0) for (let i = 0; i < len; i++) { avg.add(arr[i]) } return avg.div(len) } - static Clamp(A: Vec2d, min: number, max?: number) { + static Clamp(A: Vec, min: number, max?: number) { if (max === undefined) { - return new Vec2d(Math.min(Math.max(A.x, min)), Math.min(Math.max(A.y, min))) + return new Vec(Math.min(Math.max(A.x, min)), Math.min(Math.max(A.y, min))) } - return new Vec2d(Math.min(Math.max(A.x, min), max), Math.min(Math.max(A.y, min), max)) + return new Vec(Math.min(Math.max(A.x, min), max), Math.min(Math.max(A.y, min), max)) } /** @@ -522,12 +522,12 @@ export class Vec2d { * @param B - The second point. * @param steps - The number of points to return. */ - static PointsBetween(A: Vec2dModel, B: Vec2dModel, steps = 6): Vec2d[] { - const results: Vec2d[] = [] + static PointsBetween(A: VecModel, B: VecModel, steps = 6): Vec[] { + const results: Vec[] = [] for (let i = 0; i < steps; i++) { const t = EASINGS.easeInQuad(i / (steps - 1)) - const point = Vec2d.Lrp(A, B, t) + const point = Vec.Lrp(A, B, t) point.z = Math.min(1, 0.5 + Math.abs(0.5 - ease(t)) * 0.65) results.push(point) } @@ -536,7 +536,7 @@ export class Vec2d { } static SnapToGrid(A: VecLike, gridSize = 8) { - return new Vec2d(Math.round(A.x / gridSize) * gridSize, Math.round(A.y / gridSize) * gridSize) + return new Vec(Math.round(A.x / gridSize) * gridSize, Math.round(A.y / gridSize) * gridSize) } } diff --git a/packages/editor/src/lib/primitives/Vec2d.test.ts b/packages/editor/src/lib/primitives/Vec2d.test.ts deleted file mode 100644 index dffbbb852..000000000 --- a/packages/editor/src/lib/primitives/Vec2d.test.ts +++ /dev/null @@ -1,379 +0,0 @@ -import { Vec2d } from './Vec2d' - -describe('iteratable', () => { - it('Constructs', () => { - const v = new Vec2d(1, 2) - const { x, y } = v - expect(x).toBeCloseTo(1) - expect(y).toBeCloseTo(2) - }) -}) - -describe('Vec2d.Clamp', () => { - it('Clamps a vector between a range.', () => { - expect(Vec2d.Clamp(new Vec2d(9, 5), 7, 10)).toMatchObject(new Vec2d(9, 7)) - expect(Vec2d.Clamp(new Vec2d(-9, 5), 0, 10)).toMatchObject(new Vec2d(0, 5)) - }) -}) - -describe('Vec2d.Clamp', () => { - it('Clamps a vector between a range.', () => { - expect(Vec2d.Clamp(new Vec2d(9, 5), 7, 10)).toMatchObject(new Vec2d(9, 7)) - expect(Vec2d.Clamp(new Vec2d(-9, 5), 0, 10)).toMatchObject(new Vec2d(0, 5)) - }) - it('Clamps a vector between a range.', () => { - expect(Vec2d.Clamp(new Vec2d(9, 5), 10)).toMatchObject(new Vec2d(10, 10)) - expect(Vec2d.Clamp(new Vec2d(-9, 5), 10)).toMatchObject(new Vec2d(10, 10)) - }) -}) - -describe('Vec2d.Neg', () => { - it('Negates a vector.', () => { - expect(Vec2d.Neg(new Vec2d(9, 5))).toMatchObject(new Vec2d(-9, -5)) - expect(Vec2d.Neg(new Vec2d(-9, 0))).toMatchObject(new Vec2d(9, -0)) - }) -}) - -describe('Vec2d.Add', () => { - it('Adds two vectors.', () => { - expect(Vec2d.Add(new Vec2d(9, 5), new Vec2d(2, 1))).toMatchObject(new Vec2d(11, 6)) - expect(Vec2d.Add(new Vec2d(-9, 5), new Vec2d(2, -1))).toMatchObject(new Vec2d(-7, 4)) - }) -}) - -describe('Vec2d.AddScalar', () => { - it('Adds a scalar to a vector.', () => { - expect(Vec2d.AddScalar(new Vec2d(9, 5), 2)).toMatchObject(new Vec2d(11, 7)) - expect(Vec2d.AddScalar(new Vec2d(-9, 5), 2)).toMatchObject(new Vec2d(-7, 7)) - }) -}) - -describe('Vec2d.Sub', () => { - it('Subtracts two vectors.', () => { - expect(Vec2d.Sub(new Vec2d(9, 5), new Vec2d(2, 1))).toMatchObject(new Vec2d(7, 4)) - expect(Vec2d.Sub(new Vec2d(-9, 5), new Vec2d(2, -1))).toMatchObject(new Vec2d(-11, 6)) - }) -}) - -describe('Vec2d.SubScalar', () => { - it('Subtracts a scalar from a vector.', () => { - expect(Vec2d.SubScalar(new Vec2d(9, 5), 2)).toMatchObject(new Vec2d(7, 3)) - expect(Vec2d.SubScalar(new Vec2d(-9, 5), 2)).toMatchObject(new Vec2d(-11, 3)) - }) -}) - -describe('Vec2d.Mul', () => { - it('Get a vector multiplied by a scalar.', () => { - expect(Vec2d.Mul(new Vec2d(9, 9), 3)).toMatchObject(new Vec2d(27, 27)) - expect(Vec2d.Mul(new Vec2d(10, 10), 2)).toMatchObject(new Vec2d(20, 20)) - }) -}) - -describe('Vec2d.DivV', () => { - it('Get a vector multiplied by a vector.', () => { - expect(Vec2d.MulV(new Vec2d(16, 12), new Vec2d(2, 4))).toMatchObject(new Vec2d(32, 48)) - expect(Vec2d.MulV(new Vec2d(5, 15), new Vec2d(5, 3))).toMatchObject(new Vec2d(25, 45)) - }) -}) - -describe('Vec2d.Div', () => { - it('Get a vector divided by a scalar.', () => { - expect(Vec2d.Div(new Vec2d(9, 9), 3)).toMatchObject(new Vec2d(3, 3)) - expect(Vec2d.Div(new Vec2d(10, 10), 2)).toMatchObject(new Vec2d(5, 5)) - }) -}) - -describe('Vec2d.DivV', () => { - it('Get a vector divided by a vector.', () => { - expect(Vec2d.DivV(new Vec2d(16, 12), new Vec2d(2, 4))).toMatchObject(new Vec2d(8, 3)) - expect(Vec2d.DivV(new Vec2d(5, 15), new Vec2d(5, 3))).toMatchObject(new Vec2d(1, 5)) - }) -}) - -describe('Vec2d.Per', () => { - it('Gets the perpendicular rotation of a vector.', () => { - expect(Vec2d.Per(new Vec2d(1, -1))).toMatchObject(new Vec2d(-1, -1)) - expect(Vec2d.Per(new Vec2d(-1, 1))).toMatchObject(new Vec2d(1, 1)) - }) -}) - -describe('Vec2d.Dpr', () => { - it('Gets the dot product of two vectors.', () => { - expect(Vec2d.Dpr(new Vec2d(1, 0), new Vec2d(1, 0))).toEqual(1) - expect(Vec2d.Dpr(new Vec2d(1, 0), new Vec2d(0, 0))).toEqual(0) - expect(Vec2d.Dpr(new Vec2d(1, 0), new Vec2d(-1, 0))).toEqual(-1) - }) -}) - -describe('Vec2d.Cpr', () => { - it('Gets the cross product (outer product) of two vectors.', () => { - expect(Vec2d.Cpr(new Vec2d(0, 1), new Vec2d(1, 1))).toEqual(-1) - expect(Vec2d.Cpr(new Vec2d(1, 1), new Vec2d(1, 1))).toEqual(0) - expect(Vec2d.Cpr(new Vec2d(1, 1), new Vec2d(0, 1))).toEqual(1) - }) -}) - -describe('Vec2d.Len2', () => { - it('Gets the length of a vector squared.', () => { - expect(Vec2d.Len2(new Vec2d(0, 0))).toEqual(0) - expect(Vec2d.Len2(new Vec2d(0, 1))).toEqual(1) - expect(Vec2d.Len2(new Vec2d(1, 1))).toEqual(2) - }) -}) - -describe('Vec2d.Len', () => { - it('Gets the length of a vector.', () => { - expect(Vec2d.Len(new Vec2d(0, 0))).toEqual(0) - expect(Vec2d.Len(new Vec2d(0, 1))).toEqual(1) - expect(Vec2d.Len(new Vec2d(1, 1))).toEqual(1.4142135623730951) - }) -}) - -describe('Vec2d.Pry', () => { - it('Projects a vector A over vector B.', () => { - expect(Vec2d.Pry(new Vec2d(0, 0), new Vec2d(0, 10))).toEqual(0) - expect(Vec2d.Pry(new Vec2d(0, 0), new Vec2d(10, 10))).toEqual(0) - expect(Vec2d.Pry(new Vec2d(10, 10), new Vec2d(0, 10))).toEqual(10) - expect(Vec2d.Pry(new Vec2d(10, 10), new Vec2d(10, 10))).toEqual(14.14213562373095) - }) -}) - -describe('Vec2d.Uni', () => { - it('Gets the normalized vector.', () => { - expect(Vec2d.Uni(new Vec2d(0, 10))).toMatchObject(new Vec2d(0, 1)) - expect(Vec2d.Uni(new Vec2d(10, 10))).toMatchObject( - new Vec2d(0.7071067811865475, 0.7071067811865475) - ) - }) -}) - -describe('Vec2d.Tan', () => { - it('Gets the tangent between two vectors.', () => { - expect(Vec2d.Tan(new Vec2d(0, 0), new Vec2d(0, 10))).toMatchObject(new Vec2d(0, -1)) - expect(Vec2d.Tan(new Vec2d(0, 0), new Vec2d(10, 10))).toMatchObject( - new Vec2d(-0.7071067811865475, -0.7071067811865475) - ) - }) -}) - -describe('Vec2d.Dist2', () => { - it('Finds the squared distance between two points.', () => { - expect(Vec2d.Dist2(new Vec2d(0, 0), new Vec2d(0, 10))).toEqual(100) - expect(Vec2d.Dist2(new Vec2d(0, 0), new Vec2d(10, 10))).toEqual(200) - }) -}) - -describe('Vec2d.Dist', () => { - it('Finds the distance between two points.', () => { - expect(Vec2d.Dist(new Vec2d(0, 0), new Vec2d(0, 10))).toEqual(10) - expect(Vec2d.Dist(new Vec2d(0, 0), new Vec2d(10, 10))).toEqual(14.142135623730951) - }) -}) - -// describe('Vec2d.Ang2', () => { -// it('Finds the angle in radians between two vectors.', () => { -// expect(Vec2d.Ang2(new Vec2d(1, 0), new Vec2d(0, 1))).toEqual(Math.PI / 2) -// }) -// }) - -// describe('Vec2d.Ang3', () => { -// it('Gets the angle of ∠ABC', () => { -// expect(Vec2d.Ang3([5, 0], new Vec2d(0, 0), new Vec2d(0, 5))).toEqual(Math.PI / 2) -// expect(Vec2d.Ang3(new Vec2d(1, 0), new Vec2d(0, 0), new Vec2d(0, 1))).toEqual(Math.PI / 2) -// }) -// }) - -describe('Vec2d.Angle', () => { - it('Finds the angle in radians between two points.', () => { - expect(Vec2d.Angle(new Vec2d(0, 0), new Vec2d(10, 10))).toEqual(Math.PI / 4) - expect(Vec2d.Angle(new Vec2d(0, 0), new Vec2d(10, 0))).toEqual(0) - expect(Vec2d.Angle(new Vec2d(0, 0), new Vec2d(0, 10))).toEqual(Math.PI / 2) - }) -}) - -describe('Vec2d.Med', () => { - it('Finds the midpoint between two vectors.', () => { - expect(Vec2d.Med(new Vec2d(0, 0), new Vec2d(10, 10))).toMatchObject(new Vec2d(5, 5)) - expect(Vec2d.Med(new Vec2d(0, 0), new Vec2d(10, 0))).toMatchObject(new Vec2d(5, 0)) - expect(Vec2d.Med(new Vec2d(0, 0), new Vec2d(0, 10))).toMatchObject(new Vec2d(0, 5)) - expect(Vec2d.Med(new Vec2d(-100, 0), new Vec2d(0, 100))).toMatchObject(new Vec2d(-50, 50)) - }) -}) - -describe('Vec2d.Rot', () => { - it('Rotates a vector by a rotation in radians.', () => { - const { x, y } = Vec2d.Rot(new Vec2d(1, 0), Math.PI / 4) - expect(x).toBeCloseTo(0.7, 1) - expect(y).toBeCloseTo(0.7, 1) - }) -}) - -describe('Vec2d.RotWith', () => { - it('Rotates a vector around a second vector by a rotation in radians.', () => { - expect(Vec2d.RotWith(new Vec2d(1, 0), new Vec2d(0, 0), Math.PI / 4)).toMatchObject( - new Vec2d(0.7071067811865476, 0.7071067811865475) - ) - }) -}) - -describe('Vec2d.Equals', () => { - it('Gets whether two vectors are identical.', () => { - expect(Vec2d.Equals(new Vec2d(1, 2), new Vec2d(1, 2))).toEqual(true) - expect(Vec2d.Equals(new Vec2d(1, 2), new Vec2d(1, 3))).toEqual(false) - expect(Vec2d.Equals(new Vec2d(-0, 2), new Vec2d(0, 2))).toEqual(true) - }) -}) - -describe('Vec2d.Int', () => { - it('Interpolate from A to B', () => { - expect(Vec2d.Lrp(new Vec2d(0, 0), new Vec2d(10, 10), 0.5)).toMatchObject(new Vec2d(5, 5)) - expect(Vec2d.Lrp(new Vec2d(0, 0), new Vec2d(10, 10), 2)).toMatchObject(new Vec2d(20, 20)) - }) -}) - -describe('Vec2d.Rescale', () => { - it('Rescales a vector by a scalar', () => { - expect(Vec2d.Rescale(new Vec2d(5, 0), 1)).toMatchObject(new Vec2d(1, 0)) - expect(Vec2d.Rescale(new Vec2d(5, 0), 2)).toMatchObject(new Vec2d(2, 0)) - expect(Vec2d.Rescale(new Vec2d(0.5, 0.25), 2)).toEqual( - new Vec2d(1.7888543819998317, 0.8944271909999159) - ) - }) -}) - -describe('Vec2d.IsClockwise', () => { - it('Gets whether point A and point B wind clockwise around point C.', () => { - expect(Vec2d.Clockwise(new Vec2d(0, 0), new Vec2d(5, 5), new Vec2d(0, 5))).toEqual(true) - expect(Vec2d.Clockwise(new Vec2d(5, 5), new Vec2d(0, 0), new Vec2d(0, 5))).toEqual(false) - expect(Vec2d.Clockwise(new Vec2d(0, 10), new Vec2d(0, 0), new Vec2d(0, 5))).toEqual(false) - }) -}) - -describe('Vec2d.ToFixed', () => { - it('Rounds a vector to the a given precision.', () => { - expect(Vec2d.ToFixed(new Vec2d(1.2345, 5.678), 1)).toMatchObject(new Vec2d(1.2, 5.7)) - expect(Vec2d.ToFixed(new Vec2d(1.2345, 5.678), 2)).toMatchObject(new Vec2d(1.23, 5.68)) - }) -}) - -describe('Vec2d.Snap', () => { - it('Snaps a vector to the nearest increment provided.', () => { - expect(Vec2d.Snap(new Vec2d(10.5, 28), 10)).toMatchObject(new Vec2d(10, 30)) - }) -}) - -describe('Vec2d.NearestPointOnLineThroughPoint', () => { - it('Gets the distance from a point to a line that passes through a given point.', () => { - expect( - Vec2d.NearestPointOnLineThroughPoint(new Vec2d(0, 0), new Vec2d(0, 1), new Vec2d(5, 5)) - ).toMatchObject(new Vec2d(0, 5)) - }) -}) - -describe('Vec2d.DistanceToLineThroughPoint', () => { - it('Gets the distance from a point to a line that passes through a given point.', () => { - expect( - Vec2d.DistanceToLineThroughPoint(new Vec2d(0, 0), new Vec2d(0, 1), new Vec2d(5, 5)) - ).toEqual(5) - }) -}) - -describe('Vec2d.NearestPointOnLineSegment', () => { - it('Gets the distance from a point to a line segment.', () => { - expect( - Vec2d.NearestPointOnLineSegment(new Vec2d(0, 0), new Vec2d(0, 10), new Vec2d(5, 5)) - ).toMatchObject(new Vec2d(0, 5)) - }) -}) - -describe('Vec2d.DistanceToLineSegment', () => { - it('Gets the distance from a point to a line segment.', () => { - expect(Vec2d.DistanceToLineSegment(new Vec2d(0, 0), new Vec2d(0, 10), new Vec2d(5, 5))).toEqual( - 5 - ) - }) -}) - -describe('Vec2d.Nudge', () => { - it('Pushes a point towards another point by a given distance.', () => { - expect(Vec2d.Nudge(new Vec2d(0, 0), new Vec2d(0, 10), 5)).toMatchObject(new Vec2d(0, 5)) - }) -}) - -// describe('Vec2d.NudgeAtVector', () => { -// it('Pushes a point in a given direction vector by a given distance.', () => { -// expect(Vec2d.NudgeAtVector(new Vec2d(0, 0), new Vec2d(0.5, 0.75), 10)).toEqual( -// new Vec2d(5, 7.5) -// ) -// }) -// }) - -// describe('Vec2d.NudgeAtAngle', () => { -// it('Pushes a point in a given angle by a given distance.', () => { -// expect(Vec2d.NudgeAtAngle(new Vec2d(0, 0), Math.PI / 8, 10)).toEqual( -// new Vec2d(9.238795325112868, 3.826834323650898) -// ) -// }) -// }) - -// describe('Vec2d.PointsBetween', () => { -// it('Interpolates points between two points.', () => { -// expect(Vec2d.PointsBetween(new Vec2d(0, 0), [100, 100], 10)).toMatchObject(new Vec2)( -// new Vec2d(0, 0, 1), -// new Vec2d(11.11111111111111, 11.11111111111111, 0.8888888888888888), -// new Vec2d(22.22222222222222, 22.22222222222222, 0.7777777777777778), -// new Vec2d(33.33333333333333, 33.33333333333333, 0.6666666666666667), -// new Vec2d(44.44444444444444, 44.44444444444444, 0.5555555555555556), -// new Vec2d(55.55555555555556, 55.55555555555556, 0.5555555555555556), -// new Vec2d(66.66666666666666, 66.66666666666666, 0.6666666666666666), -// new Vec2d(77.77777777777779, 77.77777777777779, 0.7777777777777778), -// new Vec2d(88.88888888888889, 88.88888888888889, 0.8888888888888888), -// new Vec2d(100, 100, 1), -// ]) -// }) -// }) - -describe('Vec2d.Slope', () => { - it('Gets a slope from a vector.', () => { - expect(Vec2d.Slope(new Vec2d(0, 0), new Vec2d(100, 100))).toEqual(1) - expect(Vec2d.Slope(new Vec2d(0, 0), new Vec2d(50, 100))).toEqual(2) - expect(Vec2d.Slope(new Vec2d(0, 0), new Vec2d(-50, 100))).toEqual(-2) - expect(Vec2d.Slope(new Vec2d(123, 456), new Vec2d(789, 24))).toEqual(-0.6486486486486487) - }) -}) - -describe('Vec2d.ToAngle', () => { - it('Gets an angle from a vector.', () => { - expect(Vec2d.ToAngle(new Vec2d(1, 0.5))).toEqual(0.4636476090008061) - }) -}) - -describe('Vec2d.Max', () => { - it('Gets the minimum of the given vectors', () => { - expect(Vec2d.Max(new Vec2d(4, 1), new Vec2d(3, 2))).toMatchObject(new Vec2d(4, 2)) - expect(Vec2d.Max(new Vec2d(3, 2), new Vec2d(4, 1))).toMatchObject(new Vec2d(4, 2)) - }) -}) - -describe('Vec2d.Min', () => { - it('Gets the minimum of the given vectors', () => { - expect(Vec2d.Min(new Vec2d(4, 1), new Vec2d(3, 2))).toMatchObject(new Vec2d(3, 1)) - expect(Vec2d.Min(new Vec2d(3, 2), new Vec2d(4, 1))).toMatchObject(new Vec2d(3, 1)) - }) -}) - -describe('Vec2d.snapToGrid', () => { - it('snaps to the nearest given increment, mutating the original vector and returning it', () => { - expect(new Vec2d(25, 29).snapToGrid(8)).toMatchObject(new Vec2d(24, 32)) - expect(new Vec2d(25, 29).snapToGrid(8)).toMatchObject(new Vec2d(24, 32)) - expect(new Vec2d(25, 29).snapToGrid(3)).toMatchObject(new Vec2d(24, 30)) - expect(new Vec2d(25, 29).snapToGrid(10)).toMatchObject(new Vec2d(30, 30)) - expect(new Vec2d(12, 49).snapToGrid(10)).toMatchObject(new Vec2d(10, 50)) - - expect(Vec2d.SnapToGrid(new Vec2d(25, 29))).toMatchObject(new Vec2d(24, 32)) - expect(Vec2d.SnapToGrid(new Vec2d(25, 29), 8)).toMatchObject(new Vec2d(24, 32)) - expect(Vec2d.SnapToGrid(new Vec2d(25, 29), 3)).toMatchObject(new Vec2d(24, 30)) - expect(Vec2d.SnapToGrid(new Vec2d(25, 29), 10)).toMatchObject(new Vec2d(30, 30)) - expect(Vec2d.SnapToGrid(new Vec2d(12, 49), 10)).toMatchObject(new Vec2d(10, 50)) - }) -}) diff --git a/packages/editor/src/lib/primitives/geometry/Arc2d.ts b/packages/editor/src/lib/primitives/geometry/Arc2d.ts index c2c167fa2..6335a6aca 100644 --- a/packages/editor/src/lib/primitives/geometry/Arc2d.ts +++ b/packages/editor/src/lib/primitives/geometry/Arc2d.ts @@ -1,4 +1,4 @@ -import { Vec2d } from '../Vec2d' +import { Vec } from '../Vec' import { intersectLineSegmentCircle } from '../intersect' import { PI, PI2, shortAngleDist } from '../utils' import { Geometry2d, Geometry2dOptions } from './Geometry2d' @@ -6,10 +6,10 @@ import { getVerticesCountForLength } from './geometry-constants' /** @public */ export class Arc2d extends Geometry2d { - _center: Vec2d + _center: Vec radius: number - start: Vec2d - end: Vec2d + start: Vec + end: Vec measure: number length: number @@ -18,10 +18,10 @@ export class Arc2d extends Geometry2d { constructor( config: Omit & { - center: Vec2d + center: Vec radius: number - start: Vec2d - end: Vec2d + start: Vec + end: Vec sweepFlag: number largeArcFlag: number } @@ -31,8 +31,8 @@ export class Arc2d extends Geometry2d { if (start.equals(end)) throw Error(`Arc must have different start and end points.`) // ensure that the start and end are clockwise - this.angleStart = Vec2d.Angle(center, start) - this.angleEnd = Vec2d.Angle(center, end) + this.angleStart = Vec.Angle(center, start) + this.angleEnd = Vec.Angle(center, end) this.measure = getArcMeasure(this.angleStart, this.angleEnd, sweepFlag, largeArcFlag) this.length = this.measure * radius @@ -43,7 +43,7 @@ export class Arc2d extends Geometry2d { this.radius = radius } - nearestPoint(point: Vec2d): Vec2d { + nearestPoint(point: Vec): Vec { const { _center, measure, radius, angleEnd, angleStart, start: A, end: B } = this const t = getPointInArcT(measure, angleStart, angleEnd, _center.angle(point)) if (t <= 0) return A @@ -53,7 +53,7 @@ export class Arc2d extends Geometry2d { const P = _center.clone().add(point.clone().sub(_center).uni().mul(radius)) let distance = Infinity - let nearest: Vec2d | undefined + let nearest: Vec | undefined for (const pt of [A, B, P]) { if (point.dist(pt) < distance) { nearest = pt @@ -65,7 +65,7 @@ export class Arc2d extends Geometry2d { return nearest } - hitTestLineSegment(A: Vec2d, B: Vec2d, _zoom: number): boolean { + hitTestLineSegment(A: Vec, B: Vec, _zoom: number): boolean { const { _center, radius, measure, angleStart, angleEnd } = this const intersection = intersectLineSegmentCircle(A, B, _center, radius) if (intersection === null) return false @@ -76,14 +76,14 @@ export class Arc2d extends Geometry2d { }) } - getVertices(): Vec2d[] { + getVertices(): Vec[] { const { _center, measure, length, radius, angleStart } = this - const vertices: Vec2d[] = [] + const vertices: Vec[] = [] for (let i = 0, n = getVerticesCountForLength(Math.abs(length)); i < n + 1; i++) { const t = (i / n) * measure const angle = angleStart + t - vertices.push(_center.clone().add(new Vec2d(Math.cos(angle), Math.sin(angle)).mul(radius))) + vertices.push(_center.clone().add(new Vec(Math.cos(angle), Math.sin(angle)).mul(radius))) } return vertices diff --git a/packages/editor/src/lib/primitives/geometry/Circle2d.test.ts b/packages/editor/src/lib/primitives/geometry/Circle2d.test.ts index 5a23f8286..04e1fd85f 100644 --- a/packages/editor/src/lib/primitives/geometry/Circle2d.test.ts +++ b/packages/editor/src/lib/primitives/geometry/Circle2d.test.ts @@ -1,4 +1,4 @@ -import { Vec2d } from '../Vec2d' +import { Vec } from '../Vec' import { Circle2d } from './Circle2d' describe('Circle2d.bounds', () => { @@ -53,7 +53,7 @@ describe('Circle2d.isPointInBounds', () => { new Circle2d({ radius: 10, isFilled: false, - }).isPointInBounds(new Vec2d(-2, -2)) + }).isPointInBounds(new Vec(-2, -2)) ).toBe(false) }) @@ -62,7 +62,7 @@ describe('Circle2d.isPointInBounds', () => { new Circle2d({ radius: 10, isFilled: false, - }).isPointInBounds(new Vec2d(5, 5)) + }).isPointInBounds(new Vec(5, 5)) ).toBe(true) }) @@ -71,7 +71,7 @@ describe('Circle2d.isPointInBounds', () => { new Circle2d({ radius: 10, isFilled: false, - }).isPointInBounds(new Vec2d(-2, -2), 2) + }).isPointInBounds(new Vec(-2, -2), 2) ).toBe(true) }) }) @@ -82,7 +82,7 @@ describe('Circle2d.getDistanceToPoint', () => { new Circle2d({ radius: 10, isFilled: false, - }).distanceToPoint(new Vec2d(10, -2)) + }).distanceToPoint(new Vec(10, -2)) ).toBe(2) }) @@ -91,7 +91,7 @@ describe('Circle2d.getDistanceToPoint', () => { new Circle2d({ radius: 10, isFilled: false, - }).distanceToPoint(new Vec2d(10, 2)) + }).distanceToPoint(new Vec(10, 2)) ).toBe(2) }) @@ -100,7 +100,7 @@ describe('Circle2d.getDistanceToPoint', () => { new Circle2d({ radius: 10, isFilled: true, - }).distanceToPoint(new Vec2d(10, 2)) + }).distanceToPoint(new Vec(10, 2)) ).toBe(-2) }) }) @@ -111,7 +111,7 @@ describe('Circle2d.hitTestPoint', () => { new Circle2d({ radius: 10, isFilled: false, - }).hitTestPoint(new Vec2d(10, -2), 0) + }).hitTestPoint(new Vec(10, -2), 0) ).toBe(false) }) @@ -120,7 +120,7 @@ describe('Circle2d.hitTestPoint', () => { new Circle2d({ radius: 10, isFilled: false, - }).hitTestPoint(new Vec2d(10, 2), 0) + }).hitTestPoint(new Vec(10, 2), 0) ).toBe(false) }) @@ -129,7 +129,7 @@ describe('Circle2d.hitTestPoint', () => { new Circle2d({ radius: 10, isFilled: true, - }).hitTestPoint(new Vec2d(10, 2), 0) + }).hitTestPoint(new Vec(10, 2), 0) ).toBe(true) }) @@ -140,7 +140,7 @@ describe('Circle2d.hitTestPoint', () => { new Circle2d({ radius: 10, isFilled: false, - }).hitTestPoint(new Vec2d(10, -2), 2) + }).hitTestPoint(new Vec(10, -2), 2) ).toBe(true) }) @@ -149,7 +149,7 @@ describe('Circle2d.hitTestPoint', () => { new Circle2d({ radius: 10, isFilled: false, - }).hitTestPoint(new Vec2d(10, 2), 2) + }).hitTestPoint(new Vec(10, 2), 2) ).toBe(true) }) @@ -158,7 +158,7 @@ describe('Circle2d.hitTestPoint', () => { new Circle2d({ radius: 10, isFilled: true, - }).hitTestPoint(new Vec2d(10, 2), 2) + }).hitTestPoint(new Vec(10, 2), 2) ).toBe(true) }) }) @@ -169,22 +169,22 @@ describe('Circle2d.nearestPoint', () => { new Circle2d({ radius: 10, isFilled: false, - }).nearestPoint(new Vec2d(10, -2)) - ).toMatchObject(new Vec2d(10, 0)) + }).nearestPoint(new Vec(10, -2)) + ).toMatchObject(new Vec(10, 0)) expect( new Circle2d({ radius: 10, isFilled: false, - }).nearestPoint(new Vec2d(10, 2)) - ).toMatchObject(new Vec2d(10, 0)) + }).nearestPoint(new Vec(10, 2)) + ).toMatchObject(new Vec(10, 0)) expect( new Circle2d({ radius: 10, isFilled: false, - }).nearestPoint(new Vec2d(10, 30)) - ).toMatchObject(new Vec2d(10, 20)) + }).nearestPoint(new Vec(10, 30)) + ).toMatchObject(new Vec(10, 20)) }) }) @@ -194,14 +194,14 @@ describe('Circle2d.hitTestLineSegment', () => { new Circle2d({ radius: 10, isFilled: false, - }).hitTestLineSegment(new Vec2d(0, -2), new Vec2d(20, -2), 1) + }).hitTestLineSegment(new Vec(0, -2), new Vec(20, -2), 1) ).toBe(false) expect( new Circle2d({ radius: 10, isFilled: false, - }).hitTestLineSegment(new Vec2d(0, 2), new Vec2d(20, 2), 1) + }).hitTestLineSegment(new Vec(0, 2), new Vec(20, 2), 1) ).toBe(true) }) }) diff --git a/packages/editor/src/lib/primitives/geometry/Circle2d.ts b/packages/editor/src/lib/primitives/geometry/Circle2d.ts index c60bb16e1..c7d5353f4 100644 --- a/packages/editor/src/lib/primitives/geometry/Circle2d.ts +++ b/packages/editor/src/lib/primitives/geometry/Circle2d.ts @@ -1,5 +1,5 @@ -import { Box2d } from '../Box2d' -import { Vec2d } from '../Vec2d' +import { Box } from '../Box' +import { Vec } from '../Vec' import { intersectLineSegmentCircle } from '../intersect' import { PI2 } from '../utils' import { Geometry2d, Geometry2dOptions } from './Geometry2d' @@ -7,7 +7,7 @@ import { getVerticesCountForLength } from './geometry-constants' /** @public */ export class Circle2d extends Geometry2d { - _center: Vec2d + _center: Vec radius: number x: number y: number @@ -24,32 +24,32 @@ export class Circle2d extends Geometry2d { const { x = 0, y = 0, radius } = config this.x = x this.y = y - this._center = new Vec2d(radius + x, radius + y) + this._center = new Vec(radius + x, radius + y) this.radius = radius } getBounds() { - return new Box2d(this.x, this.y, this.radius * 2, this.radius * 2) + return new Box(this.x, this.y, this.radius * 2, this.radius * 2) } - getVertices(): Vec2d[] { + getVertices(): Vec[] { const { _center, radius } = this const perimeter = PI2 * radius - const vertices: Vec2d[] = [] + const vertices: Vec[] = [] for (let i = 0, n = getVerticesCountForLength(perimeter); i < n; i++) { const angle = (i / n) * PI2 - vertices.push(_center.clone().add(Vec2d.FromAngle(angle).mul(radius))) + vertices.push(_center.clone().add(Vec.FromAngle(angle).mul(radius))) } return vertices } - nearestPoint(point: Vec2d): Vec2d { + nearestPoint(point: Vec): Vec { const { _center, radius } = this - if (_center.equals(point)) return Vec2d.AddXY(_center, radius, 0) + if (_center.equals(point)) return Vec.AddXY(_center, radius, 0) return _center.clone().add(point.clone().sub(_center).uni().mul(radius)) } - hitTestLineSegment(A: Vec2d, B: Vec2d, _zoom: number): boolean { + hitTestLineSegment(A: Vec, B: Vec, _zoom: number): boolean { const { _center, radius } = this return intersectLineSegmentCircle(A, B, _center, radius) !== null } diff --git a/packages/editor/src/lib/primitives/geometry/CubicBezier2d.ts b/packages/editor/src/lib/primitives/geometry/CubicBezier2d.ts index 7bced191e..06afd0813 100644 --- a/packages/editor/src/lib/primitives/geometry/CubicBezier2d.ts +++ b/packages/editor/src/lib/primitives/geometry/CubicBezier2d.ts @@ -1,20 +1,20 @@ -import { Vec2d } from '../Vec2d' +import { Vec } from '../Vec' import { Geometry2dOptions } from './Geometry2d' import { Polyline2d } from './Polyline2d' /** @public */ export class CubicBezier2d extends Polyline2d { - a: Vec2d - b: Vec2d - c: Vec2d - d: Vec2d + a: Vec + b: Vec + c: Vec + d: Vec constructor( config: Omit & { - start: Vec2d - cp1: Vec2d - cp2: Vec2d - end: Vec2d + start: Vec + cp1: Vec + cp2: Vec + end: Vec } ) { const { start: a, cp1: b, cp2: c, end: d } = config @@ -26,13 +26,13 @@ export class CubicBezier2d extends Polyline2d { } override getVertices() { - const vertices = [] as Vec2d[] + const vertices = [] as Vec[] const { a, b, c, d } = this // we'll always use ten vertices for each bezier curve for (let i = 0, n = 10; i <= n; i++) { const t = i / n vertices.push( - new Vec2d( + new Vec( (1 - t) * (1 - t) * (1 - t) * a.x + 3 * ((1 - t) * (1 - t)) * t * b.x + 3 * (1 - t) * (t * t) * c.x + @@ -51,8 +51,8 @@ export class CubicBezier2d extends Polyline2d { return getAtT(this, 0.5) } - nearestPoint(A: Vec2d): Vec2d { - let nearest: Vec2d | undefined + nearestPoint(A: Vec): Vec { + let nearest: Vec | undefined let dist = Infinity for (const edge of this.segments) { const p = edge.nearestPoint(A) @@ -70,7 +70,7 @@ export class CubicBezier2d extends Polyline2d { function getAtT(segment: CubicBezier2d, t: number) { const { a, b, c, d } = segment - return new Vec2d( + return new Vec( (1 - t) * (1 - t) * (1 - t) * a.x + 3 * ((1 - t) * (1 - t)) * t * b.x + 3 * (1 - t) * (t * t) * c.x + diff --git a/packages/editor/src/lib/primitives/geometry/CubicSpline2d.ts b/packages/editor/src/lib/primitives/geometry/CubicSpline2d.ts index bc132ce0e..3c362b91b 100644 --- a/packages/editor/src/lib/primitives/geometry/CubicSpline2d.ts +++ b/packages/editor/src/lib/primitives/geometry/CubicSpline2d.ts @@ -1,12 +1,12 @@ -import { Vec2d } from '../Vec2d' +import { Vec } from '../Vec' import { CubicBezier2d } from './CubicBezier2d' import { Geometry2d, Geometry2dOptions } from './Geometry2d' /** @public */ export class CubicSpline2d extends Geometry2d { - points: Vec2d[] + points: Vec[] - constructor(config: Omit & { points: Vec2d[] }) { + constructor(config: Omit & { points: Vec[] }) { super({ ...config, isClosed: false, isFilled: false }) const { points } = config @@ -32,13 +32,11 @@ export class CubicSpline2d extends Geometry2d { const p3 = i === last ? p2 : points[i + 2] const start = p1, cp1 = - i === 0 - ? p0 - : new Vec2d(p1.x + ((p2.x - p0.x) / 6) * k, p1.y + ((p2.y - p0.y) / 6) * k), + i === 0 ? p0 : new Vec(p1.x + ((p2.x - p0.x) / 6) * k, p1.y + ((p2.y - p0.y) / 6) * k), cp2 = i === last ? p2 - : new Vec2d(p2.x - ((p3.x - p1.x) / 6) * k, p2.y - ((p3.y - p1.y) / 6) * k), + : new Vec(p2.x - ((p3.x - p1.x) / 6) * k, p2.y - ((p3.y - p1.y) / 6) * k), end = p2 this._segments.push(new CubicBezier2d({ start, cp1, cp2, end })) @@ -61,13 +59,13 @@ export class CubicSpline2d extends Geometry2d { getVertices() { const vertices = this.segments.reduce((acc, segment) => { return acc.concat(segment.vertices) - }, [] as Vec2d[]) + }, [] as Vec[]) vertices.push(this.points[this.points.length - 1]) return vertices } - nearestPoint(A: Vec2d): Vec2d { - let nearest: Vec2d | undefined + nearestPoint(A: Vec): Vec { + let nearest: Vec | undefined let dist = Infinity for (const segment of this.segments) { const p = segment.nearestPoint(A) @@ -82,7 +80,7 @@ export class CubicSpline2d extends Geometry2d { return nearest } - hitTestLineSegment(A: Vec2d, B: Vec2d, zoom: number): boolean { + hitTestLineSegment(A: Vec, B: Vec, zoom: number): boolean { return this.segments.some((segment) => segment.hitTestLineSegment(A, B, zoom)) } } diff --git a/packages/editor/src/lib/primitives/geometry/Edge2d.ts b/packages/editor/src/lib/primitives/geometry/Edge2d.ts index 35f67a061..87bd8ff05 100644 --- a/packages/editor/src/lib/primitives/geometry/Edge2d.ts +++ b/packages/editor/src/lib/primitives/geometry/Edge2d.ts @@ -1,16 +1,16 @@ -import { Vec2d } from '../Vec2d' +import { Vec } from '../Vec' import { linesIntersect } from '../intersect' import { Geometry2d } from './Geometry2d' /** @public */ export class Edge2d extends Geometry2d { - start: Vec2d - end: Vec2d - d: Vec2d - u: Vec2d + start: Vec + end: Vec + d: Vec + u: Vec ul: number - constructor(config: { start: Vec2d; end: Vec2d; isSnappable?: boolean }) { + constructor(config: { start: Vec; end: Vec; isSnappable?: boolean }) { super({ ...config, isClosed: false, isFilled: false }) const { start, end } = config @@ -32,28 +32,28 @@ export class Edge2d extends Geometry2d { return this._length } - midPoint(): Vec2d { + midPoint(): Vec { return this.start.lrp(this.end, 0.5) } - override getVertices(): Vec2d[] { + override getVertices(): Vec[] { return [this.start, this.end] } - override nearestPoint(point: Vec2d): Vec2d { + override nearestPoint(point: Vec): Vec { const { start, end, u, ul: l } = this if (l === 0) return start // no length in the unit vector - const k = Vec2d.Sub(point, start).dpr(u) / l + const k = Vec.Sub(point, start).dpr(u) / l const cx = start.x + u.x * k if (cx < Math.min(start.x, end.x)) return start.x < end.x ? start : end if (cx > Math.max(start.x, end.x)) return start.x > end.x ? start : end const cy = start.y + u.y * k if (cy < Math.min(start.y, end.y)) return start.y < end.y ? start : end if (cy > Math.max(start.y, end.y)) return start.y > end.y ? start : end - return new Vec2d(cx, cy) + return new Vec(cx, cy) } - override hitTestLineSegment(A: Vec2d, B: Vec2d, _zoom: number): boolean { + override hitTestLineSegment(A: Vec, B: Vec, _zoom: number): boolean { return linesIntersect(A, B, this.start, this.end) } } diff --git a/packages/editor/src/lib/primitives/geometry/Ellipse2d.ts b/packages/editor/src/lib/primitives/geometry/Ellipse2d.ts index 5084adc2e..d15b864af 100644 --- a/packages/editor/src/lib/primitives/geometry/Ellipse2d.ts +++ b/packages/editor/src/lib/primitives/geometry/Ellipse2d.ts @@ -1,5 +1,5 @@ -import { Box2d } from '../Box2d' -import { Vec2d } from '../Vec2d' +import { Box } from '../Box' +import { Vec } from '../Vec' import { PI, PI2 } from '../utils' import { Edge2d } from './Edge2d' import { Geometry2d, Geometry2dOptions } from './Geometry2d' @@ -63,7 +63,7 @@ export class Ellipse2d extends Geometry2d { const vertices = Array(len) for (let i = 0; i < len; i++) { - vertices[i] = new Vec2d(cx + cx * cos, cy + cy * sin) + vertices[i] = new Vec(cx + cx * cos, cy + cy * sin) ts = b * cos + a * sin tc = a * cos - b * sin sin = ts @@ -73,8 +73,8 @@ export class Ellipse2d extends Geometry2d { return vertices } - nearestPoint(A: Vec2d): Vec2d { - let nearest: Vec2d | undefined + nearestPoint(A: Vec): Vec { + let nearest: Vec | undefined let dist = Infinity for (const edge of this.edges) { const p = edge.nearestPoint(A) @@ -89,11 +89,11 @@ export class Ellipse2d extends Geometry2d { return nearest } - hitTestLineSegment(A: Vec2d, B: Vec2d, zoom: number): boolean { + hitTestLineSegment(A: Vec, B: Vec, zoom: number): boolean { return this.edges.some((edge) => edge.hitTestLineSegment(A, B, zoom)) } getBounds() { - return new Box2d(0, 0, this.w, this.h) + return new Box(0, 0, this.w, this.h) } } diff --git a/packages/editor/src/lib/primitives/geometry/Geometry2d.ts b/packages/editor/src/lib/primitives/geometry/Geometry2d.ts index a8c7322e8..ae87bea3b 100644 --- a/packages/editor/src/lib/primitives/geometry/Geometry2d.ts +++ b/packages/editor/src/lib/primitives/geometry/Geometry2d.ts @@ -1,5 +1,5 @@ -import { Box2d } from '../Box2d' -import { Vec2d } from '../Vec2d' +import { Box } from '../Box' +import { Vec } from '../Vec' import { pointInPolygon } from '../utils' export interface Geometry2dOptions { @@ -23,16 +23,16 @@ export abstract class Geometry2d { this.isLabel = opts.isLabel ?? false } - abstract getVertices(): Vec2d[] + abstract getVertices(): Vec[] - abstract nearestPoint(point: Vec2d): Vec2d + abstract nearestPoint(point: Vec): Vec - hitTestPoint(point: Vec2d, margin = 0, hitInside = false) { + hitTestPoint(point: Vec, margin = 0, hitInside = false) { // We've removed the broad phase here; that should be done outside of the call return this.distanceToPoint(point, hitInside) <= margin } - distanceToPoint(point: Vec2d, hitInside = false) { + distanceToPoint(point: Vec, hitInside = false) { const dist = point.dist(this.nearestPoint(point)) if (this.isClosed && (this.isFilled || hitInside) && pointInPolygon(point, this.vertices)) { @@ -41,22 +41,22 @@ export abstract class Geometry2d { return dist } - distanceToLineSegment(A: Vec2d, B: Vec2d) { + distanceToLineSegment(A: Vec, B: Vec) { const point = this.nearestPointOnLineSegment(A, B) - const dist = Vec2d.DistanceToLineSegment(A, B, point) // repeated, bleh + const dist = Vec.DistanceToLineSegment(A, B, point) // repeated, bleh return this.isClosed && this.isFilled && pointInPolygon(point, this.vertices) ? -dist : dist } - hitTestLineSegment(A: Vec2d, B: Vec2d, distance = 0): boolean { + hitTestLineSegment(A: Vec, B: Vec, distance = 0): boolean { return this.distanceToLineSegment(A, B) <= distance } - nearestPointOnLineSegment(A: Vec2d, B: Vec2d): Vec2d { + nearestPointOnLineSegment(A: Vec, B: Vec): Vec { let distance = Infinity - let nearest: Vec2d | undefined + let nearest: Vec | undefined for (let i = 0; i < this.vertices.length; i++) { const point = this.vertices[i] - const d = Vec2d.DistanceToLineSegment(A, B, point) + const d = Vec.DistanceToLineSegment(A, B, point) if (d < distance) { distance = d nearest = point @@ -66,7 +66,7 @@ export abstract class Geometry2d { return nearest } - isPointInBounds(point: Vec2d, margin = 0) { + isPointInBounds(point: Vec, margin = 0) { const { bounds } = this return !( point.x < bounds.minX - margin || @@ -76,10 +76,10 @@ export abstract class Geometry2d { ) } - _vertices: Vec2d[] | undefined + _vertices: Vec[] | undefined // eslint-disable-next-line no-restricted-syntax - get vertices(): Vec2d[] { + get vertices(): Vec[] { if (!this._vertices) { this._vertices = this.getVertices() } @@ -88,20 +88,20 @@ export abstract class Geometry2d { } getBounds() { - return Box2d.FromPoints(this.vertices) + return Box.FromPoints(this.vertices) } - _bounds: Box2d | undefined + _bounds: Box | undefined // eslint-disable-next-line no-restricted-syntax - get bounds(): Box2d { + get bounds(): Box { if (!this._bounds) { this._bounds = this.getBounds() } return this._bounds } - _snapPoints: Vec2d[] | undefined + _snapPoints: Vec[] | undefined // eslint-disable-next-line no-restricted-syntax get snapPoints() { diff --git a/packages/editor/src/lib/primitives/geometry/Group2d.ts b/packages/editor/src/lib/primitives/geometry/Group2d.ts index 7d7600605..298373e05 100644 --- a/packages/editor/src/lib/primitives/geometry/Group2d.ts +++ b/packages/editor/src/lib/primitives/geometry/Group2d.ts @@ -1,5 +1,5 @@ -import { Box2d } from '../Box2d' -import { Vec2d } from '../Vec2d' +import { Box } from '../Box' +import { Vec } from '../Vec' import { Geometry2d, Geometry2dOptions } from './Geometry2d' /** @public */ @@ -19,13 +19,13 @@ export class Group2d extends Geometry2d { this.children = children } - override getVertices(): Vec2d[] { + override getVertices(): Vec[] { return this.children.filter((c) => !c.isLabel).flatMap((c) => c.vertices) } - override nearestPoint(point: Vec2d): Vec2d { + override nearestPoint(point: Vec): Vec { let d = Infinity - let p: Vec2d | undefined + let p: Vec | undefined const { children } = this @@ -45,17 +45,17 @@ export class Group2d extends Geometry2d { return p } - override distanceToPoint(point: Vec2d, hitInside = false) { + override distanceToPoint(point: Vec, hitInside = false) { return Math.min(...this.children.map((c, i) => c.distanceToPoint(point, hitInside || i > 0))) } - override hitTestPoint(point: Vec2d, margin: number, hitInside: boolean): boolean { + override hitTestPoint(point: Vec, margin: number, hitInside: boolean): boolean { return !!this.children .filter((c) => !c.isLabel) .find((c) => c.hitTestPoint(point, margin, hitInside)) } - override hitTestLineSegment(A: Vec2d, B: Vec2d, zoom: number): boolean { + override hitTestLineSegment(A: Vec, B: Vec, zoom: number): boolean { return !!this.children.filter((c) => !c.isLabel).find((c) => c.hitTestLineSegment(A, B, zoom)) } @@ -70,7 +70,7 @@ export class Group2d extends Geometry2d { path += child.toSimpleSvgPath() } - const corners = Box2d.FromPoints(this.vertices).corners + const corners = Box.FromPoints(this.vertices).corners // draw just a few pixels around each corner, e.g. an L shape for the bottom left for (let i = 0, n = corners.length; i < n; i++) { diff --git a/packages/editor/src/lib/primitives/geometry/Point2d.ts b/packages/editor/src/lib/primitives/geometry/Point2d.ts index 556da3866..e03bccbea 100644 --- a/packages/editor/src/lib/primitives/geometry/Point2d.ts +++ b/packages/editor/src/lib/primitives/geometry/Point2d.ts @@ -1,12 +1,12 @@ -import { Vec2d } from '../Vec2d' +import { Vec } from '../Vec' import { Geometry2d, Geometry2dOptions } from './Geometry2d' /** @public */ export class Point2d extends Geometry2d { - point: Vec2d + point: Vec constructor( - config: Omit & { margin: number; point: Vec2d } + config: Omit & { margin: number; point: Vec } ) { super({ ...config, isClosed: true, isFilled: true }) const { point } = config @@ -18,11 +18,11 @@ export class Point2d extends Geometry2d { return [this.point] } - nearestPoint(): Vec2d { + nearestPoint(): Vec { return this.point } - hitTestLineSegment(A: Vec2d, B: Vec2d, margin: number): boolean { - return Vec2d.DistanceToLineSegment(A, B, this.point) < margin + hitTestLineSegment(A: Vec, B: Vec, margin: number): boolean { + return Vec.DistanceToLineSegment(A, B, this.point) < margin } } diff --git a/packages/editor/src/lib/primitives/geometry/Polygon2d.ts b/packages/editor/src/lib/primitives/geometry/Polygon2d.ts index 7f3c505e6..85265885d 100644 --- a/packages/editor/src/lib/primitives/geometry/Polygon2d.ts +++ b/packages/editor/src/lib/primitives/geometry/Polygon2d.ts @@ -1,10 +1,10 @@ -import { Vec2d } from '../Vec2d' +import { Vec } from '../Vec' import { Geometry2dOptions } from './Geometry2d' import { Polyline2d } from './Polyline2d' /** @public */ export class Polygon2d extends Polyline2d { - constructor(config: Omit & { points: Vec2d[] }) { + constructor(config: Omit & { points: Vec[] }) { super({ ...config }) this.isClosed = true } diff --git a/packages/editor/src/lib/primitives/geometry/Polyline2d.ts b/packages/editor/src/lib/primitives/geometry/Polyline2d.ts index b2f6cb492..ffa541cb2 100644 --- a/packages/editor/src/lib/primitives/geometry/Polyline2d.ts +++ b/packages/editor/src/lib/primitives/geometry/Polyline2d.ts @@ -1,12 +1,12 @@ -import { Vec2d } from '../Vec2d' +import { Vec } from '../Vec' import { Edge2d } from './Edge2d' import { Geometry2d, Geometry2dOptions } from './Geometry2d' /** @public */ export class Polyline2d extends Geometry2d { - points: Vec2d[] + points: Vec[] - constructor(config: Omit & { points: Vec2d[] }) { + constructor(config: Omit & { points: Vec[] }) { super({ isClosed: false, isFilled: false, ...config }) const { points } = config this.points = points @@ -47,12 +47,12 @@ export class Polyline2d extends Geometry2d { return this.points } - nearestPoint(A: Vec2d): Vec2d { + nearestPoint(A: Vec): Vec { const { segments } = this let nearest = this.points[0] let dist = Infinity - let p: Vec2d // current point on segment + let p: Vec // current point on segment let d: number // distance from A to p for (let i = 0; i < segments.length; i++) { p = segments[i].nearestPoint(A) @@ -66,7 +66,7 @@ export class Polyline2d extends Geometry2d { return nearest } - hitTestLineSegment(A: Vec2d, B: Vec2d, zoom: number): boolean { + hitTestLineSegment(A: Vec, B: Vec, zoom: number): boolean { return this.segments.some((edge) => edge.hitTestLineSegment(A, B, zoom)) } } diff --git a/packages/editor/src/lib/primitives/geometry/Rectangle2d.ts b/packages/editor/src/lib/primitives/geometry/Rectangle2d.ts index a5c630753..e5c7b1de3 100644 --- a/packages/editor/src/lib/primitives/geometry/Rectangle2d.ts +++ b/packages/editor/src/lib/primitives/geometry/Rectangle2d.ts @@ -1,5 +1,5 @@ -import { Box2d } from '../Box2d' -import { Vec2d } from '../Vec2d' +import { Box } from '../Box' +import { Vec } from '../Vec' import { Geometry2dOptions } from './Geometry2d' import { Polygon2d } from './Polygon2d' @@ -22,10 +22,10 @@ export class Rectangle2d extends Polygon2d { super({ ...config, points: [ - new Vec2d(x, y), - new Vec2d(x + width, y), - new Vec2d(x + width, y + height), - new Vec2d(x, y + height), + new Vec(x, y), + new Vec(x + width, y), + new Vec(x + width, y + height), + new Vec(x, y + height), ], }) this.x = x @@ -35,6 +35,6 @@ export class Rectangle2d extends Polygon2d { } getBounds() { - return new Box2d(this.x, this.y, this.w, this.h) + return new Box(this.x, this.y, this.w, this.h) } } diff --git a/packages/editor/src/lib/primitives/geometry/Stadium2d.ts b/packages/editor/src/lib/primitives/geometry/Stadium2d.ts index b973daa8c..af216cd8a 100644 --- a/packages/editor/src/lib/primitives/geometry/Stadium2d.ts +++ b/packages/editor/src/lib/primitives/geometry/Stadium2d.ts @@ -1,5 +1,5 @@ -import { Vec2d } from '../Vec2d' -import { PI, TAU } from '../utils' +import { Vec } from '../Vec' +import { HALF_PI, PI } from '../utils' import { Ellipse2d } from './Ellipse2d' import { Geometry2dOptions } from './Geometry2d' @@ -19,21 +19,21 @@ export class Stadium2d extends Ellipse2d { const cy = h / 2 const len = 10 - const points: Vec2d[] = Array(len * 2 - 2) + const points: Vec[] = Array(len * 2 - 2) if (h > w) { for (let i = 0; i < len - 1; i++) { const t1 = -PI + (PI * i) / (len - 2) const t2 = (PI * i) / (len - 2) - points[i] = new Vec2d(cx + cx * Math.cos(t1), cx + cx * Math.sin(t1)) - points[i + (len - 1)] = new Vec2d(cx + cx * Math.cos(t2), h - cx + cx * Math.sin(t2)) + points[i] = new Vec(cx + cx * Math.cos(t1), cx + cx * Math.sin(t1)) + points[i + (len - 1)] = new Vec(cx + cx * Math.cos(t2), h - cx + cx * Math.sin(t2)) } } else { for (let i = 0; i < len - 1; i++) { - const t1 = -TAU + (PI * i) / (len - 2) - const t2 = TAU + (PI * -i) / (len - 2) - points[i] = new Vec2d(w - cy + cy * Math.cos(t1), h - cy + cy * Math.sin(t1)) - points[i + (len - 1)] = new Vec2d(cy - cy * Math.cos(t2), h - cy + cy * Math.sin(t2)) + const t1 = -HALF_PI + (PI * i) / (len - 2) + const t2 = HALF_PI + (PI * -i) / (len - 2) + points[i] = new Vec(w - cy + cy * Math.cos(t1), h - cy + cy * Math.sin(t1)) + points[i + (len - 1)] = new Vec(cy - cy * Math.cos(t2), h - cy + cy * Math.sin(t2)) } } diff --git a/packages/editor/src/lib/primitives/geometry/geometry-constants.ts b/packages/editor/src/lib/primitives/geometry/geometry-constants.ts index 296d7c4b4..113715050 100644 --- a/packages/editor/src/lib/primitives/geometry/geometry-constants.ts +++ b/packages/editor/src/lib/primitives/geometry/geometry-constants.ts @@ -1,5 +1,5 @@ -export const SPACING = 20 -export const MIN_COUNT = 8 +const SPACING = 20 +const MIN_COUNT = 8 export function getVerticesCountForLength(length: number, spacing = SPACING) { return Math.max(MIN_COUNT, Math.ceil(length / spacing)) diff --git a/packages/editor/src/lib/primitives/intersect.ts b/packages/editor/src/lib/primitives/intersect.ts index 4e7ce510a..9d27236b3 100644 --- a/packages/editor/src/lib/primitives/intersect.ts +++ b/packages/editor/src/lib/primitives/intersect.ts @@ -1,6 +1,6 @@ -import { Box2d } from './Box2d' +import { Box } from './Box' import { pointInPolygon } from './utils' -import { Vec2d, VecLike } from './Vec2d' +import { Vec, VecLike } from './Vec' // need even more intersections? See https://gist.github.com/steveruizok/35c02d526c707003a5c79761bfb89a52 @@ -37,7 +37,7 @@ export function intersectLineSegmentLineSegment( const ua = ua_t / u_b const ub = ub_t / u_b if (0 <= ua && ua <= 1 && 0 <= ub && ub <= 1) { - return Vec2d.AddXY(a1, ua * AVx, ua * AVy) + return Vec.AddXY(a1, ua * AVx, ua * AVy) } } @@ -76,8 +76,8 @@ export function intersectLineSegmentCircle(a1: VecLike, a2: VecLike, c: VecLike, const result: VecLike[] = [] - if (0 <= u1 && u1 <= 1) result.push(Vec2d.Lrp(a1, a2, u1)) - if (0 <= u2 && u2 <= 1) result.push(Vec2d.Lrp(a1, a2, u2)) + if (0 <= u1 && u1 <= 1) result.push(Vec.Lrp(a1, a2, u1)) + if (0 <= u2 && u2 <= 1) result.push(Vec.Lrp(a1, a2, u2)) if (result.length === 0) return null // no intersection @@ -151,8 +151,8 @@ export function intersectCircleCircle(c1: VecLike, r1: number, c2: VecLike, r2: dx /= d dy /= d return [ - new Vec2d(c1.x + dx * x - dy * y, c1.y + dy * x + dx * y), - new Vec2d(c1.x + dx * x + dy * y, c1.y + dy * x - dx * y), + new Vec(c1.x + dx * x - dy * y, c1.y + dy * x + dx * y), + new Vec(c1.x + dx * x + dy * y, c1.y + dy * x - dx * y), ] } @@ -209,7 +209,7 @@ export function intersectCirclePolyline(c: VecLike, r: number, points: VecLike[] * * @public */ -export function intersectPolygonBounds(points: VecLike[], bounds: Box2d) { +export function intersectPolygonBounds(points: VecLike[], bounds: Box) { const result: VecLike[] = [] let segmentIntersection: VecLike[] | null @@ -285,8 +285,8 @@ export function intersectPolygonPolygon( } function orderClockwise(points: VecLike[]): VecLike[] { - const C = Vec2d.Average(points) - return points.sort((A, B) => Vec2d.Angle(C, A) - Vec2d.Angle(C, B)) + const C = Vec.Average(points) + return points.sort((A, B) => Vec.Angle(C, A) - Vec.Angle(C, B)) } /** @public */ diff --git a/packages/editor/src/lib/primitives/utils.ts b/packages/editor/src/lib/primitives/utils.ts index edca4f634..c95f7e827 100644 --- a/packages/editor/src/lib/primitives/utils.ts +++ b/packages/editor/src/lib/primitives/utils.ts @@ -1,5 +1,4 @@ -import { Box2d } from './Box2d' -import { Vec2d, VecLike } from './Vec2d' +import { Vec, VecLike } from './Vec' /** @public */ export function precise(A: VecLike) { @@ -14,12 +13,10 @@ export function average(A: VecLike, B: VecLike) { /** @public */ export const PI = Math.PI /** @public */ -export const TAU = PI / 2 +export const HALF_PI = PI / 2 /** @public */ export const PI2 = PI * 2 /** @public */ -export const EPSILON = Math.PI / 180 -/** @public */ export const SIN = Math.sin /** @@ -148,52 +145,6 @@ export function shortAngleDist(a0: number, a1: number): number { return ((2 * da) % PI2) - da } -/** - * Get the long angle distance between two angles. - * - * @param a0 - The first angle. - * @param a1 - The second angle. - * @public - */ -export function longAngleDist(a0: number, a1: number): number { - return PI2 - shortAngleDist(a0, a1) -} - -/** - * Interpolate an angle between two angles. - * - * @param a0 - The first angle. - * @param a1 - The second angle. - * @param t - The interpolation value. - * @public - */ -export function lerpAngles(a0: number, a1: number, t: number): number { - return a0 + shortAngleDist(a0, a1) * t -} - -/** - * Get the short distance between two angles. - * - * @param a0 - The first angle. - * @param a1 - The second angle. - * @public - */ -export function angleDelta(a0: number, a1: number): number { - return shortAngleDist(a0, a1) -} - -/** - * Get the "sweep" or short distance between two points on a circle's perimeter. - * - * @param C - The center of the circle. - * @param A - The first point. - * @param B - The second point. - * @public - */ -export function getSweep(C: VecLike, A: VecLike, B: VecLike): number { - return angleDelta(Vec2d.Angle(C, A), Vec2d.Angle(C, B)) -} - /** * Clamp radians within 0 and 2PI * @@ -231,38 +182,6 @@ export function areAnglesCompatible(a: number, b: number) { return a === b || approximately((a % (Math.PI / 2)) - (b % (Math.PI / 2)), 0) } -/** - * Is angle c between angles a and b? - * - * @param a - The first angle. - * @param b - The second angle. - * @param c - The third angle. - * @public - */ -export function isAngleBetween(a: number, b: number, c: number): boolean { - // Normalize the angles to ensure they're in the same domain - a = canonicalizeRotation(a) - b = canonicalizeRotation(b) - c = canonicalizeRotation(c) - - // Compute vectors corresponding to angles a and b - const ax = Math.cos(a) - const ay = Math.sin(a) - const bx = Math.cos(b) - const by = Math.sin(b) - - // Compute the vector corresponding to angle c - const cx = Math.cos(c) - const cy = Math.sin(c) - - // Calculate dot products - const dotAc = ax * cx + ay * cy - const dotBc = bx * cx + by * cy - - // If angle c is between a and b, both dot products should be >= 0 - return dotAc >= 0 && dotBc >= 0 -} - /** * Convert degrees to radians. * @@ -283,20 +202,6 @@ export function radiansToDegrees(r: number): number { return (r * 180) / PI } -/** - * Get the length of an arc between two points on a circle's perimeter. - * - * @param C - The circle's center as [x, y]. - * @param r - The circle's radius. - * @param A - The first point. - * @param B - The second point. - * @public - */ -export function getArcLength(C: VecLike, r: number, A: VecLike, B: VecLike): number { - const sweep = getSweep(C, A, B) - return r * PI2 * (sweep / PI2) -} - /** * Get a point on the perimeter of a circle. * @@ -307,13 +212,13 @@ export function getArcLength(C: VecLike, r: number, A: VecLike, B: VecLike): num * @public */ export function getPointOnCircle(cx: number, cy: number, r: number, a: number) { - return new Vec2d(cx + r * Math.cos(a), cy + r * Math.sin(a)) + return new Vec(cx + r * Math.cos(a), cy + r * Math.sin(a)) } /** @public */ export function getPolygonVertices(width: number, height: number, sides: number) { const cx = width / 2 const cy = height / 2 - const pointsOnPerimeter: Vec2d[] = [] + const pointsOnPerimeter: Vec[] = [] let minX = Infinity let maxX = -Infinity @@ -321,14 +226,14 @@ export function getPolygonVertices(width: number, height: number, sides: number) let maxY = -Infinity for (let i = 0; i < sides; i++) { const step = PI2 / sides - const t = -TAU + i * step + const t = -HALF_PI + i * step const x = cx + cx * Math.cos(t) const y = cy + cy * Math.sin(t) if (x < minX) minX = x if (y < minY) minY = y if (x > maxX) maxX = x if (y > maxY) maxY = y - pointsOnPerimeter.push(new Vec2d(x, y)) + pointsOnPerimeter.push(new Vec(x, y)) } // Bounds of calculated points @@ -387,91 +292,11 @@ export function rangeIntersection( return null } -/** - * Gets the width/height of a star given its input bounds. - * - * @param sides - Number of sides - * @param w - T target width - * @param h - Target height - * @returns Box2d - * @public - */ -export const getStarBounds = (sides: number, w: number, h: number): Box2d => { - const step = PI2 / sides / 2 - const rightMostIndex = Math.floor(sides / 4) * 2 - const leftMostIndex = sides * 2 - rightMostIndex - const topMostIndex = 0 - const bottomMostIndex = Math.floor(sides / 2) * 2 - const maxX = (Math.cos(-TAU + rightMostIndex * step) * w) / 2 - const minX = (Math.cos(-TAU + leftMostIndex * step) * w) / 2 - const minY = (Math.sin(-TAU + topMostIndex * step) * h) / 2 - const maxY = (Math.sin(-TAU + bottomMostIndex * step) * h) / 2 - return new Box2d(0, 0, maxX - minX, maxY - minY) -} - /** Helper for point in polygon */ function cross(x: VecLike, y: VecLike, z: VecLike): number { return (y.x - x.x) * (z.y - x.y) - (z.x - x.x) * (y.y - x.y) } -/** - * Utils for working with points. - * - * @public - */ -/** - * Get whether a point is inside of a circle. - * - * @param A - The point to check. - * @param C - The circle's center point as [x, y]. - * @param r - The circle's radius. - * @returns Boolean - * @public - */ -export function pointInCircle(A: VecLike, C: VecLike, r: number): boolean { - return Vec2d.Dist(A, C) <= r -} - -/** - * Get whether a point is inside of an ellipse. - * - * @param point - The point to check. - * @param center - The ellipse's center point as [x, y]. - * @param rx - The ellipse's x radius. - * @param ry - The ellipse's y radius. - * @param rotation - The ellipse's rotation. - * @returns Boolean - * @public - */ -export function pointInEllipse( - A: VecLike, - C: VecLike, - rx: number, - ry: number, - rotation = 0 -): boolean { - rotation = rotation || 0 - const cos = Math.cos(rotation) - const sin = Math.sin(rotation) - const delta = Vec2d.Sub(A, C) - const tdx = cos * delta.x + sin * delta.y - const tdy = sin * delta.x - cos * delta.y - - return (tdx * tdx) / (rx * rx) + (tdy * tdy) / (ry * ry) <= 1 -} - -/** - * Get whether a point is inside of a rectangle. - * - * @param A - The point to check. - * @param point - The rectangle's top left point as [x, y]. - * @param size - The rectangle's size as [width, height]. - * @public - */ -export function pointInRect(A: VecLike, point: VecLike, size: VecLike): boolean { - return !(A.x < point.x || A.x > point.x + size.x || A.y < point.y || A.y > point.y + size.y) -} - /** * Get whether a point is inside of a polygon. * @@ -502,245 +327,6 @@ export function pointInPolygon(A: VecLike, points: VecLike[]): boolean { return windingNumber !== 0 } -/** - * Get whether a point is inside of a bounds. - * - * @param A - The point to check. - * @param b - The bounds to check. - * @returns Boolean - * @public - */ -export function pointInBounds(A: VecLike, b: Box2d): boolean { - return !(A.x < b.minX || A.x > b.maxX || A.y < b.minY || A.y > b.maxY) -} - -/** - * Hit test a point and a polyline using a minimum distance. - * - * @param A - The point to check. - * @param points - The points that make up the polyline. - * @param distance - The mininum distance that qualifies a hit. - * @returns Boolean - * @public - */ -export function pointInPolyline(A: VecLike, points: VecLike[], distance = 3): boolean { - for (let i = 1; i < points.length; i++) { - if (Vec2d.DistanceToLineSegment(points[i - 1], points[i], A) < distance) { - return true - } - } - return false -} - -/** - * Get whether a point is within a certain distance from a polyline. - * - * @param A - The point to check. - * @param points - The points that make up the polyline. - * @param distance - The mininum distance that qualifies a hit. - * @public - */ -export function pointNearToPolyline(A: VecLike, points: VecLike[], distance = 8) { - const len = points.length - for (let i = 1; i < len; i++) { - const p1 = points[i - 1] - const p2 = points[i] - const d = Vec2d.DistanceToLineSegment(p1, p2, A) - if (d < distance) return true - } - return false -} - -/** - * Get whether a point is within a certain distance from a line segment. - * - * @param A - The point to check. - * @param p1 - The polyline's first point. - * @param p2 - The polyline's second point. - * @param distance - The mininum distance that qualifies a hit. - * @public - */ -export function pointNearToLineSegment(A: VecLike, p1: VecLike, p2: VecLike, distance = 8) { - const d = Vec2d.DistanceToLineSegment(p1, p2, A) - if (d < distance) return true - return false -} - -/** - * Simplify a line (using Ramer-Douglas-Peucker algorithm). - * - * @param points - An array of points as [x, y, ...][] - * @param tolerance - The minimum line distance (also called epsilon). - * @returns Simplified array as [x, y, ...][] - * @public - */ -export function simplify(points: VecLike[], tolerance = 1): VecLike[] { - const len = points.length - const a = points[0] - const b = points[len - 1] - const { x: x1, y: y1 } = a - const { x: x2, y: y2 } = b - if (len > 2) { - let distance = 0 - let index = 0 - const max = new Vec2d(y2 - y1, x2 - x1).len2() - for (let i = 1; i < len - 1; i++) { - const { x: x0, y: y0 } = points[i] - const d = Math.pow(x0 * (y2 - y1) + x1 * (y0 - y2) + x2 * (y1 - y0), 2) / max - if (distance > d) continue - distance = d - index = i - } - if (distance > tolerance) { - const l0 = simplify(points.slice(0, index + 1), tolerance) - const l1 = simplify(points.slice(index + 1), tolerance) - return l0.concat(l1.slice(1)) - } - } - return [a, b] -} - -function _getSqSegDist(p: VecLike, p1: VecLike, p2: VecLike) { - let x = p1.x - let y = p1.y - let dx = p2.x - x - let dy = p2.y - y - if (dx !== 0 || dy !== 0) { - const t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy) - if (t > 1) { - x = p2.x - y = p2.y - } else if (t > 0) { - x += dx * t - y += dy * t - } - } - dx = p.x - x - dy = p.y - y - return dx * dx + dy * dy -} - -function _simplifyStep( - points: VecLike[], - first: number, - last: number, - sqTolerance: number, - result: VecLike[] -) { - let maxSqDist = sqTolerance - let index = -1 - for (let i = first + 1; i < last; i++) { - const sqDist = _getSqSegDist(points[i], points[first], points[last]) - if (sqDist > maxSqDist) { - index = i - maxSqDist = sqDist - } - } - if (index > -1 && maxSqDist > sqTolerance) { - if (index - first > 1) _simplifyStep(points, first, index, sqTolerance, result) - result.push(points[index]) - if (last - index > 1) _simplifyStep(points, index, last, sqTolerance, result) - } -} - -/** @public */ -export function simplify2(points: VecLike[], tolerance = 1) { - if (points.length <= 2) return points - const sqTolerance = tolerance * tolerance - // Radial distance - let A = points[0] - let B = points[1] - const newPoints = [A] - for (let i = 1, len = points.length; i < len; i++) { - B = points[i] - if ((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y) > sqTolerance) { - newPoints.push(B) - A = B - } - } - if (A !== B) newPoints.push(B) - // Ramer-Douglas-Peucker - const last = newPoints.length - 1 - const result = [newPoints[0]] - _simplifyStep(newPoints, 0, last, sqTolerance, result) - result.push(newPoints[last], points[points.length - 1]) - return result -} - -/** @public */ -export function getMinX(pts: VecLike[]) { - let top = pts[0] - for (let i = 1; i < pts.length; i++) { - if (pts[i].x < top.x) { - top = pts[i] - } - } - return top.x -} - -/** @public */ -export function getMinY(pts: VecLike[]) { - let top = pts[0] - for (let i = 1; i < pts.length; i++) { - if (pts[i].y < top.y) { - top = pts[i] - } - } - return top.y -} - -/** @public */ -export function getMaxX(pts: VecLike[]) { - let top = pts[0] - for (let i = 1; i < pts.length; i++) { - if (pts[i].x > top.x) { - top = pts[i] - } - } - return top.x -} - -/** @public */ -export function getMaxY(pts: VecLike[]) { - let top = pts[0] - for (let i = 1; i < pts.length; i++) { - if (pts[i].y > top.y) { - top = pts[i] - } - } - return top.y -} - -/** @public */ -export function getMidX(pts: VecLike[]) { - const a = getMinX(pts) - const b = getMaxX(pts) - - return a + (b - a) / 2 -} - -/** @public */ -export function getMidY(pts: VecLike[]) { - const a = getMinY(pts) - const b = getMaxY(pts) - - return a + (b - a) / 2 -} - -/** @public */ -export function getWidth(pts: VecLike[]) { - const a = getMinX(pts) - const b = getMaxX(pts) - return b - a -} - -/** @public */ -export function getHeight(pts: VecLike[]) { - const a = getMinY(pts) - const b = getMaxY(pts) - return b - a -} - /** * The DOM likes values to be fixed to 3 decimal places * diff --git a/packages/editor/src/lib/utils/debug-flags.ts b/packages/editor/src/lib/utils/debug-flags.ts index 4fda95aff..7fb004c31 100644 --- a/packages/editor/src/lib/utils/debug-flags.ts +++ b/packages/editor/src/lib/utils/debug-flags.ts @@ -202,8 +202,7 @@ interface Defaults { all: T } -/** @internal */ -export interface DebugFlagDef { +interface DebugFlagDef { name: string defaults: Defaults shouldStoreForSession: boolean diff --git a/packages/editor/src/lib/utils/edgeScrolling.ts b/packages/editor/src/lib/utils/edgeScrolling.ts index 02a978eae..058393ccc 100644 --- a/packages/editor/src/lib/utils/edgeScrolling.ts +++ b/packages/editor/src/lib/utils/edgeScrolling.ts @@ -7,7 +7,7 @@ import { Editor } from '../editor/Editor' * @param dimension - The component dimension on the axis. * @internal */ -export function getEdgeProximityFactor(position: number, dimension: number) { +function getEdgeProximityFactor(position: number, dimension: number) { if (position < 0) { return 1 } else if (position > dimension) { diff --git a/packages/editor/src/lib/utils/getSvgPathFromPoints.ts b/packages/editor/src/lib/utils/getSvgPathFromPoints.ts index d7a60a264..1d4111adf 100644 --- a/packages/editor/src/lib/utils/getSvgPathFromPoints.ts +++ b/packages/editor/src/lib/utils/getSvgPathFromPoints.ts @@ -1,4 +1,4 @@ -import { VecLike } from '../primitives/Vec2d' +import { VecLike } from '../primitives/Vec' import { average, precise } from '../primitives/utils' /** diff --git a/packages/editor/src/lib/utils/reordering/dgreensp/dgreensp.test.ts b/packages/editor/src/lib/utils/reordering/dgreensp/dgreensp.test.ts index 024e910b9..9d48728b0 100644 --- a/packages/editor/src/lib/utils/reordering/dgreensp/dgreensp.test.ts +++ b/packages/editor/src/lib/utils/reordering/dgreensp/dgreensp.test.ts @@ -1,86 +1,6 @@ -import { - decrementInteger, - generateKeyBetween, - generateNKeysBetween, - incrementInteger, - midpoint, -} from './dgreensp' +import { generateNKeysBetween } from './dgreensp' -describe('midpoint', () => { - it('passes tests', () => { - expect(midpoint('', undefined)).toBe('V') - expect(midpoint('V', undefined)).toBe('l') - expect(midpoint('l', undefined)).toBe('t') - expect(midpoint('t', undefined)).toBe('x') - expect(midpoint('x', undefined)).toBe('z') - expect(midpoint('z', undefined)).toBe('zV') - expect(midpoint('zV', undefined)).toBe('zl') - expect(midpoint('zl', undefined)).toBe('zt') - expect(midpoint('zt', undefined)).toBe('zx') - expect(midpoint('zx', undefined)).toBe('zz') - expect(midpoint('zz', undefined)).toBe('zzV') - expect(midpoint('1', '2')).toBe('1V') - expect(() => midpoint('2', '1')).toThrowError() - expect(() => midpoint('', '')).toThrowError() - expect(() => midpoint('0', '1')).toThrowError() - expect(() => midpoint('1', '10')).toThrowError() - expect(() => midpoint('11', '1')).toThrowError() - expect(midpoint('001', '001002')).toBe('001001') - expect(midpoint('001', '001001')).toBe('001000V') - expect(midpoint('', 'V')).toBe('G') - expect(midpoint('', 'G')).toBe('8') - expect(midpoint('', '8')).toBe('4') - expect(midpoint('', '4')).toBe('2') - expect(midpoint('', '2')).toBe('1') - expect(midpoint('', '1')).toBe('0V') - expect(midpoint('0V', '1')).toBe('0l') - expect(midpoint('', '0G')).toBe('08') - expect(midpoint('', '08')).toBe('04') - expect(midpoint('', '02')).toBe('01') - expect(midpoint('', '01')).toBe('00V') - expect(midpoint('4zz', '5')).toBe('4zzV') - }) -}) - -describe('decrement integer', () => { - it('passes tests', () => { - expect(decrementInteger('a1')).toBe('a0') - expect(decrementInteger('a2')).toBe('a1') - expect(decrementInteger('b00')).toBe('az') - expect(decrementInteger('b10')).toBe('b0z') - expect(decrementInteger('b20')).toBe('b1z') - expect(decrementInteger('c000')).toBe('bzz') - expect(decrementInteger('Zz')).toBe('Zy') - expect(decrementInteger('a0')).toBe('Zz') - expect(decrementInteger('Yzz')).toBe('Yzy') - expect(decrementInteger('Z0')).toBe('Yzz') - expect(decrementInteger('Xz00')).toBe('Xyzz') - expect(decrementInteger('Xz01')).toBe('Xz00') - expect(decrementInteger('Y00')).toBe('Xzzz') - expect(decrementInteger('dAC00')).toBe('dABzz') - expect(decrementInteger('A00000000000000000000000000')).toBe(undefined) - }) -}) - -describe('increment integer', () => { - it('produces the right integer string', () => { - expect(incrementInteger('a0')).toBe('a1') - expect(incrementInteger('a1')).toBe('a2') - expect(incrementInteger('az')).toBe('b00') - expect(incrementInteger('b0z')).toBe('b10') - expect(incrementInteger('b1z')).toBe('b20') - expect(incrementInteger('bzz')).toBe('c000') - expect(incrementInteger('Zy')).toBe('Zz') - expect(incrementInteger('Zz')).toBe('a0') - expect(incrementInteger('Yzy')).toBe('Yzz') - expect(incrementInteger('Yzz')).toBe('Z0') - expect(incrementInteger('Xyzz')).toBe('Xz00') - expect(incrementInteger('Xz00')).toBe('Xz01') - expect(incrementInteger('Xzzz')).toBe('Y00') - expect(incrementInteger('dABzz')).toBe('dAC00') - expect(incrementInteger('zzzzzzzzzzzzzzzzzzzzzzzzzzz')).toBe(undefined) - }) -}) +const generateKeyBetween = (a?: string, b?: string) => generateNKeysBetween(a, b, 1)[0] describe('get order between', () => { it('passes tests', () => { diff --git a/packages/editor/src/lib/utils/reordering/dgreensp/dgreensp.ts b/packages/editor/src/lib/utils/reordering/dgreensp/dgreensp.ts index 10b29bb70..7e913655c 100644 --- a/packages/editor/src/lib/utils/reordering/dgreensp/dgreensp.ts +++ b/packages/editor/src/lib/utils/reordering/dgreensp/dgreensp.ts @@ -10,7 +10,7 @@ const SMALLEST_INTEGER = 'A00000000000000000000000000' * * @param head - The integer to use. */ -export function getIntegerLength(head: string): number { +function getIntegerLength(head: string): number { if (head >= 'a' && head <= 'z') { return head.charCodeAt(0) - 'a'.charCodeAt(0) + 2 } else if (head >= 'A' && head <= 'Z') { @@ -25,13 +25,13 @@ export function getIntegerLength(head: string): number { * * @param int - The integer to use. */ -export function validateInteger(int: string): asserts int is string { +function validateInteger(int: string): asserts int is string { if (int.length !== getIntegerLength(int.charAt(0))) { throw new Error('invalid integer part of index key: ' + int) } } -export function isNotUndefined(n: string | undefined): asserts n is string { +function isNotUndefined(n: string | undefined): asserts n is string { if (n === undefined) throw Error('n is undefined') } @@ -39,8 +39,10 @@ export function isNotUndefined(n: string | undefined): asserts n is string { * Increment an integer. * * @param x - The integer to increment + * + * @internal */ -export function incrementInteger(x: string): string | undefined { +function incrementInteger(x: string): string | undefined { validateInteger(x) const [head, ...digs] = x.split('') let carry = true @@ -72,8 +74,10 @@ export function incrementInteger(x: string): string | undefined { * Decrement an integer. * * @param x - The integer to decrement + * + * @internal */ -export function decrementInteger(x: string): string | undefined { +function decrementInteger(x: string): string | undefined { validateInteger(x) const [head, ...digs] = x.split('') let borrow = true @@ -106,8 +110,10 @@ export function decrementInteger(x: string): string | undefined { * * @param a - The start index. * @param b - The end index. + * + * @internal */ -export function midpoint(a: string, b: string | undefined): string { +function midpoint(a: string, b: string | undefined): string { if (b !== undefined && a >= b) { throw new Error(a + ' >= ' + b) } @@ -142,7 +148,7 @@ export function midpoint(a: string, b: string | undefined): string { * * @param index - The index to use. */ -export function getIntegerPart(index: string): string { +function getIntegerPart(index: string): string { const integerPartLength = getIntegerLength(index.charAt(0)) if (integerPartLength > index.length) { throw new Error('invalid index: ' + index) @@ -155,7 +161,7 @@ export function getIntegerPart(index: string): string { * * @param x - The index to validate. */ -export function validateOrder(index: string): asserts index is string { +function validateOrder(index: string): asserts index is string { if (index === SMALLEST_INTEGER) { throw new Error('invalid index: ' + index) } @@ -173,7 +179,7 @@ export function validateOrder(index: string): asserts index is string { * A string made up of an integer part followed by a fraction part. The fraction point consists of * zero or more digits with no trailing zeros. */ -export type OrderKey = string +type OrderKey = string /** * Generate an index key at the midpoint between a start and end. @@ -181,7 +187,7 @@ export type OrderKey = string * @param a - The start index key string. * @param b - The end index key string, greater than A. */ -export function generateKeyBetween(a: OrderKey | undefined, b: OrderKey | undefined): OrderKey { +function generateKeyBetween(a: OrderKey | undefined, b: OrderKey | undefined): OrderKey { if (a !== undefined) validateOrder(a) if (b !== undefined) validateOrder(b) if (a !== undefined && b !== undefined && a >= b) { @@ -259,21 +265,3 @@ export function generateNKeysBetween( const c = generateKeyBetween(a, b) return [...generateNKeysBetween(a, c, mid), c, ...generateNKeysBetween(c, b, n - mid - 1)] } - -export function getCounter() { - let index = 'a0' - return () => { - index = generateKeyBetween(index, undefined) - return index - } -} - -export function* iterableRange(n = 1) { - let index = 'a0' - let i = 0 - while (i < n) { - i++ - index = generateKeyBetween(index, undefined) - yield index - } -} diff --git a/packages/editor/src/lib/utils/reordering/dgreensp/index.ts b/packages/editor/src/lib/utils/reordering/dgreensp/index.ts deleted file mode 100644 index a31d163bd..000000000 --- a/packages/editor/src/lib/utils/reordering/dgreensp/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { generateKeyBetween, generateNKeysBetween, getCounter } from './dgreensp' -export { getCounter, generateKeyBetween, generateNKeysBetween } diff --git a/packages/editor/src/lib/utils/reordering/reordering.ts b/packages/editor/src/lib/utils/reordering/reordering.ts index 16585ce69..ea523fb92 100644 --- a/packages/editor/src/lib/utils/reordering/reordering.ts +++ b/packages/editor/src/lib/utils/reordering/reordering.ts @@ -1,4 +1,4 @@ -import { generateNKeysBetween } from './dgreensp' +import { generateNKeysBetween } from './dgreensp/dgreensp' /** * Get a number of indices between two indices. diff --git a/packages/editor/src/lib/utils/rotation.ts b/packages/editor/src/lib/utils/rotation.ts index 93c497b75..606fa5cc0 100644 --- a/packages/editor/src/lib/utils/rotation.ts +++ b/packages/editor/src/lib/utils/rotation.ts @@ -1,9 +1,9 @@ import { isShapeId, TLShape, TLShapePartial } from '@tldraw/tlschema' import { structuredClone } from '@tldraw/utils' import { Editor } from '../editor/Editor' -import { Matrix2d } from '../primitives/Matrix2d' +import { Mat } from '../primitives/Mat' import { canonicalizeRotation } from '../primitives/utils' -import { Vec2d } from '../primitives/Vec2d' +import { Vec } from '../primitives/Vec' /** @internal */ export function getRotationSnapshot({ editor }: { editor: Editor }): TLRotationSnapshot | null { @@ -49,12 +49,12 @@ export function getRotationSnapshot({ editor }: { editor: Editor }): TLRotationS * @public **/ export type TLRotationSnapshot = { - selectionPageCenter: Vec2d + selectionPageCenter: Vec initialCursorAngle: number initialSelectionRotation: number shapeSnapshots: { shape: TLShape - initialPagePoint: Vec2d + initialPagePoint: Vec }[] } @@ -79,14 +79,14 @@ export function applyRotationToSnapshotShapes({ const parentTransform = isShapeId(shape.parentId) ? editor.getShapePageTransform(shape.parentId)! - : Matrix2d.Identity() + : Mat.Identity() - const newPagePoint = Vec2d.RotWith(initialPagePoint, selectionPageCenter, delta) + const newPagePoint = Vec.RotWith(initialPagePoint, selectionPageCenter, delta) - const newLocalPoint = Matrix2d.applyToPoint( + const newLocalPoint = Mat.applyToPoint( // use the current parent transform in case it has moved/resized since the start // (e.g. if rotating a shape at the edge of a group) - Matrix2d.Inverse(parentTransform), + Mat.Inverse(parentTransform), newPagePoint ) const newRotation = canonicalizeRotation(shape.rotation + delta) diff --git a/packages/tldraw/api-report.md b/packages/tldraw/api-report.md index 0abc4b3a3..2f9447e1a 100644 --- a/packages/tldraw/api-report.md +++ b/packages/tldraw/api-report.md @@ -9,7 +9,7 @@ import { ArrayOfValidator } from '@tldraw/editor'; import { BaseBoxShapeTool } from '@tldraw/editor'; import { BaseBoxShapeUtil } from '@tldraw/editor'; -import { Box2d } from '@tldraw/editor'; +import { Box } from '@tldraw/editor'; import { Circle2d } from '@tldraw/editor'; import { CubicSpline2d } from '@tldraw/editor'; import { DictValidator } from '@tldraw/editor'; @@ -21,8 +21,8 @@ import { Geometry2d } from '@tldraw/editor'; import { Group2d } from '@tldraw/editor'; import { JsonObject } from '@tldraw/editor'; import { LANGUAGES } from '@tldraw/editor'; -import { Matrix2d } from '@tldraw/editor'; -import { Matrix2dModel } from '@tldraw/editor'; +import { Mat } from '@tldraw/editor'; +import { MatModel } from '@tldraw/editor'; import { MigrationFailureReason } from '@tldraw/editor'; import { Migrations } from '@tldraw/editor'; import { NamedExoticComponent } from 'react'; @@ -107,9 +107,9 @@ import { TLVideoShape } from '@tldraw/editor'; import { UnionValidator } from '@tldraw/editor'; import { UnknownRecord } from '@tldraw/editor'; import { Validator } from '@tldraw/editor'; -import { Vec2d } from '@tldraw/editor'; -import { Vec2dModel } from '@tldraw/editor'; +import { Vec } from '@tldraw/editor'; import { VecLike } from '@tldraw/editor'; +import { VecModel } from '@tldraw/editor'; // @public (undocumented) export class ArrowShapeTool extends StateNode { @@ -177,7 +177,7 @@ export class ArrowShapeUtil extends ShapeUtil { binding: ObjectValidator< { type: "binding"; boundShapeId: TLShapeId; - normalizedAnchor: Vec2dModel; + normalizedAnchor: VecModel; isExact: boolean; isPrecise: boolean; }>; @@ -191,7 +191,7 @@ export class ArrowShapeUtil extends ShapeUtil { binding: ObjectValidator< { type: "binding"; boundShapeId: TLShapeId; - normalizedAnchor: Vec2dModel; + normalizedAnchor: VecModel; isExact: boolean; isPrecise: boolean; }>; @@ -365,7 +365,7 @@ export class DrawShapeUtil extends ShapeUtil { size: EnumStyleProp<"l" | "m" | "s" | "xl">; segments: ArrayOfValidator< { type: "free" | "straight"; - points: Vec2dModel[]; + points: VecModel[]; }>; isComplete: Validator; isClosed: Validator; @@ -774,7 +774,7 @@ export class HighlightShapeUtil extends ShapeUtil { size: EnumStyleProp<"l" | "m" | "s" | "xl">; segments: ArrayOfValidator< { type: "free" | "straight"; - points: Vec2dModel[]; + points: VecModel[]; }>; isComplete: Validator; isPen: Validator; @@ -816,8 +816,8 @@ export class ImageShapeUtil extends BaseBoxShapeUtil { url: Validator; assetId: Validator; crop: Validator< { - topLeft: Vec2dModel; - bottomRight: Vec2dModel; + topLeft: VecModel; + bottomRight: VecModel; } | null>; }; // (undocumented) @@ -889,7 +889,7 @@ export class LineShapeUtil extends ShapeUtil { // (undocumented) getHandles(shape: TLLineShape): TLHandle[]; // (undocumented) - getOutlineSegments(shape: TLLineShape): Vec2d[][]; + getOutlineSegments(shape: TLLineShape): Vec[][]; // (undocumented) hideResizeHandles: () => boolean; // (undocumented) diff --git a/packages/tldraw/api/api.json b/packages/tldraw/api/api.json index a955e9d43..e4aaed3b1 100644 --- a/packages/tldraw/api/api.json +++ b/packages/tldraw/api/api.json @@ -1321,8 +1321,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -1366,8 +1366,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -3601,8 +3601,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -8826,8 +8826,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -9480,8 +9480,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -9489,8 +9489,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -10320,8 +10320,8 @@ }, { "kind": "Reference", - "text": "Vec2d", - "canonicalReference": "@tldraw/editor!Vec2d:class" + "text": "Vec", + "canonicalReference": "@tldraw/editor!Vec:class" }, { "kind": "Content", @@ -15722,7 +15722,7 @@ "text": "export interface TLUiContextMenuProps " } ], - "fileUrlPath": "packages/tldraw/.tsbuild-api/lib/ui/components/ContextMenu.d.ts", + "fileUrlPath": "packages/tldraw/src/lib/ui/components/ContextMenu.tsx", "releaseTag": "Public", "name": "TLUiContextMenuProps", "preserveMemberOrder": false, @@ -15745,7 +15745,6 @@ "text": ";" } ], - "fileUrlPath": "packages/tldraw/src/lib/ui/components/ContextMenu.tsx", "isReadonly": false, "isOptional": false, "releaseTag": "Public", diff --git a/packages/tldraw/src/lib/canvas/TldrawSelectionForeground.tsx b/packages/tldraw/src/lib/canvas/TldrawSelectionForeground.tsx index 634fa3f4c..328bba60d 100644 --- a/packages/tldraw/src/lib/canvas/TldrawSelectionForeground.tsx +++ b/packages/tldraw/src/lib/canvas/TldrawSelectionForeground.tsx @@ -1,5 +1,5 @@ import { - Box2d, + Box, RotateCorner, TLEmbedShape, TLSelectionForegroundComponent, @@ -19,7 +19,7 @@ import { TldrawCropHandles } from './TldrawCropHandles' /** @public */ export const TldrawSelectionForeground: TLSelectionForegroundComponent = track( - function TldrawSelectionForeground({ bounds, rotation }: { bounds: Box2d; rotation: number }) { + function TldrawSelectionForeground({ bounds, rotation }: { bounds: Box; rotation: number }) { const editor = useEditor() const rSvg = useRef(null) diff --git a/packages/tldraw/src/lib/defaultExternalContentHandlers.ts b/packages/tldraw/src/lib/defaultExternalContentHandlers.ts index c5b519f99..6947aba2f 100644 --- a/packages/tldraw/src/lib/defaultExternalContentHandlers.ts +++ b/packages/tldraw/src/lib/defaultExternalContentHandlers.ts @@ -10,7 +10,7 @@ import { TLShapePartial, TLTextShape, TLTextShapeProps, - Vec2d, + Vec, VecLike, compact, createShapeId, @@ -226,7 +226,7 @@ export function registerDefaultExternalContentHandlers( point ?? (editor.inputs.shiftKey ? editor.inputs.currentPagePoint : editor.getViewportPageCenter()) - const pagePoint = new Vec2d(position.x, position.y) + const pagePoint = new Vec(position.x, position.y) const assets: TLAsset[] = [] @@ -404,7 +404,7 @@ export async function createShapesForAssets( ): Promise { if (!assets.length) return [] - const currentPoint = Vec2d.From(position) + const currentPoint = Vec.From(position) const partials: TLShapePartial[] = [] for (const asset of assets) { @@ -489,7 +489,7 @@ function centerSelectionAroundPoint(editor: Editor, position: VecLike) { editor.updateShapes( editor.getSelectedShapes().map((shape) => { const localRotation = editor.getShapeParentTransform(shape).decompose().rotation - const localDelta = Vec2d.Rot(offset, -localRotation) + const localDelta = Vec.Rot(offset, -localRotation) return { id: shape.id, type: shape.type, diff --git a/packages/tldraw/src/lib/shapes/arrow/ArrowShapeTool.test.ts b/packages/tldraw/src/lib/shapes/arrow/ArrowShapeTool.test.ts index 7a8052451..bb1debbad 100644 --- a/packages/tldraw/src/lib/shapes/arrow/ArrowShapeTool.test.ts +++ b/packages/tldraw/src/lib/shapes/arrow/ArrowShapeTool.test.ts @@ -1,4 +1,4 @@ -import { TLArrowShape, Vec2d, createShapeId } from '@tldraw/editor' +import { TLArrowShape, Vec, createShapeId } from '@tldraw/editor' import { TestEditor } from '../../../test/TestEditor' let editor: TestEditor @@ -132,7 +132,7 @@ describe('When pointing a start shape', () => { expect(editor.getHintingShapeIds().length).toBe(1) // Fake some velocity - editor.inputs.pointerVelocity = new Vec2d(1, 1) + editor.inputs.pointerVelocity = new Vec(1, 1) editor.pointerMove(375, 500) @@ -172,7 +172,7 @@ describe('When pointing an end shape', () => { expect(editor.getHintingShapeIds().length).toBe(0) // Fake some velocity - editor.inputs.pointerVelocity = new Vec2d(1, 1) + editor.inputs.pointerVelocity = new Vec(1, 1) // Move onto shape editor.pointerMove(375, 375) @@ -206,7 +206,7 @@ describe('When pointing an end shape', () => { it('unbinds and rebinds', () => { editor.setCurrentTool('arrow').pointerDown(0, 0) - editor.inputs.pointerVelocity = new Vec2d(1, 1) + editor.inputs.pointerVelocity = new Vec(1, 1) editor.pointerMove(375, 375) @@ -268,7 +268,7 @@ describe('When pointing an end shape', () => { }) // Build up some velocity - editor.inputs.pointerVelocity = new Vec2d(1, 1) + editor.inputs.pointerVelocity = new Vec(1, 1) editor.pointerMove(325, 325) expect(editor.getHintingShapeIds().length).toBe(1) @@ -318,7 +318,7 @@ describe('When pointing an end shape', () => { it('begins imprecise when moving quickly', () => { editor.setCurrentTool('arrow').pointerDown(0, 0) - editor.inputs.pointerVelocity = new Vec2d(1, 1) + editor.inputs.pointerVelocity = new Vec(1, 1) editor.pointerMove(370, 370) const arrow = editor.getCurrentPageShapes()[editor.getCurrentPageShapes().length - 1] @@ -361,7 +361,7 @@ describe('When pointing an end shape', () => { expect(editor.getHintingShapeIds().length).toBe(0) - editor.inputs.pointerVelocity = new Vec2d(0.001, 0.001) + editor.inputs.pointerVelocity = new Vec(0.001, 0.001) editor.pointerMove(375, 375) arrow = editor.getCurrentPageShapes()[editor.getCurrentPageShapes().length - 1] diff --git a/packages/tldraw/src/lib/shapes/arrow/ArrowShapeUtil.test.ts b/packages/tldraw/src/lib/shapes/arrow/ArrowShapeUtil.test.ts index 098961172..b306069ad 100644 --- a/packages/tldraw/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +++ b/packages/tldraw/src/lib/shapes/arrow/ArrowShapeUtil.test.ts @@ -1,7 +1,7 @@ import { assert, createShapeId, - TAU, + HALF_PI, TLArrowShape, TLArrowShapeTerminal, TLShapeId, @@ -343,7 +343,7 @@ describe('When a shape it rotated', () => { }, }) - editor.updateShapes([{ id: ids.box2, type: 'geo', rotation: TAU }]) + editor.updateShapes([{ id: ids.box2, type: 'geo', rotation: HALF_PI }]) editor.pointerMove(225, 350) diff --git a/packages/tldraw/src/lib/shapes/arrow/ArrowShapeUtil.tsx b/packages/tldraw/src/lib/shapes/arrow/ArrowShapeUtil.tsx index e0175e4f7..8334720b9 100644 --- a/packages/tldraw/src/lib/shapes/arrow/ArrowShapeUtil.tsx +++ b/packages/tldraw/src/lib/shapes/arrow/ArrowShapeUtil.tsx @@ -1,6 +1,6 @@ import { Arc2d, - Box2d, + Box, DefaultFontFamilies, Edge2d, Group2d, @@ -21,17 +21,12 @@ import { TLShapePartial, TLShapeUtilCanvasSvgDef, TLShapeUtilFlag, - Vec2d, + Vec, arrowShapeMigrations, arrowShapeProps, deepCopy, getArrowTerminalsInArrowSpace, - getArrowheadPathForType, - getCurvedArrowHandlePath, getDefaultColorTheme, - getSolidCurvedArrowPath, - getSolidStraightArrowPath, - getStraightArrowHandlePath, toDomPrecision, useIsEditing, } from '@tldraw/editor' @@ -50,6 +45,13 @@ import { getFontDefForExport, } from '../shared/defaultStyleDefs' import { getPerfectDashProps } from '../shared/getPerfectDashProps' +import { getArrowheadPathForType } from './arrowheads' +import { + getCurvedArrowHandlePath, + getSolidCurvedArrowPath, + getSolidStraightArrowPath, + getStraightArrowHandlePath, +} from './arrowpaths' import { ArrowTextLabel } from './components/ArrowTextLabel' let globalRenderIndex = 0 @@ -92,14 +94,14 @@ export class ArrowShapeUtil extends ShapeUtil { const bodyGeom = info.isStraight ? new Edge2d({ - start: Vec2d.From(info.start.point), - end: Vec2d.From(info.end.point), + start: Vec.From(info.start.point), + end: Vec.From(info.end.point), }) : new Arc2d({ - center: Vec2d.Cast(info.handleArc.center), + center: Vec.Cast(info.handleArc.center), radius: info.handleArc.radius, - start: Vec2d.Cast(info.start.point), - end: Vec2d.Cast(info.end.point), + start: Vec.Cast(info.start.point), + end: Vec.Cast(info.end.point), sweepFlag: info.bodyArc.sweepFlag, largeArcFlag: info.bodyArc.largeArcFlag, }) @@ -209,16 +211,16 @@ export class ArrowShapeUtil extends ShapeUtil { // Bending the arrow... const { start, end } = getArrowTerminalsInArrowSpace(this.editor, shape) - const delta = Vec2d.Sub(end, start) - const v = Vec2d.Per(delta) + const delta = Vec.Sub(end, start) + const v = Vec.Per(delta) - const med = Vec2d.Med(end, start) - const A = Vec2d.Sub(med, v) - const B = Vec2d.Add(med, v) + const med = Vec.Med(end, start) + const A = Vec.Sub(med, v) + const B = Vec.Add(med, v) - const point = Vec2d.NearestPointOnLineSegment(A, B, handle, false) - let bend = Vec2d.Dist(point, med) - if (Vec2d.Clockwise(point, end, med)) bend *= -1 + const point = Vec.NearestPointOnLineSegment(A, B, handle, false) + let bend = Vec.Dist(point, med) + if (Vec.Clockwise(point, end, med)) bend *= -1 return { id: shape.id, type: shape.type, props: { bend } } } @@ -264,7 +266,7 @@ export class ArrowShapeUtil extends ShapeUtil { // we've got a target! the handle is being dragged over a shape, bind to it const targetGeometry = this.editor.getShapeGeometry(target) - const targetBounds = Box2d.ZeroFix(targetGeometry.bounds) + const targetBounds = Box.ZeroFix(targetGeometry.bounds) const pointInTargetSpace = this.editor.getPointInShapeSpace(target, pointInPageSpace) let precise = isPrecise @@ -307,7 +309,7 @@ export class ArrowShapeUtil extends ShapeUtil { // Funky math but we want the snap distance to be 4 at the minimum and either // 16 or 15% of the smaller dimension of the target shape, whichever is smaller if ( - Vec2d.Dist(pointInTargetSpace, targetBounds.center) < + Vec.Dist(pointInTargetSpace, targetBounds.center) < Math.max(4, Math.min(Math.min(targetBounds.width, targetBounds.height) * 0.15, 16)) / this.editor.getZoomLevel() ) { @@ -326,7 +328,7 @@ export class ArrowShapeUtil extends ShapeUtil { if (next.props.start.type === 'binding' && next.props.end.type === 'binding') { if (next.props.start.boundShapeId === next.props.end.boundShapeId) { - if (Vec2d.Equals(next.props.start.normalizedAnchor, next.props.end.normalizedAnchor)) { + if (Vec.Equals(next.props.start.normalizedAnchor, next.props.end.normalizedAnchor)) { next.props.end.normalizedAnchor.x += 0.05 } } @@ -501,7 +503,7 @@ export class ArrowShapeUtil extends ShapeUtil { ) && !this.editor.getInstanceState().isReadonly const info = this.editor.getArrowInfo(shape) - const bounds = Box2d.ZeroFix(this.editor.getShapeGeometry(shape).bounds) + const bounds = Box.ZeroFix(this.editor.getShapeGeometry(shape).bounds) // eslint-disable-next-line react-hooks/rules-of-hooks const changeIndex = React.useMemo(() => { @@ -524,7 +526,7 @@ export class ArrowShapeUtil extends ShapeUtil { const sw = 2 const { strokeDasharray, strokeDashoffset } = getPerfectDashProps( info.isStraight - ? Vec2d.Dist(info.start.handle, info.end.handle) + ? Vec.Dist(info.start.handle, info.end.handle) : Math.abs(info.handleArc.length), sw, { @@ -686,7 +688,7 @@ export class ArrowShapeUtil extends ShapeUtil { const isEditing = useIsEditing(shape.id) if (!info) return null - if (Vec2d.Equals(start, end)) return null + if (Vec.Equals(start, end)) return null const strokeWidth = STROKE_SIZES[shape.props.size] diff --git a/packages/editor/src/lib/editor/shapes/shared/arrow/arrowheads.ts b/packages/tldraw/src/lib/shapes/arrow/arrowheads.ts similarity index 50% rename from packages/editor/src/lib/editor/shapes/shared/arrow/arrowheads.ts rename to packages/tldraw/src/lib/shapes/arrow/arrowheads.ts index b0258a0ea..ffe4e6128 100644 --- a/packages/editor/src/lib/editor/shapes/shared/arrow/arrowheads.ts +++ b/packages/tldraw/src/lib/shapes/arrow/arrowheads.ts @@ -1,7 +1,4 @@ -import { Vec2d, VecLike } from '../../../../primitives/Vec2d' -import { intersectCircleCircle } from '../../../../primitives/intersect' -import { PI, TAU } from '../../../../primitives/utils' -import { TLArrowInfo } from './arrow-types' +import { HALF_PI, PI, TLArrowInfo, Vec, VecLike, intersectCircleCircle } from '@tldraw/editor' type TLArrowPointsInfo = { point: VecLike @@ -16,14 +13,14 @@ function getArrowPoints( const PT = side === 'end' ? info.end.point : info.start.point const PB = side === 'end' ? info.start.point : info.end.point - const compareLength = info.isStraight ? Vec2d.Dist(PB, PT) : Math.abs(info.bodyArc.length) // todo: arc length for curved arrows + const compareLength = info.isStraight ? Vec.Dist(PB, PT) : Math.abs(info.bodyArc.length) // todo: arc length for curved arrows const length = Math.max(Math.min(compareLength / 5, strokeWidth * 3), strokeWidth) let P0: VecLike if (info.isStraight) { - P0 = Vec2d.Nudge(PT, PB, length) + P0 = Vec.Nudge(PT, PB, length) } else { const ints = intersectCircleCircle(PT, length, info.handleArc.center, info.handleArc.radius) P0 = @@ -42,72 +39,68 @@ function getArrowPoints( } } -export function getArrowhead({ point, int }: TLArrowPointsInfo) { - const PL = Vec2d.RotWith(int, point, PI / 6) - const PR = Vec2d.RotWith(int, point, -PI / 6) +function getArrowhead({ point, int }: TLArrowPointsInfo) { + const PL = Vec.RotWith(int, point, PI / 6) + const PR = Vec.RotWith(int, point, -PI / 6) return `M ${PL.x} ${PL.y} L ${point.x} ${point.y} L ${PR.x} ${PR.y}` } -export function getTriangleHead({ point, int }: TLArrowPointsInfo) { - const PL = Vec2d.RotWith(int, point, PI / 6) - const PR = Vec2d.RotWith(int, point, -PI / 6) +function getTriangleHead({ point, int }: TLArrowPointsInfo) { + const PL = Vec.RotWith(int, point, PI / 6) + const PR = Vec.RotWith(int, point, -PI / 6) return `M ${PL.x} ${PL.y} L ${point.x} ${point.y} L ${PR.x} ${PR.y} Z` } -export function getInvertedTriangleHead({ point, int }: TLArrowPointsInfo) { - const d = Vec2d.Sub(int, point).div(2) - const PL = Vec2d.Add(point, Vec2d.Rot(d, TAU)) - const PR = Vec2d.Sub(point, Vec2d.Rot(d, TAU)) +function getInvertedTriangleHead({ point, int }: TLArrowPointsInfo) { + const d = Vec.Sub(int, point).div(2) + const PL = Vec.Add(point, Vec.Rot(d, HALF_PI)) + const PR = Vec.Sub(point, Vec.Rot(d, HALF_PI)) return `M ${PL.x} ${PL.y} L ${int.x} ${int.y} L ${PR.x} ${PR.y} Z` } -export function getDotHead({ point, int }: TLArrowPointsInfo) { - const A = Vec2d.Lrp(point, int, 0.45) - const r = Vec2d.Dist(A, point) +function getDotHead({ point, int }: TLArrowPointsInfo) { + const A = Vec.Lrp(point, int, 0.45) + const r = Vec.Dist(A, point) return `M ${A.x - r},${A.y} a ${r},${r} 0 1,0 ${r * 2},0 a ${r},${r} 0 1,0 -${r * 2},0 ` } -export function getDiamondHead({ point, int }: TLArrowPointsInfo) { - const PB = Vec2d.Lrp(point, int, 0.75) - const PL = Vec2d.RotWith(PB, point, PI / 4) - const PR = Vec2d.RotWith(PB, point, -PI / 4) +function getDiamondHead({ point, int }: TLArrowPointsInfo) { + const PB = Vec.Lrp(point, int, 0.75) + const PL = Vec.RotWith(PB, point, PI / 4) + const PR = Vec.RotWith(PB, point, -PI / 4) - const PQ = Vec2d.Lrp(PL, PR, 0.5) - PQ.add(Vec2d.Sub(PQ, point)) + const PQ = Vec.Lrp(PL, PR, 0.5) + PQ.add(Vec.Sub(PQ, point)) return `M ${PQ.x} ${PQ.y} L ${PL.x} ${PL.y} ${point.x} ${point.y} L ${PR.x} ${PR.y} Z` } -export function getSquareHead({ int, point }: TLArrowPointsInfo) { - const PB = Vec2d.Lrp(point, int, 0.85) - const d = Vec2d.Sub(PB, point).div(2) - const PL1 = Vec2d.Add(point, Vec2d.Rot(d, TAU)) - const PR1 = Vec2d.Sub(point, Vec2d.Rot(d, TAU)) - const PL2 = Vec2d.Add(PB, Vec2d.Rot(d, TAU)) - const PR2 = Vec2d.Sub(PB, Vec2d.Rot(d, TAU)) +function getSquareHead({ int, point }: TLArrowPointsInfo) { + const PB = Vec.Lrp(point, int, 0.85) + const d = Vec.Sub(PB, point).div(2) + const PL1 = Vec.Add(point, Vec.Rot(d, HALF_PI)) + const PR1 = Vec.Sub(point, Vec.Rot(d, HALF_PI)) + const PL2 = Vec.Add(PB, Vec.Rot(d, HALF_PI)) + const PR2 = Vec.Sub(PB, Vec.Rot(d, HALF_PI)) return `M ${PL1.x} ${PL1.y} L ${PL2.x} ${PL2.y} L ${PR2.x} ${PR2.y} L ${PR1.x} ${PR1.y} Z` } -export function getBarHead({ int, point }: TLArrowPointsInfo) { - const d = Vec2d.Sub(int, point).div(2) +function getBarHead({ int, point }: TLArrowPointsInfo) { + const d = Vec.Sub(int, point).div(2) - const PL = Vec2d.Add(point, Vec2d.Rot(d, TAU)) - const PR = Vec2d.Sub(point, Vec2d.Rot(d, TAU)) + const PL = Vec.Add(point, Vec.Rot(d, HALF_PI)) + const PR = Vec.Sub(point, Vec.Rot(d, HALF_PI)) return `M ${PL.x} ${PL.y} L ${PR.x} ${PR.y}` } -export function getPipeHead() { - return '' -} - /** @public */ export function getArrowheadPathForType( info: TLArrowInfo, diff --git a/packages/tldraw/src/lib/shapes/arrow/arrowpaths.ts b/packages/tldraw/src/lib/shapes/arrow/arrowpaths.ts new file mode 100644 index 000000000..3f5630f58 --- /dev/null +++ b/packages/tldraw/src/lib/shapes/arrow/arrowpaths.ts @@ -0,0 +1,49 @@ +import { TLArrowInfo, VecLike } from '@tldraw/editor' + +/* --------------------- Curved --------------------- */ + +/** + * Get a solid path for a curved arrow's handles. + * + * @param info - The arrow info. + * @public + */ +export function getCurvedArrowHandlePath(info: TLArrowInfo & { isStraight: false }) { + const { + start, + end, + handleArc: { radius, largeArcFlag, sweepFlag }, + } = info + return `M${start.handle.x},${start.handle.y} A${radius} ${radius} 0 ${largeArcFlag} ${sweepFlag} ${end.handle.x},${end.handle.y}` +} + +/** + * Get a solid path for a curved arrow's body. + * + * @param info - The arrow info. + * @public + */ +export function getSolidCurvedArrowPath(info: TLArrowInfo & { isStraight: false }) { + const { + start, + end, + bodyArc: { radius, largeArcFlag, sweepFlag }, + } = info + return `M${start.point.x},${start.point.y} A${radius} ${radius} 0 ${largeArcFlag} ${sweepFlag} ${end.point.x},${end.point.y}` +} + +/* -------------------- Straight -------------------- */ + +function getArrowPath(start: VecLike, end: VecLike) { + return `M${start.x},${start.y}L${end.x},${end.y}` +} + +/** @public */ +export function getStraightArrowHandlePath(info: TLArrowInfo & { isStraight: true }) { + return getArrowPath(info.start.handle, info.end.handle) +} + +/** @public */ +export function getSolidStraightArrowPath(info: TLArrowInfo & { isStraight: true }) { + return getArrowPath(info.start.point, info.end.point) +} diff --git a/packages/tldraw/src/lib/shapes/draw/DrawShapeUtil.tsx b/packages/tldraw/src/lib/shapes/draw/DrawShapeUtil.tsx index c257566ce..a938a68ff 100644 --- a/packages/tldraw/src/lib/shapes/draw/DrawShapeUtil.tsx +++ b/packages/tldraw/src/lib/shapes/draw/DrawShapeUtil.tsx @@ -1,6 +1,6 @@ /* eslint-disable react-hooks/rules-of-hooks */ import { - Box2d, + Box, Circle2d, Polygon2d, Polyline2d, @@ -60,7 +60,7 @@ export class DrawShapeUtil extends ShapeUtil { // A dot if (shape.props.segments.length === 1) { - const box = Box2d.FromPoints(points) + const box = Box.FromPoints(points) if (box.width < strokeWidth * 2 && box.height < strokeWidth * 2) { return new Circle2d({ x: -strokeWidth, diff --git a/packages/tldraw/src/lib/shapes/draw/getPath.ts b/packages/tldraw/src/lib/shapes/draw/getPath.ts index d31a30dcd..65b451cb3 100644 --- a/packages/tldraw/src/lib/shapes/draw/getPath.ts +++ b/packages/tldraw/src/lib/shapes/draw/getPath.ts @@ -5,7 +5,7 @@ import { TLDefaultDashStyle, TLDrawShape, TLDrawShapeSegment, - Vec2d, + Vec, } from '@tldraw/editor' import { StrokeOptions } from '../shared/freehand/types' @@ -81,17 +81,17 @@ export function getFreehandOptions( } export function getPointsFromSegments(segments: TLDrawShapeSegment[]) { - const points: Vec2d[] = [] + const points: Vec[] = [] for (const segment of segments) { if (segment.type === 'free' || segment.points.length < 2) { - points.push(...segment.points.map(Vec2d.Cast)) + points.push(...segment.points.map(Vec.Cast)) } else { const pointsToInterpolate = Math.max( 4, - Math.floor(Vec2d.Dist(segment.points[0], segment.points[1]) / 16) + Math.floor(Vec.Dist(segment.points[0], segment.points[1]) / 16) ) - points.push(...Vec2d.PointsBetween(segment.points[0], segment.points[1], pointsToInterpolate)) + points.push(...Vec.PointsBetween(segment.points[0], segment.points[1], pointsToInterpolate)) } } diff --git a/packages/tldraw/src/lib/shapes/draw/toolStates/Drawing.ts b/packages/tldraw/src/lib/shapes/draw/toolStates/Drawing.ts index fde6e82a5..5ab33ab4c 100644 --- a/packages/tldraw/src/lib/shapes/draw/toolStates/Drawing.ts +++ b/packages/tldraw/src/lib/shapes/draw/toolStates/Drawing.ts @@ -1,6 +1,6 @@ import { DRAG_DISTANCE, - Matrix2d, + Mat, StateNode, TLDefaultSizeStyle, TLDrawShape, @@ -9,8 +9,8 @@ import { TLHighlightShape, TLPointerEventInfo, TLShapePartial, - Vec2d, - Vec2dModel, + Vec, + VecModel, createShapeId, last, snapAngle, @@ -38,11 +38,11 @@ export class Drawing extends StateNode { didJustShiftClickToExtendPreviousShapeLine = false - pagePointWhereCurrentSegmentChanged = {} as Vec2d + pagePointWhereCurrentSegmentChanged = {} as Vec - pagePointWhereNextSegmentChanged = null as Vec2d | null + pagePointWhereNextSegmentChanged = null as Vec | null - lastRecordedPoint = {} as Vec2d + lastRecordedPoint = {} as Vec mergeNextPoint = false currentLineLength = 0 @@ -86,7 +86,7 @@ export class Drawing extends StateNode { // Don't update the shape if we haven't moved far enough from the last time we recorded a point if (inputs.isPen) { if ( - Vec2d.Dist(inputs.currentPagePoint, this.lastRecordedPoint) >= + Vec.Dist(inputs.currentPagePoint, this.lastRecordedPoint) >= 1 / this.editor.getZoomLevel() ) { this.lastRecordedPoint = inputs.currentPagePoint.clone() @@ -161,7 +161,7 @@ export class Drawing extends StateNode { return ( firstPoint !== lastPoint && this.currentLineLength > strokeWidth * 4 && - Vec2d.Dist(firstPoint, lastPoint) < strokeWidth * 2 + Vec.Dist(firstPoint, lastPoint) < strokeWidth * 2 ) } @@ -217,7 +217,7 @@ export class Drawing extends StateNode { } // Convert prevPoint to page space - const prevPointPageSpace = Matrix2d.applyToPoint( + const prevPointPageSpace = Mat.applyToPoint( this.editor.getShapePageTransform(shape.id)!, prevPoint ) @@ -310,7 +310,7 @@ export class Drawing extends StateNode { } const hasMovedFarEnough = - Vec2d.Dist(pagePointWhereNextSegmentChanged, inputs.currentPagePoint) > DRAG_DISTANCE + Vec.Dist(pagePointWhereNextSegmentChanged, inputs.currentPagePoint) > DRAG_DISTANCE // Find the distance from where the pointer was when shift was released and // where it is now; if it's far enough away, then update the page point where @@ -337,7 +337,7 @@ export class Drawing extends StateNode { .toJson() if (prevSegment.type === 'straight') { - this.currentLineLength += Vec2d.Dist(prevLastPoint, newLastPoint) + this.currentLineLength += Vec.Dist(prevLastPoint, newLastPoint) newSegment = { type: 'straight', @@ -346,10 +346,7 @@ export class Drawing extends StateNode { const transform = this.editor.getShapePageTransform(shape)! - this.pagePointWhereCurrentSegmentChanged = Matrix2d.applyToPoint( - transform, - prevLastPoint - ) + this.pagePointWhereCurrentSegmentChanged = Mat.applyToPoint(transform, prevLastPoint) } else { newSegment = { type: 'straight', @@ -386,7 +383,7 @@ export class Drawing extends StateNode { } const hasMovedFarEnough = - Vec2d.Dist(pagePointWhereNextSegmentChanged, inputs.currentPagePoint) > DRAG_DISTANCE + Vec.Dist(pagePointWhereNextSegmentChanged, inputs.currentPagePoint) > DRAG_DISTANCE // Find the distance from where the pointer was when shift was released and // where it is now; if it's far enough away, then update the page point where @@ -411,9 +408,7 @@ export class Drawing extends StateNode { // ended and where the pointer is now const newFreeSegment: TLDrawShapeSegment = { type: 'free', - points: [ - ...Vec2d.PointsBetween(prevPoint, newPoint, 6).map((p) => p.toFixed().toJson()), - ], + points: [...Vec.PointsBetween(prevPoint, newPoint, 6).map((p) => p.toFixed().toJson())], } const finalSegments = [...newSegments, newFreeSegment] @@ -449,7 +444,7 @@ export class Drawing extends StateNode { if (!pagePointWhereCurrentSegmentChanged) throw Error('We should have a point where the segment changed') - let pagePoint: Vec2dModel + let pagePoint: VecModel let shouldSnapToAngle = false if (this.didJustShiftClickToExtendPreviousShapeLine) { @@ -473,7 +468,7 @@ export class Drawing extends StateNode { if (shouldSnap) { if (newSegments.length > 2) { - let nearestPoint: Vec2dModel | undefined = undefined + let nearestPoint: VecModel | undefined = undefined let minDistance = 8 / this.editor.getZoomLevel() // Don't try to snap to the last two segments @@ -487,12 +482,12 @@ export class Drawing extends StateNode { if (!(first && lastPoint)) continue // Snap to the nearest point on the segment, if it's closer than the previous snapped point - const nearestPointOnSegment = Vec2d.NearestPointOnLineSegment( + const nearestPointOnSegment = Vec.NearestPointOnLineSegment( first, lastPoint, newPoint ) - const distance = Vec2d.Dist(nearestPointOnSegment, newPoint) + const distance = Vec.Dist(nearestPointOnSegment, newPoint) if (distance < minDistance) { nearestPoint = nearestPointOnSegment.toFixed().toJson() @@ -515,11 +510,11 @@ export class Drawing extends StateNode { const lastPoint = last(snapSegment.points) if (!lastPoint) throw Error('Expected a last point!') - const A = Matrix2d.applyToPoint(transform, first) + const A = Mat.applyToPoint(transform, first) - const B = Matrix2d.applyToPoint(transform, lastPoint) + const B = Mat.applyToPoint(transform, lastPoint) - const snappedPoint = Matrix2d.applyToPoint(transform, newPoint) + const snappedPoint = Mat.applyToPoint(transform, newPoint) this.editor.snaps.setLines([ { @@ -533,11 +528,11 @@ export class Drawing extends StateNode { if (shouldSnapToAngle) { // Snap line angle to nearest 15 degrees - const currentAngle = Vec2d.Angle(pagePointWhereCurrentSegmentChanged, currentPagePoint) + const currentAngle = Vec.Angle(pagePointWhereCurrentSegmentChanged, currentPagePoint) const snappedAngle = snapAngle(currentAngle, 24) const angleDiff = snappedAngle - currentAngle - pagePoint = Vec2d.RotWith( + pagePoint = Vec.RotWith( currentPagePoint, pagePointWhereCurrentSegmentChanged, angleDiff @@ -553,7 +548,7 @@ export class Drawing extends StateNode { // then the user just did a click-and-immediately-press-shift to create a new straight line // without continuing the previous line. In this case, we want to remove the previous segment. - this.currentLineLength += Vec2d.Dist(newSegment.points[0], newPoint) + this.currentLineLength += Vec.Dist(newSegment.points[0], newPoint) newSegments[newSegments.length - 1] = { ...newSegment, @@ -595,7 +590,7 @@ export class Drawing extends StateNode { // Note: we could recompute the line length here, but it's not really necessary // this.currentLineLength = this.getLineLength(newSegments) } else { - this.currentLineLength += Vec2d.Dist(newPoints[newPoints.length - 1], newPoint) + this.currentLineLength += Vec.Dist(newPoints[newPoints.length - 1], newPoint) newPoints.push(newPoint) } @@ -667,7 +662,7 @@ export class Drawing extends StateNode { for (let i = 0; i < segment.points.length - 1; i++) { const A = segment.points[i] const B = segment.points[i + 1] - length += Vec2d.Sub(B, A).len2() + length += Vec.Sub(B, A).len2() } } diff --git a/packages/tldraw/src/lib/shapes/geo/GeoShapeUtil.tsx b/packages/tldraw/src/lib/shapes/geo/GeoShapeUtil.tsx index 485b9376d..674927c1c 100644 --- a/packages/tldraw/src/lib/shapes/geo/GeoShapeUtil.tsx +++ b/packages/tldraw/src/lib/shapes/geo/GeoShapeUtil.tsx @@ -5,6 +5,7 @@ import { Ellipse2d, Geometry2d, Group2d, + HALF_PI, HTMLContainer, PI2, Polygon2d, @@ -13,13 +14,12 @@ import { SVGContainer, Stadium2d, SvgExportContext, - TAU, TLDefaultDashStyle, TLGeoShape, TLOnEditEndHandler, TLOnResizeHandler, TLShapeUtilCanvasSvgDef, - Vec2d, + Vec, VecLike, geoShapeMigrations, geoShapeProps, @@ -110,14 +110,14 @@ export class GeoShapeUtil extends BaseBoxShapeUtil { } case 'triangle': { body = new Polygon2d({ - points: [new Vec2d(cx, 0), new Vec2d(w, h), new Vec2d(0, h)], + points: [new Vec(cx, 0), new Vec(w, h), new Vec(0, h)], isFilled, }) break } case 'diamond': { body = new Polygon2d({ - points: [new Vec2d(cx, 0), new Vec2d(w, cy), new Vec2d(cx, h), new Vec2d(0, cy)], + points: [new Vec(cx, 0), new Vec(w, cy), new Vec(cx, h), new Vec(0, cy)], isFilled, }) break @@ -170,11 +170,11 @@ export class GeoShapeUtil extends BaseBoxShapeUtil { const leftMostIndex = sides * 2 - rightMostIndex const topMostIndex = 0 const bottomMostIndex = Math.floor(sides / 2) * 2 - const maxX = (Math.cos(-TAU + rightMostIndex * step) * w) / 2 - const minX = (Math.cos(-TAU + leftMostIndex * step) * w) / 2 + const maxX = (Math.cos(-HALF_PI + rightMostIndex * step) * w) / 2 + const minX = (Math.cos(-HALF_PI + leftMostIndex * step) * w) / 2 - const minY = (Math.sin(-TAU + topMostIndex * step) * h) / 2 - const maxY = (Math.sin(-TAU + bottomMostIndex * step) * h) / 2 + const minY = (Math.sin(-HALF_PI + topMostIndex * step) * h) / 2 + const maxY = (Math.sin(-HALF_PI + bottomMostIndex * step) * h) / 2 const diffX = w - Math.abs(maxX - minX) const diffY = h - Math.abs(maxY - minY) const offsetX = w / 2 + minX - (w / 2 - maxX) @@ -190,8 +190,8 @@ export class GeoShapeUtil extends BaseBoxShapeUtil { body = new Polygon2d({ points: Array.from(Array(sides * 2)).map((_, i) => { - const theta = -TAU + i * step - return new Vec2d( + const theta = -HALF_PI + i * step + return new Vec( cx + (i % 2 ? ix : ox) * Math.cos(theta), cy + (i % 2 ? iy : oy) * Math.sin(theta) ) @@ -203,12 +203,7 @@ export class GeoShapeUtil extends BaseBoxShapeUtil { case 'rhombus': { const offset = Math.min(w * 0.38, h * 0.38) body = new Polygon2d({ - points: [ - new Vec2d(offset, 0), - new Vec2d(w, 0), - new Vec2d(w - offset, h), - new Vec2d(0, h), - ], + points: [new Vec(offset, 0), new Vec(w, 0), new Vec(w - offset, h), new Vec(0, h)], isFilled, }) break @@ -216,12 +211,7 @@ export class GeoShapeUtil extends BaseBoxShapeUtil { case 'rhombus-2': { const offset = Math.min(w * 0.38, h * 0.38) body = new Polygon2d({ - points: [ - new Vec2d(0, 0), - new Vec2d(w - offset, 0), - new Vec2d(w, h), - new Vec2d(offset, h), - ], + points: [new Vec(0, 0), new Vec(w - offset, 0), new Vec(w, h), new Vec(offset, h)], isFilled, }) break @@ -229,12 +219,7 @@ export class GeoShapeUtil extends BaseBoxShapeUtil { case 'trapezoid': { const offset = Math.min(w * 0.38, h * 0.38) body = new Polygon2d({ - points: [ - new Vec2d(offset, 0), - new Vec2d(w - offset, 0), - new Vec2d(w, h), - new Vec2d(0, h), - ], + points: [new Vec(offset, 0), new Vec(w - offset, 0), new Vec(w, h), new Vec(0, h)], isFilled, }) break @@ -244,13 +229,13 @@ export class GeoShapeUtil extends BaseBoxShapeUtil { const oy = h * 0.16 body = new Polygon2d({ points: [ - new Vec2d(0, oy), - new Vec2d(w - ox, oy), - new Vec2d(w - ox, 0), - new Vec2d(w, h / 2), - new Vec2d(w - ox, h), - new Vec2d(w - ox, h - oy), - new Vec2d(0, h - oy), + new Vec(0, oy), + new Vec(w - ox, oy), + new Vec(w - ox, 0), + new Vec(w, h / 2), + new Vec(w - ox, h), + new Vec(w - ox, h - oy), + new Vec(0, h - oy), ], isFilled, }) @@ -261,13 +246,13 @@ export class GeoShapeUtil extends BaseBoxShapeUtil { const oy = h * 0.16 body = new Polygon2d({ points: [ - new Vec2d(ox, 0), - new Vec2d(ox, oy), - new Vec2d(w, oy), - new Vec2d(w, h - oy), - new Vec2d(ox, h - oy), - new Vec2d(ox, h), - new Vec2d(0, h / 2), + new Vec(ox, 0), + new Vec(ox, oy), + new Vec(w, oy), + new Vec(w, h - oy), + new Vec(ox, h - oy), + new Vec(ox, h), + new Vec(0, h / 2), ], isFilled, }) @@ -278,13 +263,13 @@ export class GeoShapeUtil extends BaseBoxShapeUtil { const oy = Math.min(w, h) * 0.38 body = new Polygon2d({ points: [ - new Vec2d(w / 2, 0), - new Vec2d(w, oy), - new Vec2d(w - ox, oy), - new Vec2d(w - ox, h), - new Vec2d(ox, h), - new Vec2d(ox, oy), - new Vec2d(0, oy), + new Vec(w / 2, 0), + new Vec(w, oy), + new Vec(w - ox, oy), + new Vec(w - ox, h), + new Vec(ox, h), + new Vec(ox, oy), + new Vec(0, oy), ], isFilled, }) @@ -295,13 +280,13 @@ export class GeoShapeUtil extends BaseBoxShapeUtil { const oy = Math.min(w, h) * 0.38 body = new Polygon2d({ points: [ - new Vec2d(ox, 0), - new Vec2d(w - ox, 0), - new Vec2d(w - ox, h - oy), - new Vec2d(w, h - oy), - new Vec2d(w / 2, h), - new Vec2d(0, h - oy), - new Vec2d(ox, h - oy), + new Vec(ox, 0), + new Vec(w - ox, 0), + new Vec(w - ox, h - oy), + new Vec(w, h - oy), + new Vec(w / 2, h), + new Vec(0, h - oy), + new Vec(ox, h - oy), ], isFilled, }) @@ -862,7 +847,7 @@ export class GeoShapeUtil extends BaseBoxShapeUtil { h = nextH } - const offset = new Vec2d(0, 0) + const offset = new Vec(0, 0) // x offsets @@ -1113,10 +1098,10 @@ function getXBoxLines(w: number, h: number, sw: number, dash: TLDefaultDashStyle if (dash === 'dashed') { return [ - [new Vec2d(0, 0), new Vec2d(w / 2, h / 2)], - [new Vec2d(w, h), new Vec2d(w / 2, h / 2)], - [new Vec2d(0, h), new Vec2d(w / 2, h / 2)], - [new Vec2d(w, 0), new Vec2d(w / 2, h / 2)], + [new Vec(0, 0), new Vec(w / 2, h / 2)], + [new Vec(w, h), new Vec(w / 2, h / 2)], + [new Vec(0, h), new Vec(w / 2, h / 2)], + [new Vec(w, 0), new Vec(w / 2, h / 2)], ] } @@ -1125,12 +1110,12 @@ function getXBoxLines(w: number, h: number, sw: number, dash: TLDefaultDashStyle return [ [ - new Vec2d(clampX(sw * inset), clampY(sw * inset)), - new Vec2d(clampX(w - sw * inset), clampY(h - sw * inset)), + new Vec(clampX(sw * inset), clampY(sw * inset)), + new Vec(clampX(w - sw * inset), clampY(h - sw * inset)), ], [ - new Vec2d(clampX(sw * inset), clampY(h - sw * inset)), - new Vec2d(clampX(w - sw * inset), clampY(sw * inset)), + new Vec(clampX(sw * inset), clampY(h - sw * inset)), + new Vec(clampX(w - sw * inset), clampY(sw * inset)), ], ] } @@ -1145,12 +1130,12 @@ function getCheckBoxLines(w: number, h: number) { return [ [ - new Vec2d(clampX(ox + size * 0.25), clampY(oy + size * 0.52)), - new Vec2d(clampX(ox + size * 0.45), clampY(oy + size * 0.82)), + new Vec(clampX(ox + size * 0.25), clampY(oy + size * 0.52)), + new Vec(clampX(ox + size * 0.45), clampY(oy + size * 0.82)), ], [ - new Vec2d(clampX(ox + size * 0.45), clampY(oy + size * 0.82)), - new Vec2d(clampX(ox + size * 0.82), clampY(oy + size * 0.22)), + new Vec(clampX(ox + size * 0.45), clampY(oy + size * 0.82)), + new Vec(clampX(ox + size * 0.82), clampY(oy + size * 0.22)), ], ] } @@ -1168,5 +1153,5 @@ export function getCentroidOfRegularPolygon(points: VecLike[]) { x += points[i].x y += points[i].y } - return new Vec2d(x / len, y / len) + return new Vec(x / len, y / len) } diff --git a/packages/tldraw/src/lib/shapes/geo/cloudOutline.ts b/packages/tldraw/src/lib/shapes/geo/cloudOutline.ts index 22f703ae8..faa62994e 100644 --- a/packages/tldraw/src/lib/shapes/geo/cloudOutline.ts +++ b/packages/tldraw/src/lib/shapes/geo/cloudOutline.ts @@ -1,8 +1,8 @@ import { PI, TLDefaultSizeStyle, - Vec2d, - Vec2dModel, + Vec, + VecModel, clockwiseAngleDist, getPointOnCircle, rng, @@ -19,12 +19,12 @@ function getPillCircumference(width: number, height: number) { type PillSection = | { type: 'straight' - start: Vec2dModel - delta: Vec2dModel + start: VecModel + delta: VecModel } | { type: 'arc' - center: Vec2dModel + center: VecModel startAngle: number } @@ -41,55 +41,55 @@ export function getPillPoints(width: number, height: number, numPoints: number) ? [ { type: 'straight', - start: new Vec2d(radius, 0), - delta: new Vec2d(1, 0), + start: new Vec(radius, 0), + delta: new Vec(1, 0), }, { type: 'arc', - center: new Vec2d(width - radius, radius), + center: new Vec(width - radius, radius), startAngle: -PI / 2, }, { type: 'straight', - start: new Vec2d(width - radius, height), - delta: new Vec2d(-1, 0), + start: new Vec(width - radius, height), + delta: new Vec(-1, 0), }, { type: 'arc', - center: new Vec2d(radius, radius), + center: new Vec(radius, radius), startAngle: PI / 2, }, ] : [ { type: 'straight', - start: new Vec2d(width, radius), - delta: new Vec2d(0, 1), + start: new Vec(width, radius), + delta: new Vec(0, 1), }, { type: 'arc', - center: new Vec2d(radius, height - radius), + center: new Vec(radius, height - radius), startAngle: 0, }, { type: 'straight', - start: new Vec2d(0, height - radius), - delta: new Vec2d(0, -1), + start: new Vec(0, height - radius), + delta: new Vec(0, -1), }, { type: 'arc', - center: new Vec2d(radius, radius), + center: new Vec(radius, radius), startAngle: PI, }, ] let sectionOffset = 0 - const points: Vec2d[] = [] + const points: Vec[] = [] for (let i = 0; i < numPoints; i++) { const section = sections[0] if (section.type === 'straight') { - points.push(Vec2d.Add(section.start, Vec2d.Mul(section.delta, sectionOffset))) + points.push(Vec.Add(section.start, Vec.Mul(section.delta, sectionOffset))) } else { points.push( getPointOnCircle( @@ -159,12 +159,12 @@ export function getCloudArcs( // in at the bottom-right and the top-left looks relatively stable const wiggledPoints = bumpPoints.slice(0) for (let i = 0; i < Math.floor(numBumps / 2); i++) { - wiggledPoints[i] = Vec2d.AddXY( + wiggledPoints[i] = Vec.AddXY( wiggledPoints[i], getRandom() * maxWiggleX, getRandom() * maxWiggleY ) - wiggledPoints[numBumps - i - 1] = Vec2d.AddXY( + wiggledPoints[numBumps - i - 1] = Vec.AddXY( wiggledPoints[numBumps - i - 1], getRandom() * maxWiggleX, getRandom() * maxWiggleY @@ -180,17 +180,17 @@ export function getCloudArcs( const leftPoint = bumpPoints[i] const rightPoint = bumpPoints[j] - const midPoint = Vec2d.Average([leftPoint, rightPoint]) - const offsetAngle = Vec2d.Angle(leftPoint, rightPoint) - Math.PI / 2 + const midPoint = Vec.Average([leftPoint, rightPoint]) + const offsetAngle = Vec.Angle(leftPoint, rightPoint) - Math.PI / 2 // when the points are on the curvy part of a pill, there is a natural arc that we need to extends past // otherwise it looks like the bumps get less bumpy on the curvy parts - const distanceBetweenOriginalPoints = Vec2d.Dist(leftPoint, rightPoint) + const distanceBetweenOriginalPoints = Vec.Dist(leftPoint, rightPoint) const curvatureOffset = distanceBetweenPointsOnPerimeter - distanceBetweenOriginalPoints - const distanceBetweenWigglePoints = Vec2d.Dist(leftWigglePoint, rightWigglePoint) + const distanceBetweenWigglePoints = Vec.Dist(leftWigglePoint, rightWigglePoint) const relativeSize = distanceBetweenWigglePoints / distanceBetweenOriginalPoints const finalDistance = (Math.max(paddingX, paddingY) + curvatureOffset) * relativeSize - const arcPoint = Vec2d.Add(midPoint, Vec2d.FromAngle(offsetAngle, finalDistance)) + const arcPoint = Vec.Add(midPoint, Vec.FromAngle(offsetAngle, finalDistance)) if (arcPoint.x < 0) { arcPoint.x = 0 } else if (arcPoint.x > width) { @@ -203,8 +203,8 @@ export function getCloudArcs( } const center = getCenterOfCircleGivenThreePoints(leftWigglePoint, rightWigglePoint, arcPoint) - const radius = Vec2d.Dist( - center ? center : Vec2d.Average([leftWigglePoint, rightWigglePoint]), + const radius = Vec.Dist( + center ? center : Vec.Average([leftWigglePoint, rightWigglePoint]), leftWigglePoint ) @@ -221,14 +221,14 @@ export function getCloudArcs( } type Arc = { - leftPoint: Vec2d - rightPoint: Vec2d - arcPoint: Vec2d - center: Vec2d | null + leftPoint: Vec + rightPoint: Vec + arcPoint: Vec + center: Vec | null radius: number } -function getCenterOfCircleGivenThreePoints(a: Vec2d, b: Vec2d, c: Vec2d) { +function getCenterOfCircleGivenThreePoints(a: Vec, b: Vec, c: Vec) { const A = a.x * (b.y - c.y) - a.y * (b.x - c.x) + b.x * c.y - c.x * b.y const B = (a.x * a.x + a.y * a.y) * (c.y - b.y) + @@ -247,7 +247,7 @@ function getCenterOfCircleGivenThreePoints(a: Vec2d, b: Vec2d, c: Vec2d) { return null } - return new Vec2d(x, y) + return new Vec(x, y) } export function cloudOutline( @@ -256,7 +256,7 @@ export function cloudOutline( seed: string, size: TLDefaultSizeStyle ) { - const path: Vec2d[] = [] + const path: Vec[] = [] const arcs = getCloudArcs(width, height, seed, size) @@ -316,12 +316,10 @@ export function inkyCloudSvgPath( } const arcs = getCloudArcs(width, height, seed, size) const avgArcLength = - arcs.reduce((sum, arc) => sum + Vec2d.Dist(arc.leftPoint, arc.rightPoint), 0) / arcs.length + arcs.reduce((sum, arc) => sum + Vec.Dist(arc.leftPoint, arc.rightPoint), 0) / arcs.length const shouldMutatePoints = avgArcLength > mutMultiplier * 15 - const mutPoint = shouldMutatePoints - ? (p: Vec2d) => new Vec2d(mut(p.x), mut(p.y)) - : (p: Vec2d) => p + const mutPoint = shouldMutatePoints ? (p: Vec) => new Vec(mut(p.x), mut(p.y)) : (p: Vec) => p let pathA = `M${toDomPrecision(arcs[0].leftPoint.x)},${toDomPrecision(arcs[0].leftPoint.y)}` let leftMutPoint = mutPoint(arcs[0].leftPoint) let pathB = `M${toDomPrecision(leftMutPoint.x)},${toDomPrecision(leftMutPoint.y)}` @@ -348,7 +346,7 @@ export function inkyCloudSvgPath( leftMutPoint = rightMutPoint continue } - const mutRadius = Math.abs(Vec2d.Dist(mutCenter, leftMutPoint)) + const mutRadius = Math.abs(Vec.Dist(mutCenter, leftMutPoint)) pathB += ` A${toDomPrecision(mutRadius)},${toDomPrecision( mutRadius @@ -360,19 +358,19 @@ export function inkyCloudSvgPath( } export function pointsOnArc( - startPoint: Vec2dModel, - endPoint: Vec2dModel, - center: Vec2dModel | null, + startPoint: VecModel, + endPoint: VecModel, + center: VecModel | null, radius: number, numPoints: number -): Vec2d[] { +): Vec[] { if (center === null) { - return [Vec2d.From(startPoint), Vec2d.From(endPoint)] + return [Vec.From(startPoint), Vec.From(endPoint)] } - const results: Vec2d[] = [] + const results: Vec[] = [] - const startAngle = Vec2d.Angle(center, startPoint) - const endAngle = Vec2d.Angle(center, endPoint) + const startAngle = Vec.Angle(center, startPoint) + const endAngle = Vec.Angle(center, endPoint) const l = clockwiseAngleDist(startAngle, endAngle) @@ -386,6 +384,6 @@ export function pointsOnArc( return results } -function isLeft(a: Vec2d, b: Vec2d, c: Vec2d) { +function isLeft(a: Vec, b: Vec, c: Vec) { return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x) > 0 } diff --git a/packages/tldraw/src/lib/shapes/geo/components/DashStyleCloud.tsx b/packages/tldraw/src/lib/shapes/geo/components/DashStyleCloud.tsx index 2bfba2d80..6356a6ac2 100644 --- a/packages/tldraw/src/lib/shapes/geo/components/DashStyleCloud.tsx +++ b/packages/tldraw/src/lib/shapes/geo/components/DashStyleCloud.tsx @@ -2,7 +2,7 @@ import { TLDefaultColorTheme, TLGeoShape, TLShapeId, - Vec2d, + Vec, canonicalizeRotation, } from '@tldraw/editor' import * as React from 'react' @@ -40,10 +40,10 @@ export const DashStyleCloud = React.memo(function DashStylePolygon({ const arcLength = center ? radius * canonicalizeRotation( - canonicalizeRotation(Vec2d.Angle(center, rightPoint)) - - canonicalizeRotation(Vec2d.Angle(center, leftPoint)) + canonicalizeRotation(Vec.Angle(center, rightPoint)) - + canonicalizeRotation(Vec.Angle(center, leftPoint)) ) - : Vec2d.Dist(leftPoint, rightPoint) + : Vec.Dist(leftPoint, rightPoint) const { strokeDasharray, strokeDashoffset } = getPerfectDashProps( arcLength, @@ -100,10 +100,10 @@ export function DashStyleCloudSvg({ const arcLength = center ? radius * canonicalizeRotation( - canonicalizeRotation(Vec2d.Angle(center, rightPoint)) - - canonicalizeRotation(Vec2d.Angle(center, leftPoint)) + canonicalizeRotation(Vec.Angle(center, rightPoint)) - + canonicalizeRotation(Vec.Angle(center, leftPoint)) ) - : Vec2d.Dist(leftPoint, rightPoint) + : Vec.Dist(leftPoint, rightPoint) const { strokeDasharray, strokeDashoffset } = getPerfectDashProps(arcLength, strokeWidth, { style: dash, diff --git a/packages/tldraw/src/lib/shapes/geo/components/DashStylePolygon.tsx b/packages/tldraw/src/lib/shapes/geo/components/DashStylePolygon.tsx index f647300b3..060650fe5 100644 --- a/packages/tldraw/src/lib/shapes/geo/components/DashStylePolygon.tsx +++ b/packages/tldraw/src/lib/shapes/geo/components/DashStylePolygon.tsx @@ -1,4 +1,4 @@ -import { TLDefaultColorTheme, TLGeoShape, Vec2d, VecLike } from '@tldraw/editor' +import { TLDefaultColorTheme, TLGeoShape, Vec, VecLike } from '@tldraw/editor' import * as React from 'react' import { ShapeFill, @@ -31,7 +31,7 @@ export const DashStylePolygon = React.memo(function DashStylePolygon({ const A = outline[i] const B = outline[(i + 1) % outline.length] - const dist = Vec2d.Dist(A, B) + const dist = Vec.Dist(A, B) const { strokeDasharray, strokeDashoffset } = getPerfectDashProps(dist, strokeWidth, { style: dash, @@ -53,7 +53,7 @@ export const DashStylePolygon = React.memo(function DashStylePolygon({ })} {lines && lines.map(([A, B], i) => { - const dist = Vec2d.Dist(A, B) + const dist = Vec.Dist(A, B) const { strokeDasharray, strokeDashoffset } = getPerfectDashProps(dist, strokeWidth, { style: dash, @@ -102,7 +102,7 @@ export function DashStylePolygonSvg({ const A = outline[i] const B = outline[(i + 1) % outline.length] - const dist = Vec2d.Dist(A, B) + const dist = Vec.Dist(A, B) const { strokeDasharray, strokeDashoffset } = getPerfectDashProps(dist, strokeWidth, { style: dash, }) @@ -120,7 +120,7 @@ export function DashStylePolygonSvg({ if (lines) { for (const [A, B] of lines) { - const dist = Vec2d.Dist(A, B) + const dist = Vec.Dist(A, B) const { strokeDasharray, strokeDashoffset } = getPerfectDashProps(dist, strokeWidth, { style: dash, start: 'skip', diff --git a/packages/tldraw/src/lib/shapes/geo/components/DrawStyleEllipse.tsx b/packages/tldraw/src/lib/shapes/geo/components/DrawStyleEllipse.tsx index 688fee4a0..1a6c6bb70 100644 --- a/packages/tldraw/src/lib/shapes/geo/components/DrawStyleEllipse.tsx +++ b/packages/tldraw/src/lib/shapes/geo/components/DrawStyleEllipse.tsx @@ -1,11 +1,11 @@ import { EASINGS, + HALF_PI, PI2, - TAU, TLDefaultColorTheme, TLGeoShape, TLShapeId, - Vec2d, + Vec, getSvgPathFromPoints, perimeterOfEllipse, rng, @@ -98,10 +98,10 @@ export function getEllipseStrokePoints( const ry = height / 2 const perimeter = perimeterOfEllipse(rx, ry) - const points: Vec2d[] = [] + const points: Vec[] = [] const start = PI2 * getRandom() - const length = PI2 + TAU / 2 + Math.abs(getRandom()) * TAU + const length = PI2 + HALF_PI / 2 + Math.abs(getRandom()) * HALF_PI const count = Math.max(16, perimeter / 10) for (let i = 0; i < count; i++) { @@ -110,7 +110,7 @@ export function getEllipseStrokePoints( const c = Math.cos(r) const s = Math.sin(r) points.push( - new Vec2d( + new Vec( rx * c + width * 0.5 + 0.05 * getRandom(), ry * s + height / 2 + 0.05 * getRandom(), Math.min( diff --git a/packages/tldraw/src/lib/shapes/geo/components/DrawStylePolygon.tsx b/packages/tldraw/src/lib/shapes/geo/components/DrawStylePolygon.tsx index 35b880a5d..2249604e0 100644 --- a/packages/tldraw/src/lib/shapes/geo/components/DrawStylePolygon.tsx +++ b/packages/tldraw/src/lib/shapes/geo/components/DrawStylePolygon.tsx @@ -88,14 +88,14 @@ export function DrawStylePolygonSvg({ } // function getPolygonDrawPoints(id: string, outline: VecLike[], strokeWidth: number) { -// const points: Vec2d[] = [] +// const points: Vec[] = [] // const getRandom = rng(id) // const start = Math.round(Math.abs(getRandom()) * outline.length) // const corners = outline.map((p) => -// Vec2d.AddXY(p, (getRandom() * strokeWidth) / 4, (getRandom() * strokeWidth) / 4) +// Vec.AddXY(p, (getRandom() * strokeWidth) / 4, (getRandom() * strokeWidth) / 4) // ) // const len = corners.length @@ -104,20 +104,20 @@ export function DrawStylePolygonSvg({ // const At = corners[(start + i) % len] // const Bt = corners[(start + i + 1) % len] -// const dist = Math.min(Vec2d.Dist(At, Bt) / 2, strokeWidth / 2) -// const A = Vec2d.Nudge(At, Bt, dist) +// const dist = Math.min(Vec.Dist(At, Bt) / 2, strokeWidth / 2) +// const A = Vec.Nudge(At, Bt, dist) -// const D = Vec2d.Med(At, Bt) +// const D = Vec.Med(At, Bt) // if (i === 0) { // Bt.z = 0.7 -// points.push(new Vec2d(D.x, D.y, 0.7), Bt) +// points.push(new Vec(D.x, D.y, 0.7), Bt) // } else if (i === outline.length) { -// const lastSegPoints = Vec2d.PointsBetween(A, D, 4) +// const lastSegPoints = Vec.PointsBetween(A, D, 4) // lastSegPoints.forEach((p) => (p.z = 0.7)) // points.push(...lastSegPoints) // } else { -// points.push(...Vec2d.PointsBetween(A, Bt, 6)) +// points.push(...Vec.PointsBetween(A, Bt, 6)) // } // } @@ -199,8 +199,8 @@ export function DrawStylePolygonSvg({ // ox = random() * offset // oy = random() * offset -// const c1 = Vec2d.Lrp(p0, p1, 0.25) -// const c2 = Vec2d.Lrp(p0, p1, 0.75) +// const c1 = Vec.Lrp(p0, p1, 0.25) +// const c2 = Vec.Lrp(p0, p1, 0.75) // polylineB += `C${c1.x + ox},${c1.y + oy} ${c2.x - ox},${c2.y - oy} ${p1.x},${p1.y}` // } @@ -224,9 +224,9 @@ export function DrawStylePolygonSvg({ // for (let i = 0, n = len * 2; i < n; i++) { // p0 = outline[i % len] // p1 = outline[(i + 1) % len] -// const dist = Vec2d.Dist(p0, p1) +// const dist = Vec.Dist(p0, p1) -// const c1 = Vec2d.Lrp(p0, p1, 0.5 + random() / 2) +// const c1 = Vec.Lrp(p0, p1, 0.5 + random() / 2) // polylineA += `${c1.x + random() * Math.min(dist / 10, offset)},${ // c1.y + random() * Math.min(dist / 10, offset) // } ${p1.x + (random() * offset) / 2},${p1.y + (random() * offset) / 2} ` @@ -249,9 +249,9 @@ export function DrawStylePolygonSvg({ // for (let i = 0, n = len * 2; i < n; i++) { // p0 = outline[i % len] // p1 = outline[(i + 1) % len] -// const dist = Vec2d.Dist(p0, p1) +// const dist = Vec.Dist(p0, p1) -// const c1 = Vec2d.Lrp(p0, p1, 0.5 + random() / 2) +// const c1 = Vec.Lrp(p0, p1, 0.5 + random() / 2) // polylineA += `${c1.x + random() * Math.min(dist / 10, offset)},${ // c1.y + random() * Math.min(dist / 10, offset) // } ${p1.x + (random() * offset) / 2},${p1.y + (random() * offset) / 2} ` diff --git a/packages/tldraw/src/lib/shapes/geo/toolStates/Pointing.ts b/packages/tldraw/src/lib/shapes/geo/toolStates/Pointing.ts index 4c3b14b3a..29041e9c3 100644 --- a/packages/tldraw/src/lib/shapes/geo/toolStates/Pointing.ts +++ b/packages/tldraw/src/lib/shapes/geo/toolStates/Pointing.ts @@ -1,11 +1,10 @@ import { - Box2d, + Box, GeoShapeGeoStyle, StateNode, TLEventHandlers, TLGeoShape, createShapeId, - getStarBounds, } from '@tldraw/editor' export class Pointing extends StateNode { @@ -93,10 +92,10 @@ export class Pointing extends StateNode { const bounds = shape.props.geo === 'star' - ? getStarBounds(5, 200, 200) + ? new Box(0, 0, 200, 190) : shape.props.geo === 'cloud' - ? new Box2d(0, 0, 300, 180) - : new Box2d(0, 0, 200, 200) + ? new Box(0, 0, 300, 180) + : new Box(0, 0, 200, 200) const delta = bounds.center const parentTransform = this.editor.getShapeParentTransform(shape) diff --git a/packages/tldraw/src/lib/shapes/image/ImageShapeUtil.tsx b/packages/tldraw/src/lib/shapes/image/ImageShapeUtil.tsx index 5aaba2250..7ab4c26b2 100644 --- a/packages/tldraw/src/lib/shapes/image/ImageShapeUtil.tsx +++ b/packages/tldraw/src/lib/shapes/image/ImageShapeUtil.tsx @@ -5,7 +5,7 @@ import { TLImageShape, TLOnDoubleClickHandler, TLShapePartial, - Vec2d, + Vec, deepCopy, imageShapeMigrations, imageShapeProps, @@ -190,10 +190,10 @@ export class ImageShapeUtil extends BaseBoxShapeUtil { const croppedHeight = (crop.bottomRight.y - crop.topLeft.y) * height const points = [ - new Vec2d(0, 0), - new Vec2d(croppedWidth, 0), - new Vec2d(croppedWidth, croppedHeight), - new Vec2d(0, croppedHeight), + new Vec(0, 0), + new Vec(croppedWidth, 0), + new Vec(croppedWidth, croppedHeight), + new Vec(0, croppedHeight), ] const polygon = document.createElementNS('http://www.w3.org/2000/svg', 'polygon') @@ -261,7 +261,7 @@ export class ImageShapeUtil extends BaseBoxShapeUtil { const w = (1 / (crop.bottomRight.x - crop.topLeft.x)) * shape.props.w const h = (1 / (crop.bottomRight.y - crop.topLeft.y)) * shape.props.h - const pointDelta = new Vec2d(crop.topLeft.x * w, crop.topLeft.y * h).rot(shape.rotation) + const pointDelta = new Vec(crop.topLeft.x * w, crop.topLeft.y * h).rot(shape.rotation) const partial: TLShapePartial = { id: shape.id, diff --git a/packages/tldraw/src/lib/shapes/line/LineShapeUtil.tsx b/packages/tldraw/src/lib/shapes/line/LineShapeUtil.tsx index 008d4a052..b74136be6 100644 --- a/packages/tldraw/src/lib/shapes/line/LineShapeUtil.tsx +++ b/packages/tldraw/src/lib/shapes/line/LineShapeUtil.tsx @@ -8,7 +8,7 @@ import { TLLineShape, TLOnHandleChangeHandler, TLOnResizeHandler, - Vec2d, + Vec, WeakMapCache, deepCopy, getDefaultColorTheme, @@ -408,7 +408,7 @@ export class LineShapeUtil extends ShapeUtil { /** @public */ export function getGeometryForLineShape(shape: TLLineShape): CubicSpline2d | Polyline2d { const { spline, handles } = shape.props - const handlePoints = Object.values(handles).sort(sortByIndex).map(Vec2d.From) + const handlePoints = Object.values(handles).sort(sortByIndex).map(Vec.From) switch (spline) { case 'cubic': { diff --git a/packages/tldraw/src/lib/shapes/line/components/svg.ts b/packages/tldraw/src/lib/shapes/line/components/svg.ts index 09619ee7f..9ff1b01f7 100644 --- a/packages/tldraw/src/lib/shapes/line/components/svg.ts +++ b/packages/tldraw/src/lib/shapes/line/components/svg.ts @@ -3,7 +3,7 @@ import { CubicSpline2d, Edge2d, Polyline2d, - Vec2d, + Vec, toDomPrecision, } from '@tldraw/editor' @@ -20,7 +20,7 @@ export function getSvgPathForEdge(edge: Edge2d, first: boolean) { export function getSvgPathForBezierCurve(curve: CubicBezier2d, first: boolean) { const { a, b, c, d } = curve - if (Vec2d.Equals(a, d)) return '' + if (Vec.Equals(a, d)) return '' return `${first ? `M${toDomPrecision(a.x)},${toDomPrecision(a.y)}` : ``}C${toDomPrecision( b.x diff --git a/packages/tldraw/src/lib/shapes/line/toolStates/Pointing.ts b/packages/tldraw/src/lib/shapes/line/toolStates/Pointing.ts index 92702bd94..46660bdc2 100644 --- a/packages/tldraw/src/lib/shapes/line/toolStates/Pointing.ts +++ b/packages/tldraw/src/lib/shapes/line/toolStates/Pointing.ts @@ -1,12 +1,12 @@ import { - Matrix2d, + Mat, StateNode, TLEventHandlers, TLHandle, TLInterruptEvent, TLLineShape, TLShapeId, - Vec2d, + Vec, createShapeId, getIndexAbove, last, @@ -45,18 +45,18 @@ export class Pointing extends StateNode { const endHandle = vertexHandles[vertexHandles.length - 1] const prevEndHandle = vertexHandles[vertexHandles.length - 2] - const shapePagePoint = Matrix2d.applyToPoint( + const shapePagePoint = Mat.applyToPoint( this.editor.getShapeParentTransform(this.shape)!, - new Vec2d(this.shape.x, this.shape.y) + new Vec(this.shape.x, this.shape.y) ) let nextEndHandleIndex: string, nextEndHandleId: string, nextEndHandle: TLHandle - const nextPoint = Vec2d.Sub(currentPagePoint, shapePagePoint) + const nextPoint = Vec.Sub(currentPagePoint, shapePagePoint) if ( - Vec2d.Dist(endHandle, prevEndHandle) < MINIMUM_DISTANCE_BETWEEN_SHIFT_CLICKED_HANDLES || - Vec2d.Dist(nextPoint, endHandle) < MINIMUM_DISTANCE_BETWEEN_SHIFT_CLICKED_HANDLES + Vec.Dist(endHandle, prevEndHandle) < MINIMUM_DISTANCE_BETWEEN_SHIFT_CLICKED_HANDLES || + Vec.Dist(nextPoint, endHandle) < MINIMUM_DISTANCE_BETWEEN_SHIFT_CLICKED_HANDLES ) { // If the end handle is too close to the previous end handle, we'll just extend the previous end handle nextEndHandleIndex = endHandle.index diff --git a/packages/tldraw/src/lib/shapes/shared/TextLabel.tsx b/packages/tldraw/src/lib/shapes/shared/TextLabel.tsx index e489fcf9f..8172b10b1 100644 --- a/packages/tldraw/src/lib/shapes/shared/TextLabel.tsx +++ b/packages/tldraw/src/lib/shapes/shared/TextLabel.tsx @@ -1,5 +1,5 @@ import { - Box2d, + Box, TLDefaultColorStyle, TLDefaultFillStyle, TLDefaultFontStyle, @@ -40,7 +40,7 @@ export const TextLabel = React.memo(function TextLabel< wrap?: boolean text: string labelColor: TLDefaultColorStyle - bounds?: Box2d + bounds?: Box }) { const { rInput, diff --git a/packages/tldraw/src/lib/shapes/shared/createTextSvgElementFromSpans.ts b/packages/tldraw/src/lib/shapes/shared/createTextSvgElementFromSpans.ts index e29e01630..be43a430f 100644 --- a/packages/tldraw/src/lib/shapes/shared/createTextSvgElementFromSpans.ts +++ b/packages/tldraw/src/lib/shapes/shared/createTextSvgElementFromSpans.ts @@ -1,6 +1,6 @@ import { - Box2d, - Box2dModel, + Box, + BoxModel, Editor, TLDefaultHorizontalAlignStyle, TLDefaultVerticalAlignStyle, @@ -13,7 +13,7 @@ function correctSpacesToNbsp(input: string) { /** Get an SVG element for a text shape. */ export function createTextSvgElementFromSpans( editor: Editor, - spans: { text: string; box: Box2dModel }[], + spans: { text: string; box: BoxModel }[], opts: { fontSize: number fontFamily: string @@ -46,7 +46,7 @@ export function createTextSvgElementFromSpans( if (spans.length === 0) return textElm - const bounds = Box2d.From(spans[0].box) + const bounds = Box.From(spans[0].box) for (const { box } of spans) { bounds.union(box) } diff --git a/packages/tldraw/src/lib/shapes/shared/freehand/getStroke.ts b/packages/tldraw/src/lib/shapes/shared/freehand/getStroke.ts index 5e504ef6d..1f43d1c55 100644 --- a/packages/tldraw/src/lib/shapes/shared/freehand/getStroke.ts +++ b/packages/tldraw/src/lib/shapes/shared/freehand/getStroke.ts @@ -1,4 +1,4 @@ -import { Vec2d, VecLike } from '@tldraw/editor' +import { Vec, VecLike } from '@tldraw/editor' import { getStrokeOutlinePoints } from './getStrokeOutlinePoints' import { getStrokePoints } from './getStrokePoints' import { setStrokePointRadii } from './setStrokePointRadii' @@ -15,7 +15,7 @@ import type { StrokeOptions } from './types' * @public */ -export function getStroke(points: VecLike[], options: StrokeOptions = {}): Vec2d[] { +export function getStroke(points: VecLike[], options: StrokeOptions = {}): Vec[] { return getStrokeOutlinePoints( setStrokePointRadii(getStrokePoints(points, options), options), options diff --git a/packages/tldraw/src/lib/shapes/shared/freehand/getStrokeOutlinePoints.ts b/packages/tldraw/src/lib/shapes/shared/freehand/getStrokeOutlinePoints.ts index 6bbe8b551..62dcee2dd 100644 --- a/packages/tldraw/src/lib/shapes/shared/freehand/getStrokeOutlinePoints.ts +++ b/packages/tldraw/src/lib/shapes/shared/freehand/getStrokeOutlinePoints.ts @@ -1,4 +1,4 @@ -import { Vec2d } from '@tldraw/editor' +import { Vec } from '@tldraw/editor' import type { StrokeOptions, StrokePoint } from './types' const { PI } = Math @@ -12,7 +12,7 @@ const FIXED_PI = PI + 0.0001 export function getStrokeOutlineTracks( strokePoints: StrokePoint[], options: StrokeOptions = {} -): { left: Vec2d[]; right: Vec2d[] } { +): { left: Vec[]; right: Vec[] } { const { size = 16, smoothing = 0.5 } = options // We can't do anything with an empty array or a stroke with negative size. @@ -30,8 +30,8 @@ export function getStrokeOutlineTracks( const minDistance = Math.pow(size * smoothing, 2) // Our collected left and right points - const leftPts: Vec2d[] = [] - const rightPts: Vec2d[] = [] + const leftPts: Vec[] = [] + const rightPts: Vec[] = [] // Previous vector let prevVector = strokePoints[0].vector @@ -87,11 +87,11 @@ export function getStrokeOutlineTracks( const cpr = prevVector.clone().cpr(nextVector) if (cpr < 0) { - tl = Vec2d.Add(point, offset) - tr = Vec2d.Sub(point, offset) + tl = Vec.Add(point, offset) + tr = Vec.Sub(point, offset) } else { - tl = Vec2d.Sub(point, offset) - tr = Vec2d.Add(point, offset) + tl = Vec.Sub(point, offset) + tr = Vec.Add(point, offset) } leftPts.push(tl) @@ -99,13 +99,13 @@ export function getStrokeOutlineTracks( } else { // Draw a "sharp" corner const offset = prevVector.clone().mul(strokePoint.radius).per() - const start = Vec2d.Sub(strokePoint.input, offset) + const start = Vec.Sub(strokePoint.input, offset) for (let step = 1 / 13, t = 0; t < 1; t += step) { - tl = Vec2d.RotWith(start, strokePoint.input, FIXED_PI * t) + tl = Vec.RotWith(start, strokePoint.input, FIXED_PI * t) leftPts.push(tl) - tr = Vec2d.RotWith(start, strokePoint.input, FIXED_PI + FIXED_PI * -t) + tr = Vec.RotWith(start, strokePoint.input, FIXED_PI + FIXED_PI * -t) rightPts.push(tr) } } @@ -123,9 +123,9 @@ export function getStrokeOutlineTracks( isPrevPointSharpCorner = false if (strokePoint === firstStrokePoint || strokePoint === lastStrokePoint) { - const offset = Vec2d.Per(vector).mul(strokePoint.radius) - leftPts.push(Vec2d.Sub(point, offset)) - rightPts.push(Vec2d.Add(point, offset)) + const offset = Vec.Per(vector).mul(strokePoint.radius) + leftPts.push(Vec.Sub(point, offset)) + rightPts.push(Vec.Add(point, offset)) continue } @@ -140,18 +140,18 @@ export function getStrokeOutlineTracks( points array. */ - const offset = Vec2d.Lrp(nextVector, vector, nextDpr).per().mul(strokePoint.radius) + const offset = Vec.Lrp(nextVector, vector, nextDpr).per().mul(strokePoint.radius) - tl = Vec2d.Sub(point, offset) + tl = Vec.Sub(point, offset) - if (i <= 1 || Vec2d.Dist2(pl, tl) > minDistance) { + if (i <= 1 || Vec.Dist2(pl, tl) > minDistance) { leftPts.push(tl) pl = tl } - tr = Vec2d.Add(point, offset) + tr = Vec.Add(point, offset) - if (i <= 1 || Vec2d.Dist2(pr, tr) > minDistance) { + if (i <= 1 || Vec.Dist2(pr, tr) > minDistance) { rightPts.push(tr) pr = tr } @@ -186,7 +186,7 @@ export function getStrokeOutlineTracks( export function getStrokeOutlinePoints( strokePoints: StrokePoint[], options: StrokeOptions = {} -): Vec2d[] { +): Vec[] { const { size = 16, start = {}, end = {}, last: isComplete = false } = options const { cap: capStart = true } = start @@ -234,7 +234,7 @@ export function getStrokeOutlinePoints( const lastPoint = strokePoints.length > 1 ? strokePoints[strokePoints.length - 1].point - : Vec2d.AddXY(firstStrokePoint.point, 1, 1) + : Vec.AddXY(firstStrokePoint.point, 1, 1) /* Draw a dot for very short or completed strokes @@ -247,13 +247,13 @@ export function getStrokeOutlinePoints( if (strokePoints.length === 1) { if (!(taperStart || taperEnd) || isComplete) { - const start = Vec2d.Add( + const start = Vec.Add( firstPoint, - Vec2d.Sub(firstPoint, lastPoint).uni().per().mul(-firstStrokePoint.radius) + Vec.Sub(firstPoint, lastPoint).uni().per().mul(-firstStrokePoint.radius) ) - const dotPts: Vec2d[] = [] + const dotPts: Vec[] = [] for (let step = 1 / 13, t = step; t <= 1; t += step) { - dotPts.push(Vec2d.RotWith(start, firstPoint, FIXED_PI * 2 * t)) + dotPts.push(Vec.RotWith(start, firstPoint, FIXED_PI * 2 * t)) } return dotPts } @@ -268,26 +268,26 @@ export function getStrokeOutlinePoints( Finally remove the first left and right points. :psyduck: */ - const startCap: Vec2d[] = [] + const startCap: Vec[] = [] if (taperStart || (taperEnd && strokePoints.length === 1)) { // The start point is tapered, noop } else if (capStart) { // Draw the round cap - add thirteen points rotating the right point around the start point to the left point for (let step = 1 / 8, t = step; t <= 1; t += step) { - const pt = Vec2d.RotWith(rightPts[0], firstPoint, FIXED_PI * t) + const pt = Vec.RotWith(rightPts[0], firstPoint, FIXED_PI * t) startCap.push(pt) } } else { // Draw the flat cap - add a point to the left and right of the start point - const cornersVector = Vec2d.Sub(leftPts[0], rightPts[0]) - const offsetA = Vec2d.Mul(cornersVector, 0.5) - const offsetB = Vec2d.Mul(cornersVector, 0.51) + const cornersVector = Vec.Sub(leftPts[0], rightPts[0]) + const offsetA = Vec.Mul(cornersVector, 0.5) + const offsetB = Vec.Mul(cornersVector, 0.51) startCap.push( - Vec2d.Sub(firstPoint, offsetA), - Vec2d.Sub(firstPoint, offsetB), - Vec2d.Add(firstPoint, offsetB), - Vec2d.Add(firstPoint, offsetA) + Vec.Sub(firstPoint, offsetA), + Vec.Sub(firstPoint, offsetB), + Vec.Add(firstPoint, offsetB), + Vec.Add(firstPoint, offsetA) ) } @@ -301,7 +301,7 @@ export function getStrokeOutlinePoints( sharp end turns. */ - const endCap: Vec2d[] = [] + const endCap: Vec[] = [] const direction = lastStrokePoint.vector.clone().per().neg() if (taperEnd || (taperStart && strokePoints.length === 1)) { @@ -309,17 +309,17 @@ export function getStrokeOutlinePoints( endCap.push(lastPoint) } else if (capEnd) { // Draw the round end cap - const start = Vec2d.Add(lastPoint, Vec2d.Mul(direction, lastStrokePoint.radius)) + const start = Vec.Add(lastPoint, Vec.Mul(direction, lastStrokePoint.radius)) for (let step = 1 / 29, t = step; t < 1; t += step) { - endCap.push(Vec2d.RotWith(start, lastPoint, FIXED_PI * 3 * t)) + endCap.push(Vec.RotWith(start, lastPoint, FIXED_PI * 3 * t)) } } else { // Draw the flat end cap endCap.push( - Vec2d.Add(lastPoint, Vec2d.Mul(direction, lastStrokePoint.radius)), - Vec2d.Add(lastPoint, Vec2d.Mul(direction, lastStrokePoint.radius * 0.99)), - Vec2d.Sub(lastPoint, Vec2d.Mul(direction, lastStrokePoint.radius * 0.99)), - Vec2d.Sub(lastPoint, Vec2d.Mul(direction, lastStrokePoint.radius)) + Vec.Add(lastPoint, Vec.Mul(direction, lastStrokePoint.radius)), + Vec.Add(lastPoint, Vec.Mul(direction, lastStrokePoint.radius * 0.99)), + Vec.Sub(lastPoint, Vec.Mul(direction, lastStrokePoint.radius * 0.99)), + Vec.Sub(lastPoint, Vec.Mul(direction, lastStrokePoint.radius)) ) } diff --git a/packages/tldraw/src/lib/shapes/shared/freehand/getStrokePoints.ts b/packages/tldraw/src/lib/shapes/shared/freehand/getStrokePoints.ts index fccb5ab58..7bed4b409 100644 --- a/packages/tldraw/src/lib/shapes/shared/freehand/getStrokePoints.ts +++ b/packages/tldraw/src/lib/shapes/shared/freehand/getStrokePoints.ts @@ -1,4 +1,4 @@ -import { Vec2d, VecLike } from '@tldraw/editor' +import { Vec, VecLike } from '@tldraw/editor' import type { StrokeOptions, StrokePoint } from './types' const MIN_START_PRESSURE = 0.025 @@ -28,7 +28,7 @@ export function getStrokePoints( const t = 0.15 + (1 - streamline) * 0.85 // Whatever the input is, make sure that the points are in number[][]. - let pts = rawInputPoints.map(Vec2d.From) + let pts = rawInputPoints.map(Vec.From) let pointsRemovedFromNearEnd = 0 @@ -55,10 +55,10 @@ export function getStrokePoints( if (pts.length === 0) return [ { - point: Vec2d.From(rawInputPoints[0]), - input: Vec2d.From(rawInputPoints[0]), + point: Vec.From(rawInputPoints[0]), + input: Vec.From(rawInputPoints[0]), pressure: simulatePressure ? 0.5 : 0.15, - vector: new Vec2d(1, 1), + vector: new Vec(1, 1), distance: 0, runningLength: 0, radius: 1, @@ -68,7 +68,7 @@ export function getStrokePoints( // Strip points that are too close to the first point. let pt = pts[1] while (pt) { - if (Vec2d.Dist(pt, pts[0]) > size / 3) break + if (Vec.Dist(pt, pts[0]) > size / 3) break pts[0].z = Math.max(pts[0].z, pt.z) // Use maximum pressure pts.splice(1, 1) pt = pts[1] @@ -78,7 +78,7 @@ export function getStrokePoints( const last = pts.pop()! pt = pts[pts.length - 1] while (pt) { - if (Vec2d.Dist(pt, last) > size / 3) break + if (Vec.Dist(pt, last) > size / 3) break pts.pop() pt = pts[pts.length - 1] pointsRemovedFromNearEnd++ @@ -88,7 +88,7 @@ export function getStrokePoints( const isComplete = options.last || !options.simulatePressure || - (pts.length > 1 && Vec2d.Dist(pts[pts.length - 1], pts[pts.length - 2]) < size) || + (pts.length > 1 && Vec.Dist(pts[pts.length - 1], pts[pts.length - 2]) < size) || pointsRemovedFromNearEnd > 0 // Add extra points between the two, to help avoid "dash" lines @@ -98,7 +98,7 @@ export function getStrokePoints( const last = pts[1] pts = pts.slice(0, -1) for (let i = 1; i < 5; i++) { - const next = Vec2d.Lrp(pts[0], last, i / 4) + const next = Vec.Lrp(pts[0], last, i / 4) next.z = ((pts[0].z + (last.z - pts[0].z)) * i) / 4 pts.push(next) } @@ -111,7 +111,7 @@ export function getStrokePoints( point: pts[0], input: pts[0], pressure: simulatePressure ? 0.5 : pts[0].z, - vector: new Vec2d(1, 1), + vector: new Vec(1, 1), distance: 0, runningLength: 0, radius: 1, @@ -126,7 +126,7 @@ export function getStrokePoints( let prev = strokePoints[0] // Iterate through all of the points, creating StrokePoints. - let point: Vec2d, distance: number + let point: Vec, distance: number if (isComplete && streamline > 0) { pts.push(pts[pts.length - 1].clone()) @@ -140,7 +140,7 @@ export function getStrokePoints( if (prev.point.equals(point)) continue // How far is the new point from the previous point? - distance = Vec2d.Dist(point, prev.point) + distance = Vec.Dist(point, prev.point) // Add this distance to the total "running length" of the line. totalLength += distance @@ -160,7 +160,7 @@ export function getStrokePoints( // The input pressure (or .5 if not specified) pressure: simulatePressure ? 0.5 : pts[i].z, // The vector from the current point to the previous point - vector: Vec2d.Sub(prev.point, point).uni(), + vector: Vec.Sub(prev.point, point).uni(), // The distance between the current point and the previous point distance, // The total distance so far diff --git a/packages/tldraw/src/lib/shapes/shared/freehand/svgInk.ts b/packages/tldraw/src/lib/shapes/shared/freehand/svgInk.ts index 57858e484..d8ff4c84a 100644 --- a/packages/tldraw/src/lib/shapes/shared/freehand/svgInk.ts +++ b/packages/tldraw/src/lib/shapes/shared/freehand/svgInk.ts @@ -1,5 +1,5 @@ import { - Vec2d, + Vec, VecLike, assert, average, @@ -40,8 +40,8 @@ function partitionAtElbows(points: StrokePoint[]): StrokePoint[][] { const prevPoint = points[i - 1] const thisPoint = points[i] const nextPoint = points[i + 1] - const prevAngle = Vec2d.Angle(prevPoint.point, thisPoint.point) - const nextAngle = Vec2d.Angle(thisPoint.point, nextPoint.point) + const prevAngle = Vec.Angle(prevPoint.point, thisPoint.point) + const nextAngle = Vec.Angle(thisPoint.point, nextPoint.point) // acuteness is a normalized representation of how acute the angle is. // 1 is an infinitely thin wedge // 0 is a straight line @@ -66,8 +66,8 @@ function partitionAtElbows(points: StrokePoint[]): StrokePoint[][] { // so now we have a reasonably acute angle but it might not be an elbow if it's far // away from it's neighbors const avgRadius = (prevPoint.radius + thisPoint.radius + nextPoint.radius) / 3 - const incomingNormalizedDist = Vec2d.Dist(prevPoint.point, thisPoint.point) / avgRadius - const outgoingNormalizedDist = Vec2d.Dist(thisPoint.point, nextPoint.point) / avgRadius + const incomingNormalizedDist = Vec.Dist(prevPoint.point, thisPoint.point) / avgRadius + const outgoingNormalizedDist = Vec.Dist(thisPoint.point, nextPoint.point) / avgRadius // angular dist is a normalized representation of how far away the point is from it's neighbors // (normalized by the radius) const angularDist = incomingNormalizedDist + outgoingNormalizedDist @@ -91,7 +91,7 @@ function cleanUpPartition(partition: StrokePoint[]) { const startPoint = partition[0] while (partition.length > 2) { const nextPoint = partition[1] - const dist = Vec2d.Dist(startPoint.point, nextPoint.point) + const dist = Vec.Dist(startPoint.point, nextPoint.point) const avgRadius = (startPoint.radius + nextPoint.radius) / 2 if (dist < avgRadius * 0.5) { partition.splice(1, 1) @@ -103,7 +103,7 @@ function cleanUpPartition(partition: StrokePoint[]) { const endPoint = partition[partition.length - 1] while (partition.length > 2) { const prevPoint = partition[partition.length - 2] - const dist = Vec2d.Dist(endPoint.point, prevPoint.point) + const dist = Vec.Dist(endPoint.point, prevPoint.point) const avgRadius = (endPoint.radius + prevPoint.radius) / 2 if (dist < avgRadius * 0.5) { partition.splice(partition.length - 2, 1) @@ -115,12 +115,12 @@ function cleanUpPartition(partition: StrokePoint[]) { if (partition.length > 1) { partition[0] = { ...partition[0], - vector: Vec2d.FromAngle(Vec2d.Angle(partition[1].point, partition[0].point)), + vector: Vec.FromAngle(Vec.Angle(partition[1].point, partition[0].point)), } partition[partition.length - 1] = { ...partition[partition.length - 1], - vector: Vec2d.FromAngle( - Vec2d.Angle(partition[partition.length - 1].point, partition[partition.length - 2].point) + vector: Vec.FromAngle( + Vec.Angle(partition[partition.length - 1].point, partition[partition.length - 2].point) ), } } @@ -170,8 +170,8 @@ export function renderPartition(strokePoints: StrokePoint[], options: StrokeOpti const point = strokePoints[strokePoints.length - 1] const radius = point.radius const direction = point.vector.clone().per().neg() - const arcStart = Vec2d.Add(point.point, Vec2d.Mul(direction, radius)) - const arcEnd = Vec2d.Add(point.point, Vec2d.Mul(direction, -radius)) + const arcStart = Vec.Add(point.point, Vec.Mul(direction, radius)) + const arcEnd = Vec.Add(point.point, Vec.Mul(direction, -radius)) svg += `${precise(arcStart)}A${toDomPrecision(radius)},${toDomPrecision( radius )} 0 0 1 ${precise(arcEnd)}T` @@ -185,8 +185,8 @@ export function renderPartition(strokePoints: StrokePoint[], options: StrokeOpti const point = strokePoints[0] const radius = point.radius const direction = point.vector.clone().per() - const arcStart = Vec2d.Add(point.point, Vec2d.Mul(direction, radius)) - const arcEnd = Vec2d.Add(point.point, Vec2d.Mul(direction, -radius)) + const arcStart = Vec.Add(point.point, Vec.Mul(direction, radius)) + const arcEnd = Vec.Add(point.point, Vec.Mul(direction, -radius)) svg += `${precise(arcStart)}A${toDomPrecision(radius)},${toDomPrecision( radius )} 0 0 1 ${precise(arcEnd)}Z` diff --git a/packages/tldraw/src/lib/shapes/shared/freehand/types.ts b/packages/tldraw/src/lib/shapes/shared/freehand/types.ts index 0a631e70f..3bc79e866 100644 --- a/packages/tldraw/src/lib/shapes/shared/freehand/types.ts +++ b/packages/tldraw/src/lib/shapes/shared/freehand/types.ts @@ -1,4 +1,4 @@ -import { Vec2d } from '@tldraw/editor' +import { Vec } from '@tldraw/editor' /** * The options object for `getStroke` or `getStrokePoints`. @@ -39,9 +39,9 @@ export interface StrokeOptions { * @public */ export interface StrokePoint { - point: Vec2d - input: Vec2d - vector: Vec2d + point: Vec + input: Vec + vector: Vec pressure: number distance: number runningLength: number diff --git a/packages/tldraw/src/lib/shapes/shared/getTextLabelSvgElement.ts b/packages/tldraw/src/lib/shapes/shared/getTextLabelSvgElement.ts index 4c2325d78..0f4201f1c 100644 --- a/packages/tldraw/src/lib/shapes/shared/getTextLabelSvgElement.ts +++ b/packages/tldraw/src/lib/shapes/shared/getTextLabelSvgElement.ts @@ -1,4 +1,4 @@ -import { Box2d, Editor, TLGeoShape, TLNoteShape } from '@tldraw/editor' +import { Box, Editor, TLGeoShape, TLNoteShape } from '@tldraw/editor' import { createTextSvgElementFromSpans } from './createTextSvgElementFromSpans' import { LABEL_FONT_SIZES, TEXT_PROPS } from './default-shape-constants' import { getLegacyOffsetX } from './legacyProps' @@ -9,7 +9,7 @@ export function getTextLabelSvgElement({ font, shape, }: { - bounds: Box2d + bounds: Box editor: Editor font: string shape: TLGeoShape | TLNoteShape diff --git a/packages/tldraw/src/lib/shapes/shared/legacyProps.ts b/packages/tldraw/src/lib/shapes/shared/legacyProps.ts index 6a0c008df..688b41e84 100644 --- a/packages/tldraw/src/lib/shapes/shared/legacyProps.ts +++ b/packages/tldraw/src/lib/shapes/shared/legacyProps.ts @@ -1,13 +1,13 @@ -import { Box2d, Box2dModel, TLDefaultHorizontalAlignStyle } from '@tldraw/editor' +import { Box, BoxModel, TLDefaultHorizontalAlignStyle } from '@tldraw/editor' export function getLegacyOffsetX( align: TLDefaultHorizontalAlignStyle | string, padding: number, - spans: { text: string; box: Box2dModel }[], + spans: { text: string; box: BoxModel }[], totalWidth: number ): number | undefined { if ((align === 'start-legacy' || align === 'end-legacy') && spans.length !== 0) { - const spansBounds = Box2d.From(spans[0].box) + const spansBounds = Box.From(spans[0].box) for (const { box } of spans) { spansBounds.union(box) } diff --git a/packages/tldraw/src/lib/shapes/shared/polygon-helpers.ts b/packages/tldraw/src/lib/shapes/shared/polygon-helpers.ts index 41c9d5e07..a28c782c6 100644 --- a/packages/tldraw/src/lib/shapes/shared/polygon-helpers.ts +++ b/packages/tldraw/src/lib/shapes/shared/polygon-helpers.ts @@ -1,4 +1,4 @@ -import { Vec2d, VecLike, toDomPrecision } from '@tldraw/editor' +import { Vec, VecLike, toDomPrecision } from '@tldraw/editor' function precise(A: VecLike) { return `${toDomPrecision(A.x)},${toDomPrecision(A.y)} ` @@ -67,12 +67,12 @@ export function getRoundedPolygonPoints( const len = outline.length for (let i = 0, n = len * passes; i < n; i++) { - p1 = Vec2d.AddXY(outline[(i + 1) % len], random() * offset, random() * offset) + p1 = Vec.AddXY(outline[(i + 1) % len], random() * offset, random() * offset) - const delta = Vec2d.Sub(p1, p0) - const distance = Vec2d.Len(delta) - const vector = Vec2d.Div(delta, distance).mul(Math.min(distance / 4, roundness)) - results.push(Vec2d.Add(p0, vector), Vec2d.Add(p1, vector.neg()), p1) + const delta = Vec.Sub(p1, p0) + const distance = Vec.Len(delta) + const vector = Vec.Div(delta, distance).mul(Math.min(distance / 4, roundness)) + results.push(Vec.Add(p0, vector), Vec.Add(p1, vector.neg()), p1) p0 = p1 } @@ -99,21 +99,21 @@ export function getDrawLinePathData(id: string, outline: VecLike[], strokeWidth: for (let i = 0, n = len - 1; i < n; i++) { p1 = outline[i + 1] - s1 = Vec2d.AddXY(outline[i + 1], random() * offset, random() * offset) + s1 = Vec.AddXY(outline[i + 1], random() * offset, random() * offset) - const delta = Vec2d.Sub(p1, p0) - const distance = Vec2d.Len(delta) - const vector = Vec2d.Div(delta, distance).mul(Math.min(distance / 4, roundness)) + const delta = Vec.Sub(p1, p0) + const distance = Vec.Len(delta) + const vector = Vec.Div(delta, distance).mul(Math.min(distance / 4, roundness)) - const q0 = Vec2d.Add(p0, vector) - const q1 = Vec2d.Add(p1, vector.neg()) + const q0 = Vec.Add(p0, vector) + const q1 = Vec.Add(p1, vector.neg()) - const sDelta = Vec2d.Sub(s1, s0) - const sDistance = Vec2d.Len(sDelta) - const sVector = Vec2d.Div(sDelta, sDistance).mul(Math.min(sDistance / 4, roundness)) + const sDelta = Vec.Sub(s1, s0) + const sDistance = Vec.Len(sDelta) + const sVector = Vec.Div(sDelta, sDistance).mul(Math.min(sDistance / 4, roundness)) - const sq0 = Vec2d.Add(s0, sVector) - const sq1 = Vec2d.Add(s1, sVector.neg()) + const sq0 = Vec.Add(s0, sVector) + const sq1 = Vec.Add(s1, sVector.neg()) if (i === n - 1) { innerPathData += `${precise(q0)}L ${precise(p1)}` diff --git a/packages/tldraw/src/lib/shapes/shared/resizeBox.ts b/packages/tldraw/src/lib/shapes/shared/resizeBox.ts index 74eae15ea..7a7e2a0db 100644 --- a/packages/tldraw/src/lib/shapes/shared/resizeBox.ts +++ b/packages/tldraw/src/lib/shapes/shared/resizeBox.ts @@ -1,11 +1,4 @@ -import { - Box2d, - TLBaseBoxShape, - TLResizeHandle, - TLResizeMode, - Vec2d, - Vec2dModel, -} from '@tldraw/editor' +import { Box, TLBaseBoxShape, TLResizeHandle, TLResizeMode, Vec, VecModel } from '@tldraw/editor' /** @public */ export type ResizeBoxOptions = Partial<{ @@ -19,12 +12,12 @@ export type ResizeBoxOptions = Partial<{ export function resizeBox( shape: TLBaseBoxShape, info: { - newPoint: Vec2dModel + newPoint: VecModel handle: TLResizeHandle mode: TLResizeMode scaleX: number scaleY: number - initialBounds: Box2d + initialBounds: Box initialShape: TLBaseBoxShape }, opts = {} as ResizeBoxOptions @@ -35,7 +28,7 @@ export function resizeBox( let w = shape.props.w * scaleX let h = shape.props.h * scaleY - const offset = new Vec2d(0, 0) + const offset = new Vec(0, 0) if (w > 0) { if (w < minWidth) { diff --git a/packages/tldraw/src/lib/shapes/shared/resizeScaled.ts b/packages/tldraw/src/lib/shapes/shared/resizeScaled.ts index 97672905c..79e4c065a 100644 --- a/packages/tldraw/src/lib/shapes/shared/resizeScaled.ts +++ b/packages/tldraw/src/lib/shapes/shared/resizeScaled.ts @@ -1,4 +1,4 @@ -import { Box2d, TLShape, Vec2d, Vec2dModel } from '@tldraw/editor' +import { Box, TLShape, Vec, VecModel } from '@tldraw/editor' export function resizeScaled( shape: Extract, @@ -8,8 +8,8 @@ export function resizeScaled( scaleY, newPoint, }: { - newPoint: Vec2dModel - initialBounds: Box2d + newPoint: VecModel + initialBounds: Box scaleX: number scaleY: number } @@ -18,7 +18,7 @@ export function resizeScaled( const scaleDelta = Math.max(0.01, Math.min(Math.abs(scaleX), Math.abs(scaleY))) // Compute the offset (if flipped X or flipped Y) - const offset = new Vec2d(0, 0) + const offset = new Vec(0, 0) if (scaleX < 0) { offset.x = -(initialBounds.width * scaleDelta) @@ -28,7 +28,7 @@ export function resizeScaled( } // Apply the offset to the new point - const { x, y } = Vec2d.Add(newPoint, offset.rot(shape.rotation)) + const { x, y } = Vec.Add(newPoint, offset.rot(shape.rotation)) return { x, diff --git a/packages/tldraw/src/lib/shapes/shared/rotated-box-shadow.ts b/packages/tldraw/src/lib/shapes/shared/rotated-box-shadow.ts index 9de872270..b6639a75c 100644 --- a/packages/tldraw/src/lib/shapes/shared/rotated-box-shadow.ts +++ b/packages/tldraw/src/lib/shapes/shared/rotated-box-shadow.ts @@ -1,4 +1,4 @@ -import { Vec2d } from '@tldraw/editor' +import { Vec } from '@tldraw/editor' const ROTATING_BOX_SHADOWS = [ { @@ -21,7 +21,7 @@ const ROTATING_BOX_SHADOWS = [ export function getRotatedBoxShadow(rotation: number) { const cssStrings = ROTATING_BOX_SHADOWS.map((shadow) => { const { offsetX, offsetY, blur, spread, color } = shadow - const vec = new Vec2d(offsetX, offsetY) + const vec = new Vec(offsetX, offsetY) const { x, y } = vec.rot(-rotation) return `${x}px ${y}px ${blur}px ${spread}px ${color}` }) diff --git a/packages/tldraw/src/lib/shapes/text/TextShapeUtil.tsx b/packages/tldraw/src/lib/shapes/text/TextShapeUtil.tsx index f6edae433..a544dcacb 100644 --- a/packages/tldraw/src/lib/shapes/text/TextShapeUtil.tsx +++ b/packages/tldraw/src/lib/shapes/text/TextShapeUtil.tsx @@ -10,7 +10,7 @@ import { TLOnResizeHandler, TLShapeUtilFlag, TLTextShape, - Vec2d, + Vec, WeakMapCache, getDefaultColorTheme, stopEventPropagation, @@ -209,7 +209,7 @@ export class TextShapeUtil extends ShapeUtil { const prevWidth = initialBounds.width let nextWidth = prevWidth * scaleX - const offset = new Vec2d(0, 0) + const offset = new Vec(0, 0) nextWidth = Math.max(1, Math.abs(nextWidth)) @@ -308,20 +308,20 @@ export class TextShapeUtil extends ShapeUtil { const wB = boundsB.width * next.props.scale const hB = boundsB.height * next.props.scale - let delta: Vec2d | undefined + let delta: Vec | undefined switch (next.props.align) { case 'middle': { - delta = new Vec2d((wB - wA) / 2, textDidChange ? 0 : (hB - hA) / 2) + delta = new Vec((wB - wA) / 2, textDidChange ? 0 : (hB - hA) / 2) break } case 'end': { - delta = new Vec2d(wB - wA, textDidChange ? 0 : (hB - hA) / 2) + delta = new Vec(wB - wA, textDidChange ? 0 : (hB - hA) / 2) break } default: { if (textDidChange) break - delta = new Vec2d(0, (hB - hA) / 2) + delta = new Vec(0, (hB - hA) / 2) break } } diff --git a/packages/tldraw/src/lib/tools/HandTool/childStates/Dragging.ts b/packages/tldraw/src/lib/tools/HandTool/childStates/Dragging.ts index 2c4da44ab..8d6e60553 100644 --- a/packages/tldraw/src/lib/tools/HandTool/childStates/Dragging.ts +++ b/packages/tldraw/src/lib/tools/HandTool/childStates/Dragging.ts @@ -1,4 +1,4 @@ -import { CAMERA_SLIDE_FRICTION, StateNode, TLEventHandlers, Vec2d } from '@tldraw/editor' +import { CAMERA_SLIDE_FRICTION, StateNode, TLEventHandlers, Vec } from '@tldraw/editor' export class Dragging extends StateNode { static override id = 'dragging' @@ -26,7 +26,7 @@ export class Dragging extends StateNode { private update() { const { currentScreenPoint, previousScreenPoint } = this.editor.inputs - const delta = Vec2d.Sub(currentScreenPoint, previousScreenPoint) + const delta = Vec.Sub(currentScreenPoint, previousScreenPoint) if (Math.abs(delta.x) > 0 || Math.abs(delta.y) > 0) { this.editor.pan(delta) diff --git a/packages/tldraw/src/lib/tools/SelectTool/DragAndDropManager.ts b/packages/tldraw/src/lib/tools/SelectTool/DragAndDropManager.ts index 4ce2681b9..9829e904f 100644 --- a/packages/tldraw/src/lib/tools/SelectTool/DragAndDropManager.ts +++ b/packages/tldraw/src/lib/tools/SelectTool/DragAndDropManager.ts @@ -1,4 +1,4 @@ -import { Editor, TLShape, TLShapeId, Vec2d, compact } from '@tldraw/editor' +import { Editor, TLShape, TLShapeId, Vec, compact } from '@tldraw/editor' const LAG_DURATION = 100 @@ -39,7 +39,7 @@ export class DragAndDropManager { }, duration) } - private handleDrag(point: Vec2d, movingShapes: TLShape[], cb?: () => void) { + private handleDrag(point: Vec, movingShapes: TLShape[], cb?: () => void) { movingShapes = compact(movingShapes.map((shape) => this.editor.getShape(shape.id))) const nextDroppingShapeId = this.editor.getDroppingOverShape(point, movingShapes)?.id ?? null diff --git a/packages/tldraw/src/lib/tools/SelectTool/childStates/Brushing.ts b/packages/tldraw/src/lib/tools/SelectTool/childStates/Brushing.ts index 63d92c803..b4e4910e8 100644 --- a/packages/tldraw/src/lib/tools/SelectTool/childStates/Brushing.ts +++ b/packages/tldraw/src/lib/tools/SelectTool/childStates/Brushing.ts @@ -1,7 +1,7 @@ import { - Box2d, + Box, HIT_TEST_MARGIN, - Matrix2d, + Mat, StateNode, TLCancelEvent, TLEventHandlers, @@ -14,7 +14,7 @@ import { TLShape, TLShapeId, TLTickEventHandler, - Vec2d, + Vec, moveCameraWhenCloseToEdge, pointInPolygon, polygonsIntersect, @@ -25,7 +25,7 @@ export class Brushing extends StateNode { info = {} as TLPointerEventInfo & { target: 'canvas' } - brush = new Box2d() + brush = new Box() initialSelectedShapeIds: TLShapeId[] = [] excludedShapeIds = new Set() @@ -108,17 +108,17 @@ export class Brushing extends StateNode { } = this.editor // Set the brush to contain the current and origin points - this.brush.setTo(Box2d.FromPoints([originPagePoint, currentPagePoint])) + this.brush.setTo(Box.FromPoints([originPagePoint, currentPagePoint])) // We'll be collecting shape ids const results = new Set(shiftKey ? this.initialSelectedShapeIds : []) - let A: Vec2d, - B: Vec2d, + let A: Vec, + B: Vec, shape: TLShape, - pageBounds: Box2d | undefined, - pageTransform: Matrix2d | undefined, - localCorners: Vec2d[] + pageBounds: Box | undefined, + pageTransform: Mat | undefined, + localCorners: Vec[] // We'll be testing the corners of the brush against the shapes const { corners } = this.brush @@ -184,10 +184,10 @@ export class Brushing extends StateNode { private handleHit( shape: TLShape, - currentPagePoint: Vec2d, + currentPagePoint: Vec, currentPageId: TLPageId, results: Set, - corners: Vec2d[] + corners: Vec[] ) { if (shape.parentId === currentPageId) { results.add(shape.id) diff --git a/packages/tldraw/src/lib/tools/SelectTool/childStates/Crop/children/Idle.ts b/packages/tldraw/src/lib/tools/SelectTool/childStates/Crop/children/Idle.ts index 9b5ae3943..1a3f22fa6 100644 --- a/packages/tldraw/src/lib/tools/SelectTool/childStates/Crop/children/Idle.ts +++ b/packages/tldraw/src/lib/tools/SelectTool/childStates/Crop/children/Idle.ts @@ -1,4 +1,4 @@ -import { StateNode, TLEventHandlers, TLExitEventHandler, TLGroupShape, Vec2d } from '@tldraw/editor' +import { StateNode, TLEventHandlers, TLExitEventHandler, TLGroupShape, Vec } from '@tldraw/editor' import { getHitShapeOnCanvasPointerDown } from '../../../../selection-logic/getHitShapeOnCanvasPointerDown' import { ShapeWithCrop, getTranslateCroppedImageChange } from './crop_helpers' @@ -183,14 +183,14 @@ export class Idle extends StateNode { // because that one uses a short timeout on release const shiftKey = keys.has('ShiftLeft') - const delta = new Vec2d(0, 0) + const delta = new Vec(0, 0) if (keys.has('ArrowLeft')) delta.x += 1 if (keys.has('ArrowRight')) delta.x -= 1 if (keys.has('ArrowUp')) delta.y += 1 if (keys.has('ArrowDown')) delta.y -= 1 - if (delta.equals(new Vec2d(0, 0))) return + if (delta.equals(new Vec(0, 0))) return if (shiftKey) delta.mul(10) diff --git a/packages/tldraw/src/lib/tools/SelectTool/childStates/Crop/children/crop_helpers.ts b/packages/tldraw/src/lib/tools/SelectTool/childStates/Crop/children/crop_helpers.ts index 74d30d016..ab36c8712 100644 --- a/packages/tldraw/src/lib/tools/SelectTool/childStates/Crop/children/crop_helpers.ts +++ b/packages/tldraw/src/lib/tools/SelectTool/childStates/Crop/children/crop_helpers.ts @@ -3,7 +3,7 @@ import { TLBaseShape, TLImageShapeCrop, TLShapePartial, - Vec2d, + Vec, deepCopy, } from '@tldraw/editor' @@ -12,7 +12,7 @@ export type ShapeWithCrop = TLBaseShape, - delta: Vec2d + delta: Vec ) { if (!shape) { throw Error('Needs to translate a cropped shape!') diff --git a/packages/tldraw/src/lib/tools/SelectTool/childStates/Cropping.ts b/packages/tldraw/src/lib/tools/SelectTool/childStates/Cropping.ts index 20c5fe34e..78b9610ad 100644 --- a/packages/tldraw/src/lib/tools/SelectTool/childStates/Cropping.ts +++ b/packages/tldraw/src/lib/tools/SelectTool/childStates/Cropping.ts @@ -8,7 +8,7 @@ import { TLImageShapeCrop, TLPointerEventInfo, TLShapePartial, - Vec2d, + Vec, deepCopy, } from '@tldraw/editor' import { MIN_CROP_SIZE } from './Crop/crop-constants' @@ -94,8 +94,8 @@ export class Cropping extends StateNode { const crop = props.crop ?? this.getDefaultCrop() const newCrop = deepCopy(crop) - const newPoint = new Vec2d(shape.x, shape.y) - const pointDelta = new Vec2d(0, 0) + const newPoint = new Vec(shape.x, shape.y) + const pointDelta = new Vec(0, 0) // original (uncropped) width and height of shape const w = (1 / (crop.bottomRight.x - crop.topLeft.x)) * props.w @@ -233,13 +233,13 @@ export class Cropping extends StateNode { const selectionBounds = this.editor.getSelectionRotatedPageBounds()! - const dragHandlePoint = Vec2d.RotWith( + const dragHandlePoint = Vec.RotWith( selectionBounds.getHandlePoint(this.info.handle!), selectionBounds.point, selectionRotation ) - const cursorHandleOffset = Vec2d.Sub(originPagePoint, dragHandlePoint) + const cursorHandleOffset = Vec.Sub(originPagePoint, dragHandlePoint) return { shape, diff --git a/packages/tldraw/src/lib/tools/SelectTool/childStates/DraggingHandle.ts b/packages/tldraw/src/lib/tools/SelectTool/childStates/DraggingHandle.ts index 425966bd0..4b64403cb 100644 --- a/packages/tldraw/src/lib/tools/SelectTool/childStates/DraggingHandle.ts +++ b/packages/tldraw/src/lib/tools/SelectTool/childStates/DraggingHandle.ts @@ -1,5 +1,5 @@ import { - Matrix2d, + Mat, StateNode, TLArrowShape, TLArrowShapeTerminal, @@ -11,7 +11,7 @@ import { TLPointerEventInfo, TLShapeId, TLShapePartial, - Vec2d, + Vec, deepCopy, snapAngle, sortByIndex, @@ -23,7 +23,7 @@ export class DraggingHandle extends StateNode { shapeId = '' as TLShapeId initialHandle = {} as TLHandle initialAdjacentHandle = null as TLHandle | null - initialPagePoint = {} as Vec2d + initialPagePoint = {} as Vec markId = '' initialPageTransform: any @@ -226,10 +226,10 @@ export class DraggingHandle extends StateNode { .add(initialHandle) if (shiftKey && initialAdjacentHandle && initialHandle.id !== 'middle') { - const angle = Vec2d.Angle(initialAdjacentHandle, point) + const angle = Vec.Angle(initialAdjacentHandle, point) const snappedAngle = snapAngle(angle, 24) const angleDifference = snappedAngle - angle - point = Vec2d.RotWith(point, initialAdjacentHandle, angleDifference) + point = Vec.RotWith(point, initialAdjacentHandle, angleDifference) } // Clear any existing snaps @@ -252,12 +252,12 @@ export class DraggingHandle extends StateNode { // Get all the outline segments from the shape const additionalSegments = util .getOutlineSegments(shape) - .map((segment) => Matrix2d.applyToPoints(pageTransform, segment)) + .map((segment) => Mat.applyToPoints(pageTransform, segment)) .filter((_segment, i) => i !== handleIndex - 1 && i !== handleIndex) const snapDelta = snaps.getSnappingHandleDelta({ additionalSegments, - handlePoint: Matrix2d.applyToPoint(pageTransform, point), + handlePoint: Mat.applyToPoint(pageTransform, point), }) if (snapDelta) { diff --git a/packages/tldraw/src/lib/tools/SelectTool/childStates/Idle.ts b/packages/tldraw/src/lib/tools/SelectTool/childStates/Idle.ts index dab92daa9..f405a08a7 100644 --- a/packages/tldraw/src/lib/tools/SelectTool/childStates/Idle.ts +++ b/packages/tldraw/src/lib/tools/SelectTool/childStates/Idle.ts @@ -8,7 +8,7 @@ import { TLKeyboardEventInfo, TLShape, TLTextShape, - Vec2d, + Vec, VecLike, createShapeId, pointInPolygon, @@ -529,14 +529,14 @@ export class Idle extends StateNode { // because that one uses a short timeout on release const shiftKey = keys.has('ShiftLeft') - const delta = new Vec2d(0, 0) + const delta = new Vec(0, 0) if (keys.has('ArrowLeft')) delta.x -= 1 if (keys.has('ArrowRight')) delta.x += 1 if (keys.has('ArrowUp')) delta.y -= 1 if (keys.has('ArrowDown')) delta.y += 1 - if (delta.equals(new Vec2d(0, 0))) return + if (delta.equals(new Vec(0, 0))) return if (!ephemeral) this.editor.mark('nudge shapes') @@ -574,6 +574,6 @@ function isPointInRotatedSelectionBounds(editor: Editor, point: VecLike) { return pointInPolygon( point, - selectionBounds.corners.map((c) => Vec2d.RotWith(c, selectionBounds.point, selectionRotation)) + selectionBounds.corners.map((c) => Vec.RotWith(c, selectionBounds.point, selectionRotation)) ) } diff --git a/packages/tldraw/src/lib/tools/SelectTool/childStates/Resizing.ts b/packages/tldraw/src/lib/tools/SelectTool/childStates/Resizing.ts index dcb6dd802..478e2134c 100644 --- a/packages/tldraw/src/lib/tools/SelectTool/childStates/Resizing.ts +++ b/packages/tldraw/src/lib/tools/SelectTool/childStates/Resizing.ts @@ -1,11 +1,11 @@ import { - Matrix2d, + HALF_PI, + Mat, PI, PI2, SelectionCorner, SelectionEdge, StateNode, - TAU, TLEnterEventHandler, TLEventHandlers, TLFrameShape, @@ -14,7 +14,7 @@ import { TLShapeId, TLShapePartial, TLTickEventHandler, - Vec2d, + Vec, VecLike, areAnglesCompatible, compact, @@ -231,9 +231,9 @@ export class Resizing extends StateNode { const shouldSnap = this.editor.user.getIsSnapMode() ? !ctrlKey : ctrlKey - if (shouldSnap && selectionRotation % TAU === 0) { + if (shouldSnap && selectionRotation % HALF_PI === 0) { const { nudge } = this.editor.snaps.snapResize({ - dragDelta: Vec2d.Sub(currentPagePoint, originPagePoint), + dragDelta: Vec.Sub(currentPagePoint, originPagePoint), initialSelectionPageBounds: this.snapshot.initialSelectionPageBounds, handle: rotateSelectionHandle(dragHandle, selectionRotation), isAspectRatioLocked, @@ -245,7 +245,7 @@ export class Resizing extends StateNode { // get the page point of the selection handle opposite to the drag handle // or the center of the selection box if altKey is pressed - const scaleOriginPage = Vec2d.RotWith( + const scaleOriginPage = Vec.RotWith( altKey ? selectionBounds.center : selectionBounds.getHandlePoint(scaleOriginHandle), selectionBounds.point, selectionRotation @@ -254,15 +254,15 @@ export class Resizing extends StateNode { // calculate the scale by measuring the current distance between the drag handle and the scale origin // and dividing by the original distance between the drag handle and the scale origin - const distanceFromScaleOriginNow = Vec2d.Sub(currentPagePoint, scaleOriginPage).rot( + const distanceFromScaleOriginNow = Vec.Sub(currentPagePoint, scaleOriginPage).rot( -selectionRotation ) - const distanceFromScaleOriginAtStart = Vec2d.Sub(originPagePoint, scaleOriginPage).rot( + const distanceFromScaleOriginAtStart = Vec.Sub(originPagePoint, scaleOriginPage).rot( -selectionRotation ) - const scale = Vec2d.DivV(distanceFromScaleOriginNow, distanceFromScaleOriginAtStart) + const scale = Vec.DivV(distanceFromScaleOriginNow, distanceFromScaleOriginAtStart) if (!Number.isFinite(scale.x)) scale.x = 1 if (!Number.isFinite(scale.y)) scale.y = 1 @@ -334,7 +334,7 @@ export class Resizing extends StateNode { const dx = current.x - initial.x const dy = current.y - initial.y - const delta = new Vec2d(dx, dy).rot(-initial.rotation) + const delta = new Vec(dx, dy).rot(-initial.rotation) if (delta.x !== 0 || delta.y !== 0) { for (const child of children) { @@ -421,13 +421,13 @@ export class Resizing extends StateNode { const selectionBounds = this.editor.getSelectionRotatedPageBounds()! - const dragHandlePoint = Vec2d.RotWith( + const dragHandlePoint = Vec.RotWith( selectionBounds.getHandlePoint(this.info.handle!), selectionBounds.point, selectionRotation ) - const cursorHandleOffset = Vec2d.Sub(originPagePoint, dragHandlePoint) + const cursorHandleOffset = Vec.Sub(originPagePoint, dragHandlePoint) const shapeSnapshots = new Map() @@ -487,7 +487,7 @@ export class Resizing extends StateNode { shape, bounds: this.editor.getShapeGeometry(shape).bounds, pageTransform, - pageRotation: Matrix2d.Decompose(pageTransform!).rotation, + pageRotation: Mat.Decompose(pageTransform!).rotation, isAspectRatioLocked: util.isAspectRatioLocked(shape), } } diff --git a/packages/tldraw/src/lib/tools/SelectTool/childStates/Rotating.ts b/packages/tldraw/src/lib/tools/SelectTool/childStates/Rotating.ts index d2c06cf2b..0378d147d 100644 --- a/packages/tldraw/src/lib/tools/SelectTool/childStates/Rotating.ts +++ b/packages/tldraw/src/lib/tools/SelectTool/childStates/Rotating.ts @@ -1,18 +1,19 @@ import { - EPSILON, RotateCorner, StateNode, TLEventHandlers, TLPointerEventInfo, TLRotationSnapshot, - angleDelta, applyRotationToSnapshotShapes, degreesToRadians, getRotationSnapshot, + shortAngleDist, snapAngle, } from '@tldraw/editor' import { CursorTypeMap } from './PointingResizeHandle' +const ONE_DEGREE = Math.PI / 180 + export class Rotating extends StateNode { static override id = 'rotating' @@ -159,11 +160,11 @@ export class Rotating extends StateNode { if (shiftKey) { newSelectionRotation = snapAngle(newSelectionRotation, 24) } else if (snapToNearestDegree) { - newSelectionRotation = Math.round(newSelectionRotation / EPSILON) * EPSILON + newSelectionRotation = Math.round(newSelectionRotation / ONE_DEGREE) * ONE_DEGREE if (this.editor.getInstanceState().isCoarsePointer) { const snappedToRightAngle = snapAngle(newSelectionRotation, 4) - const angleToRightAngle = angleDelta(newSelectionRotation, snappedToRightAngle) + const angleToRightAngle = shortAngleDist(newSelectionRotation, snappedToRightAngle) if (Math.abs(angleToRightAngle) < degreesToRadians(5)) { newSelectionRotation = snappedToRightAngle } diff --git a/packages/tldraw/src/lib/tools/SelectTool/childStates/ScribbleBrushing.ts b/packages/tldraw/src/lib/tools/SelectTool/childStates/ScribbleBrushing.ts index 9ab8017dc..7de3e5b85 100644 --- a/packages/tldraw/src/lib/tools/SelectTool/childStates/ScribbleBrushing.ts +++ b/packages/tldraw/src/lib/tools/SelectTool/childStates/ScribbleBrushing.ts @@ -7,7 +7,7 @@ import { TLGroupShape, TLShape, TLShapeId, - Vec2d, + Vec, intersectLineSegmentPolyline, pointInPolygon, } from '@tldraw/editor' @@ -98,7 +98,7 @@ export class ScribbleBrushing extends StateNode { } const shapes = currentPageShapes - let shape: TLShape, geometry: Geometry2d, A: Vec2d, B: Vec2d + let shape: TLShape, geometry: Geometry2d, A: Vec, B: Vec for (let i = 0, n = shapes.length; i < n; i++) { shape = shapes[i] diff --git a/packages/tldraw/src/lib/tools/SelectTool/childStates/Translating.ts b/packages/tldraw/src/lib/tools/SelectTool/childStates/Translating.ts index 1f22a86d6..c5fe1f5f7 100644 --- a/packages/tldraw/src/lib/tools/SelectTool/childStates/Translating.ts +++ b/packages/tldraw/src/lib/tools/SelectTool/childStates/Translating.ts @@ -1,8 +1,8 @@ import { - Box2d, + Box, Editor, - Matrix2d, - Matrix2dModel, + Mat, + MatModel, PageRecordType, SnapPoint, StateNode, @@ -11,7 +11,7 @@ import { TLShape, TLShapePartial, TLTickEventHandler, - Vec2d, + Vec, compact, isPageId, moveCameraWhenCloseToEdge, @@ -277,7 +277,7 @@ export class Translating extends StateNode { const parentTransform = isPageId(shape.parentId) ? null - : Matrix2d.Inverse(editor.getShapePageTransform(shape.parentId)!) + : Mat.Inverse(editor.getShapePageTransform(shape.parentId)!) shapeSnapshot.parentTransform = parentTransform }) @@ -286,7 +286,7 @@ export class Translating extends StateNode { function getTranslatingSnapshot(editor: Editor) { const movingShapes: TLShape[] = [] - const pagePoints: Vec2d[] = [] + const pagePoints: Vec[] = [] const shapeSnapshots = compact( editor.getSelectedShapeIds().map((id): null | MovingShapeSnapshot => { @@ -300,7 +300,7 @@ function getTranslatingSnapshot(editor: Editor) { const parentTransform = PageRecordType.isId(shape.parentId) ? null - : Matrix2d.Inverse(editor.getShapePageTransform(shape.parentId)!) + : Mat.Inverse(editor.getShapePageTransform(shape.parentId)!) return { shape, @@ -325,7 +325,7 @@ function getTranslatingSnapshot(editor: Editor) { } return { - averagePagePoint: Vec2d.Average(pagePoints), + averagePagePoint: Vec.Average(pagePoints), movingShapes, shapeSnapshots, initialPageBounds: editor.getSelectionPageBounds()!, @@ -337,8 +337,8 @@ export type TranslatingSnapshot = ReturnType export interface MovingShapeSnapshot { shape: TLShape - pagePoint: Vec2d - parentTransform: Matrix2dModel | null + pagePoint: Vec + parentTransform: MatModel | null } export function moveShapesToPoint({ @@ -350,8 +350,8 @@ export function moveShapesToPoint({ }: { editor: Editor shapeSnapshots: MovingShapeSnapshot[] - averagePagePoint: Vec2d - initialSelectionPageBounds: Box2d + averagePagePoint: Vec + initialSelectionPageBounds: Box initialSelectionSnapPoints: SnapPoint[] }) { const { inputs } = editor @@ -360,7 +360,7 @@ export function moveShapesToPoint({ const gridSize = editor.getDocumentSettings().gridSize - const delta = Vec2d.Sub(inputs.currentPagePoint, inputs.originPagePoint) + const delta = Vec.Sub(inputs.currentPagePoint, inputs.originPagePoint) const flatten: 'x' | 'y' | null = editor.inputs.shiftKey ? Math.abs(delta.x) < Math.abs(delta.y) @@ -392,20 +392,20 @@ export function moveShapesToPoint({ delta.add(nudge) } - const averageSnappedPoint = Vec2d.Add(averagePagePoint, delta) + const averageSnappedPoint = Vec.Add(averagePagePoint, delta) if (isGridMode && !inputs.ctrlKey) { averageSnappedPoint.snapToGrid(gridSize) } - const averageSnap = Vec2d.Sub(averageSnappedPoint, averagePagePoint) + const averageSnap = Vec.Sub(averageSnappedPoint, averagePagePoint) editor.updateShapes( compact( snapshots.map(({ shape, pagePoint, parentTransform }): TLShapePartial | null => { - const newPagePoint = Vec2d.Add(pagePoint, averageSnap) + const newPagePoint = Vec.Add(pagePoint, averageSnap) const newLocalPoint = parentTransform - ? Matrix2d.applyToPoint(parentTransform, newPagePoint) + ? Mat.applyToPoint(parentTransform, newPagePoint) : newPagePoint return { diff --git a/packages/tldraw/src/lib/tools/SelectTool/children/DraggingHandle.ts b/packages/tldraw/src/lib/tools/SelectTool/children/DraggingHandle.ts index 425966bd0..4b64403cb 100644 --- a/packages/tldraw/src/lib/tools/SelectTool/children/DraggingHandle.ts +++ b/packages/tldraw/src/lib/tools/SelectTool/children/DraggingHandle.ts @@ -1,5 +1,5 @@ import { - Matrix2d, + Mat, StateNode, TLArrowShape, TLArrowShapeTerminal, @@ -11,7 +11,7 @@ import { TLPointerEventInfo, TLShapeId, TLShapePartial, - Vec2d, + Vec, deepCopy, snapAngle, sortByIndex, @@ -23,7 +23,7 @@ export class DraggingHandle extends StateNode { shapeId = '' as TLShapeId initialHandle = {} as TLHandle initialAdjacentHandle = null as TLHandle | null - initialPagePoint = {} as Vec2d + initialPagePoint = {} as Vec markId = '' initialPageTransform: any @@ -226,10 +226,10 @@ export class DraggingHandle extends StateNode { .add(initialHandle) if (shiftKey && initialAdjacentHandle && initialHandle.id !== 'middle') { - const angle = Vec2d.Angle(initialAdjacentHandle, point) + const angle = Vec.Angle(initialAdjacentHandle, point) const snappedAngle = snapAngle(angle, 24) const angleDifference = snappedAngle - angle - point = Vec2d.RotWith(point, initialAdjacentHandle, angleDifference) + point = Vec.RotWith(point, initialAdjacentHandle, angleDifference) } // Clear any existing snaps @@ -252,12 +252,12 @@ export class DraggingHandle extends StateNode { // Get all the outline segments from the shape const additionalSegments = util .getOutlineSegments(shape) - .map((segment) => Matrix2d.applyToPoints(pageTransform, segment)) + .map((segment) => Mat.applyToPoints(pageTransform, segment)) .filter((_segment, i) => i !== handleIndex - 1 && i !== handleIndex) const snapDelta = snaps.getSnappingHandleDelta({ additionalSegments, - handlePoint: Matrix2d.applyToPoint(pageTransform, point), + handlePoint: Mat.applyToPoint(pageTransform, point), }) if (snapDelta) { diff --git a/packages/tldraw/src/lib/tools/ZoomTool/childStates/ZoomBrushing.ts b/packages/tldraw/src/lib/tools/ZoomTool/childStates/ZoomBrushing.ts index f92d58266..06cd5db18 100644 --- a/packages/tldraw/src/lib/tools/ZoomTool/childStates/ZoomBrushing.ts +++ b/packages/tldraw/src/lib/tools/ZoomTool/childStates/ZoomBrushing.ts @@ -1,11 +1,11 @@ -import { Box2d, StateNode, TLEventHandlers, TLPointerEventInfo } from '@tldraw/editor' +import { Box, StateNode, TLEventHandlers, TLPointerEventInfo } from '@tldraw/editor' export class ZoomBrushing extends StateNode { static override id = 'zoom_brushing' info = {} as TLPointerEventInfo & { onInteractionEnd?: string } - zoomBrush = new Box2d() + zoomBrush = new Box() override onEnter = (info: TLPointerEventInfo & { onInteractionEnd: string }) => { this.info = info @@ -33,7 +33,7 @@ export class ZoomBrushing extends StateNode { inputs: { originPagePoint, currentPagePoint }, } = this.editor - this.zoomBrush.setTo(Box2d.FromPoints([originPagePoint, currentPagePoint])) + this.zoomBrush.setTo(Box.FromPoints([originPagePoint, currentPagePoint])) this.editor.updateInstanceState({ zoomBrush: this.zoomBrush.toJson() }) } diff --git a/packages/tldraw/src/lib/ui/components/NavigationZone/Minimap.tsx b/packages/tldraw/src/lib/ui/components/NavigationZone/Minimap.tsx index 91b1d930f..94cf138a4 100644 --- a/packages/tldraw/src/lib/ui/components/NavigationZone/Minimap.tsx +++ b/packages/tldraw/src/lib/ui/components/NavigationZone/Minimap.tsx @@ -1,9 +1,9 @@ import { ANIMATION_MEDIUM_MS, - Box2d, + Box, TLPointerEventInfo, TLShapeId, - Vec2d, + Vec, getPointerInfo, intersectPolygonPolygon, normalizeWheel, @@ -93,8 +93,8 @@ export function Minimap({ shapeFill, selectFill, viewportFill }: MinimapProps) { minimap.originPagePoint.setTo(clampedPoint) minimap.originPageCenter.setTo(_vpPageBounds.center) } else { - const delta = Vec2d.Sub(_vpPageBounds.center, _vpPageBounds.point) - const pagePoint = Vec2d.Add(point, delta) + const delta = Vec.Sub(_vpPageBounds.center, _vpPageBounds.point) + const pagePoint = Vec.Add(point, delta) minimap.originPagePoint.setTo(pagePoint) minimap.originPageCenter.setTo(point) editor.centerOnPoint(point, { duration: ANIMATION_MEDIUM_MS }) @@ -120,7 +120,7 @@ export function Minimap({ shapeFill, selectFill, viewportFill }: MinimapProps) { if (rPointing.current) { if (minimap.isInViewport) { const delta = minimap.originPagePoint.clone().sub(minimap.originPageCenter) - editor.centerOnPoint(Vec2d.Sub(point, delta)) + editor.centerOnPoint(Vec.Sub(point, delta)) return } @@ -153,7 +153,7 @@ export function Minimap({ shapeFill, selectFill, viewportFill }: MinimapProps) { type: 'wheel', name: 'wheel', delta: offset, - point: new Vec2d(e.clientX, e.clientY), + point: new Vec(e.clientX, e.clientY), shiftKey: e.shiftKey, altKey: e.altKey, ctrlKey: e.metaKey || e.ctrlKey, @@ -194,17 +194,17 @@ export function Minimap({ shapeFill, selectFill, viewportFill }: MinimapProps) { const _dpr = devicePixelRatio.get() // dereference minimap.contentPageBounds = commonBoundsOfAllShapesOnCurrentPage - ? Box2d.Expand(commonBoundsOfAllShapesOnCurrentPage, viewportPageBounds) + ? Box.Expand(commonBoundsOfAllShapesOnCurrentPage, viewportPageBounds) : viewportPageBounds minimap.updateContentScreenBounds() // All shape bounds - const allShapeBounds = [] as (Box2d & { id: TLShapeId })[] + const allShapeBounds = [] as (Box & { id: TLShapeId })[] shapeIdsOnCurrentPage.forEach((id) => { - let pageBounds = editor.getShapePageBounds(id) as Box2d & { id: TLShapeId } + let pageBounds = editor.getShapePageBounds(id) as Box & { id: TLShapeId } if (!pageBounds) return const pageMask = editor.getShapeMask(id) @@ -214,7 +214,7 @@ export function Minimap({ shapeFill, selectFill, viewportFill }: MinimapProps) { if (!intersection) { return } - pageBounds = Box2d.FromPoints(intersection) as Box2d & { id: TLShapeId } + pageBounds = Box.FromPoints(intersection) as Box & { id: TLShapeId } } if (pageBounds) { diff --git a/packages/tldraw/src/lib/ui/components/NavigationZone/MinimapManager.ts b/packages/tldraw/src/lib/ui/components/NavigationZone/MinimapManager.ts index 554480ecf..afaba7c0b 100644 --- a/packages/tldraw/src/lib/ui/components/NavigationZone/MinimapManager.ts +++ b/packages/tldraw/src/lib/ui/components/NavigationZone/MinimapManager.ts @@ -1,10 +1,10 @@ import { - Box2d, + Box, Editor, PI2, TLInstancePresence, TLShapeId, - Vec2d, + Vec, clamp, uniqueId, } from '@tldraw/editor' @@ -22,17 +22,17 @@ export class MinimapManager { id = uniqueId() cvs: HTMLCanvasElement | null = null - pageBounds: (Box2d & { id: TLShapeId })[] = [] + pageBounds: (Box & { id: TLShapeId })[] = [] collaborators: TLInstancePresence[] = [] - canvasScreenBounds = new Box2d() - canvasPageBounds = new Box2d() + canvasScreenBounds = new Box() + canvasPageBounds = new Box() - contentPageBounds = new Box2d() - contentScreenBounds = new Box2d() + contentPageBounds = new Box() + contentScreenBounds = new Box() - originPagePoint = new Vec2d() - originPageCenter = new Vec2d() + originPagePoint = new Vec() + originPageCenter = new Vec() isInViewport = false @@ -104,7 +104,7 @@ export class MinimapManager { const { x: screenX, y: screenY } = this.getScreenPoint(x, y) - return new Vec2d( + return new Vec( canvasPageBounds.minX + (screenX * contentPageBounds.width) / contentScreenBounds.width, canvasPageBounds.minY + (screenY * contentPageBounds.height) / contentScreenBounds.height, 1 @@ -168,7 +168,7 @@ export class MinimapManager { } } - return new Vec2d(px, py) + return new Vec(px, py) } render = () => { @@ -224,7 +224,7 @@ export class MinimapManager { // When there are many shapes, don't draw rounded rectangles; // consider using the shape's size instead. - let pb: Box2d & { id: TLShapeId } + let pb: Box & { id: TLShapeId } for (let i = 0, n = pageBounds.length; i < n; i++) { pb = pageBounds[i] MinimapManager.roundedRect( @@ -248,7 +248,7 @@ export class MinimapManager { if (this.debug) { // Page bounds - const commonBounds = Box2d.Common(pageBounds) + const commonBounds = Box.Common(pageBounds) const { minX, minY, width, height } = commonBounds ctx.strokeStyle = 'green' ctx.lineWidth = 2 / sx diff --git a/packages/tldraw/src/lib/ui/hooks/clipboard/pasteExcalidrawContent.ts b/packages/tldraw/src/lib/ui/hooks/clipboard/pasteExcalidrawContent.ts index e6526e36b..7c7c3a59c 100644 --- a/packages/tldraw/src/lib/ui/hooks/clipboard/pasteExcalidrawContent.ts +++ b/packages/tldraw/src/lib/ui/hooks/clipboard/pasteExcalidrawContent.ts @@ -1,6 +1,6 @@ import { AssetRecordType, - Box2d, + Box, Editor, TLArrowShapeArrowheadStyle, TLAssetId, @@ -13,7 +13,7 @@ import { TLDefaultSizeStyle, TLOpacityType, TLShapeId, - Vec2d, + Vec, VecLike, compact, createShapeId, @@ -346,7 +346,7 @@ export async function pasteExcalidrawContent(editor: Editor, clipboard: any, poi } const rootShapes = compact(rootShapeIds.map((id) => editor.getShape(id))) - const bounds = Box2d.Common(rootShapes.map((s) => editor.getShapePageBounds(s)!)) + const bounds = Box.Common(rootShapes.map((s) => editor.getShapePageBounds(s)!)) const viewPortCenter = editor.getViewportPageBounds().center editor.updateShapes( rootShapes.map((s) => { @@ -481,19 +481,19 @@ const arrowheadsToArrowheadTypes: Record = { function getBend(element: any, startPoint: any, endPoint: any) { let bend = 0 if (element.points.length > 2) { - const start = new Vec2d(startPoint[0], startPoint[1]) - const end = new Vec2d(endPoint[0], endPoint[1]) - const handle = new Vec2d(element.points[1][0], element.points[1][1]) - const delta = Vec2d.Sub(end, start) - const v = Vec2d.Per(delta) + const start = new Vec(startPoint[0], startPoint[1]) + const end = new Vec(endPoint[0], endPoint[1]) + const handle = new Vec(element.points[1][0], element.points[1][1]) + const delta = Vec.Sub(end, start) + const v = Vec.Per(delta) - const med = Vec2d.Med(end, start) - const A = Vec2d.Sub(med, v) - const B = Vec2d.Add(med, v) + const med = Vec.Med(end, start) + const A = Vec.Sub(med, v) + const B = Vec.Add(med, v) - const point = Vec2d.NearestPointOnLineSegment(A, B, handle, false) - bend = Vec2d.Dist(point, med) - if (Vec2d.Clockwise(point, end, med)) bend *= -1 + const point = Vec.NearestPointOnLineSegment(A, B, handle, false) + bend = Vec.Dist(point, med) + if (Vec.Clockwise(point, end, med)) bend *= -1 } return bend } diff --git a/packages/tldraw/src/lib/ui/hooks/useActions.tsx b/packages/tldraw/src/lib/ui/hooks/useActions.tsx index a1e03f1be..cb2d1332e 100644 --- a/packages/tldraw/src/lib/ui/hooks/useActions.tsx +++ b/packages/tldraw/src/lib/ui/hooks/useActions.tsx @@ -1,8 +1,8 @@ import { ANIMATION_MEDIUM_MS, - Box2d, + Box, Editor, - TAU, + HALF_PI, TLBookmarkShape, TLEmbedShape, TLFrameShape, @@ -10,7 +10,7 @@ import { TLShapeId, TLShapePartial, TLTextShape, - Vec2d, + Vec, approximately, compact, createShapeId, @@ -313,9 +313,9 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) { if (!shape || !editor.isShapeOfType(shape, 'embed') || !shape.props.url) continue - const newPos = new Vec2d(shape.x, shape.y) + const newPos = new Vec(shape.x, shape.y) newPos.rot(-shape.rotation) - newPos.add(new Vec2d(shape.props.w / 2 - 300 / 2, shape.props.h / 2 - 320 / 2)) // see bookmark shape util + newPos.add(new Vec(shape.props.w / 2 - 300 / 2, shape.props.h / 2 - 320 / 2)) // see bookmark shape util newPos.rot(shape.rotation) const partial: TLShapePartial = { id: createShapeId(), @@ -367,9 +367,9 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) { const { width, height } = embedInfo.definition - const newPos = new Vec2d(shape.x, shape.y) + const newPos = new Vec(shape.x, shape.y) newPos.rot(-shape.rotation) - newPos.add(new Vec2d(shape.props.w / 2 - width / 2, shape.props.h / 2 - height / 2)) + newPos.add(new Vec(shape.props.w / 2 - width / 2, shape.props.h / 2 - height / 2)) newPos.rot(shape.rotation) const shapeToCreate: TLShapePartial = { @@ -407,7 +407,7 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) { trackEvent('duplicate-shapes', { source }) const ids = editor.getSelectedShapeIds() - const commonBounds = Box2d.Common(compact(ids.map((id) => editor.getShapePageBounds(id)))) + const commonBounds = Box.Common(compact(ids.map((id) => editor.getShapePageBounds(id)))) const offset = editor.getInstanceState().canMoveCamera ? { x: commonBounds.width + 10, @@ -877,11 +877,11 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) { trackEvent('rotate-cw', { source }) editor.mark('rotate-cw') - const offset = editor.getSelectionRotation() % (TAU / 2) - const dontUseOffset = approximately(offset, 0) || approximately(offset, TAU / 2) + const offset = editor.getSelectionRotation() % (HALF_PI / 2) + const dontUseOffset = approximately(offset, 0) || approximately(offset, HALF_PI / 2) editor.rotateShapesBy( editor.getSelectedShapeIds(), - TAU / 2 - (dontUseOffset ? 0 : offset) + HALF_PI / 2 - (dontUseOffset ? 0 : offset) ) }, }, @@ -896,11 +896,11 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) { trackEvent('rotate-ccw', { source }) editor.mark('rotate-ccw') - const offset = editor.getSelectionRotation() % (TAU / 2) + const offset = editor.getSelectionRotation() % (HALF_PI / 2) const offsetCloseToZero = approximately(offset, 0) editor.rotateShapesBy( editor.getSelectedShapeIds(), - offsetCloseToZero ? -(TAU / 2) : -offset + offsetCloseToZero ? -(HALF_PI / 2) : -offset ) }, }, diff --git a/packages/tldraw/src/lib/utils/frames/frames.ts b/packages/tldraw/src/lib/utils/frames/frames.ts index 44fba77fc..f43b341ff 100644 --- a/packages/tldraw/src/lib/utils/frames/frames.ts +++ b/packages/tldraw/src/lib/utils/frames/frames.ts @@ -1,12 +1,4 @@ -import { - Box2d, - Editor, - TLFrameShape, - TLShapeId, - TLShapePartial, - Vec2d, - compact, -} from '@tldraw/editor' +import { Box, Editor, TLFrameShape, TLShapeId, TLShapePartial, Vec, compact } from '@tldraw/editor' /** * Remove a frame. @@ -58,7 +50,7 @@ export function fitFrameToContent(editor: Editor, id: TLShapeId, opts = {} as { const children = compact(childIds.map((id) => editor.getShape(id))) if (!children.length) return - const bounds = Box2d.FromPoints( + const bounds = Box.FromPoints( children.flatMap((shape) => { const geometry = editor.getShapeGeometry(shape.id) return editor.getShapeLocalTransform(shape)!.applyToPoints(geometry.vertices) @@ -73,7 +65,7 @@ export function fitFrameToContent(editor: Editor, id: TLShapeId, opts = {} as { // The shapes already perfectly fit the frame. if (dx === 0 && dy === 0 && frame.props.w === w && frame.props.h === h) return - const diff = new Vec2d(dx, dy).rot(frame.rotation) + const diff = new Vec(dx, dy).rot(frame.rotation) editor.batch(() => { const changes: TLShapePartial[] = childIds.map((child) => { const shape = editor.getShape(child)! diff --git a/packages/tldraw/src/lib/utils/tldr/buildFromV1Document.ts b/packages/tldraw/src/lib/utils/tldr/buildFromV1Document.ts index 454c0edee..7f9114d5d 100644 --- a/packages/tldraw/src/lib/utils/tldr/buildFromV1Document.ts +++ b/packages/tldraw/src/lib/utils/tldr/buildFromV1Document.ts @@ -21,8 +21,8 @@ import { TLShapeId, TLTextShape, TLVideoShape, - Vec2d, - Vec2dModel, + Vec, + VecModel, clamp, createShapeId, } from '@tldraw/editor' @@ -392,7 +392,7 @@ export function buildFromV1Document(editor: Editor, document: LegacyTldrawDocume const v1Bend = coerceNumber(v1Shape.bend) const v1Start = getV2Point(v1Shape.handles.start.point) const v1End = getV2Point(v1Shape.handles.end.point) - const dist = Vec2d.Dist(v1Start, v1End) + const dist = Vec.Dist(v1Start, v1End) const v2Bend = (dist * -v1Bend) / 2 // Could also be a line... but we'll use it as an arrow anyway @@ -1150,7 +1150,7 @@ function getV2Dash(dash: DashStyle | undefined): TLDefaultDashStyle { return dash ? v1DashesToV2Dashes[dash] ?? 'draw' : 'draw' } -function getV2Point(point: number[]): Vec2dModel { +function getV2Point(point: number[]): VecModel { return { x: coerceNumber(point[0]), y: coerceNumber(point[1]), diff --git a/packages/tldraw/src/test/TestEditor.ts b/packages/tldraw/src/test/TestEditor.ts index e55e3c648..48bcaaaa2 100644 --- a/packages/tldraw/src/test/TestEditor.ts +++ b/packages/tldraw/src/test/TestEditor.ts @@ -1,13 +1,13 @@ import { - Box2dModel, + BoxModel, Editor, - Matrix2d, + HALF_PI, + Mat, PageRecordType, ROTATE_CORNER_TO_SELECTION_CORNER, RequiredKeys, RotateCorner, SelectionHandle, - TAU, TLContent, TLEditorOptions, TLEventInfo, @@ -18,7 +18,7 @@ import { TLShapeId, TLShapePartial, TLWheelEventInfo, - Vec2d, + Vec, VecLike, createShapeId, createTLStore, @@ -83,7 +83,7 @@ export class TestEditor extends Editor { lineHeight: number maxWidth: null | number } - ): Box2dModel => { + ): BoxModel => { const breaks = textToMeasure.split('\n') const longest = breaks.reduce((acc, curr) => { return curr.length > acc.length ? curr : acc @@ -117,7 +117,7 @@ export class TestEditor extends Editor { elm: HTMLDivElement bounds = { x: 0, y: 0, top: 0, left: 0, width: 1080, height: 720, bottom: 720, right: 1080 } - setScreenBounds(bounds: Box2dModel, center = false) { + setScreenBounds(bounds: BoxModel, center = false) { this.bounds.x = bounds.x this.bounds.y = bounds.y this.bounds.top = bounds.y @@ -385,7 +385,7 @@ export class TestEditor extends Editor { this.dispatch({ type: 'wheel', name: 'wheel', - point: new Vec2d(this.inputs.currentScreenPoint.x, this.inputs.currentScreenPoint.y), + point: new Vec(this.inputs.currentScreenPoint.x, this.inputs.currentScreenPoint.y), shiftKey: this.inputs.shiftKey, ctrlKey: this.inputs.ctrlKey, altKey: this.inputs.altKey, @@ -480,11 +480,7 @@ export class TestEditor extends Editor { .clone() .rotWith(this.getSelectionRotatedPageBounds()!.point, this.getSelectionRotation()) - const targetHandlePoint = Vec2d.RotWith( - handlePoint, - this.getSelectionPageCenter()!, - angleRadians - ) + const targetHandlePoint = Vec.RotWith(handlePoint, this.getSelectionPageCenter()!, angleRadians) this.pointerDown(handlePoint.x, handlePoint.y, { target: 'selection', handle }) this.pointerMove(targetHandlePoint.x, targetHandlePoint.y, { shiftKey }) @@ -502,7 +498,7 @@ export class TestEditor extends Editor { const selectionRotation = this.getSelectionRotation() const selectionBounds = this.getSelectionRotatedPageBounds() if (!selectionBounds) return null - return Vec2d.RotWith(selectionBounds.center, selectionBounds.point, selectionRotation) + return Vec.RotWith(selectionBounds.center, selectionBounds.point, selectionRotation) } translateSelection(dx: number, dy: number, options?: Partial) { @@ -538,17 +534,17 @@ export class TestEditor extends Editor { ? bounds.center : bounds.getHandlePoint(rotateSelectionHandle(handle, Math.PI)) - const preRotationTargetHandlePoint = Vec2d.Add( - Vec2d.Sub(preRotationHandlePoint, preRotationScaleOriginPoint).mulV({ x: scaleX, y: scaleY }), + const preRotationTargetHandlePoint = Vec.Add( + Vec.Sub(preRotationHandlePoint, preRotationScaleOriginPoint).mulV({ x: scaleX, y: scaleY }), preRotationScaleOriginPoint ) - const handlePoint = Vec2d.RotWith( + const handlePoint = Vec.RotWith( preRotationHandlePoint, bounds.point, this.getSelectionRotation() ) - const targetHandlePoint = Vec2d.RotWith( + const targetHandlePoint = Vec.RotWith( preRotationTargetHandlePoint, bounds.point, this.getSelectionRotation() @@ -582,7 +578,7 @@ export class TestEditor extends Editor { const pageTransform = this.getShapePageTransform(shape.id) if (!pageTransform) return null const center = this.getShapeGeometry(shape).bounds.center - return Matrix2d.applyToPoint(pageTransform, center) + return Mat.applyToPoint(pageTransform, center) } /** @@ -598,7 +594,7 @@ export class TestEditor extends Editor { getPageRotationById(id: TLShapeId): number { const pageTransform = this.getShapePageTransform(id) if (pageTransform) { - return Matrix2d.Decompose(pageTransform).rotation + return Mat.Decompose(pageTransform).rotation } return 0 } @@ -631,7 +627,7 @@ export const createDefaultShapes = (): TLShapePartial[] => [ type: 'geo', x: 200, y: 200, - rotation: TAU / 2, + rotation: HALF_PI / 2, props: { w: 100, h: 100, diff --git a/packages/tldraw/src/test/__snapshots__/groups.test.ts.snap b/packages/tldraw/src/test/__snapshots__/groups.test.ts.snap index 8ee8971fa..a6e0c5d2e 100644 --- a/packages/tldraw/src/test/__snapshots__/groups.test.ts.snap +++ b/packages/tldraw/src/test/__snapshots__/groups.test.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`creating new shapes pencil lines will reisze the group appropriately if the new shape changes the group bounds: box shape after second resize 1`] = ` -Box2d { +Object { "h": 40, "w": 40, "x": -20, @@ -10,7 +10,7 @@ Box2d { `; exports[`creating new shapes pencil lines will reisze the group appropriately if the new shape changes the group bounds: group shape after second resize 1`] = ` -Box2d { +Object { "h": 120, "w": 120, "x": -20, @@ -19,7 +19,7 @@ Box2d { `; exports[`creating new shapes pencil lines will reisze the group appropriately if the new shape changes the group bounds: group with line shape 1`] = ` -Box2d { +Box { "h": 110, "w": 110, "x": -10, @@ -28,7 +28,7 @@ Box2d { `; exports[`creating new shapes pencil lines works if the shape drawing begins outside of the current group bounds: box shape after resize 1`] = ` -Box2d { +Object { "h": 50, "w": 50, "x": -100, @@ -37,7 +37,7 @@ Box2d { `; exports[`creating new shapes pencil lines works if the shape drawing begins outside of the current group bounds: group with line 1`] = ` -Box2d { +Object { "h": 200, "w": 200, "x": -100, diff --git a/packages/tldraw/src/test/arrows-megabus.test.ts b/packages/tldraw/src/test/arrows-megabus.test.ts index cf9ba5b51..4cfba92e4 100644 --- a/packages/tldraw/src/test/arrows-megabus.test.ts +++ b/packages/tldraw/src/test/arrows-megabus.test.ts @@ -1,4 +1,4 @@ -import { TLArrowShape, Vec2d, createShapeId } from '@tldraw/editor' +import { TLArrowShape, Vec, createShapeId } from '@tldraw/editor' import { TestEditor } from './TestEditor' let editor: TestEditor @@ -499,7 +499,7 @@ describe('When starting an arrow inside of multiple shapes', () => { editor.bringToFront([ids.box1]) expect( - editor.getShapeAtPoint(new Vec2d(25, 25), { + editor.getShapeAtPoint(new Vec(25, 25), { filter: (shape) => editor.getShapeUtil(shape).canBind(shape), hitInside: true, hitFrameInside: true, diff --git a/packages/tldraw/src/test/commands/alignShapes.test.tsx b/packages/tldraw/src/test/commands/alignShapes.test.tsx index 69226f701..0ec1ec9cd 100644 --- a/packages/tldraw/src/test/commands/alignShapes.test.tsx +++ b/packages/tldraw/src/test/commands/alignShapes.test.tsx @@ -1,4 +1,4 @@ -import { Box2d, PI, TLShapeId } from '@tldraw/editor' +import { Box, PI, TLShapeId } from '@tldraw/editor' import { TestEditor } from '../TestEditor' import { TL } from '../test-jsx' @@ -133,7 +133,7 @@ describe('when multiple shapes are selected', () => { editor.alignShapes(editor.getSelectedShapeIds(), 'center-horizontal') jest.advanceTimersByTime(1000) - const commonBounds = Box2d.Common([ + const commonBounds = Box.Common([ editor.getShapePageBounds(ids.boxA)!, editor.getShapePageBounds(ids.boxB)!, editor.getShapePageBounds(ids.boxC)!, @@ -172,7 +172,7 @@ describe('when multiple shapes are selected', () => { editor.alignShapes(editor.getSelectedShapeIds(), 'left') jest.advanceTimersByTime(1000) - const commonBounds = Box2d.Common([ + const commonBounds = Box.Common([ editor.getShapePageBounds(ids.boxA)!, editor.getShapePageBounds(ids.boxB)!, editor.getShapePageBounds(ids.boxC)!, @@ -212,7 +212,7 @@ describe('when multiple shapes are selected', () => { editor.alignShapes(editor.getSelectedShapeIds(), 'right') jest.advanceTimersByTime(1000) - const commonBounds = Box2d.Common([ + const commonBounds = Box.Common([ editor.getShapePageBounds(ids.boxA)!, editor.getShapePageBounds(ids.boxC)!, ]) @@ -245,7 +245,7 @@ describe('When shapes are parented to other shapes...', () => { it('Aligns to the top left.', () => { editor.setSelectedShapes([ids.boxC, ids.boxB]) - const commonBoundsBefore = Box2d.Common([ + const commonBoundsBefore = Box.Common([ editor.getShapePageBounds(ids.boxC)!, editor.getShapePageBounds(ids.boxB)!, ]) @@ -255,7 +255,7 @@ describe('When shapes are parented to other shapes...', () => { editor.alignShapes(editor.getSelectedShapeIds(), 'left') jest.advanceTimersByTime(1000) - const commonBoundsAfter = Box2d.Common([ + const commonBoundsAfter = Box.Common([ editor.getShapePageBounds(ids.boxC)!, editor.getShapePageBounds(ids.boxB)!, ]) @@ -267,7 +267,7 @@ describe('When shapes are parented to other shapes...', () => { it('Aligns to the bottom right.', () => { editor.setSelectedShapes([ids.boxC, ids.boxB]) - const commonBoundsBefore = Box2d.Common([ + const commonBoundsBefore = Box.Common([ editor.getShapePageBounds(ids.boxC)!, editor.getShapePageBounds(ids.boxB)!, ]) @@ -277,7 +277,7 @@ describe('When shapes are parented to other shapes...', () => { editor.alignShapes(editor.getSelectedShapeIds(), 'right') jest.advanceTimersByTime(1000) - const commonBoundsAfter = Box2d.Common([ + const commonBoundsAfter = Box.Common([ editor.getShapePageBounds(ids.boxC)!, editor.getShapePageBounds(ids.boxB)!, ]) @@ -333,7 +333,7 @@ describe('When shapes are parented to a rotated shape...', () => { it('Aligns to the top left.', () => { editor.setSelectedShapes([ids.boxC, ids.boxB]) - const commonBoundsBefore = Box2d.Common([ + const commonBoundsBefore = Box.Common([ editor.getShapePageBounds(ids.boxC)!, editor.getShapePageBounds(ids.boxB)!, ]) @@ -343,7 +343,7 @@ describe('When shapes are parented to a rotated shape...', () => { editor.alignShapes(editor.getSelectedShapeIds(), 'left') jest.advanceTimersByTime(1000) - const commonBoundsAfter = Box2d.Common([ + const commonBoundsAfter = Box.Common([ editor.getShapePageBounds(ids.boxC)!, editor.getShapePageBounds(ids.boxB)!, ]) @@ -361,7 +361,7 @@ describe('When shapes are parented to a rotated shape...', () => { it('Aligns to the bottom right.', () => { editor.setSelectedShapes([ids.boxC, ids.boxB]) - const commonBoundsBefore = Box2d.Common([ + const commonBoundsBefore = Box.Common([ editor.getShapePageBounds(ids.boxC)!, editor.getShapePageBounds(ids.boxB)!, ]) @@ -371,7 +371,7 @@ describe('When shapes are parented to a rotated shape...', () => { editor.alignShapes(editor.getSelectedShapeIds(), 'right') jest.advanceTimersByTime(1000) - const commonBoundsAfter = Box2d.Common([ + const commonBoundsAfter = Box.Common([ editor.getShapePageBounds(ids.boxC)!, editor.getShapePageBounds(ids.boxB)!, ]) diff --git a/packages/tldraw/src/test/commands/pan.test.ts b/packages/tldraw/src/test/commands/pan.test.ts index 12a1d4564..f3bad0be1 100644 --- a/packages/tldraw/src/test/commands/pan.test.ts +++ b/packages/tldraw/src/test/commands/pan.test.ts @@ -1,4 +1,4 @@ -import { Box2d, Vec2d } from '@tldraw/editor' +import { Box, Vec } from '@tldraw/editor' import { TestEditor, createDefaultShapes } from '../TestEditor' let editor: TestEditor @@ -16,7 +16,7 @@ describe('When panning', () => { it('Updates the pageBounds', () => { const screenBounds = editor.getViewportScreenBounds() - const beforeScreenBounds = new Box2d( + const beforeScreenBounds = new Box( screenBounds.x, screenBounds.y, screenBounds.w, @@ -26,7 +26,7 @@ describe('When panning', () => { editor.pan({ x: 200, y: 200 }) expect(editor.getViewportScreenBounds()).toMatchObject(beforeScreenBounds.toJson()) expect(editor.getViewportPageBounds().toJson()).toMatchObject( - beforePageBounds.translate(new Vec2d(-200, -200)).toJson() + beforePageBounds.translate(new Vec(-200, -200)).toJson() ) }) }) diff --git a/packages/tldraw/src/test/commands/penmode.test.ts b/packages/tldraw/src/test/commands/penmode.test.ts index 36daec455..b60e5b388 100644 --- a/packages/tldraw/src/test/commands/penmode.test.ts +++ b/packages/tldraw/src/test/commands/penmode.test.ts @@ -1,4 +1,4 @@ -import { Vec2d } from '@tldraw/editor' +import { Vec } from '@tldraw/editor' import { TestEditor } from '../TestEditor' let editor: TestEditor @@ -15,7 +15,7 @@ it('ignores touch events while in pen mode', async () => { name: 'pointer_down', isPen: false, pointerId: 1, - point: new Vec2d(100, 100), + point: new Vec(100, 100), shiftKey: false, altKey: false, ctrlKey: false, diff --git a/packages/tldraw/src/test/commands/zoomToBounds.test.ts b/packages/tldraw/src/test/commands/zoomToBounds.test.ts index 42eb58dc3..42b6f1555 100644 --- a/packages/tldraw/src/test/commands/zoomToBounds.test.ts +++ b/packages/tldraw/src/test/commands/zoomToBounds.test.ts @@ -1,4 +1,4 @@ -import { Box2d } from '@tldraw/editor' +import { Box } from '@tldraw/editor' import { TestEditor } from '../TestEditor' let editor: TestEditor @@ -24,7 +24,7 @@ describe('When zooming to bounds', () => { h: 1000, }) - editor.zoomToBounds(new Box2d(200, 300, 300, 300)) + editor.zoomToBounds(new Box(200, 300, 300, 300)) expect(editor.getCamera().z).toCloselyMatchObject((1000 - 256) / 300) expect(editor.getViewportPageBounds().width).toCloselyMatchObject(1000 / ((1000 - 256) / 300)) expect(editor.getViewportPageBounds().height).toCloselyMatchObject(1000 / ((1000 - 256) / 300)) @@ -32,12 +32,12 @@ describe('When zooming to bounds', () => { }) it('does not zoom past max', () => { - editor.zoomToBounds(new Box2d(0, 0, 1, 1)) + editor.zoomToBounds(new Box(0, 0, 1, 1)) expect(editor.getZoomLevel()).toBe(8) }) it('does not zoom past min', () => { - editor.zoomToBounds(new Box2d(0, 0, 1000000, 100000)) + editor.zoomToBounds(new Box(0, 0, 1000000, 100000)) expect(editor.getZoomLevel()).toBe(0.1) }) @@ -45,6 +45,6 @@ it('does not zoom to bounds when camera is frozen', () => { editor.setScreenBounds({ x: 0, y: 0, w: 1000, h: 1000 }) expect(editor.getViewportPageCenter().toJson()).toCloselyMatchObject({ x: 500, y: 500 }) editor.updateInstanceState({ canMoveCamera: false }) - editor.zoomToBounds(new Box2d(200, 300, 300, 300)) + editor.zoomToBounds(new Box(200, 300, 300, 300)) expect(editor.getViewportPageCenter().toJson()).toCloselyMatchObject({ x: 500, y: 500 }) }) diff --git a/packages/tldraw/src/test/flipShapes.test.ts b/packages/tldraw/src/test/flipShapes.test.ts index 81239cf62..f9681132a 100644 --- a/packages/tldraw/src/test/flipShapes.test.ts +++ b/packages/tldraw/src/test/flipShapes.test.ts @@ -1,5 +1,5 @@ import { - Matrix2d, + Mat, PI, TLArrowShape, TLArrowShapeProps, @@ -410,8 +410,8 @@ describe('flipping rotated shapes', () => { const arrow = editor.getShape(id)! if (arrow.props.start.type !== 'point' || arrow.props.end.type !== 'point') throw new Error('not a point') - const start = Matrix2d.applyToPoint(transform, arrow.props.start) - const end = Matrix2d.applyToPoint(transform, arrow.props.end) + const start = Mat.applyToPoint(transform, arrow.props.start) + const end = Mat.applyToPoint(transform, arrow.props.end) return { start, end } } diff --git a/packages/tldraw/src/test/groups.test.ts b/packages/tldraw/src/test/groups.test.ts index 9e0e58252..422937996 100644 --- a/packages/tldraw/src/test/groups.test.ts +++ b/packages/tldraw/src/test/groups.test.ts @@ -1,5 +1,5 @@ import { - Box2d, + Box, GroupShapeUtil, TLArrowShape, TLGroupShape, @@ -1276,7 +1276,7 @@ describe('creating new shapes', () => { } editor.pointerUp() - const roundToNearestTen = (vals: Box2d) => { + const roundToNearestTen = (vals: Box) => { return { x: Math.round(vals.x / 10) * 10, y: Math.round(vals.y / 10) * 10, @@ -1304,7 +1304,7 @@ describe('creating new shapes', () => { } editor.pointerUp() - const roundToNearestTen = (vals: Box2d) => { + const roundToNearestTen = (vals: Box) => { return { x: Math.round(vals.x / 10) * 10, y: Math.round(vals.y / 10) * 10, @@ -1356,11 +1356,13 @@ describe('creating new shapes', () => { expect(editor.getShapePageBounds(groupA.id)).toMatchSnapshot('group with line shape') editor.pointerMove(-20, -20).pointerUp(-20, -20) - expect(editor.getShapePageBounds(groupA.id)).toMatchSnapshot( + expect(editor.getShapePageBounds(groupA.id)!.toJson()).toMatchSnapshot( 'group shape after second resize' ) const boxC = onlySelectedShape() - expect(editor.getShapePageBounds(boxC.id)).toMatchSnapshot('box shape after second resize') + expect(editor.getShapePageBounds(boxC.id)!.toJson()).toMatchSnapshot( + 'box shape after second resize' + ) }) it('works if the shape drawing begins outside of the current group bounds', () => { @@ -1370,10 +1372,12 @@ describe('creating new shapes', () => { editor.setCurrentTool('line') editor.pointerDown(-50, -50).pointerMove(-100, -100).pointerUp() - expect(editor.getShapePageBounds(groupA.id)).toMatchSnapshot('group with line') + expect(editor.getShapePageBounds(groupA.id)!.toJson()).toMatchSnapshot('group with line') const boxC = onlySelectedShape() - expect(editor.getShapePageBounds(boxC.id)).toMatchSnapshot('box shape after resize') + expect(editor.getShapePageBounds(boxC.id)!.toJson()).toMatchSnapshot( + 'box shape after resize' + ) }) }) diff --git a/packages/tldraw/src/test/resizeBox.test.ts b/packages/tldraw/src/test/resizeBox.test.ts index 3e6ea73b5..6f869a5b2 100644 --- a/packages/tldraw/src/test/resizeBox.test.ts +++ b/packages/tldraw/src/test/resizeBox.test.ts @@ -1,4 +1,4 @@ -import { Box2d, TLGeoShape, createShapeId, resizeBox } from '@tldraw/editor' +import { Box, TLGeoShape, createShapeId, resizeBox } from '@tldraw/editor' import { TestEditor } from './TestEditor' let editor: TestEditor @@ -31,7 +31,7 @@ describe('Resize box', () => { mode: 'resize_bounds', scaleX: 1.5, scaleY: 1.5, - initialBounds: new Box2d(0, 0, 100, 100), + initialBounds: new Box(0, 0, 100, 100), initialShape: shape, }) expect(results).toMatchObject({ @@ -51,7 +51,7 @@ describe('Resize box', () => { mode: 'resize_bounds', scaleX: 1.5, scaleY: 1.5, - initialBounds: new Box2d(0, 0, 100, 100), + initialBounds: new Box(0, 0, 100, 100), initialShape: shape, }) expect(results).toMatchObject({ @@ -71,7 +71,7 @@ describe('Resize box', () => { mode: 'resize_bounds', scaleX: 1.5, scaleY: 1.5, - initialBounds: new Box2d(0, 0, 100, 100), + initialBounds: new Box(0, 0, 100, 100), initialShape: shape, }) expect(results).toMatchObject({ @@ -91,7 +91,7 @@ describe('Resize box', () => { mode: 'resize_bounds', scaleX: 1.5, scaleY: 1.5, - initialBounds: new Box2d(0, 0, 100, 100), + initialBounds: new Box(0, 0, 100, 100), initialShape: shape, }) expect(results).toMatchObject({ diff --git a/packages/tldraw/src/test/resizing.test.ts b/packages/tldraw/src/test/resizing.test.ts index 81d95dab5..47ff98f29 100644 --- a/packages/tldraw/src/test/resizing.test.ts +++ b/packages/tldraw/src/test/resizing.test.ts @@ -1,5 +1,4 @@ import { - EPSILON, GapsSnapLine, PI, PI2, @@ -9,7 +8,7 @@ import { TLSelectionHandle, TLShapeId, TLShapePartial, - Vec2d, + Vec, canonicalizeRotation, createShapeId, rotateSelectionHandle, @@ -235,7 +234,7 @@ describe('When resizing a rotated shape...', () => { Math.PI / 2, // Math.PI / 4, Math.PI ])('Resizes a shape rotated %i from the top left', (rotation) => { - const offset = new Vec2d(10, 10) + const offset = new Vec(10, 10) // Rotate the shape by $rotation from its top left corner @@ -243,9 +242,9 @@ describe('When resizing a rotated shape...', () => { const initialPagePoint = editor.getShapePageTransform(ids.boxA)!.point() - const pt0 = Vec2d.From(initialPagePoint) - const pt1 = Vec2d.RotWith(initialPagePoint, editor.getSelectionPageBounds()!.center, rotation) - const pt2 = Vec2d.Sub(initialPagePoint, offset).rotWith( + const pt0 = Vec.From(initialPagePoint) + const pt1 = Vec.RotWith(initialPagePoint, editor.getSelectionPageBounds()!.center, rotation) + const pt2 = Vec.Sub(initialPagePoint, offset).rotWith( editor.getSelectionPageBounds()!.center!, rotation ) @@ -265,9 +264,7 @@ describe('When resizing a rotated shape...', () => { // Resize by moving the top left resize handle to pt2. Should be a delta of [10, 10]. - expect(Vec2d.Dist(editor.getShapePageTransform(ids.boxA)!.point(), pt2)).toBeCloseTo( - offset.len() - ) + expect(Vec.Dist(editor.getShapePageTransform(ids.boxA)!.point(), pt2)).toBeCloseTo(offset.len()) editor .pointerDown(pt1.x, pt1.y, { @@ -327,7 +324,7 @@ describe('When resizing mulitple shapes...', () => { const rotateStart = editor.getShapePageTransform(ids.boxA)!.point() const rotateCenter = editor.getPageCenter(shapeA)! - const rotateEnd = Vec2d.RotWith(rotateStart, rotateCenter, rotation) + const rotateEnd = Vec.RotWith(rotateStart, rotateCenter, rotation) editor .select(ids.boxA) @@ -353,16 +350,13 @@ describe('When resizing mulitple shapes...', () => { // oddly rotated shapes maintain aspect ratio when being resized (for now) const aspectRatio = initialBounds.width / initialBounds.height const offsetX = initialBounds.width + 200 - const offset = new Vec2d(offsetX, offsetX / aspectRatio) + const offset = new Vec(offsetX, offsetX / aspectRatio) const resizeStart = initialBounds.point - const resizeEnd = Vec2d.Sub(resizeStart, offset) + const resizeEnd = Vec.Sub(resizeStart, offset) - expect(Vec2d.Dist(resizeStart, resizeEnd)).toBeCloseTo(offset.len()) + expect(Vec.Dist(resizeStart, resizeEnd)).toBeCloseTo(offset.len()) expect( - Vec2d.Min( - editor.getShapePageBounds(shapeB)!.point, - editor.getShapePageBounds(shapeC)!.point - ) + Vec.Min(editor.getShapePageBounds(shapeB)!.point, editor.getShapePageBounds(shapeC)!.point) ).toCloselyMatchObject(resizeStart) editor @@ -375,8 +369,8 @@ describe('When resizing mulitple shapes...', () => { .pointerUp() expect(editor.getSelectionPageBounds()!.point).toCloselyMatchObject(resizeEnd) - expect(new Vec2d(initialBounds.maxX, initialBounds.maxY)).toCloselyMatchObject( - new Vec2d(editor.getSelectionPageBounds()!.maxX, editor.getSelectionPageBounds()!.maxY) + expect(new Vec(initialBounds.maxX, initialBounds.maxY)).toCloselyMatchObject( + new Vec(editor.getSelectionPageBounds()!.maxX, editor.getSelectionPageBounds()!.maxY) ) } ) @@ -3453,7 +3447,7 @@ describe('resizing a selection of mixed rotations', () => { expect(roundedPageBounds(ids.boxD)).toMatchObject({ x: 0, y: 20, w: 20, h: 5 }) }) it('does lock the aspect ratio if the rotations are not compatible', () => { - editor.updateShapes([{ id: ids.boxC, type: 'geo', rotation: Math.PI + EPSILON }]) + editor.updateShapes([{ id: ids.boxC, type: 'geo', rotation: Math.PI + Math.PI / 180 }]) editor.select(ids.boxA, ids.boxB, ids.boxC, ids.boxD) editor.pointerDown(50, 50, { target: 'selection', handle: 'bottom_right' }).pointerMove(100, 25) expect(roundedPageBounds(ids.boxA, 0.5)).toMatchObject({ x: 0, y: 0, w: 20, h: 20 }) @@ -3461,7 +3455,7 @@ describe('resizing a selection of mixed rotations', () => { it('does lock the aspect ratio if one of the shapes has a child with an incompatible aspect ratio', () => { editor.updateShapes([ - { id: ids.boxC, type: 'geo', rotation: Math.PI + EPSILON, parentId: ids.boxA }, + { id: ids.boxC, type: 'geo', rotation: Math.PI + Math.PI / 180, parentId: ids.boxA }, ]) editor.select(ids.boxA, ids.boxB, ids.boxD) diff --git a/packages/tldraw/src/test/rotating.test.ts b/packages/tldraw/src/test/rotating.test.ts index 7c462ec34..6a9fa3524 100644 --- a/packages/tldraw/src/test/rotating.test.ts +++ b/packages/tldraw/src/test/rotating.test.ts @@ -1,4 +1,4 @@ -import { Vec2d, createShapeId } from '@tldraw/editor' +import { Vec, createShapeId } from '@tldraw/editor' import { TestEditor } from './TestEditor' let editor: TestEditor @@ -122,7 +122,7 @@ describe('When rotating...', () => { const box = editor.getSelectionPageBounds()! const center = box.center.clone().toFixed() - expect(Vec2d.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject(center) + expect(Vec.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject(center) editor .pointerDown(box.midX, box.minY, { @@ -132,19 +132,19 @@ describe('When rotating...', () => { .pointerMove(box.maxX, box.midY) .expectShapeToMatch({ id: ids.box1, rotation: Math.PI * 0.5 }) - expect(Vec2d.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject(center) + expect(Vec.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject(center) editor .pointerMove(box.midY, box.maxY) .expectShapeToMatch({ id: ids.box1, rotation: Math.PI * 1.0 }) - expect(Vec2d.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject(center) + expect(Vec.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject(center) editor .pointerMove(box.minX, box.midY) .expectShapeToMatch({ id: ids.box1, rotation: Math.PI * 1.5 }) - expect(Vec2d.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject(center) + expect(Vec.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject(center) // Preserves the selection bounds same center expect(center).toMatchObject(box.center) @@ -167,19 +167,19 @@ describe('When rotating...', () => { handle: 'top_left_rotate', }) - const next = Vec2d.RotWith(new Vec2d(box.midX, box.minY), center, Math.PI * 0.5) + const next = Vec.RotWith(new Vec(box.midX, box.minY), center, Math.PI * 0.5) editor .pointerMove(next.x, next.y) .expectShapeToMatch({ id: ids.box1, rotation: Math.PI * 0.5 }) .expectShapeToMatch({ id: ids.box2, rotation: Math.PI * 0.5 }) - expect(Vec2d.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject( - Vec2d.RotWith(centerA, center, Math.PI * 0.5).toFixed() + expect(Vec.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject( + Vec.RotWith(centerA, center, Math.PI * 0.5).toFixed() ) - expect(Vec2d.ToFixed(editor.getPageCenter(shapeB)!)).toMatchObject( - Vec2d.RotWith(centerB, center, Math.PI * 0.5).toFixed() + expect(Vec.ToFixed(editor.getPageCenter(shapeB)!)).toMatchObject( + Vec.RotWith(centerB, center, Math.PI * 0.5).toFixed() ) editor @@ -189,11 +189,11 @@ describe('When rotating...', () => { { id: ids.box2, rotation: Math.PI * 1.0 } ) - expect(Vec2d.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject( - Vec2d.RotWith(centerA, center, Math.PI).toFixed() + expect(Vec.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject( + Vec.RotWith(centerA, center, Math.PI).toFixed() ) - expect(Vec2d.ToFixed(editor.getPageCenter(shapeB)!)).toMatchObject( - Vec2d.RotWith(centerB, center, Math.PI).toFixed() + expect(Vec.ToFixed(editor.getPageCenter(shapeB)!)).toMatchObject( + Vec.RotWith(centerB, center, Math.PI).toFixed() ) editor @@ -203,11 +203,11 @@ describe('When rotating...', () => { { id: ids.box2, rotation: Math.PI * 1.5 } ) - expect(Vec2d.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject( - Vec2d.RotWith(centerA, center, Math.PI * 1.5).toFixed() + expect(Vec.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject( + Vec.RotWith(centerA, center, Math.PI * 1.5).toFixed() ) - expect(Vec2d.ToFixed(editor.getPageCenter(shapeB)!)).toMatchObject( - Vec2d.RotWith(centerB, center, Math.PI * 1.5).toFixed() + expect(Vec.ToFixed(editor.getPageCenter(shapeB)!)).toMatchObject( + Vec.RotWith(centerB, center, Math.PI * 1.5).toFixed() ) // Preserves the selection bounds same center @@ -237,7 +237,7 @@ describe('When rotating...', () => { { id: ids.box2, x: 200, y: 200, rotation: 0 } ) - expect(Vec2d.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject(centerA.toFixed()) + expect(Vec.ToFixed(editor.getPageCenter(shapeA)!)).toMatchObject(centerA.toFixed()) // Preserves the selection bounds same center expect(center).toMatchObject(box.center) @@ -304,16 +304,16 @@ describe('When rotating...', () => { describe('Rotation math', () => { it('rotates one point around another', () => { - const a = new Vec2d(100, 100) - const b = new Vec2d(200, 200) + const a = new Vec(100, 100) + const b = new Vec(200, 200) expect( - Vec2d.RotWith(a, b, Math.PI / 2) + Vec.RotWith(a, b, Math.PI / 2) .toFixed() .toJson() ).toMatchObject({ x: 300, y: 100 }) - expect(Vec2d.RotWith(a, b, Math.PI).toFixed().toJson()).toMatchObject({ x: 300, y: 300 }) + expect(Vec.RotWith(a, b, Math.PI).toFixed().toJson()).toMatchObject({ x: 300, y: 300 }) expect( - Vec2d.RotWith(a, b, Math.PI * 1.5) + Vec.RotWith(a, b, Math.PI * 1.5) .toFixed() .toJson() ).toMatchObject({ x: 100, y: 300 }) diff --git a/packages/tldraw/src/test/roundedBox.ts b/packages/tldraw/src/test/roundedBox.ts index bfd1c78cb..361338094 100644 --- a/packages/tldraw/src/test/roundedBox.ts +++ b/packages/tldraw/src/test/roundedBox.ts @@ -1,10 +1,10 @@ -import { Box2d } from '@tldraw/editor' +import { Box } from '@tldraw/editor' -export const roundedBox = (box: Box2d, accuracy = 0.01) => { +export const roundedBox = (box: Box, accuracy = 0.01) => { // for some reason jest treats -0 and 0 as not equal, so prevent -0s from appearing const noNegativeZero = (value: number) => (value === 0 ? 0 : value) - return new Box2d( + return new Box( noNegativeZero(Math.round(box.x / accuracy) * accuracy), noNegativeZero(Math.round(box.y / accuracy) * accuracy), noNegativeZero(Math.round(box.w / accuracy) * accuracy), diff --git a/packages/tldraw/src/test/testutils/roundedBox.ts b/packages/tldraw/src/test/testutils/roundedBox.ts index bfd1c78cb..361338094 100644 --- a/packages/tldraw/src/test/testutils/roundedBox.ts +++ b/packages/tldraw/src/test/testutils/roundedBox.ts @@ -1,10 +1,10 @@ -import { Box2d } from '@tldraw/editor' +import { Box } from '@tldraw/editor' -export const roundedBox = (box: Box2d, accuracy = 0.01) => { +export const roundedBox = (box: Box, accuracy = 0.01) => { // for some reason jest treats -0 and 0 as not equal, so prevent -0s from appearing const noNegativeZero = (value: number) => (value === 0 ? 0 : value) - return new Box2d( + return new Box( noNegativeZero(Math.round(box.x / accuracy) * accuracy), noNegativeZero(Math.round(box.y / accuracy) * accuracy), noNegativeZero(Math.round(box.w / accuracy) * accuracy), diff --git a/packages/tldraw/src/test/translating.test.ts b/packages/tldraw/src/test/translating.test.ts index d21341a0e..b0dfaf65c 100644 --- a/packages/tldraw/src/test/translating.test.ts +++ b/packages/tldraw/src/test/translating.test.ts @@ -6,7 +6,7 @@ import { TLGeoShape, TLShapeId, TLShapePartial, - Vec2d, + Vec, createShapeId, } from '@tldraw/editor' import { TestEditor } from './TestEditor' @@ -394,17 +394,17 @@ describe('When translating shapes that are descendants of a rotated shape...', ( const shapeA = editor.getShape(ids.box1)! const shapeD = editor.getShape(ids.boxD)! - expect(editor.getPageCenter(shapeA)).toMatchObject(new Vec2d(60, 60)) - expect(editor.getShapeGeometry(shapeD).center).toMatchObject(new Vec2d(5, 5)) - expect(editor.getPageCenter(shapeD)).toMatchObject(new Vec2d(35, 35)) + expect(editor.getPageCenter(shapeA)).toMatchObject(new Vec(60, 60)) + expect(editor.getShapeGeometry(shapeD).center).toMatchObject(new Vec(5, 5)) + expect(editor.getPageCenter(shapeD)).toMatchObject(new Vec(35, 35)) const rads = 0 - expect(editor.getPageCenter(shapeA)).toMatchObject(new Vec2d(60, 60)) + expect(editor.getPageCenter(shapeA)).toMatchObject(new Vec(60, 60)) // Expect the node's page position to be rotated around its parent's page center expect(editor.getPageCenter(shapeD)).toMatchObject( - new Vec2d(35, 35).rotWith(editor.getPageCenter(shapeA)!, rads) + new Vec(35, 35).rotWith(editor.getPageCenter(shapeA)!, rads) ) const centerD = editor.getPageCenter(shapeD)!.clone().toFixed() @@ -416,7 +416,7 @@ describe('When translating shapes that are descendants of a rotated shape...', ( .pointerMove(centerD.x, centerD.y - 10) .pointerUp() - expect(editor.getPageCenter(shapeD)).toMatchObject(new Vec2d(centerD.x, centerD.y - 10)) + expect(editor.getPageCenter(shapeD)).toMatchObject(new Vec(centerD.x, centerD.y - 10)) const centerA = editor.getPageCenter(shapeA)!.clone().toFixed() diff --git a/packages/tlschema/api-report.md b/packages/tlschema/api-report.md index df7f2034b..887eab690 100644 --- a/packages/tlschema/api-report.md +++ b/packages/tlschema/api-report.md @@ -41,7 +41,7 @@ export const arrowShapeProps: { binding: T.ObjectValidator<{ type: "binding"; boundShapeId: TLShapeId; - normalizedAnchor: Vec2dModel; + normalizedAnchor: VecModel; isExact: boolean; isPrecise: boolean; }>; @@ -55,7 +55,7 @@ export const arrowShapeProps: { binding: T.ObjectValidator<{ type: "binding"; boundShapeId: TLShapeId; - normalizedAnchor: Vec2dModel; + normalizedAnchor: VecModel; isExact: boolean; isPrecise: boolean; }>; @@ -93,7 +93,7 @@ export const bookmarkShapeProps: { }; // @public -export interface Box2dModel { +export interface BoxModel { // (undocumented) h: number; // (undocumented) @@ -105,7 +105,7 @@ export interface Box2dModel { } // @public (undocumented) -export const box2dModelValidator: T.Validator; +export const boxModelValidator: T.Validator; // @public (undocumented) export const CameraRecordType: RecordType; @@ -193,7 +193,7 @@ export const drawShapeProps: { size: EnumStyleProp<"l" | "m" | "s" | "xl">; segments: T.ArrayOfValidator<{ type: "free" | "straight"; - points: Vec2dModel[]; + points: VecModel[]; }>; isComplete: T.Validator; isClosed: T.Validator; @@ -512,7 +512,7 @@ export const highlightShapeProps: { size: EnumStyleProp<"l" | "m" | "s" | "xl">; segments: T.ArrayOfValidator<{ type: "free" | "straight"; - points: Vec2dModel[]; + points: VecModel[]; }>; isComplete: T.Validator; isPen: T.Validator; @@ -532,8 +532,8 @@ export const imageShapeProps: { url: T.Validator; assetId: T.Validator; crop: T.Validator<{ - topLeft: Vec2dModel; - bottomRight: Vec2dModel; + topLeft: VecModel; + bottomRight: VecModel; } | null>; }; @@ -998,7 +998,7 @@ export type TLImageShapeProps = ShapePropsType; // @public export interface TLInstance extends BaseRecord<'instance', TLInstanceId> { // (undocumented) - brush: Box2dModel | null; + brush: BoxModel | null; // (undocumented) canMoveCamera: boolean; // (undocumented) @@ -1043,13 +1043,13 @@ export interface TLInstance extends BaseRecord<'instance', TLInstanceId> { // (undocumented) openMenus: string[]; // (undocumented) - screenBounds: Box2dModel; + screenBounds: BoxModel; // (undocumented) scribbles: TLScribble[]; // (undocumented) stylesForNextShape: Record; // (undocumented) - zoomBrush: Box2dModel | null; + zoomBrush: BoxModel | null; } // @public (undocumented) @@ -1083,7 +1083,7 @@ export interface TLInstancePageState extends BaseRecord<'instance_page_state', T // @public (undocumented) export interface TLInstancePresence extends BaseRecord<'instance_presence', TLInstancePresenceID> { // (undocumented) - brush: Box2dModel | null; + brush: BoxModel | null; // (undocumented) camera: { x: number; @@ -1110,7 +1110,7 @@ export interface TLInstancePresence extends BaseRecord<'instance_presence', TLIn // (undocumented) meta: JsonObject; // (undocumented) - screenBounds: Box2dModel; + screenBounds: BoxModel; // (undocumented) scribbles: TLScribble[]; // (undocumented) @@ -1161,7 +1161,7 @@ export type TLSchema = StoreSchema; // @public export type TLScribble = { id: string; - points: Vec2dModel[]; + points: VecModel[]; size: number; color: TLCanvasUiColor; opacity: number; @@ -1231,7 +1231,7 @@ export type TLVideoAsset = TLBaseAsset<'video', { export type TLVideoShape = TLBaseShape<'video', TLVideoShapeProps>; // @public -export interface Vec2dModel { +export interface VecModel { // (undocumented) x: number; // (undocumented) @@ -1241,7 +1241,7 @@ export interface Vec2dModel { } // @public (undocumented) -export const vec2dModelValidator: T.Validator; +export const vecModelValidator: T.Validator; // @internal (undocumented) export const videoShapeMigrations: Migrations; diff --git a/packages/tlschema/api/api.json b/packages/tlschema/api/api.json index 7f1e668e6..8ee36440e 100644 --- a/packages/tlschema/api/api.json +++ b/packages/tlschema/api/api.json @@ -350,8 +350,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -395,8 +395,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -587,22 +587,22 @@ }, { "kind": "Interface", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface", "docComment": "/**\n * A serializable model for 2D boxes.\n *\n * @public\n */\n", "excerptTokens": [ { "kind": "Content", - "text": "export interface Box2dModel " + "text": "export interface BoxModel " } ], "fileUrlPath": "packages/tlschema/src/misc/geometry-types.ts", "releaseTag": "Public", - "name": "Box2dModel", + "name": "BoxModel", "preserveMemberOrder": false, "members": [ { "kind": "PropertySignature", - "canonicalReference": "@tldraw/tlschema!Box2dModel#h:member", + "canonicalReference": "@tldraw/tlschema!BoxModel#h:member", "docComment": "", "excerptTokens": [ { @@ -629,7 +629,7 @@ }, { "kind": "PropertySignature", - "canonicalReference": "@tldraw/tlschema!Box2dModel#w:member", + "canonicalReference": "@tldraw/tlschema!BoxModel#w:member", "docComment": "", "excerptTokens": [ { @@ -656,7 +656,7 @@ }, { "kind": "PropertySignature", - "canonicalReference": "@tldraw/tlschema!Box2dModel#x:member", + "canonicalReference": "@tldraw/tlschema!BoxModel#x:member", "docComment": "", "excerptTokens": [ { @@ -683,7 +683,7 @@ }, { "kind": "PropertySignature", - "canonicalReference": "@tldraw/tlschema!Box2dModel#y:member", + "canonicalReference": "@tldraw/tlschema!BoxModel#y:member", "docComment": "", "excerptTokens": [ { @@ -713,12 +713,12 @@ }, { "kind": "Variable", - "canonicalReference": "@tldraw/tlschema!box2dModelValidator:var", + "canonicalReference": "@tldraw/tlschema!boxModelValidator:var", "docComment": "/**\n * @public\n */\n", "excerptTokens": [ { "kind": "Content", - "text": "box2dModelValidator: " + "text": "boxModelValidator: " }, { "kind": "Reference", @@ -731,8 +731,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -742,7 +742,7 @@ "fileUrlPath": "packages/tlschema/src/misc/geometry-types.ts", "isReadonly": true, "releaseTag": "Public", - "name": "box2dModelValidator", + "name": "boxModelValidator", "variableTypeTokenRange": { "startIndex": 1, "endIndex": 5 @@ -1684,8 +1684,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -2290,8 +2290,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -2403,8 +2403,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -2412,8 +2412,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -6460,8 +6460,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -7090,8 +7090,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -7182,8 +7182,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -7637,8 +7637,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -7896,8 +7896,8 @@ }, { "kind": "Reference", - "text": "Box2dModel", - "canonicalReference": "@tldraw/tlschema!Box2dModel:interface" + "text": "BoxModel", + "canonicalReference": "@tldraw/tlschema!BoxModel:interface" }, { "kind": "Content", @@ -8570,8 +8570,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -9263,22 +9263,22 @@ }, { "kind": "Interface", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface", + "canonicalReference": "@tldraw/tlschema!VecModel:interface", "docComment": "/**\n * A serializable model for 2D vectors.\n *\n * @public\n */\n", "excerptTokens": [ { "kind": "Content", - "text": "export interface Vec2dModel " + "text": "export interface VecModel " } ], "fileUrlPath": "packages/tlschema/src/misc/geometry-types.ts", "releaseTag": "Public", - "name": "Vec2dModel", + "name": "VecModel", "preserveMemberOrder": false, "members": [ { "kind": "PropertySignature", - "canonicalReference": "@tldraw/tlschema!Vec2dModel#x:member", + "canonicalReference": "@tldraw/tlschema!VecModel#x:member", "docComment": "", "excerptTokens": [ { @@ -9305,7 +9305,7 @@ }, { "kind": "PropertySignature", - "canonicalReference": "@tldraw/tlschema!Vec2dModel#y:member", + "canonicalReference": "@tldraw/tlschema!VecModel#y:member", "docComment": "", "excerptTokens": [ { @@ -9332,7 +9332,7 @@ }, { "kind": "PropertySignature", - "canonicalReference": "@tldraw/tlschema!Vec2dModel#z:member", + "canonicalReference": "@tldraw/tlschema!VecModel#z:member", "docComment": "", "excerptTokens": [ { @@ -9362,12 +9362,12 @@ }, { "kind": "Variable", - "canonicalReference": "@tldraw/tlschema!vec2dModelValidator:var", + "canonicalReference": "@tldraw/tlschema!vecModelValidator:var", "docComment": "/**\n * @public\n */\n", "excerptTokens": [ { "kind": "Content", - "text": "vec2dModelValidator: " + "text": "vecModelValidator: " }, { "kind": "Reference", @@ -9380,8 +9380,8 @@ }, { "kind": "Reference", - "text": "Vec2dModel", - "canonicalReference": "@tldraw/tlschema!Vec2dModel:interface" + "text": "VecModel", + "canonicalReference": "@tldraw/tlschema!VecModel:interface" }, { "kind": "Content", @@ -9391,7 +9391,7 @@ "fileUrlPath": "packages/tlschema/src/misc/geometry-types.ts", "isReadonly": true, "releaseTag": "Public", - "name": "vec2dModelValidator", + "name": "vecModelValidator", "variableTypeTokenRange": { "startIndex": 1, "endIndex": 5 diff --git a/packages/tlschema/src/index.ts b/packages/tlschema/src/index.ts index 1c8b48eda..9aef3104e 100644 --- a/packages/tlschema/src/index.ts +++ b/packages/tlschema/src/index.ts @@ -21,10 +21,10 @@ export { type TLHandle, type TLHandleType } from './misc/TLHandle' export { opacityValidator, type TLOpacityType } from './misc/TLOpacity' export { scribbleValidator, type TLScribble } from './misc/TLScribble' export { - box2dModelValidator, - vec2dModelValidator, - type Box2dModel, - type Vec2dModel, + boxModelValidator, + vecModelValidator, + type BoxModel, + type VecModel, } from './misc/geometry-types' export { idValidator } from './misc/id-validator' export { diff --git a/packages/tlschema/src/misc/TLScribble.ts b/packages/tlschema/src/misc/TLScribble.ts index c27d523a6..8fddc9f43 100644 --- a/packages/tlschema/src/misc/TLScribble.ts +++ b/packages/tlschema/src/misc/TLScribble.ts @@ -1,7 +1,7 @@ import { T } from '@tldraw/validate' import { SetValue } from '../util-types' import { TLCanvasUiColor, canvasUiColorTypeValidator } from './TLColor' -import { Vec2dModel, vec2dModelValidator } from './geometry-types' +import { VecModel, vecModelValidator } from './geometry-types' /** * The scribble states used by tldraw. @@ -15,7 +15,7 @@ export const TL_SCRIBBLE_STATES = new Set(['starting', 'paused', 'active', 'stop * @public */ export type TLScribble = { id: string - points: Vec2dModel[] + points: VecModel[] size: number color: TLCanvasUiColor opacity: number @@ -28,7 +28,7 @@ export type TLScribble = { /** @internal */ export const scribbleValidator: T.Validator = T.object({ id: T.string, - points: T.arrayOf(vec2dModelValidator), + points: T.arrayOf(vecModelValidator), size: T.positiveNumber, color: canvasUiColorTypeValidator, opacity: T.number, diff --git a/packages/tlschema/src/misc/geometry-types.ts b/packages/tlschema/src/misc/geometry-types.ts index 507b2f446..85c976077 100644 --- a/packages/tlschema/src/misc/geometry-types.ts +++ b/packages/tlschema/src/misc/geometry-types.ts @@ -4,7 +4,7 @@ import { T } from '@tldraw/validate' * A serializable model for 2D boxes. * * @public */ -export interface Box2dModel { +export interface BoxModel { x: number y: number w: number @@ -15,21 +15,21 @@ export interface Box2dModel { * A serializable model for 2D vectors. * * @public */ -export interface Vec2dModel { +export interface VecModel { x: number y: number z?: number } /** @public */ -export const vec2dModelValidator: T.Validator = T.object({ +export const vecModelValidator: T.Validator = T.object({ x: T.number, y: T.number, z: T.number.optional(), }) /** @public */ -export const box2dModelValidator: T.Validator = T.object({ +export const boxModelValidator: T.Validator = T.object({ x: T.number, y: T.number, w: T.number, diff --git a/packages/tlschema/src/records/TLInstance.ts b/packages/tlschema/src/records/TLInstance.ts index 22f4b8d08..33ff9de59 100644 --- a/packages/tlschema/src/records/TLInstance.ts +++ b/packages/tlschema/src/records/TLInstance.ts @@ -1,7 +1,7 @@ import { BaseRecord, createRecordType, defineMigrations, RecordId } from '@tldraw/store' import { JsonObject } from '@tldraw/utils' import { T } from '@tldraw/validate' -import { Box2dModel, box2dModelValidator } from '../misc/geometry-types' +import { BoxModel, boxModelValidator } from '../misc/geometry-types' import { idValidator } from '../misc/id-validator' import { cursorValidator, TLCursor } from '../misc/TLCursor' import { opacityValidator, TLOpacityType } from '../misc/TLOpacity' @@ -23,15 +23,15 @@ export interface TLInstance extends BaseRecord<'instance', TLInstanceId> { // ephemeral followingUserId: string | null highlightedUserIds: string[] - brush: Box2dModel | null + brush: BoxModel | null cursor: TLCursor scribbles: TLScribble[] isFocusMode: boolean isDebugMode: boolean isToolLocked: boolean exportBackground: boolean - screenBounds: Box2dModel - zoomBrush: Box2dModel | null + screenBounds: BoxModel + zoomBrush: BoxModel | null chatMessage: string isChatting: boolean isPenMode: boolean @@ -70,7 +70,7 @@ export function createInstanceRecordType(stylesById: Map('instance'), currentPageId: pageIdValidator, followingUserId: T.string.nullable(), - brush: box2dModelValidator.nullable(), + brush: boxModelValidator.nullable(), opacityForNextShape: opacityValidator, stylesForNextShape: T.object(stylesForNextShapeValidators), cursor: cursorValidator, @@ -79,8 +79,8 @@ export function createInstanceRecordType(stylesById: Map = T.mode y: T.number, z: T.number, }), - screenBounds: box2dModelValidator, + screenBounds: boxModelValidator, selectedShapeIds: T.arrayOf(idValidator('shape')), currentPageId: idValidator('page'), - brush: box2dModelValidator.nullable(), + brush: boxModelValidator.nullable(), scribbles: T.arrayOf(scribbleValidator), chatMessage: T.string, meta: T.jsonValue as T.ObjectValidator, diff --git a/packages/tlschema/src/shapes/TLArrowShape.ts b/packages/tlschema/src/shapes/TLArrowShape.ts index 5c8a9dac5..94cf53625 100644 --- a/packages/tlschema/src/shapes/TLArrowShape.ts +++ b/packages/tlschema/src/shapes/TLArrowShape.ts @@ -1,6 +1,6 @@ import { defineMigrations } from '@tldraw/store' import { T } from '@tldraw/validate' -import { vec2dModelValidator } from '../misc/geometry-types' +import { vecModelValidator } from '../misc/geometry-types' import { StyleProp } from '../styles/StyleProp' import { DefaultColorStyle, DefaultLabelColorStyle } from '../styles/TLColorStyle' import { DefaultDashStyle } from '../styles/TLDashStyle' @@ -41,7 +41,7 @@ const ArrowShapeTerminal = T.union('type', { binding: T.object({ type: T.literal('binding'), boundShapeId: shapeIdValidator, - normalizedAnchor: vec2dModelValidator, + normalizedAnchor: vecModelValidator, isExact: T.boolean, isPrecise: T.boolean, }), diff --git a/packages/tlschema/src/shapes/TLDrawShape.ts b/packages/tlschema/src/shapes/TLDrawShape.ts index 8bb6b269d..14b7f2882 100644 --- a/packages/tlschema/src/shapes/TLDrawShape.ts +++ b/packages/tlschema/src/shapes/TLDrawShape.ts @@ -1,6 +1,6 @@ import { defineMigrations } from '@tldraw/store' import { T } from '@tldraw/validate' -import { vec2dModelValidator } from '../misc/geometry-types' +import { vecModelValidator } from '../misc/geometry-types' import { DefaultColorStyle } from '../styles/TLColorStyle' import { DefaultDashStyle } from '../styles/TLDashStyle' import { DefaultFillStyle } from '../styles/TLFillStyle' @@ -9,7 +9,7 @@ import { ShapePropsType, TLBaseShape } from './TLBaseShape' export const DrawShapeSegment = T.object({ type: T.literalEnum('free', 'straight'), - points: T.arrayOf(vec2dModelValidator), + points: T.arrayOf(vecModelValidator), }) /** @public */ diff --git a/packages/tlschema/src/shapes/TLImageShape.ts b/packages/tlschema/src/shapes/TLImageShape.ts index e570f8a30..436870af8 100644 --- a/packages/tlschema/src/shapes/TLImageShape.ts +++ b/packages/tlschema/src/shapes/TLImageShape.ts @@ -1,13 +1,13 @@ import { defineMigrations } from '@tldraw/store' import { T } from '@tldraw/validate' import { assetIdValidator } from '../assets/TLBaseAsset' -import { vec2dModelValidator } from '../misc/geometry-types' +import { vecModelValidator } from '../misc/geometry-types' import { ShapePropsType, TLBaseShape } from './TLBaseShape' /** @public */ export const ImageShapeCrop = T.object({ - topLeft: vec2dModelValidator, - bottomRight: vec2dModelValidator, + topLeft: vecModelValidator, + bottomRight: vecModelValidator, }) /** @public */ export type TLImageShapeCrop = T.TypeOf