Skip to content

Commit

Permalink
Fix for creating bounding box that span the antimeridian
Browse files Browse the repository at this point in the history
  • Loading branch information
nighthawk committed Oct 21, 2022
1 parent 678daa8 commit 7e5d8ba
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Sources/GeoJSONKitTurf/Turf+BoundingBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ extension GeoJSON.BoundingBox {
}

public init(positions: [GeoJSON.Position], allowSpanningAntimeridian: Bool) {
guard allowSpanningAntimeridian, let first = positions.first else {
guard allowSpanningAntimeridian, !positions.isEmpty else {
self.init(positions: positions)
return
}

self = positions.dropFirst()
.sorted { $0.longitude < $1.longitude }
.reduce(into: GeoJSON.BoundingBox(positions: [first])) { box, next in
let sorted = positions.sorted { $0.longitude < $1.longitude }

self = sorted.dropFirst()
.reduce(into: GeoJSON.BoundingBox(positions: Array(sorted.prefix(1)))) { box, next in
box.append(next, allowSpanningAntimeridian: allowSpanningAntimeridian)
}
}
Expand Down

0 comments on commit 7e5d8ba

Please sign in to comment.