@mocanvas/editor · class
declare class VecThis 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 · 110
abs(): thisstatic Abs(A: VecLike): Vecadd(V: VecLike): thisstatic Add(A: VecLike, B: VecLike): VecaddScalar(n: number): thisstatic AddScalar(A: VecLike, n: number): VecaddXY(x: number, y: number): thisstatic AddXY(A: VecLike, x: number, y: number): Vecangle(B: VecLike): numberThe angle from this point to B, in radians.
static Angle(A: VecLike, B: VecLike): numberThe angle from A to B, in radians.
static AngleBetween(A: VecLike, B: VecLike): numberThe 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[]): VecThe average of every vector given; the zero vector for an empty list.
static Cast(A: VecLike): VecA itself when it is already a Vec, otherwise a Vec copy of it.
clamp(min: number, max?: number): thisClamp both components into [min, max]; with no max, a floor only.
static Clamp(A: VecLike, min: number, max?: number): VecBoth 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): booleanWhether the turn A→B→C goes clockwise in screen (y-down) axes.
clone(): Vecconstructor(x?: number, y?: number, z?: number | undefined)cpr(V: VecLike): numberThe scalar cross product — see Vec.Cpr.
static Cpr(A: VecLike, B: VecLike): numberThe 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): thisThe full 3D cross product with V, written back into this vector.
static Cross(A: VecLike, V: VecLike): VecThe 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): numberstatic Dist(A: VecLike, B: VecLike): numberdist2(V: VecLike): numberstatic Dist2(A: VecLike, B: VecLike): numberdistanceToLineSegment(A: VecLike, B: VecLike): numberstatic DistanceToLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp?: boolean): numberstatic DistanceToLineThroughPoint(A: VecLike, u: VecLike, P: VecLike): numberstatic DistMin(A: VecLike, B: VecLike, n: number): booleanWhether A and B are closer together than n, without taking a root.
div(t: number): thisstatic Div(A: VecLike, t: number): VecdivV(V: VecLike): thisstatic DivV(A: VecLike, B: VecLike): VecComponent-wise divide.
dot(V: VecLike): numberThe dot product, under its older name.
@deprecated Use Vec.dpr, the documented name.
static Dot(A: VecLike, B: VecLike): numberThe dot product, under its older name.
@deprecated Use Vec.Dpr, the documented name.
dpr(V: VecLike): numberThe dot product.
static Dpr(A: VecLike, B: VecLike): numberThe dot product.
equals(B: VecLike): booleanstatic Equals(A: VecLike, B: VecLike): booleanequalsApprox(B: VecLike, epsilon?: number): booleanEquality with a tolerance, for values that have been through a transform.
equalsXY(x: number, y: number): booleanstatic EqualsXY(A: VecLike, x: number, y: number): booleanstatic From({ x, y, z }: VecLike): Vecstatic FromAngle(r: number, length?: number): VecThe vector length units long pointing at r radians.
static FromArray(v: number[]): VecisFinite(): booleanstatic IsFinite(A: VecLike): booleanstatic IsNaN(A: VecLike): booleanlen(): numberstatic Len(A: VecLike): numberlen2(): numberSquared length — the comparison you want when you do not need the root.
static Len2(A: VecLike): numberlrp(B: VecLike, t: number): thisstatic Lrp(A: VecLike, B: VecLike, t: number): Vecstatic ManhattanDist(A: VecLike, B: VecLike): numberDistance along the axes rather than through them — the taxicab metric.
static Max(A: VecLike, B: VecLike): Vecstatic Med(A: VecLike, B: VecLike): VecThe midpoint of A and B.
static Min(A: VecLike, B: VecLike): Vecmul(t: number): thisstatic Mul(A: VecLike, t: number): VecmulV(V: VecLike): thisstatic MulV(A: VecLike, B: VecLike): VecComponent-wise multiply, i.e. a non-uniform scale.
static NearestPointOnLineSegment(A: VecLike, B: VecLike, P: VecLike, clamp?: boolean): VecThe 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): VecThe point closest to P on the infinite line through A in direction u.
neg(): thisstatic Neg(A: VecLike): Vecnudge(B: VecLike, distance: number): thisMove this point distance units towards B.
static Nudge(A: VecLike, B: VecLike, distance: number): VecA moved distance units towards B.
per(): thisRotate a quarter turn: (x, y) becomes (-y, x).
static Per(A: VecLike): VecA 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(): numberThe 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): numberHow far along V the projection of this vector lands.
static Pry(A: VecLike, B: VecLike): numberHow far along B the projection of A lands.
static Rescale(A: VecLike, n: number): VecA scaled to length n, keeping its direction.
rot(r: number): thisstatic Rot(A: VecLike, r?: number): VecrotWith(C: VecLike, r: number): thisstatic RotWith(A: VecLike, C: VecLike, r: number): Vecstatic ScaleWithOrigin(A: VecLike, scale: number, origin: VecLike): VecA scaled about origin rather than about the page origin.
set(x?: number, y?: number, z?: number | undefined): thissetTo(B: VecLike): thisslope(B: VecLike): numberThe gradient of the line to B; NaN for a vertical one.
static Slope(A: VecLike, B: VecLike): numberThe gradient of the line A→B; NaN for a vertical or degenerate one.
static Snap(A: VecLike, step?: number): VecBoth components rounded to the nearest multiple of step.
snapToGrid(gridSize: number): thisRound each axis to the nearest multiple of gridSize.
static SnapToGrid(A: VecLike, gridSize?: number): Vecsub(V: VecLike): thisstatic Sub(A: VecLike, B: VecLike): VecsubScalar(n: number): thisstatic SubScalar(A: VecLike, n: number): VecsubXY(x: number, y: number): thisstatic SubXY(A: VecLike, x: number, y: number): Vectan(V: VecLike): VecThe unit direction from V towards this point.
static Tan(A: VecLike, B: VecLike): VecThe unit direction from B towards A.
toAngle(): numberThe direction this vector points in, normalized to [0, 2π).
static ToAngle(A: VecLike): numberThe direction A points in, normalized to [0, 2π).
toArray(): number[]static ToArray(A: VecLike): number[]static ToCss(A: VecLike): stringThe 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): thisRound each axis to precision decimal places, in place.
static ToFixed(A: VecLike, precision?: number): Vecstatic ToInt(A: VecLike): VecBoth components truncated towards zero.
toJson(): VecModel$1The 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$1toString(): stringstatic ToString(A: VecLike): stringuni(): thisScale to unit length. A zero vector has no direction and stays at zero.
static Uni(A: VecLike): VecA scaled to unit length. A zero vector has no direction and stays zero.
Properties · 3
x: numbery: numberz: number | undefinedmocanvas 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.