Skip to content

Commit 562f098

Browse files
committed
Fix polygon validation function
Some previous changes to improve the behaviour in case of degenerate poygons introduced a bug in the polygon validation function. The changes are rolled back.
1 parent 65268ed commit 562f098

File tree

3 files changed

+81
-15
lines changed

3 files changed

+81
-15
lines changed

Diff for: expected/poly.out

+43-6
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,17 @@ LINE 1: SELECT spoly '{(0d,0d),(10d,10d),(0d,10d),(10d,0d)}';
403403
^
404404
--- degenerate polygons -----
405405
SELECT spoly '{(0d,1d),(0d,2d),(0d,3d)}';
406-
ERROR: spherepoly_from_array: a line segment overlaps or polygon too large
407-
LINE 1: SELECT spoly '{(0d,1d),(0d,2d),(0d,3d)}';
408-
^
406+
spoly
407+
---------------------------------
408+
{(0d , 1d),(0d , 2d),(0d , 3d)}
409+
(1 row)
410+
409411
SELECT spoly '{(1d,0d),(2d,0d),(3d,0d)}';
410-
ERROR: spherepoly_from_array: a line segment overlaps or polygon too large
411-
LINE 1: SELECT spoly '{(1d,0d),(2d,0d),(3d,0d)}';
412-
^
412+
spoly
413+
---------------------------------
414+
{(1d , 0d),(2d , 0d),(3d , 0d)}
415+
(1 row)
416+
413417
--- functions
414418
SELECT npoints( spoly '{(10d,0d),(10d,1d),(15d,0d)}');
415419
npoints
@@ -1874,3 +1878,36 @@ SELECT spoly_is_convex(NULL);
18741878
f
18751879
(1 row)
18761880

1881+
-- Complex but valid polygon
1882+
SELECT '{
1883+
(3.30474723646012 , 1.08600456205300),
1884+
(3.30341855309927 , 1.08577960186707),
1885+
(3.30341054542378 , 1.08578643990271),
1886+
(3.30297351563319 , 1.08633534556428),
1887+
(3.30357156120003 , 1.08643683957210),
1888+
(3.30358891855857 , 1.08643995044436),
1889+
(3.30360894676365 , 1.08644306147078),
1890+
(3.30361829343581 , 1.08644430596871),
1891+
(3.30362630482521 , 1.08644555030213),
1892+
(3.30364633346451 , 1.08644866102000),
1893+
(3.30365300940335 , 1.08645052692055),
1894+
(3.30366102096957 , 1.08645177113937),
1895+
(3.30367036769496 , 1.08645363721023),
1896+
(3.30367837934959 , 1.08645488137174),
1897+
(3.30368906174976 , 1.08645612569695),
1898+
(3.30370107936906 , 1.08645799183673),
1899+
(3.30370642025712 , 1.08645985750225),
1900+
(3.30373179124734 , 1.08646358962156),
1901+
(3.30374514456618 , 1.08646545561358),
1902+
(3.30410706158729 , 1.08652886672786),
1903+
(3.30427803417922 , 1.08655868846497),
1904+
(3.30429673329093 , 1.08655930694968),
1905+
(3.30432478121775 , 1.08655930174652),
1906+
(3.30433278932944 , 1.08655308246640),
1907+
(3.30446348355532 , 1.08638330933224)
1908+
}'::spoly;
1909+
spoly
1910+
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1911+
{(3.3047472 , 1.0860046),(3.3034186 , 1.0857796),(3.3034105 , 1.0857864),(3.3029735 , 1.0863353),(3.3035716 , 1.0864368),(3.3035889 , 1.08644),(3.3036089 , 1.0864431),(3.3036183 , 1.0864443),(3.3036263 , 1.0864456),(3.3036463 , 1.0864487),(3.303653 , 1.0864505),(3.303661 , 1.0864518),(3.3036704 , 1.0864536),(3.3036784 , 1.0864549),(3.3036891 , 1.0864561),(3.3037011 , 1.086458),(3.3037064 , 1.0864599),(3.3037318 , 1.0864636),(3.3037451 , 1.0864655),(3.3041071 , 1.0865289),(3.304278 , 1.0865587),(3.3042967 , 1.0865593),(3.3043248 , 1.0865593),(3.3043328 , 1.0865531),(3.3044635 , 1.0863833)}
1912+
(1 row)
1913+

