diff --git a/python/PyQt6/core/auto_generated/qgsvector3d.sip.in b/python/PyQt6/core/auto_generated/qgsvector3d.sip.in index 9fe5178311be..424235ebde78 100644 --- a/python/PyQt6/core/auto_generated/qgsvector3d.sip.in +++ b/python/PyQt6/core/auto_generated/qgsvector3d.sip.in @@ -84,6 +84,8 @@ Sets vector coordinates QgsVector3D operator-( const QgsVector3D &other ) const /HoldGIL/; + const QgsVector3D operator-() const /HoldGIL/; + QgsVector3D operator *( const double factor ) const /HoldGIL/; QgsVector3D operator /( const double factor ) const /HoldGIL/; diff --git a/python/core/auto_generated/qgsvector3d.sip.in b/python/core/auto_generated/qgsvector3d.sip.in index 9fe5178311be..424235ebde78 100644 --- a/python/core/auto_generated/qgsvector3d.sip.in +++ b/python/core/auto_generated/qgsvector3d.sip.in @@ -84,6 +84,8 @@ Sets vector coordinates QgsVector3D operator-( const QgsVector3D &other ) const /HoldGIL/; + const QgsVector3D operator-() const /HoldGIL/; + QgsVector3D operator *( const double factor ) const /HoldGIL/; QgsVector3D operator /( const double factor ) const /HoldGIL/; diff --git a/src/core/qgsvector3d.h b/src/core/qgsvector3d.h index 621bf1b81b42..a7ee846502c0 100644 --- a/src/core/qgsvector3d.h +++ b/src/core/qgsvector3d.h @@ -99,6 +99,16 @@ class CORE_EXPORT QgsVector3D return QgsVector3D( mX - other.mX, mY - other.mY, mZ - other.mZ ); } + /** + * Swaps the sign of the components of the vector. + * + * \since QGIS 3.40 + */ + const QgsVector3D operator-() const SIP_HOLDGIL + { + return QgsVector3D( -mX, -mY, -mZ ); + } + //! Returns a new vector multiplied by scalar QgsVector3D operator *( const double factor ) const SIP_HOLDGIL { diff --git a/tests/src/core/testqgsvector.cpp b/tests/src/core/testqgsvector.cpp index 6cbc22773243..2a41ab6369d5 100644 --- a/tests/src/core/testqgsvector.cpp +++ b/tests/src/core/testqgsvector.cpp @@ -84,6 +84,12 @@ void TestQgsVector::vector3d() QCOMPARE( QgsVector3D::perpendicularPoint( QgsVector3D( 0.0, 0.0, 0.0 ), QgsVector3D( 0.0, 5.0, 0.0 ), QgsVector3D( 1.0, 4.0, 0.0 ) ), QgsVector3D( 0.0, 4.0, 0.0 ) ); QCOMPARE( QgsVector3D::perpendicularPoint( QgsVector3D( 0.0, 0.0, 5.0 ), QgsVector3D( 0.0, 0.0, 10.0 ), QgsVector3D( 2.0, 4.0, 7 ) ), QgsVector3D( 0.0, 0.0, 7.0 ) ); QCOMPARE( QgsVector3D::perpendicularPoint( QgsVector3D( 0.0, 0.0, 5.0 ), QgsVector3D( 0.0, 5.0, 10.0 ), QgsVector3D( 1.0, 4.0, 5.0 ) ).toString( 2 ), QgsVector3D( 0.0, 2.0, 7.0 ).toString( 2 ) ); + + // operator - + QgsVector3D v1( 1.0, -2.0, 5.0 ); + QgsVector3D v2( -3.0, 12.0, 1.0 ); + QCOMPARE( v1 - v2, QgsVector3D( 4.0, -14.0, 4.0 ) ); + QCOMPARE( -v2, QgsVector3D( 3.0, -12.0, -1.0 ) ); } void TestQgsVector::setters()