aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-10 08:48:06 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-10 08:48:06 +0100
commitc8d05f759bb1be0ec99e8f23eaa65c80c36ce03d (patch)
tree8d176b831b9619cffc953f368be2eefc9e52c8ca /src/crepe/api
parente5e2eefc7f0f6199fe2b36688b2ad64a97784717 (diff)
Implemented feedback
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/AI.cpp15
-rw-r--r--src/crepe/api/AI.h6
2 files changed, 16 insertions, 5 deletions
diff --git a/src/crepe/api/AI.cpp b/src/crepe/api/AI.cpp
index 00e5b37..472550b 100644
--- a/src/crepe/api/AI.cpp
+++ b/src/crepe/api/AI.cpp
@@ -1,10 +1,17 @@
+#include <stdexcept>
+
#include "AI.h"
namespace crepe {
AI::AI(game_object_id_t id, float max_force) : Component(id), max_force(max_force) {}
-void AI::make_circle_path(float radius, vec2 center, float start_angle, bool clockwise) {
+void AI::make_circle_path(float radius, const vec2 & center, float start_angle,
+ bool clockwise) {
+ if (radius <= 0) {
+ throw std::runtime_error("Radius must be greater than 0");
+ }
+
// 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)
@@ -27,8 +34,12 @@ void AI::make_circle_path(float radius, vec2 center, float start_angle, bool clo
}
}
-void AI::make_oval_path(float radius_x, float radius_y, vec2 center, float start_angle,
+void AI::make_oval_path(float radius_x, float radius_y, const vec2 & center, float start_angle,
bool clockwise, float rotation) {
+ if (radius_x <= 0 && radius_y <= 0) {
+ throw std::runtime_error("Radius must be greater than 0");
+ }
+
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;
diff --git a/src/crepe/api/AI.h b/src/crepe/api/AI.h
index c95924d..de574cd 100644
--- a/src/crepe/api/AI.h
+++ b/src/crepe/api/AI.h
@@ -68,7 +68,7 @@ public:
*
* \param node The path node to add
*/
- void add_path_node(vec2 node) { path.push_back(node); }
+ void add_path_node(const vec2 & node) { path.push_back(node); }
/**
* \brief Make a circle path (for the path following behavior)
*
@@ -79,7 +79,7 @@ public:
* \param start_angle The start angle of the circle (in radians)
* \param clockwise The direction of the circle
*/
- void make_circle_path(float radius, vec2 center = {0, 0}, float start_angle = 0,
+ void make_circle_path(float radius, const vec2 & center = {0, 0}, float start_angle = 0,
bool clockwise = true);
/**
* \brief Make an oval path (for the path following behavior)
@@ -93,7 +93,7 @@ public:
* \param clockwise The direction of the oval
* \param rotation The rotation of the oval (in radians)
*/
- void make_oval_path(float radius_x, float radius_y, vec2 center = {0, 0},
+ void make_oval_path(float radius_x, float radius_y, const vec2 & center = {0, 0},
float start_angle = 0, bool clockwise = true, float rotation = 0);
public: