UNPKG

tav-media

Version:

Cross platform media editing framework

336 lines (335 loc) 12 kB
import { tav } from "../tav"; import { Rect } from "./tav-rect"; import { Point } from "./types"; /*** * Matrix holds a 3x3 matrix for transforming coordinates. This allows mapping Point and vectors * with translation, scaling, skewing, rotation, and perspective. * Matrix elements are in row major order. Matrix does not have a constructor, so it must be * explicitly initialized. setIdentity() initializes Matrix so it has no effect. * setTranslate(), setScale(), setSkew(), setRotate(), set9 and setAll() initializes all Matrix * elements with the corresponding mapping. */ export declare class Matrix { private _nativeMatrix; constructor(nativeMatrix?: tav.TAVMatrix); /** * Sets Matrix to scale by (sx, sy). Returned matrix is: * * | sx 0 0 | * | 0 sy 0 | * | 0 0 1 | * * @param sx horizontal scale factor * @param sy vertical scale factor * @return Matrix with scale */ static MakeScale(sx: number, sy?: number): Matrix; /** * Sets Matrix to translate by (dx, dy). Returned matrix is: * * | 1 0 dx | * | 0 1 dy | * | 0 0 1 | * * @param dx horizontal translation * @param dy vertical translation * @return Matrix with translation */ static MakeTrans(dx: number, dy: number): Matrix; /** * Sets Matrix to: * * | scaleX skewX transX | * | skewY scaleY transY | * | pers0 pers1 pers2 | * * @param scaleX horizontal scale factor * @param skewX horizontal skew factor * @param transX horizontal translation * @param skewY vertical skew factor * @param scaleY vertical scale factor * @param transY vertical translation * @param pers0 input x-axis perspective factor * @param pers1 input y-axis perspective factor * @param pers2 perspective scale factor * @return Matrix constructed from parameters */ static MakeAll(scaleX: number, skewX: number, transX: number, skewY: number, scaleY: number, transY: number, pers0: number, pers1: number, pers2: number): Matrix; build(): tav.TAVMatrix; setNativeMatrix(nativeMatrix: tav.TAVMatrix): void; /** * Returns true if Matrix is identity. Identity matrix is: * * | 1 0 0 | * | 0 1 0 | * | 0 0 1 | * * @return true if Matrix has no effect */ isIdentity(): boolean; /** * Returns one matrix value. */ get(index: number): number; /** * Returns scale factor multiplied by x-axis input, contributing to x-axis output. With * mapPoints(), scales Point along the x-axis. * @return horizontal scale factor */ getScaleX(): number; /** * Returns scale factor multiplied by y-axis input, contributing to y-axis output. With * mapPoints(), scales Point along the y-axis. * @return vertical scale factor */ getScaleY(): number; /** * Returns scale factor multiplied by x-axis input, contributing to y-axis output. With * mapPoints(), skews Point along the y-axis. Skewing both axes can rotate Point. * @return vertical skew factor */ getSkewY(): number; /** * Returns scale factor multiplied by y-axis input, contributing to x-axis output. With * mapPoints(), skews Point along the x-axis. Skewing both axes can rotate Point. * @return horizontal scale factor */ getSkewX(): number; /** * Returns translation contributing to x-axis output. With mapPoints(), moves Point along the * x-axis. * @return horizontal translation factor */ getTranslateX(): number; /** * Returns translation contributing to y-axis output. With mapPoints(), moves Point along the * y-axis. * @return vertical translation factor */ getTranslateY(): number; /** * Sets Matrix value. */ set(index: number, value: number): void; /** * Sets horizontal scale factor. * @param v horizontal scale factor to store */ setScaleX(v: number): void; /** * Sets vertical scale factor. * @param v vertical scale factor to store */ setScaleY(v: number): void; /** * Sets vertical skew factor. * @param v vertical skew factor to store */ setSkewY(v: number): void; /** * Sets horizontal skew factor. * @param v horizontal skew factor to store */ setSkewX(v: number): void; /** * Sets horizontal translation. * @param v horizontal translation to store */ setTranslateX(v: number): void; /** * Sets vertical translation. * @param v vertical translation to store */ setTranslateY(v: number): void; /** * Sets all values from parameters. Sets matrix to: * * | scaleX skewX transX | * | skewY scaleY transY | * | persp0 persp1 persp2 | * * @param scaleX horizontal scale factor to store * @param skewX horizontal skew factor to store * @param transX horizontal translation to store * @param skewY vertical skew factor to store * @param scaleY vertical scale factor to store * @param transY vertical translation to store * @param persp0 input x-axis values perspective factor to store * @param persp1 input y-axis values perspective factor to store * @param persp2 perspective scale factor to store */ setAll(scaleX: number, skewX: number, transX: number, skewY: number, scaleY: number, transY: number, persp0: number, persp1: number, persp2: number): void; setAffine(a: number, b: number, c: number, d: number, tx: number, ty: number): void; /** * Copies nine scalar values contained by Matrix into buffer, in member value ascending order: * kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2. * @param buffer storage for nine scalar values */ get9(): number[]; /** * Sets Matrix to nine scalar values in buffer, in member value ascending order: kMScaleX, * kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2. * * Sets matrix to: * * | buffer[0] buffer[1] buffer[2] | * | buffer[3] buffer[4] buffer[5] | * | buffer[6] buffer[7] buffer[8] | * * @param buffer nine scalar values */ set9(buffer: number[]): void; /** * Sets Matrix to identity; which has no effect on mapped Point. Sets Matrix to: * * | 1 0 0 | * | 0 1 0 | * | 0 0 1 | * * Also called setIdentity(){}; use the one that provides better inline documentation. */ reset(): void; /** * Sets Matrix to identity; which has no effect on mapped Point. Sets Matrix to: * * | 1 0 0 | * | 0 1 0 | * | 0 0 1 | * * Also called reset(){}; use the one that provides better inline documentation. */ setIdentity(): void; /** * Sets Matrix to translate by (dx, dy). * @param dx horizontal translation * @param dy vertical translation */ setTranslate(dx: number, dy: number): void; /** * Sets TAVMatrix to scale by sx and sy about at pivot point at (0, 0). * @param sx horizontal scale factor * @param sy vertical scale factor */ setScale(sx: number, sy: number): any; /** * Sets TAVMatrix to rotate by degrees about a pivot point at (0, 0). Positive degrees rotates * clockwise. * @param degrees angle of axes relative to upright axes */ setRotate(degrees: number): any; /** * Sets TAVMatrix to rotate by sinValue and cosValue, about a pivot point at (0, 0). * Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1). * Vector length specifies scale. */ setSinCos(sinV: number, cosV: number): any; /** * Sets TAVMatrix to skew by kx and ky, about a pivot point at (0, 0). * @param kx horizontal skew factor * @param ky vertical skew factor */ setSkew(kx: number, ky: number): any; /** * Sets Matrix to Matrix a multiplied by Matrix b. Either a or b may be this. * * Given: * * | A B C | | J K L | * a = | D E F |, b = | M N O | * | G H I | | P Q R | * * sets Matrix to: * * | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR | * a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR | * | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR | * * @param a Matrix on left side of multiply expression * @param b Matrix on right side of multiply expression */ setConcat(a: Matrix, b: Matrix): void; /** * Preconcats the matrix with the specified translate. M' = M * T(dx, dy) */ preTranslate(dx: number, dy: number): void; /** * Preconcats the matrix with the specified scale. M' = M * S(sx, sy) */ preScale(sx: number, sy: number): any; /** * Preconcats the matrix with the specified rotation. M' = M * R(degrees) */ preRotate(degrees: number): any; /** * Preconcats the matrix with the specified skew. M' = M * K(kx, ky) */ preSkew(kx: number, ky: number): any; /** * Preconcats the matrix with the specified matrix. M' = M * other */ preConcat(other: Matrix): void; /** * Postconcats the matrix with the specified translation. M' = T(dx, dy) * M */ postTranslate(dx: number, dy: number): void; /** * Postconcats the matrix with the specified scale. M' = S(sx, sy) * M */ postScale(sx: number, sy: number): any; /** * Postconcats the matrix with the specified rotation. M' = R(degrees) * M */ postRotate(degrees: number): any; /** * Postconcats the matrix with the specified skew. M' = K(kx, ky) * M */ postSkew(kx: number, ky: number): any; /** * Postconcats the matrix with the specified matrix. M' = other * M */ postConcat(other: Matrix): void; /** * If this matrix can be inverted, return true and if inverse is not null, set inverse to be the * inverse of this matrix. If this matrix cannot be inverted, ignore inverse and return false. */ invert(inverse: Matrix): boolean; invertible(): boolean; /** * Returns Point (x, y) multiplied by Matrix. Given: * * | A B C | | x | * Matrix = | D E F |, pt = | y | * | G H I | | 1 | * * result is computed as: * * |A B C| |x| Ax+By+C Dx+Ey+F * Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , ------- * |G H I| |1| Gx+Hy+I Gx+Hy+I * * @param x x-axis value of Point to map * @param y y-axis value of Point to map * @return mapped Point */ mapXY(x: number, y: number): Point; /** * Returns bounds of src corners mapped by Matrix. */ mapRect(src: Rect): Rect; /** * Returns the minimum scaling factor of Matrix by decomposing the scaling and skewing elements. * Returns -1 if scale factor overflows or Matrix contains perspective. */ getMinScale(): number; /** * Returns the maximum scaling factor of Matrix by decomposing the scaling and skewing elements. * Returns -1 if scale factor overflows or Matrix contains perspective. */ getMaxScale(): number; /** * Returns true if all elements of the matrix are finite. Returns false if any * element is infinity, or NaN. */ isFinite(): boolean; private makeNativeMatrix; }