@mocanvas/editor · class

Vec

declare class Vec

This one ships without a description. The signature above is read from the package, and the guides cover the area it belongs to.


Methods · 110

abs(): this
static Abs(A: VecLike): Vec
add(V: VecLike): this
static Add(A: VecLike, B: VecLike): Vec
addScalar(n: number): this
static AddScalar(A: VecLike, n: number): Vec
addXY(x: number, y: number): this
static AddXY(A: VecLike, x: number, y: number): Vec
angle(B: VecLike): number

The angle from this point to B, in radians.

static Angle(A: VecLike, B: VecLike): number

The angle from A to B, in radians.

static AngleBetween(A: VecLike, B: VecLike): number

The signed angle you would turn through to get from direction A to direction B, in (-π, π].

SEMANTICS-ASSUMED: the docs give only the signature. Reading the arguments as directions (rather than as two positions, which Vec.Angle already covers) is what makes this distinct from Angle.

static Average(arr: VecLike[]): Vec

The average of every vector given; the zero vector for an empty list.

static Cast(A: VecLike): Vec

A itself when it is already a Vec, otherwise a Vec copy of it.

clamp(min: number, max?: number): this

Clamp both components into [min, max]; with no max, a floor only.

static Clamp(A: VecLike, min: number, max?: number): Vec

Both components clamped into [min, max]. With no max, min is a floor only — the form you want when clamping a size away from zero.

SEMANTICS-ASSUMED: the one-bound overload is documented but not described; a lone lower bound is the only reading that makes Clamp(v, 0) useful.

static Clockwise(A: VecLike, B: VecLike, C: VecLike): boolean

Whether the turn A→B→C goes clockwise in screen (y-down) axes.

clone(): Vec
constructor(x?: number, y?: number, z?: number | undefined)
cpr(V: VecLike): number

The scalar cross product — see Vec.Cpr.

static Cpr(A: VecLike, B: VecLike): number

The scalar cross product, i.e. the signed area of the parallelogram A and B span. Positive when B is counter-clockwise of A in maths axes, which on a y-down canvas reads as clockwise.

cross(V: VecLike): this

The full 3D cross product with V, written back into this vector.

static Cross(A: VecLike, V: VecLike): Vec

The full 3D cross product, taking z as a real axis. Rarely what a 2D caller wants — see Vec.Cpr for the signed area, which is the z of this result.

SEMANTICS-ASSUMED: the docs give Cross a Vec return and Cpr a number, which only makes sense if Cross is the vector product; a point with no recorded pressure is read as sitting at the default depth.

dist(V: VecLike): number
static Dist(A: VecLike, B: VecLike): number
dist2(V: VecLike): number
static Dist2(A: VecLike, B: VecLike): number
distanceToLineSegment(A: VecLike, B: VecLike): number
static DistanceToLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp?: boolean): number
static DistanceToLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): number
static DistMin(A: VecLike, B: VecLike, n: number): boolean

Whether A and B are closer together than n, without taking a root.

div(t: number): this
static Div(A: VecLike, t: number): Vec
divV(V: VecLike): this
static DivV(A: VecLike, B: VecLike): Vec

Component-wise divide.

dot(V: VecLike): number

The dot product, under its older name.

@deprecated Use Vec.dpr, the documented name.

static Dot(A: VecLike, B: VecLike): number

The dot product, under its older name.

@deprecated Use Vec.Dpr, the documented name.

dpr(V: VecLike): number

The dot product.

static Dpr(A: VecLike, B: VecLike): number

The dot product.

equals(B: VecLike): boolean
static Equals(A: VecLike, B: VecLike): boolean
equalsApprox(B: VecLike, epsilon?: number): boolean

Equality with a tolerance, for values that have been through a transform.

equalsXY(x: number, y: number): boolean
static EqualsXY(A: VecLike, x: number, y: number): boolean
static From({ x, y, z }: VecLike): Vec
static FromAngle(r: number, length?: number): Vec

The vector length units long pointing at r radians.

static FromArray(v: number[]): Vec
isFinite(): boolean
static IsFinite(A: VecLike): boolean
static IsNaN(A: VecLike): boolean
len(): number
static Len(A: VecLike): number
len2(): number

Squared length — the comparison you want when you do not need the root.

static Len2(A: VecLike): number
lrp(B: VecLike, t: number): this
static Lrp(A: VecLike, B: VecLike, t: number): Vec
static ManhattanDist(A: VecLike, B: VecLike): number

