more updates
[synfig.git] / synfig-core / trunk / src / synfig / transform.cpp
1 /* === S I N F G =========================================================== */
2 /*!     \file template.cpp
3 **      \brief Template File
4 **
5 **      $Id: transform.cpp,v 1.2 2005/01/24 05:00:18 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "transform.h"
32 #include <algorithm>
33
34 #endif
35
36 /* === U S I N G =========================================================== */
37
38 using namespace std;
39 using namespace etl;
40 using namespace sinfg;
41
42 /* === M A C R O S ========================================================= */
43
44 /* === G L O B A L S ======================================================= */
45
46 /* === P R O C E D U R E S ================================================= */
47
48 /* === M E T H O D S ======================================================= */
49
50 sinfg::GUID
51 TransformStack::get_guid()const
52 {
53         GUID ret(0);
54         
55         for(const_iterator iter(begin());iter!=end();++iter)
56                 ret%=(*iter)->get_guid();
57         return ret;
58 }
59
60 sinfg::Vector
61 TransformStack::perform(const sinfg::Vector& x)const
62 {
63         sinfg::Vector ret(x);
64         
65         for(const_reverse_iterator iter(rbegin());iter!=rend();++iter)
66                 ret=(*iter)->perform(ret);
67         
68         return ret;
69 }
70
71 sinfg::Vector
72 TransformStack::unperform(const sinfg::Vector& x)const
73 {
74         sinfg::Vector ret(x);
75         
76         for(const_iterator iter(begin());iter!=end();++iter)
77                 ret=(*iter)->unperform(ret);
78         
79         return ret;
80 }
81
82 sinfg::Rect
83 TransformStack::perform(const sinfg::Rect& x)const
84 {
85         Point min(x.get_min());
86         Point max(x.get_max());
87         Rect ret(perform(min),perform(max));
88
89         std::swap(min[1],max[1]);
90         ret
91                 .expand(perform(min))
92                 .expand(perform(max))
93         ;
94         return ret;
95 }
96
97 sinfg::Rect
98 TransformStack::unperform(const sinfg::Rect& x)const
99 {
100         Point min(x.get_min());
101         Point max(x.get_max());
102         Rect ret(unperform(min),unperform(max));
103
104         std::swap(min[1],max[1]);
105         ret
106                 .expand(unperform(min))
107                 .expand(unperform(max))
108         ;
109         return ret;
110 }
111
112 sinfg::Rect
113 Transform::perform(const sinfg::Rect& x)const
114 {
115         if(x.area()>1000000000000.0)
116                 return Rect::full_plane();
117
118         Point min(x.get_min());
119         Point max(x.get_max());
120
121         Rect ret(perform(min),perform(max));
122
123         std::swap(min[1],max[1]);
124         ret
125                 .expand(perform(min))
126                 .expand(perform(max))
127         ;
128         return ret;
129 }
130
131 sinfg::Rect
132 Transform::unperform(const sinfg::Rect& x)const
133 {
134         if(x.area()>1000000000000.0)
135                 return Rect::full_plane();
136
137         Point min(x.get_min());
138         Point max(x.get_max());
139                 
140         Rect ret(unperform(min),unperform(max));
141
142         std::swap(min[1],max[1]);
143         ret
144                 .expand(unperform(min))
145                 .expand(unperform(max))
146         ;
147         return ret;
148 }