-
Notifications
You must be signed in to change notification settings - Fork 28
/
rect.go
136 lines (103 loc) · 2.65 KB
/
rect.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package geojson
import (
"github.com/tidwall/geojson/geometry"
)
type Rect struct {
base geometry.Rect
}
func NewRect(rect geometry.Rect) *Rect {
return &Rect{base: rect}
}
func (g *Rect) ForEach(iter func(geom Object) bool) bool {
return iter(g)
}
func (g *Rect) Empty() bool {
return g.base.Empty()
}
func (g *Rect) Valid() bool {
return g.base.Valid()
}
func (g *Rect) Rect() geometry.Rect {
return g.base
}
func (g *Rect) Base() geometry.Rect {
return g.base
}
func (g *Rect) Center() geometry.Point {
return g.base.Center()
}
// Polygon returns the Rect as a GeoJSON Polygon.
func (g *Rect) Polygon() Object {
gPoly := new(Polygon)
gPoly.base.Exterior = g.base
return gPoly
}
func (g *Rect) AppendJSON(dst []byte) []byte {
return g.Polygon().AppendJSON(dst)
}
func (g *Rect) JSON() string {
return string(g.AppendJSON(nil))
}
func (g *Rect) MarshalJSON() ([]byte, error) {
return g.AppendJSON(nil), nil
}
func (g *Rect) String() string {
return string(g.AppendJSON(nil))
}
func (g *Rect) Contains(obj Object) bool {
return obj.Spatial().WithinRect(g.base)
}
func (g *Rect) Within(obj Object) bool {
return obj.Contains(g)
}
func (g *Rect) WithinRect(rect geometry.Rect) bool {
return rect.ContainsRect(g.base)
}
func (g *Rect) WithinPoint(point geometry.Point) bool {
return point.ContainsRect(g.base)
}
func (g *Rect) WithinLine(line *geometry.Line) bool {
return line.ContainsRect(g.base)
}
func (g *Rect) WithinPoly(poly *geometry.Poly) bool {
return poly.ContainsRect(g.base)
}
func (g *Rect) Intersects(obj Object) bool {
return obj.Spatial().IntersectsRect(g.base)
}
func (g *Rect) IntersectsPoint(point geometry.Point) bool {
return g.base.IntersectsPoint(point)
}
func (g *Rect) IntersectsRect(rect geometry.Rect) bool {
return g.base.IntersectsRect(rect)
}
func (g *Rect) IntersectsLine(line *geometry.Line) bool {
return g.base.IntersectsLine(line)
}
func (g *Rect) IntersectsPoly(poly *geometry.Poly) bool {
return g.base.IntersectsPoly(poly)
}
func (g *Rect) NumPoints() int {
return 2
}
func (g *Rect) Spatial() Spatial {
return g
}
func (g *Rect) Distance(obj Object) float64 {
return obj.Spatial().DistanceRect(g.base)
}
func (g *Rect) DistancePoint(point geometry.Point) float64 {
return geoDistancePoints(g.Center(), point)
}
func (g *Rect) DistanceRect(rect geometry.Rect) float64 {
return geoDistancePoints(g.Center(), rect.Center())
}
func (g *Rect) DistanceLine(line *geometry.Line) float64 {
return geoDistancePoints(g.Center(), line.Rect().Center())
}
func (g *Rect) DistancePoly(poly *geometry.Poly) float64 {
return geoDistancePoints(g.Center(), poly.Rect().Center())
}
func (g *Rect) Members() string {
return ""
}