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_core.h"
20 #include <QtGlobal>
21
28 class CORE_EXPORT QgsVector
29 {
30
31  public:
32
36  QgsVector() = default;
37
43  QgsVector( double x, double y );
44
46  QgsVector operator-() const;
47
52  QgsVector operator*( double scalar ) const;
53
58  QgsVector operator/( double scalar ) const;
59
65  double operator*( QgsVector v ) const;
66
71  QgsVector operator+( QgsVector other ) const;
72
77  QgsVector &operator+=( QgsVector other );
78
83  QgsVector operator-( QgsVector other ) const;
84
89  QgsVector &operator-=( QgsVector other );
90
95  double length() const;
96
102  double lengthSquared() const
103  {
104  return mX * mX + mY * mY;
105  }
106
111  double x() const;
112
117  double y() const;
118
122  QgsVector perpVector() const;
123
127  double angle() const;
128
132  double angle( QgsVector v ) const;
133
140  double crossProduct( QgsVector v ) const;
141
146  QgsVector rotateBy( double rot ) const;
147
152  QgsVector normalized() const;
153
155  bool operator==( QgsVector other ) const;
156
158  bool operator!=( QgsVector other ) const;
159
160  private:
161  double mX = 0.0, mY = 0.0;
162
163 };
164
165 Q_DECLARE_TYPEINFO( QgsVector, Q_MOVABLE_TYPE );
166
167 #endif // QGSVECTOR_H
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
double lengthSquared() const
Returns the length of the vector.
Definition: qgsvector.h:102
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
QDateTime operator+(const QDateTime &start, QgsInterval interval)
A class to represent a vector.
Definition: qgsvector.h:28
QgsInterval operator-(const QDateTime &dt1, const QDateTime &dt2)
Returns the interval between two datetimes.
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