1 #ifndef RECTANGLE_WARPER_CLASS
2 #define RECTANGLE_WARPER_CLASS
34 template <
class numeric_type>
127 template <
class numeric_type>
132 : _system_1(system_1), _system_2(system_2), _vert_1(v1), _vert_2(v2)
135 template <
class numeric_type>
138 template <
class numeric_type>
141 { _system_1 = to_set; _vert_1 = v; }
143 template <
class numeric_type>
146 { _system_2 = to_set; _vert_2 = v; }
148 template <
class numeric_type>
151 {
return scale_point(_system_2, _system_1, _vert_2, _vert_1, in_system_2); }
153 template <
class numeric_type>
156 {
return scale_point(_system_1, _system_2, _vert_1, _vert_2, in_system_1); }
158 template <
class numeric_type>
162 return scale_rectangle(_system_2, _system_1, _vert_2, _vert_1,
166 template <
class numeric_type>
170 return scale_rectangle(_system_1, _system_2, _vert_1, _vert_2,
174 template <
class numeric_type>
178 if ( (v == BOTTOM_LEFT) || (v == BOTTOM_RIGHT) ) to_set = RW_BOTTOM;
182 template <
class numeric_type>
186 if ( (v == BOTTOM_LEFT) || (v == TOP_LEFT) ) to_set = RW_LEFT;
190 template <
class numeric_type>
193 origin_vertex targo)
const
196 if (flipo == targo)
return to_flip;
197 numeric_type x1(to_flip.
vertex_1().x());
198 numeric_type y1(to_flip.
vertex_1().y());
199 numeric_type x2(to_flip.
vertex_2().x());
200 numeric_type y2(to_flip.
vertex_2().y());
201 horizontal_component horiz1;
202 separate_horizontal(flipo, horiz1);
203 horizontal_component horiz2;
204 separate_horizontal(targo, horiz2);
205 bool flip_x = bool(horiz1 != horiz2);
206 vertical_component vert1;
207 separate_vertical(flipo, vert1);
208 vertical_component vert2;
209 separate_vertical(targo, vert2);
210 bool flip_y = bool(vert1 != vert2);
217 template <
class numeric_type>
218 rectangle<numeric_type> rectangle_warper<numeric_type>::scale_rectangle
219 (
const rectangle<numeric_type> &source,
220 const rectangle<numeric_type> &target, origin_vertex source_origin,
221 origin_vertex target_origin,
const rectangle<numeric_type> &old)
const
223 rectangle<numeric_type> s = rectangle<numeric_type>
224 (flip_accordingly(source, source_origin, BOTTOM_LEFT));
225 numeric_type width_source = s.vertex_2().x() - s.vertex_1().x();
226 numeric_type height_source = s.vertex_2().y() - s.vertex_1().y();
227 if ( !width_source || !height_source ) {
232 rectangle<numeric_type> t(flip_accordingly(target, target_origin, BOTTOM_LEFT));
233 numeric_type width_target = t.vertex_2().x() - t.vertex_1().x();
234 numeric_type height_target = t.vertex_2().y() - t.vertex_1().y();
235 numeric_type x_scale = width_target / width_source;
236 numeric_type y_scale = height_target / height_source;
240 rectangle<numeric_type> o(flip_accordingly(old, source_origin, BOTTOM_LEFT));
242 rectangle<numeric_type> to_return = flip_accordingly(rectangle<numeric_type>
243 ((o.vertex_1().x() - s.vertex_1().x()) * x_scale + t.vertex_1().x(),
244 (o.vertex_1().y() - s.vertex_1().y()) * y_scale + t.vertex_1().y(),
245 (o.vertex_2().x() - s.vertex_1().x()) * x_scale + t.vertex_1().x(),
246 (o.vertex_2().y() - s.vertex_1().y()) * y_scale + t.vertex_1().y()),
247 BOTTOM_LEFT, target_origin);
254 template <
class numeric_type>
255 point<numeric_type> rectangle_warper<numeric_type>::scale_point
256 (
const rectangle<numeric_type> &source,
const rectangle<numeric_type> &target,
257 origin_vertex source_origin, origin_vertex target_origin,
258 const point<numeric_type> &old)
const
261 return scale_rectangle(source, target, source_origin, target_origin,
262 rectangle<numeric_type>(old, old)).vertex_1();
265 template <
class numeric_type>
270 case BOTTOM_LEFT: name =
"bottom-left";
break;
271 case BOTTOM_RIGHT: name =
"bottom-right";
break;
272 case TOP_LEFT: name =
"top-left";
break;
273 case TOP_RIGHT: name =
"top-right";
break;
278 template <
class numeric_type>
Provides a dynamically resizable ASCII character string.
virtual void text_form(base_string &state_fill) const
Provides a text view of all the important info owned by this object.
Represents a geometric point.
basis::astring vertex_name(origin_vertex v) const
Prints out the name of the vertex location.
rectangle_warper(const rectangle< numeric_type > &system_1, const rectangle< numeric_type > &system_2, origin_vertex system_1_origin=BOTTOM_LEFT, origin_vertex system_2_origin=BOTTOM_LEFT)
constructs a warper given the two reference systems.
origin_vertex origin_1() const
rectangle< numeric_type > system_1() const
origin_vertex origin_2() const
void separate_horizontal(origin_vertex v, horizontal_component &to_set) const
separates out a component of the placement of the vertex.
point< numeric_type > to_system_1(const point< numeric_type > &in_system_2) const
Converts from the second system into the first.
rectangle< numeric_type > system_2() const
basis::astring text_form() const
Prints out the two systems held in the rectangle_warper.
origin_vertex
describes where a rectangle's origin is located on the rectangle.
void separate_vertical(origin_vertex v, vertical_component &to_set) const
point< numeric_type > to_system_2(const point< numeric_type > &in_system_1) const
Converts from the first system into the second.
Represents a geometric rectangle.
point< numeric_type > vertex_1() const
point< numeric_type > vertex_2() const
void swap_values(type &a, type &b)
Exchanges the values held by "a" & "b".
Contains all of our objects for geometry and avoids name clashes.