-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathclip.go
39 lines (34 loc) · 961 Bytes
/
clip.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
package mvt
import (
"github.com/paulmach/orb"
"github.com/paulmach/orb/clip"
)
var (
// MapboxGLDefaultExtentBound holds the default mapbox vector tile bounds used by mapbox-gl.
// (https://www.mapbox.com/mapbox-gl-js/style-spec/#sources-vector)
MapboxGLDefaultExtentBound = orb.Bound{
Min: orb.Point{-1 * DefaultExtent, -1 * DefaultExtent},
Max: orb.Point{2*DefaultExtent - 1, 2*DefaultExtent - 1},
}
)
// Clip will clip all geometries in all layers to the given bounds.
func (ls Layers) Clip(box orb.Bound) {
for _, l := range ls {
l.Clip(box)
}
}
// Clip will clip all geometries in this layer to the given bounds.
// Will remove features that clip to an empty geometry, modifies the
// layer.Features slice in place.
func (l *Layer) Clip(box orb.Bound) {
at := 0
for _, f := range l.Features {
g := clip.Geometry(box, f.Geometry)
if g != nil {
f.Geometry = g
l.Features[at] = f
at++
}
}
l.Features = l.Features[:at]
}