1 //////////////////////////////////////////////////////////////////////////////
2 // Name: SVGMatrix.cpp
3 // Purpose:
4 // Author: Alex Thuering
5 // Created: 2005/05/05
6 // RCS-ID: $Id: SVGMatrix.cpp,v 1.6 2014/08/09 11:13:02 ntalex Exp $
7 // Copyright: (c) 2005 Alex Thuering
8 // Licence: wxWindows licence
9 //////////////////////////////////////////////////////////////////////////////
10
11 #include "SVGMatrix.h"
12 #include <wx/math.h>
13
Multiply(const wxSVGMatrix & secondMatrix) const14 wxSVGMatrix wxSVGMatrix::Multiply(const wxSVGMatrix& secondMatrix) const {
15 wxSVGMatrix res;
16 res.SetA(GetA() * secondMatrix.GetA() + GetC() * secondMatrix.GetB());
17 res.SetB(GetB() * secondMatrix.GetA() + GetD() * secondMatrix.GetB());
18 res.SetC(GetA() * secondMatrix.GetC() + GetC() * secondMatrix.GetD());
19 res.SetD(GetB() * secondMatrix.GetC() + GetD() * secondMatrix.GetD());
20 res.SetE(GetA() * secondMatrix.GetE() + GetC() * secondMatrix.GetF() + GetE());
21 res.SetF(GetB() * secondMatrix.GetE() + GetD() * secondMatrix.GetF() + GetF());
22 return res;
23 }
24
Inverse() const25 wxSVGMatrix wxSVGMatrix::Inverse() const {
26 wxSVGMatrix res;
27 double d = 1.0 / (GetA() * GetD() - GetB() * GetC());
28 res.SetA(GetD() * d);
29 res.SetB(-GetB() * d);
30 res.SetC(-GetC() * d);
31 res.SetD(GetA() * d);
32 res.SetE(-GetE() * res.GetA() - GetF() * res.GetC());
33 res.SetF(-GetE() * res.GetB() - GetF() * res.GetD());
34 return res;
35 }
36
Translate(double x,double y) const37 wxSVGMatrix wxSVGMatrix::Translate(double x, double y) const {
38 return Multiply(wxSVGMatrix(1, 0, 0, 1, x, y));
39 }
40
Scale(double scaleFactor) const41 wxSVGMatrix wxSVGMatrix::Scale(double scaleFactor) const {
42 return Multiply(wxSVGMatrix(scaleFactor, 0, 0, scaleFactor, 0, 0));
43 }
44
ScaleNonUniform(double scaleFactorX,double scaleFactorY) const45 wxSVGMatrix wxSVGMatrix::ScaleNonUniform(double scaleFactorX, double scaleFactorY) const {
46 return Multiply(wxSVGMatrix(scaleFactorX, 0, 0, scaleFactorY, 0, 0));
47 }
48
Rotate(double angle) const49 wxSVGMatrix wxSVGMatrix::Rotate(double angle) const {
50 angle = angle * M_PI / 180;
51 return Multiply(wxSVGMatrix(cos(angle), sin(angle), -sin(angle), cos(angle), 0, 0));
52 }
53
RotateFromVector(double x,double y) const54 wxSVGMatrix wxSVGMatrix::RotateFromVector(double x, double y) const {
55 return Multiply(wxSVGMatrix(1, 0, 0, 1, 0, 0));
56 }
57
FlipX() const58 wxSVGMatrix wxSVGMatrix::FlipX() const {
59 return Multiply(wxSVGMatrix(-1, 0, 0, 1, 0, 0));
60 }
61
FlipY() const62 wxSVGMatrix wxSVGMatrix::FlipY() const {
63 return Multiply(wxSVGMatrix(1, 0, 0, -1, 0, 0));
64 }
65
SkewX(double angle) const66 wxSVGMatrix wxSVGMatrix::SkewX(double angle) const {
67 return Multiply(wxSVGMatrix(1, 0, tan(angle * M_PI / 180), 1, 0, 0));
68 }
69
SkewY(double angle) const70 wxSVGMatrix wxSVGMatrix::SkewY(double angle) const {
71 return Multiply(wxSVGMatrix(1, tan(angle * M_PI / 180), 0, 1, 0, 0));
72 }
73
74