From d2c8a2bf07275f5458c576990b8742a710b15013 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Thu, 19 Dec 2024 20:16:30 +0100 Subject: is_nan fix --- src/crepe/api/Vector2.hpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/crepe/api/Vector2.hpp') diff --git a/src/crepe/api/Vector2.hpp b/src/crepe/api/Vector2.hpp index ff53cb0..a470595 100644 --- a/src/crepe/api/Vector2.hpp +++ b/src/crepe/api/Vector2.hpp @@ -163,4 +163,9 @@ Vector2 Vector2::perpendicular() const { return {-y, x}; } +template +bool Vector2::is_nan() const { + return std::isnan(x) && std::isnan(y); +} + } // namespace crepe -- cgit v1.2.3 From 3894948275e10b6a0e3614ba0da90b9ea8d6cd4e Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Thu, 19 Dec 2024 20:27:39 +0100 Subject: make format --- src/crepe/api/Vector2.hpp | 2 +- src/crepe/system/CollisionSystem.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src/crepe/api/Vector2.hpp') diff --git a/src/crepe/api/Vector2.hpp b/src/crepe/api/Vector2.hpp index a470595..e195760 100644 --- a/src/crepe/api/Vector2.hpp +++ b/src/crepe/api/Vector2.hpp @@ -165,7 +165,7 @@ Vector2 Vector2::perpendicular() const { template bool Vector2::is_nan() const { - return std::isnan(x) && std::isnan(y); + return std::isnan(x) && std::isnan(y); } } // namespace crepe diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 0bceac7..e4396b9 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -168,7 +168,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern // Get resolution vector from box-box collision detection resolution = this->get_box_box_detection(BOX1, BOX2); // If no collision (NaN values), return false - if(resolution.is_nan()) return false; + if (resolution.is_nan()) return false; break; } case CollisionInternalType::BOX_CIRCLE: { @@ -184,7 +184,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern // Get resolution vector from box-circle collision detection resolution = this->get_box_circle_detection(BOX1, CIRCLE2); // If no collision (NaN values), return false - if(resolution.is_nan()) return false; + if (resolution.is_nan()) return false; // Invert the resolution vector for proper collision response resolution = -resolution; break; @@ -202,7 +202,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern // Get resolution vector from circle-circle collision detection resolution = this->get_circle_circle_detection(CIRCLE1, CIRCLE2); // If no collision (NaN values), return false - if(resolution.is_nan()) return false; + if (resolution.is_nan()) return false; break; } case CollisionInternalType::CIRCLE_BOX: { @@ -218,7 +218,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern // Get resolution vector from box-circle collision detection (order swapped) resolution = this->get_box_circle_detection(BOX2, CIRCLE1); // If no collision (NaN values), return false - if(resolution.is_nan()) return false; + if (resolution.is_nan()) return false; break; } case CollisionInternalType::NONE: @@ -239,7 +239,8 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern return true; } -vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1, const BoxColliderInternal & box2) const { +vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1, + const BoxColliderInternal & box2) const { vec2 resolution{NAN, NAN}; // Get current positions of colliders vec2 pos1 = AbsolutePosition::get_position(box1.transform, box1.collider.offset); @@ -370,7 +371,8 @@ vec2 CollisionSystem::get_circle_circle_detection( return resolution; } // No collision - return vec2{NAN, NAN};; + return vec2{NAN, NAN}; + ; } CollisionSystem::Direction -- cgit v1.2.3