KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
35struct RAY2D;
36struct RAYSEG2D;
37
41struct BBOX_2D
42{
43public:
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
141 bool Inside( const BBOX_2D& aBBox ) const;
142
148 float Area() const;
149
155 bool IsInitialized() const;
156
160 void Reset();
161
165 SFVEC2F GetCenter() const;
166
170 SFVEC2F GetExtent() const;
171
175 const SFVEC2F& Min() const { return m_min; }
176
180 const SFVEC2F& Max() const { return m_max; }
181
182
186 unsigned int MaxDimension() const;
187
191 float Perimeter() const;
192
198 bool Intersect( const RAY2D& aRay, float* t ) const;
199
200 bool Intersect( const RAY2D& aRay, float* aOutHitT0, float* aOutHitT1 ) const;
201
202 bool Intersect( const RAYSEG2D& aRaySeg ) const;
203
204private:
207};
208
209#endif // bbox_2d.h
Manage a bounding box defined by two SFVEC2F min max points.
Definition: bbox_2d.h:42
float Perimeter() const
Definition: bbox_2d.cpp:142
SFVEC2F GetCenter() const
Definition: bbox_2d.cpp:119
bool Intersects(const BBOX_2D &aBBox) const
Test if a bounding box intersects this box.
Definition: bbox_2d.cpp:211
~BBOX_2D()
Definition: bbox_2d.cpp:56
unsigned int MaxDimension() const
Definition: bbox_2d.cpp:131
SFVEC2F m_min
point of the lower position of the bounding box
Definition: bbox_2d.h:205
void ScaleNextDown()
Scale a bounding box to the next float representation making it smaller.
Definition: bbox_2d.cpp:172
SFVEC2F GetExtent() const
Definition: bbox_2d.cpp:125
SFVEC2F m_max
point of the higher position of the bounding box
Definition: bbox_2d.h:206
void Union(const SFVEC2F &aPoint)
Recalculate the bounding box adding a point.
Definition: bbox_2d.cpp:93
void Scale(float aScale)
Scale a bounding box by its center.
Definition: bbox_2d.cpp:150
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_2d.cpp:79
const SFVEC2F & Min() const
Definition: bbox_2d.h:175
float Area() const
Calculate the area of a bounding box.
Definition: bbox_2d.cpp:242
bool Inside(const SFVEC2F &aPoint) const
Check is a point is inside this bounding box.
Definition: bbox_2d.cpp:223
BBOX_2D()
Create with default values a bounding box (not initialized).
Definition: bbox_2d.cpp:37
void Reset()
Reset the bounding box to zero and uninitialize it.
Definition: bbox_2d.cpp:86
const SFVEC2F & Max() const
Definition: bbox_2d.h:180
void Set(const SFVEC2F &aPbMin, const SFVEC2F &aPbMax)
Set bounding box with new parameters.
Definition: bbox_2d.cpp:61
void ScaleNextUp()
Scale a bounding box to the next float representation making it larger.
Definition: bbox_2d.cpp:162
bool Intersect(const RAY2D &aRay, float *t) const
Definition: bbox_2d.cpp:250
Definition: ray.h:94
Definition: ray.h:106
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42