|
1 |
| -// Copyright 2020-2024 Tier IV, Inc. |
| 1 | +// Copyright 2025 The Autoware Contributors |
2 | 2 | //
|
3 | 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 4 | // you may not use this file except in compliance with the License.
|
|
15 | 15 | #ifndef AUTOWARE_UTILS__GEOMETRY__ALT_GEOMETRY_HPP_
|
16 | 16 | #define AUTOWARE_UTILS__GEOMETRY__ALT_GEOMETRY_HPP_
|
17 | 17 |
|
18 |
| -#include "autoware_utils/geometry/boost_geometry.hpp" |
| 18 | +// NOLINTBEGIN(build/namespaces, whitespace/line_length) |
| 19 | +// clang-format off |
19 | 20 |
|
20 |
| -#include <list> |
21 |
| -#include <optional> |
22 |
| -#include <utility> |
23 |
| -#include <vector> |
| 21 | +#include <autoware_utils_geometry/alt_geometry.hpp> |
| 22 | +namespace autoware_utils { using namespace autoware_utils_geometry; } |
24 | 23 |
|
25 |
| -namespace autoware_utils |
26 |
| -{ |
27 |
| -// Alternatives for Boost.Geometry ---------------------------------------------------------------- |
28 |
| -// TODO(mitukou1109): remove namespace |
29 |
| -namespace alt |
30 |
| -{ |
31 |
| -class Vector2d |
32 |
| -{ |
33 |
| -public: |
34 |
| - Vector2d() : x_(0.0), y_(0.0) {} |
35 |
| - |
36 |
| - Vector2d(const double x, const double y) : x_(x), y_(y) {} |
37 |
| - |
38 |
| - explicit Vector2d(const autoware_utils::Point2d & point) : x_(point.x()), y_(point.y()) {} |
39 |
| - |
40 |
| - double cross(const Vector2d & other) const { return x_ * other.y() - y_ * other.x(); } |
41 |
| - |
42 |
| - double dot(const Vector2d & other) const { return x_ * other.x() + y_ * other.y(); } |
43 |
| - |
44 |
| - double norm2() const { return x_ * x_ + y_ * y_; } |
45 |
| - |
46 |
| - double norm() const { return std::sqrt(norm2()); } |
47 |
| - |
48 |
| - Vector2d vector_triple(const Vector2d & v1, const Vector2d & v2) const |
49 |
| - { |
50 |
| - const auto tmp = this->cross(v1); |
51 |
| - return {-v2.y() * tmp, v2.x() * tmp}; |
52 |
| - } |
53 |
| - |
54 |
| - const double & x() const { return x_; } |
55 |
| - |
56 |
| - double & x() { return x_; } |
57 |
| - |
58 |
| - const double & y() const { return y_; } |
59 |
| - |
60 |
| - double & y() { return y_; } |
61 |
| - |
62 |
| -private: |
63 |
| - double x_; |
64 |
| - double y_; |
65 |
| -}; |
66 |
| - |
67 |
| -inline Vector2d operator+(const Vector2d & v1, const Vector2d & v2) |
68 |
| -{ |
69 |
| - return {v1.x() + v2.x(), v1.y() + v2.y()}; |
70 |
| -} |
71 |
| - |
72 |
| -inline Vector2d operator-(const Vector2d & v1, const Vector2d & v2) |
73 |
| -{ |
74 |
| - return {v1.x() - v2.x(), v1.y() - v2.y()}; |
75 |
| -} |
76 |
| - |
77 |
| -inline Vector2d operator-(const Vector2d & v) |
78 |
| -{ |
79 |
| - return {-v.x(), -v.y()}; |
80 |
| -} |
81 |
| - |
82 |
| -inline Vector2d operator*(const double & s, const Vector2d & v) |
83 |
| -{ |
84 |
| - return {s * v.x(), s * v.y()}; |
85 |
| -} |
86 |
| - |
87 |
| -// We use Vector2d to represent points, but we do not name the class Point2d directly |
88 |
| -// as it has some vector operation functions. |
89 |
| -using Point2d = Vector2d; |
90 |
| -using Points2d = std::vector<Point2d>; |
91 |
| -using PointList2d = std::list<Point2d>; |
92 |
| - |
93 |
| -class Polygon2d |
94 |
| -{ |
95 |
| -public: |
96 |
| - static std::optional<Polygon2d> create( |
97 |
| - const PointList2d & outer, const std::vector<PointList2d> & inners) noexcept; |
98 |
| - |
99 |
| - static std::optional<Polygon2d> create( |
100 |
| - PointList2d && outer, std::vector<PointList2d> && inners) noexcept; |
101 |
| - |
102 |
| - static std::optional<Polygon2d> create(const autoware_utils::Polygon2d & polygon) noexcept; |
103 |
| - |
104 |
| - const PointList2d & outer() const noexcept { return outer_; } |
105 |
| - |
106 |
| - PointList2d & outer() noexcept { return outer_; } |
107 |
| - |
108 |
| - const std::vector<PointList2d> & inners() const noexcept { return inners_; } |
109 |
| - |
110 |
| - std::vector<PointList2d> & inners() noexcept { return inners_; } |
111 |
| - |
112 |
| - autoware_utils::Polygon2d to_boost() const; |
113 |
| - |
114 |
| -protected: |
115 |
| - Polygon2d(const PointList2d & outer, const std::vector<PointList2d> & inners) |
116 |
| - : outer_(outer), inners_(inners) |
117 |
| - { |
118 |
| - } |
119 |
| - |
120 |
| - Polygon2d(PointList2d && outer, std::vector<PointList2d> && inners) |
121 |
| - : outer_(std::move(outer)), inners_(std::move(inners)) |
122 |
| - { |
123 |
| - } |
124 |
| - |
125 |
| - PointList2d outer_; |
126 |
| - |
127 |
| - std::vector<PointList2d> inners_; |
128 |
| -}; |
129 |
| - |
130 |
| -class ConvexPolygon2d : public Polygon2d |
131 |
| -{ |
132 |
| -public: |
133 |
| - static std::optional<ConvexPolygon2d> create(const PointList2d & vertices) noexcept; |
134 |
| - |
135 |
| - static std::optional<ConvexPolygon2d> create(PointList2d && vertices) noexcept; |
136 |
| - |
137 |
| - static std::optional<ConvexPolygon2d> create(const autoware_utils::Polygon2d & polygon) noexcept; |
138 |
| - |
139 |
| - const PointList2d & vertices() const noexcept { return outer(); } |
140 |
| - |
141 |
| - PointList2d & vertices() noexcept { return outer(); } |
142 |
| - |
143 |
| -private: |
144 |
| - explicit ConvexPolygon2d(const PointList2d & vertices) : Polygon2d(vertices, {}) {} |
145 |
| - |
146 |
| - explicit ConvexPolygon2d(PointList2d && vertices) : Polygon2d(std::move(vertices), {}) {} |
147 |
| -}; |
148 |
| -} // namespace alt |
149 |
| - |
150 |
| -double area(const alt::ConvexPolygon2d & poly); |
151 |
| - |
152 |
| -std::optional<alt::ConvexPolygon2d> convex_hull(const alt::Points2d & points); |
153 |
| - |
154 |
| -void correct(alt::Polygon2d & poly); |
155 |
| - |
156 |
| -bool covered_by(const alt::Point2d & point, const alt::ConvexPolygon2d & poly); |
157 |
| - |
158 |
| -bool disjoint(const alt::ConvexPolygon2d & poly1, const alt::ConvexPolygon2d & poly2); |
159 |
| - |
160 |
| -double distance( |
161 |
| - const alt::Point2d & point, const alt::Point2d & seg_start, const alt::Point2d & seg_end); |
162 |
| - |
163 |
| -double distance(const alt::Point2d & point, const alt::ConvexPolygon2d & poly); |
164 |
| - |
165 |
| -std::optional<alt::ConvexPolygon2d> envelope(const alt::Polygon2d & poly); |
166 |
| - |
167 |
| -bool equals(const alt::Point2d & point1, const alt::Point2d & point2); |
168 |
| - |
169 |
| -bool equals(const alt::Polygon2d & poly1, const alt::Polygon2d & poly2); |
170 |
| - |
171 |
| -alt::Points2d::const_iterator find_farthest( |
172 |
| - const alt::Points2d & points, const alt::Point2d & seg_start, const alt::Point2d & seg_end); |
173 |
| - |
174 |
| -bool intersects( |
175 |
| - const alt::Point2d & seg1_start, const alt::Point2d & seg1_end, const alt::Point2d & seg2_start, |
176 |
| - const alt::Point2d & seg2_end); |
177 |
| - |
178 |
| -bool intersects(const alt::ConvexPolygon2d & poly1, const alt::ConvexPolygon2d & poly2); |
179 |
| - |
180 |
| -bool is_above( |
181 |
| - const alt::Point2d & point, const alt::Point2d & seg_start, const alt::Point2d & seg_end); |
182 |
| - |
183 |
| -bool is_clockwise(const alt::PointList2d & vertices); |
184 |
| - |
185 |
| -bool is_convex(const alt::Polygon2d & poly); |
186 |
| - |
187 |
| -alt::PointList2d simplify(const alt::PointList2d & line, const double max_distance); |
188 |
| - |
189 |
| -bool touches( |
190 |
| - const alt::Point2d & point, const alt::Point2d & seg_start, const alt::Point2d & seg_end); |
191 |
| - |
192 |
| -bool touches(const alt::Point2d & point, const alt::ConvexPolygon2d & poly); |
193 |
| - |
194 |
| -bool within(const alt::Point2d & point, const alt::ConvexPolygon2d & poly); |
195 |
| - |
196 |
| -bool within( |
197 |
| - const alt::ConvexPolygon2d & poly_contained, const alt::ConvexPolygon2d & poly_containing); |
198 |
| -} // namespace autoware_utils |
| 24 | +// clang-format on |
| 25 | +// NOLINTEND |
199 | 26 |
|
200 | 27 | #endif // AUTOWARE_UTILS__GEOMETRY__ALT_GEOMETRY_HPP_
|
0 commit comments