-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathclip_test.go
80 lines (72 loc) · 1.88 KB
/
clip_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
package mvt
import (
"reflect"
"testing"
"github.com/paulmach/orb"
"github.com/paulmach/orb/geojson"
)
func TestLayersClip(t *testing.T) {
cases := []struct {
name string
bound orb.Bound
input Layers
output Layers
}{
{
name: "clips polygon and line",
input: Layers{&Layer{
Features: []*geojson.Feature{
geojson.NewFeature(orb.Polygon([]orb.Ring{
{
{-10, 10}, {0, 10}, {10, 10}, {10, 5}, {10, -5},
{10, -10}, {20, -10}, {20, 10}, {40, 10}, {40, 20},
{20, 20}, {20, 40}, {10, 40}, {10, 20}, {5, 20},
{-10, 20},
},
})),
geojson.NewFeature(orb.LineString{{-15, 0}, {66, 0}}),
},
}},
output: Layers{&Layer{
Features: []*geojson.Feature{
geojson.NewFeature(orb.Polygon([]orb.Ring{
{
{0, 10}, {0, 10}, {10, 10}, {10, 5}, {10, 0},
{20, 0}, {20, 10}, {30, 10}, {30, 20}, {20, 20},
{20, 30}, {10, 30}, {10, 20}, {5, 20}, {0, 20},
},
})),
geojson.NewFeature(orb.LineString{{0, 0}, {30, 0}}),
},
}},
bound: orb.Bound{Min: orb.Point{0, 0}, Max: orb.Point{30, 30}},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
tc.input.Clip(tc.bound)
if !reflect.DeepEqual(tc.input, tc.output) {
t.Errorf("incorrect clip")
t.Logf("%v", tc.input)
t.Logf("%v", tc.output)
}
})
}
}
func TestLayerClip_empty(t *testing.T) {
layer := &Layer{
Features: []*geojson.Feature{
geojson.NewFeature(orb.Polygon{{
{-1, 1}, {0, 1}, {1, 1}, {1, 5}, {1, -5},
}}),
geojson.NewFeature(orb.LineString{{55, 0}, {66, 0}}),
},
}
layer.Clip(orb.Bound{Min: orb.Point{50, -10}, Max: orb.Point{70, 10}})
if v := len(layer.Features); v != 1 {
t.Errorf("incorrect number of features: %d", v)
}
if v := layer.Features[0].Geometry.GeoJSONType(); v != "LineString" {
t.Errorf("kept the wrong geometry: %v", layer.Features[0].Geometry)
}
}