/** * @license * Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ import { Mat2Array, Mat2dArray, Mat3Array, Mat4Array, Vec2Array, Vec3Array } from './common'; export type { Vec2Array }; /** * @class 2 Dimensional Vector * @name vec2 */ /** * Creates a new, empty vec2 * * @returns a new 2D vector */ export declare function create(): Vec2Array; /** * Creates a new vec2 initialized with values from an existing vector * * @param a vector to clone * @returns a new 2D vector */ export declare function clone(a: Vec2Array): Vec2Array; /** * Creates a new vec2 initialized with the given values * * @param x X component * @param y Y component * @returns a new 2D vector */ export declare function fromValues(x: number, y: number): Vec2Array; /** * Copy the values from one vec2 to another * * @param out the receiving vector * @param a the source vector * @returns out */ export declare function copy(out: Vec2Array, a: Vec2Array): Vec2Array; /** * Set the components of a vec2 to the given values * * @param out the receiving vector * @param x X component * @param y Y component * @returns out */ export declare function set(out: Vec2Array, x: number, y: number): Vec2Array; /** * Adds two vec2's * * @param out the receiving vector * @param a the first operand * @param b the second operand * @returns out */ export declare function add(out: Vec2Array, a: Vec2Array, b: Vec2Array): Vec2Array; /** * Subtracts vector b from vector a * * @param out the receiving vector * @param a the first operand * @param b the second operand * @returns out */ export declare function subtract(out: Vec2Array, a: Vec2Array, b: Vec2Array): Vec2Array; /** * Alias for {@link vec2.subtract} */ export declare const sub: typeof subtract; /** * Multiplies two vec2's * * @param out the receiving vector * @param a the first operand * @param b the second operand * @returns out */ export declare function multiply(out: Vec2Array, a: Vec2Array, b: Vec2Array): Vec2Array; /** * Alias for {@link vec2.multiply} */ export declare const mul: typeof multiply; /** * Divides two vec2's * * @param out the receiving vector * @param a the first operand * @param b the second operand * @returns out */ export declare function divide(out: Vec2Array, a: Vec2Array, b: Vec2Array): Vec2Array; /** * Alias for {@link vec2.divide} */ export declare const div: typeof divide; /** * Returns the minimum of two vec2's * * @param out the receiving vector * @param a the first operand * @param b the second operand * @returns out */ export declare function min(out: Vec2Array, a: Vec2Array, b: Vec2Array): Vec2Array; /** * Returns the maximum of two vec2's * * @param out the receiving vector * @param a the first operand * @param b the second operand * @returns out */ export declare function max(out: Vec2Array, a: Vec2Array, b: Vec2Array): Vec2Array; /** * Scales a vec2 by a scalar number * * @param out the receiving vector * @param a the vector to scale * @param b amount to scale the vector by * @returns out */ export declare function scale(out: Vec2Array, a: Vec2Array, b: number): Vec2Array; /** * Adds two vec2's after scaling the second operand by a scalar value * * @param out the receiving vector * @param a the first operand * @param b the second operand * @param scale the amount to scale b by before adding * @returns out */ export declare function scaleAndAdd(out: Vec2Array, a: Vec2Array, b: Vec2Array, scale: number): Vec2Array; /** * Calculates the euclidian distance between two vec2's * * @param a the first operand * @param b the second operand * @returns distance between a and b */ export declare function distance(a: Vec2Array, b: Vec2Array): number; /** * Alias for {@link vec2.distance} */ export declare const dist: typeof distance; /** * Calculates the squared euclidian distance between two vec2's * * @param a the first operand * @param b the second operand * @returns squared distance between a and b */ export declare function squaredDistance(a: Vec2Array, b: Vec2Array): number; /** * Alias for {@link vec2.squaredDistance} */ export declare const sqrDist: typeof squaredDistance; /** * Calculates the length of a vec2 * * @param a vector to calculate length of * @returns length of a */ export declare function length(a: Vec2Array): number; /** * Alias for {@link vec2.length} */ export declare const len: typeof length; /** * Calculates the squared length of a vec2 * * @param a vector to calculate squared length of * @returns squared length of a */ export declare function squaredLength(a: Vec2Array): number; /** * Alias for {@link vec2.squaredLength} */ export declare const sqrLen: typeof squaredLength; /** * Negates the components of a vec2 * * @param out the receiving vector * @param a vector to negate * @returns out */ export declare function negate(out: Vec2Array, a: Vec2Array): Vec2Array; /** * Returns the inverse of the components of a vec2 * * @param out the receiving vector * @param a vector to invert * @returns out */ export declare function inverse(out: Vec2Array, a: Vec2Array): Vec2Array; /** * Normalize a vec2 * * @param out the receiving vector * @param a vector to normalize * @returns out */ export declare function normalize(out: Vec2Array, a: Vec2Array): Vec2Array; /** * Calculates the dot product of two vec2's * * @param a the first operand * @param b the second operand * @returns dot product of a and b */ export declare function dot(a: Vec2Array, b: Vec2Array): number; /** * Computes the cross product of two vec2's * Note that the cross product must by definition produce a 3D vector * * @param out the receiving vector * @param a the first operand * @param b the second operand * @returns out */ export declare function cross(out: Vec3Array, a: Vec2Array, b: Vec2Array): Vec3Array; /** * Performs a linear interpolation between two vec2's * * @param out the receiving vector * @param a the first operand * @param b the second operand * @param t interpolation amount between the two inputs * @returns out */ export declare function lerp(out: Vec2Array, a: Vec2Array, b: Vec2Array, t: number): Vec2Array; /** * Generates a random vector with the given scale * * @param out the receiving vector * @param [scale] Length of the resulting vector. If ommitted, a unit vector will be returned * @returns out */ export declare function random(out: Vec2Array, scale: number): Vec2Array; /** * Transforms the vec2 with a mat2 * * @param out the receiving vector * @param a the vector to transform * @param {mat2} m matrix to transform with * @returns out */ export declare function transformMat2(out: Vec2Array, a: Vec2Array, m: Mat2Array): Vec2Array; /** * Transforms the vec2 with a mat2d * * @param out the receiving vector * @param a the vector to transform * @param m matrix to transform with * @returns out */ export declare function transformMat2d(out: Vec2Array, a: Vec2Array, m: Mat2dArray): Vec2Array; /** * Transforms the vec2 with a mat3 * 3rd vector component is implicitly '1' * * @param out the receiving vector * @param a the vector to transform * @param m matrix to transform with * @returns out */ export declare function transformMat3(out: Vec2Array, a: Vec2Array, m: Mat3Array): Vec2Array; /** * Transforms the vec2 with a mat4 * 3rd vector component is implicitly '0' * 4th vector component is implicitly '1' * * @param out the receiving vector * @param a the vector to transform * @param {mat4} m matrix to transform with * @returns out */ export declare function transformMat4(out: Vec2Array, a: Vec2Array, m: Mat4Array): Vec2Array; /** * Perform some operation over an array of vec2s. * * @param a the array of vectors to iterate over * @param stride Number of elements between the start of each vec2. If 0 assumes tightly packed * @param offset Number of elements to skip at the beginning of the array * @param count Number of vec2s to iterate over. If 0 iterates over entire array export function para} to call for each vector in the array * @param arg additional argument to pass to fn * @returns */ export declare const forEach: (a: { readonly length: number; [n: number]: number; }, stride: number, offset: number, count: number, fn: undefined extends T ? (a: Vec2Array, b: Vec2Array) => void : (a: Vec2Array, b: Vec2Array, arg: T) => void, arg?: T) => { [n: number]: number; readonly length: number; };