libgpac
Documentation of the core library of GPAC
Matrix2D Interface Reference

import"evg.idl";

Public Member Functions

 Matrix2D ()
 
 Matrix2D (Matrix2D from)
 
 Matrix2D (double coefs...)
 
Point2D get_scale ()
 
Point2D get_translate ()
 
double get_rotate ()
 
Matrix2D inverse ()
 
Matrix2D copy ()
 
void copy (Matrix2D from)
 
Matrix2D add (Matrix2D mx, optional boolean premultiply=false)
 
Matrix2D translate (double x, double y)
 
Matrix2D translate (Point2D vec)
 
Matrix2D rotate (double cx, double cy, double a)
 
Matrix2D scale (double sx, double sy)
 
Matrix2D scale (double sx, double sy, double cx, double cy, double angle)
 
Matrix2D skew (double skew_x, double skew_y)
 
Matrix2D skew_x (double skew)
 
Matrix2D skew_y (double skew)
 
Point2D apply (Point2D in)
 
Rect apply (Rect in)
 

Data Fields

attribute double xx
 
attribute double xy
 
attribute double tx
 
attribute double yx
 
attribute double yy
 
attribute boolean identity
 
attribute const boolean is3D = false
 

Detailed Description

2D matrix, see GF_Matrix2D the transformation of (x, y) into (x', y') is:

x' = x * m.xx + y * m.xy + m.tx;
y' = x * m.yx + y * m.yy + m.ty;

Most matrix functions return the path object itself, so that the operations can be chained:

mx.rotate(0).translate(10, 20).scale(2, 2);

All objects (Point2D, Rect) used in the API do not use constructors, their type is inferred if the expected attributes (eg x y, ...) are present in the object

let res = max.apply({x:0,y: 0});
print(`transformed ${res.x} ${res.y});`
void print(DOMString log)

Constructor & Destructor Documentation

◆ Matrix2D() [1/3]

Matrix2D::Matrix2D ( )

constructor

◆ Matrix2D() [2/3]

Matrix2D::Matrix2D ( Matrix2D  from)

constructor

Parameters
fromthe color matrix to use

◆ Matrix2D() [3/3]

Matrix2D::Matrix2D ( double  coefs...)

constructor

Parameters
coefsthe matrix coeficients

Member Function Documentation

◆ get_scale()

Point2D Matrix2D::get_scale ( )

get scale part of the matrix after decomposition - see gf_mx2d_decompose

Returns
{x, y} object, or null if matrix cannot be decomposed

◆ get_translate()

Point2D Matrix2D::get_translate ( )

get translate part of the matrix after decomposition - see gf_mx2d_decompose

Returns
{x, y} object, or null if matrix cannot be decomposed

◆ get_rotate()

double Matrix2D::get_rotate ( )

get rotation part of the matrix after decomposition - see gf_mx2d_decompose

Returns
rotation, or null if matrix cannot be decomposed

◆ inverse()

Matrix2D Matrix2D::inverse ( )

inverse matrix - see gf_mx2d_inverse

Returns
the matrix

◆ copy() [1/2]

Matrix2D Matrix2D::copy ( )

copies the matrix

Returns
the new copy matrix

◆ copy() [2/2]

void Matrix2D::copy ( Matrix2D  from)

copies from a matrix

Parameters
fromthe matrix to copy from

◆ add()

Matrix2D Matrix2D::add ( Matrix2D  mx,
optional boolean  premultiply = false 
)

adds a matrix - see gf_mx2d_add_matrix and gf_mx2d_pre_multiply

Parameters
mxthe matrix to multiply
premultiplyif true, performs
mx * this
, otherwise
this * mx
Returns
the matrix

◆ translate() [1/2]

Matrix2D Matrix2D::translate ( double  x,
double  y 
)

add a translation - see gf_mx2d_add_translation

Parameters
xhorizontal translation
yvertical translation
Returns
the matrix

◆ translate() [2/2]

Matrix2D Matrix2D::translate ( Point2D  vec)

add a translation - see gf_mx2d_add_translation

Parameters
vectranslation vector
Returns
the matrix

◆ rotate()

Matrix2D Matrix2D::rotate ( double  cx,
double  cy,
double  a 
)

add a rotation - see gf_mx2d_add_rotation

Parameters
cxcenter x coordinate
cycenter y coordinate
arotation angle
Returns
the matrix

◆ scale() [1/2]

Matrix2D Matrix2D::scale ( double  sx,
double  sy 
)

adds scale - see gf_mx2d_add_scale

Parameters
sxhorizontal scale factor
syvertical scale factor
Returns
the matrix

◆ scale() [2/2]

Matrix2D Matrix2D::scale ( double  sx,
double  sy,
double  cx,
double  cy,
double  angle 
)

adds scale - see gf_mx2d_add_scale_at

Parameters
sxhorizontal scale factor
syvertical scale factor
cxhorizontal scaling center coordinate
cyvertical scaling center coordinate
anglescale orienttion angle in radians
Returns
the matrix

◆ skew()

Matrix2D Matrix2D::skew ( double  skew_x,
double  skew_y 
)

adds skew - see gf_mx2d_add_skew

Parameters
skew_xhorizontal skew factor
skew_yvertical skew factor
Returns
the matrix

◆ skew_x()

Matrix2D Matrix2D::skew_x ( double  skew)

adds horizontal skew - see gf_mx2d_add_skew_x

Parameters
skewhorizontal skew factor
Returns
the matrix

◆ skew_y()

Matrix2D Matrix2D::skew_y ( double  skew)

adds vertical skew - see gf_mx2d_add_skew_y

Parameters
skewvertical skew factor
Returns
the matrix

◆ apply() [1/2]

Point2D Matrix2D::apply ( Point2D  in)

transforms a point with a matrix - see gf_mx2d_apply_point

Parameters
ininput point to transform
Returns
the transformed point

◆ apply() [2/2]

Rect Matrix2D::apply ( Rect  in)

transforms a rectangle with a matrix - see gf_mx2d_apply_rect

Parameters
ininput rectangle to transform
Returns
the transformed rectangle

Field Documentation

◆ xx

attribute double Matrix2D::xx

xx

◆ xy

attribute double Matrix2D::xy

xy

◆ tx

attribute double Matrix2D::tx

tx

ty

◆ yx

attribute double Matrix2D::yx

yx

◆ yy

attribute double Matrix2D::yy

yy

◆ identity

attribute boolean Matrix2D::identity

matrix is identity

◆ is3D

attribute const boolean Matrix2D::is3D = false

indicates matrix is a 2D matrix