QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
3d
qgsaabb.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsaabb.cpp
3
--------------------------------------
4
Date : July 2017
5
Copyright : (C) 2017 by Martin Dobias
6
Email : wonder dot sk at gmail dot com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#include "
qgsaabb.h
"
17
18
#include <QString>
19
20
using namespace
Qt::StringLiterals;
21
22
QgsAABB::QgsAABB
(
float
xMin
,
float
yMin
,
float
zMin
,
float
xMax
,
float
yMax
,
float
zMax
)
23
:
xMin
(
xMin
)
24
,
yMin
(
yMin
)
25
,
zMin
(
zMin
)
26
,
xMax
(
xMax
)
27
,
yMax
(
yMax
)
28
,
zMax
(
zMax
)
29
{
30
// normalize coords
31
if
( this->
xMax < this->
xMin )
32
std::swap( this->xMin, this->xMax );
33
if
( this->
yMax < this->
yMin )
34
std::swap( this->yMin, this->yMax );
35
if
( this->
zMax < this->
zMin )
36
std::swap( this->zMin, this->zMax );
37
}
38
39
bool
QgsAABB::intersects
(
const
QgsAABB
&other )
const
40
{
41
return
xMin
< other.
xMax
&& other.
xMin
<
xMax
&&
yMin
< other.
yMax
&& other.
yMin
<
yMax
&&
zMin
< other.
zMax
&& other.
zMin
<
zMax
;
42
}
43
44
bool
QgsAABB::intersects
(
float
x,
float
y,
float
z )
const
45
{
46
return
xMin <= x && xMax >
= x &&
yMin <= y && yMax >
= y &&
zMin <= z && zMax >
= z;
47
}
48
49
50
float
QgsAABB::distanceFromPoint
(
float
x,
float
y,
float
z )
const
51
{
52
const
float
dx = std::max(
xMin
- x, std::max( 0.f, x -
xMax
) );
53
const
float
dy = std::max(
yMin
- y, std::max( 0.f, y -
yMax
) );
54
const
float
dz = std::max(
zMin
- z, std::max( 0.f, z -
zMax
) );
55
return
sqrt( dx * dx + dy * dy + dz * dz );
56
}
57
58
float
QgsAABB::distanceFromPoint
( QVector3D v )
const
59
{
60
return
distanceFromPoint
( v.x(), v.y(), v.z() );
61
}
62
63
QList<QVector3D>
QgsAABB::verticesForLines
()
const
64
{
65
QList<QVector3D> vertices;
66
for
(
int
i = 0; i < 2; ++i )
67
{
68
const
float
x = i ?
xMax
:
xMin
;
69
for
(
int
j = 0; j < 2; ++j )
70
{
71
const
float
y = j ?
yMax
:
yMin
;
72
for
(
int
k = 0; k < 2; ++k )
73
{
74
const
float
z = k ?
zMax
:
zMin
;
75
if
( i == 0 )
76
{
77
vertices.append( QVector3D(
xMin
, y, z ) );
78
vertices.append( QVector3D(
xMax
, y, z ) );
79
}
80
if
( j == 0 )
81
{
82
vertices.append( QVector3D( x,
yMin
, z ) );
83
vertices.append( QVector3D( x,
yMax
, z ) );
84
}
85
if
( k == 0 )
86
{
87
vertices.append( QVector3D( x, y,
zMin
) );
88
vertices.append( QVector3D( x, y,
zMax
) );
89
}
90
}
91
}
92
}
93
return
vertices;
94
}
95
96
QString
QgsAABB::toString
()
const
97
{
98
return
u
"X %1 - %2 Y %3 - %4 Z %5 - %6"
_s.arg(
xMin
).arg(
xMax
).arg(
yMin
).arg(
yMax
).arg(
zMin
).arg(
zMax
);
99
}
QgsAABB::yMax
float yMax
Definition
qgsaabb.h:104
QgsAABB::verticesForLines
QList< QVector3D > verticesForLines() const
Returns a list of pairs of vertices (useful for display of bounding boxes).
Definition
qgsaabb.cpp:63
QgsAABB::xMax
float xMax
Definition
qgsaabb.h:103
QgsAABB::toString
QString toString() const
Returns text representation of the bounding box.
Definition
qgsaabb.cpp:96
QgsAABB::xMin
float xMin
Definition
qgsaabb.h:100
QgsAABB::zMax
float zMax
Definition
qgsaabb.h:105
QgsAABB::intersects
bool intersects(const QgsAABB &other) const
Determines whether the box intersects some other axis aligned box.
Definition
qgsaabb.cpp:39
QgsAABB::yMin
float yMin
Definition
qgsaabb.h:101
QgsAABB::distanceFromPoint
float distanceFromPoint(float x, float y, float z) const
Returns shortest distance from the box to a point.
Definition
qgsaabb.cpp:50
QgsAABB::QgsAABB
QgsAABB()=default
Constructs bounding box with null coordinates.
QgsAABB::zMin
float zMin
Definition
qgsaabb.h:102
qgsaabb.h
Generated on
for QGIS API Documentation by
1.17.0