Skip to content
pixi-silk
GitHub repository
Class

SnapEngine

import { SnapEngine } from 'pixi-silk/ui/snap';

Experimental

Pure snapping maths, no drawing. It moves a rectangle so its edges or centre line up with other rectangles, guide lines and points, or so it sits at an equal gap from its neighbours. Each axis picks the nearest candidate within the threshold. Works in whatever space the rectangles are given in, axis-aligned only. Change the properties at any time.

Experimental: the API may change in a minor release.

Constructors#

Constructor#

new SnapEngine(options?: SnapEngineOptions): SnapEngine;

Experimental

Parameters#

ParameterType
optionsSnapEngineOptions

Returns#

SnapEngine

Properties#

PropertyTypeDescriptionDefined in
centresbooleanExperimental Uses target centres as snap anchors.ui/snap.ts:99
edgesbooleanExperimental Uses target edges as snap anchors.ui/snap.ts:97
lines{ x: number[]; y: number[]; }Experimental Fixed guide lines. Guides.bindSnap() from pixi-silk/ui/guides keeps them in step with a guides layer.ui/snap.ts:105
lines.xnumber[]-ui/snap.ts:105
lines.ynumber[]-ui/snap.ts:105
points{ x: number; y: number; }[]Experimental Points, used like zero-size targets.ui/snap.ts:107
spacingbooleanExperimental Snaps to equal gaps between neighbours.ui/snap.ts:101
targetsSnapRect[]Experimental Rectangles to snap against.ui/snap.ts:103
thresholdnumberExperimental Distance within which things snap, in the snapping space’s units.ui/snap.ts:95

Methods#

snap()#

snap(rect: SnapRect, exclude?: readonly SnapRect[]): SnapResult;

Experimental

Snaps a moving rectangle and returns the move and the guides. Does not change rect. exclude leaves out targets by identity, usually the moving object’s own rectangle.

Parameters#

ParameterTypeDefault value
rectSnapRectundefined
excludereadonly SnapRect[][]

Returns#

SnapResult


snapPoint()#

snapPoint(x: number, y: number): {
  guides: SnapGuide[];
  x: number;
  y: number;
};

Experimental

Snaps a single point, as a zero-size rectangle, and returns where it lands.

Parameters#

ParameterType
xnumber
ynumber

Returns#

{
  guides: SnapGuide[];
  x: number;
  y: number;
}
NameTypeDefined in
guidesSnapGuide[]ui/snap.ts:153
xnumberui/snap.ts:153
ynumberui/snap.ts:153