|
|
@@ -60,11 +60,7 @@ namespace math {
|
|
|
}
|
|
|
|
|
|
bool contains(dim2::quad const & shape, dim2::point const & pt) {
|
|
|
- std::vector<dim2::line> segments{
|
|
|
- {shape.ll, shape.lr}, {shape.lr, shape.ur},
|
|
|
- {shape.ur, shape.ul}, {shape.ul, shape.ll}
|
|
|
- };
|
|
|
- return contains(segments, pt);
|
|
|
+ return contains(shapes::segments(shape), pt);
|
|
|
}
|
|
|
|
|
|
bool intersects(dim2::line const & lhs, dim2::line const & rhs) {
|
|
|
@@ -79,10 +75,7 @@ namespace math {
|
|
|
}
|
|
|
|
|
|
bool intersects(dim2::line const & lhs, dim2::quad const & rhs) {
|
|
|
- std::vector<dim2::line> segments{
|
|
|
- {rhs.ll, rhs.lr}, {rhs.lr, rhs.ur},
|
|
|
- {rhs.ur, rhs.ul}, {rhs.ul, rhs.ll}
|
|
|
- };
|
|
|
+ std::vector<dim2::line> segments = shapes::segments(rhs);
|
|
|
auto lhs_intersects = [&lhs](dim2::line const & ln) {
|
|
|
return intersects(lhs, ln);
|
|
|
};
|
|
|
@@ -91,7 +84,15 @@ namespace math {
|
|
|
contains(segments, lhs.second);
|
|
|
}
|
|
|
|
|
|
- bool intersects(dim2::quad const & lhs, dim2::circle const & rhs);
|
|
|
+ bool intersects(dim2::quad const & lhs, dim2::circle const & rhs) {
|
|
|
+ std::vector<dim2::line> segments = shapes::segments(lhs);
|
|
|
+ auto rhs_intersects = [&rhs](dim2::line const & ln) {
|
|
|
+ return intersects(ln, rhs);
|
|
|
+ };
|
|
|
+ return std::any_of(segments.begin(), segments.end(), rhs_intersects) ||
|
|
|
+ contains(lhs, rhs.center);
|
|
|
+ }
|
|
|
+
|
|
|
bool intersects(dim2::quad const & lhs, dim2::quad const & rhs);
|
|
|
|
|
|
bool intersects(dim2::circle const & lhs, dim2::circle const & rhs) {
|