Laxkit  0.0.7.1
transformmath.h
1 //
2 //
3 // The Laxkit, a windowing toolkit
4 // Please consult http://laxkit.sourceforge.net about where to send any
5 // correspondence about this software.
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // Copyright (C) 2004-2012 by Tom Lechner
22 //
23 #ifndef _LAX_TRANSFORMMATH_H
24 #define _LAX_TRANSFORMMATH_H
25 
26 #include <lax/vectors.h>
27 
28 //-------------------- Affine Transform Utilities ---------------------
29 
30 namespace Laxkit {
31 
32 class Affine
33 {
34  protected:
35  double _m[6];
36 
37  public:
38  Affine();
39  Affine(const double *m);
40  Affine(const Affine &m);
41  Affine(double xx,double xy,double yx,double yy,double tx,double ty);
42  Affine &operator=(Affine const &m);
43  Affine &operator*=(Affine const &m);
44  Affine operator*(Affine const m);
45  virtual ~Affine();
46  virtual void set(Affine a);
47  virtual void setIdentity();
48  virtual bool isIdentity();
49  virtual void setRotation(double angle);
50  virtual void setScale(double sx,double sy);
51  virtual void setBasis(flatpoint o, flatpoint x,flatpoint y);
52  virtual void setBasics(double x,double y,double sx,double sy,double angle,double shear);
53  virtual void getBasics(double *x,double *y,double *sx,double *sy,double *angle,double *shear);
54 
55  virtual void Translate(flatvector d);
56  virtual void Rotate(double angle);
57  virtual void Rotate(double angle, flatpoint around_point);
58  virtual void RotatePointed(flatpoint anchor1, flatpoint anchor2, flatpoint newanchor2);
59  virtual void RotateScale(flatpoint anchor1, flatpoint anchor2, flatpoint newanchor2);
60  virtual void Stretch(flatpoint anchor1, flatpoint anchor2, flatpoint newanchor2);
61  virtual void AnchorShear(flatpoint anchor1, flatpoint anchor2, flatpoint anchor3, flatpoint newanchor3);
62  virtual void Scale(double s);
63  virtual void Scale(flatpoint o, double s);
64  virtual void Scale(flatpoint o, double sx,double sy);
65  virtual void Scale(flatpoint anchor1, flatpoint anchor2, flatpoint newanchor2);
66  virtual void FlipH();
67  virtual void FlipV();
68  virtual void Flip(flatpoint f1,flatpoint f2);
69  virtual void Multiply(Affine &m);
70  virtual void PreMultiply(Affine &m);
71 
72  virtual Affine Inversion();
73  virtual void Invert();
74  virtual flatpoint transformPoint(flatpoint p);
75  virtual flatpoint transformPointInverse(flatpoint p);
77 
78  virtual const double *m() const { return _m; }
79  virtual void m(const double *mm);
80  virtual void m(double xx,double xy,double yx,double yy,double tx,double ty);
81  virtual double m(int c) { return _m[c]; }
82  virtual void m(int c,double v) { _m[c]=v; }
83  virtual void Unshear(int preserve_x, int normalize);
84  virtual void Normalize();
85 
86  virtual flatpoint origin() { return flatpoint(_m[4],_m[5]); }
87  virtual void origin(flatpoint o) { _m[4]=o.x; _m[5]=o.y; }
88  virtual flatpoint xaxis() { return flatpoint(_m[0],_m[1]); }
89  virtual void xaxis(flatpoint x) { _m[0]=x.x; _m[1]=x.y; }
90  virtual flatpoint yaxis() { return flatpoint(_m[2],_m[3]); }
91  virtual void yaxis(flatpoint y) { _m[2]=y.x; _m[3]=y.y; }
92 };
93 
94 void dumpctm(const double *d);
95 int is_degenerate_transform(double *m);
96 double *transform_invert(double *result,const double *m);
97 double *transform_mult(double *result,const double *a,const double *b);
98 double *transform_identity(double *result);
99 double *transform_rotate(double *m, double angle);
100 double *transform_from_basis(double *result,flatpoint o,flatpoint x,flatpoint y);
101 void transform_to_basis(double *m,flatpoint *o,flatpoint *x,flatpoint *y);
102 double *transform_from_basics(double *result,double x,double y,double sx,double sy,double angle,double shear);
103 void transform_to_basics(double *m,double *x,double *y,double *sx,double *sy,double *angle,double *shear);
104 double *transform_set(double *m,double a,double b,double c,double d,double x0,double y0);
105 void transform_copy(double *dest,const double *src);
106 flatpoint transform_point_inverse(const double *m,flatpoint p);
107 flatpoint transform_point(const double *m,flatpoint p);
108 flatpoint transform_point(const double *m,double x,double y);
109 flatpoint transform_vector(const double *m,flatpoint p);
110 
111 double *transform_from_3x3_fixed(double *result,int M[3][3]);
112 void transform_to_3x3_fixed(int M[3][3],double *m);
113 
114 double *svgtransform(const char *v, double *m);
115 
116 } // namespace Laxkit
117 
118 #endif
119 

Mon Feb 17 2014 11:52:57, Laxkit