From d254e169c4b571b2c61822a592e96fa8880611e0 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Thu, 22 Jun 2023 16:42:23 -0700 Subject: [PATCH] Added ellipse contains function to Geometry2D. --- Crawler/Crawler.cpp | 2 +- Crawler/Version.h | 2 +- Crawler/olcUTIL_Geometry2D.h | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index ac9894ea..2887f07e 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -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; } diff --git a/Crawler/Version.h b/Crawler/Version.h index 8c656d62..597133b2 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -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 diff --git a/Crawler/olcUTIL_Geometry2D.h b/Crawler/olcUTIL_Geometry2D.h index b3afe212..827fd5a4 100644 --- a/Crawler/olcUTIL_Geometry2D.h +++ b/Crawler/olcUTIL_Geometry2D.h @@ -197,6 +197,34 @@ namespace olc::utils::geom2d } }; + template + struct ellipse + { + olc::v2d_generic pos; + olc::v2d_generic radius; + + inline ellipse(const olc::v2d_generic& p = { T(0), T(0) }, const olc::v2d_generic 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 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 + inline constexpr bool contains(const ellipse& c, const olc::v2d_generic& 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 inline constexpr bool contains(const circle& c, const olc::v2d_generic& p)