Make automated FSCommand invocation tests show player-side output.
[gnash.git] / libcore / SWFRect.cpp
blobdbe34dc716cbfa1f436d3792ba45514e3d585cf3
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software 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 // Set ourself to bound a rectangle that has been transformed by m.
31 void
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();
39 point p0(x1, y1);
40 point p1(x2, y1);
41 point p2(x2, y2);
42 point p3(x1, y2);
44 m.transform(p0);
45 m.transform(p1);
46 m.transform(p2);
47 m.transform(p3);
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);
55 void
56 SWFRect::expand_to_rect(const SWFRect& r)
57 // Expand ourself to enclose the given SWFRect.
59 if( r.is_null() ) {
60 return;
63 if( is_null() ) {
64 *this = r;
65 }else {
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());
73 void
74 SWFRect::expand_to_transformed_rect(const SWFMatrix& m, const SWFRect& r)
76 if (r.is_null()) {
77 return;
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();
85 point p0(x1, y1);
86 point p1(x2, y1);
87 point p2(x2, y2);
88 point p3(x1, y2);
90 m.transform(p0);
91 m.transform(p1);
92 m.transform(p2);
93 m.transform(p3);
95 if (is_null()) {
96 set_to_point(p0.x, p0.y);
98 else {
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);
106 void
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);
119 void
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);
127 std::string
128 SWFRect::toString() const
130 std::stringstream ss;
131 ss << *this;
132 return ss.str();
135 } // end namespace gnash
138 // Local Variables:
139 // mode: C++
140 // c-basic-offset: 8
141 // tab-width: 8
142 // indent-tabs-mode: t
143 // End: