Mozilla2:GFXMatrix: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 4: Line 4:
=== The API ===
=== The API ===
  class Matrix {
  class Matrix {
private:
    double m0, m1, m2, m3, m4, m5;
  public:
  public:
     Matrix() { reset(); }
     Matrix() { }
     Matrix(const Matrix& m);
     Matrix(const Matrix& m);
     Matrix(double a, double b, double c, double d, double tx, double ty);
     Matrix(double a, double b, double c, double d, double tx, double ty);
    Matrix(const cairo_matrix_t* m);
   
   
     const Matrix& operator *= (const Matrix& m) { return multiply(m); }
     Matrix& operator=(const cairo_matrix_t* m);
     Matrix operator * (const Matrix& m) { return Matrix(*this).multiply(m); }
     const Matrix& operator *= (const Matrix& m);
    Matrix operator * (const Matrix& m);
   
   
     const Matrix& reset();
     const Matrix& reset();
    const Matrix& invert();
     const Matrix& scale(double x, double y);
     const Matrix& scale(double x, double y);
     const Matrix& translate(double x, double y);
     const Matrix& translate(double x, double y);
     const Matrix& rotate(double radians);
     const Matrix& rotate(double radians);
     const Matrix& multiply(const Matrix& m);
     const Matrix& multiply(const Matrix& m);
     void transformDistance(double *dx, double *dy) const;
     void transformDistance(double *dx, double *dy) const;
     void transformPoint(double *x, double *y) const;
     void transformPoint(double *x, double *y) const;

Revision as of 06:39, 14 March 2005

Matrix Class

Since we'll be doing scaling, translations and rotates, we need some sort of matrix class. This class is really just an affine transform and might should be renamed to indicate that.

The API

class Matrix {
private:
    double m0, m1, m2, m3, m4, m5;

public:
    Matrix() { }
    Matrix(const Matrix& m);
    Matrix(double a, double b, double c, double d, double tx, double ty);
    Matrix(const cairo_matrix_t* m);

    Matrix& operator=(const cairo_matrix_t* m);
    const Matrix& operator *= (const Matrix& m);
    Matrix operator * (const Matrix& m);

    const Matrix& reset();
    const Matrix& invert();
    const Matrix& scale(double x, double y);
    const Matrix& translate(double x, double y);
    const Matrix& rotate(double radians);
    const Matrix& multiply(const Matrix& m);
    void transformDistance(double *dx, double *dy) const;
    void transformPoint(double *x, double *y) const;
};

Notes

Cairo currently uses row vectors to transform points, which is less optimal than if we used column vectors.