Apollo 10.0
自动驾驶开放平台
apollo::common::math::AABox2d类 参考

Implements a class of (undirected) axes-aligned bounding boxes in 2-D. 更多...

#include <aabox2d.h>

apollo::common::math::AABox2d 的协作图:

Public 成员函数

 AABox2d ()=default
 Default constructor.
 
 AABox2d (const Vec2d &center, const double length, const double width)
 Parameterized constructor.
 
 AABox2d (const Vec2d &one_corner, const Vec2d &opposite_corner)
 Parameterized constructor.
 
 AABox2d (const std::vector< Vec2d > &points)
 Parameterized constructor.
 
const Vec2dcenter () const
 Getter of center_
 
double center_x () const
 Getter of x-component of center_
 
double center_y () const
 Getter of y-component of center_
 
double length () const
 Getter of length_
 
double width () const
 Getter of width_
 
double half_length () const
 Getter of half_length_
 
double half_width () const
 Getter of half_width_
 
double area () const
 Getter of length_*width_
 
double min_x () const
 Returns the minimum x-coordinate of the box
 
double max_x () const
 Returns the maximum x-coordinate of the box
 
double min_y () const
 Returns the minimum y-coordinate of the box
 
double max_y () const
 Returns the maximum y-coordinate of the box
 
void GetAllCorners (std::vector< Vec2d > *const corners) const
 Gets all corners in counter clockwise order.
 
bool IsPointIn (const Vec2d &point) const
 Determines whether a given point is in the box.
 
bool IsPointOnBoundary (const Vec2d &point) const
 Determines whether a given point is on the boundary of the box.
 
double DistanceTo (const Vec2d &point) const
 Determines the distance between a point and the box.
 
double DistanceTo (const AABox2d &box) const
 Determines the distance between two boxes.
 
bool HasOverlap (const AABox2d &box) const
 Determines whether two boxes overlap.
 
void Shift (const Vec2d &shift_vec)
 Shift the center of AABox by the input vector.
 
void MergeFrom (const AABox2d &other_box)
 Changes box to include another given box, as well as the current one.
 
void MergeFrom (const Vec2d &other_point)
 Changes box to include a given point, as well as the current box.
 
std::string DebugString () const
 Gets a human-readable debug string
 

详细描述

Implements a class of (undirected) axes-aligned bounding boxes in 2-D.

This class is referential-agnostic.

在文件 aabox2d.h42 行定义.

构造及析构函数说明

◆ AABox2d() [1/4]

apollo::common::math::AABox2d::AABox2d ( )
default

Default constructor.

Creates an axes-aligned box with zero length and width at the origin.

◆ AABox2d() [2/4]

apollo::common::math::AABox2d::AABox2d ( const Vec2d center,
const double  length,
const double  width 
)

Parameterized constructor.

Creates an axes-aligned box with given center, length, and width.

参数
centerThe center of the box
lengthThe size of the box along the x-axis
widthThe size of the box along the y-axis

在文件 aabox2d.cc31 行定义.

32 : center_(center),
33 length_(length),
34 width_(width),
35 half_length_(length / 2.0),
36 half_width_(width / 2.0) {
37 CHECK_GT(length_, -kMathEpsilon);
38 CHECK_GT(width_, -kMathEpsilon);
39}
const Vec2d & center() const
Getter of center_
Definition aabox2d.h:75
double length() const
Getter of length_
Definition aabox2d.h:93
double width() const
Getter of width_
Definition aabox2d.h:99
constexpr double kMathEpsilon
Definition vec2d.h:35

◆ AABox2d() [3/4]

apollo::common::math::AABox2d::AABox2d ( const Vec2d one_corner,
const Vec2d opposite_corner 
)

Parameterized constructor.

Creates an axes-aligned box from two opposite corners.

参数
one_cornerOne corner of the box
opposite_cornerThe opposite corner to the first one

在文件 aabox2d.cc41 行定义.

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())) {}
AABox2d()=default
Default constructor.

◆ AABox2d() [4/4]

apollo::common::math::AABox2d::AABox2d ( const std::vector< Vec2d > &  points)
explicit

Parameterized constructor.

Creates an axes-aligned box containing all points in a given vector.

参数
pointsVector of points to be included inside the box.

在文件 aabox2d.cc46 行定义.

