|
|
|
@ -594,11 +594,10 @@ namespace olc::utils::geom2d |
|
|
|
|
template<typename T1, typename T2> |
|
|
|
|
inline constexpr bool overlaps(const rect<T1>& r, const line<T2>& l) |
|
|
|
|
{ |
|
|
|
|
return contains(r, l.start) |
|
|
|
|
|| contains(r, l.end); |
|
|
|
|
|
|
|
|
|
// TODO: This method is no good, it cant detect lines whose start and end
|
|
|
|
|
// points are outside the rectangle
|
|
|
|
|
return overlaps(r.left(),l)|| |
|
|
|
|
overlaps(r.top(),l)|| |
|
|
|
|
overlaps(r.bottom(),l)|| |
|
|
|
|
overlaps(r.right(),l); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check if circle overlaps line segment
|
|
|
|
@ -649,8 +648,16 @@ namespace olc::utils::geom2d |
|
|
|
|
template<typename T1, typename T2> |
|
|
|
|
inline std::vector<olc::v2d_generic<T2>> intersects(const rect<T1>& r, const line<T2>& l) |
|
|
|
|
{ |
|
|
|
|
// TODO:
|
|
|
|
|
return {}; |
|
|
|
|
std::vector<olc::v2d_generic<T2>>intersections; |
|
|
|
|
std::vector<olc::v2d_generic<T2>>result=intersects(r.left(),l); |
|
|
|
|
if(result.size()>0)intersections.push_back(result[0]); |
|
|
|
|
result=intersects(r.right(),l); |
|
|
|
|
if(result.size()>0)intersections.push_back(result[0]); |
|
|
|
|
result=intersects(r.top(),l); |
|
|
|
|
if(result.size()>0)intersections.push_back(result[0]); |
|
|
|
|
result=intersects(r.bottom(),l); |
|
|
|
|
if(result.size()>0)intersections.push_back(result[0]); |
|
|
|
|
return intersections; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get intersection points where circle intersects with line segment
|
|
|
|
@ -789,8 +796,7 @@ namespace olc::utils::geom2d |
|
|
|
|
template<typename T1, typename T2> |
|
|
|
|
inline std::vector<olc::v2d_generic<T2>> intersects(const line<T1>& l, const rect<T2>& r) |
|
|
|
|
{ |
|
|
|
|
// TODO:
|
|
|
|
|
return {}; |
|
|
|
|
return intersects(r,l); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get intersection points where rectangle intersects with rectangle
|
|
|
|
|