/****************************************************************************
* gmatrix.h :
* 2D Transformation matrix class.
*
* Change Log :
* Jan 31, 1998 Initial version, Liujian Qian
*
* $Id: gmatrix.h,v 1.1.1.1 1998/05/21 05:37:28 qian Exp $
***************************************************************************/
#ifndef _GMATRIX_H_
#define _GMATRIX_H_
#include "gobject.h"
class DataPipe;
/**
Defines a 2D transformation matrix.
DESCRIPTION
GMatrix does the classical 2D transformations such as translation,
scale, shear, and rotate.
*/
class GMatrix : public GObject
{
double a11, a12;
double a21, a22;
double dx, dy;
public:
///
// ctors
//
NOP GMatrix();
NOP GMatrix(double m11, double m12, double m21, double m22,
double dx, double dy );
///
// initialize it to be an identity matrix
//
Result init();
///
// set the parameters
//
void set(double m11, double m12, double m21, double m22,
double dx, double dy );
///
// transform (x,y) to (new_x, new_y)
//
void xform(int x, int y, int& new_x, int& new_y) const;
///
// same as above but work on doubles
//
void xform(double x, double y, double& new_x, double& new_y) const;
///
// transform an array of points (x1 y1 x2 y2...) to new_points;
//
void xform(int n, double* points, double* new_points);
///
// setup the translation
//
GMatrix& translate(double dx, double dy);
///
// setup the scale information
//
GMatrix& scale(double sx, double sy);
///
// setup the shearing
//
GMatrix& shear(double sh, double sv);
///
// setup the rotation
//
GMatrix& rotate( double a);
///
// return the invert matrix, set the invertable flag
//
GMatrix invert(bool& invertable) const;
///
//
GMatrix& operator*= ( const GMatrix& mx);
///
// serialize a matrix into a pipe
//
Result pack (DataPipe& p) const ;
///
// restore a matrix out of a pipe
//
Result unpack (DataPipe& p) ;
private:
GMatrix& mult(const GMatrix& o);
};
GMatrix operator* (const GMatrix& a, const GMatrix& b);
#endif
Documentation generated by lqian@lqian-sun on Wed Jul 14 09:36:10 EDT 1999