Added some more Geom2D functions, only 32 to go...

pull/300/head
Javidx9 2 years ago
parent 429f84fece
commit c29acc74cc
  1. 17
      utilities/olcUTIL_Geometry2D.h

@ -496,8 +496,7 @@ namespace olc::utils::geom2d
template<typename T1, typename T2> template<typename T1, typename T2>
inline constexpr bool contains(const circle<T1>& c1, const line<T2>& l) inline constexpr bool contains(const circle<T1>& c1, const line<T2>& l)
{ {
// TODO: return contains(c1, l.start) && contains(c1, l.end);
return false;
} }
// Check if triangle contains line segment // Check if triangle contains line segment
@ -637,8 +636,10 @@ namespace olc::utils::geom2d
template<typename T1, typename T2> template<typename T1, typename T2>
inline constexpr bool contains(const circle<T1>& c, const rect<T2>& r) inline constexpr bool contains(const circle<T1>& c, const rect<T2>& r)
{ {
// TODO: return contains(c, r.pos)
return false; && contains(c, olc::v2d_generic<T2>{ r.pos.x + r.size.x, r.pos.y })
&& contains(c, olc::v2d_generic<T2>{ r.pos.x, r.pos.y + r.size.y })
&& contains(c, r.pos + r.size);
} }
// Check if triangle contains rectangle // Check if triangle contains rectangle
@ -680,8 +681,12 @@ namespace olc::utils::geom2d
template<typename T1, typename T2> template<typename T1, typename T2>
inline constexpr bool overlaps(const circle<T1>& c, const rect<T2>& r) inline constexpr bool overlaps(const circle<T1>& c, const rect<T2>& r)
{ {
// TODO: // Inspired by this (very clever btw)
return false; // https://stackoverflow.com/questions/45370692/circle-rectangle-collision-response
// But modified to work :P
T2 overlap = (olc::v2d_generic<T2>{ std::clamp(c.pos.x, r.pos.x, r.pos.x + r.size.x), std::clamp(c.pos.y, r.pos.y, r.pos.y + r.size.y) } - c.pos).mag2();
if (std::isnan(overlap)) overlap = T2(0);
return (overlap - (c.radius * c.radius)) < T2(0);
} }
// Check if triangle overlaps rectangle // Check if triangle overlaps rectangle

Loading…
Cancel
Save