| 1 |
// Copyright 2023 Google LLC |
| 2 |
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 3 |
|
| 4 |
#include "modules/bentleyottmann/include/Point.h" |
| 5 |
|
| 6 |
#include <limits> |
| 7 |
#include <tuple> |
| 8 |
|
| 9 |
namespace bentleyottmann { |
| 10 |
|
| 11 |
// -- Point ---------------------------------------------------------------------------------------- |
| 12 |
bool operator<(const Point& p0, const Point& p1) { |
| 13 |
return std::tie(p0.y, p0.x) < std::tie(p1.y, p1.x); |
| 14 |
} |
| 15 |
|
| 16 |
bool operator>(const Point& p0, const Point& p1) { |
| 17 |
return p1 < p0; |
| 18 |
} |
| 19 |
|
| 20 |
bool operator>=(const Point& p0, const Point& p1) { |
| 21 |
return !(p0 < p1); |
| 22 |
} |
| 23 |
|
| 24 |
bool operator<=(const Point& p0, const Point& p1) { |
| 25 |
return !(p0 > p1); |
| 26 |
} |
| 27 |
|
| 28 |
bool operator==(const Point& p0, const Point& p1) { |
| 29 |
return std::tie(p0.y, p0.x) == std::tie(p1.y, p1.x); |
| 30 |
} |
| 31 |
|
| 32 |
bool operator!=(const Point& p0, const Point& p1) { |
| 33 |
return !(p0 == p1); |
| 34 |
} |
| 35 |
|
| 36 |
Point Point::Smallest() { |
| 37 |
const int32_t kMinCoordinate = std::numeric_limits<int32_t>::min(); |
| 38 |
return {kMinCoordinate, kMinCoordinate}; |
| 39 |
} |
| 40 |
|
| 41 |
Point Point::Largest() { |
| 42 |
const int32_t kMaxCoordinate = std::numeric_limits<int32_t>::max(); |
| 43 |
return {kMaxCoordinate, kMaxCoordinate}; |
| 44 |
} |
| 45 |
|
| 46 |
bool Point::DifferenceTooBig(Point p0, Point p1) { |
| 47 |
auto tooBig = [](int32_t a, int32_t b) { |
| 48 |
return (b > 0 && a < std::numeric_limits<int32_t>::min() + b) || |
| 49 |
(b < 0 && a > std::numeric_limits<int32_t>::max() + b); |
| 50 |
}; |
| 51 |
|
| 52 |
return tooBig(p0.x, p1.x) || tooBig(p0.y, p1.y); |
| 53 |
} |
| 54 |
} // namespace bentleyottmann |