libgpac
Documentation of the core library of GPAC
Math 2d

2D Mathematics More...

+ Collaboration diagram for Math 2d:

Data Structures

struct  GF_Point2D
 2D point More...
 
struct  GF_Rect
 rectangle 2D More...
 
struct  GF_IRect
 pixel-aligned rectangle More...
 
struct  GF_Matrix2D
 2D matrix More...
 

Macros

#define gf_mx2d_init(_obj)
 matrix initialization More...
 
#define gf_mx2d_copy(_obj, from)
 matrix copy More...
 
#define gf_mx2d_is_identity(_obj)
 matrix identity testing More...
 

Functions

Fixed gf_v2d_len (GF_Point2D *vec)
 get 2D vector length More...
 
Fixed gf_v2d_distance (GF_Point2D *a, GF_Point2D *b)
 get distance between 2 points More...
 
GF_Point2D gf_v2d_from_polar (Fixed length, Fixed angle)
 2D vector from polar coordinates More...
 
void gf_rect_union (GF_Rect *rc1, GF_Rect *rc2)
 rectangle union More...
 
GF_Rect gf_rect_center (Fixed w, Fixed h)
 centers a rectangle More...
 
Bool gf_rect_overlaps (GF_Rect rc1, GF_Rect rc2)
 rectangle overlap test More...
 
Bool gf_rect_equal (GF_Rect *rc1, GF_Rect *rc2)
 rectangle identity test More...
 
void gf_rect_intersect (GF_Rect *rc1, GF_Rect *rc2)
 rectangle intersection More...
 
GF_IRect gf_rect_pixelize (GF_Rect *r)
 gets the pixelized version of a rectangle More...
 
void gf_irect_union (GF_IRect *rc1, GF_IRect *rc2)
 
void gf_mx2d_add_matrix (GF_Matrix2D *_this, GF_Matrix2D *from)
 2D matrix multiplication More...
 
void gf_mx2d_pre_multiply (GF_Matrix2D *_this, GF_Matrix2D *from)
 2D matrix pre-multiplication More...
 
void gf_mx2d_add_translation (GF_Matrix2D *_this, Fixed cx, Fixed cy)
 matrix translating More...
 
void gf_mx2d_add_rotation (GF_Matrix2D *_this, Fixed cx, Fixed cy, Fixed angle)
 matrix rotating More...
 
void gf_mx2d_add_scale (GF_Matrix2D *_this, Fixed scale_x, Fixed scale_y)
 matrix scaling More...
 
void gf_mx2d_add_scale_at (GF_Matrix2D *_this, Fixed scale_x, Fixed scale_y, Fixed cx, Fixed cy, Fixed angle)
 matrix uncentered scaling More...
 
void gf_mx2d_add_skew (GF_Matrix2D *_this, Fixed skew_x, Fixed skew_y)
 matrix skewing More...
 
void gf_mx2d_add_skew_x (GF_Matrix2D *_this, Fixed angle)
 matrix horizontal skewing More...
 
void gf_mx2d_add_skew_y (GF_Matrix2D *_this, Fixed angle)
 matrix vertical skewing More...
 
void gf_mx2d_inverse (GF_Matrix2D *_this)
 matrix inversing More...
 
void gf_mx2d_apply_coords (GF_Matrix2D *_this, Fixed *x, Fixed *y)
 matrix coordinate transformation More...
 
void gf_mx2d_apply_point (GF_Matrix2D *_this, GF_Point2D *pt)
 matrix point transformation More...
 
void gf_mx2d_apply_rect (GF_Matrix2D *_this, GF_Rect *rc)
 matrix rectangle transformation More...
 
Bool gf_mx2d_decompose (GF_Matrix2D *_this, GF_Point2D *scale, Fixed *rotate, GF_Point2D *translate)
 matrix decomposition More...
 

Detailed Description

This section documents mathematic tools for 2D geometry and color matrices operations


Data Structure Documentation

◆ GF_Point2D

struct GF_Point2D

The 2D point object is used in all the GPAC framework for both point and vector representation.

Data Fields
Fixed x
Fixed y

◆ GF_Rect

struct GF_Rect

The 2D rectangle used in the GPAC project.

Data Fields
Fixed x

the left coordinate of the rectangle

Fixed y

the top coordinate of the rectangle, regardless of the canvas orientation. In other words, y is always the greatest coordinate value, even if the rectangle is presented bottom-up. This insures proper rectangles testing

Fixed width

the width of the rectangle. Width must be greater than or equal to 0

