Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for edge and corner cases #11

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading