File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -203,8 +203,29 @@ public struct GeoJSON: Hashable {
203203 }
204204
205205 public struct Polygon : Hashable {
206- public typealias LinearRing = LineString
207-
206+ public struct LinearRing : Hashable {
207+ public var positions : [ Position ]
208+
209+ // We precompute this as it's static, but slow to re-compute
210+ private let precomputedHash : Int
211+
212+ public init ( positions: [ Position ] ) {
213+ var adjusted = positions
214+ if let first = adjusted. first, first != adjusted. last {
215+ adjusted. append ( first)
216+ }
217+ self . positions = adjusted
218+
219+ var hasher = Hasher ( )
220+ hasher. combine ( adjusted)
221+ precomputedHash = hasher. finalize ( )
222+ }
223+
224+ public func hash( into hasher: inout Hasher ) {
225+ hasher. combine ( precomputedHash)
226+ }
227+ }
228+
208229 public var exterior : LinearRing
209230 public var interiors : [ LinearRing ]
210231
@@ -227,7 +248,6 @@ public struct GeoJSON: Hashable {
227248 self . exterior = exterior
228249 self . interiors = interiors
229250
230-
231251 var hasher = Hasher ( )
232252 hasher. combine ( exterior)
233253 hasher. combine ( interiors)
You can’t perform that action at this time.
0 commit comments