UNPKG

@turbox3d/math

Version:

Large-scale graphics application math library

99 lines (98 loc) 3.14 kB
import { Matrix3 } from './Matrix3'; import { Tolerance } from './Tolerance'; import { Vector3 } from './Vector3'; declare class Vector2 { static fromObject(obj: { x: number; y: number; }): Vector2; readonly isVector2: boolean; x: number; y: number; constructor(x?: number, y?: number); get width(): number; set width(value: number); get height(): number; set height(value: number); set(x: number, y: number): this; setScalar(scalar: number): this; setX(x: number): this; setY(y: number): this; setComponent(index: number, value: number): this; getComponent(index: number): number; clone(): Vector2; copy(v: Vector2): this; add(v: Vector2): this; added(v: Vector2): Vector2; addScalar(s: number): this; addVectors(a: Vector2, b: Vector2): this; addScaledVector(v: Vector2, s: number): this; sub(v: Vector2): this; subtracted(v: Vector2): Vector2; subScalar(s: number): this; subVectors(a: Vector2, b: Vector2): this; reverse(): this; reversed(): Vector2; multiply(v: Vector2): this; /** * Return a new vector which is the scaler result of this vector. * @param scale */ multiplied(scale: number): Vector2; multiplyScalar(scalar: number): this; divide(v: Vector2): this; divideScalar(scalar: number): this; applyMatrix3(m: Matrix3): this; min(v: Vector2): this; max(v: Vector2): this; clamp(min: Vector2, max: Vector2): this; clampScalar(minVal: number, maxVal: number): this; clampLength(min: number, max: number): this; floor(): this; ceil(): this; round(): this; roundToZero(): this; negate(): this; dot(v: Vector2): number; cross(v: Vector2): number; get lengthSq(): number; get length(): number; get manhattanLength(): number; normalize(): this; /** * The angle in [0, PI] */ angle(v?: Vector2): number; /** * The angle in [0, 2PI) */ angleTo(v: Vector2): number; /** * 返回单位向量 */ normalized(): Vector2; distanceTo(v: Vector2): number; distanceToSquared(v: Vector2): number; manhattanDistanceTo(v: Vector2): number; setLength(length: number): this; lerp(v: Vector2, alpha: number): this; lerpVectors(v1: Vector2, v2: Vector2, alpha: number): this; equals(v: Vector2, distTol?: number, cosTol?: number): boolean; isZero(distTol?: number): boolean; /** * 是否平行 */ isParallel(vec: Vector2, tol?: Tolerance, checkZeroVec?: boolean): boolean; /** * 是否垂直 */ isPerpendicular(vec: Vector2, tol?: Tolerance, checkZeroVec?: boolean): boolean; isSameDirection(v: Vector2, tol?: Tolerance, checkZeroVec?: boolean): boolean; isOpposite(vec: Vector2, tol?: Tolerance, checkZeroVec?: boolean): boolean; fromArray(array: number[] | ArrayLike<number>, offset?: number): this; toArray(array?: number[], offset?: number): number[]; toVector3(): Vector3; rotateAround(center: Vector2, angle: number): this; random(): this; } export { Vector2 };