forked from paulmach/orb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
51 lines (42 loc) · 1.12 KB
/
example_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
package simplify_test
import (
"fmt"
"github.com/Smadarl/orb"
"github.com/Smadarl/orb/planar"
"github.com/Smadarl/orb/simplify"
)
func ExampleDouglasPeuckerSimplifier() {
// +
// \
// \
// +
// \
// \
// +-----+
original := orb.LineString{{0, 0}, {2, 0}, {1, 1}, {0, 2}}
// low threshold just removes the colinear point
reduced := simplify.DouglasPeucker(0.0).Simplify(original.Clone())
fmt.Println(reduced)
// high threshold just leaves start and end
reduced = simplify.DouglasPeucker(2).Simplify(original)
fmt.Println(reduced)
// Output:
// [[0 0] [2 0] [0 2]]
// [[0 0] [0 2]]
}
func ExampleRadialSimplifier() {
// +
// \
// \
// +
// |
// +--+
original := orb.LineString{{0, 0}, {1, 0}, {1, 1}, {0, 2}}
// will remove the points within 1.0 of the previous point
// in this case just the second point
reduced := simplify.Radial(planar.Distance, 1.0).Simplify(original.Clone())
fmt.Println(reduced)
// will remove the 2nd and 3rd point since it's within 1.5 or the first point.
reduced = simplify.Radial(planar.Distance, 1.5).Simplify(original)
fmt.Println(reduced)
}