Distance along the axes rather than through them — the taxicab metric.

static Max(A: VecLike, B: VecLike): Vec
static Med(A: VecLike, B: VecLike): Vec

The midpoint of A and B.

static Min(A: VecLike, B: VecLike): Vec
mul(t: number): this
static Mul(A: VecLike, t: number): Vec
mulV(V: VecLike): this
static MulV(A: VecLike, B: VecLike): Vec

Component-wise multiply, i.e. a non-uniform scale.

static NearestPointOnLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp?: boolean): Vec

The point on the segment A→B closest to P. With clamp false the segment is treated as the infinite line through A and B.

static NearestPointOnLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): Vec

The point closest to P on the infinite line through A in direction u.

neg(): this
static Neg(A: VecLike): Vec
nudge(B: VecLike, distance: number): this

Move this point distance units towards B.

static Nudge(A: VecLike, B: VecLike, distance: number): Vec

A moved distance units towards B.

per(): this

Rotate a quarter turn: (x, y) becomes (-y, x).

static Per(A: VecLike): Vec

A quarter turn: (x, y) becomes (-y, x).

static PointsBetween(A: VecModel$1, B: VecModel$1, steps?: number, ease?: (t: number) => number): Vec[]

steps points spread from A to B inclusive, optionally eased. Used to turn a jump — a camera move, an animated nudge — into something to tween along.

get pressure(): number

The pen pressure this point was recorded with, in [0, 1]. An alias for z, named for what it means rather than which slot it sits in.

SEMANTICS-ASSUMED: the docs give pressure as a read-only getter alongside a writable z but do not say how the two relate. Making it a plain alias is the only reading under which both can be true at once.

pry(V: VecLike): number

How far along V the projection of this vector lands.

static Pry(A: VecLike, B: VecLike): number

How far along B the projection of A lands.

static Rescale(A: VecLike, n: number): Vec

A scaled to length n, keeping its direction.

rot(r: number): this
static Rot(A: VecLike, r?: number): Vec
rotWith(C: VecLike, r: number): this
static RotWith(A: VecLike, C: VecLike, r: number): Vec
static ScaleWithOrigin(A: VecLike, scale: number, origin: VecLike): Vec

A scaled about origin rather than about the page origin.

set(x?: number, y?: number, z?: number | undefined): this
setTo(B: VecLike): this
slope(B: VecLike): number

The gradient of the line to B; NaN for a vertical one.

static Slope(A: VecLike, B: VecLike): number

The gradient of the line A→B; NaN for a vertical or degenerate one.

static Snap(A: VecLike, step?: number): Vec

Both components rounded to the nearest multiple of step.

snapToGrid(gridSize: number): this

Round each axis to the nearest multiple of gridSize.

static SnapToGrid(A: VecLike, gridSize?: number): Vec
sub(V: VecLike): this
static Sub(A: VecLike, B: VecLike): Vec
subScalar(n: number): this
static SubScalar(A: VecLike, n: number): Vec
subXY(x: number, y: number): this
static SubXY(A: VecLike, x: number, y: number): Vec
tan(V: VecLike): Vec

The unit direction from V towards this point.

static Tan(A: VecLike, B: VecLike): Vec

The unit direction from B towards A.

toAngle(): number

The direction this vector points in, normalized to [0, 2π).

static ToAngle(A: VecLike): number

The direction A points in, normalized to [0, 2π).

toArray(): number[]
static ToArray(A: VecLike): number[]
static ToCss(A: VecLike): string

The vector as a CSS translate().

SEMANTICS-ASSUMED: the docs give only (A: VecLike) => string. A ready-to-use transform is the only form that earns the "Css" in the name; a bare "x,y" pair is already Vec.ToString.

toFixed(precision?: number): this

Round each axis to precision decimal places, in place.

static ToFixed(A: VecLike, precision?: number): Vec
static ToInt(A: VecLike): Vec

Both components truncated towards zero.

toJson(): VecModel$1

The serialized form. z is omitted unless a real pressure was recorded, so geometry-derived points round-trip as the plain { x, y } they have always been stored as.

static ToJson(A: VecLike): VecModel$1
toString(): string
static ToString(A: VecLike): string
uni(): this

Scale to unit length. A zero vector has no direction and stays at zero.

static Uni(A: VecLike): Vec

A scaled to unit length. A zero vector has no direction and stays zero.


Properties · 3

x: number
y: number
z: number | undefined

mocanvas 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.