Skip to content

Commit 0bacf0f

Browse files
lbartolettinyalldawson
authored andcommitted
- Add some methods in QgsVector3D
- Move QgsVector3D from 3d to core - Use QgsVector3D instead of QVector3D
1 parent 9d649e7 commit 0bacf0f

10 files changed

+264
-125
lines changed

python/core/core_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
%Include qgstestutils.sip
137137
%Include qgsziputils.sip
138138
%Include qgsvector.sip
139+
%Include qgsvector3d.sip
139140
%Include auth/qgsauthcertutils.sip
140141
%Include auth/qgsauthconfig.sip
141142
%Include auth/qgsauthmanager.sip

python/core/geometry/qgsgeometryutils.sip.in

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212

1313

14-
1514
class QgsGeometryUtils
1615
{
1716
%Docstring
@@ -493,8 +492,8 @@ Return the coefficients (a, b, c for equation "ax + by + c = 0") of a line defin
493492
%End
494493

495494

496-
static double skewLinesDistance( const QVector3D &P1, const QVector3D &P12,
497-
const QVector3D &P2, const QVector3D &P22 );
495+
static double skewLinesDistance( const QgsVector3D &P1, const QgsVector3D &P12,
496+
const QgsVector3D &P2, const QgsVector3D &P22 );
498497
%Docstring
499498
An algorithm to calculate the shortest distance between two skew lines.
500499

@@ -506,9 +505,9 @@ An algorithm to calculate the shortest distance between two skew lines.
506505
:return: the shortest distance
507506
%End
508507

509-
static bool skewLinesProjection( const QVector3D &P1, const QVector3D &P12,
510-
const QVector3D &P2, const QVector3D &P22,
511-
QVector3D &X1 /Out/,
508+
static bool skewLinesProjection( const QgsVector3D &P1, const QgsVector3D &P12,
509+
const QgsVector3D &P2, const QgsVector3D &P22,
510+
QgsVector3D &X1 /Out/,
512511
double epsilon = 0.0001 );
513512
%Docstring
514513
A method to project one skew line onto another.
@@ -522,9 +521,9 @@ A method to project one skew line onto another.
522521
:return: true if such point exists, false - otherwise.
523522
%End
524523

525-
static bool linesIntersection3D( const QVector3D &La1, const QVector3D &La2,
526-
const QVector3D &Lb1, const QVector3D &Lb2,
527-
QVector3D &intersection /Out/ );
524+
static bool linesIntersection3D( const QgsVector3D &La1, const QgsVector3D &La2,
525+
const QgsVector3D &Lb1, const QgsVector3D &Lb2,
526+
QgsVector3D &intersection /Out/ );
528527
%Docstring
529528
An algorithm to calculate an (approximate) intersection of two lines in 3D.
530529

@@ -538,28 +537,28 @@ An algorithm to calculate an (approximate) intersection of two lines in 3D.
538537
example:
539538
.. code-block:: python
540539

541-
QgsGeometryUtils.linesIntersection3D(QVector3D(0,0,0), QVector3D(5,0,0), QVector3D(2,1,0), QVector3D(2,3,0))
542-
# (True, PyQt5.QtGui.QVector3D(2.0, 0.0, 0.0))
543-
QgsGeometryUtils.linesIntersection3D(QVector3D(0,0,0), QVector3D(5,0,0), QVector3D(2,1,0), QVector3D(2,0,0))
544-
# (True, PyQt5.QtGui.QVector3D(2.0, 0.0, 0.0))
545-
QgsGeometryUtils.linesIntersection3D(QVector3D(0,0,0), QVector3D(5,0,0), QVector3D(0,1,0), QVector3D(0,3,0))
546-
# (True, PyQt5.QtGui.QVector3D(0.0, 0.0, 0.0))
547-
QgsGeometryUtils.linesIntersection3D(QVector3D(0,0,0), QVector3D(5,0,0), QVector3D(0,1,0), QVector3D(0,0,0))
548-
# (True, PyQt5.QtGui.QVector3D(0.0, 0.0, 0.0))
549-
QgsGeometryUtils.linesIntersection3D(QVector3D(0,0,0), QVector3D(5,0,0), QVector3D(5,1,0), QVector3D(5,3,0))
550-
# (False, PyQt5.QtGui.QVector3D(0.0, 0.0, 0.0))
551-
QgsGeometryUtils.linesIntersection3D(QVector3D(0,0,0), QVector3D(5,0,0), QVector3D(5,1,0), QVector3D(5,0,0))
552-
# (False, PyQt5.QtGui.QVector3D(0.0, 0.0, 0.0))
553-
QgsGeometryUtils.linesIntersection3D(QVector3D(1,1,0), QVector3D(2,2,0), QVector3D(3,1,0), QVector3D(3,2,0))
554-
# (True, PyQt5.QtGui.QVector3D(3.0, 3.0, 0.0))
555-
QgsGeometryUtils.linesIntersection3D(QVector3D(1,1,0), QVector3D(2,2,0), QVector3D(3,2,0), QVector3D(3,1,0))
556-
# (True, PyQt5.QtGui.QVector3D(3.0, 3.0, 0.0))
557-
QgsGeometryUtils.linesIntersection3D(QVector3D(5,5,5), QVector3D(0,0,0), QVector3D(0,5,5), QVector3D(5,0,0))
558-
# (True, PyQt5.QtGui.QVector3D(2.5, 2.5, 2.5))
559-
QgsGeometryUtils.linesIntersection3D(QVector3D(2.5,2.5,2.5), QVector3D(0,5,0), QVector3D(2.5,2.5,2.5), QVector3D(5,0,0))
560-
# (True, PyQt5.QtGui.QVector3D(2.5, 2.5, 2.5))
561-
QgsGeometryUtils.linesIntersection3D(QVector3D(2.5,2.5,2.5), QVector3D(5,0,0), QVector3D(0,5,5), QVector3D(5,5,5))
562-
# (True, PyQt5.QtGui.QVector3D(0.0, 5.0, 5.0))
540+
QgsGeometryUtils.linesIntersection3D(QgsVector3D(0,0,0), QgsVector3D(5,0,0), QgsVector3D(2,1,0), QgsVector3D(2,3,0))
541+
# (True, PyQt5.QtGui.QgsVector3D(2.0, 0.0, 0.0))
542+
QgsGeometryUtils.linesIntersection3D(QgsVector3D(0,0,0), QgsVector3D(5,0,0), QgsVector3D(2,1,0), QgsVector3D(2,0,0))
543+
# (True, PyQt5.QtGui.QgsVector3D(2.0, 0.0, 0.0))
544+
QgsGeometryUtils.linesIntersection3D(QgsVector3D(0,0,0), QgsVector3D(5,0,0), QgsVector3D(0,1,0), QgsVector3D(0,3,0))
545+
# (True, PyQt5.QtGui.QgsVector3D(0.0, 0.0, 0.0))
546+
QgsGeometryUtils.linesIntersection3D(QgsVector3D(0,0,0), QgsVector3D(5,0,0), QgsVector3D(0,1,0), QgsVector3D(0,0,0))
547+
# (True, PyQt5.QtGui.QgsVector3D(0.0, 0.0, 0.0))
548+
QgsGeometryUtils.linesIntersection3D(QgsVector3D(0,0,0), QgsVector3D(5,0,0), QgsVector3D(5,1,0), QgsVector3D(5,3,0))
549+
# (False, PyQt5.QtGui.QgsVector3D(0.0, 0.0, 0.0))
550+
QgsGeometryUtils.linesIntersection3D(QgsVector3D(0,0,0), QgsVector3D(5,0,0), QgsVector3D(5,1,0), QgsVector3D(5,0,0))
551+
# (False, PyQt5.QtGui.QgsVector3D(0.0, 0.0, 0.0))
552+
QgsGeometryUtils.linesIntersection3D(QgsVector3D(1,1,0), QgsVector3D(2,2,0), QgsVector3D(3,1,0), QgsVector3D(3,2,0))
553+
# (True, PyQt5.QtGui.QgsVector3D(3.0, 3.0, 0.0))
554+
QgsGeometryUtils.linesIntersection3D(QgsVector3D(1,1,0), QgsVector3D(2,2,0), QgsVector3D(3,2,0), QgsVector3D(3,1,0))
555+
# (True, PyQt5.QtGui.QgsVector3D(3.0, 3.0, 0.0))
556+
QgsGeometryUtils.linesIntersection3D(QgsVector3D(5,5,5), QgsVector3D(0,0,0), QgsVector3D(0,5,5), QgsVector3D(5,0,0))
557+
# (True, PyQt5.QtGui.QgsVector3D(2.5, 2.5, 2.5))
558+
QgsGeometryUtils.linesIntersection3D(QgsVector3D(2.5,2.5,2.5), QgsVector3D(0,5,0), QgsVector3D(2.5,2.5,2.5), QgsVector3D(5,0,0))
559+
# (True, PyQt5.QtGui.QgsVector3D(2.5, 2.5, 2.5))
560+
QgsGeometryUtils.linesIntersection3D(QgsVector3D(2.5,2.5,2.5), QgsVector3D(5,0,0), QgsVector3D(0,5,5), QgsVector3D(5,5,5))
561+
# (True, PyQt5.QtGui.QgsVector3D(0.0, 5.0, 5.0))
563562
%End
564563

565564
static bool setZValueFromPoints( const QgsPointSequence &points, QgsPoint &point );

python/core/qgsvector3d.sip.in

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/qgsvector3d.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
class QgsVector3D
12+
{
13+
%Docstring
14+
Class for storage of 3D vectors similar to QgsVector3D, with the difference that it uses double precision
15+
instead of single precision floating point numbers.
16+
17+
.. versionadded:: 3.0
18+
%End
19+
20+
%TypeHeaderCode
21+
#include "qgsvector3d.h"
22+
%End
23+
public:
24+
QgsVector3D();
25+
%Docstring
26+
Constructs a null vector
27+
%End
28+
29+
QgsVector3D( double x, double y, double z );
30+
%Docstring
31+
Constructs a vector from given coordinates
32+
%End
33+
bool isNull() const;
34+
%Docstring
35+
Returns true if all three coordinates are zero
36+
%End
37+
38+
double x() const;
39+
%Docstring
40+
Returns X coordinate
41+
%End
42+
double y() const;
43+
%Docstring
44+
Returns Y coordinate
45+
%End
46+
double z() const;
47+
%Docstring
48+
Returns Z coordinate
49+
%End
50+
51+
void set( double x, double y, double z );
52+
%Docstring
53+
Sets vector coordinates
54+
%End
55+
56+
bool operator==( const QgsVector3D &other ) const;
57+
bool operator!=( const QgsVector3D &other ) const;
58+
59+
QgsVector3D operator+( const QgsVector3D &other ) const;
60+
61+
QgsVector3D operator-( const QgsVector3D &other ) const;
62+
63+
QgsVector3D operator *( const double factor) const;
64+
65+
QgsVector3D operator /( const double factor) const;
66+
67+
static double dotProduct( const QgsVector3D &v1, const QgsVector3D &v2);
68+
%Docstring
69+
Returns the dot product of two vectors
70+
%End
71+
72+
static QgsVector3D crossProduct(const QgsVector3D& v1, const QgsVector3D& v2);
73+
%Docstring
74+
Returns the cross product of two vectors
75+
%End
76+
77+
double length() const;
78+
%Docstring
79+
Returns the length of the vector
80+
%End
81+
82+
void normalize();
83+
%Docstring
84+
Normalizes the currect vector in place.
85+
%End
86+
87+
88+
};
89+
90+
/************************************************************************
91+
* This file has been generated automatically from *
92+
* *
93+
* src/core/qgsvector3d.h *
94+
* *
95+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
96+
************************************************************************/

src/3d/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ SET(QGIS_3D_SRCS
1111
qgstessellatedpolygongeometry.cpp
1212
qgstessellator.cpp
1313
qgstilingscheme.cpp
14-
qgsvector3d.cpp
1514
qgsvectorlayer3drenderer.cpp
1615

1716
chunks/qgschunkboundsentity_p.cpp
@@ -85,7 +84,6 @@ SET(QGIS_3D_HDRS
8584
qgstessellatedpolygongeometry.h
8685
qgstessellator.h
8786
qgstilingscheme.h
88-
qgsvector3d.h
8987
qgsvectorlayer3drenderer.h
9088

9189
chunks/qgschunkboundsentity_p.h

src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ SET(QGIS_CORE_SRCS
299299
qgstransactiongroup.cpp
300300
qgsunittypes.cpp
301301
qgsvector.cpp
302+
qgsvector3d.cpp
302303
qgsvectordataprovider.cpp
303304
qgsvectorfilewriter.cpp
304305
qgsvectorfilewritertask.cpp
@@ -946,6 +947,7 @@ SET(QGIS_CORE_HDRS
946947
qgstestutils.h
947948
qgsziputils.h
948949
qgsvector.h
950+
qgsvector3d.h
949951
qgslocalec.h
950952

951953
annotations/qgsannotationregistry.h

src/core/geometry/qgsgeometryutils.cpp

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,28 +1331,28 @@ double QgsGeometryUtils::averageAngle( double a1, double a2 )
13311331
return normalizedAngle( resultAngle );
13321332
}
13331333

1334-
double QgsGeometryUtils::skewLinesDistance( const QVector3D &P1, const QVector3D &P12,
1335-
const QVector3D &P2, const QVector3D &P22 )
1334+
double QgsGeometryUtils::skewLinesDistance( const QgsVector3D &P1, const QgsVector3D &P12,
1335+
const QgsVector3D &P2, const QgsVector3D &P22 )
13361336
{
1337-
QVector3D u1 = P12 - P1;
1338-
QVector3D u2 = P22 - P2;
1339-
QVector3D u3 = QVector3D::crossProduct( u1, u2 );
1337+
QgsVector3D u1 = P12 - P1;
1338+
QgsVector3D u2 = P22 - P2;
1339+
QgsVector3D u3 = QgsVector3D::crossProduct( u1, u2 );
13401340
if ( u3.length() == 0 ) return 1;
13411341
u3.normalize();
1342-
QVector3D dir = P1 - P2;
1343-
return std::fabs( ( QVector3D::dotProduct( dir, u3 ) ) ); // u3 is already normalized
1342+
QgsVector3D dir = P1 - P2;
1343+
return std::fabs( ( QgsVector3D::dotProduct( dir, u3 ) ) ); // u3 is already normalized
13441344
}
13451345

1346-
bool QgsGeometryUtils::skewLinesProjection( const QVector3D &P1, const QVector3D &P12,
1347-
const QVector3D &P2, const QVector3D &P22,
1348-
QVector3D &X1, double epsilon )
1346+
bool QgsGeometryUtils::skewLinesProjection( const QgsVector3D &P1, const QgsVector3D &P12,
1347+
const QgsVector3D &P2, const QgsVector3D &P22,
1348+
QgsVector3D &X1, double epsilon )
13491349
{
1350-
QVector3D d = P2 - P1;
1351-
QVector3D u1 = P12 - P1;
1350+
QgsVector3D d = P2 - P1;
1351+
QgsVector3D u1 = P12 - P1;
13521352
u1.normalize();
1353-
QVector3D u2 = P22 - P2;
1353+
QgsVector3D u2 = P22 - P2;
13541354
u2.normalize();
1355-
QVector3D u3 = QVector3D::crossProduct( u1, u2 );
1355+
QgsVector3D u3 = QgsVector3D::crossProduct( u1, u2 );
13561356

13571357
if ( std::fabs( u3.x() ) <= epsilon &&
13581358
std::fabs( u3.y() ) <= epsilon &&
@@ -1366,8 +1366,8 @@ bool QgsGeometryUtils::skewLinesProjection( const QVector3D &P1, const QVector3D
13661366
// we want to find X1 (lies on u1)
13671367
// solving the linear equation in r1 and r2: Xi = Pi + ri*ui
13681368
// we are only interested in X1 so we only solve for r1.
1369-
float a1 = QVector3D::dotProduct( u1, u1 ), b1 = QVector3D::dotProduct( u1, u2 ), c1 = QVector3D::dotProduct( u1, d );
1370-
float a2 = QVector3D::dotProduct( u1, u2 ), b2 = QVector3D::dotProduct( u2, u2 ), c2 = QVector3D::dotProduct( u2, d );
1369+
float a1 = QgsVector3D::dotProduct( u1, u1 ), b1 = QgsVector3D::dotProduct( u1, u2 ), c1 = QgsVector3D::dotProduct( u1, d );
1370+
float a2 = QgsVector3D::dotProduct( u1, u2 ), b2 = QgsVector3D::dotProduct( u2, u2 ), c2 = QgsVector3D::dotProduct( u2, d );
13711371
if ( !( std::fabs( b1 ) > epsilon ) )
13721372
{
13731373
// Denominator is close to zero.
@@ -1385,9 +1385,9 @@ bool QgsGeometryUtils::skewLinesProjection( const QVector3D &P1, const QVector3D
13851385
return true;
13861386
}
13871387

1388-
bool QgsGeometryUtils::linesIntersection3D( const QVector3D &La1, const QVector3D &La2,
1389-
const QVector3D &Lb1, const QVector3D &Lb2,
1390-
QVector3D &intersection )
1388+
bool QgsGeometryUtils::linesIntersection3D( const QgsVector3D &La1, const QgsVector3D &La2,
1389+
const QgsVector3D &Lb1, const QgsVector3D &Lb2,
1390+
QgsVector3D &intersection )
13911391
{
13921392

13931393
// if all Vector are on the same plane (have the same Z), use the 2D intersection
@@ -1404,9 +1404,7 @@ bool QgsGeometryUtils::linesIntersection3D( const QVector3D &La1, const QVector3
14041404
isIntersection,
14051405
1e-8,
14061406
true );
1407-
intersection.setX( ptInter.x() );
1408-
intersection.setY( ptInter.y() );
1409-
intersection.setZ( La1.z() );
1407+
intersection.set( ptInter.x(), ptInter.y(), La1.z() );
14101408
return true;
14111409
}
14121410

@@ -1416,33 +1414,33 @@ bool QgsGeometryUtils::linesIntersection3D( const QVector3D &La1, const QVector3
14161414
if ( qgsDoubleNear( distance, 0.0 ) )
14171415
{
14181416
// 3d lines have exact intersection point.
1419-
QVector3D C = La2;
1420-
QVector3D D = Lb2;
1421-
QVector3D e = La1 - La2;
1422-
QVector3D f = Lb1 - Lb2;
1423-
QVector3D g = D - C;
1424-
if ( qgsDoubleNear( ( QVector3D::crossProduct( f, g ) ).length(), 0.0 ) || qgsDoubleNear( ( QVector3D::crossProduct( f, e ) ).length(), 0.0 ) )
1417+
QgsVector3D C = La2;
1418+
QgsVector3D D = Lb2;
1419+
QgsVector3D e = La1 - La2;
1420+
QgsVector3D f = Lb1 - Lb2;
1421+
QgsVector3D g = D - C;
1422+
if ( qgsDoubleNear( ( QgsVector3D::crossProduct( f, g ) ).length(), 0.0 ) || qgsDoubleNear( ( QgsVector3D::crossProduct( f, e ) ).length(), 0.0 ) )
14251423
{
14261424
// Lines have no intersection, are they parallel?
14271425
return false;
14281426
}
14291427

1430-
QVector3D fgn = QVector3D::crossProduct( f, g );
1428+
QgsVector3D fgn = QgsVector3D::crossProduct( f, g );
14311429
fgn.normalize();
14321430

1433-
QVector3D fen = QVector3D::crossProduct( f, e );
1431+
QgsVector3D fen = QgsVector3D::crossProduct( f, e );
14341432
fen.normalize();
14351433

14361434
int di = -1;
14371435
if ( fgn == fen ) // same direction?
14381436
di *= -1;
14391437

1440-
intersection = C + e * di * ( QVector3D::crossProduct( f, g ).length() / QVector3D::crossProduct( f, e ).length() );
1438+
intersection = C + e * di * ( QgsVector3D::crossProduct( f, g ).length() / QgsVector3D::crossProduct( f, e ).length() );
14411439
return true;
14421440
}
14431441

14441442
// try to calculate the approximate intersection point
1445-
QVector3D X1, X2;
1443+
QgsVector3D X1, X2;
14461444
bool firstIsDone = skewLinesProjection( La1, La2, Lb1, Lb2, X1 );
14471445
bool secondIsDone = skewLinesProjection( Lb1, Lb2, La1, La2, X2 );
14481446

0 commit comments

Comments
 (0)