46 {
47 ACHECK(!points.empty());
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) {
53 min_x = std::min(min_x, point.x());
54 max_x = std::max(max_x, point.x());
55 min_y = std::min(min_y, point.y());
56 max_y = std::max(max_y, point.y());
57 }
58
59 center_ = {(min_x + max_x) / 2.0, (min_y + max_y) / 2.0};
60 length_ = max_x - min_x;
61 width_ = max_y - min_y;
62 half_length_ = length_ / 2.0;
63 half_width_ = width_ / 2.0;
64}
double max_y() const
Returns the maximum y-coordinate of the box
Definition aabox2d.h:145
double min_x() const
Returns the minimum x-coordinate of the box
Definition aabox2d.h:124
double min_y() const
Returns the minimum y-coordinate of the box
Definition aabox2d.h:138
double max_x() const
Returns the maximum x-coordinate of the box
Definition aabox2d.h:131
#define ACHECK(cond)
Definition log.h:80

成员函数说明

◆ area()

double apollo::common::math::AABox2d::area ( ) const
inline

Getter of length_*width_

返回
The area of the box

在文件 aabox2d.h117 行定义.

117{ return length_ * width_; }

◆ center()

const Vec2d & apollo::common::math::AABox2d::center ( ) const
inline

Getter of center_

返回
Center of the box

在文件 aabox2d.h75 行定义.

75{ return center_; }

◆ center_x()

double apollo::common::math::AABox2d::center_x ( ) const
inline

Getter of x-component of center_

返回
x-component of the center of the box

在文件 aabox2d.h81 行定义.

81{ return center_.x(); }
double x() const
Getter for x component
Definition vec2d.h:54

◆ center_y()

double apollo::common::math::AABox2d::center_y ( ) const
inline

Getter of y-component of center_

返回
y-component of the center of the box

在文件 aabox2d.h87 行定义.

87{ return center_.y(); }
double y() const
Getter for y component
Definition vec2d.h:57

◆ DebugString()

std::string apollo::common::math::AABox2d::DebugString ( ) const

Gets a human-readable debug string

返回
A string

在文件 aabox2d.cc148 行定义.

148 {
149 return absl::StrCat("aabox2d ( center = ", center_.DebugString(),
150 " length = ", length_, " width = ", width_, " )");
151}
std::string DebugString() const
Returns a human-readable string representing this object
Definition vec2d.cc:125

◆ DistanceTo() [1/2]

double apollo::common::math::AABox2d::DistanceTo ( const AABox2d box) const

Determines the distance between two boxes.

参数
boxAnother box.

在文件 aabox2d.cc101 行定义.

101 {
102 const double dx =
103 std::abs(box.center_x() - center_.x()) - box.half_length() - half_length_;
104 const double dy =
105 std::abs(box.center_y() - center_.y()) - box.half_width() - half_width_;
106 if (dx <= 0.0) {
107 return std::max(0.0, dy);
108 }
109 if (dy <= 0.0) {
110 return dx;
111 }
112 return hypot(dx, dy);
113}

◆ DistanceTo() [2/2]

double apollo::common::math::AABox2d::DistanceTo ( const Vec2d point) const

Determines the distance between a point and the box.

参数
pointThe point whose distance to the box we wish to determine.

在文件 aabox2d.cc89 行定义.

89 {
90 const double dx = std::abs(point.x() - center_.x()) - half_length_;
91 const double dy = std::abs(point.y() - center_.y()) - half_width_;
92 if (dx <= 0.0) {
93 return std::max(0.0, dy);
94 }
95 if (dy <= 0.0) {
96 return dx;
97 }
98 return hypot(dx, dy);
99}

◆ GetAllCorners()

void apollo::common::math::AABox2d::GetAllCorners ( std::vector< Vec2d > *const  corners) const

Gets all corners in counter clockwise order.

参数
cornersOutput where the corners are written

在文件 aabox2d.cc66 行定义.

66 {
67 CHECK_NOTNULL(corners)->clear();
68 corners->reserve(4);
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_);
73}

◆ half_length()

double apollo::common::math::AABox2d::half_length ( ) const
inline

Getter of half_length_

返回
Half of the length of the box

在文件 aabox2d.h105 行定义.

105{ return half_length_; }

◆ half_width()

