forked from paulmach/orb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
line_string.go
40 lines (33 loc) · 1.05 KB
/
line_string.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
package orb
// LineString represents a set of points to be thought of as a polyline.
type LineString []Point
// GeoJSONType returns the GeoJSON type for the object.
func (ls LineString) GeoJSONType() string {
return "LineString"
}
// Dimensions returns 1 because a LineString is a 1d object.
func (ls LineString) Dimensions() int {
return 1
}
// Reverse will reverse the line string.
// This is done inplace, ie. it modifies the original data.
func (ls LineString) Reverse() {
l := len(ls) - 1
for i := 0; i <= l/2; i++ {
ls[i], ls[l-i] = ls[l-i], ls[i]
}
}
// Bound returns a rect around the line string. Uses rectangular coordinates.
func (ls LineString) Bound() Bound {
return MultiPoint(ls).Bound()
}
// Equal compares two line strings. Returns true if lengths are the same
// and all points are Equal.
func (ls LineString) Equal(lineString LineString) bool {
return MultiPoint(ls).Equal(MultiPoint(lineString))
}
// Clone returns a new copy of the line string.
func (ls LineString) Clone() LineString {
ps := MultiPoint(ls)
return LineString(ps.Clone())
}