Skip to content

Commit

Permalink
Merge 602468d into 18cb502
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstace committed Mar 31, 2023
2 parents 18cb502 + 602468d commit 3e9a7bc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

- Add a `BoundingDiagonal` method to the `Envelope` type.

- Return an error rather than panicking when certain internal assumptions are
violated during DCEL extraction.

## v0.41.0

2022-11-15
Expand Down
32 changes: 32 additions & 0 deletions geom/alg_set_op_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1491,3 +1491,35 @@ func TestBinaryOpOutputOrdering(t *testing.T) {
})
}
}

func TestErrInsteadOfPanic(t *testing.T) {
for i, tc := range []struct {
input1 string
input2 string
op func(_, _ geom.Geometry) (geom.Geometry, error)
}{
{
input1: `POLYGON((
-83.58253051 32.73168239,
-83.59843118 32.74617142,
-83.70048117 32.63984372,
-83.58253051 32.73168239
))`,
input2: `POLYGON((
-83.70047745 32.63984661,
-83.68891846 32.59896320,
-83.58253417 32.73167955,
-83.70047745 32.63984661
))`,
op: geom.Union,
},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
g1 := geomFromWKT(t, tc.input1)
g2 := geomFromWKT(t, tc.input2)
_, err := tc.op(g1, g2)
expectErr(t, err)
t.Log(err)
})
}
}
4 changes: 4 additions & 0 deletions geom/dcel_extract_geometry.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (d *doublyConnectedEdgeList) extractPolygons(include func([2]bool) bool) ([
})
}

if len(rings) == 0 {
return nil, fmt.Errorf("no rings to extract")
}

// Construct the polygon.
orderPolygonRings(rings)
poly, err := NewPolygon(rings)
Expand Down
34 changes: 28 additions & 6 deletions internal/cmprefimpl/cmpgeos/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,11 @@ var skipIntersection = map[string]bool{
"POLYGON((1 0,-0.9 -0.2,-1 -0.0000000000000032310891488651735,-0.9 0.2,1 0))": true,
"LINESTRING(0.5 0,0.5000000000000001 0.5)": true,
"LINESTRING(0.5 1,0.5000000000000001 0.5)": true,

// Cause simplefeatures DCEL operations to fail with "no rings" error. See
// https://github.com/peterstace/simplefeatures/pull/497 for details.
"POLYGON((-83.58253051 32.73168239,-83.59843118 32.74617142,-83.70048117 32.63984372,-83.58253051 32.73168239))": true,
"POLYGON((-83.70047745 32.63984661,-83.68891846 32.5989632,-83.58253417 32.73167955,-83.70047745 32.63984661))": true,
}

