Skip to content

Commit

Permalink
Step advance edge case improvements (#387)
Browse files Browse the repository at this point in the history
* Rust: refactor step advance model to allow for min threshold from end

* First pass at more changes

* Committing a bit more...

* Bump AGP

* Commit most snapshots

* Commit contentious section of snapshot

* Fix non-compiling code

* Cleanup

* iOS cleanup

* Rollup of Rust dependency updates

* Update snapshots

* Finishing touches

* Bump version

* Fix iOS test code

* Apply suggested name change

* Update iOS guide

* Update the rest of the docs

* Fix the web!

* Clean up examples

* prettier

* Update snapshot
  • Loading branch information
ianthetechie authored Dec 18, 2024
1 parent ea0a50e commit c0f816b
Show file tree
Hide file tree
Showing 30 changed files with 113,146 additions and 153 deletions.
5 changes: 5 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
builder:
configs:
- documentation_targets: [FerrostarCore, FerrostarMapLibreUI, FerrostarSwiftUI]
platform: ios
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/maplibre/swiftui-dsl",
"state" : {
"revision" : "ba76be30097bb92f2316742316c2090cef934910",
"version" : "0.4.1"
"revision" : "e9ad08274471fb30e8cfddf55c3a6c5426943b20",
"version" : "0.4.3"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import uniffi.ferrostar.RouteRequest
import uniffi.ferrostar.RouteRequestGenerator
import uniffi.ferrostar.RouteResponseParser
import uniffi.ferrostar.RouteStep
import uniffi.ferrostar.SpecialAdvanceConditions
import uniffi.ferrostar.StepAdvanceMode
import uniffi.ferrostar.UserLocation
import uniffi.ferrostar.VisualInstruction
Expand Down Expand Up @@ -397,7 +398,11 @@ class FerrostarCoreTest {
core.startNavigation(
routes.first(),
NavigationControllerConfig(
stepAdvance = StepAdvanceMode.RelativeLineStringDistance(16U, 16U),
stepAdvance =
StepAdvanceMode.RelativeLineStringDistance(
16U,
specialAdvanceConditions =
SpecialAdvanceConditions.MinimumDistanceFromCurrentStepLine(16U)),
routeDeviationTracking =
RouteDeviationTracking.Custom(
detector =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,20 @@ class SimulatedLocationProvider : LocationProvider {
}

private suspend fun startSimulation() {
var pendingCompletion = false

while (true) {
delay((1.0 / warpFactor.toFloat()).toDuration(DurationUnit.SECONDS))
val initialState = simulationState ?: return
val updatedState = advanceLocationSimulation(initialState)

// Stop if the route has been fully simulated (no state change).
if (updatedState == initialState) {
return
if (pendingCompletion) {
return
} else {
pendingCompletion = true
}
}

simulationState = updatedState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import okhttp3.OkHttpClient
import uniffi.ferrostar.CourseFiltering
import uniffi.ferrostar.NavigationControllerConfig
import uniffi.ferrostar.RouteDeviationTracking
import uniffi.ferrostar.SpecialAdvanceConditions
import uniffi.ferrostar.StepAdvanceMode

/**
Expand Down Expand Up @@ -86,7 +87,11 @@ object AppModule {
navigationControllerConfig =
NavigationControllerConfig(
StepAdvanceMode.RelativeLineStringDistance(
minimumHorizontalAccuracy = 25U, automaticAdvanceDistance = 10U),
minimumHorizontalAccuracy = 25U,
specialAdvanceConditions =
// NOTE: We have not yet put this threshold through extensive real-world
// testing
SpecialAdvanceConditions.MinimumDistanceFromCurrentStepLine(10U)),
RouteDeviationTracking.StaticThreshold(15U, 50.0),
CourseFiltering.SNAP_TO_ROUTE),
options =
Expand Down
5 changes: 4 additions & 1 deletion apple/DemoApp/Demo/AppEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class AppEnvironment: ObservableObject {
// Configure the navigation session.
// You have a lot of flexibility here based on your use case.
let config = SwiftNavigationControllerConfig(
stepAdvance: .relativeLineStringDistance(minimumHorizontalAccuracy: 32, automaticAdvanceDistance: 10),
stepAdvance: .relativeLineStringDistance(
minimumHorizontalAccuracy: 32,
specialAdvanceConditions: .minimumDistanceFromCurrentStepLine(10)
),
routeDeviationTracking: .staticThreshold(minimumHorizontalAccuracy: 25, maxAcceptableDeviation: 20),
snappedLocationCourseFiltering: .snapToRoute
)
Expand Down
4 changes: 3 additions & 1 deletion apple/DemoApp/Demo/NavigationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class NavigationDelegate: FerrostarCoreDelegate {
// but we provide devs with flexibility here.
let config = SwiftNavigationControllerConfig(
stepAdvance: .relativeLineStringDistance(minimumHorizontalAccuracy: 32,
automaticAdvanceDistance: 10),
specialAdvanceConditions: .minimumDistanceFromCurrentStepLine(
10
)),
routeDeviationTracking: .staticThreshold(minimumHorizontalAccuracy: 25, maxAcceptableDeviation: 20),
snappedLocationCourseFiltering: .snapToRoute
)
Expand Down
10 changes: 8 additions & 2 deletions apple/Sources/FerrostarCore/Location.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ public class SimulatedLocationProvider: LocationProviding, ObservableObject {
}

private func updateLocation() async throws {
var pendingCompletion = false

while isUpdating {
// Exit if the task has been cancelled.
try Task.checkCancellation()
Expand All @@ -213,8 +215,12 @@ public class SimulatedLocationProvider: LocationProviding, ObservableObject {

// Stop if the route has been fully simulated (no state change).
if initialState == updatedState {
stopUpdating()
return
if pendingCompletion {
stopUpdating()
return
} else {
pendingCompletion = true
}
}

// Bump the last location.
Expand Down
4 changes: 2 additions & 2 deletions apple/Sources/FerrostarSwiftUI/Views/InstructionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public struct InstructionsView: View {
maneuverType: visualInstruction.primaryContent.maneuverType,
maneuverModifier: visualInstruction.primaryContent.maneuverModifier,
distanceFormatter: distanceFormatter,
distanceToNextManeuver: step.distance == 0 ? nil : step.distance,
distanceToNextManeuver: step.distance,
theme: primaryRowTheme
)
.font(.title2.bold())
Expand All @@ -106,7 +106,7 @@ public struct InstructionsView: View {
maneuverType: visualInstruction.primaryContent.maneuverType,
maneuverModifier: visualInstruction.primaryContent.maneuverModifier,
distanceFormatter: distanceFormatter,
distanceToNextManeuver: distanceToNextManeuver == 0 ? nil : distanceToNextManeuver,
distanceToNextManeuver: distanceToNextManeuver,
theme: primaryRowTheme
)
.font(.title2.bold())
Expand Down
132 changes: 124 additions & 8 deletions apple/Sources/UniFFI/ferrostar.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion apple/Tests/FerrostarCoreTests/FerrostarCoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,10 @@ final class FerrostarCoreTests: XCTestCase {

locationProvider.lastLocation = CLLocation(latitude: 0, longitude: 0).userLocation
let config = SwiftNavigationControllerConfig(
stepAdvance: .relativeLineStringDistance(minimumHorizontalAccuracy: 16, automaticAdvanceDistance: 16),
stepAdvance: .relativeLineStringDistance(
minimumHorizontalAccuracy: 16,
specialAdvanceConditions: .advanceAtDistanceFromEnd(16)
),
routeDeviationTracking: .custom(detector: { _, _, _ in
// Pretend that the user is always off route
.offRoute(deviationFromRouteLine: 42)
Expand Down
1 change: 1 addition & 0 deletions common/ferrostar/proptest-regressions/algorithms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ cc 9343327e3112d7e3337bda8d95349a10f7882025f43fa76201929eba8deaa87d # shrinks to
cc b87a314ecd2957021a836398aa55a516f91d5fd526c2a4f9e5a57a42e8f597ae # shrinks to x1 = 1.7321418387536385, y1 = 1.3433541773527303e-308, x2 = 0.0, y2 = 17.833686113757857
cc 9fa5f4eafafbffedde0d3fdaf6ac83f92c4aae3c9382d58855c07b562e1c59f1 # shrinks to x1 = 8.250574670883433e29, y1 = 0.0, x2 = 0.0, y2 = 7.980493463728753e-93, x3 = 0.0, y3 = 0.0, has_next_step = true, distance = 0, minimum_horizontal_accuracy = 0, excess_inaccuracy = 0.0, automatic_advance_distance = None
cc 561ce71db95074e5505c8db3e95cb5d0c5b14a2e38e137dc7e72954dadc1608b # shrinks to bearing = 359.65552398004445
cc 314739c47b6e4dc64c8e6170e02b9adf02b11229ce552fc418a0e3ecf902c5a4 # shrinks to x1 = 0.0, y1 = 0.0, x2 = -7.67381909875473e-185, y2 = 0.0, x3 = -1.50341296605448e-308, y3 = -0.0, has_next_step = true, distance = 0, minimum_horizontal_accuracy = 0, excess_inaccuracy = 0.0, threshold = Some(1)
Loading

0 comments on commit c0f816b

Please sign in to comment.