2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
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 // Set ourself to bound a rectangle that has been transformed by m.
32 SWFRect::enclose_transformed_rect(const SWFMatrix
& m
, const SWFRect
& r
)
34 std::int32_t x1
= r
.get_x_min();
35 std::int32_t y1
= r
.get_y_min();
36 std::int32_t x2
= r
.get_x_max();
37 std::int32_t y2
= r
.get_y_max();
49 set_to_point(p0
.x
, p0
.y
);
50 expand_to(p1
.x
, p1
.y
);
51 expand_to(p2
.x
, p2
.y
);
52 expand_to(p3
.x
, p3
.y
);
56 SWFRect::expand_to_rect(const SWFRect
& r
)
57 // Expand ourself to enclose the given SWFRect.
66 _xMin
= std::min(_xMin
, r
.get_x_min());
67 _yMin
= std::min(_yMin
, r
.get_y_min());
68 _xMax
= std::max(_xMax
, r
.get_x_max());
69 _yMax
= std::max(_yMax
, r
.get_y_max());
74 SWFRect::expand_to_transformed_rect(const SWFMatrix
& m
, const SWFRect
& r
)
80 const std::int32_t x1
= r
.get_x_min();
81 const std::int32_t y1
= r
.get_y_min();
82 const std::int32_t x2
= r
.get_x_max();
83 const std::int32_t y2
= r
.get_y_max();
96 set_to_point(p0
.x
, p0
.y
);
99 expand_to(p0
.x
, p0
.y
);
101 expand_to(p1
.x
, p1
.y
);
102 expand_to(p2
.x
, p2
.y
);
103 expand_to(p3
.x
, p3
.y
);
107 SWFRect::set_lerp(const SWFRect
& a
, const SWFRect
& b
, float t
)
108 // Set this to the lerp of a and b.
110 assert( !a
.is_null() );
111 assert( !b
.is_null() );
113 _xMin
= lerp
<float>(a
.get_x_min(), b
.get_x_min(), t
);
114 _yMin
= lerp
<float>(a
.get_y_min(), b
.get_y_min(), t
);
115 _xMax
= lerp
<float>(a
.get_x_max(), b
.get_x_max(), t
);
116 _yMax
= lerp
<float>(a
.get_y_max(), b
.get_y_max(), t
);
120 SWFRect::clamp(point
& p
) const
122 assert( !is_null() );
123 p
.x
= gnash::clamp
<std::int32_t>(p
.x
, _xMin
, _xMax
);
124 p
.y
= gnash::clamp
<std::int32_t>(p
.y
, _yMin
, _yMax
);
128 SWFRect::toString() const
130 std::stringstream ss
;
135 } // end namespace gnash
142 // indent-tabs-mode: t