From ee8386044b028c1d60aa808671e77b5c11ad7c4f Mon Sep 17 00:00:00 2001 From: Bard Date: Mon, 30 Oct 2023 14:08:34 +0100 Subject: [PATCH 1/2] Added comparison operator overloading for vec2 and segment: <, <=, >, >=. --- Trajectory_Hotspots/Trajectory_Hotspots/segment.cpp | 10 ++++++---- Trajectory_Hotspots/Trajectory_Hotspots/segment.h | 5 +++++ Trajectory_Hotspots/Trajectory_Hotspots/vec2.cpp | 5 +++++ Trajectory_Hotspots/Trajectory_Hotspots/vec2.h | 7 ++++++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/segment.cpp b/Trajectory_Hotspots/Trajectory_Hotspots/segment.cpp index dc48edf..e28492a 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/segment.cpp +++ b/Trajectory_Hotspots/Trajectory_Hotspots/segment.cpp @@ -287,7 +287,9 @@ bool Segment::operator==(const Segment& operand) const return (start == operand.start && end == operand.end) || (end == operand.start && start == operand.end); } -bool Segment::operator!=(const Segment& operand) const -{ - return !(*this == operand);; -} \ No newline at end of file +bool Segment::operator!=(const Segment& operand) const { return !(*this == operand); } + +bool Segment::operator<(const Segment& operand) const { return start < operand.start && end < operand.end; } +bool Segment::operator<=(const Segment& operand) const { return start <= operand.start && end <= operand.end; } +bool Segment::operator>(const Segment& operand) const { return start > operand.start && end > operand.end; } +bool Segment::operator>=(const Segment& operand) const { return start >= operand.start && end >= operand.end; } diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/segment.h b/Trajectory_Hotspots/Trajectory_Hotspots/segment.h index 85d6bfa..894f99d 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/segment.h +++ b/Trajectory_Hotspots/Trajectory_Hotspots/segment.h @@ -37,6 +37,11 @@ class Segment bool operator==(const Segment& operand) const; bool operator!=(const Segment& operand) const; + + bool operator<(const Segment& operand) const; + bool operator<=(const Segment& operand) const; + bool operator>(const Segment& operand) const; + bool operator>=(const Segment& operand) const; Float length() const; Float squared_length() const; diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/vec2.cpp b/Trajectory_Hotspots/Trajectory_Hotspots/vec2.cpp index a7e7e52..2cc110f 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/vec2.cpp +++ b/Trajectory_Hotspots/Trajectory_Hotspots/vec2.cpp @@ -51,5 +51,10 @@ Vec2 Vec2::operator/=(const Float& scalar) const { return Vec2(x / scalar, y / s bool Vec2::operator==(const Vec2& operand) const { return x == operand.x && y == operand.y; } bool Vec2::operator!=(const Vec2& operand) const { return !(*this == operand); } +bool Vec2::operator<(const Vec2& operand) const { return x < operand.x && y < operand.y; } +bool Vec2::operator<=(const Vec2& operand) const { return x <= operand.x && y <= operand.y; } +bool Vec2::operator>(const Vec2& operand) const { return x > operand.x && y > operand.y; } +bool Vec2::operator>=(const Vec2& operand) const { return x >= operand.x && y >= operand.y; } + Vec2 operator*(const Float& scalar, const Vec2& vec) { return Vec2(vec.x * scalar, vec.y * scalar); } Vec2 operator/(const Float& scalar, const Vec2& vec) { return Vec2(vec.x / scalar, vec.y / scalar); } \ No newline at end of file diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/vec2.h b/Trajectory_Hotspots/Trajectory_Hotspots/vec2.h index c63aea7..df2ceb0 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/vec2.h +++ b/Trajectory_Hotspots/Trajectory_Hotspots/vec2.h @@ -34,9 +34,14 @@ class Vec2 Vec2 operator-=(const Vec2& other) const; Vec2 operator*=(const Float& scalar) const; Vec2 operator/=(const Float& scalar) const; - + bool operator==(const Vec2& operand) const; bool operator!=(const Vec2& operand) const; + + bool operator<(const Vec2& operand) const; + bool operator<=(const Vec2& operand) const; + bool operator>(const Vec2& operand) const; + bool operator>=(const Vec2& operand) const; Float x; Float y; From 6a0ccc6a584e7b160f477a2f51611776f4b77a0d Mon Sep 17 00:00:00 2001 From: Bardio <107430862+BardoBard@users.noreply.github.com> Date: Mon, 30 Oct 2023 16:04:20 +0100 Subject: [PATCH 2/2] updated edge case with assert --- Trajectory_Hotspots/Trajectory_Hotspots/trapezoidal_map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Trajectory_Hotspots/Trajectory_Hotspots/trapezoidal_map.cpp b/Trajectory_Hotspots/Trajectory_Hotspots/trapezoidal_map.cpp index 390ee3e..8b48d8c 100644 --- a/Trajectory_Hotspots/Trajectory_Hotspots/trapezoidal_map.cpp +++ b/Trajectory_Hotspots/Trajectory_Hotspots/trapezoidal_map.cpp @@ -829,7 +829,7 @@ void Trapezoidal_Map::add_overlapping_segment(const std::vector Trapezoidal_Map::follow_segment(const Segment& query_segment) { - assert(query_segment.start.y < query_segment.end.y); + assert(query_segment.start.y <= query_segment.end.y); std::vector intersecting_trapezoids;