22#include "absl/strings/str_cat.h"
35 half_length_(length / 2.0),
36 half_width_(width / 2.0) {
42 :
AABox2d((one_corner + opposite_corner) / 2.0,
43 std::abs(one_corner.x() - opposite_corner.x()),
44 std::abs(one_corner.y() - opposite_corner.y())) {}
48 double min_x = points[0].x();
49 double max_x = points[0].x();
50 double min_y = points[0].y();
51 double max_y = points[0].y();
52 for (
const auto &point : points) {
62 half_length_ = length_ / 2.0;
63 half_width_ = width_ / 2.0;
67 CHECK_NOTNULL(corners)->clear();
69 corners->emplace_back(center_.
x() + half_length_, center_.
y() - half_width_);
70 corners->emplace_back(center_.
x() + half_length_, center_.
y() + half_width_);
71 corners->emplace_back(center_.
x() - half_length_, center_.
y() + half_width_);
72 corners->emplace_back(center_.
x() - half_length_, center_.
y() - half_width_);
76 return std::abs(point.
x() - center_.
x()) <= half_length_ +
kMathEpsilon &&
81 const double dx = std::abs(point.
x() - center_.
x());
82 const double dy = std::abs(point.
y() - center_.
y());
90 const double dx = std::abs(point.
x() - center_.
x()) - half_length_;
91 const double dy = std::abs(point.
y() - center_.
y()) - half_width_;
93 return std::max(0.0, dy);
107 return std::max(0.0, dy);
112 return hypot(dx, dy);
116 return std::abs(box.
center_x() - center_.
x()) <=
118 std::abs(box.
center_y() - center_.
y()) <=
125 const double x1 = std::min(
min_x(), other_box.
min_x());
126 const double x2 = std::max(
max_x(), other_box.
max_x());
127 const double y1 = std::min(
min_y(), other_box.
min_y());
128 const double y2 = std::max(
max_y(), other_box.
max_y());
129 center_ =
Vec2d((x1 + x2) / 2.0, (y1 + y2) / 2.0);
132 half_length_ = length_ / 2.0;
133 half_width_ = width_ / 2.0;
137 const double x1 = std::min(
min_x(), other_point.
x());
138 const double x2 = std::max(
max_x(), other_point.
x());
139 const double y1 = std::min(
min_y(), other_point.
y());
140 const double y2 = std::max(
max_y(), other_point.
y());
141 center_ =
Vec2d((x1 + x2) / 2.0, (y1 + y2) / 2.0);
144 half_length_ = length_ / 2.0;
145 half_width_ = width_ / 2.0;
149 return absl::StrCat(
"aabox2d ( center = ", center_.
DebugString(),
150 " length = ", length_,
" width = ", width_,
" )");
Defines the AABox2d class.
Implements a class of (undirected) axes-aligned bounding boxes in 2-D.
double max_y() const
Returns the maximum y-coordinate of the box
double min_x() const
Returns the minimum x-coordinate of the box
double min_y() const
Returns the minimum y-coordinate of the box
void MergeFrom(const AABox2d &other_box)
Changes box to include another given box, as well as the current one.
double center_y() const
Getter of y-component of center_
double half_length() const
Getter of half_length_
std::string DebugString() const
Gets a human-readable debug string
bool IsPointOnBoundary(const Vec2d &point) const
Determines whether a given point is on the boundary of the box.
bool HasOverlap(const AABox2d &box) const
Determines whether two boxes overlap.
double half_width() const
Getter of half_width_
double center_x() const
Getter of x-component of center_
void Shift(const Vec2d &shift_vec)
Shift the center of AABox by the input vector.
bool IsPointIn(const Vec2d &point) const
Determines whether a given point is in the box.
double DistanceTo(const Vec2d &point) const
Determines the distance between a point and the box.
AABox2d()=default
Default constructor.
double max_x() const
Returns the maximum x-coordinate of the box
void GetAllCorners(std::vector< Vec2d > *const corners) const
Gets all corners in counter clockwise order.
Implements a class of 2-dimensional vectors.
std::string DebugString() const
Returns a human-readable string representing this object
double y() const
Getter for y component
double x() const
Getter for x component
Math-related util functions.
constexpr double kMathEpsilon