Fixed height

the height of the rectangle. Height must be greater than or equal to 0

◆ GF_IRect

struct GF_IRect

Pixel-aligned rectangle used in the GPAC framework. This is usually needed for 2D drawing algorithms.

Data Fields
s32 x

the left coordinate of the rectangle

s32 y

the top coordinate of the rectangle, regardless of the canvas orientation. In other words, y is always the greatest coordinate value, even if the rectangle is presented bottom-up. This insures proper rectangles operations

s32 width

the width of the rectangle. Width must be greater than or equal to 0

s32 height

the height of the rectangle. Height must be greater than or equal to 0

◆ GF_Matrix2D

struct GF_Matrix2D

The 2D affine matrix object usied in GPAC. The transformation of P(x,y) in P'(X, Y) is:

X = m[0]*x + m[1]*y + m[2];
Y = m[3]*x + m[4]*y + m[5];
Data Fields
Fixed m[6]

Macro Definition Documentation

◆ gf_mx2d_init

#define gf_mx2d_init (   _obj)

Inits the matrix to the identity matrix

◆ gf_mx2d_copy

#define gf_mx2d_copy (   _obj,
  from 
)

Copies the matrix _from to the matrix _obj

◆ gf_mx2d_is_identity

#define gf_mx2d_is_identity (   _obj)

This macro evaluates to 1 if the matrix _obj is the identity matrix, 0 otherwise

Function Documentation

◆ gf_v2d_len()

Fixed gf_v2d_len ( GF_Point2D vec)

Gets the length of a 2D vector

Parameters
vecthe target vector
Returns
length of the vector

◆ gf_v2d_distance()

Fixed gf_v2d_distance ( GF_Point2D a,
GF_Point2D b 
)

Gets the distance between the 2 points

Parameters
afirst point
bsecond point
Returns
distance

◆ gf_v2d_from_polar()

GF_Point2D gf_v2d_from_polar ( Fixed  length,
Fixed  angle 
)

Constructs a 2D vector from its polar coordinates

Parameters
lengththe length of the vector
anglethe angle of the vector in radians
Returns
the 2D vector

◆ gf_rect_union()

void gf_rect_union ( GF_Rect rc1,
GF_Rect rc2 
)

Gets the union of two rectangles.

Parameters
rc1first rectangle of the union. Upon return, this rectangle will contain the result of the union
rc2second rectangle of the union

◆ gf_rect_center()

GF_Rect gf_rect_center ( Fixed  w,
Fixed  h 
)

Builds a rectangle centered on the origin

Parameters
wwidth of the rectangle
hheight of the rectangle
Returns
centered rectangle object

◆ gf_rect_overlaps()

Bool gf_rect_overlaps ( GF_Rect  rc1,
GF_Rect  rc2 
)

Tests if two rectangles overlap.

Parameters
rc1first rectangle to test
rc2second rectangle to test
Returns
1 if rectangles overlap, 0 otherwise

◆ gf_rect_equal()

Bool gf_rect_equal ( GF_Rect rc1,
GF_Rect rc2 
)

Tests if two rectangles are identical.

Parameters
rc1first rectangle to test
rc2second rectangle to test
Returns
1 if rectangles are identical, 0 otherwise

◆ gf_rect_intersect()

void gf_rect_intersect ( GF_Rect rc1,
GF_Rect rc2 
)

Intersects two rectangle.

Parameters
rc1rectangle to use, updated to intersection result
rc2second rectangle to use

◆ gf_rect_pixelize()

GF_IRect gf_rect_pixelize ( GF_Rect r)

Gets the smallest pixel-aligned rectangle completely containing a rectangle

Parameters
rthe rectangle to transform
Returns
the pixel-aligned transformed rectangle

◆ gf_irect_union()

void gf_irect_union ( GF_IRect rc1,
GF_IRect rc2 
)

add adds rc2 to rc1 - the new rc1 contains the old rc1 and rc2

Parameters
rc1target rectangle
rc2rectangle to add

◆ gf_mx2d_add_matrix()

void gf_mx2d_add_matrix ( GF_Matrix2D _this,
GF_Matrix2D from 
)

Multiplies two 2D matrices from*_this

Parameters
_thismatrix being transformed. Once the function is called, _this contains the result matrix
fromtransformation matrix to add

◆ gf_mx2d_pre_multiply()

void gf_mx2d_pre_multiply ( GF_Matrix2D _this,
GF_Matrix2D from 
)

Multiplies two 2D matrices _this*from

