From 405bf73b273c7b9a6574d77b4a034d9588c9af1b Mon Sep 17 00:00:00 2001 From: max-001 Date: Wed, 11 Dec 2024 13:18:59 +0100 Subject: Removed magic numbers --- src/crepe/api/AI.cpp | 16 ++++++++-------- src/crepe/api/AI.h | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/api/AI.cpp b/src/crepe/api/AI.cpp index 472550b..34e1438 100644 --- a/src/crepe/api/AI.cpp +++ b/src/crepe/api/AI.cpp @@ -13,10 +13,10 @@ void AI::make_circle_path(float radius, const vec2 & center, float start_angle, } // The step size is determined by the radius (step size is in radians) - float step = 400.0f / radius; - // Force at least 16 steps (in case of a small radius) - if (step > 2 * M_PI / 16) { - step = 2 * M_PI / 16; + float step = RADIUS_TO_STEP / radius; + // Force at least MIN_STEP steps (in case of a small radius) + if (step > 2 * M_PI / MIN_STEP) { + step = 2 * M_PI / MIN_STEP; } // The path node distance is determined by the step size and the radius path_node_distance = radius * step * 0.75f; @@ -42,10 +42,10 @@ void AI::make_oval_path(float radius_x, float radius_y, const vec2 & center, flo float max_radius = std::max(radius_x, radius_y); // The step size is determined by the radius (step size is in radians) - float step = 400.0f / max_radius; - // Force at least 16 steps (in case of a small radius) - if (step > 2 * M_PI / 16) { - step = 2 * M_PI / 16; + float step = RADIUS_TO_STEP / max_radius; + // Force at least MIN_STEP steps (in case of a small radius) + if (step > 2 * M_PI / MIN_STEP) { + step = 2 * M_PI / MIN_STEP; } // The path node distance is determined by the step size and the radius path_node_distance = max_radius * step * 0.75f; diff --git a/src/crepe/api/AI.h b/src/crepe/api/AI.h index 80feda5..fc28451 100644 --- a/src/crepe/api/AI.h +++ b/src/crepe/api/AI.h @@ -116,6 +116,9 @@ private: //! The AISystem is the only class that should access the flags and path_index variables friend class AISystem; + + static constexpr const int MIN_STEP = 16; + static constexpr const float RADIUS_TO_STEP = 400.0f; }; } // namespace crepe -- cgit v1.2.3