Skip to content

Commit

Permalink
Merge pull request #159 from intere/polylines
Browse files Browse the repository at this point in the history
Directions (Routes) and AR Polylines
  • Loading branch information
aaronbrethorst authored Feb 28, 2019
2 parents dea9ae9 + cb7df11 commit 8698199
Show file tree
Hide file tree
Showing 57 changed files with 3,488 additions and 1,132 deletions.
22 changes: 22 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Background

Describe the purpose of this pull request.

### Breaking Changes
Describe any breaking changes that this pull request will introduce.

### Meta
- Tied to Version Release(s):

### Checklist

- [ ] Appropriate label has been added to this PR (i.e., Bug, Enhancement, etc.).
- [ ] Documentation has been added to all `open`, and `public` scoped methods and properties.
- [ ] Changelog has been updated
- [ ] Tests have have been added to all new features. (not a requirement, but helpful)
- [ ] Image/GIFs have been added for all UI related changed.

<!--- For UI Changes, please upload a GIF or Image of the feature in action --->
<!--- https://www.cockos.com/licecap/ Is a great tool to create quick and easy gifs --->

### Screenshots
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

15 changes: 9 additions & 6 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
line_length: 130

disabled_rules:
- file_length
- identifier_name
- line_length
- shorthand_operator
- type_body_length
function_body_length: 70
- variable_name
- todo
- valid_docs

excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- Pods
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: objective-c
osx_image: xcode10.1

script:
- pod lib lint

notifications:
email: false
3 changes: 2 additions & 1 deletion ARCL.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Pod::Spec.new do |s|
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.source = { :git => "https://[email protected]/ProjectDent/ARKit-CoreLocation.git", :tag => s.version.to_s, :submodules => false }
s.platform = :ios, '9.0'
s.swift_version = "4.2"
s.requires_arc = true
s.source_files = 'ARCL/Source/*.swift'
s.source_files = 'ARCL/Source/**/*.{swift}'
s.frameworks = 'Foundation', 'UIKit', 'ARKit', 'CoreLocation', 'MapKit', 'SceneKit'
s.ios.deployment_target = '9.0'
end
107 changes: 0 additions & 107 deletions ARCL/Source/CLLocation+Extensions.swift

This file was deleted.

29 changes: 29 additions & 0 deletions ARCL/Source/Extensions/BaseTypes+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// BaseTypes+Extensions.swift
// ARKit+CoreLocation
//
// Created by Ilya Seliverstov on 08/08/2017.
// Copyright © 2017 Project Dent. All rights reserved.
//

import Foundation

public extension Double {

var metersToLatitude: Double {
return self / (6_360_500.0)
}

var metersToLongitude: Double {
return self / (5_602_900.0)
}
}

public extension Float {
var short: String { return String(format: "%.2f", self) }
}

public extension Int {
var short: String { return String(format: "%02d", self) }
var short3: String { return String(format: "%03d", self / 1_000_000) }
}
File renamed without changes.
102 changes: 102 additions & 0 deletions ARCL/Source/Extensions/CLLocation+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// CLLocation+Extensions.swift
// ARKit+CoreLocation
//
// Created by Andrew Hart on 02/07/2017.
// Copyright © 2017 Project Dent. All rights reserved.
//

import Foundation
import CoreLocation

///Translation in meters between 2 locations
public struct LocationTranslation {
public var latitudeTranslation: Double
public var longitudeTranslation: Double
public var altitudeTranslation: Double
}

