Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qgsvector3d: Add support for minus operator #58068

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading