Skip to content

Commit 33d422b

Browse files
authoredNov 3, 2017
Merge pull request #5518 from nyalldawson/interp
Start on unit tests for interpolation classes
2 parents fb7f8f1 + 61fa8da commit 33d422b

17 files changed

+569
-343
lines changed
 

‎python/analysis/interpolation/qgsgridfilewriter.sip

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,23 @@ class QgsGridFileWriter
1717
#include "qgsgridfilewriter.h"
1818
%End
1919
public:
20-
QgsGridFileWriter( QgsInterpolator *i, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows, double cellSizeX, double cellSizeY );
2120

21+
QgsGridFileWriter( QgsInterpolator *interpolator, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows );
22+
%Docstring
23+
Constructor for QgsGridFileWriter, for the specified ``interpolator``.
24+
25+
The ``outputPath`` argument is used to set the output file path.
26+
27+
The ``extent`` and ``nCols``, ``nRows`` arguments dictate the extent and size of the output raster.
28+
%End
2229

2330
int writeFile( QgsFeedback *feedback = 0 );
2431
%Docstring
2532
Writes the grid file.
26-
\param feedback optional feedback object for progress reports and cancelation support
27-
:return: 0 in case of success*
33+
34+
An optional ``feedback`` object can be set for progress reports and cancelation support
35+
36+
:return: 0 in case of success
2837
:rtype: int
2938
%End
3039

‎python/plugins/processing/algs/qgis/IdwInterpolation.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ class IdwInterpolation(QgisAlgorithm):
8989
DISTANCE_COEFFICIENT = 'DISTANCE_COEFFICIENT'
9090
COLUMNS = 'COLUMNS'
9191
ROWS = 'ROWS'
92-
CELLSIZE_X = 'CELLSIZE_X'
93-
CELLSIZE_Y = 'CELLSIZE_Y'
9492
EXTENT = 'EXTENT'
9593
OUTPUT = 'OUTPUT'
9694

@@ -116,12 +114,6 @@ def initAlgorithm(self, config=None):
116114
self.addParameter(QgsProcessingParameterNumber(self.ROWS,
117115
self.tr('Number of rows'),
118116
minValue=0, maxValue=10000000, defaultValue=300))
119-
self.addParameter(QgsProcessingParameterNumber(self.CELLSIZE_X,
120-
self.tr('Cell Size X'), type=QgsProcessingParameterNumber.Double,
121-
minValue=0.0, maxValue=999999.000000, defaultValue=0.0))
122-
self.addParameter(QgsProcessingParameterNumber(self.CELLSIZE_Y,
123-
self.tr('Cell Size Y'), type=QgsProcessingParameterNumber.Double,
124-
minValue=0.0, maxValue=999999.000000, defaultValue=0.0))
125117
self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
126118
self.tr('Extent'),
127119
optional=False))
@@ -139,8 +131,6 @@ def processAlgorithm(self, parameters, context, feedback):
139131
coefficient = self.parameterAsDouble(parameters, self.DISTANCE_COEFFICIENT, context)
140132
columns = self.parameterAsInt(parameters, self.COLUMNS, context)
141133
rows = self.parameterAsInt(parameters, self.ROWS, context)
142-
cellsizeX = self.parameterAsDouble(parameters, self.CELLSIZE_X, context)
143-
cellsizeY = self.parameterAsDouble(parameters, self.CELLSIZE_Y, context)
144134
bbox = self.parameterAsExtent(parameters, self.EXTENT, context)
145135
output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
146136

@@ -176,9 +166,7 @@ def processAlgorithm(self, parameters, context, feedback):
176166
output,
177167
bbox,
178168
columns,
179-
rows,
180-
cellsizeX,
181-
cellsizeY)
169+
rows)
182170

183171
writer.writeFile(feedback)
184172
return {self.OUTPUT: output}

‎python/plugins/processing/algs/qgis/TinInterpolation.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ class TinInterpolation(QgisAlgorithm):
9292
METHOD = 'METHOD'
9393
COLUMNS = 'COLUMNS'
9494
ROWS = 'ROWS'
95-
CELLSIZE_X = 'CELLSIZE_X'
96-
CELLSIZE_Y = 'CELLSIZE_Y'
9795
EXTENT = 'EXTENT'
9896
OUTPUT = 'OUTPUT'
9997
TRIANGULATION = 'TRIANGULATION'
@@ -124,12 +122,6 @@ def initAlgorithm(self, config=None):
124122
self.addParameter(QgsProcessingParameterNumber(self.ROWS,
125123
self.tr('Number of rows'),
126124
minValue=0, maxValue=10000000, defaultValue=300))
127-
self.addParameter(QgsProcessingParameterNumber(self.CELLSIZE_X,
128-
self.tr('Cell size X'), type=QgsProcessingParameterNumber.Double,
129-
minValue=0.0, maxValue=999999.000000, defaultValue=0.0))
130-
self.addParameter(QgsProcessingParameterNumber(self.CELLSIZE_Y,
131-
self.tr('Cell size Y'), type=QgsProcessingParameterNumber.Double,
132-
minValue=0.0, maxValue=999999.000000, defaultValue=0.0))
133125
self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
134126
self.tr('Extent'),
135127
optional=False))
@@ -154,19 +146,13 @@ def processAlgorithm(self, parameters, context, feedback):
154146
method = self.parameterAsEnum(parameters, self.METHOD, context)
155147
columns = self.parameterAsInt(parameters, self.COLUMNS, context)
156148
rows = self.parameterAsInt(parameters, self.ROWS, context)
157-
cellsizeX = self.parameterAsDouble(parameters, self.CELLSIZE_X, context)
158-
cellsizeY = self.parameterAsDouble(parameters, self.CELLSIZE_Y, context)
159149
bbox = self.parameterAsExtent(parameters, self.EXTENT, context)
160150
output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
161151

162152
if interpolationData is None:
163153
raise QgsProcessingException(
164154
self.tr('You need to specify at least one input layer.'))
165155

166-
if cellsizeX == 0.0 or cellsizeY == 0.0:
167-
raise QgsProcessingException(
168-
self.tr('Cellsize should be greater than 0.'))
169-
170156
layerData = []
171157
layers = []
172158
crs = QgsCoordinateReferenceSystem()
@@ -207,9 +193,7 @@ def processAlgorithm(self, parameters, context, feedback):
207193
output,
208194
bbox,
209195
columns,
210-
rows,
211-
cellsizeX,
212-
cellsizeY)
196+
rows)
213197

214198
writer.writeFile(feedback)
215199
return {self.OUTPUT: output, self.TRIANGULATION: triangulation_dest_id}

‎python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,8 +1497,6 @@ tests:
14971497
- algorithm: qgis:idwinterpolation
14981498
name: IDW interpolation using attribute
14991499
params:
1500-
CELLSIZE_X: 0.02667
1501-
CELLSIZE_Y: 0.02667
15021500
COLUMNS: 300
15031501
DISTANCE_COEFFICIENT: 2.0
15041502
EXTENT: 0, 8, -5, 3
@@ -1508,14 +1506,14 @@ tests:
15081506
ROWS: 300
15091507
results:
15101508
OUTPUT:
1511-
hash: 56d2671d50444f8571affba3f9e585830b82af5e380394178f521065
1509+
hash:
1510+
- 56d2671d50444f8571affba3f9e585830b82af5e380394178f521065
1511+
- 2ae62aca803e6864ac75e47b4357292b0637d811cb510ed19471f422
15121512
type: rasterhash
15131513

