Do not expect exact load timing. Hopefull makes buildbot results more stable (see...
[gnash.git] / libcore / SWFRect.cpp
blob1ff35a745d816f0730920ed18a93a1407a79f359
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "SWFRect.h"
21 #include <sstream>
23 #include "SWFMatrix.h"
24 #include "Point2d.h"
25 #include "GnashNumeric.h" // for flerp, clamp...
28 namespace gnash {
30 const boost::int32_t SWFRect::rectNull;
31 const boost::int32_t SWFRect::rectMax;
34 // Set ourself to bound a rectangle that has been transformed by m.
35 void
36 SWFRect::enclose_transformed_rect(const SWFMatrix& m, const SWFRect& r)
38 boost::int32_t x1 = r.get_x_min();
39 boost::int32_t y1 = r.get_y_min();
40 boost::int32_t x2 = r.get_x_max();
41 boost::int32_t y2 = r.get_y_max();
43 point p0(x1, y1);
44 point p1(x2, y1);
45 point p2(x2, y2);
46 point p3(x1, y2);
48 m.transform(p0);
49 m.transform(p1);
50 m.transform(p2);
51 m.transform(p3);
53 set_to_point(p0.x, p0.y);
54 expand_to(p1.x, p1.y);
55 expand_to(p2.x, p2.y);
56 expand_to(p3.x, p3.y);
59 void
60 SWFRect::expand_to_rect(const SWFRect& r)
61 // Expand ourself to enclose the given SWFRect.
63 if( r.is_null() ) {
64 return;
67 if( is_null() ) {
68 *this = r;
69 }else {
70 _xMin = std::min(_xMin, r.get_x_min());
71 _yMin = std::min(_yMin, r.get_y_min());
72 _xMax = std::max(_xMax, r.get_x_max());
73 _yMax = std::max(_yMax, r.get_y_max());
77 void
78 SWFRect::expand_to_transformed_rect(const SWFMatrix& m, const SWFRect& r)
80 if (r.is_null()) {
81 return;
84 const boost::int32_t x1 = r.get_x_min();
85 const boost::int32_t y1 = r.get_y_min();
86 const boost::int32_t x2 = r.get_x_max();
87 const boost::int32_t y2 = r.get_y_max();
89 point p0(x1, y1);
90 point p1(x2, y1);
91 point p2(x2, y2);
92 point p3(x1, y2);
94 m.transform(p0);
95 m.transform(p1);
96 m.transform(p2);
97 m.transform(p3);
99 if (is_null()) {
100 set_to_point(p0.x, p0.y);
102 else {
103 expand_to(p0.x, p0.y);
105 expand_to(p1.x, p1.y);
106 expand_to(p2.x, p2.y);
107 expand_to(p3.x, p3.y);
110 void
111 SWFRect::set_lerp(const SWFRect& a, const SWFRect& b, float t)
112 // Set this to the lerp of a and b.
114 assert( !a.is_null() );
115 assert( !b.is_null() );
117 _xMin = lerp<float>(a.get_x_min(), b.get_x_min(), t);
118 _yMin = lerp<float>(a.get_y_min(), b.get_y_min(), t);
119 _xMax = lerp<float>(a.get_x_max(), b.get_x_max(), t);
120 _yMax = lerp<float>(a.get_y_max(), b.get_y_max(), t);
123 void
124 SWFRect::clamp(point& p) const
126 assert( !is_null() );
127 p.x = gnash::clamp<boost::int32_t>(p.x, _xMin, _xMax);
128 p.y = gnash::clamp<boost::int32_t>(p.y, _yMin, _yMax);
131 std::string
132 SWFRect::toString() const
134 std::stringstream ss;
135 ss << *this;
136 return ss.str();
139 } // end namespace gnash
142 // Local Variables:
143 // mode: C++
144 // c-basic-offset: 8
145 // tab-width: 8
146 // indent-tabs-mode: t
147 // End: