Skip to content

Commit

Permalink
Faster selection / erasing (#3454)
Browse files Browse the repository at this point in the history
This PR makes a small improvement to the way we measure distances.
(Often we measure distances multiple times per frame per shape on the
screen). In many cases, we compare a minimum distance. This makes those
checks faster by avoiding a square root.

### Change Type

- [x] `sdk` — Changes the tldraw SDK
- [x] `improvement` — Improving existing features

### Release Notes

- Improve performance of minimum distance checks.
  • Loading branch information
steveruizok committed Apr 13, 2024
1 parent 152b915 commit 3ceebc8
Show file tree
Hide file tree
Showing 39 changed files with 441 additions and 539 deletions.
2 changes: 0 additions & 2 deletions apps/examples/src/examples/exploded/ExplodedExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
DefaultContextMenuContent,
TldrawEditor,
TldrawHandles,
TldrawHoveredShapeIndicator,
TldrawScribble,
TldrawSelectionBackground,
TldrawSelectionForeground,
Expand All @@ -23,7 +22,6 @@ const defaultComponents = {
SelectionForeground: TldrawSelectionForeground,
SelectionBackground: TldrawSelectionBackground,
Handles: TldrawHandles,
HoveredShapeIndicator: TldrawHoveredShapeIndicator,
}

//[2]
Expand Down
24 changes: 9 additions & 15 deletions packages/editor/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class Arc2d extends Geometry2d {
// (undocumented)
getVertices(): Vec[];
// (undocumented)
hitTestLineSegment(A: Vec, B: Vec, _zoom: number): boolean;
hitTestLineSegment(A: Vec, B: Vec): boolean;
// (undocumented)
length: number;
// (undocumented)
Expand Down Expand Up @@ -332,7 +332,7 @@ export class Circle2d extends Geometry2d {
// (undocumented)
getVertices(): Vec[];
// (undocumented)
hitTestLineSegment(A: Vec, B: Vec, _zoom: number): boolean;
hitTestLineSegment(A: Vec, B: Vec, distance?: number): boolean;
// (undocumented)
nearestPoint(point: Vec): Vec;
// (undocumented)
Expand Down Expand Up @@ -414,7 +414,7 @@ export class CubicSpline2d extends Geometry2d {
// (undocumented)
getVertices(): Vec[];
// (undocumented)
hitTestLineSegment(A: Vec, B: Vec, zoom: number): boolean;
hitTestLineSegment(A: Vec, B: Vec): boolean;
// (undocumented)
get length(): number;
// (undocumented)
Expand Down Expand Up @@ -471,9 +471,6 @@ export function DefaultHandle({ handle, isCoarse, className, zoom }: TLHandlePro
// @public (undocumented)
export const DefaultHandles: ({ children }: TLHandlesProps) => JSX_2.Element;

// @public (undocumented)
export function DefaultHoveredShapeIndicator({ shapeId }: TLHoveredShapeIndicatorProps): JSX_2.Element | null;

// @public (undocumented)
export function DefaultScribble({ scribble, zoom, color, opacity, className }: TLScribbleProps): JSX_2.Element | null;

Expand Down Expand Up @@ -552,7 +549,7 @@ export class Edge2d extends Geometry2d {
// (undocumented)
getVertices(): Vec[];
// (undocumented)
hitTestLineSegment(A: Vec, B: Vec, _zoom: number): boolean;
hitTestLineSegment(A: Vec, B: Vec, distance?: number): boolean;
// (undocumented)
get length(): number;
// (undocumented)
Expand Down Expand Up @@ -968,7 +965,7 @@ export class Ellipse2d extends Geometry2d {
// (undocumented)
h: number;
// (undocumented)
hitTestLineSegment(A: Vec, B: Vec, zoom: number): boolean;
hitTestLineSegment(A: Vec, B: Vec): boolean;
// (undocumented)
nearestPoint(A: Vec): Vec;
// (undocumented)
Expand Down Expand Up @@ -1458,7 +1455,7 @@ export class Polyline2d extends Geometry2d {
// (undocumented)
getVertices(): Vec[];
// (undocumented)
hitTestLineSegment(A: Vec, B: Vec, zoom: number): boolean;
hitTestLineSegment(A: Vec, B: Vec, distance?: number): boolean;
// (undocumented)
get length(): number;
// (undocumented)
Expand Down Expand Up @@ -2302,11 +2299,6 @@ export type TLHistoryMark = {
onRedo: boolean;
};

// @public (undocumented)
export type TLHoveredShapeIndicatorProps = {
shapeId: TLShapeId;
};

// @public (undocumented)
export type TLInterruptEvent = (info: TLInterruptEventInfo) => void;

Expand Down Expand Up @@ -2539,6 +2531,7 @@ export type TLShapeIndicatorProps = {
color?: string | undefined;
opacity?: number;
className?: string;
hidden?: boolean;
};

// @public (undocumented)
Expand Down Expand Up @@ -2726,7 +2719,6 @@ export function useEditorComponents(): Partial<{
Spinner: ComponentType | null;
SelectionForeground: ComponentType<TLSelectionForegroundProps> | null;
SelectionBackground: ComponentType<TLSelectionBackgroundProps> | null;
HoveredShapeIndicator: ComponentType<TLHoveredShapeIndicatorProps> | null;
OnTheCanvas: ComponentType | null;
InFrontOfTheCanvas: ComponentType | null;
LoadingScreen: ComponentType | null;
Expand Down Expand Up @@ -2850,6 +2842,8 @@ export class Vec {
// (undocumented)
static DistanceToLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): number;
// (undocumented)
static DistMin(A: VecLike, B: VecLike, n: number): boolean;
// (undocumented)
static Div(A: VecLike, t: number): Vec;
// (undocumented)
div(t: number): this;
Expand Down
Loading

0 comments on commit 3ceebc8

Please sign in to comment.