|
|
@ -197,6 +197,34 @@ namespace olc::utils::geom2d |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> |
|
|
|
|
|
|
|
struct ellipse |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
olc::v2d_generic<T> pos; |
|
|
|
|
|
|
|
olc::v2d_generic<T> radius; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline ellipse(const olc::v2d_generic<T>& p = { T(0), T(0) }, const olc::v2d_generic<T> r = {T(1),T(1)}) |
|
|
|
|
|
|
|
: pos(p), radius(r) |
|
|
|
|
|
|
|
{ } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get area of ellipse
|
|
|
|
|
|
|
|
inline constexpr T area() const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return T(pi) * radius.x * radius.y; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get perimeter of an ellipse
|
|
|
|
|
|
|
|
inline constexpr T perimeter() const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return T(2.0 * pi) * sqrt((radius.x*radius.x+radius.y*radius.y)/(2*1.0)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get circumference of ellipse. Which is the same as a permieter of one.
|
|
|
|
|
|
|
|
inline constexpr T circumference() const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return perimeter(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
template<typename T> |
|
|
|
template<typename T> |
|
|
|
struct circle |
|
|
|
struct circle |
|
|
@ -376,6 +404,13 @@ namespace olc::utils::geom2d |
|
|
|
p.x > (r.pos.x + r.size.x) || p.y > (r.pos.y + r.size.y)); |
|
|
|
p.x > (r.pos.x + r.size.x) || p.y > (r.pos.y + r.size.y)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Checks if ellipse contains a point
|
|
|
|
|
|
|
|
template<typename T1, typename T2> |
|
|
|
|
|
|
|
inline constexpr bool contains(const ellipse<T1>& c, const olc::v2d_generic<T2>& p) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return std::pow(p.x-c.pos.x,2)/(c.radius.x*c.radius.x)+std::pow(p.y-c.pos.y,2)/(c.radius.y*c.radius.y)<1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Checks if circle contains a point
|
|
|
|
// Checks if circle contains a point
|
|
|
|
template<typename T1, typename T2> |
|
|
|
template<typename T1, typename T2> |
|
|
|
inline constexpr bool contains(const circle<T1>& c, const olc::v2d_generic<T2>& p) |
|
|
|
inline constexpr bool contains(const circle<T1>& c, const olc::v2d_generic<T2>& p) |
|
|
|