-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecompose_test.go
63 lines (56 loc) · 1.96 KB
/
decompose_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
package decompose
import (
"github.com/TopoSimplify/offset"
"github.com/TopoSimplify/opts"
"github.com/TopoSimplify/pln"
"github.com/franela/goblin"
"github.com/intdxdt/geom"
"github.com/intdxdt/iter"
"testing"
"time"
)
func TestDecompose(t *testing.T) {
var g = goblin.Goblin(t)
var id = iter.NewIgen(0)
g.Describe("hull decomposition", func() {
g.It("should test decomposition of a line", func() {
g.Timeout(1 * time.Hour)
var options = &opts.Opts{
Threshold: 50.0,
MinDist: 20.0,
RelaxDist: 30.0,
PlanarSelf: true,
AvoidNewSelfIntersects: true,
GeomRelation: true,
DistRelation: false,
DirRelation: false,
}
var sqrRelation = func(val float64) bool {
var t = options.Threshold
return val <= t*t
}
// self.relates = relations(self)
var wkt = "LINESTRING ( 470 480, 470 450, 490 430, 520 420, 540 440, 560 430, 580 420, 590 410, 630 400, 630 430, 640 460, 630 490, 630 520, 640 540, 660 560, 690 580, 700 600, 730 600, 750 570, 780 560, 790 550, 800 520, 830 500, 840 480, 850 460, 900 440, 920 440, 950 480, 990 480, 1000 520, 1000 570, 990 600, 1010 620, 1060 600 )"
var coords = geom.NewLineStringFromWKT(wkt).Coordinates
var poly = pln.Polyline{}
var inst = &dpTest{
Pln: pln.CreatePolyline(coords),
Opts: options,
ScoreFn: offset.SquareMaxOffset,
}
var decomp = offset.EpsilonDecomposition{
ScoreFn: inst.ScoreFn,
Relation: sqrRelation,
}
var hulls = DouglasPeucker(id, poly, decomp, hullGeom, inst)
g.Assert(len(hulls)).Equal(0)
inst.Opts.Threshold = 120
hulls = DouglasPeucker(id, inst.Polyline(), decomp, hullGeom, inst)
g.Assert(len(hulls)).Equal(4)
inst.Opts.Threshold = 150
hulls = DouglasPeucker(id, inst.Polyline(), decomp, hullGeom, inst)
g.Assert(len(hulls)).Equal(1)
g.Assert(hulls[0].Range.AsSlice()).Equal([]int{0, coords.Len() - 1})
})
})
}