public extension CLLocation {
public convenience init(coordinate: CLLocationCoordinate2D, altitude: CLLocationDistance) {
self.init(coordinate: coordinate, altitude: altitude, horizontalAccuracy: 0, verticalAccuracy: 0, timestamp: Date())
}

///Translates distance in meters between two locations.
///Returns the result as the distance in latitude and distance in longitude.
public func translation(toLocation location: CLLocation) -> LocationTranslation {
let inbetweenLocation = CLLocation(latitude: self.coordinate.latitude, longitude: location.coordinate.longitude)

let distanceLatitude = location.distance(from: inbetweenLocation)

let latitudeTranslation = location.coordinate.latitude > inbetweenLocation.coordinate.latitude ? distanceLatitude
: -distanceLatitude

let distanceLongitude = distance(from: inbetweenLocation)

let longitudeTranslation = coordinate.longitude > inbetweenLocation.coordinate.longitude ? -distanceLongitude
: distanceLongitude

let altitudeTranslation = location.altitude - self.altitude

return LocationTranslation( latitudeTranslation: latitudeTranslation,
longitudeTranslation: longitudeTranslation,
altitudeTranslation: altitudeTranslation)
}

public func translatedLocation(with translation: LocationTranslation) -> CLLocation {
let latitudeCoordinate = self.coordinate.coordinateWithBearing(bearing: 0,
distanceMeters: translation.latitudeTranslation)

let longitudeCoordinate = self.coordinate.coordinateWithBearing(bearing: 90,
distanceMeters: translation.longitudeTranslation)

let coordinate = CLLocationCoordinate2D( latitude: latitudeCoordinate.latitude, longitude: longitudeCoordinate.longitude)

let altitude = self.altitude + translation.altitudeTranslation

return CLLocation(coordinate: coordinate,
altitude: altitude,
horizontalAccuracy: self.horizontalAccuracy,
verticalAccuracy: self.verticalAccuracy,
timestamp: self.timestamp)
}

func bearing(between point: CLLocation) -> Double {
let lat1 = self.coordinate.latitude.degreesToRadians
let lon1 = self.coordinate.longitude.degreesToRadians

let lat2 = point.coordinate.latitude.degreesToRadians
let lon2 = point.coordinate.longitude.degreesToRadians

let dLon = lon2 - lon1

let y = sin(dLon) * cos(lat2)
let x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon)
return atan2(y, x).radiansToDegrees
}
}

public extension CLLocation {
var debugLog: String {
return "location: \(self.coordinate), accuracy: \(self.horizontalAccuracy), date: \(self.timestamp)"
}
}

public extension CLLocationCoordinate2D {

func coordinateWithBearing(bearing: Double, distanceMeters: Double) -> CLLocationCoordinate2D {
//The numbers for earth radius may be _off_ here
//but this gives a reasonably accurate result..
//Any correction here is welcome.
let distRadiansLat = distanceMeters.metersToLatitude // earth radius in meters latitude
let distRadiansLong = distanceMeters.metersToLongitude // earth radius in meters longitude

let lat1 = self.latitude * Double.pi / 180
let lon1 = self.longitude * Double.pi / 180

let lat2 = asin(sin(lat1) * cos(distRadiansLat) + cos(lat1) * sin(distRadiansLat) * cos(bearing))
let lon2 = lon1 + atan2(sin(bearing) * sin(distRadiansLong) * cos(lat1), cos(distRadiansLong) - sin(lat1) * sin(lat2))

return CLLocationCoordinate2D(latitude: lat2 * 180 / Double.pi, longitude: lon2 * 180 / Double.pi)
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ extension SCNNode {
let quiverThickness = (quiverLength / 50.0) * quiverThickness
let chamferRadius = quiverThickness / 2.0

let xQuiverBox = SCNBox(width: quiverLength, height: quiverThickness, length: quiverThickness, chamferRadius: chamferRadius)
let xQuiverBox = SCNBox(width: quiverLength,
height: quiverThickness,
length: quiverThickness,
chamferRadius: chamferRadius)
xQuiverBox.firstMaterial?.diffuse.contents = UIColor.red
let xQuiverNode = SCNNode(geometry: xQuiverBox)
xQuiverNode.position = SCNVector3Make(Float(quiverLength / 2.0), 0.0, 0.0)

let yQuiverBox = SCNBox(width: quiverThickness, height: quiverLength, length: quiverThickness, chamferRadius: chamferRadius)
let yQuiverBox = SCNBox(width: quiverThickness,
height: quiverLength,
length: quiverThickness,
chamferRadius: chamferRadius)
yQuiverBox.firstMaterial?.diffuse.contents = UIColor.green
let yQuiverNode = SCNNode(geometry: yQuiverBox)
yQuiverNode.position = SCNVector3Make(0.0, Float(quiverLength / 2.0), 0.0)

let zQuiverBox = SCNBox(width: quiverThickness, height: quiverThickness, length: quiverLength, chamferRadius: chamferRadius)
let zQuiverBox = SCNBox(width: quiverThickness,
height: quiverThickness,
length: quiverLength,
chamferRadius: chamferRadius)
zQuiverBox.firstMaterial?.diffuse.contents = UIColor.blue
let zQuiverNode = SCNNode(geometry: zQuiverBox)
zQuiverNode.position = SCNVector3Make(0.0, 0.0, Float(quiverLength / 2.0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import SceneKit

extension SCNVector3 {
public extension SCNVector3 {
///Calculates distance between vectors
///Doesn't include the y axis, matches functionality of CLLocation 'distance' function.
func distance(to anotherVector: SCNVector3) -> Float {
Expand Down
Loading

0 comments on commit 8698199

Please sign in to comment.