/*
    Copyright (C) 2001-2003 KSVG Team
    This file is part of the KDE project
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.
 
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.
 
    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef MATRIX_H
#define MATRIX_H

#include <qwmatrix.h>

/**
 * Gracefully borrowed from the KSVG project
 */
class Matrix
{
public:
  Matrix();
  Matrix(QWMatrix mat);
  Matrix(double, double, double, double, double, double);
  ~Matrix();

  bool operator==(const Matrix&);
  bool operator!=(const Matrix&);

  void setA(const double &);
  double a() const;

  void setB(const double &);
  double b() const;

  void setC(const double &);
  double c() const;

  void setD(const double &);
  double d() const;

  void setE(const double &);
  double e() const;

  void setF(const double &);
  double f() const;

  void copy(const Matrix& other);

  void debugPrint() const;

  /**
   * Returns an inverted copy of this Matrix
   */
  Matrix inverse() const;

  /**
   * Inverts this Matrix
   * @return 
   */
  Matrix *invert();

  // Pre-multiplied operations, as per the specs.
  Matrix *multiply(const Matrix &secondMatrix);
  Matrix *translate(const double &x, const double &y);
  Matrix *scale(const double &scaleFactor);
  Matrix *scaleNonUniform(const double &scaleFactorX, const double &scaleFactorY);
  Matrix *rotate(const double &angle);
  Matrix *rotateFromVector(const double &x, const double &y);
  Matrix *flipX();
  Matrix *flipY();
  Matrix *skewX(const double &angle);
  Matrix *skewY(const double &angle);

  // Post-multiplied operations
  Matrix *postMultiply(const Matrix &secondMatrix);
  Matrix *postTranslate(const double &x, const double &y);
  Matrix *postScale(const double &scaleFactorX, const double &scaleFactorY);
  Matrix *postRotate(const double &angle);
  Matrix *postRotateFromVector(const double &x, const double &y);
  Matrix *postFlipX();
  Matrix *postFlipY();
  Matrix *postSkewX(const double &angle);
  Matrix *postSkewY(const double &angle);

  void reset();

  // KSVG helper method
  QWMatrix &qmatrix();
  const QWMatrix &qmatrix() const;

private:
  void setMatrix(QWMatrix mat);
  QWMatrix m_mat;

};
#endif
