v2.0.0
Packaging
⚠️ Turf requires Xcode 12.0 or above to build from source. (#152)⚠️ When installing this library using Carthage, Carthage builds it with library evolution enabled. (#134)- Turf is now 100% documented. A full API reference is available online. (#162)
Geometry
-
⚠️ Replaced the Linux-specific definitions ofCLLocationCoordinate2D
,CLLocationDirection
,CLLocationDistance
, andCLLocationDegrees
withLocationCoordinate2D
,LocationDirection
,LocationDistance
, andLocationDegrees
, respectively. On Apple platforms, the new types remain type aliases, so you can continue to use the familiarCL
-prefixed Core Location types unless you are writing cross-platform code that supports Linux. (#132) -
⚠️ Combined theGeoJSON
class andGeoJSON
protocol into a unifiedGeoJSONObject
enumeration. UseJSONDecoder
instead of theGeoJSON.parse(_:)
orGeoJSON.parse<T: GeoJSONObject>(_:from:)
method. (#154)v1.x if let feature = try GeoJSON.parse(data)?.decodedFeature, case let .lineString(lineString) = feature.geometry { … }
v2.0.0 if case let .feature(feature) = try JSONDecoder().decode(GeoJSONObject.self, from: data), case let .lineString(lineString) = feature.geometry { … }
-
⚠️ Removed theFeatureCollection.identifier
andFeatureCollection.properties
properties with no replacement. These properties had been represented in GeoJSON by foreign members, which are not yet implemented. If you had been relying on theidentifier
orproperties
foreign members of FeatureCollection objects, move the data to each individual feature in the collection. (#154)v1.x let uuid = UUID().description featureCollection.identifier = .string(uuid)
v2.0.0 let uuid = UUID().description for feature in featureCollection.features { $0.identifier = .string(uuid) }
-
⚠️ TheFeature.properties
property is now aJSONObject?
(in other words,[String: JSONValue?]?
). JSONObject is type-checked at compile time instead of runtime, but you can initialize it using a literal or full-width conversion fromAny?
. Code that builds a JSON object using literals will have to be modified to either specify aJSONValue
case for each value or call theJSONObject(rawValue:)
initializer. (#154)v1.x feature.properties = [ "name": "Wapakoneta", "population": 9_957, "favorite": isFavorite, ] let isBigCity = (feature.properties?["population"] as? Double).flatMap { $0 > 10_000 }
v2.0.0 feature.properties = [ "name": "Wapakoneta", "population": 9_957, "favorite": .boolean(isFavorite), ] var isBigCity: Bool? if case let .number(population) = feature.properties?["population"] { isBigCity = population > 10_000 }
-
⚠️ TheFeature.geometry
property is now optional. (#154) -
⚠️ Removed theGeometry.type
property. Use pattern matching (case let
) instead. (#154)v1.x if geometry.type == .Point { … }
v2.0.0 if case .point = geometry { … }
-
⚠️ Removed theGeometry.value
property. This type erasure is unnecessary and can potentially become a source of bugs. Use pattern matching instead. (#154)v1.x if let point = geometry.value as? Point { … }
v2.0.0 if case let .point(point) = geometry { … }
-
⚠️ Removed theNumber
enumeration in favor of aDouble
-typedFeatureIdentifier.number(_:)
case. JSON doesn’t distinguish between integers and double-precision floating point numbers. Any distinction in the type system or encoded JSON is purely cosmetic. (#154)v1.x let randomNumber = Int.random(in: 0...255) feature.identifier = .number(.int(randomNumber)) if let number = feature.identifier?.value as? Int { print("You rolled a \(number)!") }
v2.0.0 let randomNumber = Int.random(in: 0...255) feature.identifier = .number(Double(randomNumber)) if let .number(number) = feature.identifier { print("You rolled a \(Int(number))!") }
-
⚠️ Renamed theBoundingBox(_:_:)
initializer toBoundingBox(southWest:northEast:)
. (#132) -
Feature
andFeatureCollection
now conform to theEquatable
protocol. (#154) -
Each geometric type, such as
Point
, now conforms to theCodable
andEquatable
protocols. (#154) -
BoundingBox
andFeatureIdentifier
now conform to theHashable
protocol. (#154, #159)
Trigonometry
⚠️ TheRadianCoordinate2D.direction(to:)
method now returns aMeasurement<UnitAngle>
instead of aRadianDirection
, and theRadianCoordinate2D.coordinate(at:facing:)
method now accepts aMeasurement<UnitAngle>
instance instead of aRadianDirection
. TheLocationCoordinate2D.coordinate(at:facing:)
method can now accept aMeasurement<UnitAngle>
instance instead of aLocationDirection
instance. (#143)- Added the
Polygon.smooth(iterations:)
method for polygon smoothing. (#137) - Added the
Polygon.simplify(tolerance:highestQuality)
method in both non-mutating and mutating forms. (#138) - Added the
LineString.bezier(resolution:sharpness:)
method for calculating a Bézier curve. (#140) - Added the
Polygon.center
,Polygon.centroid
, andPolygon.centerOfMass
properties. (#148)
Documentation is available online or within Xcode.