Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
cairo-matrix.c File Reference
#include <stdlib.h>
#include "cairoint.h"

Go to the source code of this file.

Defines

#define _GNU_SOURCE

Functions

static void _cairo_matrix_scalar_multiply (cairo_matrix_t *matrix, double scalar)
static void _cairo_matrix_compute_adjoint (cairo_matrix_t *matrix)
void cairo_matrix_init_identity (cairo_matrix_t *matrix)
 cairo_matrix_init_identity: : a cairo_matrix_t
 slim_hidden_def (cairo_matrix_init_identity)
void cairo_matrix_init (cairo_matrix_t *matrix, double xx, double yx, double xy, double yy, double x0, double y0)
 cairo_matrix_init: : a cairo_matrix_t : xx component of the affine transformation : yx component of the affine transformation : xy component of the affine transformation : yy component of the affine transformation : X translation component of the affine transformation : Y translation component of the affine transformation
 slim_hidden_def (cairo_matrix_init)
void _cairo_matrix_get_affine (const cairo_matrix_t *matrix, double *xx, double *yx, double *xy, double *yy, double *x0, double *y0)
 _cairo_matrix_get_affine: : a : location to store xx component of matrix : location to store yx component of matrix : location to store xy component of matrix : location to store yy component of matrix : location to store x0 (X-translation component) of matrix, or NULL : location to store y0 (Y-translation component) of matrix, or NULL
void cairo_matrix_init_translate (cairo_matrix_t *matrix, double tx, double ty)
 cairo_matrix_init_translate: : a cairo_matrix_t : amount to translate in the X direction : amount to translate in the Y direction
 slim_hidden_def (cairo_matrix_init_translate)
void cairo_matrix_translate (cairo_matrix_t *matrix, double tx, double ty)
 cairo_matrix_translate: : a cairo_matrix_t : amount to translate in the X direction : amount to translate in the Y direction
void cairo_matrix_init_scale (cairo_matrix_t *matrix, double sx, double sy)
 cairo_matrix_init_scale: : a cairo_matrix_t : scale factor in the X direction : scale factor in the Y direction
 slim_hidden_def (cairo_matrix_init_scale)
void cairo_matrix_scale (cairo_matrix_t *matrix, double sx, double sy)
 cairo_matrix_scale: : a cairo_matrix_t : scale factor in the X direction : scale factor in the Y direction
 slim_hidden_def (cairo_matrix_scale)
void cairo_matrix_init_rotate (cairo_matrix_t *matrix, double radians)
 cairo_matrix_init_rotate: : a cairo_matrix_t : angle of rotation, in radians.
 slim_hidden_def (cairo_matrix_init_rotate)
void cairo_matrix_rotate (cairo_matrix_t *matrix, double radians)
 cairo_matrix_rotate: : a : angle of rotation, in radians.
void cairo_matrix_multiply (cairo_matrix_t *result, const cairo_matrix_t *a, const cairo_matrix_t *b)
 cairo_matrix_multiply:
 slim_hidden_def (cairo_matrix_multiply)
void cairo_matrix_transform_distance (const cairo_matrix_t *matrix, double *dx, double *dy)
 cairo_matrix_transform_distance: : a : X component of a distance vector.
 slim_hidden_def (cairo_matrix_transform_distance)
void cairo_matrix_transform_point (const cairo_matrix_t *matrix, double *x, double *y)
 cairo_matrix_transform_point: : a : X position.
 slim_hidden_def (cairo_matrix_transform_point)
void _cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix, double *x, double *y, double *width, double *height)
cairo_status_t cairo_matrix_invert (cairo_matrix_t *matrix)
 cairo_matrix_invert: : a
 slim_hidden_def (cairo_matrix_invert)
void _cairo_matrix_compute_determinant (const cairo_matrix_t *matrix, double *det)
cairo_status_t _cairo_matrix_compute_scale_factors (const cairo_matrix_t *matrix, double *sx, double *sy, int x_major)
cairo_bool_t _cairo_matrix_is_integer_translation (const cairo_matrix_t *m, int *itx, int *ity)
double _cairo_matrix_transformed_circle_major_axis (cairo_matrix_t *matrix, double radius)

Define Documentation

Definition at line 37 of file cairo-matrix.c.


Function Documentation

static void _cairo_matrix_compute_adjoint ( cairo_matrix_t matrix) [static]

Definition at line 427 of file cairo-matrix.c.

