Apollo  6.0
Open source self driving car software
rect2d.h
Go to the documentation of this file.
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 
17 #pragma once
18 
19 #include "Eigen/Core"
20 
21 namespace apollo {
22 namespace localization {
23 namespace msf {
24 
25 template <typename T>
26 class Rect2D {
27  public:
29  Rect2D();
31  Rect2D(T min_x, T min_y, T max_x, T max_y);
33  Rect2D(const Rect2D<T>& ref);
35  Rect2D<T>& operator=(const Rect2D<T>& ref);
37  T GetMinX() const;
39  T GetMinY() const;
41  T GetMaxX() const;
43  T GetMaxY() const;
45  Eigen::Matrix<T, 2, 1> GetLeftTopCorner() const;
47  Eigen::Matrix<T, 2, 1> GetRightBottomCorner() const;
48 
49  private:
51  Eigen::Matrix<T, 4, 1, Eigen::DontAlign> _data;
52 };
53 
54 template <typename T>
56 
57 template <typename T>
58 Rect2D<T>::Rect2D(T min_x, T min_y, T max_x, T max_y)
59  : _data(min_x, min_y, max_x, max_y) {}
60 
61 template <typename T>
63  _data = ref._data;
64 }
65 
66 template <typename T>
68  _data = ref._data;
69  return *this;
70 }
71 
72 template <typename T>
73 T Rect2D<T>::GetMinX() const {
74  return _data(0);
75 }
76 
77 template <typename T>
78 T Rect2D<T>::GetMinY() const {
79  return _data(1);
80 }
81 
82 template <typename T>
83 T Rect2D<T>::GetMaxX() const {
84  return _data(2);
85 }
86 
87 template <typename T>
88 T Rect2D<T>::GetMaxY() const {
89  return _data(3);
90 }
91 
92 template <typename T>
93 Eigen::Matrix<T, 2, 1> Rect2D<T>::GetLeftTopCorner() const {
94  Eigen::Matrix<T, 2, 1> corner;
95  corner(0) = _data(0);
96  corner(1) = _data(1);
97  return corner;
98 }
99 
100 template <typename T>
101 Eigen::Matrix<T, 2, 1> Rect2D<T>::GetRightBottomCorner() const {
102  Eigen::Matrix<T, 2, 1> corner;
103  corner(0) = _data(2);
104  corner(1) = _data(3);
105  return corner;
106 }
107 
108 } // namespace msf
109 } // namespace localization
110 } // namespace apollo
T GetMinY() const
Get the min y of the rectangle.
Definition: rect2d.h:78
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
T GetMaxY() const
Get the max y of the rectangle.
Definition: rect2d.h:88
Eigen::Matrix< T, 2, 1 > GetRightBottomCorner() const
Get the right bottom corner of the rectangle.
Definition: rect2d.h:101
Rect2D()
Definition: rect2d.h:55
T GetMaxX() const
Get the max x of the rectangle.
Definition: rect2d.h:83
T GetMinX() const
Get the min x of the rectangle.
Definition: rect2d.h:73
Rect2D< T > & operator=(const Rect2D< T > &ref)
Overloading the operator =.
Definition: rect2d.h:67
Definition: rect2d.h:26
Eigen::Matrix< T, 2, 1 > GetLeftTopCorner() const
Get the left top corner of the rectangle.
Definition: rect2d.h:93