-
Notifications
You must be signed in to change notification settings - Fork 0
/
isequal.go
159 lines (149 loc) · 3.88 KB
/
isequal.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
158
159
package tegola
// IsPointEqual will check to see if the two tegola points are equal.
func IsPointEqual(p1, p2 Point) bool {
if p1 == nil || p2 == nil {
return p1 == p2
}
return p1.X() == p2.X() && p1.Y() == p2.Y()
}
// IsPoint3Equal will check to see if the two 3d tegola points are equal.
func IsPoint3Equal(p1, p2 Point3) bool {
return p1.X() == p2.X() && p1.Y() == p2.Y() && p1.Z() == p2.Z()
}
// IsMultiPointEqual will check to see if the two provided multipoints are equal
func IsMultiPointEqual(mp1, mp2 MultiPoint) bool {
pts1, pts2 := mp1.Points(), mp2.Points()
if len(pts1) != len(pts2) {
return false
}
for i, pt := range pts1 {
if !IsPointEqual(pt, pts2[i]) {
return false
}
}
return true
}
// IsLineStringEqual will check to see if the two linesstrings provided are equal.
func IsLineStringEqual(l1, l2 LineString) bool {
pts1, pts2 := l1.Subpoints(), l2.Subpoints()
if len(pts1) != len(pts2) {
return false
}
for i, pt := range pts1 {
if !IsPointEqual(pt, pts2[i]) {
return false
}
}
return true
}
// IsMultiLineEqual will check to see if the two Multilines that are provided are equal.
func IsMultiLineEqual(ml1, ml2 MultiLine) bool {
lns1, lns2 := ml1.Lines(), ml2.Lines()
if len(lns1) != len(lns2) {
return false
}
for i, ln := range lns1 {
if !IsLineStringEqual(ln, lns2[i]) {
return false
}
}
return true
}
// PolygonIsEqual will check to see if the two provided polygons are equal.
func IsPolygonEqual(p1, p2 Polygon) bool {
lns1, lns2 := p1.Sublines(), p2.Sublines()
if len(lns1) != len(lns2) {
return false
}
for i, ln := range lns1 {
if !IsLineStringEqual(ln, lns2[i]) {
return false
}
}
return true
}
// MultiPolygonIsEqual will check to see if the two provided multi-polygons are equal.
func IsMultiPolygonEqual(mp1, mp2 MultiPolygon) bool {
pgs1, pgs2 := mp1.Polygons(), mp2.Polygons()
if len(pgs1) != len(pgs2) {
return false
}
for i, pg := range pgs1 {
if !IsPolygonEqual(pg, pgs2[i]) {
return false
}
}
return true
}
// GeometryIsEqual will check to see if the two given geometeries are equal. This function does not check to see if there are any
// recursive structures if there are any recursive structures it will hang. If the type of the geometry is unknown, it is assumed
// that it does not match any other geometries.
func IsGeometryEqual(g1, g2 Geometry) bool {
switch geo1 := g1.(type) {
case Point:
geo2, ok := g2.(Point)
if !ok {
return false
}
return IsPointEqual(geo1, geo2)
case Point3:
geo2, ok := g2.(Point3)
if !ok {
return false
}
return IsPoint3Equal(geo1, geo2)
case MultiPoint:
geo2, ok := g2.(MultiPoint)
if !ok {
return false
}
return IsMultiPointEqual(geo1, geo2)
case LineString:
geo2, ok := g2.(LineString)
if !ok {
return false
}
return IsLineStringEqual(geo1, geo2)
case MultiLine:
geo2, ok := g2.(MultiLine)
if !ok {
return false
}
return IsMultiLineEqual(geo1, geo2)
case Polygon:
geo2, ok := g2.(Polygon)
if !ok {
return false
}
return IsPolygonEqual(geo1, geo2)
case MultiPolygon:
geo2, ok := g2.(MultiPolygon)
if !ok {
return false
}
return IsMultiPolygonEqual(geo1, geo2)
case Collection:
geo2, ok := g2.(Collection)
if !ok {
return false
}
return IsCollectionEqual(geo1, geo2)
}
// If we don't know the type, we will assume they don't match.
return false
}
// CollectionIsEqual will check to see if the provided collections are equal. This function does not check to see if the collections
// contain any recursive structures, and if there are any recursive structures it will hang. If the collections contains any unknown
// geometries it will be assumed to not match.
func IsCollectionEqual(c1, c2 Collection) bool {
geos1, geos2 := c1.Geometries(), c2.Geometries()
if len(geos1) != len(geos2) {
return false
}
for i, geo := range geos1 {
if !IsGeometryEqual(geo, geos2[i]) {
return false
}
}
return true
}