Apollo 10.0
自动驾驶开放平台
aabox2d.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22#pragma once
23
24#include <string>
25#include <vector>
26
28
33namespace apollo {
34namespace common {
35namespace math {
36
42class AABox2d {
43 public:
48 AABox2d() = default;
56 AABox2d(const Vec2d &center, const double length, const double width);
63 AABox2d(const Vec2d &one_corner, const Vec2d &opposite_corner);
69 explicit AABox2d(const std::vector<Vec2d> &points);
70
75 const Vec2d &center() const { return center_; }
76
81 double center_x() const { return center_.x(); }
82
87 double center_y() const { return center_.y(); }
88
93 double length() const { return length_; }
94
99 double width() const { return width_; }
100
105 double half_length() const { return half_length_; }
106
111 double half_width() const { return half_width_; }
112
117 double area() const { return length_ * width_; }
118
124 double min_x() const { return center_.x() - half_length_; }
125
131 double max_x() const { return center_.x() + half_length_; }
132
138 double min_y() const { return center_.y() - half_width_; }
139
145 double max_y() const { return center_.y() + half_width_; }
146
152 void GetAllCorners(std::vector<Vec2d> *const corners) const;
153
159 bool IsPointIn(const Vec2d &point) const;
160
166 bool IsPointOnBoundary(const Vec2d &point) const;
167
173 double DistanceTo(const Vec2d &point) const;
174
180 double DistanceTo(const AABox2d &box) const;
181
187 bool HasOverlap(const AABox2d &box) const;
188
194 void Shift(const Vec2d &shift_vec);
195
202 void MergeFrom(const AABox2d &other_box);
203
209 void MergeFrom(const Vec2d &other_point);
210
216 std::string DebugString() const;
217
218 private:
219 Vec2d center_;
220 double length_ = 0.0;
221 double width_ = 0.0;
222 double half_length_ = 0.0;
223 double half_width_ = 0.0;
224};
225
226} // namespace math
227} // namespace common
228} // namespace apollo
Implements a class of (undirected) axes-aligned bounding boxes in 2-D.
Definition aabox2d.h:42
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
const Vec2d & center() const
Getter of center_
Definition aabox2d.h:75
void MergeFrom(const AABox2d &other_box)
Changes box to include another given box, as well as the current one.
Definition aabox2d.cc:124
double length() const
Getter of length_
Definition aabox2d.h:93
double center_y() const
Getter of y-component of center_
Definition aabox2d.h:87
double half_length() const
Getter of half_length_
Definition aabox2d.h:105
std::string DebugString() const
Gets a human-readable debug string
Definition aabox2d.cc:148
bool IsPointOnBoundary(const Vec2d &point) const
Determines whether a given point is on the boundary of the box.
Definition aabox2d.cc:80
bool HasOverlap(const AABox2d &box) const
Determines whether two boxes overlap.
Definition aabox2d.cc:115
double width() const
Getter of width_
Definition aabox2d.h:99
double half_width() const
Getter of half_width_
Definition aabox2d.h:111
double center_x() const
Getter of x-component of center_
Definition aabox2d.h:81
void Shift(const Vec2d &shift_vec)
Shift the center of AABox by the input vector.
Definition aabox2d.cc:122
bool IsPointIn(const Vec2d &point) const
Determines whether a given point is in the box.
Definition aabox2d.cc:75
double DistanceTo(const Vec2d &point) const
Determines the distance between a point and the box.
Definition aabox2d.cc:89
AABox2d()=default
Default constructor.
double max_x() const
Returns the maximum x-coordinate of the box
Definition aabox2d.h:131
double area() const
Getter of length_*width_
Definition aabox2d.h:117
void GetAllCorners(std::vector< Vec2d > *const corners) const
Gets all corners in counter clockwise order.
Definition aabox2d.cc:66
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
double y() const
Getter for y component
Definition vec2d.h:57
double x() const
Getter for x component
Definition vec2d.h:54
class register implement
Definition arena_queue.h:37
Defines the Vec2d class.