-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce QgsVector3D for 3D vectors with double precision
QVector3D with single precision is not always enough (it has only ~7 significant digits)
- Loading branch information
Showing
16 changed files
with
139 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/*************************************************************************** | ||
qgsvector3d.h | ||
-------------------------------------- | ||
Date : November 2017 | ||
Copyright : (C) 2017 by Martin Dobias | ||
Email : wonder dot sk at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsvector3d.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/*************************************************************************** | ||
qgsvector3d.h | ||
-------------------------------------- | ||
Date : November 2017 | ||
Copyright : (C) 2017 by Martin Dobias | ||
Email : wonder dot sk at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSVECTOR3D_H | ||
#define QGSVECTOR3D_H | ||
|
||
#include "qgis_3d.h" | ||
|
||
/** | ||
* Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precision | ||
* instead of single precision floating point numbers. | ||
* | ||
* \note Added in QGIS 3.0 | ||
*/ | ||
class _3D_EXPORT QgsVector3D | ||
{ | ||
public: | ||
//! Constructs a null vector | ||
QgsVector3D() = default; | ||
|
||
//! Constructs a vector from given coordinates | ||
QgsVector3D( double x, double y, double z ) | ||
: mX( x ), mY( y ), mZ( z ) {} | ||
|
||
//! Returns true if all three coordinates are zero | ||
bool isNull() const { return mX == 0 && mY == 0 && mZ == 0; } | ||
|
||
//! Returns X coordinate | ||
double x() const { return mX; } | ||
//! Returns Y coordinate | ||
double y() const { return mY; } | ||
//! Returns Z coordinate | ||
double z() const { return mZ; } | ||
|
||
//! Sets vector coordinates | ||
void set( double x, double y, double z ) | ||
{ | ||
mX = x; | ||
mY = y; | ||
mZ = z; | ||
} | ||
|
||
//! Returns sum of two vectors | ||
QgsVector3D operator+( const QgsVector3D &other ) | ||
{ | ||
return QgsVector3D( mX + other.mX, mY + other.mY, mZ + other.mZ ); | ||
} | ||
|
||
//! Returns difference of two vectors | ||
QgsVector3D operator-( const QgsVector3D &other ) | ||
{ | ||
return QgsVector3D( mX - other.mX, mY - other.mY, mZ - other.mZ ); | ||
} | ||
|
||
private: | ||
double mX = 0, mY = 0, mZ = 0; | ||
}; | ||
|
||
#endif // QGSVECTOR3D_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters