Skip to content

Commit ce7cc2f

Browse files
committed
Made GeoJSONObject idempotent
1 parent 53910de commit ce7cc2f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Sources/Turf/GeoJSON.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public protocol GeoJSONObjectConvertible {
7474
var geoJSONObject: GeoJSONObject { get }
7575
}
7676

77+
extension GeoJSONObject: GeoJSONObjectConvertible {
78+
public var geoJSONObject: GeoJSONObject { return self }
79+
}
80+
7781
extension Geometry: GeoJSONObjectConvertible {
7882
public var geoJSONObject: GeoJSONObject { return .geometry(self) }
7983
}

Tests/TurfTests/GeoJSONTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ class GeoJSONTests: XCTestCase {
2323
XCTAssertEqual(Geometry(GeometryCollection(geometries: [])),
2424
.geometryCollection(GeometryCollection(geometries: [])))
2525

26+
XCTAssertEqual(Geometry(Geometry(Geometry(Geometry(Point(nullIsland))))), .point(.init(nullIsland)))
27+
2628
XCTAssertEqual(GeoJSONObject(Geometry(Point(nullIsland))), .geometry(.point(.init(nullIsland))))
2729
XCTAssertEqual(GeoJSONObject(Feature(geometry: nil)), .feature(.init(geometry: nil)))
2830
let nullGeometry: Geometry? = nil
2931
XCTAssertEqual(GeoJSONObject(Feature(geometry: nullGeometry)), .feature(.init(geometry: nil)))
3032
XCTAssertEqual(GeoJSONObject(FeatureCollection(features: [])), .featureCollection(.init(features: [])))
33+
34+
XCTAssertEqual(GeoJSONObject(GeoJSONObject(GeoJSONObject(GeoJSONObject(Geometry(Point(nullIsland)))))),
35+
.geometry(.point(.init(nullIsland))))
3136
}
3237

3338
func testPoint() {

0 commit comments

Comments
 (0)