Skip to content

Commit

Permalink
Added comparison operator overloading for vec2 and segment: <, <=, >,…
Browse files Browse the repository at this point in the history
… >=.
  • Loading branch information
BardoBard committed Oct 30, 2023
1 parent 4802941 commit ee83860
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 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
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 ee83860

Please sign in to comment.