Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added comparison operator overloading for vec2 and segment: <, <=, >,… #16

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added comparison operator overloading for vec2 and segment: <, <=, >,…
… >=.
  • Loading branch information
BardoBard committed Oct 30, 2023
commit ee8386044b028c1d60aa808671e77b5c11ad7c4f
10 changes: 6 additions & 4 deletions Trajectory_Hotspots/Trajectory_Hotspots/segment.cpp
Original file line number Diff line number Diff line change
@@ -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
@@ -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;
5 changes: 5 additions & 0 deletions Trajectory_Hotspots/Trajectory_Hotspots/vec2.cpp
Original file line number Diff line number Diff line change
@@ -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
@@ -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;