Skip to content

Commit

Permalink
Merge pull request #11 from PDOK/tests-edge-cases
Browse files Browse the repository at this point in the history
add tests for edge and corner cases
  • Loading branch information
roelarents authored Nov 10, 2023
2 parents 5721a8e + e5407d3 commit ee216e5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
2 changes: 0 additions & 2 deletions snap/pointindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ type quadrantToCheck struct {
i int // quadrant number
certain bool // whether the line certainly intersects this quadrant (true) or needs to be checked (false)
mutex bool // if the line intersects this one, the other cannot be intersected
// TODO account for edge cases: lines on, or stopping at the exclusive extent edges
// TODO not only exclusive lines but also last/first point on a line
}

// getInfiniteQuadrant determines in which infinite quadrant the point lies
Expand Down
61 changes: 59 additions & 2 deletions snap/pointindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,71 @@ func TestPointIndex_SnapClosestPoints(t *testing.T) {
{110907.6453125, 504428.8065625}, // horizontal line still here
},
},
{
name: "corner case topleft",
matrix: newSimpleTileMatrix(4.0, 2, 1.0),
poly: geom.Polygon{{{1.5, 1.5}, {2.5, 1.5}, {2.5, 2.5}, {1.5, 2.5}}},
line: geom.Line{{0.0, 4.0}, {1.0, 3.0}},
want: [][2]float64{},
},
{
name: "corner case topright",
matrix: newSimpleTileMatrix(4.0, 2, 1.0),
poly: geom.Polygon{{{1.5, 1.5}, {2.5, 1.5}, {2.5, 2.5}, {1.5, 2.5}}},
line: geom.Line{{4.0, 4.0}, {3.0, 3.0}},
want: [][2]float64{},
},
{
name: "corner case bottomright",
matrix: newSimpleTileMatrix(4.0, 2, 1.0),
poly: geom.Polygon{{{1.5, 1.5}, {2.5, 1.5}, {2.5, 2.5}, {1.5, 2.5}}},
line: geom.Line{{4.0, 0.0}, {3.0, 1.0}},
want: [][2]float64{},
},
{
name: "corner case bottomleft",
matrix: newSimpleTileMatrix(4.0, 2, 1.0),
poly: geom.Polygon{{{1.5, 1.5}, {2.5, 1.5}, {2.5, 2.5}, {1.5, 2.5}}},
line: geom.Line{{0.0, 0.0}, {1.0, 1.0}},
want: [][2]float64{{1.5, 1.5}},
},
{
name: "edge case top",
matrix: newSimpleTileMatrix(4.0, 2, 1.0),
poly: geom.Polygon{{{1.5, 1.5}, {2.5, 1.5}, {2.5, 2.5}, {1.5, 2.5}}},
line: geom.Line{{0.0, 3.0}, {4.0, 3.0}},
want: [][2]float64{},
},
{
name: "edge case right",
matrix: newSimpleTileMatrix(4.0, 2, 1.0),
poly: geom.Polygon{{{1.5, 1.5}, {2.5, 1.5}, {2.5, 2.5}, {1.5, 2.5}}},
line: geom.Line{{3.0, 4.0}, {3.0, 0.0}},
want: [][2]float64{},
},
{
name: "edge case bottom",
matrix: newSimpleTileMatrix(4.0, 2, 1.0),
poly: geom.Polygon{{{1.5, 1.5}, {2.5, 1.5}, {2.5, 2.5}, {1.5, 2.5}}},
line: geom.Line{{0.0, 1.0}, {4.0, 1.0}},
want: [][2]float64{{1.5, 1.5}, {2.5, 1.5}},
},
{
name: "edge case left",
matrix: newSimpleTileMatrix(4.0, 2, 1.0),
poly: geom.Polygon{{{1.5, 1.5}, {2.5, 1.5}, {2.5, 2.5}, {1.5, 2.5}}},
line: geom.Line{{1.0, 0.0}, {1.0, 4.0}},
want: [][2]float64{{1.5, 1.5}, {1.5, 2.5}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ix := NewPointIndexFromTileMatrix(tt.matrix)
ix.InsertPolygon(&tt.poly)
ix.toWkt(os.Stdout)
poly := tt.poly
ix.InsertPolygon(&poly)
got := ix.SnapClosestPoints(tt.line)
if !assert.EqualValues(t, tt.want, got) {
ix.toWkt(os.Stdout)
t.Errorf("SnapClosestPoints() = %v, want %v", got, tt.want)
}
})
Expand Down

0 comments on commit ee216e5

Please sign in to comment.