Parameters
_thismatrix being transformed. Once the function is called, _this contains the result matrix
fromtransformation matrix to add

◆ gf_mx2d_add_translation()

void gf_mx2d_add_translation ( GF_Matrix2D _this,
Fixed  cx,
Fixed  cy 
)

Translates a 2D matrix

Parameters
_thismatrix being transformed. Once the function is called, _this contains the result matrix
cxhorizontal translation
cyvertical translation

◆ gf_mx2d_add_rotation()

void gf_mx2d_add_rotation ( GF_Matrix2D _this,
Fixed  cx,
Fixed  cy,
Fixed  angle 
)

Rotates a 2D matrix

Parameters
_thismatrix being transformed. Once the function is called, _this contains the result matrix
cxhorizontal rotation center coordinate
cyvertical rotation center coordinate
anglerotation angle in radians

◆ gf_mx2d_add_scale()

void gf_mx2d_add_scale ( GF_Matrix2D _this,
Fixed  scale_x,
Fixed  scale_y 
)

Scales a 2D matrix

Parameters
_thismatrix being transformed. Once the function is called, _this contains the result matrix
scale_xhorizontal scaling factor
scale_yvertical scaling factor

◆ gf_mx2d_add_scale_at()

void gf_mx2d_add_scale_at ( GF_Matrix2D _this,
Fixed  scale_x,
Fixed  scale_y,
Fixed  cx,
Fixed  cy,
Fixed  angle 
)

Scales a 2D matrix with a non-centered scale

Parameters
_thismatrix being transformed. Once the function is called, _this contains the result matrix
scale_xhorizontal scaling factor
scale_yvertical scaling factor
cxhorizontal scaling center coordinate
cyvertical scaling center coordinate
anglescale orienttion angle in radians

◆ gf_mx2d_add_skew()

void gf_mx2d_add_skew ( GF_Matrix2D _this,
Fixed  skew_x,
Fixed  skew_y 
)

Skews a 2D matrix

Parameters
_thismatrix being transformed. Once the function is called, _this contains the result matrix
skew_xhorizontal skew factor
skew_yvertical skew factor

◆ gf_mx2d_add_skew_x()

void gf_mx2d_add_skew_x ( GF_Matrix2D _this,
Fixed  angle 
)

Skews a 2D matrix horizontally by a given angle

Parameters
_thismatrix being transformed. Once the function is called, _this contains the result matrix
anglehorizontal skew angle in radians

◆ gf_mx2d_add_skew_y()

void gf_mx2d_add_skew_y ( GF_Matrix2D _this,
Fixed  angle 
)

Skews a 2D matrix vertically by a given angle

Parameters
_thismatrix being transformed. Once the function is called, _this contains the result matrix
anglevertical skew angle in radians

◆ gf_mx2d_inverse()

void gf_mx2d_inverse ( GF_Matrix2D _this)

Inverses a 2D matrix

Parameters
_thismatrix being transformed. Once the function is called, _this contains the result matrix

◆ gf_mx2d_apply_coords()

void gf_mx2d_apply_coords ( GF_Matrix2D _this,
Fixed x,
Fixed y 
)

Applies a 2D matrix transformation to coordinates

Parameters
_thistransformation matrix
xpointer to horizontal coordinate. Once the function is called, x contains the transformed horizontal coordinate
ypointer to vertical coordinate. Once the function is called, y contains the transformed vertical coordinate

◆ gf_mx2d_apply_point()

void gf_mx2d_apply_point ( GF_Matrix2D _this,
GF_Point2D pt 
)

Applies a 2D matrix transformation to a 2D point

Parameters
_thistransformation matrix
ptpointer to 2D point. Once the function is called, pt contains the transformed point

◆ gf_mx2d_apply_rect()

void gf_mx2d_apply_rect ( GF_Matrix2D _this,
GF_Rect rc 
)

Applies a 2D matrix transformation to a rectangle, giving the enclosing rectangle of the transformed one

Parameters
_thistransformation matrix
rcpointer to rectangle. Once the function is called, rc contains the transformed rectangle

◆ gf_mx2d_decompose()

Bool gf_mx2d_decompose ( GF_Matrix2D _this,
GF_Point2D scale,
Fixed rotate,
GF_Point2D translate 
)

Decomposes a 2D matrix M as M=Scale x Rotation x Translation if possible

Parameters
_thistransformation matrix
scaleresulting scale part
rotateresulting rotation part
translateresulting translation part
Returns
0 if matrix cannot be decomposed, 1 otherwise