-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
topology_operations_test.go
538 lines (494 loc) · 17.2 KB
/
topology_operations_test.go
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package geomfn
import (
"fmt"
"math"
"testing"
"github.com/cockroachdb/cockroach/pkg/geo"
"github.com/cockroachdb/errors"
"github.com/stretchr/testify/require"
"github.com/twpayne/go-geom"
)
func TestBoundary(t *testing.T) {
testCases := []struct {
wkt string
expected string
}{
{"POINT EMPTY", "POINT EMPTY"},
{"POINT (1 1)", "GEOMETRYCOLLECTION EMPTY"},
{"LINESTRING EMPTY", "LINESTRING EMPTY"},
{"LINESTRING (100 150, 50 60, 70 80, 160 170)", "MULTIPOINT (100 150, 160 170)"},
{"SRID=4000;LINESTRING (100 150, 50 60, 70 80, 160 170)", "SRID=4000;MULTIPOINT (100 150, 160 170)"},
{
"POLYGON ((10 130, 50 190, 110 190, 140 150, 150 80, 100 10, 20 40, 10 130), (70 40, 100 50, 120 80, 80 110, 50 90, 70 40))",
"MULTILINESTRING ((10 130, 50 190, 110 190, 140 150, 150 80, 100 10, 20 40, 10 130), (70 40, 100 50, 120 80, 80 110, 50 90, 70 40))",
},
}
for _, tc := range testCases {
t.Run(tc.wkt, func(t *testing.T) {
g, err := geo.ParseGeometry(tc.wkt)
require.NoError(t, err)
ret, err := Boundary(g)
require.NoError(t, err)
wkt, err := geo.SpatialObjectToEWKT(ret.SpatialObject(), 0)
require.NoError(t, err)
require.EqualValues(t, tc.expected, wkt)
})
}
}
func TestCentroid(t *testing.T) {
testCases := []struct {
wkt string
expected string
}{
{"POINT(1.0 1.0)", "POINT (1.0 1.0)"},
{"SRID=4326;POINT(1.0 1.0)", "SRID=4326;POINT (1.0 1.0)"},
{"LINESTRING(1.0 1.0, 2.0 2.0, 3.0 3.0)", "POINT (2.0 2.0)"},
{"POLYGON((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 0.0))", "POINT (0.666666666666667 0.333333333333333)"},
{"POLYGON((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 0.0), (0.1 0.1, 0.2 0.1, 0.2 0.2, 0.1 0.1))", "POINT (0.671717171717172 0.335353535353535)"},
{"MULTIPOINT((1.0 1.0), (2.0 2.0))", "POINT (1.5 1.5)"},
{"MULTILINESTRING((1.0 1.0, 2.0 2.0, 3.0 3.0), (6.0 6.0, 7.0 6.0))", "POINT (3.17541743733684 3.04481549985497)"},
{"MULTIPOLYGON(((3.0 3.0, 4.0 3.0, 4.0 4.0, 3.0 3.0)), ((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 0.0), (0.1 0.1, 0.2 0.1, 0.2 0.2, 0.1 0.1)))", "POINT (2.17671691792295 1.84187604690117)"},
{"GEOMETRYCOLLECTION (POINT (40 10),LINESTRING (10 10, 20 20, 10 40),POLYGON ((40 40, 20 45, 45 30, 40 40)))", "POINT (35 38.3333333333333)"},
}
for _, tc := range testCases {
t.Run(tc.wkt, func(t *testing.T) {
g, err := geo.ParseGeometry(tc.wkt)
require.NoError(t, err)
ret, err := Centroid(g)
require.NoError(t, err)
expected, err := geo.ParseGeometry(tc.expected)
require.NoError(t, err)
requireGeometryWithinEpsilon(t, expected, ret, 2e-10)
})
}
}
func TestMinimumBoundingCircle(t *testing.T) {
testCases := []struct {
wkt string
expectedRadius float64
expectedCoords []float64
}{
{
wkt: "POLYGON((26426 65078,26531 65242,26075 65136,26096 65427,26426 65078))",
expectedRadius: 247.436,
expectedCoords: []float64{26284.842, 65267.115},
},
{
wkt: "GEOMETRYCOLLECTION (POLYGON((1 0, 1 1, 0 1, 0 0, 1 0)), POLYGON((1 1, 2 1, 2 2, 1 2, 1 1)))",
expectedRadius: 1.414,
expectedCoords: []float64{1, 1},
},
{
wkt: "GEOMETRYCOLLECTION (POLYGON((0 1.5, 1 3, -1 3, 0 1.5)), POINT(1 0))",
expectedRadius: 1.803,
expectedCoords: []float64{0, 1.5},
},
{
wkt: "GEOMETRYCOLLECTION (LINESTRING(0 0, 4 0), POINT(0 4))",
expectedRadius: 2.828,
expectedCoords: []float64{2, 2},
},
{
wkt: "POLYGON((2 0, 2 2, 0 2, 0 0, 2 0))",
expectedRadius: 1.414,
expectedCoords: []float64{1, 1},
},
}
for index, tt := range testCases {
t.Run(fmt.Sprintf("%d", index), func(t *testing.T) {
g, err := geo.ParseGeometry(tt.wkt)
require.NoError(t, err)
_, center, radius, err := MinimumBoundingCircle(g)
require.NoError(t, err)
precision := 1000.0
require.Equal(t, tt.expectedRadius, math.Round(radius*precision)/precision)
geomT, err := center.AsGeomT()
require.NoError(t, err)
c := geomT.(*geom.Point)
centerCoords := []float64{math.Round(precision*c.Coords()[0]) / precision, math.Round(precision*c.Coords()[1]) / precision}
require.Equal(t, tt.expectedCoords, centerCoords)
})
}
}
func TestConvexHull(t *testing.T) {
testCases := []struct {
wkt string
expected string
}{
{
"GEOMETRYCOLLECTION (POINT (40 10),LINESTRING (10 10, 20 20, 10 40),POLYGON ((40 40, 20 45, 45 30, 40 40)))",
"POLYGON((10 10,10 40,20 45,40 40,45 30,40 10,10 10))",
},
{
"SRID=4326;GEOMETRYCOLLECTION (POINT (40 10),LINESTRING (10 10, 20 20, 10 40),POLYGON ((40 40, 20 45, 45 30, 40 40)))",
"SRID=4326;POLYGON((10 10,10 40,20 45,40 40,45 30,40 10,10 10))",
},
{
"MULTILINESTRING((100 190,10 8),(150 10, 20 30))",
"POLYGON((10 8,20 30,100 190,150 10,10 8))",
},
}
for _, tc := range testCases {
t.Run(tc.wkt, func(t *testing.T) {
g, err := geo.ParseGeometry(tc.wkt)
require.NoError(t, err)
ret, err := ConvexHull(g)
require.NoError(t, err)
expected, err := geo.ParseGeometry(tc.expected)
require.NoError(t, err)
require.Equal(t, expected, ret)
})
}
}
func TestDifference(t *testing.T) {
testCases := []struct {
wkt1 string
wkt2 string
expected string
}{
{"POINT EMPTY", "LINESTRING EMPTY", "POINT EMPTY"},
{"LINESTRING EMPTY", "POINT EMPTY", "LINESTRING EMPTY"},
{"LINESTRING (50 100, 50 200)", "LINESTRING(50 50, 50 150)", "LINESTRING (50 150, 50 200)"},
{"SRID=4000;LINESTRING (50 100, 50 200)", "SRID=4000;LINESTRING(50 50, 50 150)", "SRID=4000;LINESTRING (50 150, 50 200)"},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%v - %v", tc.wkt2, tc.wkt1), func(t *testing.T) {
g1, err := geo.ParseGeometry(tc.wkt1)
require.NoError(t, err)
g2, err := geo.ParseGeometry(tc.wkt2)
require.NoError(t, err)
ret, err := Difference(g1, g2)
require.NoError(t, err)
wkt, err := geo.SpatialObjectToEWKT(ret.SpatialObject(), 0)
require.NoError(t, err)
require.EqualValues(t, tc.expected, wkt)
})
}
t.Run("errors if SRIDs mismatch", func(t *testing.T) {
_, err := Difference(mismatchingSRIDGeometryA, mismatchingSRIDGeometryB)
requireMismatchingSRIDError(t, err)
})
}
func TestSimplify(t *testing.T) {
testCases := []struct {
wkt string
tolerance float64
expected string
}{
{
wkt: "POLYGON ((20 10, 10 20, 20 20, 20 30, 30 30, 30 20, 40 20, 40 10, 30 0, 20 0, 20 10))",
tolerance: 5,
expected: "POLYGON ((20 10, 10 20, 30 30, 40 10, 30 00, 20 0, 20 10))",
},
{
wkt: "POLYGON ((5 7, 2 5, 5 4, 13 4, 18 7, 16 11, 7 9, 11 7, 5 7), (13 8, 13 6, 14 6, 15 9, 13 8))",
tolerance: 3,
expected: "POLYGON ((5 7, 16 11, 18 7, 2 5, 5 7))",
},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%s_%f", tc.wkt, tc.tolerance), func(t *testing.T) {
g, err := geo.ParseGeometry(tc.wkt)
require.NoError(t, err)
ret, err := Simplify(g, tc.tolerance)
require.NoError(t, err)
expected, err := geo.ParseGeometry(tc.expected)
require.NoError(t, err)
require.Equal(t, expected, ret)
})
}
}
func TestSimplifyPreserveTopology(t *testing.T) {
testCases := []struct {
wkt string
tolerance float64
expected string
}{
{
wkt: "POLYGON ((5 7, 2 5, 5 4, 13 4, 18 7, 16 11, 7 9, 11 7, 5 7), (13 8, 13 6, 14 6, 15 9, 13 8))",
tolerance: 3,
expected: "POLYGON ((5 7, 2 5, 13 4, 18 7, 16 11, 5 7), (13 8, 13 6, 14 6, 15 9, 13 8))",
},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%s_%f", tc.wkt, tc.tolerance), func(t *testing.T) {
g, err := geo.ParseGeometry(tc.wkt)
require.NoError(t, err)
ret, err := SimplifyPreserveTopology(g, tc.tolerance)
require.NoError(t, err)
expected, err := geo.ParseGeometry(tc.expected)
require.NoError(t, err)
require.Equal(t, expected, ret)
})
}
}
func TestPointOnSurface(t *testing.T) {
testCases := []struct {
wkt string
expected string
}{
{"POINT(1.0 1.0)", "POINT (1.0 1.0)"},
{"SRID=4326;POINT(1.0 1.0)", "SRID=4326;POINT (1.0 1.0)"},
{"LINESTRING(1.0 1.0, 2.0 2.0, 3.0 3.0)", "POINT (2.0 2.0)"},
{"POLYGON((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 0.0))", "POINT(0.75 0.5)"},
{"POLYGON((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 0.0), (0.1 0.1, 0.2 0.1, 0.2 0.2, 0.1 0.1))", "POINT(0.8 0.6)"},
{"MULTIPOINT((1.0 1.0), (2.0 2.0))", "POINT (1 1)"},
{"MULTILINESTRING((1.0 1.0, 2.0 2.0, 3.0 3.0), (6.0 6.0, 7.0 6.0))", "POINT (2 2)"},
{"MULTIPOLYGON(((3.0 3.0, 4.0 3.0, 4.0 4.0, 3.0 3.0)), ((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 0.0), (0.1 0.1, 0.2 0.1, 0.2 0.2, 0.1 0.1)))", "POINT(3.75 3.5)"},
{"GEOMETRYCOLLECTION (POINT (40 10),LINESTRING (10 10, 20 20, 10 40),POLYGON ((40 40, 20 45, 45 30, 40 40)))", "POINT(39.5833333333333 35)"},
}
for _, tc := range testCases {
t.Run(tc.wkt, func(t *testing.T) {
g, err := geo.ParseGeometry(tc.wkt)
require.NoError(t, err)
ret, err := PointOnSurface(g)
require.NoError(t, err)
expected, err := geo.ParseGeometry(tc.expected)
require.NoError(t, err)
requireGeometryWithinEpsilon(t, expected, ret, 2e-10)
})
}
}
func TestIntersection(t *testing.T) {
testCases := []struct {
a geo.Geometry
b geo.Geometry
expected geo.Geometry
}{
{rightRect, rightRect, geo.MustParseGeometry("POLYGON ((1 0, 0 0, 0 1, 1 1, 1 0))")},
{geo.MustParseGeometry("LINESTRING EMPTY"), geo.MustParseGeometry("POINT(5 5)"), geo.MustParseGeometry("LINESTRING EMPTY")},
{geo.MustParseGeometry("POINT(5 5)"), geo.MustParseGeometry("LINESTRING EMPTY"), geo.MustParseGeometry("LINESTRING EMPTY")},
{rightRect, rightRectPoint, rightRectPoint},
{rightRectPoint, rightRectPoint, rightRectPoint},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("tc:%d", i), func(t *testing.T) {
g, err := Intersection(tc.a, tc.b)
require.NoError(t, err)
require.Equal(t, tc.expected, g)
})
}
t.Run("errors if SRIDs mismatch", func(t *testing.T) {
_, err := Intersection(mismatchingSRIDGeometryA, mismatchingSRIDGeometryB)
requireMismatchingSRIDError(t, err)
})
}
func TestUnion(t *testing.T) {
testCases := []struct {
a geo.Geometry
b geo.Geometry
expected geo.Geometry
}{
{rightRect, rightRect, geo.MustParseGeometry("POLYGON ((1 0, 0 0, 0 1, 1 1, 1 0))")},
{rightRect, rightRectPoint, geo.MustParseGeometry("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))")},
{rightRectPoint, rightRectPoint, rightRectPoint},
{leftRect, rightRect, geo.MustParseGeometry("POLYGON ((0 0, -1 0, -1 1, 0 1, 1 1, 1 0, 0 0))")},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("tc:%d", i), func(t *testing.T) {
g, err := Union(tc.a, tc.b)
require.NoError(t, err)
require.Equal(t, tc.expected, g)
})
}
t.Run("errors if SRIDs mismatch", func(t *testing.T) {
_, err := Union(mismatchingSRIDGeometryA, mismatchingSRIDGeometryB)
requireMismatchingSRIDError(t, err)
})
}
func TestSymDifference(t *testing.T) {
testCases := []struct {
a geo.Geometry
b geo.Geometry
expected geo.Geometry
}{
{rightRect, rightRect, emptyRect},
{leftRect, rightRect, geo.MustParseGeometry("POLYGON((0 0, -1 0, -1 1, 0 1, 1 1, 1 0, 0 0))")},
{leftRect, overlappingRightRect, geo.MustParseGeometry("MULTIPOLYGON(((-0.1 0, -1 0, -1 1, -0.1 1, -0.1 0)), ((0 0, 0 1, 1 1, 1 0, 0 0)))")},
{rightRect, rightRectPoint, geo.MustParseGeometry("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))")},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("tc:%d", i), func(t *testing.T) {
g, err := SymDifference(tc.a, tc.b)
require.NoError(t, err)
require.Equal(t, tc.expected, g)
})
}
t.Run("errors if SRIDs mismatch", func(t *testing.T) {
_, err := SymDifference(mismatchingSRIDGeometryA, mismatchingSRIDGeometryB)
requireMismatchingSRIDError(t, err)
})
}
func TestSharedPaths(t *testing.T) {
type args struct {
a geo.Geometry
b geo.Geometry
}
tests := []struct {
name string
args args
want geo.Geometry
wantErr error
}{
{
name: "shared path between a MultiLineString and LineString",
args: args{
a: geo.MustParseGeometry("MULTILINESTRING((26 125,26 200,126 200,126 125,26 125)," +
"(51 150,101 150,76 175,51 150))"),
b: geo.MustParseGeometry("LINESTRING(151 100,126 156.25,126 125,90 161, 76 175)"),
},
want: geo.MustParseGeometry("GEOMETRYCOLLECTION(MULTILINESTRING((126 156.25,126 125)," +
"(101 150,90 161),(90 161,76 175)),MULTILINESTRING EMPTY)"),
},
{
name: "shared path between a Linestring and MultiLineString",
args: args{
a: geo.MustParseGeometry("LINESTRING(76 175,90 161,126 125,126 156.25,151 100)"),
b: geo.MustParseGeometry("MULTILINESTRING((26 125,26 200,126 200,126 125,26 125), " +
"(51 150,101 150,76 175,51 150))"),
},
want: geo.MustParseGeometry("GEOMETRYCOLLECTION(MULTILINESTRING EMPTY," +
"MULTILINESTRING((76 175,90 161),(90 161,101 150),(126 125,126 156.25)))"),
},
{
name: "shared path between non-lineal geometry",
args: args{
a: geo.MustParseGeometry("MULTIPOINT((0 0), (3 2))"),
b: geo.MustParseGeometry("MULTIPOINT((0 1), (1 2))"),
},
wantErr: errors.New("geos error: IllegalArgumentException: Geometry is not lineal"),
},
{
name: "no shared path between two Linestring",
args: args{
a: geo.MustParseGeometry("LINESTRING(0 0, 10 0)"),
b: geo.MustParseGeometry("LINESTRING(-10 5, 10 5)"),
},
want: geo.MustParseGeometry("GEOMETRYCOLLECTION(MULTILINESTRING EMPTY, MULTILINESTRING EMPTY)"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := SharedPaths(tt.args.a, tt.args.b)
if tt.wantErr != nil && tt.wantErr.Error() != err.Error() {
t.Errorf("SharedPaths() error = %v, wantErr %v", err, tt.wantErr)
return
}
require.Equal(t, tt.want, got)
})
}
}
func TestUnaryUnion(t *testing.T) {
tests := []struct {
name string
arg geo.Geometry
want geo.Geometry
}{
{
"linstring",
geo.MustParseGeometry("LINESTRING(0 0, 10 10, 0 10, 10 0)"),
geo.MustParseGeometry("MULTILINESTRING((0 0,5 5),(5 5,10 10,0 10,5 5),(5 5,10 0))"),
},
{
"linestring, nothing to union",
geo.MustParseGeometry("LINESTRING(0 0, -10 10, 0 10)"),
geo.MustParseGeometry("LINESTRING(0 0, -10 10, 0 10)"),
},
{
"multipolygon to dissolve",
geo.MustParseGeometry("MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)), ((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))"),
geo.MustParseGeometry("MULTIPOLYGON(((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)),((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)))"),
},
{
"geometry collection of different types",
geo.MustParseGeometry("GEOMETRYCOLLECTION(POINT(1 0),POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)))"),
geo.MustParseGeometry("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))"),
},
{
"geometry collection with duplicates",
geo.MustParseGeometry("GEOMETRYCOLLECTION(POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)),POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)))"),
geo.MustParseGeometry("POLYGON((1 0,0 0,0 1,1 1,1 0))"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := UnaryUnion(tt.arg)
require.NoError(t, err)
require.Equal(t, tt.want, got)
})
}
}
func TestMinimumRotatedRectangle(t *testing.T) {
tests := []struct {
name string
arg geo.Geometry
want geo.Geometry
}{
{
"empty multipoint",
geo.MustParseGeometry("MULTIPOINT EMPTY"),
geo.MustParseGeometry("POLYGON EMPTY"),
},
{
"multipoint, must return the valid polygon",
geo.MustParseGeometry("MULTIPOINT ((0 0), (-1 -1), (3 2))"),
geo.MustParseGeometry("POLYGON((3 2,2.88 2.16,-1.12 -0.84,-1 -1,3 2))"),
},
{
"multipoint, must give linestring in case of degenerate input",
geo.MustParseGeometry("MULTIPOINT ((0 0), (-2 0), (1 0))"),
geo.MustParseGeometry("LINESTRING (-2 0, 1 0)"),
},
{
"multipoint, must give point in case of degenerate input",
geo.MustParseGeometry("MULTIPOINT ((0 0), (0 0), (0 0))"),
geo.MustParseGeometry("POINT (0 0)"),
},
{
"point, must return the valid point",
geo.MustParseGeometry("POINT (1 1)"),
geo.MustParseGeometry("POINT (1 1)"),
},
{
"linestring, must return the valid polygon",
geo.MustParseGeometry("LINESTRING (0 0, 50 200, 100 0)"),
geo.MustParseGeometry("POLYGON ((0 0,94.1176470588235 -23.5294117647059,144.117647058824 176.470588235294,50 200,0 0))"),
},
{
"polygon, must return the valid polygon",
geo.MustParseGeometry("POLYGON ((0 0,1 -2,1 1,5 2,0 0))"),
geo.MustParseGeometry("POLYGON ((-0.5 -0.5,1 -2,5 2,3.5 3.5,-0.5 -0.5))"),
},
{
"multilinestring, must give linestring in case of degenerate input",
geo.MustParseGeometry("MULTILINESTRING ((1 1, 2 2))"),
geo.MustParseGeometry("LINESTRING (1 1,2 2)"),
},
{
"multipolygon, must give linestring in case of degenerate input",
geo.MustParseGeometry("MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))"),
geo.MustParseGeometry("LINESTRING (1 2,5 6)"),
},
{
"multilinestring, must give linestring in case of degenerate input",
geo.MustParseGeometry("GEOMETRYCOLLECTION (MULTIPOINT (1 1, 2 2))"),
geo.MustParseGeometry("LINESTRING (1 1,2 2)"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := MinimumRotatedRectangle(tt.arg)
require.NoError(t, err)
require.Equal(t, true, EqualsExact(got, tt.want, 1e-6))
})
}
}