-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTransformTranslate.swift
More file actions
54 lines (45 loc) · 1.93 KB
/
TransformTranslate.swift
File metadata and controls
54 lines (45 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#if canImport(CoreLocation)
import CoreLocation
#endif
import Foundation
// Ported from https://github.com/Turfjs/turf/blob/master/packages/turf-transform-translate
extension GeoJson {
/// Moves the receiver for a specified distance along a Rhumb line on the provided direction angle.
///
/// - Parameters:
/// - distance: The length of the motion, in meters
/// - direction: The direction of the motion, in decimal degrees from north, positive clockwise.
/// - zTranslation: The length of the vertical motion, in meters (defaults to 0.0)
public func transformedTranslate(
distance: CLLocationDistance,
direction: CLLocationDegrees,
zTranslation: CLLocationDistance = 0.0
) -> Self {
guard distance != 0.0 || zTranslation != 0.0 else { return self }
let distance = abs(distance)
let direction = abs(direction)
return transformedCoordinates({ (coordinate) in
var newCoordinate = coordinate.rhumbDestination(distance: distance, bearing: direction)
if zTranslation != 0.0, let altitude = coordinate.altitude {
newCoordinate.altitude = altitude + zTranslation
}
return newCoordinate
})
}
/// Moves the receiver for a specified distance along a Rhumb line on the provided direction angle.
///
/// - Parameters:
/// - distance: The length of the motion, in meters
/// - direction: The direction of the motion, in decimal degrees from north, positive clockwise.
/// - zTranslation: The length of the vertical motion, in meters (defaults to 0.0)
public mutating func transformTranslate(
distance: CLLocationDistance,
direction: CLLocationDegrees,
zTranslation: CLLocationDistance = 0.0
) {
self = transformedTranslate(
distance: distance,
direction: direction,
zTranslation: zTranslation)
}
}