var skipDifference = map[string]bool{
Expand All @@ -728,6 +733,11 @@ var skipDifference = map[string]bool{
"POLYGON((0.9 0.1,0.9 1,0.901921471959677 1.019509032201613,0.9076120467488714 1.0382683432365092,0.9168530387697456 1.0555570233019602,0.9292893218813453 1.0707106781186548,0.9444429766980398 1.0831469612302547,0.961731656763491 1.0923879532511287,0.9804909677983872 1.0980785280403231,1 1.1,1.0195090322016127 1.0980785280403231,1.038268343236509 1.0923879532511287,1.0555570233019602 1.0831469612302547,1.0707106781186546 1.0707106781186548,1.0831469612302544 1.0555570233019602,1.0923879532511287 1.0382683432365092,1.0980785280403231 1.019509032201613,1.1 1,1.0717462120245884 0.06467514421272098,0.9353248557872769 -0.07174621202458649,0 -0.1,-0.019509032201612955 -0.09807852804032302,-0.03826834323650912 -0.09238795325112863,-0.055557023301960363 -0.08314696123025443,-0.07071067811865482 -0.07071067811865468,-0.08314696123025457 -0.055557023301960155,-0.0923879532511287 -0.03826834323650893,-0.09807852804032306 -0.01950903220161279,-0.1 0.000000000000000012246467991473533,-0.09807852804032305 0.01950903220161282,-0.0923879532511287 0.03826834323650895,-0.08314696123025456 0.055557023301960176,-0.07071067811865482 0.0707106781186547,-0.05555702330196031 0.08314696123025447,-0.0382683432365091 0.09238795325112864,-0.019509032201612972 0.09807852804032302,0 0.1,0.9 0.1))": true,
"POLYGON((0.9 0.1,0.9 1,0.901921471959677 1.019509032201613,0.9076120467488714 1.0382683432365092,0.9168530387697456 1.0555570233019602,0.9292893218813453 1.0707106781186548,0.9444429766980398 1.0831469612302547,0.961731656763491 1.0923879532511287,0.9804909677983872 1.0980785280403231,1 1.1,1.0195090322016127 1.0980785280403231,1.038268343236509 1.0923879532511287,1.0555570233019602 1.0831469612302547,1.0707106781186546 1.0707106781186548,1.0831469612302544 1.0555570233019602,1.0923879532511287 1.0382683432365092,1.0980785280403231 1.019509032201613,1.1 1,1.1 0,1 -0.1,0 -0.1,-0.019509032201612955 -0.09807852804032302,-0.03826834323650912 -0.09238795325112863,-0.055557023301960363 -0.08314696123025443,-0.07071067811865482 -0.07071067811865468,-0.08314696123025457 -0.055557023301960155,-0.0923879532511287 -0.03826834323650893,-0.09807852804032306 -0.01950903220161279,-0.1 0.000000000000000012246467991473533,-0.09807852804032305 0.01950903220161282,-0.0923879532511287 0.03826834323650895,-0.08314696123025456 0.055557023301960176,-0.07071067811865482 0.0707106781186547,-0.05555702330196031 0.08314696123025447,-0.0382683432365091 0.09238795325112864,-0.019509032201612972 0.09807852804032302,0 0.1,0.9 0.1))": true,
"POLYGON((0.9 0.1,0.9 1,0.901921471959677 1.019509032201613,0.9076120467488714 1.0382683432365092,0.9168530387697456 1.0555570233019602,0.9292893218813453 1.0707106781186548,0.9444429766980398 1.0831469612302547,0.961731656763491 1.0923879532511287,0.9804909677983872 1.0980785280403231,1 1.1,1.0195090322016127 1.0980785280403231,1.038268343236509 1.0923879532511287,1.0555570233019602 1.0831469612302547,1.0707106781186546 1.0707106781186548,1.0831469612302544 1.0555570233019602,1.0923879532511287 1.0382683432365092,1.0980785280403231 1.019509032201613,1.1 1,1.1 0,1.0980785280403231 -0.019509032201612826,1.0923879532511287 -0.03826834323650898,1.0831469612302544 -0.05555702330196022,1.0707106781186548 -0.07071067811865475,1.0555570233019602 -0.08314696123025453,1.038268343236509 -0.09238795325112868,1.019509032201613 -0.09807852804032305,1 -0.1,0 -0.1,-0.019509032201612955 -0.09807852804032302,-0.03826834323650912 -0.09238795325112863,-0.055557023301960363 -0.08314696123025443,-0.07071067811865482 -0.07071067811865468,-0.08314696123025457 -0.055557023301960155,-0.0923879532511287 -0.03826834323650893,-0.09807852804032306 -0.01950903220161279,-0.1 0.000000000000000012246467991473533,-0.09807852804032305 0.01950903220161282,-0.0923879532511287 0.03826834323650895,-0.08314696123025456 0.055557023301960176,-0.07071067811865482 0.0707106781186547,-0.05555702330196031 0.08314696123025447,-0.0382683432365091 0.09238795325112864,-0.019509032201612972 0.09807852804032302,0 0.1,0.9 0.1))": true,

// Cause simplefeatures DCEL operations to fail with "no rings" error. See
// https://github.com/peterstace/simplefeatures/pull/497 for details.
"POLYGON((-83.58253051 32.73168239,-83.59843118 32.74617142,-83.70048117 32.63984372,-83.58253051 32.73168239))": true,
"POLYGON((-83.70047745 32.63984661,-83.68891846 32.5989632,-83.58253417 32.73167955,-83.70047745 32.63984661))": true,
}

var skipSymDiff = map[string]bool{
Expand All @@ -736,6 +746,18 @@ var skipSymDiff = map[string]bool{
"LINESTRING(1 0,0.5000000000000001 0.5,0 1)": true,
"MULTILINESTRING((0 0,0.5 0.5),(0.5 0.5,1 1),(0 1,0.3333333333 0.6666666667),(0.3333333333 0.6666666667,0.5 0.5),(0.5 0.5,1 0))": true,
"MULTILINESTRING((0 1,0.3333333333 0.6666666667),(0.3333333333 0.6666666667,1 0))": true,

// Cause simplefeatures DCEL operations to fail with "no rings" error. See
// https://github.com/peterstace/simplefeatures/pull/497 for details.
"POLYGON((-83.58253051 32.73168239,-83.59843118 32.74617142,-83.70048117 32.63984372,-83.58253051 32.73168239))": true,
"POLYGON((-83.70047745 32.63984661,-83.68891846 32.5989632,-83.58253417 32.73167955,-83.70047745 32.63984661))": true,
}

var skipUnion = map[string]bool{
// Cause simplefeatures DCEL operations to fail with "no rings" error. See
// https://github.com/peterstace/simplefeatures/pull/497 for details.
"POLYGON((-83.58253051 32.73168239,-83.59843118 32.74617142,-83.70048117 32.63984372,-83.58253051 32.73168239))": true,
"POLYGON((-83.70047745 32.63984661,-83.68891846 32.5989632,-83.58253417 32.73167955,-83.70047745 32.63984661))": true,
}

func checkDCELOperations(h *Handle, g1, g2 geom.Geometry, log *log.Logger) error {
Expand All @@ -754,7 +776,7 @@ func checkDCELOperations(h *Handle, g1, g2 geom.Geometry, log *log.Logger) error
"Union",
func(g1, g2 geom.Geometry) (geom.Geometry, error) { return geom.Union(g1, g2) },
func(g1, g2 geom.Geometry) (geom.Geometry, error) { return h.union(g1, g2) },
nil,
skipUnion,
},
{
"Intersection",
Expand Down Expand Up @@ -802,11 +824,6 @@ func checkDCELOp(
return nil
}

got, err := op(g1, g2)
if err != nil {
return err
}

// Some geometries give results that are not topologically equivalent to
// those from GEOS. These have been checked manually, and decided that the
// difference is acceptable (they typically have to do with different
Expand All @@ -817,6 +834,11 @@ func checkDCELOp(
return nil
}

got, err := op(g1, g2)
if err != nil {
return err
}

want, err := refImpl(g1, g2)
if err != nil {
if err == errInvalidAccordingToGEOS {
Expand Down

0 comments on commit 3e9a7bc

Please sign in to comment.