|
|
@@ -8,6 +8,7 @@
|
|
|
#include "game/math/common.hpp"
|
|
|
|
|
|
#include "game/math/angle.hpp"
|
|
|
+#include "game/math/compare.hpp"
|
|
|
#include "game/math/shape.hpp"
|
|
|
|
|
|
namespace math {
|
|
|
@@ -29,4 +30,27 @@ namespace math {
|
|
|
rotate(c, q.ul, r)
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+ bool contains(dim2::circle const & shape, dim2::point const & pt) {
|
|
|
+ vec2 const delta = pt - shape.center;
|
|
|
+ return delta.dot(delta) <= std::pow(shape.radius, 2);
|
|
|
+ }
|
|
|
+ bool contains(dim2::quad const & shape, dim2::point const & pt);
|
|
|
+ bool intersects(dim2::line const & lhs, dim2::line const & rhs) {
|
|
|
+ dim2::point const inter = lines::intersection(lhs, rhs);
|
|
|
+ return approx_equal((rhs.first[0] - inter[0]) * rhs.slope() + inter[1],
|
|
|
+ rhs.first[1], static_cast<float>(1E-6));
|
|
|
+ }
|
|
|
+ bool intersects(dim2::line const & lhs, dim2::circle const & rhs) {
|
|
|
+ dim2::line const orth = lines::orthogonal(lhs, rhs.center);
|
|
|
+ vec2 const delta = orth.second - orth.first;
|
|
|
+ return delta.dot(delta) <= std::pow(rhs.radius, 2);
|
|
|
+ }
|
|
|
+ bool intersects(dim2::line const & lhs, dim2::quad const & rhs);
|
|
|
+ bool intersects(dim2::quad const & lhs, dim2::circle const & rhs);
|
|
|
+ bool intersects(dim2::quad const & lhs, dim2::quad const & rhs);
|
|
|
+ bool intersects(dim2::circle const & lhs, dim2::circle const & rhs) {
|
|
|
+ vec2 const delta = rhs.center - lhs.center;
|
|
|
+ return delta.dot(delta) <= std::pow(lhs.radius + rhs.radius, 2);
|
|
|
+ }
|
|
|
}
|