1 /*
2  * affine.h -- ePiX::affine class (affine screen maps)
3  *
4  * This file is part of ePiX, a C++ library for creating high-quality
5  * figures in LaTeX
6  *
7  * Version 1.1.21
8  * Last Change: September 23, 2007
9  *
10  *
11  * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
12  * Andrew D. Hwang <rot 13 nujnat at zngupf dot ubylpebff dot rqh>
13  * Department of Mathematics and Computer Science
14  * College of the Holy Cross
15  * Worcester, MA, 01610-2395, USA
16  *
17  *
18  * ePiX is free software; you can redistribute it and/or modify it
19  * under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * (at your option) any later version.
22  *
23  * ePiX is distributed in the hope that it will be useful, but WITHOUT
24  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
26  * License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with ePiX; if not, write to the Free Software Foundation, Inc.,
30  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31  */
32 
33 /*
34  * An affine map is constructed from the images of the "standard
35  * triple" (0,0), (1,0), and (0,1).
36  *
37  * An affine map may be (post)-composed with translation, rotation,
38  * reflection, scaling along either or both coordinate axes, shearing,
39  * and may be inverted. An optional pair argument, defaulting to
40  * (0,0), gives the center of the operation (if appropriate).
41  *
42  * An affine map may be post-composed via member function, and
43  * pre-composed with operator syntax. The evaluation operator
44  * returns the image of the argument.
45  */
46 
47 #ifndef EPIX_AFFINE
48 #define EPIX_AFFINE
49 
50 #include "pairs.h"
51 #include "triples.h"
52 
53 namespace ePiX {
54 
55   class affine {
56   public:
57     // the identity map
58     affine();
59 
60     // images of (1,0), (0,1), (0,0)
61     affine(const pair&, const pair&, const pair& loc=pair(0,0));
62     affine(const P&, const P&, const P& loc=P(0,0));
63 
64     // post-operations
65     // translate by arg
66     affine&   shift(const pair& arg);
67     affine&   shift(const P& arg);
68 
69     // rotate by theta about ctr
70     affine&  rotate(double theta, const pair& ctr = pair(0,0));
71     affine&  rotate(double theta, const P& ctr);
72 
73     // reflect in angle-theta line through ctr
74     affine& reflect(double theta, const pair& ctr = pair(0,0));
75     affine& reflect(double theta, const P& ctr);
76 
77     // scale coord direction(s) fixing ctr
78     affine& h_scale(double, const pair& ctr=pair(0,0));
79     affine& v_scale(double, const pair& ctr=pair(0,0));
80     affine&   scale(double, const pair& ctr=pair(0,0));
81 
82     affine& h_scale(double, const P& ctr);
83     affine& v_scale(double, const P& ctr);
84     affine&   scale(double, const P& ctr);
85 
86     // shear, fixing ctr
87     affine& h_shear(double, const pair& ctr=pair(0,0));
88     affine& v_shear(double, const pair& ctr=pair(0,0));
89 
90     affine& h_shear(double, const P& ctr);
91     affine& v_shear(double, const P& ctr);
92 
93     // post-compose
94     affine& postcomp(const affine&);
95 
96     affine& invert();
97 
98     // evaluation
99     pair operator() (const pair&) const;
100     pair operator() (const P&) const;
101 
102     // pre-compose
103     affine operator() (const affine&) const;
104 
105     bool reverses_orientation() const;
106 
107   private:
108     pair m_00;
109     pair m_10;
110     pair m_01;
111   };
112 } // end of ePiX namespace
113 
114 #endif /* EPIX_AFFINE */
115