Skip to main content
Module

x/canvas/types.ts>VectorHelpers

Canvas API for Deno, ported from canvaskit-wasm (Skia).
Go to Latest
interface VectorHelpers
import { type VectorHelpers } from "https://deno.land/x/canvas@v1.0.0/types.ts";

Functions for manipulating vectors. It is Loosely based off of SkV3 in SkM44.h but Skia also has SkVec2 and Skv4. This combines them and works on vectors of any length.

Methods

add(a: VectorN, b: VectorN): VectorN

Adds 2 vectors together, term by term, returning a new Vector.

cross(a: Vector3, b: Vector3): Vector3

Returns the cross product of the two vectors. Only works for length 3.

dist(a: VectorN, b: VectorN): number

Returns the length(sub(a, b))

dot(a: VectorN, b: VectorN): number

Returns the dot product of the two vectors.

length(v: VectorN): number

Returns the length of this vector, which is always positive.

lengthSquared(v: VectorN): number

Returns the length squared of this vector.

mulScalar(v: VectorN, s: number): VectorN

Returns a new vector which is v multiplied by the scalar s.

normalize(v: VectorN): VectorN

Returns a normalized vector.

sub(a: VectorN, b: VectorN): VectorN

Subtracts vector b from vector a (termwise).