Skip to content

Commit

Permalink
Removed fileprivate Coordinate extension and replaced with Flyover op…
Browse files Browse the repository at this point in the history
…erator
  • Loading branch information
SvenTiigi committed Feb 28, 2018
1 parent 46ad45e commit 2d181cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 34 deletions.
43 changes: 9 additions & 34 deletions FlyoverKit/Camera/FlyoverCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ open class FlyoverCamera {
self.animator?.forceStopAnimation()
// Set center coordinate
self.mapCamera.centerCoordinate = flyover.coordinate
// Check if duration is zero or the current mapView camera center coordinates
// equals nearly the same to the current coordinate
if self.mapView?.camera.centerCoordinate ~~ self.flyover?.coordinate {
// Check if duration is zero or the current mapView camera
// equals nearly the same to the current flyover
if self.mapView?.camera ~~ self.flyover {
// Simply perform flyover as we still looking at the same coordinate
self.performFlyover(flyover)
} else if case .animated(let duration, let curve) = self.configuration.regionChangeAnimation, duration > 0 {
Expand Down Expand Up @@ -197,9 +197,9 @@ open class FlyoverCamera {
///
/// - Parameter flyover: The Flyover object
private func performFlyover(_ flyover: Flyover?) {
// Unwrap coordinate
guard let coordinate = flyover?.coordinate else {
// Coordinate unavailable return out of function
// Unwrap Flyover
guard let flyover = flyover else {
// Flyover unavailable return out of function
return
}
// Increase heading by heading step for mapCamera
Expand All @@ -214,10 +214,10 @@ open class FlyoverCamera {
})
// Add completion
self.animator?.setCompletion {
// Check if coordinates are equal
if self.flyover?.coordinate ~~ coordinate {
// Check if flyovers are nearly equal
if self.flyover ~~ flyover {
// Invoke recursion
self.performFlyover(coordinate)
self.performFlyover(flyover)
}
}
// Start Animation
Expand Down Expand Up @@ -266,28 +266,3 @@ fileprivate extension UIViewPropertyAnimator {
}

}

// MARK: - CLLocationCoordinate2D Comparison Extension

/// Nearly the same infix operator
infix operator ~~

fileprivate extension Optional where Wrapped == CLLocationCoordinate2D {

/// Check if two given coordinates via infix operator are nearly the same
/// via rounding the latitude and longitude to avoid float comparison
///
/// - Parameters:
/// - lhs: The left hand side
/// - rhs: The right hand side
/// - Returns: Boolean if the two coordinates are nearly the same
static func ~~ (lhs: CLLocationCoordinate2D?, rhs: CLLocationCoordinate2D?) -> Bool {
guard let lhs = lhs, let rhs = rhs else {
return false
}
let factor = 1000.0
return round(lhs.latitude * factor) == round(rhs.latitude * factor)
&& round(lhs.longitude * factor) == round(rhs.longitude * factor)
}

}
2 changes: 2 additions & 0 deletions FlyoverKit/Flyover+Operators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import Foundation

infix operator ~~

public extension Optional where Wrapped == Flyover {

/// Compare two given Flyover types
Expand Down

0 comments on commit 2d181cf

Please sign in to comment.