A rotated 2-dimensional box in the plane. More...
#include <Box2D.hpp>
Public Types | |
typedef Point2D::value_type | value_type |
The type of the stored x, y coordinates, and the rotation. | |
Public Member Functions | |
Box2D () | |
Constructor for an all-zero Box2D. | |
Box2D (const Point2D ¢er, const Point2D &size, value_type rotation=0.0) | |
Constructor with specified center point, size, and rotation. | |
Box2D (value_type x_center, value_type y_center, value_type x_size, value_type y_size, value_type rotation=0.0) | |
Constructor with all values given. | |
virtual const UINT32 | getUsedMemory () const |
Accessor methods for information about this box | |
const Point2D & | getCenter () const |
Returns the center point of this Box. | |
const Point2D & | getSize () const |
Returns the size of this Box. | |
value_type | getRotation () const |
Polygon2D | toPolygon () const |
Converts this Box2D to a closed polygon. | |
Box2D | toBoundingBox () const |
Returns a Box in parallel to the coordinate system that bounds this box. | |
std::pair< value_type, value_type > | getBoundingAngles () const |
Returns boundary angles for this box. | |
Box2D | movedBy (const Point2D ¢erMovement) const |
Returns a Box that is copied from this one but with its center point moved. | |
Setter methods for changing this box | |
void | setCenter (const Point2D &p) |
Sets the center point of this Box2D. | |
void | setCenter (value_type x, value_type y) |
Sets the center point of this Box2D. | |
void | setSize (const Point2D &p) |
Sets the size of this Box. Must be non-negative. | |
void | setSize (value_type x_length, value_type y_width) |
Sets the size of this Box2D. Must be non-negative. | |
void | setRotation (value_type r) |
Sets the rotation angle of this Box in [radians], counter clock wise. | |
void | moveBy (const Point2D ¢erMovement) |
Move the center point of this box by the given point values. | |
Private Attributes | |
Point2D | m_center |
value_type | m_rotation |
Point2D | m_size |
Geometrical relations to other objects | |
bool | containsPoint (const Point2D &point) const |
Returns true if the given Point2D is inside this box or on its outline. | |
Point2D::value_type | distanceFromOutline (const Point2D &point) const |
Returns the distance from the outline of this Box2D to the given point. | |
Point2D::value_type | distanceFromOutline (const std::vector< Point2D > &points) const |
Returns the mean distance from the outline of this Box2D to all points of the point vector. | |
Point2D::value_type | distanceFromOutline (const std::vector< Point2D >::const_iterator &begin, const std::vector< Point2D >::const_iterator &end) const |
Returns the mean distance from the outline of this Box2D to all points of the given point iterator range. | |
std::string | toString () const |
static Box2D | orientatedBox (value_type orientation_rad, const Polygon2D &poly) |
Returns an orientated bounding box for the given list of points. | |
static Box2D | orientatedBox (value_type orientation_rad, const std::vector< Point2D > &points) |
Returns an orientated bounding box for the given list of points. | |
static Box2D | orientatedBox (value_type orientation_rad, const std::vector< Point2D >::const_iterator &begin, const std::vector< Point2D >::const_iterator &end) |
Returns an orientated bounding box for the given list of points. | |
bool | operator== (const Box2D &, const Box2D &) |
bool | operator!= (const Box2D &, const Box2D &) |
void | verifyNumericRanges () |
A rotated 2-dimensional box in the plane.
This box (rectangle) is defined by its center point, its size in x- and y-direction, and its rotation.
The rotation denotes the rotation of this box' x-axis compared to the original x-axis. The size denotes the total length and width of this box in the box' coordinate system, i.e. the distance from the center point to each outline is half that size.
The size argument must be non-negative. The rotation argument must be in the range [-pi,pi], which can be obtained by using normalizeRadians().
datatypes::Box2D::Box2D | ( | const Point2D & | center, |
const Point2D & | size, | ||
value_type | rotation = 0.0 |
||
) |
Constructor with specified center point, size, and rotation.
center | The center point |
size | The size of the box in the box' coordinate system. Must be non-negative. |
rotation | The rotation of the box' coordinate system around its center point in [radians]. Must be in the interval [-pi,pi], which can be obtained by using normalizeRadians(). |
datatypes::Box2D::Box2D | ( | value_type | x_center, |
value_type | y_center, | ||
value_type | x_size, | ||
value_type | y_size, | ||
value_type | rotation = 0.0 |
||
) |
Constructor with all values given.
Constructor with all values given: x/y of center point, x/y of size (where the x coordinate of the size is in the same direction as the x axis of the coordinate system, rotated by the rotation argument; the y coordinate accordingly), and rotation.
x_center | X-coordinate of center point |
y_center | Y-coordinate of center point |
x_size | The size of the box in X-direction in the box' coordinate system. Must be non-negative. |
y_size | The size of the box in Y-direction in the box' coordinate system. Must be non-negative. |
rotation | The rotation of the box' coordinate system around its center point in [radians]. Must be in the interval [-pi,pi], which can be obtained by using normalizeRadians(). |
bool datatypes::Box2D::containsPoint | ( | const Point2D & | point | ) | const |
Point2D::value_type datatypes::Box2D::distanceFromOutline | ( | const Point2D & | point | ) | const |
Returns the distance from the outline of this Box2D to the given point.
This function calculates the minimum distance over the distances from the given point to each of the four outside lines of this Box2D.
Internally, this might be implemented using Polygon2D::distanceToPoint and Line2D::distanceFromLineSegment(), but maybe the implementation will be optimized to work in some other way.
Point2D::value_type datatypes::Box2D::distanceFromOutline | ( | const std::vector< Point2D > & | points | ) | const |
Returns the mean distance from the outline of this Box2D to all points of the point vector.
For each given point, this function calculates the minimum distance over the distances from the given point to each of the four outside lines of this Box2D and returns that minimum distance. The returned value is the mean value of all distances.
This is an overloaded version of distanceFromOutline(const Point2D&) for your convenience.
Point2D::value_type datatypes::Box2D::distanceFromOutline | ( | const std::vector< Point2D >::const_iterator & | begin, |
const std::vector< Point2D >::const_iterator & | end | ||
) | const |
Returns the mean distance from the outline of this Box2D to all points of the given point iterator range.
For each given point, this function calculates the minimum distance over the distances from the given point to each of the four outside lines of this Box2D and returns that minimum distance. The returned value is the mean value of all distances.
This is an overloaded version of distanceFromOutline(const Point2D&) for your convenience.
std::pair< Box2D::value_type, Box2D::value_type > datatypes::Box2D::getBoundingAngles | ( | ) | const |
Returns boundary angles for this box.
This function calculates a low and a high boundary angle for all edges of the given (rotated) Box2D. The returned FloatPair has the component "first" for the lower bounding angle, and "second" for the upper bounding angle.
(Note: This ordering is swapped compared to the scan point ordering!)
const Point2D& datatypes::Box2D::getCenter | ( | ) | const [inline] |
value_type datatypes::Box2D::getRotation | ( | ) | const [inline] |
const Point2D& datatypes::Box2D::getSize | ( | ) | const [inline] |
Returns the size of this Box.
The returned size denotes the size of the box in x-direction Point2D::getX() and y-direction Point2D::getY(), where the x-direction is rotated against the original x-axis by getRotation().
virtual const UINT32 datatypes::Box2D::getUsedMemory | ( | ) | const [inline, virtual] |
Implements datatypes::BasicData.
void datatypes::Box2D::moveBy | ( | const Point2D & | centerMovement | ) |
Box2D datatypes::Box2D::movedBy | ( | const Point2D & | centerMovement | ) | const |
Box2D datatypes::Box2D::orientatedBox | ( | value_type | orientation_rad, |
const Polygon2D & | poly | ||
) | [static] |
Box2D datatypes::Box2D::orientatedBox | ( | value_type | orientation_rad, |
const std::vector< Point2D > & | points | ||
) | [static] |
Returns an orientated bounding box for the given list of points.
Given a list of points and a fixed orientation, this function will calculate a bounding box for the points that has the given orientation.
This is an overloaded version of orientatedBox(const Polygon2D&) for your convenience.
Box2D datatypes::Box2D::orientatedBox | ( | value_type | orientation_rad, |
const std::vector< Point2D >::const_iterator & | begin, | ||
const std::vector< Point2D >::const_iterator & | end | ||
) | [static] |
Returns an orientated bounding box for the given list of points.
Given a list of points and a fixed orientation, this function will calculate a bounding box for the points that has the given orientation.
This is an overloaded version of orientatedBox(const Polygon2D&) for your convenience.
void datatypes::Box2D::setCenter | ( | const Point2D & | p | ) | [inline] |
void datatypes::Box2D::setCenter | ( | value_type | x, |
value_type | y | ||
) | [inline] |
void datatypes::Box2D::setRotation | ( | value_type | r | ) |
Sets the rotation angle of this Box in [radians], counter clock wise.
The rotation of the box' coordinate system around its center point. Must be in the interval [-pi,pi], which can be obtained by using normalizeRadians().
void datatypes::Box2D::setSize | ( | const Point2D & | p | ) |
void datatypes::Box2D::setSize | ( | value_type | x_length, |
value_type | y_width | ||
) |
Box2D datatypes::Box2D::toBoundingBox | ( | ) | const |
Returns a Box in parallel to the coordinate system that bounds this box.
This function calculates a bounding box to the given box, because the given one might be rotated into some other direction. In contrast to this, the returned box will have zero rotation and will be in parallel to the coordinate system.
Polygon2D datatypes::Box2D::toPolygon | ( | ) | const |
std::string datatypes::Box2D::toString | ( | ) | const |
void datatypes::Box2D::verifyNumericRanges | ( | ) | [private] |
Point2D datatypes::Box2D::m_center [private] |
value_type datatypes::Box2D::m_rotation [private] |
Point2D datatypes::Box2D::m_size [private] |