@mocanvas/editor · class
declare class BoxThis one ships without a description. The signature above is read from the package, and the guides cover the area it belongs to.
On this page
Methods · 64
get aspectRatio(): numberWidth over height. Infinity for a zero-height box.
get bottom(): numberget center(): VecThe centre. Setting it moves the box without resizing it.
set center(v: VecLike)clone(): Boxcollides(B: BoxLike): booleanWhether this box and B overlap at all.
static Collides(A: BoxLike, B: BoxLike): booleanWhether A and B overlap at all. Touching edges count as colliding.
static Common(boxes: BoxLike[]): BoxThe smallest box containing every box given.
constructor(x?: number, y?: number, w?: number, h?: number)contains(B: BoxLike): booleanWhether B lies entirely inside this box (touching edges count as inside).
static Contains(A: BoxLike, B: BoxLike): booleanWhether B lies entirely inside A. Touching edges count as inside.
static ContainsApproximately(A: BoxLike, B: BoxLike, precision?: number): booleanBox.Contains, but tolerant of float dust from a transform.
containsPoint(V: VecLike, margin?: number): booleanWhether V lies inside this box, optionally grown by margin on every side.
static ContainsPoint(A: BoxLike, B: VecLike, margin?: number): booleanget corners(): Vec[]The four corners, clockwise from the top left.
get cornersAndCenter(): Vec[]The four corners followed by the centre — the five snap points of a box.
equals(other: BoxLike): booleanstatic Equals(a: BoxLike, b: BoxLike): booleanexpand(A: BoxLike): thisGrow this box to contain A as well.
static Expand(A: BoxLike, B: BoxLike): BoxThe smallest box containing both A and B.
@param A - the box to grow @param B - the box to grow it around, or, in the deprecated scalar form, the amount to grow it by on every side.
static Expand(A: BoxLike, n: number): Box@deprecated Use Box.ExpandBy, which is what a number here means.
expandBy(n: number): thisGrow this box by n on every side. A negative n shrinks it.
static ExpandBy(A: BoxLike, n: number): BoxA grown by n on every side. A negative n shrinks it.
static From(box: BoxModel): Boxstatic FromCenter(center: VecLike, size: VecLike): BoxThe box of the given size centred on center.
static FromMinMax(minX: number, minY: number, maxX: number, maxY: number): Boxstatic FromPoints(points: VecLike[]): BoxThe smallest box containing every point. Empty input gives an empty box.
getHandlePoint(handle: BoxHandle | RotateCorner): VecThe point at handle on this box's edge.
get height(): numberset height(n: number)includes(B: BoxLike): booleanWhether B has any part inside this box — contained or merely overlapping.
static Includes(A: BoxLike, B: BoxLike): booleanWhether A either contains B or overlaps it — i.e. whether B has any
part in A at all. This is what a marquee uses when it selects on touch
rather than on enclosure.
isValid(): booleanWhether this box has a real, finite, non-negative size.
get left(): numberget maxX(): numberget maxY(): numberget midX(): numberget midY(): numberget minX(): numberset minX(n: number)get minY(): numberset minY(n: number)get point(): VecThe top-left corner. Setting it moves the box without resizing it.
set point(v: VecLike)resize(handle: BoxHandle | string, dx: number, dy: number): voidApply a resize in place. See Box.Resize.
static Resize(box: BoxLike, handle: BoxHandle | string, dx: number, dy: number, isAspectRatioLocked?: boolean): {box after dragging handle by (dx, dy), as a fresh box. Dragging a side
past its opposite flips the box rather than producing a negative size, which
is what makes a resize feel like a resize rather than a stop.
The scaleX / scaleY in the result are signed: -1 means that axis was
flipped, which is what a shape needs in order to mirror its own contents.
get right(): numberscale(n: number): thisScale this box about the page origin.
set(x?: number, y?: number, w?: number, h?: number): thissetTo(B: BoxLike): thisget sides(): [Vec, Vec][]The four sides as point pairs, clockwise from the top edge.
static Sides(A: BoxLike, inset?: number): [Vec, Vec][]The four sides as point pairs, in clockwise order from the top edge. An
inset pulls each side's endpoints in along the edge, which is how an edge
handle avoids covering the corners next to it.
get size(): VecThe box's size as a vector.
set size(v: VecLike)snapToGrid(size: number): voidSnap every edge to the grid, so the box stays whole cells wide.
toFixed(precision?: number): thisRound every component to precision decimal places.
toJson(): BoxModelget top(): numbertranslate(delta: VecLike): thisMove this box by delta.
union(box: BoxModel): thisGrow this box to contain box as well. An alias of Box.expand.
get width(): numberset width(n: number)zeroFix(): thisFold a negative width or height back into the position. See Box.ZeroFix.
static ZeroFix(other: BoxLike): BoxA copy of other with any negative width or height folded back into its
position, so that a box dragged up and to the left still reads left-to-right.
Properties · 4
h: numberw: numberx: numbery: numbermocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.