QGIS API Documentation  3.10.0-A CoruĂ±a (6c816b4204)
qgsvector.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvector.h - QgsVector
3
4  ---------------------
5  begin : 24.2.2017
6  copyright : (C) 2017 by Matthias Kuhn
7  email : [email protected]
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSVECTOR_H
17 #define QGSVECTOR_H
18
19 #include "qgis.h"
20 #include "qgis_core.h"
21 #include <QtGlobal>
22
29 class CORE_EXPORT QgsVector
30 {
31
32  public:
33
37  QgsVector() = default;
38
44  QgsVector( double x, double y );
45
47  QgsVector operator-() const;
48
53  QgsVector operator*( double scalar ) const;
54
59  QgsVector operator/( double scalar ) const;
60
66  double operator*( QgsVector v ) const;
67
72  QgsVector operator+( QgsVector other ) const;
73
78  QgsVector &operator+=( QgsVector other );
79
84  QgsVector operator-( QgsVector other ) const;
85
90  QgsVector &operator-=( QgsVector other );
91
96  double length() const;
97
103  double lengthSquared() const
104  {
105  return mX * mX + mY * mY;
106  }
107
112  double x() const;
113
118  double y() const;
119
123  QgsVector perpVector() const;
124
128  double angle() const;
129
133  double angle( QgsVector v ) const;
134
141  double crossProduct( QgsVector v ) const;
142
147  QgsVector rotateBy( double rot ) const;
148
153  QgsVector normalized() const;
154
156  bool operator==( QgsVector other ) const;
157
159  bool operator!=( QgsVector other ) const;
160
161
166  QString toString( int precision = 17 ) const
167  {
168  QString str = "Vector (";
169  str += qgsDoubleToString( mX, precision );
170  str += ", ";
171  str += qgsDoubleToString( mY, precision );
172  str += ')';
173  return str;
174  }
175
176 #ifdef SIP_RUN
177  SIP_PYOBJECT __repr__();
178  % MethodCode
179  QString str = QStringLiteral( "<QgsVector: %1>" ).arg( sipCpp->toString() );
180  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
181  % End
182 #endif
183
184  private:
185  double mX = 0.0, mY = 0.0;
186
187 };
188
189 Q_DECLARE_TYPEINFO( QgsVector, Q_MOVABLE_TYPE );
190
191 #endif // QGSVECTOR_H
int precision
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
Q_DECLARE_TYPEINFO(QgsVector, Q_MOVABLE_TYPE)
QgsMargins operator/(const QgsMargins &margins, double divisor)
Returns a QgsMargins object that is formed by dividing the components of the given margins by the giv...
Definition: qgsmargins.h:262
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:240
QDateTime operator+(const QDateTime &start, QgsInterval interval)
A class to represent a vector.
Definition: qgsvector.h:29
QgsInterval operator-(const QDateTime &dt1, const QDateTime &dt2)
Returns the interval between two datetimes.
QString toString(int precision=17) const
Returns a string representation of the vector.
Definition: qgsvector.h:166
QgsMargins operator*(const QgsMargins &margins, double factor)
Returns a QgsMargins object that is formed by multiplying each component of the given margins by fact...
Definition: qgsmargins.h:242
double lengthSquared() const
Returns the length of the vector.
Definition: qgsvector.h:103