Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #ifndef BOX2D_H
00007 #define BOX2D_H
00008
00009 #include "Point2D.hpp"
00010 #include "../BasicDatatypes.hpp"
00011 #include <iosfwd>
00012 #include <vector>
00013
00014 namespace datatypes
00015 {
00016
00017
00018 class Polygon2D;
00019
00021
00034 class Box2D : public BasicData
00035 {
00036 public:
00038 typedef Point2D::value_type value_type;
00039 private:
00040 Point2D m_center;
00041 Point2D m_size;
00042 value_type m_rotation;
00043 public:
00045 Box2D();
00046
00048
00059 Box2D(const Point2D& center, const Point2D& size, value_type rotation = 0.0);
00060
00062
00082 Box2D(value_type x_center, value_type y_center, value_type x_size, value_type y_size, value_type rotation = 0.0);
00083
00084
00085 virtual const UINT32 getUsedMemory() const { return sizeof(*this); };
00086
00087
00089
00090
00092 const Point2D& getCenter() const { return m_center; }
00093
00095
00101 const Point2D& getSize() const { return m_size; }
00102
00108 value_type getRotation() const { return m_rotation; }
00109
00111
00115 Polygon2D toPolygon() const;
00116
00118
00124 Box2D toBoundingBox() const;
00125
00136 std::pair<value_type, value_type> getBoundingAngles() const;
00137
00140 Box2D movedBy(const Point2D& centerMovement) const;
00141
00142
00143
00145
00146
00148 void setCenter(const Point2D& p) { m_center = p; }
00149
00151 void setCenter(value_type x, value_type y) { m_center.setXY(x, y); }
00152
00154 void setSize(const Point2D& p);
00155
00157 void setSize(value_type x_length, value_type y_width);
00158
00166 void setRotation(value_type r);
00167
00169 void moveBy(const Point2D& centerMovement);
00170
00171
00173
00174
00176
00181 bool containsPoint(const Point2D& point) const;
00182
00184
00194 Point2D::value_type distanceFromOutline(const Point2D& point) const;
00195
00197
00207 Point2D::value_type distanceFromOutline(const std::vector<Point2D>& points) const;
00208
00210
00220 Point2D::value_type distanceFromOutline(const std::vector<Point2D>::const_iterator& begin,
00221 const std::vector<Point2D>::const_iterator& end) const;
00222
00223
00225
00230 static Box2D orientatedBox(value_type orientation_rad, const Polygon2D& poly);
00231
00233
00241 static Box2D orientatedBox(value_type orientation_rad, const std::vector<Point2D>& points);
00242
00244
00252 static Box2D orientatedBox(value_type orientation_rad,
00253 const std::vector<Point2D>::const_iterator& begin,
00254 const std::vector<Point2D>::const_iterator& end);
00255
00256
00257 std::string toString() const;
00258
00259
00260 friend inline bool operator==(const Box2D &, const Box2D &);
00261 friend inline bool operator!=(const Box2D &, const Box2D &);
00262
00263 private:
00264 void verifyNumericRanges();
00265
00266 };
00267
00268
00269 inline bool operator==(const Box2D &b1, const Box2D &b2)
00270 {
00271 return (b1.m_center == b2.m_center)
00272 && (b1.m_size == b2.m_size)
00273 && (fuzzyCompare(b1.m_rotation, b2.m_rotation)
00274 || (isNaN(b1.m_rotation) && isNaN(b2.m_rotation)));
00275 }
00276
00277 inline bool operator!=(const Box2D &b1, const Box2D &b2)
00278 {
00279 return ! operator==(b1, b2);
00280 }
00281
00282
00283 }
00284
00285 #endif // BOX2D_H