Diff for: sql/poly.sql

+29
Original file line numberDiff line numberDiff line change
@@ -650,3 +650,32 @@ SELECT spoly_is_convex(spoly'{(53d 45m 35.0s, 37d 6m 30.0s), (52d 21m 36.0s, 41d
650650
SELECT spoly_is_convex(spoly'{(12d,32d),(34d,12d),(59d,21d),(69d,21d)}');
651651
SELECT spoly_is_convex(spoly'{(12d,32d),(34d,12d),(59d,21d),(34d,40d)}');
652652
SELECT spoly_is_convex(NULL);
653+
654+
-- Complex but valid polygon
655+
SELECT '{
656+
(3.30474723646012 , 1.08600456205300),
657+
(3.30341855309927 , 1.08577960186707),
658+
(3.30341054542378 , 1.08578643990271),
659+
(3.30297351563319 , 1.08633534556428),
660+
(3.30357156120003 , 1.08643683957210),
661+
(3.30358891855857 , 1.08643995044436),
662+
(3.30360894676365 , 1.08644306147078),
663+
(3.30361829343581 , 1.08644430596871),
664+
(3.30362630482521 , 1.08644555030213),
665+
(3.30364633346451 , 1.08644866102000),
666+
(3.30365300940335 , 1.08645052692055),
667+
(3.30366102096957 , 1.08645177113937),
668+
(3.30367036769496 , 1.08645363721023),
669+
(3.30367837934959 , 1.08645488137174),
670+
(3.30368906174976 , 1.08645612569695),
671+
(3.30370107936906 , 1.08645799183673),
672+
(3.30370642025712 , 1.08645985750225),
673+
(3.30373179124734 , 1.08646358962156),
674+
(3.30374514456618 , 1.08646545561358),
675+
(3.30410706158729 , 1.08652886672786),
676+
(3.30427803417922 , 1.08655868846497),
677+
(3.30429673329093 , 1.08655930694968),
678+
(3.30432478121775 , 1.08655930174652),
679+
(3.30433278932944 , 1.08655308246640),
680+
(3.30446348355532 , 1.08638330933224)
681+
}'::spoly;

Diff for: src/line.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,15 @@ sline_sline_pos(const SLine *l1, const SLine *l2)
496496
vector3d_spoint(&p[2], &v[1][0]);
497497
vector3d_spoint(&p[3], &v[1][1]);
498498

499+
/* check connected lines */
500+
if (FPgt(il2->length, 0.0) && (vector3d_eq(&v[0][0], &v[1][0]) ||
501+
vector3d_eq(&v[0][0], &v[1][1]) ||
502+
vector3d_eq(&v[0][1], &v[1][0]) ||
503+
vector3d_eq(&v[0][1], &v[1][1])))
504+
{
505+
return PGS_LINE_CONNECT;
506+
}
507+
499508
/* Check, sl2 is at equator */
500509
if (FPzero(p[2].lat) && FPzero(p[3].lat))
501510
{
@@ -520,15 +529,6 @@ sline_sline_pos(const SLine *l1, const SLine *l2)
520529
return PGS_LINE_AVOID;
521530
}
522531

523-
/* check connected lines */
524-
if (FPgt(il2->length, 0.0) && (vector3d_eq(&v[0][0], &v[1][0]) ||
525-
vector3d_eq(&v[0][0], &v[1][1]) ||
526-
vector3d_eq(&v[0][1], &v[1][0]) ||
527-
vector3d_eq(&v[0][1], &v[1][1])))
528-
{
529-
return PGS_LINE_CONNECT;
530-
}
531-
532532
/* Now sl2 is not at equator */
533533

534534
if (FPle(il2->length, seg_length))

0 commit comments

Comments
 (0)