-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added rough Wind Struct and appended it to route
- Loading branch information
1 parent
27dd2fe
commit 858fde1
Showing
5 changed files
with
98 additions
and
86 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Route.swift | ||
// windrider-ios | ||
// | ||
// Created by Daniel Grbac Bravo on 01/03/2024. | ||
// | ||
|
||
import Foundation | ||
import CoreLocation | ||
import MapKit | ||
import SwiftUI | ||
|
||
struct Route { | ||
let routeId: UUID? | ||
let points: [CLLocationCoordinate2D] | ||
var wind: Wind? | ||
|
||
init(routeId: String? = nil, points: [CLLocationCoordinate2D]) { | ||
self.routeId = UUID() | ||
self.points = points | ||
} | ||
|
||
func calcuateCenterCoordinate() -> CLLocationCoordinate2D { | ||
var maxLat: CLLocationDegrees = -90 | ||
var maxLon: CLLocationDegrees = -180 | ||
var minLat: CLLocationDegrees = 90 | ||
var minLon: CLLocationDegrees = 180 | ||
|
||
for coordinate in points { | ||
let lat = Double(coordinate.latitude) | ||
let long = Double(coordinate.longitude) | ||
|
||
maxLat = max(maxLat, lat) | ||
maxLon = max(maxLon, long) | ||
minLat = min(minLat, lat) | ||
minLon = min(minLon, long) | ||
} | ||
|
||
let center = CLLocationCoordinate2D(latitude: (minLat + maxLat) / 2, longitude: (minLon + maxLon) / 2) | ||
return center | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
// Helper struct to decode/encode CLLocationCoordinate2D since it's not directly Codable | ||
private struct Point: Codable { | ||
let latitude: CLLocationDegrees | ||
let longitude: CLLocationDegrees | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Wind.swift | ||
// windrider-ios | ||
// | ||
// Created by Daniel Grbac Bravo on 01/03/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
struct Wind: Codable{ | ||
var speed: Double // m/s | ||
var direction: Double // degrees | ||
var relativeDirection: Double | ||
var gust: Double // m/s | ||
var lastUpdated: time_t | ||
var location: String | ||
|
||
init(speed: Double, direction: Double, relativeDirection: Double, gust: Double, lastUpdated: time_t, location: String){ | ||
self.speed = speed | ||
self.direction = direction | ||
self.relativeDirection = relativeDirection | ||
self.gust = gust | ||
self.lastUpdated = lastUpdated | ||
self.location = location | ||
} | ||
// very basic wind direction calculation (probably not accurate) | ||
func calculateRelativeDirection(bikeHeading: Double, windHeading: Double ) -> Double { | ||
let relativeDirection = windHeading - bikeHeading | ||
return relativeDirection | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.