aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/paulmach/orb/internal/length/length_test.go
blob: d4fc49bf780e1f65f9c0a58587af0af07eb7e29e (plain) (blame)
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
package length

import (
	"math"
	"testing"

	"github.com/paulmach/orb"
)

func Distance(a, b orb.Point) float64 {
	dx := a[0] - b[0]
	dy := a[1] - b[1]
	return math.Sqrt(dx*dx + dy*dy)
}

func TestLength(t *testing.T) {
	for _, g := range orb.AllGeometries {
		// should not panic with unsupported type
		Length(g, Distance)
	}

	ls := orb.LineString{{0, 0}, {3, 0}, {3, 4}, {0, 0}}
	if l := Length(ls, Distance); l != 12 {
		t.Errorf("incorrect length: %v != %v", l, 12)
	}

	mls := orb.MultiLineString{
		{{0, 0}, {3, 0}, {3, 4}, {0, 0}},
		{{5, 0}, {5, 7}},
	}
	if l := Length(mls, Distance); l != 19 {
		t.Errorf("incorrect length: %v != %v", l, 19)
	}

	p := orb.Polygon{{{0, 0}, {3, 0}, {3, 4}, {0, 0}}}
	if l := Length(p, Distance); l != 12 {
		t.Errorf("incorrect length: %v != %v", l, 12)
	}

	mp := orb.MultiPolygon{
		{{{0, 0}, {3, 0}, {3, 4}, {0, 0}}},
		{{{5, 0}, {8, 0}, {8, 4}, {5, 0}}},
	}
	if l := Length(mp, Distance); l != 24 {
		t.Errorf("incorrect length: %v != %v", l, 24)
	}
}