forked from tidwall/geojson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rect.go
157 lines (126 loc) · 2.99 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package geojson
import (
"github.com/tidwall/geojson/geometry"
)
// Rect ...
type Rect struct {
base geometry.Rect
}
// NewRect ...
func NewRect(rect geometry.Rect) *Rect {
return &Rect{base: rect}
}
// ForEach ...
func (g *Rect) ForEach(iter func(geom Object) bool) bool {
return iter(g)
}
// Empty ...
func (g *Rect) Empty() bool {
return g.base.Empty()
}
// Valid ...
func (g *Rect) Valid() bool {
return g.base.Valid()
}
// Rect ...
func (g *Rect) Rect() geometry.Rect {
return g.base
}
// Base ...
func (g *Rect) Base() geometry.Rect {
return g.base
}
// Center ...
func (g *Rect) Center() geometry.Point {
return g.base.Center()
}
// AppendJSON ...
func (g *Rect) AppendJSON(dst []byte) []byte {
var gPoly Polygon
gPoly.base.Exterior = g.base
return gPoly.AppendJSON(dst)
}
// JSON ...
func (g *Rect) JSON() string {
return string(g.AppendJSON(nil))
}
// MarshalJSON ...
func (g *Rect) MarshalJSON() ([]byte, error) {
return g.AppendJSON(nil), nil
}
// String ...
func (g *Rect) String() string {
return string(g.AppendJSON(nil))
}
// Contains ...
func (g *Rect) Contains(obj Object) bool {
return obj.Spatial().WithinRect(g.base)
}
// Within ...
func (g *Rect) Within(obj Object) bool {
return obj.Contains(g)
}
// WithinRect ...
func (g *Rect) WithinRect(rect geometry.Rect) bool {
return rect.ContainsRect(g.base)
}
// WithinPoint ...
func (g *Rect) WithinPoint(point geometry.Point) bool {
return point.ContainsRect(g.base)
}
// WithinLine ...
func (g *Rect) WithinLine(line *geometry.Line) bool {
return line.ContainsRect(g.base)
}
// WithinPoly ...
func (g *Rect) WithinPoly(poly *geometry.Poly) bool {
return poly.ContainsRect(g.base)
}
// Intersects ...
func (g *Rect) Intersects(obj Object) bool {
return obj.Spatial().IntersectsRect(g.base)
}
// IntersectsPoint ...
func (g *Rect) IntersectsPoint(point geometry.Point) bool {
return g.base.IntersectsPoint(point)
}
// IntersectsRect ...
func (g *Rect) IntersectsRect(rect geometry.Rect) bool {
return g.base.IntersectsRect(rect)
}
// IntersectsLine ...
func (g *Rect) IntersectsLine(line *geometry.Line) bool {
return g.base.IntersectsLine(line)
}
// IntersectsPoly ...
func (g *Rect) IntersectsPoly(poly *geometry.Poly) bool {
return g.base.IntersectsPoly(poly)
}
// NumPoints ...
func (g *Rect) NumPoints() int {
return 2
}
// Spatial ...
func (g *Rect) Spatial() Spatial {
return g
}
// Distance ...
func (g *Rect) Distance(obj Object) float64 {
return obj.Spatial().DistanceRect(g.base)
}
// DistancePoint ...
func (g *Rect) DistancePoint(point geometry.Point) float64 {
return geoDistancePoints(g.Center(), point)
}
// DistanceRect ...
func (g *Rect) DistanceRect(rect geometry.Rect) float64 {
return geoDistancePoints(g.Center(), rect.Center())
}
// DistanceLine ...
func (g *Rect) DistanceLine(line *geometry.Line) float64 {
return geoDistancePoints(g.Center(), line.Rect().Center())
}
// DistancePoly ...
func (g *Rect) DistancePoly(poly *geometry.Poly) float64 {
return geoDistancePoints(g.Center(), poly.Rect().Center())
}