15141514
- algorithm: qgis:idwinterpolation
15151515
name: IDW interpolation using Z value
15161516
params:
1517-
CELLSIZE_X: 0.02667
1518-
CELLSIZE_Y: 0.02667
15191517
COLUMNS: 300
15201518
DISTANCE_COEFFICIENT: 2.0
15211519
EXTENT: 0, 8, -5, 3
@@ -1525,14 +1523,14 @@ tests:
15251523
ROWS: 300
15261524
results:
15271525
OUTPUT:
1528-
hash: 56d2671d50444f8571affba3f9e585830b82af5e380394178f521065
1526+
hash:
1527+
- 56d2671d50444f8571affba3f9e585830b82af5e380394178f521065
1528+
- 2ae62aca803e6864ac75e47b4357292b0637d811cb510ed19471f422
15291529
type: rasterhash
15301530

15311531
- algorithm: qgis:tininterpolation
15321532
name: TIN interpolation using attribute
15331533
params:
1534-
CELLSIZE_X: 0.02667
1535-
CELLSIZE_Y: 0.02667
15361534
COLUMNS: 300
15371535
EXTENT: 0, 8, -5, 3
15381536
INTERPOLATION_DATA:
@@ -1542,7 +1540,9 @@ tests:
15421540
ROWS: 300
15431541
results:
15441542
OUTPUT:
1545-
hash: 87f40be6ec08f3fcbb5707762de71f6be35bb265c61f594335562a26
1543+
hash:
1544+
- 87f40be6ec08f3fcbb5707762de71f6be35bb265c61f594335562a26
1545+
- a31f0faf918ebe0902e5c9c5c8cf606d30f52eb4094bf24e4f8ac67a
15461546
type: rasterhash
15471547
#TRIANGULATION_FILE:
15481548
# name: expected/triangulation.gml
@@ -1551,8 +1551,6 @@ tests:
15511551
- algorithm: qgis:tininterpolation
15521552
name: TIN interpolation using Z value
15531553
params:
1554-
CELLSIZE_X: 0.02667
1555-
CELLSIZE_Y: 0.02667
15561554
COLUMNS: 300
15571555
EXTENT: 0, 8, -5, 3
15581556
INTERPOLATION_DATA:
@@ -1562,7 +1560,9 @@ tests:
15621560
ROWS: 300
15631561
results:
15641562
OUTPUT:
1565-
hash: 5e14dd0b879884b8b8da56c082947dad681feb4e9f1137f5cda126f8
1563+
hash:
1564+
- 5e14dd0b879884b8b8da56c082947dad681feb4e9f1137f5cda126f8
1565+
- b8389559d6a85e7a672d72254228473fae71af2d89e5a5dd73d1b0d7
15661566
type: rasterhash
15671567
#TRIANULATION_FILE:
15681568
# name: expected/triangulation.gml

‎src/analysis/interpolation/CloughTocherInterpolator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void CloughTocherInterpolator::init( double x, double y )//version, which has th
227227

228228
if ( mTIN )
229229
{
230-
mTIN->getTriangle( x, y, &point1, &ptn1, &v1, &state1, &point2, &ptn2, &v2, &state2, &point3, &ptn3, &v3, &state3 );
230+
mTIN->getTriangle( x, y, point1, ptn1, &v1, &state1, point2, ptn2, &v2, &state2, point3, ptn3, &v3, &state3 );
231231

232232
if ( point1 == lpoint1 && point2 == lpoint2 && point3 == lpoint3 )//if we are in the same triangle as at the last run, we can leave 'init'
233233
{

‎src/analysis/interpolation/DualEdgeTriangulation.cpp

Lines changed: 174 additions & 192 deletions
Large diffs are not rendered by default.

‎src/analysis/interpolation/DualEdgeTriangulation.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,11 @@ class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
5757
//! Draws the points, edges and the forced lines
5858
//virtual void draw(QPainter* p, double xlowleft, double ylowleft, double xupright, double yupright, double width, double height) const;
5959
//! Returns a pointer to the point with number i
60-
virtual QgsPoint *getPoint( unsigned int i ) const override;
61-
//! Returns the number of the point opposite to the triangle points p1, p2 (which have to be on a halfedge)
60+
virtual QgsPoint *getPoint( int i ) const override;
6261
int getOppositePoint( int p1, int p2 ) override;
63-
//! Finds out, in which triangle the point with coordinates x and y is and assigns the numbers of the vertices to 'n1', 'n2' and 'n3' and the vertices to 'p1', 'p2' and 'p3'
64-
virtual bool getTriangle( double x, double y, QgsPoint *p1 SIP_OUT, int *n1 SIP_OUT, QgsPoint *p2 SIP_OUT, int *n2 SIP_OUT, QgsPoint *p3 SIP_OUT, int *n3 SIP_OUT ) SIP_PYNAME( getTriangleVertices ) override;
65-
//! Finds out, in which triangle the point with coordinates x and y is and assigns addresses to the points at the vertices to 'p1', 'p2' and 'p3
66-
virtual bool getTriangle( double x, double y, QgsPoint *p1 SIP_OUT, QgsPoint *p2 SIP_OUT, QgsPoint *p3 SIP_OUT ) override;
67-
//! Returns a pointer to a value list with the information of the triangles surrounding (counterclockwise) a point. Four integer values describe a triangle, the first three are the number of the half edges of the triangle and the fourth is -10, if the third (and most counterclockwise) edge is a breakline, and -20 otherwise. The value list has to be deleted by the code which called the method
68-
QList<int> *getSurroundingTriangles( int pointno ) override;
62+
bool getTriangle( double x, double y, QgsPoint &p1 SIP_OUT, int &n1 SIP_OUT, QgsPoint &p2 SIP_OUT, int &n2 SIP_OUT, QgsPoint &p3 SIP_OUT, int &n3 SIP_OUT ) SIP_PYNAME( getTriangleVertices ) override;
63+
bool getTriangle( double x, double y, QgsPoint &p1 SIP_OUT, QgsPoint &p2 SIP_OUT, QgsPoint &p3 SIP_OUT ) override;
64+
QList<int> getSurroundingTriangles( int pointno ) override;
6965
//! Returns the largest x-coordinate value of the bounding box
7066
virtual double getXMax() const override { return xMax; }
7167
//! Returns the smallest x-coordinate value of the bounding box
@@ -174,6 +170,8 @@ class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
174170
bool edgeOnConvexHull( int edge );
175171
//! Function needed for the ruppert algorithm. Tests, if point is in the circle through both endpoints of edge and the endpoint of edge->dual->next->point. If so, the function calls itself recursively for edge->next and edge->next->next. Stops, if it finds a forced edge or a convex hull edge
176172
void evaluateInfluenceRegion( QgsPoint *point, int edge, QSet<int> &set );
173+
174+
friend class TestQgsInterpolator;
177175
};
178176

179177
#ifndef SIP_RUN
@@ -203,8 +201,11 @@ inline int DualEdgeTriangulation::getNumberOfPoints() const
203201
return mPointVector.count();
204202
}
205203

