Skip to content

Commit

Permalink
Merge pull request #20 from NHLStenden-ISAL/refactor
Browse files Browse the repository at this point in the history
Removed bug related to trajectory, added default constructor in traje…
  • Loading branch information
GTMeijer authored Nov 16, 2023
2 parents fd2004e + 149c71c commit 5aabb8b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Trajectory_Hotspots/Trajectory_Hotspots/float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion Trajectory_Hotspots/Trajectory_Hotspots/float.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Float
Float(const Float& other) : value(other.value) {};
~Float() {};

static inline float fixed_epsilon = 0.0000001f;

float get_value() const { return value; }
float set_value(const float value) { this->value = value; }

Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions Trajectory_Hotspots/Trajectory_Hotspots/trajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Segment> x_segments;
std::vector<Segment> y_segments;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion Trajectory_Hotspots/Trajectory_Hotspots/trajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class Trajectory
{
public:

Trajectory(){}
Trajectory(std::vector<Segment>& ordered_segments);
Trajectory(const std::vector<Vec2>& ordered_points);

Expand Down
4 changes: 4 additions & 0 deletions Trajectory_Hotspots/Trajectory_Hotspots/vec2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand Down
4 changes: 4 additions & 0 deletions Trajectory_Hotspots/Trajectory_Hotspots/vec2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 5aabb8b

Please sign in to comment.