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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
25
26#ifndef _BBOX_2D_H_
27#define _BBOX_2D_H_
28
29#include <plugins/3dapi/xv3d_types.h> // SFVEC2F
30
31struct RAY2D;
32struct RAYSEG2D;
33
37struct BBOX_2D
38{
39public:
40
44 BBOX_2D();
45
51 explicit BBOX_2D( const SFVEC2F& aPbInit );
52
59 BBOX_2D( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax );
60
61 ~BBOX_2D();
62
63
70 void Set( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax );
71
77 void Set( const BBOX_2D& aBBox );
78
84 void Union( const SFVEC2F& aPoint );
85
91 void Union( const BBOX_2D& aBBox );
92
98 void Scale( float aScale );
99
103 void ScaleNextUp();
104
108 void ScaleNextDown();
109
115 bool Intersects( const BBOX_2D& aBBox ) const;
116
122 bool Intersects( const SFVEC2F& aCenter, float aRadiusSquared ) const;
123
129 bool Inside( const SFVEC2F& aPoint ) const;
130
137 bool Inside( const BBOX_2D& aBBox ) const;
138
144 float Area() const;
145
151 bool IsInitialized() const;
152
156 void Reset();
157
161 SFVEC2F GetCenter() const;
162
166 SFVEC2F GetExtent() const;
167
171 const SFVEC2F& Min() const { return m_min; }
172
176 const SFVEC2F& Max() const { return m_max; }
177
178
182 unsigned int MaxDimension() const;
183
187 float Perimeter() const;
188
194 bool Intersect( const RAY2D& aRay, float* t ) const;
195
196 bool Intersect( const RAY2D& aRay, float* aOutHitT0, float* aOutHitT1 ) const;
197
198 bool Intersect( const RAYSEG2D& aRaySeg ) const;
199
200private:
203};
204
205#endif // bbox_2d.h
float Perimeter() const
Definition bbox_2d.cpp:138
SFVEC2F GetCenter() const
Definition bbox_2d.cpp:115
bool Intersects(const BBOX_2D &aBBox) const
Test if a bounding box intersects this box.
Definition bbox_2d.cpp:207
~BBOX_2D()
Definition bbox_2d.cpp:52
unsigned int MaxDimension() const
Definition bbox_2d.cpp:127
SFVEC2F m_min
point of the lower position of the bounding box
Definition bbox_2d.h:201
void ScaleNextDown()
Scale a bounding box to the next float representation making it smaller.
Definition bbox_2d.cpp:168
SFVEC2F GetExtent() const
Definition bbox_2d.cpp:121
SFVEC2F m_max
point of the higher position of the bounding box
Definition bbox_2d.h:202
void Union(const SFVEC2F &aPoint)
Recalculate the bounding box adding a point.
Definition bbox_2d.cpp:89
void Scale(float aScale)
Scale a bounding box by its center.
Definition bbox_2d.cpp:146
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition bbox_2d.cpp:75
const SFVEC2F & Min() const
Definition bbox_2d.h:171
float Area() const
Calculate the area of a bounding box.
Definition bbox_2d.cpp:238
bool Inside(const SFVEC2F &aPoint) const
Check is a point is inside this bounding box.
Definition bbox_2d.cpp:219
BBOX_2D()
Create with default values a bounding box (not initialized).
Definition bbox_2d.cpp:33
void Reset()
Reset the bounding box to zero and uninitialize it.
Definition bbox_2d.cpp:82
const SFVEC2F & Max() const
Definition bbox_2d.h:176
void Set(const SFVEC2F &aPbMin, const SFVEC2F &aPbMax)
Set bounding box with new parameters.
Definition bbox_2d.cpp:57
void ScaleNextUp()
Scale a bounding box to the next float representation making it larger.
Definition bbox_2d.cpp:158
bool Intersect(const RAY2D &aRay, float *t) const
Definition bbox_2d.cpp:246
Definition ray.h:90
glm::vec2 SFVEC2F
Definition xv3d_types.h:38