KiCad PCB EDA Suite
bbox_2d.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 <[email protected]>
5  * Copyright (C) 1992-2020 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 _BBOX_2D_H_
31 #define _BBOX_2D_H_
32 
33 #include <plugins/3dapi/xv3d_types.h> // SFVEC2F
34 
35 struct RAY2D;
36 struct RAYSEG2D;
37 
41 struct BBOX_2D
42 {
43 public:
44 
48  BBOX_2D();
49 
55  explicit BBOX_2D( const SFVEC2F& aPbInit );
56 
63  BBOX_2D( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax );
64 
65  ~BBOX_2D();
66 
67 
74  void Set( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax );
75 
81  void Set( const BBOX_2D& aBBox );
82 
88  void Union( const SFVEC2F& aPoint );
89 
95  void Union( const BBOX_2D& aBBox );
96 
102  void Scale( float aScale );
103 
107  void ScaleNextUp();
108 
112  void ScaleNextDown();
113 
119  bool Intersects( const BBOX_2D& aBBox ) const;
120 
126  bool Intersects( const SFVEC2F& aCenter, float aRadiusSquared ) const;
127 
133  bool Inside( const SFVEC2F& aPoint ) const;
134 
140  float Area() const;
141 
147  bool IsInitialized() const;
148 
152  void Reset();
153 
157  SFVEC2F GetCenter() const;
158 
162  SFVEC2F GetExtent() const;
163 
167  const SFVEC2F& Min() const { return m_min; }
168 
172  const SFVEC2F& Max() const { return m_max; }
173 
174 
178  unsigned int MaxDimension() const;
179 
183  float Perimeter() const;
184 
190  bool Intersect( const RAY2D& aRay, float* t ) const;
191 
192  bool Intersect( const RAY2D& aRay, float* aOutHitT0, float* aOutHitT1 ) const;
193 
194  bool Intersect( const RAYSEG2D& aRaySeg ) const;
195 
196 private:
199 };
200 
201 #endif // bbox_2d.h
BBOX_2D()
Create with default values a bounding box (not initialized).
Definition: bbox_2d.cpp:37
SFVEC2F m_min
point of the lower position of the bounding box
Definition: bbox_2d.h:197
SFVEC2F GetExtent() const
Definition: bbox_2d.cpp:125
SFVEC2F GetCenter() const
Definition: bbox_2d.cpp:119
void Set(const SFVEC2F &aPbMin, const SFVEC2F &aPbMax)
Set bounding box with new parameters.
Definition: bbox_2d.cpp:61
bool Inside(const SFVEC2F &aPoint) const
Check is a point is inside this bounding box.
Definition: bbox_2d.cpp:223
const SFVEC2F & Max() const
Definition: bbox_2d.h:172
~BBOX_2D()
Definition: bbox_2d.cpp:56
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
void Reset()
Reset the bounding box to zero and uninitialize it.
Definition: bbox_2d.cpp:86
void Scale(float aScale)
Scale a bounding box by its center.
Definition: bbox_2d.cpp:150
void ScaleNextDown()
Scale a bounding box to the next float representation making it smaller.
Definition: bbox_2d.cpp:172
Manage a bounding box defined by two SFVEC2F min max points.
Definition: bbox_2d.h:41
bool Intersect(const RAY2D &aRay, float *t) const
Definition: bbox_2d.cpp:240
void Union(const SFVEC2F &aPoint)
Recalculate the bounding box adding a point.
Definition: bbox_2d.cpp:93
const SFVEC2F & Min() const
Definition: bbox_2d.h:167
Definition: ray.h:93
unsigned int MaxDimension() const
Definition: bbox_2d.cpp:131
float Area() const
Calculate the area of a bounding box.
Definition: bbox_2d.cpp:232
bool Intersects(const BBOX_2D &aBBox) const
Test if a bounding box intersects this box.
Definition: bbox_2d.cpp:211
void ScaleNextUp()
Scale a bounding box to the next float representation making it larger.
Definition: bbox_2d.cpp:162
SFVEC2F m_max
point of the higher position of the bounding box
Definition: bbox_2d.h:198
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_2d.cpp:79
float Perimeter() const
Definition: bbox_2d.cpp:142
Definition: ray.h:105