{
    /* adj (A) = transpose (C:cofactor (A,i,j)) */
    double a, b, c, d, tx, ty;

    _cairo_matrix_get_affine (matrix,
                           &a,  &b,
                           &c,  &d,
                           &tx, &ty);

    cairo_matrix_init (matrix,
                     d, -b,
                     -c, a,
                     c*ty - d*tx, b*tx - a*ty);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _cairo_matrix_compute_determinant ( const cairo_matrix_t matrix,
double *  det 
)

Definition at line 475 of file cairo-matrix.c.

{
    double a, b, c, d;

    a = matrix->xx; b = matrix->yx;
    c = matrix->xy; d = matrix->yy;

    *det = a*d - b*c;
}

Here is the caller graph for this function:

cairo_status_t _cairo_matrix_compute_scale_factors ( const cairo_matrix_t matrix,
double *  sx,
double *  sy,
int  x_major 
)

Definition at line 488 of file cairo-matrix.c.

{
    double det;

    _cairo_matrix_compute_determinant (matrix, &det);

    if (det == 0)
    {
       *sx = *sy = 0;
    }
    else
    {
       double x = x_major != 0;
       double y = x == 0;
       double major, minor;
       
       cairo_matrix_transform_distance (matrix, &x, &y);
       major = sqrt(x*x + y*y);
       /*
        * ignore mirroring
        */
       if (det < 0)
           det = -det;
       if (major)
           minor = det / major;
       else 
           minor = 0.0;
       if (x_major)
       {
           *sx = major;
           *sy = minor;
       }
       else
       {
           *sx = minor;
           *sy = major;
       }
    }

    return CAIRO_STATUS_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _cairo_matrix_get_affine ( const cairo_matrix_t matrix,
double *  xx,
double *  yx,
double *  xy,
double *  yy,
double *  x0,
double *  y0 
)

_cairo_matrix_get_affine: : a : location to store xx component of matrix : location to store yx component of matrix : location to store xy component of matrix : location to store yy component of matrix : location to store x0 (X-translation component) of matrix, or NULL : location to store y0 (Y-translation component) of matrix, or NULL

Gets the matrix values for the affine tranformation that represents. See cairo_matrix_init().

This function is a leftover from the old public API, but is still mildly useful as an internal means for getting at the matrix members in a positional way. For example, when reassigning to some external matrix type, or when renaming members to more meaningful names (such as a,b,c,d,e,f) for particular manipulations.

Definition at line 116 of file cairo-matrix.c.

{
    *xx  = matrix->xx;
    *yx  = matrix->yx;

    *xy  = matrix->xy;
    *yy  = matrix->yy;

    if (x0)
       *x0 = matrix->x0;
    if (y0)
       *y0 = matrix->y0;
}

Here is the caller graph for this function:

Definition at line 532 of file cairo-matrix.c.

{
    cairo_bool_t is_integer_translation;
    cairo_fixed_t x0_fixed, y0_fixed;

    x0_fixed = _cairo_fixed_from_double (m->x0);
    y0_fixed = _cairo_fixed_from_double (m->y0);

    is_integer_translation = ((m->xx == 1.0) &&
                           (m->yx == 0.0) &&
                           (m->xy == 0.0) &&
                           (m->yy == 1.0) &&
                           (_cairo_fixed_is_integer(x0_fixed)) &&
                           (_cairo_fixed_is_integer(y0_fixed)));

    if (! is_integer_translation)
       return FALSE;

    if (itx)
       *itx = _cairo_fixed_integer_part(x0_fixed);
    if (ity)
       *ity = _cairo_fixed_integer_part(y0_fixed);

    return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void _cairo_matrix_scalar_multiply ( cairo_matrix_t matrix,
double  scalar 
) [static]

Definition at line 410 of file cairo-matrix.c.

{
    matrix->xx *= scalar;
    matrix->yx *= scalar;

    matrix->xy *= scalar;
    matrix->yy *= scalar;

    matrix->x0 *= scalar;
    matrix->y0 *= scalar;
}

Here is the caller graph for this function:

void _cairo_matrix_transform_bounding_box ( const cairo_matrix_t matrix,
double *  x,
double *  y,
double *  width,
double *  height 
)

Definition at line 358 of file cairo-matrix.c.

{
    int i;
    double quad_x[4], quad_y[4];
    double dx1, dy1;
    double dx2, dy2;
    double min_x, max_x;
    double min_y, max_y;

    quad_x[0] = *x;
    quad_y[0] = *y;
    cairo_matrix_transform_point (matrix, &quad_x[0], &quad_y[0]);

    dx1 = *width;
    dy1 = 0;
    cairo_matrix_transform_distance (matrix, &dx1, &dy1);
    quad_x[1] = quad_x[0] + dx1;
    quad_y[1] = quad_y[0] + dy1;

    dx2 = 0;
    dy2 = *height;
    cairo_matrix_transform_distance (matrix, &dx2, &dy2);
    quad_x[2] = quad_x[0] + dx2;
    quad_y[2] = quad_y[0] + dy2;

    quad_x[3] = quad_x[0] + dx1 + dx2;
    quad_y[3] = quad_y[0] + dy1 + dy2;

    min_x = max_x = quad_x[0];
    min_y = max_y = quad_y[0];

    for (i=1; i < 4; i++) {
       if (quad_x[i] < min_x)
           min_x = quad_x[i];
       if (quad_x[i] > max_x)
           max_x = quad_x[i];

       if (quad_y[i] < min_y)
           min_y = quad_y[i];
       if (quad_y[i] > max_y)
           max_y = quad_y[i];
    }

    *x = min_x;
    *y = min_y;
    *width = max_x - min_x;
    *height = max_y - min_y;
}
double _cairo_matrix_transformed_circle_major_axis ( cairo_matrix_t matrix,
double  radius 
)

Definition at line 680 of file cairo-matrix.c.

{
    double  a, b, c, d, f, g, h, i, j;

    _cairo_matrix_get_affine (matrix,
                              &a, &b,
                              &c, &d,
                              NULL, NULL);

    i = a*a + b*b;
    j = c*c + d*d;

    f = 0.5 * (i + j);
    g = 0.5 * (i - j);
    h = a*c + b*d;

    return radius * sqrt (f + sqrt (g*g+h*h));

    /*
     * we don't need the minor axis length, which is
     * double min = radius * sqrt (f - sqrt (g*g+h*h));
     */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cairo_matrix_init ( cairo_matrix_t matrix,
double  xx,
double  yx,
double  xy,
double  yy,
double  x0,
double  y0 
)

cairo_matrix_init: : a cairo_matrix_t : xx component of the affine transformation : yx component of the affine transformation : xy component of the affine transformation : yy component of the affine transformation : X translation component of the affine transformation : Y translation component of the affine transformation

Sets to be the affine transformation given by , , , , , . The transformation is given by: <programlisting> x_new = xx * x + xy * y + x0; y_new = yx * x + yy * y + y0; </programlisting>

Definition at line 83 of file cairo-matrix.c.

{
    matrix->xx = xx; matrix->yx = yx;
    matrix->xy = xy; matrix->yy = yy;
    matrix->x0 = x0; matrix->y0 = y0;
}

Here is the call graph for this function:

cairo_matrix_init_identity: : a cairo_matrix_t

Modifies to be an identity transformation.

Definition at line 55 of file cairo-matrix.c.

{
    cairo_matrix_init (matrix,
                     1, 0,
                     0, 1,
                     0, 0);
}
void cairo_matrix_init_rotate ( cairo_matrix_t matrix,
double  radians 
)

cairo_matrix_init_rotate: : a cairo_matrix_t : angle of rotation, in radians.

The direction of rotation is defined such that positive angles rotate in the direction from the positive X axis toward the positive Y axis. With the default axis orientation of cairo, positive angles rotate in a clockwise direction.

Initialized to a transformation that rotates by .

Definition at line 227 of file cairo-matrix.c.

{
    double  s;
    double  c;

    s = sin (radians);
    c = cos (radians);

    cairo_matrix_init (matrix,
                     c, s,
                     -s, c,
                     0, 0);
}
void cairo_matrix_init_scale ( cairo_matrix_t matrix,
double  sx,
double  sy 
)

cairo_matrix_init_scale: : a cairo_matrix_t : scale factor in the X direction : scale factor in the Y direction

Initializes to a transformation that scales by and in the X and Y dimensions, respectively.

Definition at line 184 of file cairo-matrix.c.

{
    cairo_matrix_init (matrix,
                     sx,  0,
                     0, sy,
                     0, 0);
}
void cairo_matrix_init_translate ( cairo_matrix_t matrix,
double  tx,
double  ty 
)

cairo_matrix_init_translate: : a cairo_matrix_t : amount to translate in the X direction : amount to translate in the Y direction

Initializes to a transformation that translates by and in the X and Y dimensions, respectively.

Definition at line 143 of file cairo-matrix.c.

{
    cairo_matrix_init (matrix,
                     1, 0,
                     0, 1,
                     tx, ty);
}

cairo_matrix_invert: : a

Changes to be the inverse of it's original value. Not all transformation matrices have inverses; if the matrix collapses points together (it is <firstterm>degenerate</firstterm>), then it has no inverse and this function will fail.

Returns: If has an inverse, modifies to be the inverse matrix and returns CAIRO_STATUS_SUCCESS. Otherwise, returns CAIRO_STATUS_INVALID_MATRIX.

Definition at line 457 of file cairo-matrix.c.

{
    /* inv (A) = 1/det (A) * adj (A) */
    double det;

    _cairo_matrix_compute_determinant (matrix, &det);
    
    if (det == 0)
       return CAIRO_STATUS_INVALID_MATRIX;

    _cairo_matrix_compute_adjoint (matrix);
    _cairo_matrix_scalar_multiply (matrix, 1 / det);

    return CAIRO_STATUS_SUCCESS;
}

Here is the call graph for this function:

cairo_matrix_multiply:

Returns:
: a in which to store the result : a : a

Multiplies the affine transformations in and together and stores the result in

Returns:
. The effect of the resulting transformation is to first apply the transformation in to the coordinates and then apply the transformation in to the coordinates.

It is allowable for

Returns:
to be identical to either or .

Definition at line 288 of file cairo-matrix.c.

{
    cairo_matrix_t r;

    r.xx = a->xx * b->xx + a->yx * b->xy;
    r.yx = a->xx * b->yx + a->yx * b->yy;

    r.xy = a->xy * b->xx + a->yy * b->xy;
    r.yy = a->xy * b->yx + a->yy * b->yy;

    r.x0 = a->x0 * b->xx + a->y0 * b->xy + b->x0;
    r.y0 = a->x0 * b->yx + a->y0 * b->yy + b->y0;

    *result = r;
}
void cairo_matrix_rotate ( cairo_matrix_t matrix,
double  radians 
)

cairo_matrix_rotate: : a : angle of rotation, in radians.

The direction of rotation is defined such that positive angles rotate in the direction from the positive X axis toward the positive Y axis. With the default axis orientation of cairo, positive angles rotate in a clockwise direction.

Applies rotation by to the transformation in . The effect of the new transformation is to first rotate the coordinates by , then apply the original transformation to the coordinates.

Definition at line 258 of file cairo-matrix.c.

{
    cairo_matrix_t tmp;

    cairo_matrix_init_rotate (&tmp, radians);

    cairo_matrix_multiply (matrix, &tmp, matrix);
}
void cairo_matrix_scale ( cairo_matrix_t matrix,
double  sx,
double  sy 
)

cairo_matrix_scale: : a cairo_matrix_t : scale factor in the X direction : scale factor in the Y direction

Applies scaling by , to the transformation in . The effect of the new transformation is to first scale the coordinates by and , then apply the original transformation to the coordinates.

Definition at line 205 of file cairo-matrix.c.

{
    cairo_matrix_t tmp;

    cairo_matrix_init_scale (&tmp, sx, sy);

    cairo_matrix_multiply (matrix, &tmp, matrix);
}
void cairo_matrix_transform_distance ( const cairo_matrix_t matrix,
double *  dx,
double *  dy 
)

cairo_matrix_transform_distance: : a : X component of a distance vector.

An in/out parameter : Y component of a distance vector. An in/out parameter

Transforms the distance vector (,) by . This is similar to cairo_matrix_transform() except that the translation components of the transformation are ignored. The calculation of the returned vector is as follows:

<programlisting> dx2 = dx1 * a + dy1 * c; dy2 = dx1 * b + dy1 * d; </programlisting>

Affine transformations are position invariant, so the same vector always transforms to the same vector. If (,) transforms to (,) then (+,+) will transform to (+,+) for all values of and .

Definition at line 327 of file cairo-matrix.c.

{
    double new_x, new_y;

    new_x = (matrix->xx * *dx + matrix->xy * *dy);
    new_y = (matrix->yx * *dx + matrix->yy * *dy);

    *dx = new_x;
    *dy = new_y;
}
void cairo_matrix_transform_point ( const cairo_matrix_t matrix,
double *  x,
double *  y 
)

cairo_matrix_transform_point: : a : X position.

An in/out parameter : Y position. An in/out parameter

Transforms the point (, ) by .

Definition at line 348 of file cairo-matrix.c.

{
    cairo_matrix_transform_distance (matrix, x, y);

    *x += matrix->x0;
    *y += matrix->y0;
}
void cairo_matrix_translate ( cairo_matrix_t matrix,
double  tx,
double  ty 
)

cairo_matrix_translate: : a cairo_matrix_t : amount to translate in the X direction : amount to translate in the Y direction

Applies a translation by , to the transformation in . The effect of the new transformation is to first translate the coordinates by and , then apply the original transformation to the coordinates.

Definition at line 165 of file cairo-matrix.c.

{
    cairo_matrix_t tmp;

    cairo_matrix_init_translate (&tmp, tx, ty);

    cairo_matrix_multiply (matrix, &tmp, matrix);
}