5 #define _USE_MATH_DEFINES
9 #include "../tools/errorhandler.hpp"
34 , m_rotation(rotation)
38 #ifdef ASSERT_NUMERIC_RANGES
45 : m_center(x_center, y_center)
46 , m_size(x_size, y_size)
47 , m_rotation(rotation)
51 #ifdef ASSERT_NUMERIC_RANGES
66 #ifdef ASSERT_NUMERIC_RANGES
74 #ifdef ASSERT_NUMERIC_RANGES
100 value_type XCos = deltaX * dCos, XSin = deltaX * dSin;
101 value_type YCos = deltaY * dCos, YSin = deltaY * dSin;
127 value_type xmax = deltaX * dCos + deltaY * dSin;
128 value_type ymax = deltaX * dSin + deltaY * dCos;
131 Point2D size(2.0f * xmax, 2.0f * ymax);
137 std::pair<Box2D::value_type, Box2D::value_type>
150 return std::make_pair(-
PI,
PI);
159 for (
unsigned k = 1; k < 4; ++k)
163 if (pointangle < minangle)
164 minangle = pointangle;
166 if (pointangle > maxangle)
167 maxangle = pointangle;
170 return std::make_pair(minangle, maxangle);
183 return (std::abs(pointX) <= 0.5f *
m_size.
getX())
184 && (std::abs(pointY) <= 0.5f *
m_size.
getY());
200 if (std::max(std::abs(deltaX), std::abs(deltaY)) > half_sizeX + half_sizeY)
206 value_type pointX = dCos * deltaX + dSin * deltaY;
207 value_type pointY = -dSin * deltaX + dCos * deltaY;
210 return ((std::abs(pointX) <= half_sizeX)
211 && (std::abs(pointY) <= half_sizeY));
218 template<
typename floatT>
224 floatT pointXAbs = std::abs(pointX);
225 floatT pointYAbs = std::abs(pointY);
228 if (pointXAbs > boxSizeX && pointYAbs > boxSizeY)
231 return hypot(pointXAbs - boxSizeX, pointYAbs - boxSizeY);
234 if (pointXAbs > boxSizeX)
236 return pointXAbs - boxSizeX;
238 if (pointYAbs > boxSizeY)
240 return pointYAbs - boxSizeY;
243 return std::min(boxSizeX - pointXAbs, boxSizeY - pointYAbs);
247 template<
class Po
intT>
274 -dSin * deltaX + dCos * deltaY,
282 template<
class IteratorT>
286 std::vector<Point2D>::size_type numPoints = 0;
288 for (IteratorT iter = begin; iter != end; ++iter)
310 template<
class Po
intT>
311 static inline double rotate_x(
const PointT& p,
double dCos,
double dSin)
313 return dCos * p.getX() + dSin * p.getY();
318 template <
class Po
intT>
319 static inline double rotate_y(
const PointT& p,
double dCos,
double dSin)
321 return -dSin * p.getX() + dCos * p.getY();
328 template<
class IterT>
static Box2D
333 float dCos = cos(orientation);
334 float dSin = sin(orientation);
338 assert(begin != end);
345 float minX =
rotate_x(*begin, dCos, dSin);
347 float minY =
rotate_y(*begin, dCos, dSin);
352 for (IterT iter = begin + 1; iter != end; iter++)
354 float x =
rotate_x(*iter, dCos, dSin);
355 float y =
rotate_y(*iter, dCos, dSin);
356 if (x < minX) minX = x;
357 if (x > maxX) maxX = x;
358 if (y < minY) minY = y;
359 if (y > maxY) maxY = y;
363 float rotated_center_x = 0.5 * (maxX + minX);
364 float rotated_center_y = 0.5 * (maxY + minY);
367 result.
setCenter(dCos * rotated_center_x - dSin * rotated_center_y,
368 dSin * rotated_center_x + dCos * rotated_center_y);
386 const std::vector<Point2D>::const_iterator& begin,
387 const std::vector<Point2D>::const_iterator& end)
394 const std::vector<Point2D>& points)
423 bool __attribute__((unused)) correctRange =
true;
425 bool correctRange =
true;
430 printWarning(
"Size of Box2D was given as negative value (" +
432 ") - silently using the absolute value instead.");
435 correctRange =
false;
443 printWarning(
"Size.getX() of Box2D was given as NaN value - silently using Zero instead.");
444 correctRange =
false;
449 printWarning(
"Size.getY() of Box2D was given as NaN value - silently using Zero instead.");
450 correctRange =
false;
455 printWarning(
"Rotation of Box2D was given as NaN value - silently using Zero instead.");
456 correctRange =
false;
461 printWarning(
"Rotation of Box2D (" + ::
toString(
m_rotation, 2) +
") was outside of its [-pi,pi] definition range - silently normalizing it back into that range (" +
464 correctRange =
false;
466 #ifdef ASSERT_NUMERIC_RANGES
467 assert(correctRange);