From 5e365314c8b4931bf749dc369224e4023ceb107a Mon Sep 17 00:00:00 2001 From: Bard Date: Thu, 16 Nov 2023 11:08:58 +0100 Subject: [PATCH 1/5] Removed bug related to trajectory, added default constructor in trajectory, added operator overloading for vec2 with n --- Trajectory_Hotspots/Trajectory_Hotspots/trajectory.cpp | 4 ++-- Trajectory_Hotspots/Trajectory_Hotspots/trajectory.h | 2 +- Trajectory_Hotspots/Trajectory_Hotspots/vec2.cpp | 4 ++++ Trajectory_Hotspots/Trajectory_Hotspots/vec2.h | 4 ++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/trajectory.cpp b/Trajectory_Hotspots/Trajectory_Hotspots/trajectory.cpp index 7c04171..d308be3 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/trajectory.cpp +++ b/Trajectory_Hotspots/Trajectory_Hotspots/trajectory.cpp @@ -51,7 +51,7 @@ AABB Trajectory::get_hotspot_fixed_radius_contiguous(Float radius) const Float longest_valid_subtrajectory(0.f); AABB optimal_hotspot; - //Setup trapezoidal maps representing the graphs with the x or y coördinates on the y-axis and time on the x-axis + //Setup trapezoidal maps representing the graphs with the x or y co�rdinates on the y-axis and time on the x-axis std::vector x_segments; std::vector y_segments; @@ -88,7 +88,7 @@ AABB Trajectory::get_hotspot_fixed_radius_contiguous(Float radius) const //Test horizontal lines //Test below - Vec2 vert_at_radius(current_y_vert.x, current_y_vert.y - radius); + vert_at_radius = Vec2(current_y_vert.x, current_y_vert.y - radius); frc_test_between_lines(trapezoidal_map_y, current_y_vert, vert_at_radius, false, segment_tree, radius, longest_valid_subtrajectory, optimal_hotspot); //Test above diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/trajectory.h b/Trajectory_Hotspots/Trajectory_Hotspots/trajectory.h index 3aad5fa..1b43634 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/trajectory.h +++ b/Trajectory_Hotspots/Trajectory_Hotspots/trajectory.h @@ -5,7 +5,7 @@ class Trajectory { public: - + Trajectory(){} Trajectory(std::vector& ordered_segments); Trajectory(const std::vector& ordered_points); diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/vec2.cpp b/Trajectory_Hotspots/Trajectory_Hotspots/vec2.cpp index c20f0a3..d2e8e11 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/vec2.cpp +++ b/Trajectory_Hotspots/Trajectory_Hotspots/vec2.cpp @@ -37,7 +37,11 @@ Vec2 Vec2::normalized() const } Vec2 Vec2::operator+(const Vec2& other) const { return Vec2(x + other.x, y + other.y); } +Vec2 Vec2::operator+(const Float& n) const { return Vec2(x + n, y + n); } + Vec2 Vec2::operator-(const Vec2& other) const { return Vec2(x - other.x, y - other.y); } +Vec2 Vec2::operator-(const Float& n) const { return Vec2(x - n, y - n); } + Vec2 Vec2::operator*(const Float& scalar) const { return Vec2(x * scalar, y * scalar); } Vec2 Vec2::operator/(const Float& scalar) const { return Vec2(x / scalar, y / scalar); } diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/vec2.h b/Trajectory_Hotspots/Trajectory_Hotspots/vec2.h index 1240358..3f8630f 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/vec2.h +++ b/Trajectory_Hotspots/Trajectory_Hotspots/vec2.h @@ -24,7 +24,11 @@ class Vec2 Vec2 normalized() const; Vec2 operator+(const Vec2& other) const; + Vec2 operator+(const Float& n) const; + Vec2 operator-(const Vec2& other) const; + Vec2 operator-(const Float& n) const; + Vec2 operator*(const Float& scalar) const; Vec2 operator/(const Float& scalar) const; From e4e6da55bd3a47ddec529680373bb5f62abe243d Mon Sep 17 00:00:00 2001 From: Bard Date: Thu, 16 Nov 2023 11:45:07 +0100 Subject: [PATCH 2/5] added static fixed epsilon instead of given to nearly_equal --- Trajectory_Hotspots/Trajectory_Hotspots/float.cpp | 4 ++-- Trajectory_Hotspots/Trajectory_Hotspots/float.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/float.cpp b/Trajectory_Hotspots/Trajectory_Hotspots/float.cpp index 8d89953..e3a7a2e 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/float.cpp +++ b/Trajectory_Hotspots/Trajectory_Hotspots/float.cpp @@ -34,11 +34,11 @@ int32_t Float::ulps_distance(const float a, const float b) const //Check for nearly equal float values -bool Float::nearly_equal(const float a, const float b, const float fixedEpsilon, const int ulpsEpsilon) const +bool Float::nearly_equal(const float a, const float b const int ulpsEpsilon) const { // Handle the near-zero case. const float difference = fabs(a - b); - if (difference <= fixedEpsilon) return true; + if (difference <= fixed_epsilon) return true; return ulps_distance(a, b) <= ulpsEpsilon; } diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/float.h b/Trajectory_Hotspots/Trajectory_Hotspots/float.h index cb4c2f4..b057bfc 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/float.h +++ b/Trajectory_Hotspots/Trajectory_Hotspots/float.h @@ -8,6 +8,8 @@ class Float Float(const Float& other) : value(other.value) {}; ~Float() {}; + static float fixed_epsilon = 0.0000001f; + float get_value() const { return value; } float set_value(const float value) { this->value = value; } @@ -69,7 +71,7 @@ class Float int32_t ulps_distance(const float a, const float b) const; //Check for nearly equal float values - bool nearly_equal(const float a, const float b, const float fixedEpsilon = 0.0000001f, const int ulpsEpsilon = 3) const; + bool nearly_equal(const float a, const float b, const int ulpsEpsilon = 3) const; bool nearly_less(const float a, const float b) const; From 56b3506fbd9dd8675dd58394c45380c496777ece Mon Sep 17 00:00:00 2001 From: Bard Date: Thu, 16 Nov 2023 11:45:26 +0100 Subject: [PATCH 3/5] typo --- Trajectory_Hotspots/Trajectory_Hotspots/float.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/float.cpp b/Trajectory_Hotspots/Trajectory_Hotspots/float.cpp index e3a7a2e..ba64344 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/float.cpp +++ b/Trajectory_Hotspots/Trajectory_Hotspots/float.cpp @@ -34,7 +34,7 @@ int32_t Float::ulps_distance(const float a, const float b) const //Check for nearly equal float values -bool Float::nearly_equal(const float a, const float b const int ulpsEpsilon) const +bool Float::nearly_equal(const float a, const float b, const int ulpsEpsilon) const { // Handle the near-zero case. const float difference = fabs(a - b); From 5f09b2da991328573c39f446d1bb6882059a8d3c Mon Sep 17 00:00:00 2001 From: Bard Date: Thu, 16 Nov 2023 11:48:11 +0100 Subject: [PATCH 4/5] forgot inline :o oops --- Trajectory_Hotspots/Trajectory_Hotspots/float.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/float.h b/Trajectory_Hotspots/Trajectory_Hotspots/float.h index b057bfc..9ab9fcf 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/float.h +++ b/Trajectory_Hotspots/Trajectory_Hotspots/float.h @@ -8,7 +8,7 @@ class Float Float(const Float& other) : value(other.value) {}; ~Float() {}; - static float fixed_epsilon = 0.0000001f; + static inline float fixed_epsilon = 0.0000001f; float get_value() const { return value; } float set_value(const float value) { this->value = value; } From 149c71c9dc0d9b27421138f2497508c9b2454140 Mon Sep 17 00:00:00 2001 From: Gert Meijer Date: Thu, 16 Nov 2023 12:50:34 +0100 Subject: [PATCH 5/5] Update trajectory.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ö --- Trajectory_Hotspots/Trajectory_Hotspots/trajectory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/trajectory.cpp b/Trajectory_Hotspots/Trajectory_Hotspots/trajectory.cpp index d308be3..f26278d 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/trajectory.cpp +++ b/Trajectory_Hotspots/Trajectory_Hotspots/trajectory.cpp @@ -51,7 +51,7 @@ AABB Trajectory::get_hotspot_fixed_radius_contiguous(Float radius) const Float longest_valid_subtrajectory(0.f); AABB optimal_hotspot; - //Setup trapezoidal maps representing the graphs with the x or y co�rdinates on the y-axis and time on the x-axis + //Setup trapezoidal maps representing the graphs with the x or y coördinates on the y-axis and time on the x-axis std::vector x_segments; std::vector y_segments; @@ -455,4 +455,4 @@ bool Trajectory::flc_breakpoint_V(const Segment_Search_Tree& tree, const Float l potential_hotspot = tree.query(start_segment.get_time_at_point(p), end_segment.get_time_at_point(q)); return true; -} \ No newline at end of file +}