2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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.
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.
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
23 #include "SWFMatrix.h"
25 #include "GnashNumeric.h" // for flerp, clamp...
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.
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();
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
);
60 SWFRect::expand_to_rect(const SWFRect
& r
)
61 // Expand ourself to enclose the given SWFRect.
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());
78 SWFRect::expand_to_transformed_rect(const SWFMatrix
& m
, const SWFRect
& r
)
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();
100 set_to_point(p0
.x
, p0
.y
);
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
);
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
);
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
);
132 SWFRect::toString() const
134 std::stringstream ss
;
139 } // end namespace gnash
146 // indent-tabs-mode: t