Skip to content

Commit

Permalink
qgsvector3d: Add support for minus operator
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitjano authored and lbartoletti committed Jul 11, 2024
1 parent b05941c commit 1b5390e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/PyQt6/core/auto_generated/qgsvector3d.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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/;
Expand Down
2 changes: 2 additions & 0 deletions python/core/auto_generated/qgsvector3d.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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/;
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsvector3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
6 changes: 6 additions & 0 deletions tests/src/core/testqgsvector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1b5390e

Please sign in to comment.