/Users/enrico/Ricerca/develop/PINS/pins-mechatronix/LibSources/submodules/Clothoids/src/Clothoids/BBox.hxx Source File

Clothoids: /Users/enrico/Ricerca/develop/PINS/pins-mechatronix/LibSources/submodules/Clothoids/src/Clothoids/BBox.hxx Source File
Clothoids
BBox.hxx
1/*--------------------------------------------------------------------------*\
2 | |
3 | Copyright (C) 2018 |
4 | |
5 | , __ , __ |
6 | /|/ \ /|/ \ |
7 | | __/ _ ,_ | __/ _ ,_ |
8 | | \|/ / | | | | \|/ / | | | |
9 | |(__/|__/ |_/ \_/|/|(__/|__/ |_/ \_/|/ |
10 | /| /| |
11 | \| \| |
12 | |
13 | Paolo Bevilacqua and Enrico Bertolazzi |
14 | |
15 | (1) Dipartimento di Ingegneria e Scienza dell'Informazione |
16 | (2) Dipartimento di Ingegneria Industriale |
17 | |
18 | Universita` degli Studi di Trento |
19 | email: paolo.bevilacqua@unitn.it |
20 | email: enrico.bertolazzi@unitn.it |
21 | |
22\*--------------------------------------------------------------------------*/
23
27
28namespace G2lib {
29
30 using std::setw;
31 using std::vector;
32 using std::pair;
33
34 using std::make_shared;
35 using std::shared_ptr; // promemoria shared_ptr<Foo>(&foo, [](void*){});
36
37 /*\
38 | ____ ____
39 | | __ )| __ ) _____ __
40 | | _ \| _ \ / _ \ \/ /
41 | | |_) | |_) | (_) > <
42 | |____/|____/ \___/_/\_\
43 \*/
47 class BBox {
48 public:
49 using PtrBBox = shared_ptr<BBox const>;
50 using PairPtrBBox = pair<PtrBBox,PtrBBox>;
51 using VecPtrBBox = vector<PtrBBox>;
52 using VecPairPtrBBox = vector<PairPtrBBox>;
53
54 private:
55 real_type m_bbox[4]{0,0,0,0};
56 integer m_id{0};
57 integer m_ipos{0};
58
59 BBox();
60
61 BBox( BBox const & ) = default;
62 BBox( BBox && ) = default;
63
64 public:
65
77 real_type xmin,
78 real_type ymin,
79 real_type xmax,
80 real_type ymax,
81 integer id,
82 integer ipos
83 ) {
84 m_bbox[0] = xmin;
85 m_bbox[1] = ymin;
86 m_bbox[2] = xmax;
87 m_bbox[3] = ymax;
88 m_id = id;
89 m_ipos = ipos;
90 }
91
100 real_type const bbox[4],
101 integer id,
102 integer ipos
103 ) {
104 std::copy_n( bbox, 4, m_bbox );
105 m_id = id;
106 m_ipos = ipos;
107 }
108
118 real_type const bbox_min[2],
119 real_type const bbox_max[2],
120 integer id,
121 integer ipos
122 ) {
123 std::copy_n( bbox_min, 2, m_bbox );
124 std::copy_n( bbox_max, 2, m_bbox+2 );
125 m_id = id;
126 m_ipos = ipos;
127 }
128
137 vector<PtrBBox> const & bboxes,
138 integer id,
139 integer ipos
140 ) {
141 m_id = id;
142 m_ipos = ipos;
143 this -> join( bboxes );
144 }
145
146 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147
148 real_type const * bbox() { return m_bbox; }
149 real_type const * bbox_min() { return m_bbox; }
150 real_type const * bbox_max() { return m_bbox+2; }
151
152 real_type & x_min() { return m_bbox[0]; }
153 real_type & y_min() { return m_bbox[1]; }
154 real_type & x_max() { return m_bbox[2]; }
155 real_type & y_max() { return m_bbox[3]; }
156
157 real_type const & x_min() const { return m_bbox[0]; }
158 real_type const & y_min() const { return m_bbox[1]; }
159 real_type const & x_max() const { return m_bbox[2]; }
160 real_type const & y_max() const { return m_bbox[3]; }
161
162 integer const & Id() const { return m_id; }
163 integer const & Ipos() const { return m_ipos; }
164
168 BBox const &
169 operator = ( BBox const & rhs ) {
170 std::copy_n( rhs.m_bbox, 4, m_bbox );
171 m_id = rhs.m_id;
172 m_ipos = rhs.m_ipos;
173 return *this;
174 }
175
179 bool
180 collision( BBox const & box ) const {
181 return !( (box.x_min() > this->x_max() ) ||
182 (box.x_max() < this->x_min() ) ||
183 (box.y_min() > this->y_max() ) ||
184 (box.y_max() < this->y_min() ) );
185 }
186
190 void
191 join( vector<PtrBBox> const & bboxes );
192
197 distance( real_type x, real_type y ) const;
198
203 max_distance( real_type x, real_type y ) const;
204
208 void print( ostream_type & stream ) const;
209
210 };
211
212 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
220 inline
222 operator << ( ostream_type & stream, BBox const & bb ) {
223 bb.print(stream);
224 return stream;
225 }
226
227}
228
Definition BBox.hxx:47
BBox const & operator=(BBox const &rhs)
Definition BBox.hxx:169
integer const & Ipos() const
return BBOX position
Definition BBox.hxx:163
real_type const & y_max() const
y-maximum coordinate of the bbox
Definition BBox.hxx:160
bool collision(BBox const &box) const
Definition BBox.hxx:180
real_type & y_max()
y-maximum coordinate of the bbox
Definition BBox.hxx:155
BBox(real_type const bbox[4], integer id, integer ipos)
Definition BBox.hxx:99
BBox(real_type xmin, real_type ymin, real_type xmax, real_type ymax, integer id, integer ipos)
Definition BBox.hxx:76
void print(ostream_type &stream) const
Definition BBox.cc:122
real_type & x_min()
x-minimum coordinate of the bbox
Definition BBox.hxx:152
BBox(real_type const bbox_min[2], real_type const bbox_max[2], integer id, integer ipos)
Definition BBox.hxx:117
real_type const & x_max() const
x-maximum coordinate of the bbox
Definition BBox.hxx:159
real_type max_distance(real_type x, real_type y) const
Definition BBox.cc:113
real_type const & x_min() const
x-minimum coordinate of the bbox
Definition BBox.hxx:157
real_type & y_min()
y-minimum coordinate of the bbox
Definition BBox.hxx:153
real_type & x_max()
x-maximum coordinate of the bbox
Definition BBox.hxx:154
real_type const & y_min() const
y-minimum coordinate of the bbox
Definition BBox.hxx:158
real_type distance(real_type x, real_type y) const
Definition BBox.cc:78
void join(vector< PtrBBox > const &bboxes)
Definition BBox.cc:57
BBox(vector< PtrBBox > const &bboxes, integer id, integer ipos)
Definition BBox.hxx:136
integer const & Id() const
return BBOX id
Definition BBox.hxx:162
Definition BBox.cc:42
std::basic_ostream< char > ostream_type
output streaming
Definition Clothoids.hh:78
ostream_type & operator<<(ostream_type &stream, Biarc const &bi)
Definition Biarc.cc:1013
double real_type
real type number
Definition Clothoids.hh:79
int integer
integer type number
Definition Clothoids.hh:80