206-
inline QgsPoint *DualEdgeTriangulation::getPoint( unsigned int i ) const
204+
inline QgsPoint *DualEdgeTriangulation::getPoint( int i ) const
207205
{
206+
if ( i < 0 || i >= mPointVector.count() )
207+
return nullptr;
208+
208209
return mPointVector.at( i );
209210
}
210211

‎src/analysis/interpolation/LinTriangleInterpolator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bool LinTriangleInterpolator::calcFirstDerX( double x, double y, Vector3D *vec )
2626
QgsPoint pt2( 0, 0, 0 );
2727
QgsPoint pt3( 0, 0, 0 );
2828

29-
if ( !mTIN->getTriangle( x, y, &pt1, &pt2, &pt3 ) )
29+
if ( !mTIN->getTriangle( x, y, pt1, pt2, pt3 ) )
3030
{
3131
return false;//point outside the convex hull or numerical problems
3232
}
@@ -52,7 +52,7 @@ bool LinTriangleInterpolator::calcFirstDerY( double x, double y, Vector3D *vec )
5252
QgsPoint pt2( 0, 0, 0 );
5353
QgsPoint pt3( 0, 0, 0 );
5454

55-
if ( !mTIN->getTriangle( x, y, &pt1, &pt2, &pt3 ) )
55+
if ( !mTIN->getTriangle( x, y, pt1, pt2, pt3 ) )
5656
{
5757
return false;
5858
}
@@ -105,7 +105,7 @@ bool LinTriangleInterpolator::calcPoint( double x, double y, QgsPoint &point )
105105
QgsPoint pt2( 0, 0, 0 );
106106
QgsPoint pt3( 0, 0, 0 );
107107

108-
if ( !mTIN->getTriangle( x, y, &pt1, &pt2, &pt3 ) )
108+
if ( !mTIN->getTriangle( x, y, pt1, pt2, pt3 ) )
109109
{
110110
return false;//point is outside the convex hull or numerical problems
111111
}

‎src/analysis/interpolation/NormVecDecorator.cpp

Lines changed: 45 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ int NormVecDecorator::addPoint( const QgsPoint &p )
5858
{
5959
estimateFirstDerivative( pointno );
6060
//update also the neighbours of the new point
61-
QList<int> *list = mTIN->getSurroundingTriangles( pointno );
62-
QList<int>::iterator it = list->begin();//iterate through the list and analize it
63-
while ( it != list->end() )
61+
const QList<int> list = mTIN->getSurroundingTriangles( pointno );
62+
auto it = list.constBegin();//iterate through the list and analize it
63+
while ( it != list.constEnd() )
6464
{
6565
int point;
6666
point = *it;
@@ -73,7 +73,6 @@ int NormVecDecorator::addPoint( const QgsPoint &p )
7373
++it;
7474
++it;
7575
}
76-
delete list;
7776
}
7877
return pointno;
7978
}
@@ -122,20 +121,19 @@ bool NormVecDecorator::calcNormalForPoint( double x, double y, int point, Vector
122121
result->setY( 0 );
123122
result->setZ( 0 );
124123

125-
QList<int> *vlist = getSurroundingTriangles( point );//get the value list
126-
127-
if ( !vlist )//an error occurred in 'getSurroundingTriangles'
124+
const QList<int> vlist = getSurroundingTriangles( point );//get the value list
125+
if ( vlist.empty() )//an error occurred in 'getSurroundingTriangles'
128126
{
129127
return false;
130128
}
131129

132-
if ( ( ( vlist->count() ) % 4 ) != 0 ) //number of items in vlist has to be a multiple of 4
130+
if ( ( ( vlist.count() ) % 4 ) != 0 ) //number of items in vlist has to be a multiple of 4
133131
{
134132
QgsDebugMsg( "warning, wrong number of items in vlist" );
135133
return false;
136134
}
137135

138-
QList<int>::iterator it = vlist->begin();
136+
auto it = vlist.constBegin();
139137

140138
bool firstrun;
141139

@@ -212,18 +210,13 @@ bool NormVecDecorator::calcNormalForPoint( double x, double y, int point, Vector
212210
}
213211

214212
++it;
215-
if ( it == vlist->end() )//restart at the beginning of the loop
216-
{it = vlist->begin();}
217-
218-
213+
if ( it == vlist.constEnd() )//restart at the beginning of the loop
214+
{
215+
it = vlist.constBegin();
216+
}
219217
}
220-
221-
delete vlist;
222-
223218
return true;
224-
225219
}
226-
227220
else
228221
{
229222
QgsDebugMsg( "warning, null pointer" );
@@ -253,51 +246,39 @@ bool NormVecDecorator::calcPoint( double x, double y, QgsPoint &result )
253246
}
254247
}
255248

256-
bool NormVecDecorator::getTriangle( double x, double y, QgsPoint *p1, Vector3D *v1, QgsPoint *p2, Vector3D *v2, QgsPoint *p3, Vector3D *v3 )
249+
bool NormVecDecorator::getTriangle( double x, double y, QgsPoint &p1, Vector3D *v1, QgsPoint &p2, Vector3D *v2, QgsPoint &p3, Vector3D *v3 )
257250
{
258-
if ( p1 && p2 && p3 && v1 && v2 && v3 )
251+
if ( v1 && v2 && v3 )
259252
{
260-
int *nr1 = new int();
261-
int *nr2 = new int();
262-
int *nr3 = new int();
253+
int nr1 = 0;
254+
int nr2 = 0;
255+
int nr3 = 0;
263256

264257
if ( TriDecorator::getTriangle( x, y, p1, nr1, p2, nr2, p3, nr3 ) )//everything allright
265258
{
266-
if ( ( *mNormVec )[( *nr1 )] && ( *mNormVec )[( *nr2 )] && ( *mNormVec )[( *nr3 )] )
259+
if ( ( *mNormVec )[ nr1 ] && ( *mNormVec )[ nr2 ] && ( *mNormVec )[ nr3 ] )
267260
{
268-
v1->setX( ( *mNormVec )[( *nr1 )]->getX() );
269-
v1->setY( ( *mNormVec )[( *nr1 )]->getY() );
270-
v1->setZ( ( *mNormVec )[( *nr1 )]->getZ() );
261+
v1->setX( ( *mNormVec )[ nr1 ]->getX() );
262+
v1->setY( ( *mNormVec )[nr1 ]->getY() );
263+
v1->setZ( ( *mNormVec )[nr1 ]->getZ() );
271264

272-
v2->setX( ( *mNormVec )[( *nr2 )]->getX() );
273-
v2->setY( ( *mNormVec )[( *nr2 )]->getY() );
274-
v2->setZ( ( *mNormVec )[( *nr2 )]->getZ() );
265+
v2->setX( ( *mNormVec )[nr2 ]->getX() );
266+
v2->setY( ( *mNormVec )[nr2 ]->getY() );
267+
v2->setZ( ( *mNormVec )[nr2 ]->getZ() );
275268

276-
v3->setX( ( *mNormVec )[( *nr3 )]->getX() );
277-
v3->setY( ( *mNormVec )[( *nr3 )]->getY() );
278-
v3->setZ( ( *mNormVec )[( *nr3 )]->getZ() );
269+
v3->setX( ( *mNormVec )[nr3 ]->getX() );
270+
v3->setY( ( *mNormVec )[nr3 ]->getY() );
271+
v3->setZ( ( *mNormVec )[nr3 ]->getZ() );
279272
}
280273
else
281274
{
282275
QgsDebugMsg( "warning, null pointer" );
283-
delete nr1;
284-
delete nr2;
285-
delete nr3;
286276
return false;
287277
}
288-
289-
delete nr1;
290-
delete nr2;
291-
delete nr3;
292278
return true;
293-
294279
}
295-
296280
else
297281
{
298-
delete nr1;
299-
delete nr2;
300-
delete nr3;
301282
return false;
302283
}
303284
}
@@ -323,29 +304,29 @@ NormVecDecorator::PointState NormVecDecorator::getState( int pointno ) const
323304
}
324305

325306

326-
bool NormVecDecorator::getTriangle( double x, double y, QgsPoint *p1, int *ptn1, Vector3D *v1, PointState *state1, QgsPoint *p2, int *ptn2, Vector3D *v2, PointState *state2, QgsPoint *p3, int *ptn3, Vector3D *v3, PointState *state3 )
307+
bool NormVecDecorator::getTriangle( double x, double y, QgsPoint &p1, int &ptn1, Vector3D *v1, PointState *state1, QgsPoint &p2, int &ptn2, Vector3D *v2, PointState *state2, QgsPoint &p3, int &ptn3, Vector3D *v3, PointState *state3 )
327308
{
328-
if ( p1 && p2 && p3 && v1 && v2 && v3 && ptn1 && ptn2 && ptn3 && state1 && state2 && state3 )
309+
if ( v1 && v2 && v3 && state1 && state2 && state3 )
329310
{
330311
if ( TriDecorator::getTriangle( x, y, p1, ptn1, p2, ptn2, p3, ptn3 ) )//everything allright
331312
{
332-
v1->setX( ( *mNormVec )[( *ptn1 )]->getX() );
333-
v1->setY( ( *mNormVec )[( *ptn1 )]->getY() );
334-
v1->setZ( ( *mNormVec )[( *ptn1 )]->getZ() );
313+
v1->setX( ( *mNormVec )[( ptn1 )]->getX() );
314+
v1->setY( ( *mNormVec )[( ptn1 )]->getY() );
315+
v1->setZ( ( *mNormVec )[( ptn1 )]->getZ() );
335316

336-
( *state1 ) = ( *mPointState )[( *ptn1 )];
317+
( *state1 ) = ( *mPointState )[( ptn1 )];
337318

338-
v2->setX( ( *mNormVec )[( *ptn2 )]->getX() );
339-
v2->setY( ( *mNormVec )[( *ptn2 )]->getY() );
340-
v2->setZ( ( *mNormVec )[( *ptn2 )]->getZ() );
319+
v2->setX( ( *mNormVec )[( ptn2 )]->getX() );
320+
v2->setY( ( *mNormVec )[( ptn2 )]->getY() );
321+
v2->setZ( ( *mNormVec )[( ptn2 )]->getZ() );
341322

342-
( *state2 ) = ( *mPointState )[( *ptn2 )];
323+
( *state2 ) = ( *mPointState )[( ptn2 )];
343324

344-
v3->setX( ( *mNormVec )[( *ptn3 )]->getX() );
345-
v3->setY( ( *mNormVec )[( *ptn3 )]->getY() );
346-
v3->setZ( ( *mNormVec )[( *ptn3 )]->getZ() );
325+
v3->setX( ( *mNormVec )[( ptn3 )]->getX() );
326+
v3->setY( ( *mNormVec )[( ptn3 )]->getY() );
327+
v3->setZ( ( *mNormVec )[( ptn3 )]->getZ() );
347328

348-
( *state3 ) = ( *mPointState )[( *ptn3 )];
329+
( *state3 ) = ( *mPointState )[( ptn3 )];
349330

350331
return true;
351332
}
@@ -379,9 +360,9 @@ bool NormVecDecorator::estimateFirstDerivative( int pointno )
379360
double currentweight = 0;//current weight
380361
PointState status;
381362

382-
QList<int> *vlist = getSurroundingTriangles( pointno );//get the value list
363+
const QList<int> vlist = getSurroundingTriangles( pointno );//get the value list
383364

384-
if ( !vlist )
365+
if ( vlist.empty() )
385366
{
386367
//something went wrong in getSurroundingTriangles, set the normal to (0,0,0)
387368
if ( mNormVec->size() <= mNormVec->count() )//allocate more memory if necessary
@@ -406,14 +387,14 @@ bool NormVecDecorator::estimateFirstDerivative( int pointno )
406387
return false;
407388
}
408389

409-
if ( ( vlist->count() % 4 ) != 0 ) //number of items in vlist has to be a multiple of 4
390+
if ( ( vlist.count() % 4 ) != 0 ) //number of items in vlist has to be a multiple of 4
410391
{
411392
QgsDebugMsg( "warning, wrong number of items in vlist" );
412393
return false;
413394
}
414395

415-
QList<int>::iterator it = vlist->begin();//iterate through the list and analize it
416-
while ( it != vlist->end() )
396+
auto it = vlist.constBegin();//iterate through the list and analize it
397+
while ( it != vlist.constEnd() )
417398
{
418399
int p1, p2, p3, flag;
419400
part.setX( 0 );
@@ -479,8 +460,6 @@ bool NormVecDecorator::estimateFirstDerivative( int pointno )
479460
status = BreakLine;
480461
}
481462

482-
delete vlist;
483-
484463
//insert the new calculated vector
485464
if ( mNormVec->size() <= mNormVec->count() )//allocate more memory if necessary
486465
{

‎src/analysis/interpolation/NormVecDecorator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class ANALYSIS_EXPORT NormVecDecorator: public TriDecorator
5757
//! Returns a pointer to the normal vector for the point with the number n
5858
Vector3D *getNormal( int n ) const;
5959
//! Finds out, in which triangle a point with coordinates x and y is and assigns the triangle points to p1, p2, p3 and the estimated normals to v1, v2, v3. The vectors are normally taken from 'mNormVec', except if p1, p2 or p3 is a point on a breakline. In this case, the normal is calculated on-the-fly. Returns false, if something went wrong and true otherwise
60-
bool getTriangle( double x, double y, QgsPoint *p1 SIP_OUT, Vector3D *v1 SIP_OUT, QgsPoint *p2 SIP_OUT, Vector3D *v2 SIP_OUT, QgsPoint *p3 SIP_OUT, Vector3D *v3 SIP_OUT ) SIP_PYNAME( getTriangleVertices );
60+
bool getTriangle( double x, double y, QgsPoint &p1 SIP_OUT, Vector3D *v1 SIP_OUT, QgsPoint &p2 SIP_OUT, Vector3D *v2 SIP_OUT, QgsPoint &p3 SIP_OUT, Vector3D *v3 SIP_OUT ) SIP_PYNAME( getTriangleVertices );
6161
//! This function behaves similar to the one above. Additionally, the numbers of the points are returned (ptn1, ptn2, ptn3) as well as the PointStates of the triangle points (state1, state2, state3)
62-
bool getTriangle( double x, double y, QgsPoint *p1 SIP_OUT, int *ptn1 SIP_OUT, Vector3D *v1 SIP_OUT, PointState *state1 SIP_OUT, QgsPoint *p2 SIP_OUT, int *ptn2 SIP_OUT, Vector3D *v2 SIP_OUT, PointState *state2 SIP_OUT, QgsPoint *p3 SIP_OUT, int *ptn3 SIP_OUT, Vector3D *v3 SIP_OUT, PointState *state3 SIP_OUT );
62+
bool getTriangle( double x, double y, QgsPoint &p1 SIP_OUT, int &ptn1 SIP_OUT, Vector3D *v1 SIP_OUT, PointState *state1 SIP_OUT, QgsPoint &p2 SIP_OUT, int &ptn2 SIP_OUT, Vector3D *v2 SIP_OUT, PointState *state2 SIP_OUT, QgsPoint &p3 SIP_OUT, int &ptn3 SIP_OUT, Vector3D *v3 SIP_OUT, PointState *state3 SIP_OUT );
6363
//! Returns the state of the point with the number 'pointno'
6464
PointState getState( int pointno ) const;
6565
//! Sets an interpolator

‎src/analysis/interpolation/TriDecorator.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ bool TriDecorator::calcPoint( double x, double y, QgsPoint &result )
8383
}
8484
}
8585

86-
QgsPoint *TriDecorator::getPoint( unsigned int i ) const
86+
QgsPoint *TriDecorator::getPoint( int i ) const
8787
{
8888
if ( mTIN )
8989
{
@@ -97,7 +97,7 @@ QgsPoint *TriDecorator::getPoint( unsigned int i ) const
9797
}
9898
}
9999

100-
bool TriDecorator::getTriangle( double x, double y, QgsPoint *p1, int *n1, QgsPoint *p2, int *n2, QgsPoint *p3, int *n3 )
100+
bool TriDecorator::getTriangle( double x, double y, QgsPoint &p1, int &n1, QgsPoint &p2, int &n2, QgsPoint &p3, int &n3 )
101101
{
102102
if ( mTIN )
103103
{
@@ -111,7 +111,7 @@ bool TriDecorator::getTriangle( double x, double y, QgsPoint *p1, int *n1, QgsPo
111111
}
112112
}
113113

114-
bool TriDecorator::getTriangle( double x, double y, QgsPoint *p1, QgsPoint *p2, QgsPoint *p3 )
114+
bool TriDecorator::getTriangle( double x, double y, QgsPoint &p1, QgsPoint &p2, QgsPoint &p3 )
115115
{
116116
if ( mTIN )
117117
{
@@ -152,17 +152,15 @@ int TriDecorator::getOppositePoint( int p1, int p2 )
152152
}
153153
}
154154

155-
QList<int> *TriDecorator::getSurroundingTriangles( int pointno )
155+
QList<int> TriDecorator::getSurroundingTriangles( int pointno )
156156
{
157157
if ( mTIN )
158158
{
159-
QList<int> *vl = mTIN->getSurroundingTriangles( pointno );
160-
return vl;
159+
return mTIN->getSurroundingTriangles( pointno );
161160
}
162161
else
163162
{
164-
QgsDebugMsg( "warning, null pointer" );
165-
return nullptr;
163+
return QList< int >();
166164
}
167165
}
168166

‎src/analysis/interpolation/TriDecorator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ class ANALYSIS_EXPORT TriDecorator : public Triangulation
4242
void performConsistencyTest() override;
4343
bool calcNormal( double x, double y, Vector3D *result SIP_OUT ) override;
4444
bool calcPoint( double x, double y, QgsPoint &result SIP_OUT ) override;
45-
QgsPoint *getPoint( unsigned int i ) const override;
45+
QgsPoint *getPoint( int i ) const override;
4646
int getNumberOfPoints() const override;
47-
bool getTriangle( double x, double y, QgsPoint *p1 SIP_OUT, int *n1 SIP_OUT, QgsPoint *p2 SIP_OUT, int *n2 SIP_OUT, QgsPoint *p3 SIP_OUT, int *n3 SIP_OUT ) SIP_PYNAME( getTriangleVertices ) override;
48-
bool getTriangle( double x, double y, QgsPoint *p1 SIP_OUT, QgsPoint *p2 SIP_OUT, QgsPoint *p3 SIP_OUT ) override;
47+
bool getTriangle( double x, double y, QgsPoint &p1 SIP_OUT, int &n1 SIP_OUT, QgsPoint &p2 SIP_OUT, int &n2 SIP_OUT, QgsPoint &p3 SIP_OUT, int &n3 SIP_OUT ) SIP_PYNAME( getTriangleVertices ) override;
48+
bool getTriangle( double x, double y, QgsPoint &p1 SIP_OUT, QgsPoint &p2 SIP_OUT, QgsPoint &p3 SIP_OUT ) override;
4949
int getOppositePoint( int p1, int p2 ) override;
50-
QList<int> *getSurroundingTriangles( int pointno ) override;
50+
QList<int> getSurroundingTriangles( int pointno ) override;
5151
double getXMax() const override;
5252
double getXMin() const override;
5353
double getYMax() const override;

‎src/analysis/interpolation/Triangulation.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,23 @@ class ANALYSIS_EXPORT Triangulation
7676
virtual bool calcPoint( double x, double y, QgsPoint &result SIP_OUT ) = 0;
7777

7878
//! Returns a pointer to the point with number i. Any virtual points must have the number -1
79-
virtual QgsPoint *getPoint( unsigned int i ) const = 0;
79+
virtual QgsPoint *getPoint( int i ) const = 0;
8080

8181
/**
8282
* Finds out in which triangle the point with coordinates x and y is and
8383
* assigns the numbers of the vertices to 'n1', 'n2' and 'n3' and the vertices to 'p1', 'p2' and 'p3'
8484
*/
85-
virtual bool getTriangle( double x, double y, QgsPoint *p1 SIP_OUT, int *n1 SIP_OUT, QgsPoint *p2 SIP_OUT, int *n2 SIP_OUT, QgsPoint *p3 SIP_OUT, int *n3 SIP_OUT ) = 0 SIP_PYNAME( getTriangleVertices );
85+
virtual bool getTriangle( double x, double y, QgsPoint &p1 SIP_OUT, int &n1 SIP_OUT, QgsPoint &p2 SIP_OUT, int &n2 SIP_OUT, QgsPoint &p3 SIP_OUT, int &n3 SIP_OUT ) = 0 SIP_PYNAME( getTriangleVertices );
8686

8787
//! Finds out, in which triangle the point with coordinates x and y is and assigns the points at the vertices to 'p1', 'p2' and 'p3
88-
virtual bool getTriangle( double x, double y, QgsPoint *p1 SIP_OUT, QgsPoint *p2 SIP_OUT, QgsPoint *p3 SIP_OUT ) = 0;
88+
virtual bool getTriangle( double x, double y, QgsPoint &p1 SIP_OUT, QgsPoint &p2 SIP_OUT, QgsPoint &p3 SIP_OUT ) = 0;
8989

90-
//! Returns the number of the point opposite to the triangle points p1, p2 (which have to be on a halfedge)
90+
/**
91+
* Returns the number of the point opposite to the triangle points p1, p2 (which have to be on a halfedge).
92+
*
93+
* Returns -1 if point is a virtual point.
94+
* Returns -10 if point crosses over edges.
95+
*/
9196
virtual int getOppositePoint( int p1, int p2 ) = 0;
9297

9398
//! Returns the largest x-coordinate value of the bounding box
@@ -109,10 +114,9 @@ class ANALYSIS_EXPORT Triangulation
109114
* Returns a pointer to a value list with the information of the triangles surrounding (counterclockwise) a point.
110115
* Four integer values describe a triangle, the first three are the number of the half edges of the triangle
111116
* and the fourth is -10, if the third (and most counterclockwise) edge is a breakline, and -20 otherwise.
112-
* The value list has to be deleted by the code which called the method.
113117
* Any virtual point needs to have the number -1
114118
*/
115-
virtual QList<int> *getSurroundingTriangles( int pointno ) = 0;
119+
virtual QList<int> getSurroundingTriangles( int pointno ) = 0;
116120

117121
/**
118122
* Returns a value list with the numbers of the four points, which would be affected by an edge swap.

‎src/analysis/interpolation/qgsgridfilewriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
#include <QFile>
2323
#include <QFileInfo>
2424

25-
QgsGridFileWriter::QgsGridFileWriter( QgsInterpolator *i, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows, double cellSizeX, double cellSizeY )
25+
QgsGridFileWriter::QgsGridFileWriter( QgsInterpolator *i, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows )
2626
: mInterpolator( i )
2727
, mOutputFilePath( outputPath )
2828
, mInterpolationExtent( extent )
2929
, mNumColumns( nCols )
3030
, mNumRows( nRows )
31-
, mCellSizeX( cellSizeX )
32-
, mCellSizeY( cellSizeY )
31+
, mCellSizeX( extent.width() / nCols )
32+
, mCellSizeY( extent.height() / nRows )
3333
{}
3434

3535
int QgsGridFileWriter::writeFile( QgsFeedback *feedback )

‎src/analysis/interpolation/qgsgridfilewriter.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,23 @@ class QgsFeedback;
3333
class ANALYSIS_EXPORT QgsGridFileWriter
3434
{
3535
public:
36-
QgsGridFileWriter( QgsInterpolator *i, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows, double cellSizeX, double cellSizeY );
3736

3837
/**
39-
* Writes the grid file.
40-
\param feedback optional feedback object for progress reports and cancelation support
41-
\returns 0 in case of success*/
38+
* Constructor for QgsGridFileWriter, for the specified \a interpolator.
39+
*
40+
* The \a outputPath argument is used to set the output file path.
41+
*
42+
* The \a extent and \a nCols, \a nRows arguments dictate the extent and size of the output raster.
43+
*/
44+
QgsGridFileWriter( QgsInterpolator *interpolator, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows );
4245

46+
/**
47+
* Writes the grid file.
48+
*
49+
* An optional \a feedback object can be set for progress reports and cancelation support
50+
*
51+
* \returns 0 in case of success
52+
*/
4353
int writeFile( QgsFeedback *feedback = nullptr );
4454

4555
private:

‎tests/src/analysis/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
1717
${CMAKE_SOURCE_DIR}/src/core/raster
1818
${CMAKE_SOURCE_DIR}/src/core/symbology
1919
${CMAKE_SOURCE_DIR}/src/analysis
20+
${CMAKE_SOURCE_DIR}/src/analysis/interpolation
2021
${CMAKE_SOURCE_DIR}/src/analysis/network
2122
${CMAKE_SOURCE_DIR}/src/analysis/processing
2223
${CMAKE_SOURCE_DIR}/src/analysis/vector
@@ -68,6 +69,7 @@ ENDMACRO (ADD_QGIS_TEST)
6869
# Tests:
6970
SET(TESTS
7071
testqgsgeometrysnapper.cpp
72+
testqgsinterpolator.cpp
7173
testqgsprocessing.cpp
7274
testqgszonalstatistics.cpp
7375
testqgsrastercalculator.cpp
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
/***************************************************************************
2+
testqgsinterpolator.cpp
3+
-----------------------
4+
Date : November 2017
5+
Copyright : (C) 2017 by Nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
#include "qgstest.h"
16+
17+
#include "qgsapplication.h"
18+
#include "DualEdgeTriangulation.h"
19+
20+
class TestQgsInterpolator : public QObject
21+
{
22+
Q_OBJECT
23+
24+
public:
25+
26+
private slots:
27+
void initTestCase();// will be called before the first testfunction is executed.
28+
void cleanupTestCase();// will be called after the last testfunction was executed.
29+
void init() ;// will be called before each testfunction is executed.
30+
void cleanup() ;// will be called after every testfunction.
31+
void dualEdge();
32+
33+
private:
34+
};
35+
36+
void TestQgsInterpolator::initTestCase()
37+
{
38+
//
39+
// Runs once before any tests are run
40+
//
41+
// init QGIS's paths - true means that all path will be inited from prefix
42+
QgsApplication::init();
43+
QgsApplication::initQgis();
44+
}
45+
46+
void TestQgsInterpolator::cleanupTestCase()
47+
{
48+
QgsApplication::exitQgis();
49+
}
50+
51+
void TestQgsInterpolator::init()
52+
{}
53+
54+
void TestQgsInterpolator::cleanup()
55+
{}
56+
57+
void TestQgsInterpolator::dualEdge()
58+
{
59+
DualEdgeTriangulation tri;
60+
QVERIFY( !tri.getPoint( 0 ) );
61+
QVERIFY( !tri.getPoint( 1 ) );
62+
QCOMPARE( tri.getNumberOfPoints(), 0 );
63+
64+
tri.addPoint( QgsPoint( 1, 2, 3 ) );
65+
QCOMPARE( *tri.getPoint( 0 ), QgsPoint( 1, 2, 3 ) );
66+
QCOMPARE( tri.getNumberOfPoints(), 1 );
67+
68+
tri.addPoint( QgsPoint( 3, 0, 4 ) );
69+
QCOMPARE( *tri.getPoint( 1 ), QgsPoint( 3, 0, 4 ) );
70+
QCOMPARE( tri.getNumberOfPoints(), 2 );
71+
72+
tri.addPoint( QgsPoint( 4, 4, 5 ) );
73+
QCOMPARE( *tri.getPoint( 2 ), QgsPoint( 4, 4, 5 ) );
74+
QCOMPARE( tri.getNumberOfPoints(), 3 );
75+
76+
QgsPoint p1( 0, 0, 0 );
77+
QgsPoint p2( 0, 0, 0 );
78+
QgsPoint p3( 0, 0, 0 );
79+
int n1 = 0;
80+
int n2 = 0;
81+
int n3 = 0;
82+
QVERIFY( !tri.pointInside( 0, 1 ) );
83+
QVERIFY( !tri.getTriangle( 0, 1, p1, p2, p3 ) );
84+
QVERIFY( !tri.getTriangle( 0, 1, p1, n1, p2, n2, p3, n3 ) );
85+
QVERIFY( !tri.pointInside( 1, 1 ) );
86+
QVERIFY( !tri.getTriangle( 1, 1, p1, p2, p3 ) );
87+
QVERIFY( !tri.getTriangle( 1, 1, p1, n1, p2, n2, p3, n3 ) );
88+
QVERIFY( !tri.pointInside( 4, 1 ) );
89+
QVERIFY( !tri.getTriangle( 4, 1, p1, p2, p3 ) );
90+
QVERIFY( !tri.getTriangle( 4, 1, p1, n1, p2, n2, p3, n3 ) );
91+
QVERIFY( !tri.pointInside( 2, 4 ) );
92+
QVERIFY( !tri.getTriangle( 2, 4, p1, p2, p3 ) );
93+
QVERIFY( !tri.getTriangle( 2, 4, p1, n1, p2, n2, p3, n3 ) );
94+
QVERIFY( !tri.pointInside( 3, -1 ) );
95+
QVERIFY( !tri.getTriangle( 3, -1, p1, p2, p3 ) );
96+
QVERIFY( !tri.getTriangle( 3, -1, p1, n1, p2, n2, p3, n3 ) );
97+
QVERIFY( tri.pointInside( 2, 2 ) );
98+
QVERIFY( tri.getTriangle( 2, 2, p1, p2, p3 ) );
99+
QCOMPARE( p1, QgsPoint( 1, 2, 3 ) );
100+
QCOMPARE( p2, QgsPoint( 3, 0, 4 ) );
101+
QCOMPARE( p3, QgsPoint( 4, 4, 5 ) );
102+
QVERIFY( tri.getTriangle( 2, 2, p1, n1, p2, n2, p3, n3 ) );
103+
QCOMPARE( p1, QgsPoint( 1, 2, 3 ) );
104+
QCOMPARE( p2, QgsPoint( 3, 0, 4 ) );
105+
QCOMPARE( p3, QgsPoint( 4, 4, 5 ) );
106+
QCOMPARE( n1, 0 );
107+
QCOMPARE( n2, 1 );
108+
QCOMPARE( n3, 2 );
109+
QVERIFY( tri.pointInside( 3, 1 ) );
110+
QVERIFY( tri.getTriangle( 3, 1, p1, p2, p3 ) );
111+
QCOMPARE( p1, QgsPoint( 1, 2, 3 ) );
112+
QCOMPARE( p2, QgsPoint( 3, 0, 4 ) );
113+
QCOMPARE( p3, QgsPoint( 4, 4, 5 ) );
114+
QVERIFY( tri.getTriangle( 3, 1, p1, n1, p2, n2, p3, n3 ) );
115+
QCOMPARE( p1, QgsPoint( 1, 2, 3 ) );
116+
QCOMPARE( p2, QgsPoint( 3, 0, 4 ) );
117+
QCOMPARE( p3, QgsPoint( 4, 4, 5 ) );
118+
QCOMPARE( n1, 0 );
119+
QCOMPARE( n2, 1 );
120+
QCOMPARE( n3, 2 );
121+
QVERIFY( tri.pointInside( 3.5, 3.5 ) );
122+
QVERIFY( tri.getTriangle( 3.5, 3.5, p1, p2, p3 ) );
123+
QCOMPARE( p1, QgsPoint( 1, 2, 3 ) );
124+
QCOMPARE( p2, QgsPoint( 3, 0, 4 ) );
125+
QCOMPARE( p3, QgsPoint( 4, 4, 5 ) );
126+
QVERIFY( tri.getTriangle( 3.5, 3.5, p1, n1, p2, n2, p3, n3 ) );
127+
QCOMPARE( p1, QgsPoint( 1, 2, 3 ) );
128+
QCOMPARE( p2, QgsPoint( 3, 0, 4 ) );
129+
QCOMPARE( p3, QgsPoint( 4, 4, 5 ) );
130+
QCOMPARE( n1, 0 );
131+
QCOMPARE( n2, 1 );
132+
QCOMPARE( n3, 2 );
133+
134+
QCOMPARE( tri.getOppositePoint( 0, 1 ), -1 );
135+
QCOMPARE( tri.getOppositePoint( 0, 2 ), 1 );
136+
QCOMPARE( tri.getOppositePoint( 1, 0 ), 2 );
137+
QCOMPARE( tri.getOppositePoint( 1, 2 ), -1 );
138+
QCOMPARE( tri.getOppositePoint( 2, 0 ), -1 );
139+
QCOMPARE( tri.getOppositePoint( 2, 1 ), 0 );
140+
141+
// add another point
142+
tri.addPoint( QgsPoint( 2, 4, 6 ) );
143+
QCOMPARE( *tri.getPoint( 3 ), QgsPoint( 2, 4, 6 ) );
144+
QCOMPARE( tri.getNumberOfPoints(), 4 );
145+
QVERIFY( !tri.pointInside( 2, 4.5 ) );
146+
QVERIFY( !tri.getTriangle( 2, 4.5, p1, p2, p3 ) );
147+
QVERIFY( !tri.getTriangle( 2, 4.5, p1, n1, p2, n2, p3, n3 ) );
148+
QVERIFY( !tri.pointInside( 1, 4 ) );
149+
QVERIFY( !tri.getTriangle( 1, 4, p1, p2, p3 ) );
150+
QVERIFY( !tri.getTriangle( 1, 4, p1, n1, p2, n2, p3, n3 ) );
151+
QVERIFY( tri.pointInside( 2, 3.5 ) );
152+
QVERIFY( tri.getTriangle( 2, 3.5, p1, p2, p3 ) );
153+
QCOMPARE( p1, QgsPoint( 1, 2, 3 ) );
154+
QCOMPARE( p2, QgsPoint( 4, 4, 5 ) );
155+
QCOMPARE( p3, QgsPoint( 2, 4, 6 ) );
156+
QVERIFY( tri.getTriangle( 2, 3.5, p1, n1, p2, n2, p3, n3 ) );
157+
QCOMPARE( p1, QgsPoint( 1, 2, 3 ) );
158+
QCOMPARE( p2, QgsPoint( 4, 4, 5 ) );
159+
QCOMPARE( p3, QgsPoint( 2, 4, 6 ) );
160+
QCOMPARE( n1, 0 );
161+
QCOMPARE( n2, 2 );
162+
QCOMPARE( n3, 3 );
163+
QVERIFY( tri.getTriangle( 2, 2, p1, n1, p2, n2, p3, n3 ) );
164+
QCOMPARE( p1, QgsPoint( 1, 2, 3 ) );
165+
QCOMPARE( p2, QgsPoint( 3, 0, 4 ) );
166+
QCOMPARE( p3, QgsPoint( 4, 4, 5 ) );
167+
QCOMPARE( n1, 0 );
168+
QCOMPARE( n2, 1 );
169+
QCOMPARE( n3, 2 );
170+
171+
QCOMPARE( tri.getOppositePoint( 0, 1 ), -1 );
172+
QCOMPARE( tri.getOppositePoint( 0, 2 ), 1 );
173+
QCOMPARE( tri.getOppositePoint( 0, 3 ), 2 );
174+
QCOMPARE( tri.getOppositePoint( 1, 0 ), 2 );
175+
QCOMPARE( tri.getOppositePoint( 1, 2 ), -1 );
176+
QCOMPARE( tri.getOppositePoint( 1, 3 ), -10 );
177+
QCOMPARE( tri.getOppositePoint( 2, 0 ), 3 );
178+
QCOMPARE( tri.getOppositePoint( 2, 1 ), 0 );
179+
QCOMPARE( tri.getOppositePoint( 2, 3 ), -1 );
180+
QCOMPARE( tri.getOppositePoint( 3, 0 ), -1 );
181+
QCOMPARE( tri.getOppositePoint( 3, 1 ), -10 );
182+
QCOMPARE( tri.getOppositePoint( 3, 2 ), 0 );
183+
184+
185+
// add another point
186+
tri.addPoint( QgsPoint( 2, 2, 7 ) );
187+
QCOMPARE( *tri.getPoint( 4 ), QgsPoint( 2, 2, 7 ) );
188+
QCOMPARE( tri.getNumberOfPoints(), 5 );
189+
QVERIFY( !tri.pointInside( 2, 4.5 ) );
190+
QVERIFY( !tri.getTriangle( 2, 4.5, p1, p2, p3 ) );
191+
QVERIFY( !tri.getTriangle( 2, 4.5, p1, n1, p2, n2, p3, n3 ) );
192+
QVERIFY( !tri.pointInside( 1, 4 ) );
193+
QVERIFY( !tri.getTriangle( 1, 4, p1, p2, p3 ) );
194+
QVERIFY( !tri.getTriangle( 1, 4, p1, n1, p2, n2, p3, n3 ) );
195+
QVERIFY( tri.pointInside( 2, 3.5 ) );
196+
QVERIFY( tri.getTriangle( 2, 3.5, p1, p2, p3 ) );
197+
QCOMPARE( p1, QgsPoint( 2, 4, 6 ) );
198+
QCOMPARE( p2, QgsPoint( 1, 2, 3 ) );
199+
QCOMPARE( p3, QgsPoint( 2, 2, 7 ) );
200+
QVERIFY( tri.getTriangle( 2, 3.5, p1, n1, p2, n2, p3, n3 ) );
201+
QCOMPARE( p1, QgsPoint( 2, 4, 6 ) );
202+
QCOMPARE( p2, QgsPoint( 1, 2, 3 ) );
203+
QCOMPARE( p3, QgsPoint( 2, 2, 7 ) );
204+
QCOMPARE( n1, 3 );
205+
QCOMPARE( n2, 0 );
206+
QCOMPARE( n3, 4 );
207+
QVERIFY( tri.pointInside( 2, 1.5 ) );
208+
QVERIFY( tri.getTriangle( 2, 1.5, p1, p2, p3 ) );
209+
QCOMPARE( p1, QgsPoint( 1, 2, 3 ) );
210+
QCOMPARE( p2, QgsPoint( 3, 0, 4 ) );
211+
QCOMPARE( p3, QgsPoint( 2, 2, 7 ) );
212+
QVERIFY( tri.getTriangle( 2, 1.5, p1, n1, p2, n2, p3, n3 ) );
213+
QCOMPARE( p1, QgsPoint( 1, 2, 3 ) );
214+
QCOMPARE( p2, QgsPoint( 3, 0, 4 ) );
215+
QCOMPARE( p3, QgsPoint( 2, 2, 7 ) );
216+
QCOMPARE( n1, 0 );
217+
QCOMPARE( n2, 1 );
218+
QCOMPARE( n3, 4 );
219+
QVERIFY( tri.pointInside( 3.1, 1 ) );
220+
QVERIFY( tri.getTriangle( 3.1, 1, p1, p2, p3 ) );
221+
QCOMPARE( p1, QgsPoint( 2, 2, 7 ) );
222+
QCOMPARE( p2, QgsPoint( 3, 0, 4 ) );
223+
QCOMPARE( p3, QgsPoint( 4, 4, 5 ) );
224+
QVERIFY( tri.getTriangle( 3.1, 1, p1, n1, p2, n2, p3, n3 ) );
225+
QCOMPARE( p1, QgsPoint( 2, 2, 7 ) );
226+
QCOMPARE( p2, QgsPoint( 3, 0, 4 ) );
227+
QCOMPARE( p3, QgsPoint( 4, 4, 5 ) );
228+
QCOMPARE( n1, 4 );
229+
QCOMPARE( n2, 1 );
230+
QCOMPARE( n3, 2 );
231+
QVERIFY( tri.pointInside( 2.5, 3.5 ) );
232+
QVERIFY( tri.getTriangle( 2.5, 3.5, p1, p2, p3 ) );
233+
QCOMPARE( p1, QgsPoint( 2, 2, 7 ) );
234+
QCOMPARE( p2, QgsPoint( 4, 4, 5 ) );
235+
QCOMPARE( p3, QgsPoint( 2, 4, 6 ) );
236+
QVERIFY( tri.getTriangle( 2.5, 3.5, p1, n1, p2, n2, p3, n3 ) );
237+
QCOMPARE( p1, QgsPoint( 2, 2, 7 ) );
238+
QCOMPARE( p2, QgsPoint( 4, 4, 5 ) );
239+
QCOMPARE( p3, QgsPoint( 2, 4, 6 ) );
240+
QCOMPARE( n1, 4 );
241+
QCOMPARE( n2, 2 );
242+
QCOMPARE( n3, 3 );
243+
244+
QCOMPARE( tri.getOppositePoint( 0, 1 ), -1 );
245+
QCOMPARE( tri.getOppositePoint( 0, 2 ), -10 );
246+
QCOMPARE( tri.getOppositePoint( 0, 3 ), 4 );
247+
QCOMPARE( tri.getOppositePoint( 0, 4 ), 1 );
248+
QCOMPARE( tri.getOppositePoint( 1, 0 ), 4 );
249+
QCOMPARE( tri.getOppositePoint( 1, 2 ), -1 );
250+
QCOMPARE( tri.getOppositePoint( 1, 3 ), -10 );
251+
QCOMPARE( tri.getOppositePoint( 1, 4 ), 2 );
252+
QCOMPARE( tri.getOppositePoint( 2, 0 ), -10 );
253+
QCOMPARE( tri.getOppositePoint( 2, 1 ), 4 );
254+
QCOMPARE( tri.getOppositePoint( 2, 3 ), -1 );
255+
QCOMPARE( tri.getOppositePoint( 2, 4 ), 3 );
256+
QCOMPARE( tri.getOppositePoint( 3, 0 ), -1 );
257+
QCOMPARE( tri.getOppositePoint( 3, 1 ), -10 );
258+
QCOMPARE( tri.getOppositePoint( 3, 2 ), 4 );
259+
QCOMPARE( tri.getOppositePoint( 3, 4 ), 0 );
260+
QCOMPARE( tri.getOppositePoint( 4, 0 ), 3 );
261+
QCOMPARE( tri.getOppositePoint( 4, 1 ), 0 );
262+
QCOMPARE( tri.getOppositePoint( 4, 2 ), 1 );
263+
QCOMPARE( tri.getOppositePoint( 4, 3 ), 2 );
264+
265+
// QVERIFY( tri.getSurroundingTriangles( 0 ).empty() );
266+
}
267+
268+
QGSTEST_MAIN( TestQgsInterpolator )
269+
#include "testqgsinterpolator.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.