/
testqgscircle.cpp
360 lines (325 loc) · 21.3 KB
/
testqgscircle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/***************************************************************************
testqgscircle.cpp
--------------------------------------
Date : August 2021
Copyright : (C) 2021 by Loïc Bartoletti
Email : loic dot bartoletti at oslandia 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 "qgstest.h"
#include <QObject>
#include <QString>
#include "qgscircle.h"
#include "qgsgeometryutils.h"
#include "qgslinestring.h"
#include "qgspoint.h"
#include "testgeometryutils.h"
class TestQgsCircle: public QObject
{
Q_OBJECT
private slots:
void circle();
};
void TestQgsCircle::circle()
{
//test constructors
QgsCircle circ1;
QVERIFY( circ1.center().isEmpty() );
QCOMPARE( circ1.radius(), 0.0 );
QCOMPARE( circ1.azimuth(), 0.0 );
QVERIFY( circ1.isEmpty() );
QgsCircle circ2( QgsPoint( 5, 10 ), 3 );
QVERIFY( circ2.center() == QgsPoint( 5, 10 ) );
QCOMPARE( circ2.radius(), 3.0 );
QCOMPARE( circ2.azimuth(), 0.0 );
QVERIFY( !circ2.isEmpty() );
QgsCircle circ3( QgsPoint( 5, 10 ), 3, 45 );
QVERIFY( circ3.center() == QgsPoint( 5, 10 ) );
QCOMPARE( circ3.radius(), 3.0 );
QCOMPARE( circ3.azimuth(), 45.0 );
QVERIFY( !circ3.isEmpty() );
//test toString
QCOMPARE( circ1.toString(), QString( "Empty" ) );
QCOMPARE( circ2.toString(), QString( "Circle (Center: Point (5 10), Radius: 3, Azimuth: 0)" ) );
QCOMPARE( circ3.toString(), QString( "Circle (Center: Point (5 10), Radius: 3, Azimuth: 45)" ) );
//test equality operator
QCOMPARE( QgsCircle().isEmpty(), QgsCircle( QgsPoint(), 0, 0 ).isEmpty() );
QVERIFY( !( QgsCircle() == QgsCircle( QgsPoint( 0, 0 ), 0, 0.0005 ) ) );
QVERIFY( circ2 == QgsCircle( QgsPoint( 5, 10 ), 3, 0 ) );
QVERIFY( circ2 != circ3 );
//test setter and getter
circ1.setAzimuth( 45 );
QCOMPARE( circ1.azimuth(), 45.0 );
circ1.setRadius( 50 );
QCOMPARE( circ1.radius(), 50.0 );
QCOMPARE( circ1.semiMajorAxis(), 50.0 );
QCOMPARE( circ1.semiMinorAxis(), 50.0 );
circ1.setSemiMajorAxis( 250 );
QCOMPARE( circ1.radius(), 250.0 );
QCOMPARE( circ1.semiMajorAxis(), 250.0 );
QCOMPARE( circ1.semiMinorAxis(), 250.0 );
circ1.setSemiMinorAxis( 8250 );
QCOMPARE( circ1.radius(), 8250.0 );
QCOMPARE( circ1.semiMajorAxis(), 8250.0 );
QCOMPARE( circ1.semiMinorAxis(), 8250.0 );
circ1.setCenter( QgsPoint( 5, 10 ) );
QVERIFY( circ1.center() == QgsPoint( 5, 10 ) );
QVERIFY( circ1.rcenter() == QgsPoint( 5, 10 ) );
circ1.rcenter() = QgsPoint( 25, 310 );
QVERIFY( circ1.center() == QgsPoint( 25, 310 ) );
//test "alt" constructors
// by2Points
QVERIFY( QgsCircle().from2Points( QgsPoint( -5, 0 ), QgsPoint( 5, 0 ) ) == QgsCircle( QgsPoint( 0, 0 ), 5, 90 ) );
QVERIFY( QgsCircle().from2Points( QgsPoint( 0, -5 ), QgsPoint( 0, 5 ) ) == QgsCircle( QgsPoint( 0, 0 ), 5, 0 ) );
// byExtent
QVERIFY( QgsCircle().fromExtent( QgsPoint( -5, -5 ), QgsPoint( 5, 5 ) ) == QgsCircle( QgsPoint( 0, 0 ), 5, 0 ) );
QVERIFY( QgsCircle().fromExtent( QgsPoint( -7.5, -2.5 ), QgsPoint( 2.5, 200.5 ) ).isEmpty() );
// by3Points
QVERIFY( QgsCircle().from3Points( QgsPoint( -5, 0 ), QgsPoint( 5, 0 ), QgsPoint( 0, 5 ) ) == QgsCircle( QgsPoint( 0, 0 ), 5 ) );
QVERIFY( QgsCircle().from3Points( QgsPoint( 5, 0 ), QgsPoint( 6, 0 ), QgsPoint( 7, 0 ) ).isEmpty() );
// byCenterDiameter
QVERIFY( QgsCircle().fromCenterDiameter( QgsPoint( 0, 0 ), 10 ) == QgsCircle( QgsPoint( 0, 0 ), 5, 0 ) );
QVERIFY( QgsCircle().fromCenterDiameter( QgsPoint( 2, 100 ), -10 ) == QgsCircle( QgsPoint( 2, 100 ), 5, 0 ) );
QVERIFY( QgsCircle().fromCenterDiameter( QgsPoint( 2, 100 ), -10, 45 ) == QgsCircle( QgsPoint( 2, 100 ), 5, 45 ) );
// byCenterPoint
QVERIFY( QgsCircle().fromCenterPoint( QgsPoint( 0, 0 ), QgsPoint( 5, 0 ) ) == QgsCircle( QgsPoint( 0, 0 ), 5, 90 ) );
QVERIFY( QgsCircle().fromCenterPoint( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ) ) == QgsCircle( QgsPoint( 0, 0 ), 5, 0 ) );
QVERIFY( QgsCircle().fromCenterPoint( QgsPoint( 0, 0 ), QgsPoint( 5 * std::cos( 45 * M_PI / 180.0 ), 5 * std::sin( 45 * M_PI / 180.0 ) ) ) == QgsCircle( QgsPoint( 0, 0 ), 5, 45 ) );
// by3Tangents
// Tangents from circle tri1( 0,0 ; 0,5 ), tri2( 0,0 ; 5,0 ), tri3( 5,0 ; 0,5 )
QgsCircle circ_tgt = QgsCircle().from3Tangents( QgsPoint( 0, 0 ), QgsPoint( 0, 1 ), QgsPoint( 2, 0 ), QgsPoint( 3, 0 ), QgsPoint( 5, 0 ), QgsPoint( 0, 5 ) );
QGSCOMPARENEARPOINT( circ_tgt.center(), QgsPoint( 1.4645, 1.4645 ), 0.0001 );
QGSCOMPARENEAR( circ_tgt.radius(), 1.4645, 0.0001 );
// with parallels
circ_tgt = QgsCircle().from3Tangents( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 1, 0 ), QgsPoint( 1, 5 ), QgsPoint( 5, 0 ), QgsPoint( 0, 5 ) );
QVERIFY( circ_tgt.isEmpty() );
circ_tgt = QgsCircle().from3Tangents( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 0 ), QgsPoint( 0, 5 ), QgsPoint( 1, 0 ), QgsPoint( 1, 5 ) );
QVERIFY( circ_tgt.isEmpty() );
circ_tgt = QgsCircle().from3Tangents( QgsPoint( 5, 0 ), QgsPoint( 0, 5 ), QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 1, 0 ), QgsPoint( 1, 5 ) );
QVERIFY( circ_tgt.isEmpty() );
// with 2 parallels
const double epsilon = 1e-8;
circ_tgt = QgsCircle().from3Tangents( QgsPoint( 0, 0 ), QgsPoint( 5, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 5 ), QgsPoint( 2.5, 0 ), QgsPoint( 7.5, 5 ) );
QVERIFY( circ_tgt.isEmpty() );
circ_tgt = QgsCircle().from3Tangents( QgsPoint( 0, 0 ), QgsPoint( 5, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 5 ), QgsPoint( 2.5, 0 ), QgsPoint( 7.5, 5 ), epsilon, QgsPoint( 2, 0 ) );
QGSCOMPARENEARPOINT( circ_tgt.center(), QgsPoint( 1.4645, 2.5000 ), 0.0001 );
QGSCOMPARENEAR( circ_tgt.radius(), 2.5, 0.0001 );
circ_tgt = QgsCircle().from3Tangents( QgsPoint( 0, 0 ), QgsPoint( 5, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 5 ), QgsPoint( 2.5, 0 ), QgsPoint( 7.5, 5 ), epsilon, QgsPoint( 3, 0 ) );
QGSCOMPARENEARPOINT( circ_tgt.center(), QgsPoint( 8.5355, 2.5000 ), 0.0001 );
QGSCOMPARENEAR( circ_tgt.radius(), 2.5, 0.0001 );
// from3tangentsMulti
QVector<QgsCircle> circles_tgt;
circles_tgt = QgsCircle().from3TangentsMulti( QgsPoint( 0, 0 ), QgsPoint( 5, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 5 ), QgsPoint( 2.5, 0 ), QgsPoint( 7.5, 5 ) );
QCOMPARE( circles_tgt.count(), 2 );
circ_tgt = circles_tgt.at( 0 );
QGSCOMPARENEARPOINT( circ_tgt.center(), QgsPoint( 8.5355, 2.5000 ), 0.0001 );
QGSCOMPARENEAR( circ_tgt.radius(), 2.5, 0.0001 );
circ_tgt = circles_tgt.at( 1 );
QGSCOMPARENEARPOINT( circ_tgt.center(), QgsPoint( 1.4645, 2.5000 ), 0.0001 );
QGSCOMPARENEAR( circ_tgt.radius(), 2.5, 0.0001 );
circles_tgt = QgsCircle().from3TangentsMulti( QgsPoint( 0, 0 ), QgsPoint( 5, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 5 ), QgsPoint( 2.5, 0 ), QgsPoint( 7.5, 5 ), epsilon, QgsPoint( 2, 0 ) );
QCOMPARE( circles_tgt.count(), 1 );
circ_tgt = circles_tgt.at( 0 );
QGSCOMPARENEARPOINT( circ_tgt.center(), QgsPoint( 1.4645, 2.5000 ), 0.0001 );
QGSCOMPARENEAR( circ_tgt.radius(), 2.5, 0.0001 );
circles_tgt = QgsCircle().from3TangentsMulti( QgsPoint( 0, 0 ), QgsPoint( 5, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 5 ), QgsPoint( 2.5, 0 ), QgsPoint( 7.5, 5 ), epsilon, QgsPoint( 3, 0 ) );
QCOMPARE( circles_tgt.count(), 1 );
circles_tgt = QgsCircle().from3TangentsMulti( QgsPoint( 0, 0 ), QgsPoint( 5, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 5 ), QgsPoint( 15, 5 ), QgsPoint( 20, 5 ) );
QVERIFY( circles_tgt.isEmpty() );
// check that Z dimension is ignored in case of using tangents
QgsCircle circ_tgt_z = QgsCircle().from3Tangents( QgsPoint( 0, 0, 333 ), QgsPoint( 0, 1, 1 ), QgsPoint( 2, 0, 2 ), QgsPoint( 3, 0, 3 ), QgsPoint( 5, 0, 4 ), QgsPoint( 0, 5, 5 ) );
QCOMPARE( circ_tgt_z.center().is3D(), false );
// minimalCircleFrom3points
QgsCircle minCircle3Points = QgsCircle().minimalCircleFrom3Points( QgsPoint( 0, 5 ), QgsPoint( 0, -5 ), QgsPoint( 1, 2 ) );
QGSCOMPARENEARPOINT( minCircle3Points.center(), QgsPoint( 0, 0 ), 0.0001 );
QGSCOMPARENEAR( minCircle3Points.radius(), 5.0, 0.0001 );
minCircle3Points = QgsCircle().minimalCircleFrom3Points( QgsPoint( 0, 5 ), QgsPoint( 5, 0 ), QgsPoint( -5, 0 ) );
QGSCOMPARENEARPOINT( minCircle3Points.center(), QgsPoint( 0, 0 ), 0.0001 );
QGSCOMPARENEAR( minCircle3Points.radius(), 5.0, 0.0001 );
// test quadrant
QgsPointSequence quad = QgsCircle( QgsPoint( 0, 0 ), 5 ).northQuadrant();
QVERIFY( quad.at( 0 ) == QgsPoint( 0, 5 ) );
QVERIFY( quad.at( 1 ) == QgsPoint( 5, 0 ) );
QVERIFY( quad.at( 2 ) == QgsPoint( 0, -5 ) );
QVERIFY( quad.at( 3 ) == QgsPoint( -5, 0 ) );
quad = QgsCircle( QgsPoint( 0, 0 ), 5, 123 ).northQuadrant();
QVERIFY( quad.at( 0 ) == QgsPoint( 0, 5 ) );
QVERIFY( quad.at( 1 ) == QgsPoint( 5, 0 ) );
QVERIFY( quad.at( 2 ) == QgsPoint( 0, -5 ) );
QVERIFY( quad.at( 3 ) == QgsPoint( -5, 0 ) );
quad = QgsCircle( QgsPoint( 0, 0 ), 5, 456 ).northQuadrant();
QVERIFY( quad.at( 0 ) == QgsPoint( 0, 5 ) );
QVERIFY( quad.at( 1 ) == QgsPoint( 5, 0 ) );
QVERIFY( quad.at( 2 ) == QgsPoint( 0, -5 ) );
QVERIFY( quad.at( 3 ) == QgsPoint( -5, 0 ) );
quad = QgsCircle( QgsPoint( 0, 0 ), 5, -789l ).northQuadrant();
QVERIFY( quad.at( 0 ) == QgsPoint( 0, 5 ) );
QVERIFY( quad.at( 1 ) == QgsPoint( 5, 0 ) );
QVERIFY( quad.at( 2 ) == QgsPoint( 0, -5 ) );
QVERIFY( quad.at( 3 ) == QgsPoint( -5, 0 ) );
//test conversion
QgsPointSequence ptsPol;
std::unique_ptr< QgsPolygon > pol( new QgsPolygon() );
// polygon
pol.reset( QgsCircle( QgsPoint( 0, 0 ), 5 ).toPolygon( 4 ) );
QCOMPARE( pol->numInteriorRings(), 0 );
QCOMPARE( pol->exteriorRing()->numPoints(), 5 );
pol->exteriorRing()->points( ptsPol );
QCOMPARE( ptsPol.length(), 5 );
QVERIFY( ptsPol.at( 0 ) == QgsPoint( 0, 5 ) );
QVERIFY( ptsPol.at( 1 ) == QgsPoint( 5, 0 ) );
QVERIFY( ptsPol.at( 2 ) == QgsPoint( 0, -5 ) );
QVERIFY( ptsPol.at( 3 ) == QgsPoint( -5, 0 ) );
QVERIFY( ptsPol.at( 4 ) == QgsPoint( 0, 5 ) );
// oriented
//45
double val = 5 * std::sin( M_PI / 4 );
pol.reset( QgsCircle( QgsPoint( 0, 0 ), 5, 45 ).toPolygon( 4 ) );
QCOMPARE( pol->numInteriorRings(), 0 );
QCOMPARE( pol->exteriorRing()->numPoints(), 5 );
pol->exteriorRing()->points( ptsPol );
QCOMPARE( ptsPol.length(), 5 );
QVERIFY( ptsPol.at( 0 ) == QgsPoint( val, val ) );
QVERIFY( ptsPol.at( 1 ) == QgsPoint( val, -val ) );
QVERIFY( ptsPol.at( 2 ) == QgsPoint( -val, -val ) );
QVERIFY( ptsPol.at( 3 ) == QgsPoint( -val, val ) );
QVERIFY( ptsPol.at( 4 ) == QgsPoint( val, val ) );
//135
pol.reset( QgsCircle( QgsPoint( 0, 0 ), 5, 135 ).toPolygon( 4 ) );
QCOMPARE( pol->numInteriorRings(), 0 );
QCOMPARE( pol->exteriorRing()->numPoints(), 5 );
pol->exteriorRing()->points( ptsPol );
QCOMPARE( ptsPol.length(), 5 );
QVERIFY( ptsPol.at( 0 ) == QgsPoint( val, -val ) );
QVERIFY( ptsPol.at( 1 ) == QgsPoint( -val, -val ) );
QVERIFY( ptsPol.at( 2 ) == QgsPoint( -val, val ) );
QVERIFY( ptsPol.at( 3 ) == QgsPoint( val, val ) );
QVERIFY( ptsPol.at( 4 ) == QgsPoint( val, -val ) );
//225
pol.reset( QgsCircle( QgsPoint( 0, 0 ), 5, 225 ).toPolygon( 4 ) );
QCOMPARE( pol->numInteriorRings(), 0 );
QCOMPARE( pol->exteriorRing()->numPoints(), 5 );
pol->exteriorRing()->points( ptsPol );
QCOMPARE( ptsPol.length(), 5 );
QVERIFY( ptsPol.at( 0 ) == QgsPoint( -val, -val ) );
QVERIFY( ptsPol.at( 1 ) == QgsPoint( -val, val ) );
QVERIFY( ptsPol.at( 2 ) == QgsPoint( val, val ) );
QVERIFY( ptsPol.at( 3 ) == QgsPoint( val, -val ) );
QVERIFY( ptsPol.at( 4 ) == QgsPoint( -val, -val ) );
//315
pol.reset( QgsCircle( QgsPoint( 0, 0 ), 5, 315 ).toPolygon( 4 ) );
QCOMPARE( pol->numInteriorRings(), 0 );
QCOMPARE( pol->exteriorRing()->numPoints(), 5 );
pol->exteriorRing()->points( ptsPol );
QCOMPARE( ptsPol.length(), 5 );
QVERIFY( ptsPol.at( 0 ) == QgsPoint( -val, val ) );
QVERIFY( ptsPol.at( 1 ) == QgsPoint( val, val ) );
QVERIFY( ptsPol.at( 2 ) == QgsPoint( val, -val ) );
QVERIFY( ptsPol.at( 3 ) == QgsPoint( -val, -val ) );
QVERIFY( ptsPol.at( 4 ) == QgsPoint( -val, val ) );
// circular arc
std::unique_ptr< QgsCircularString > cs( QgsCircle( QgsPoint( 0, 0 ), 5 ).toCircularString() );
QCOMPARE( cs->asWkt( 2 ), QString( "CircularString (0 5, 5 0, 0 -5, -5 0, 0 5)" ) );
cs.reset( QgsCircle( QgsPoint( 0, 0 ), 5 ).toCircularString( true ) );
QCOMPARE( cs->asWkt( 2 ), QString( "CircularString (0 5, 5 0, 0 -5, -5 0, 0 5)" ) );
cs.reset( QgsCircle( QgsPoint( 0, 0 ), 5, 315 ).toCircularString() );
QCOMPARE( cs->asWkt( 2 ), QString( "CircularString (0 5, 5 0, 0 -5, -5 0, 0 5)" ) );
cs.reset( QgsCircle( QgsPoint( 0, 0 ), 5, 315 ).toCircularString( true ) );
QCOMPARE( cs->asWkt( 2 ), QString( "CircularString (-3.54 3.54, 3.54 3.54, 3.54 -3.54, -3.54 -3.54, -3.54 3.54)" ) );
// bounding box
QVERIFY( QgsRectangle( QgsPointXY( -2.5, -2.5 ), QgsPointXY( 2.5, 2.5 ) ) == QgsCircle( QgsPoint( 0, 0 ), 2.5, 0 ).boundingBox() );
QVERIFY( QgsRectangle( QgsPointXY( -2.5, -2.5 ), QgsPointXY( 2.5, 2.5 ) ) == QgsCircle( QgsPoint( 0, 0 ), 2.5, 45 ).boundingBox() );
// area
QGSCOMPARENEAR( 314.1593, QgsCircle( QgsPoint( 0, 0 ), 10 ).area(), 0.0001 );
// perimeter
QGSCOMPARENEAR( 31.4159, QgsCircle( QgsPoint( 0, 0 ), 5 ).perimeter(), 0.0001 );
// contains
QgsPoint pc;
pc = QgsPoint( 1, 1 );
QVERIFY( QgsCircle( QgsPoint( 0, 0 ), 5 ).contains( pc ) );
pc = QgsPoint( 0, 5 );
QVERIFY( QgsCircle( QgsPoint( 0, 0 ), 5 ).contains( pc ) );
pc = QgsPoint( 6, 1 );
QVERIFY( !QgsCircle( QgsPoint( 0, 0 ), 5 ).contains( pc ) );
// intersections
QgsCircle ci1( QgsPoint( 0, 0 ), 1 );
QgsPoint int1;
QgsPoint int2;
QCOMPARE( ci1.intersections( QgsCircle( QgsPoint( 2, 0 ), 0.5 ), int1, int2 ), 0 );
QCOMPARE( ci1.intersections( QgsCircle( QgsPoint( 0.5, 0.1 ), 0.2 ), int1, int2 ), 0 );
// one intersection
QCOMPARE( ci1.intersections( QgsCircle( QgsPoint( 3, 0 ), 2 ), int1, int2 ), 1 );
QCOMPARE( int1, QgsPoint( 1, 0 ) );
QCOMPARE( int2, QgsPoint( 1, 0 ) );
// two intersections
ci1 = QgsCircle( QgsPoint( 5, 3 ), 2 );
QCOMPARE( ci1.intersections( QgsCircle( QgsPoint( 7, -1 ), 4 ), int1, int2 ), 2 );
QCOMPARE( int1.wkbType(), QgsWkbTypes::Point );
QGSCOMPARENEAR( int1.x(), 3.8, 0.001 );
QGSCOMPARENEAR( int1.y(), 1.4, 0.001 );
QCOMPARE( int2.wkbType(), QgsWkbTypes::Point );
QGSCOMPARENEAR( int2.x(), 7.0, 0.001 );
QGSCOMPARENEAR( int2.y(), 3.0, 0.001 );
// with z
ci1 = QgsCircle( QgsPoint( 5, 3, 11 ), 2 );
QCOMPARE( ci1.intersections( QgsCircle( QgsPoint( 7, -1, 5 ), 4 ), int1, int2, true ), 0 );
QCOMPARE( ci1.intersections( QgsCircle( QgsPoint( 7, -1, 11 ), 4 ), int1, int2, true ), 2 );
QCOMPARE( int1.wkbType(), QgsWkbTypes::PointZ );
QGSCOMPARENEAR( int1.x(), 3.8, 0.001 );
QGSCOMPARENEAR( int1.y(), 1.4, 0.001 );
QGSCOMPARENEAR( int1.z(), 11.0, 0.001 );
QCOMPARE( int2.wkbType(), QgsWkbTypes::PointZ );
QGSCOMPARENEAR( int2.x(), 7.0, 0.001 );
QGSCOMPARENEAR( int2.y(), 3.0, 0.001 );
QGSCOMPARENEAR( int2.z(), 11.0, 0.001 );
// tangent to point
QgsPointXY t1;
QgsPointXY t2;
QVERIFY( !QgsCircle( QgsPoint( 1, 2 ), 4 ).tangentToPoint( QgsPointXY( 1, 2 ), t1, t2 ) );
QVERIFY( QgsCircle( QgsPoint( 1, 2 ), 4 ).tangentToPoint( QgsPointXY( 8, 4 ), t1, t2 ) );
QGSCOMPARENEAR( t1.x(), 4.03, 0.01 );
QGSCOMPARENEAR( t1.y(), -0.61, 0.01 );
QGSCOMPARENEAR( t2.x(), 2.2, 0.01 );
QGSCOMPARENEAR( t2.y(), 5.82, 0.01 );
// two outer circle tangents
QgsPointXY l1p1, l1p2, l2p1, l2p2;
QCOMPARE( QgsCircle( QgsPoint( 1, 2 ), 4 ).outerTangents( QgsCircle( QgsPoint( 2, 3 ), 1 ), l1p1, l1p2, l2p1, l2p2 ), 0 );
QCOMPARE( QgsCircle( QgsPoint( 1, 2 ), 1 ).outerTangents( QgsCircle( QgsPoint( 10, 3 ), 4 ), l1p1, l1p2, l2p1, l2p2 ), 2 );
QGSCOMPARENEAR( l1p1.x(), 0.566, 0.01 );
QGSCOMPARENEAR( l1p1.y(), 2.901, 0.01 );
QGSCOMPARENEAR( l1p2.x(), 8.266, 0.01 );
QGSCOMPARENEAR( l1p2.y(), 6.604, 0.01 );
QGSCOMPARENEAR( l2p1.x(), 0.7749, 0.01 );
QGSCOMPARENEAR( l2p1.y(), 1.025, 0.01 );
QGSCOMPARENEAR( l2p2.x(), 9.099, 0.01 );
QGSCOMPARENEAR( l2p2.y(), -0.897, 0.01 );
// two inner circle tangents
QCOMPARE( QgsCircle( QgsPoint( 1, 2 ), 4 ).innerTangents( QgsCircle( QgsPoint( 2, 3 ), 1 ), l1p1, l1p2, l2p1, l2p2 ), 0 );
QCOMPARE( QgsCircle( QgsPoint( 0, 0 ), 4 ).innerTangents( QgsCircle( QgsPoint( 8, 0 ), 5 ), l1p1, l1p2, l2p1, l2p2 ), 0 );
QCOMPARE( QgsCircle( QgsPoint( 0, 0 ), 4 ).innerTangents( QgsCircle( QgsPoint( 8, 0 ), 4 ), l1p1, l1p2, l2p1, l2p2 ), 0 );
QCOMPARE( QgsCircle( QgsPoint( 1, 2 ), 1 ).innerTangents( QgsCircle( QgsPoint( 10, 3 ), 4 ), l1p1, l1p2, l2p1, l2p2 ), 2 );
QGSCOMPARENEAR( l1p1.x(), 7.437, 0.01 );
QGSCOMPARENEAR( l1p1.y(), 6.071, 0.01 );
QGSCOMPARENEAR( l1p2.x(), 1.641, 0.01 );
QGSCOMPARENEAR( l1p2.y(), 1.232, 0.01 );
QGSCOMPARENEAR( l2p1.x(), 8.173, 0.01 );
QGSCOMPARENEAR( l2p1.y(), -0.558, 0.01 );
QGSCOMPARENEAR( l2p2.x(), 1.457, 0.01 );
QGSCOMPARENEAR( l2p2.y(), 2.89, 0.01 );
// asGML3
QgsCircle exportCircle( QgsPoint( 1, 1 ), 3 );
QDomDocument doc( "gml" );
QString expectedGML3( QStringLiteral( "<Circle xmlns=\"gml\"><posList xmlns=\"gml\" srsDimension=\"2\">1 4 4 1 1 -2</posList></Circle>" ) );
QGSCOMPAREGML( elemToString( exportCircle.asGml3( doc ) ), expectedGML3 );
// asGML2
QString expectedGML2( QStringLiteral( "<LineString xmlns=\"gml\"><coordinates xmlns=\"gml\" cs=\",\" ts=\" \">1,4 1.05,4 1.1,4 1.16,4 1.21,3.99 1.26,3.99 1.31,3.98 1.37,3.98 1.42,3.97 1.47,3.96 1.52,3.95 1.57,3.94 1.62,3.93 1.67,3.92 1.73,3.91 1.78,3.9 1.83,3.88 1.88,3.87 1.93,3.85 1.98,3.84 2.03,3.82 2.08,3.8 2.12,3.78 2.17,3.76 2.22,3.74 2.27,3.72 2.32,3.7 2.36,3.67 2.41,3.65 2.45,3.62 2.5,3.6 2.55,3.57 2.59,3.54 2.63,3.52 2.68,3.49 2.72,3.46 2.76,3.43 2.81,3.4 2.85,3.36 2.89,3.33 2.93,3.3 2.97,3.26 3.01,3.23 3.05,3.19 3.08,3.16 3.12,3.12 3.16,3.08 3.19,3.05 3.23,3.01 3.26,2.97 3.3,2.93 3.33,2.89 3.36,2.85 3.4,2.81 3.43,2.76 3.46,2.72 3.49,2.68 3.52,2.63 3.54,2.59 3.57,2.55 3.6,2.5 3.62,2.45 3.65,2.41 3.67,2.36 3.7,2.32 3.72,2.27 3.74,2.22 3.76,2.17 3.78,2.12 3.8,2.08 3.82,2.03 3.84,1.98 3.85,1.93 3.87,1.88 3.88,1.83 3.9,1.78 3.91,1.73 3.92,1.67 3.93,1.62 3.94,1.57 3.95,1.52 3.96,1.47 3.97,1.42 3.98,1.37 3.98,1.31 3.99,1.26 3.99,1.21 4,1.16 4,1.1 4,1.05 4,1 4,0.95 4,0.9 4,0.84 3.99,0.79 3.99,0.74 3.98,0.69 3.98,0.63 3.97,0.58 3.96,0.53 3.95,0.48 3.94,0.43 3.93,0.38 3.92,0.33 3.91,0.27 3.9,0.22 3.88,0.17 3.87,0.12 3.85,0.07 3.84,0.02 3.82,-0.03 3.8,-0.08 3.78,-0.12 3.76,-0.17 3.74,-0.22 3.72,-0.27 3.7,-0.32 3.67,-0.36 3.65,-0.41 3.62,-0.45 3.6,-0.5 3.57,-0.55 3.54,-0.59 3.52,-0.63 3.49,-0.68 3.46,-0.72 3.43,-0.76 3.4,-0.81 3.36,-0.85 3.33,-0.89 3.3,-0.93 3.26,-0.97 3.23,-1.01 3.19,-1.05 3.16,-1.08 3.12,-1.12 3.08,-1.16 3.05,-1.19 3.01,-1.23 2.97,-1.26 2.93,-1.3 2.89,-1.33 2.85,-1.36 2.81,-1.4 2.76,-1.43 2.72,-1.46 2.68,-1.49 2.63,-1.52 2.59,-1.54 2.55,-1.57 2.5,-1.6 2.45,-1.62 2.41,-1.65 2.36,-1.67 2.32,-1.7 2.27,-1.72 2.22,-1.74 2.17,-1.76 2.12,-1.78 2.08,-1.8 2.03,-1.82 1.98,-1.84 1.93,-1.85 1.88,-1.87 1.83,-1.88 1.78,-1.9 1.73,-1.91 1.67,-1.92 1.62,-1.93 1.57,-1.94 1.52,-1.95 1.47,-1.96 1.42,-1.97 1.37,-1.98 1.31,-1.98 1.26,-1.99 1.21,-1.99 1.16,-2 1.1,-2 1.05,-2 1,-2 0.95,-2 0.9,-2 0.84,-2 0.79,-1.99 0.74,-1.99 0.69,-1.98 0.63,-1.98 0.58,-1.97 0.53,-1.96 0.48,-1.95 0.43,-1.94 0.38,-1.93 0.33,-1.92 0.27,-1.91 0.22,-1.9 0.17,-1.88 0.12,-1.87 0.07,-1.85 0.02,-1.84 -0.03,-1.82 -0.08,-1.8 -0.12,-1.78 -0.17,-1.76 -0.22,-1.74 -0.27,-1.72 -0.32,-1.7 -0.36,-1.67 -0.41,-1.65 -0.45,-1.62 -0.5,-1.6 -0.55,-1.57 -0.59,-1.54 -0.63,-1.52 -0.68,-1.49 -0.72,-1.46 -0.76,-1.43 -0.81,-1.4 -0.85,-1.36 -0.89,-1.33 -0.93,-1.3 -0.97,-1.26 -1.01,-1.23 -1.05,-1.19 -1.08,-1.16 -1.12,-1.12 -1.16,-1.08 -1.19,-1.05 -1.23,-1.01 -1.26,-0.97 -1.3,-0.93 -1.33,-0.89 -1.36,-0.85 -1.4,-0.81 -1.43,-0.76 -1.46,-0.72 -1.49,-0.68 -1.52,-0.63 -1.54,-0.59 -1.57,-0.55 -1.6,-0.5 -1.62,-0.45 -1.65,-0.41 -1.67,-0.36 -1.7,-0.32 -1.72,-0.27 -1.74,-0.22 -1.76,-0.17 -1.78,-0.12 -1.8,-0.08 -1.82,-0.03 -1.84,0.02 -1.85,0.07 -1.87,0.12 -1.88,0.17 -1.9,0.22 -1.91,0.27 -1.92,0.33 -1.93,0.38 -1.94,0.43 -1.95,0.48 -1.96,0.53 -1.97,0.58 -1.98,0.63 -1.98,0.69 -1.99,0.74 -1.99,0.79 -2,0.84 -2,0.9 -2,0.95 -2,1 -2,1.05 -2,1.1 -2,1.16 -1.99,1.21 -1.99,1.26 -1.98,1.31 -1.98,1.37 -1.97,1.42 -1.96,1.47 -1.95,1.52 -1.94,1.57 -1.93,1.62 -1.92,1.67 -1.91,1.73 -1.9,1.78 -1.88,1.83 -1.87,1.88 -1.85,1.93 -1.84,1.98 -1.82,2.03 -1.8,2.08 -1.78,2.12 -1.76,2.17 -1.74,2.22 -1.72,2.27 -1.7,2.32 -1.67,2.36 -1.65,2.41 -1.62,2.45 -1.6,2.5 -1.57,2.55 -1.54,2.59 -1.52,2.63 -1.49,2.68 -1.46,2.72 -1.43,2.76 -1.4,2.81 -1.36,2.85 -1.33,2.89 -1.3,2.93 -1.26,2.97 -1.23,3.01 -1.19,3.05 -1.16,3.08 -1.12,3.12 -1.08,3.16 -1.05,3.19 -1.01,3.23 -0.97,3.26 -0.93,3.3 -0.89,3.33 -0.85,3.36 -0.81,3.4 -0.76,3.43 -0.72,3.46 -0.68,3.49 -0.63,3.52 -0.59,3.54 -0.55,3.57 -0.5,3.6 -0.45,3.62 -0.41,3.65 -0.36,3.67 -0.32,3.7 -0.27,3.72 -0.22,3.74 -0.17,3.76 -0.12,3.78 -0.08,3.8 -0.03,3.82 0.02,3.84 0.07,3.85 0.12,3.87 0.17,3.88 0.22,3.9 0.27,3.91 0.33,3.92 0.38,3.93 0.43,3.94 0.48,3.95 0.53,3.96 0.58,3.97 0.63,3.98 0.69,3.98 0.74,3.99 0.79,3.99 0.84,4 0.9,4 0.95,4 1,4</coordinates></LineString>" ) );
QGSCOMPAREGML( elemToString( exportCircle.asGml2( doc, 2 ) ), expectedGML2 );
}
QGSTEST_MAIN( TestQgsCircle )
#include "testqgscircle.moc"