Skip to content

Commit 33da423

Browse files
authored
Merge pull request #162 from mapbox/1ec5-docs-turfjs
Generate API reference documentation
2 parents 0eb12b6 + eeab0ae commit 33da423

File tree

13 files changed

+282
-114
lines changed

13 files changed

+282
-114
lines changed

README.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
📺[![tvOS](https://app.bitrise.io/app/0b037542c2395ffb/status.svg?token=yOtMqbu-5bj8grB1Jmoefg)](https://www.bitrise.io/app/0b037542c2395ffb)    
66
⌚️[![watchOS](https://app.bitrise.io/app/0d4d611f02295183/status.svg?token=NiLB_E_0IvYYqV4Mj973TQ)](https://www.bitrise.io/app/0d4d611f02295183)    
77
<img src="https://upload.wikimedia.org/wikipedia/commons/3/3c/TuxFlat.svg" width="20" alt="Linux">[![](https://api.travis-ci.com/mapbox/turf-swift.svg?branch=main)](https://travis-ci.com/mapbox/turf-swift) &nbsp;&nbsp;&nbsp;
8+
[![](https://mapbox.github.io/turf-swift/1.2.0/badge.svg)](https://mapbox.github.io/turf-swift/) &nbsp;&nbsp;&nbsp;
89
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) &nbsp;&nbsp;&nbsp;
910
[![CocoaPods](https://img.shields.io/cocoapods/v/Turf.svg)](http://cocoadocs.org/docsets/Turf/) &nbsp;&nbsp;&nbsp;
1011
[![SPM compatible](https://img.shields.io/badge/SPM-compatible-4BC51D.svg?style=flat)](https://swift.org/package-manager/) &nbsp;&nbsp;&nbsp;
@@ -67,34 +68,33 @@ Then `import Turf` in any Swift file in your module.
6768

6869
This work-in-progress port of [Turf.js](https://github.com/Turfjs/turf/) contains the following functionality:
6970

70-
Turf.js | Turf-swift
71+
Turf.js | Turf for Swift
7172
----|----
72-
[turf-along](https://github.com/Turfjs/turf/tree/master/packages/turf-along/) | `LineString.coordinateFromStart(distance:)`
73-
[turf-area](https://github.com/Turfjs/turf/blob/master/packages/turf-area/) | `Polygon.area`
74-
[turf-bearing](https://turfjs.org/docs/#bearing) | `CLLocationCoordinate2D.direction(to:)`<br>`LocationCoordinate2D.direction(to:)` on Linux<br>`RadianCoordinate2D.direction(to:)`
75-
[turf-bezier-spline](https://github.com/Turfjs/turf/tree/master/packages/turf-bezier-spline/) | `LineString.bezier(resolution:sharpness:)`
76-
[turf-boolean-point-in-polygon](https://github.com/Turfjs/turf/tree/master/packages/turf-boolean-point-in-polygon) | `Polygon.contains(_:ignoreBoundary:)`
77-
[turf-center](http://turfjs.org/docs/#center) | `Polygon.center`
78-
[turf-center-of-mass](http://turfjs.org/docs/#centerOfMass) | `Polygon.centerOfMass`
79-
[turf-centroid](http://turfjs.org/docs/#centroid) | `Polygon.centroid`
80-
[turf-circle](https://turfjs.org/docs/#circle) | `Polygon(center:radius:vertices:)` |
81-
[turf-destination](https://github.com/Turfjs/turf/tree/master/packages/turf-destination/) | `CLLocationCoordinate2D.coordinate(at:facing:)`<br>`LocationCoordinate2D.coordinate(at:facing:)` on Linux<br>`RadianCoordinate2D.coordinate(at:facing:)`
82-
[turf-distance](https://github.com/Turfjs/turf/tree/master/packages/turf-distance/) | `CLLocationCoordinate2D.distance(to:)`<br>`LocationCoordinate2D.distance(to:)` on Linux<br>`RadianCoordinate2D.distance(to:)`
83-
[turf-helpers#polygon](https://github.com/Turfjs/turf/tree/master/packages/turf-helpers/#polygon) | `Polygon(_:)`
84-
[turf-helpers#lineString](https://github.com/Turfjs/turf/tree/master/packages/turf-helpers/#linestring) | `LineString(_:)`
85-
[turf-helpers#degreesToRadians](https://github.com/Turfjs/turf/tree/master/packages/turf-helpers/#degreesToRadians) | `CLLocationDegrees.toRadians()`<br>`LocationDegrees.toRadians()` on Linux
86-
[turf-helpers#radiansToDegrees](https://github.com/Turfjs/turf/tree/master/packages/turf-helpers/#radiansToDegrees) | `CLLocationDegrees.toDegrees()`<br>`LocationDegrees.toDegrees()` on Linux
87-
[turf-helpers#convertLength](https://github.com/Turfjs/turf/tree/master/packages/turf-helpers#convertlength)<br>[turf-helpers#convertArea](https://github.com/Turfjs/turf/tree/master/packages/turf-helpers#convertarea) | `Measurement.converted(to:)`
88-
[turf-length](https://github.com/Turfjs/turf/tree/master/packages/turf-length/) | `LineString.distance(from:to:)`
89-
[turf-line-intersect](https://github.com/Turfjs/turf/tree/master/packages/turf-line-intersect/) | `intersection(_:_:)`
90-
[turf-line-slice](https://github.com/Turfjs/turf/tree/master/packages/turf-line-slice/) | `LineString.sliced(from:to:)`
91-
[turf-line-slice-along](https://github.com/Turfjs/turf/tree/master/packages/turf-line-slice-along/) | `LineString.trimmed(from:distance:)`
92-
[turf-midpoint](https://github.com/Turfjs/turf/blob/master/packages/turf-midpoint/index.js) | `mid(_:_:)`
93-
[turf-nearest-point-on-line](https://github.com/Turfjs/turf/tree/master/packages/turf-nearest-point-on-line/) | `LineString.closestCoordinate(to:)`
94-
[turf-polygon-to-line](https://github.com/Turfjs/turf/tree/master/packages/turf-polygon-to-line/) | `LineString(_:)`<br>`MultiLineString(_:)`<br>`FeatureCollection(_:)`
95-
[turf-simplify](https://github.com/Turfjs/turf/tree/master/packages/turf-simplify) | `LineString.simplified(tolerance:highestQuality:)`
96-
[turf-polygon-smooth](https://github.com/Turfjs/turf/tree/master/packages/turf-polygon-smooth) | `Polygon.smooth(iterations:)`
97-
[turf-simplify](https://github.com/Turfjs/turf/tree/master/packages/turf-simplify) | `Polygon.simplified(tolerance:highestQuality:)`
73+
[turf-along#along](https://turfjs.org/docs/#along) | `LineString.coordinateFromStart(distance:)`
74+
[turf-area#area](https://turfjs.org/docs/#area) | `Polygon.area`
75+
[turf-bearing#bearing](https://turfjs.org/docs/#bearing) | `CLLocationCoordinate2D.direction(to:)`<br>`LocationCoordinate2D.direction(to:)` on Linux<br>`RadianCoordinate2D.direction(to:)`
76+
[turf-bezier-spline#bezierSpline](https://turfjs.org/docs/#bezierSpline) | `LineString.bezier(resolution:sharpness:)`
77+
[turf-boolean-point-in-polygon#booleanPointInPolygon](https://turfjs.org/docs/#booleanPointInPolygon) | `Polygon.contains(_:ignoreBoundary:)`
78+
[turf-center#center](https://turfjs.org/docs/#center) | `Polygon.center`
79+
[turf-center-of-mass#centerOfMass](https://turfjs.org/docs/#centerOfMass) | `Polygon.centerOfMass`
80+
[turf-centroid#centroid](https://turfjs.org/docs/#centroid) | `Polygon.centroid`
81+
[turf-circle#circle](https://turfjs.org/docs/#circle) | `Polygon(center:radius:vertices:)` |
82+
[turf-destination#destination](https://turfjs.org/docs/#destination) | `CLLocationCoordinate2D.coordinate(at:facing:)`<br>`LocationCoordinate2D.coordinate(at:facing:)` on Linux<br>`RadianCoordinate2D.coordinate(at:facing:)`
83+
[turf-distance#distance](https://turfjs.org/docs/#distance) | `CLLocationCoordinate2D.distance(to:)`<br>`LocationCoordinate2D.distance(to:)` on Linux<br>`RadianCoordinate2D.distance(to:)`
84+
[turf-helpers#polygon](https://turfjs.org/docs/#polygon) | `Polygon(_:)`
85+
[turf-helpers#lineString](https://turfjs.org/docs/#lineString) | `LineString(_:)`
86+
[turf-helpers#degreesToRadians](https://turfjs.org/docs/#degreesToRadians) | `CLLocationDegrees.toRadians()`<br>`LocationDegrees.toRadians()` on Linux
87+
[turf-helpers#radiansToDegrees](https://turfjs.org/docs/#radiansToDegrees) | `CLLocationDegrees.toDegrees()`<br>`LocationDegrees.toDegrees()` on Linux
88+
[turf-helpers#convertLength](https://turfjs.org/docs/#convertLength)<br>[turf-helpers#convertArea](https://turfjs.org/docs/#convertArea) | `Measurement.converted(to:)`
89+
[turf-length#length](https://turfjs.org/docs/#length) | `LineString.distance(from:to:)`
90+
[turf-line-intersect#lineIntersect](https://turfjs.org/docs/#lineIntersect) | `intersection(_:_:)`
91+
[turf-line-slice#lineSlice](https://turfjs.org/docs/#lineSlice) | `LineString.sliced(from:to:)`
92+
[turf-line-slice-along#lineSliceAlong](https://turfjs.org/docs/#lineSliceAlong) | `LineString.trimmed(from:distance:)`
93+
[turf-midpoint#midpoint](https://turfjs.org/docs/#midpoint) | `mid(_:_:)`
94+
[turf-nearest-point-on-line#nearestPointOnLine](https://turfjs.org/docs/#nearestPointOnLine) | `LineString.closestCoordinate(to:)`
95+
[turf-polygon-to-line#polygonToLine](https://turfjs.org/docs/#polygonToLine) | `LineString(_:)`<br>`MultiLineString(_:)`
96+
[turf-simplify#simplify](https://turfjs.org/docs/#simplify) | `LineString.simplify(tolerance:highestQuality:)`<br>`LineString.simplified(tolerance:highestQuality:)`
97+
[turf-polygon-smooth#polygonSmooth](https://turfjs.org/docs/#polygonSmooth) | `Polygon.smooth(iterations:)`
9898
— | `CLLocationDirection.difference(from:)`<br>`LocationDirection.difference(from:)` on Linux
9999
— | `CLLocationDirection.wrap(min:max:)`<br>`LocationDirection.wrap(min:max:)` on Linux
100100

Sources/Turf/CoreLocation.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,17 @@ extension LocationDirection {
107107
extension LocationDegrees {
108108
/**
109109
Returns the direction in radians.
110+
111+
This method is equivalent to the [`degreesToRadians`](https://turfjs.org/docs/#degreesToRadians) method of the turf-helpers package of Turf.js ([source code](https://github.com/Turfjs/turf/tree/master/packages/turf-helpers/)).
110112
*/
111113
public func toRadians() -> LocationRadians {
112114
return self * .pi / 180.0
113115
}
114116

115117
/**
116118
Returns the direction in degrees.
119+
120+
This method is equivalent to the [`radiansToDegrees`](https://turfjs.org/docs/#radiansToDegrees) method of the turf-helpers package of Turf.js ([source code](https://github.com/Turfjs/turf/tree/master/packages/turf-helpers/)).
117121
*/
118122
public func toDegrees() -> LocationDirection {
119123
return self * 180.0 / .pi
@@ -198,7 +202,11 @@ extension LocationCoordinate2D: Equatable {
198202
return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
199203
}
200204

201-
/// Returns the direction from the receiver to the given coordinate.
205+
/**
206+
Returns the direction from the receiver to the given coordinate.
207+
208+
This method is equivalent to the [turf-bearing](https://turfjs.org/docs/#bearing) package of Turf.js ([source code](https://github.com/Turfjs/turf/tree/master/packages/turf-bearing/)).
209+
*/
202210
public func direction(to coordinate: LocationCoordinate2D) -> LocationDirection {
203211
return RadianCoordinate2D(self).direction(to: RadianCoordinate2D(coordinate)).converted(to: .degrees).value
204212
}
@@ -209,14 +217,20 @@ extension LocationCoordinate2D: Equatable {
209217
return coordinate(at: distance, facing: angle)
210218
}
211219

212-
/// Returns a coordinate a certain Haversine distance away in the given direction.
220+
/**
221+
Returns a coordinate a certain Haversine distance away in the given direction.
222+
223+
This method is equivalent to the [turf-destination](https://turfjs.org/docs/#destination) package of Turf.js ([source code](https://github.com/Turfjs/turf/tree/master/packages/turf-destination/)).
224+
*/
213225
public func coordinate(at distance: LocationDistance, facing direction: Measurement<UnitAngle>) -> LocationCoordinate2D {
214226
let radianCoordinate = RadianCoordinate2D(self).coordinate(at: distance / metersPerRadian, facing: direction)
215227
return LocationCoordinate2D(radianCoordinate)
216228
}
217229

218230
/**
219231
Returns the Haversine distance between two coordinates measured in degrees.
232+
233+
This method is equivalent to the [turf-distance](https://turfjs.org/docs/#distance) package of Turf.js ([source code](https://github.com/Turfjs/turf/tree/master/packages/turf-distance/)).
220234
*/
221235
public func distance(to coordinate: LocationCoordinate2D) -> LocationDistance {
222236
return RadianCoordinate2D(self).distance(to: RadianCoordinate2D(coordinate)) * metersPerRadian

Sources/Turf/Feature.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@ import CoreLocation
77
A [Feature object](https://datatracker.ietf.org/doc/html/rfc7946#section-3.2) represents a spatially bounded thing.
88
*/
99
public struct Feature: Equatable {
10+
/**
11+
A string or number that commonly identifies the feature in the context of a data set.
12+
13+
Turf does not guarantee that the feature is unique; however, a data set may make such a guarantee.
14+
*/
1015
public var identifier: FeatureIdentifier?
16+
17+
/// Arbitrary, JSON-compatible attributes to associate with the feature.
1118
public var properties: JSONObject?
19+
20+
/// The geometry at which the feature is located.
1221
public var geometry: Geometry?
1322

23+
/**
24+
Initializes a feature located at the given geometry.
25+
26+
- parameter geometry: The geometry at which the feature is located.
27+
*/
1428
public init(geometry: Geometry?) {
1529
self.geometry = geometry
1630
}

Sources/Turf/FeatureCollection.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ import Foundation
44
A [FeatureCollection object](https://datatracker.ietf.org/doc/html/rfc7946#section-3.3) is a collection of Feature objects.
55
*/
66
public struct FeatureCollection: Equatable {
7-
public var features: Array<Feature> = []
7+
/// The features that the collection contains.
8+
public var features: [Feature] = []
89

10+
/**
11+
Initializes a feature collection containing the given features.
12+
13+
- parameter features: The features that the collection contains.
14+
*/
915
public init(features: [Feature]) {
1016
self.features = features
1117
}

0 commit comments

Comments
 (0)