double apollo::common::math::AABox2d::half_width ( ) const
inline

Getter of half_width_

返回
Half of the width of the box

在文件 aabox2d.h111 行定义.

111{ return half_width_; }

◆ HasOverlap()

bool apollo::common::math::AABox2d::HasOverlap ( const AABox2d box) const

Determines whether two boxes overlap.

参数
boxAnother box

在文件 aabox2d.cc115 行定义.

115 {
116 return std::abs(box.center_x() - center_.x()) <=
117 box.half_length() + half_length_ &&
118 std::abs(box.center_y() - center_.y()) <=
119 box.half_width() + half_width_;
120}

◆ IsPointIn()

bool apollo::common::math::AABox2d::IsPointIn ( const Vec2d point) const

Determines whether a given point is in the box.

参数
pointThe point we wish to test for containment in the box

在文件 aabox2d.cc75 行定义.

75 {
76 return std::abs(point.x() - center_.x()) <= half_length_ + kMathEpsilon &&
77 std::abs(point.y() - center_.y()) <= half_width_ + kMathEpsilon;
78}

◆ IsPointOnBoundary()

bool apollo::common::math::AABox2d::IsPointOnBoundary ( const Vec2d point) const

Determines whether a given point is on the boundary of the box.

参数
pointThe point we wish to test for boundary membership

在文件 aabox2d.cc80 行定义.

80 {
81 const double dx = std::abs(point.x() - center_.x());
82 const double dy = std::abs(point.y() - center_.y());
83 return (std::abs(dx - half_length_) <= kMathEpsilon &&
84 dy <= half_width_ + kMathEpsilon) ||
85 (std::abs(dy - half_width_) <= kMathEpsilon &&
86 dx <= half_length_ + kMathEpsilon);
87}

◆ length()

double apollo::common::math::AABox2d::length ( ) const
inline

Getter of length_

返回
The length of the box

在文件 aabox2d.h93 行定义.

93{ return length_; }

◆ max_x()

double apollo::common::math::AABox2d::max_x ( ) const
inline

Returns the maximum x-coordinate of the box

返回
x-coordinate

在文件 aabox2d.h131 行定义.

131{ return center_.x() + half_length_; }

◆ max_y()

double apollo::common::math::AABox2d::max_y ( ) const
inline

Returns the maximum y-coordinate of the box

返回
y-coordinate

在文件 aabox2d.h145 行定义.

145{ return center_.y() + half_width_; }

◆ MergeFrom() [1/2]

void apollo::common::math::AABox2d::MergeFrom ( const AABox2d other_box)

Changes box to include another given box, as well as the current one.

参数
other_boxAnother box

在文件 aabox2d.cc124 行定义.

124 {
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);
130 length_ = x2 - x1;
131 width_ = y2 - y1;
132 half_length_ = length_ / 2.0;
133 half_width_ = width_ / 2.0;
134}

◆ MergeFrom() [2/2]

void apollo::common::math::AABox2d::MergeFrom ( const Vec2d other_point)

Changes box to include a given point, as well as the current box.

参数
other_pointAnother point

在文件 aabox2d.cc136 行定义.

136 {
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);
142 length_ = x2 - x1;
143 width_ = y2 - y1;
144 half_length_ = length_ / 2.0;
145 half_width_ = width_ / 2.0;
146}

◆ min_x()

double apollo::common::math::AABox2d::min_x ( ) const
inline

Returns the minimum x-coordinate of the box

返回
x-coordinate

在文件 aabox2d.h124 行定义.

124{ return center_.x() - half_length_; }

◆ min_y()

double apollo::common::math::AABox2d::min_y ( ) const
inline

Returns the minimum y-coordinate of the box

返回
y-coordinate

在文件 aabox2d.h138 行定义.

138{ return center_.y() - half_width_; }

◆ Shift()

void apollo::common::math::AABox2d::Shift ( const Vec2d shift_vec)

Shift the center of AABox by the input vector.

参数
shift_vecThe vector by which we wish to shift the box

在文件 aabox2d.cc122 行定义.

122{ center_ += shift_vec; }

◆ width()

double apollo::common::math::AABox2d::width ( ) const
inline

Getter of width_

返回
The width of the box

在文件 aabox2d.h99 行定义.

99{ return width_; }

该类的文档由以下文件生成: