KiCad PCB EDA Suite
cbbox2d.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #ifndef _CBBOX2D_H_
31 #define _CBBOX2D_H_
32 
33 #include "../ray.h"
34 
35 
40 struct CBBOX2D
41 {
42 
43 public:
44 
49  CBBOX2D();
50 
56  explicit CBBOX2D( const SFVEC2F &aPbInit );
57 
64  CBBOX2D( const SFVEC2F &aPbMin, const SFVEC2F &aPbMax );
65 
66  ~CBBOX2D();
67 
68 
75  void Set( const SFVEC2F &aPbMin, const SFVEC2F &aPbMax );
76 
82  void Set( const CBBOX2D &aBBox );
83 
89  void Union( const SFVEC2F &aPoint );
90 
96  void Union( const CBBOX2D &aBBox );
97 
103  void Scale( float aScale );
104 
109  void ScaleNextUp();
110 
115  void ScaleNextDown();
116 
122  bool Intersects( const CBBOX2D &aBBox ) const;
123 
129  bool Intersects( const SFVEC2F &aCenter, float aRadiusSquared ) const;
130 
136  bool Inside( const SFVEC2F &aPoint ) const;
137 
143  float Area() const;
144 
150  bool IsInitialized() const;
151 
156  void Reset();
157 
163  SFVEC2F GetCenter() const;
164 
169  SFVEC2F GetExtent() const;
170 
176  const SFVEC2F &Min() const { return m_min; }
177 
183  const SFVEC2F &Max() const { return m_max; }
184 
185 
190  unsigned int MaxDimension() const;
191 
196  float Perimeter() const;
197 
204  bool Intersect( const RAY2D &aRay, float *t ) const;
205 
206  bool Intersect( const RAY2D &aRay, float *aOutHitT0, float *aOutHitT1 ) const;
207 
208  bool Intersect( const RAYSEG2D &aRaySeg ) const;
209 
210 private:
213 };
214 
215 #endif // CBBox2d_h
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox2d.cpp:79
void Union(const SFVEC2F &aPoint)
Function Union recalculate the bounding box adding a point.
Definition: cbbox2d.cpp:95
float Perimeter() const
Function Perimeter.
Definition: cbbox2d.cpp:144
CBBOX2D()
Constructor CBBOX2D Create with default values a bounding box (not inizialized)
Definition: cbbox2d.cpp:37
void ScaleNextDown()
Function ScaleNextDown scales a bounding box to the next float representation making it smaller...
Definition: cbbox2d.cpp:174
Class CBBOX manages a bounding box defined by two SFVEC2F min max points.
Definition: cbbox2d.h:40
bool Intersects(const CBBOX2D &aBBox) const
Function Intersects test if a bounding box intersects this box.
Definition: cbbox2d.cpp:213
void Reset()
Function Reset reset the bounding box to zero and de-initialized it.
Definition: cbbox2d.cpp:88
SFVEC2F m_max
point of the higher position of the bounding box
Definition: cbbox2d.h:212
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
void Scale(float aScale)
Function Scale scales a bounding box by its center.
Definition: cbbox2d.cpp:152
void Set(const SFVEC2F &aPbMin, const SFVEC2F &aPbMax)
Function Set Set bounding box with new parameters.
Definition: cbbox2d.cpp:61
float Area() const
Function Area calculate the area of a bounding box.
Definition: cbbox2d.cpp:234
~CBBOX2D()
Definition: cbbox2d.cpp:56
void ScaleNextUp()
Function ScaleNextUp scales a bounding box to the next float representation making it larger...
Definition: cbbox2d.cpp:164
SFVEC2F GetCenter() const
Function GetCenter return the center point of the bounding box.
Definition: cbbox2d.cpp:121
Definition: ray.h:74
SFVEC2F m_min
point of the lower position of the bounding box
Definition: cbbox2d.h:211
unsigned int MaxDimension() const
Function MaxDimension.
Definition: cbbox2d.cpp:133
bool Inside(const SFVEC2F &aPoint) const
Function Inside check is a point is inside this bounding box.
Definition: cbbox2d.cpp:225
const SFVEC2F & Min() const
Function Min return the minimun vertex pointer.
Definition: cbbox2d.h:176
SFVEC2F GetExtent() const
Function GetExtent.
Definition: cbbox2d.cpp:127
const SFVEC2F & Max() const
Function Max return the maximum vertex pointer.
Definition: cbbox2d.h:183
bool Intersect(const RAY2D &aRay, float *t) const
Function Intersect.
Definition: cbbox2d.cpp:242
Definition: ray.h:86