-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathBooleanClockwise.swift
More file actions
37 lines (28 loc) · 1015 Bytes
/
BooleanClockwise.swift
File metadata and controls
37 lines (28 loc) · 1015 Bytes
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
#if canImport(CoreLocation)
import CoreLocation
#endif
import Foundation
// Ported from https://github.com/Turfjs/turf/blob/master/packages/turf-boolean-clockwise
extension Ring {
/// Check whether or not the ring is clockwise.
///
/// - Returns: *true* if the ring is clockwise, *false* otherwise.
public var isClockwise: Bool {
guard coordinates.count > 0 else { return false }
var sum: Double = 0.0
var previous: Coordinate3D?
var current: Coordinate3D?
for index in 1 ..< coordinates.count {
previous = current ?? coordinates[0]
current = coordinates[index]
sum += ((current!.longitude - previous!.longitude) * (current!.latitude + previous!.latitude))
}
return sum > 0
}
/// Check whether or not the ring is counter-clockwise.
///
/// - Returns: *true* if the ring is counter-clockwise, *false* otherwise.
public var isCounterClockwise: Bool {
!isClockwise
}
}