Skip to content

Commit

Permalink
feat: added rough Wind Struct and appended it to route
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgrbacbravo committed Mar 1, 2024
1 parent 27dd2fe commit 858fde1
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 86 deletions.
Binary file added NLD_wind-speed_10m.tif
Binary file not shown.
14 changes: 13 additions & 1 deletion windrider-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
652D84312B9200B100AE8CCD /* RouteMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 652D84302B9200B100AE8CCD /* RouteMapView.swift */; };
652D84332B92019B00AE8CCD /* Route.swift in Sources */ = {isa = PBXBuildFile; fileRef = 652D84322B92019B00AE8CCD /* Route.swift */; };
652D84362B92524F00AE8CCD /* Wind.swift in Sources */ = {isa = PBXBuildFile; fileRef = 652D84352B92524F00AE8CCD /* Wind.swift */; };
653CDEE62B909823000D4E8B /* windrider_iosApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653CDEE52B909823000D4E8B /* windrider_iosApp.swift */; };
653CDEEC2B909825000D4E8B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 653CDEEB2B909825000D4E8B /* Assets.xcassets */; };
653CDEEF2B909825000D4E8B /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 653CDEEE2B909825000D4E8B /* Preview Assets.xcassets */; };
Expand Down Expand Up @@ -41,6 +42,7 @@
/* Begin PBXFileReference section */
652D84302B9200B100AE8CCD /* RouteMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouteMapView.swift; sourceTree = "<group>"; };
652D84322B92019B00AE8CCD /* Route.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Route.swift; sourceTree = "<group>"; };
652D84352B92524F00AE8CCD /* Wind.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Wind.swift; sourceTree = "<group>"; };
653CDEE22B909823000D4E8B /* windrider-ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "windrider-ios.app"; sourceTree = BUILT_PRODUCTS_DIR; };
653CDEE52B909823000D4E8B /* windrider_iosApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = windrider_iosApp.swift; sourceTree = "<group>"; };
653CDEEB2B909825000D4E8B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -81,6 +83,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
652D84342B9251AD00AE8CCD /* Models */ = {
isa = PBXGroup;
children = (
652D84322B92019B00AE8CCD /* Route.swift */,
652D84352B92524F00AE8CCD /* Wind.swift */,
);
path = Models;
sourceTree = "<group>";
};
653CDED92B909823000D4E8B = {
isa = PBXGroup;
children = (
Expand All @@ -104,13 +115,13 @@
653CDEE42B909823000D4E8B /* windrider-ios */ = {
isa = PBXGroup;
children = (
652D84342B9251AD00AE8CCD /* Models */,
653CDEE52B909823000D4E8B /* windrider_iosApp.swift */,
655D4EAC2B90BAC5008B6B2B /* MapView.swift */,
655D4EAE2B90C072008B6B2B /* ConditionPreviewView.swift */,
655D4EB02B90C250008B6B2B /* WindCondition.swift */,
655D4EB22B90C4BD008B6B2B /* ContentView.swift */,
652D84302B9200B100AE8CCD /* RouteMapView.swift */,
652D84322B92019B00AE8CCD /* Route.swift */,
653CDEEB2B909825000D4E8B /* Assets.xcassets */,
653CDEED2B909825000D4E8B /* Preview Content */,
);
Expand Down Expand Up @@ -279,6 +290,7 @@
652D84312B9200B100AE8CCD /* RouteMapView.swift in Sources */,
655D4EAF2B90C072008B6B2B /* ConditionPreviewView.swift in Sources */,
655D4EB12B90C250008B6B2B /* WindCondition.swift in Sources */,
652D84362B92524F00AE8CCD /* Wind.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
53 changes: 53 additions & 0 deletions windrider-ios/Models/Route.swift
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
}
}
32 changes: 32 additions & 0 deletions windrider-ios/Models/Wind.swift
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
}
}
85 changes: 0 additions & 85 deletions windrider-ios/Route.swift

This file was deleted.

0 comments on commit 858fde1

Please sign in to comment.