Added ellipse contains function to Geometry2D.
This commit is contained in:
parent
e6268b0edc
commit
d254e169c4
@ -133,7 +133,7 @@ bool Crawler::OnUserCreate(){
|
||||
,{MonsterName::SLIME_BLUE,{(rand()%20/2.f-5)*24,(rand()%20/2.f-5)*24}}
|
||||
}}));
|
||||
|
||||
LoadLevel(CAMPAIGN_1_1);
|
||||
LoadLevel(LEVEL2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 175
|
||||
#define VERSION_BUILD 180
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
@ -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>
|
||||
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));
|
||||
}
|
||||
|
||||
// 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
|
||||
template<typename T1, typename T2>
|
||||
inline constexpr bool contains(const circle<T1>& c, const olc::v2d_generic<T2>& p)
|
||||
|
Loading…
x
Reference in New Issue
Block a user