|
Packit Service |
e3b512 |
/* Copyright (C) 2008 Jonathon Jongsma
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
e3b512 |
* modify it under the terms of the GNU Library General Public
|
|
Packit Service |
e3b512 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
e3b512 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
e3b512 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
e3b512 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
e3b512 |
* Library General Public License for more details.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* You should have received a copy of the GNU Library General Public
|
|
Packit Service |
e3b512 |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
e3b512 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
e3b512 |
* 02110-1301, USA.
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
#ifndef __CAIROMM_MATRIX_H
|
|
Packit Service |
e3b512 |
#define __CAIROMM_MATRIX_H
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
#include <cairo.h>
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
namespace Cairo
|
|
Packit Service |
e3b512 |
{
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** @class cairo_matrix_t
|
|
Packit Service |
e3b512 |
* See the
|
|
Packit Service |
e3b512 |
* href="http://www.cairographics.org/manual/cairo-matrix.html">cairo_matrix_t
|
|
Packit Service |
e3b512 |
* reference in the cairo manual for more information
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** A Transformation matrix.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* Cairo::Matrix is used throughout cairomm to convert between different
|
|
Packit Service |
e3b512 |
* coordinate spaces. A Matrix holds an affine transformation, such as
|
|
Packit Service |
e3b512 |
* a scale, rotation, shear, or a combination of these. The transformation of
|
|
Packit Service |
e3b512 |
* a point (x,y) is given by:
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @code
|
|
Packit Service |
e3b512 |
* x_new = xx * x + xy * y + x0;
|
|
Packit Service |
e3b512 |
* y_new = yx * x + yy * y + y0;
|
|
Packit Service |
e3b512 |
* @endcode
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* The current transformation matrix of a Context, represented as a
|
|
Packit Service |
e3b512 |
* Matrix, defines the transformation from user-space coordinates to
|
|
Packit Service |
e3b512 |
* device-space coordinates.
|
|
Packit Service |
e3b512 |
* @sa Context::get_matrix()
|
|
Packit Service |
e3b512 |
* @sa Context::set_matrix()
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
class Matrix : public cairo_matrix_t
|
|
Packit Service |
e3b512 |
{
|
|
Packit Service |
e3b512 |
public:
|
|
Packit Service |
e3b512 |
/** Creates an uninitialized matrix. If you want a matrix initialized to a
|
|
Packit Service |
e3b512 |
* certain value, either specify the values explicitly with the other
|
|
Packit Service |
e3b512 |
* constructor or use one of the free functions for initializing matrices with
|
|
Packit Service |
e3b512 |
* specific scales, rotations, etc.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @sa identity_matrix()
|
|
Packit Service |
e3b512 |
* @sa rotation_matrix()
|
|
Packit Service |
e3b512 |
* @sa translation_matrix()
|
|
Packit Service |
e3b512 |
* @sa scaling_matrix()
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
Matrix();
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Creates a matrix Sets to be the affine transformation given by xx, yx, xy,
|
|
Packit Service |
e3b512 |
* yy, x0, y0. The transformation is given by:
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @code
|
|
Packit Service |
e3b512 |
* x_new = xx * x + xy * y + x0;
|
|
Packit Service |
e3b512 |
* y_new = yx * x + yy * y + y0;
|
|
Packit Service |
e3b512 |
* @endcode
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @param xx xx component of the affine transformation
|
|
Packit Service |
e3b512 |
* @param yx yx component of the affine transformation
|
|
Packit Service |
e3b512 |
* @param xy xy component of the affine transformation
|
|
Packit Service |
e3b512 |
* @param yy yy component of the affine transformation
|
|
Packit Service |
e3b512 |
* @param x0 X translation component of the affine transformation
|
|
Packit Service |
e3b512 |
* @param y0 Y translation component of the affine transformation
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
Matrix(double xx, double yx, double xy, double yy, double x0, double y0);
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Applies a translation by tx, ty to the transformation in matrix. The
|
|
Packit Service |
e3b512 |
* effect of the new transformation is to first translate the coordinates by
|
|
Packit Service |
e3b512 |
* tx and ty, then apply the original transformation to the coordinates.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @param tx amount to translate in the X direction
|
|
Packit Service |
e3b512 |
* @param ty amount to translate in the Y direction
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
void translate(double tx, double ty);
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Applies scaling by sx, sy to the transformation in matrix. The effect of
|
|
Packit Service |
e3b512 |
* the new transformation is to first scale the coordinates by sx and sy, then
|
|
Packit Service |
e3b512 |
* apply the original transformation to the coordinates.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @param sx scale factor in the X direction
|
|
Packit Service |
e3b512 |
* @param sy scale factor in the Y direction
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
void scale(double sx, double sy);
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Applies rotation by radians to the transformation in matrix. The effect of
|
|
Packit Service |
e3b512 |
* the new transformation is to first rotate the coordinates by radians, then
|
|
Packit Service |
e3b512 |
* apply the original transformation to the coordinates.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @param radians angle of rotation, in radians. The direction of rotation is
|
|
Packit Service |
e3b512 |
* defined such that positive angles rotate in the direction from the positive
|
|
Packit Service |
e3b512 |
* X axis toward the positive Y axis. With the default axis orientation of
|
|
Packit Service |
e3b512 |
* cairo, positive angles rotate in a clockwise direction.
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
void rotate(double radians);
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Changes matrix to be the inverse of it's original value. Not all
|
|
Packit Service |
e3b512 |
* transformation matrices have inverses; if the matrix collapses points
|
|
Packit Service |
e3b512 |
* together (it is degenerate), then it has no inverse and this function will
|
|
Packit Service |
e3b512 |
* throw an exception.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @exception
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
void invert();
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Multiplies the affine transformations in a and b together and stores the
|
|
Packit Service |
e3b512 |
* result in this matrix. The effect of the resulting transformation is to first
|
|
Packit Service |
e3b512 |
* apply the transformation in a to the coordinates and then apply the
|
|
Packit Service |
e3b512 |
* transformation in b to the coordinates.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* It is allowable for result to be identical to either a or b.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @param a a Matrix
|
|
Packit Service |
e3b512 |
* @param b a Matrix
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @sa operator*()
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
void multiply(Matrix& a, Matrix& b);
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Transforms the distance vector (dx,dy) by matrix. This is similar to
|
|
Packit Service |
e3b512 |
* transform_point() except that the translation components of the
|
|
Packit Service |
e3b512 |
* transformation are ignored. The calculation of the returned vector is as
|
|
Packit Service |
e3b512 |
* follows:
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @code
|
|
Packit Service |
e3b512 |
* dx2 = dx1 * a + dy1 * c;
|
|
Packit Service |
e3b512 |
* dy2 = dx1 * b + dy1 * d;
|
|
Packit Service |
e3b512 |
* @endcode
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* Affine transformations are position invariant, so the same vector always
|
|
Packit Service |
e3b512 |
* transforms to the same vector. If (x1,y1) transforms to (x2,y2) then
|
|
Packit Service |
e3b512 |
* (x1+dx1,y1+dy1) will transform to (x1+dx2,y1+dy2) for all values of x1 and
|
|
Packit Service |
e3b512 |
* x2.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @param dx X component of a distance vector. An in/out parameter
|
|
Packit Service |
e3b512 |
* @param dy Y component of a distance vector. An in/out parameter
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
void transform_distance(double& dx, double& dy) const;
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Transforms the point (x, y) by this matrix.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @param x X position. An in/out parameter
|
|
Packit Service |
e3b512 |
* @param y Y position. An in/out parameter
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
void transform_point(double& x, double& y) const;
|
|
Packit Service |
e3b512 |
};
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Returns a Matrix initialized to the identity matrix
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @relates Matrix
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
Matrix identity_matrix();
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Returns a Matrix initialized to a transformation that translates by tx and
|
|
Packit Service |
e3b512 |
* ty in the X and Y dimensions, respectively.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @param tx amount to translate in the X direction
|
|
Packit Service |
e3b512 |
* @param ty amount to translate in the Y direction
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @relates Matrix
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
Matrix translation_matrix(double tx, double ty);
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Returns a Matrix initialized to a transformation that scales by sx and sy in
|
|
Packit Service |
e3b512 |
* the X and Y dimensions, respectively.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @param sx scale factor in the X direction
|
|
Packit Service |
e3b512 |
* @param sy scale factor in the Y direction
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @relates Matrix
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
Matrix scaling_matrix(double sx, double sy);
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Returns a Matrix initialized to a transformation that rotates by radians.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @param radians angle of rotation, in radians. The direction of rotation is
|
|
Packit Service |
e3b512 |
* defined such that positive angles rotate in the direction from the positive X
|
|
Packit Service |
e3b512 |
* axis toward the positive Y axis. With the default axis orientation of cairo,
|
|
Packit Service |
e3b512 |
* positive angles rotate in a clockwise direction.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @relates Matrix
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
Matrix rotation_matrix(double radians);
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
/** Multiplies the affine transformations in a and b together and returns the
|
|
Packit Service |
e3b512 |
* result. The effect of the resulting transformation is to first
|
|
Packit Service |
e3b512 |
* apply the transformation in a to the coordinates and then apply the
|
|
Packit Service |
e3b512 |
* transformation in b to the coordinates.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* It is allowable for result to be identical to either a or b.
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @param a a Matrix
|
|
Packit Service |
e3b512 |
* @param b a Matrix
|
|
Packit Service |
e3b512 |
*
|
|
Packit Service |
e3b512 |
* @relates Matrix
|
|
Packit Service |
e3b512 |
*/
|
|
Packit Service |
e3b512 |
Matrix operator*(const Matrix& a, const Matrix& b);
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
} // namespace Cairo
|
|
Packit Service |
e3b512 |
|
|
Packit Service |
e3b512 |
#endif // __CAIROMM_MATRIX_H
|