Skip to content

Commit

Permalink
Merge pull request #16 from NHLStenden-ISAL/operator-overloading
Browse files Browse the repository at this point in the history
Added comparison operator overloading for vec2 and segment: <, <=, >,…
  • Loading branch information
GTMeijer authored Oct 30, 2023
2 parents 4802941 + 6a0ccc6 commit cc1ca8a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
10 changes: 6 additions & 4 deletions Trajectory_Hotspots/Trajectory_Hotspots/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);;
}
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; }
5 changes: 5 additions & 0 deletions Trajectory_Hotspots/Trajectory_Hotspots/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ void Trapezoidal_Map::add_overlapping_segment(const std::vector<Trapezoidal_Leaf
//Returns the intersected trapezoids ordered from bottom to top
std::vector<Trapezoidal_Leaf_Node*> 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<Trapezoidal_Leaf_Node*> intersecting_trapezoids;

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

0 comments on commit cc1ca8a

Please sign in to comment.