Add line to rectangle collision detection in geom2d header.
This commit is contained in:
parent
5a8527f51b
commit
d9e8c6ddbd
@ -2,7 +2,7 @@
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 221
|
||||
#define VERSION_BUILD 231
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user