From f8162fdf485ca2f727760180ab9ecb6da7f0dd20 Mon Sep 17 00:00:00 2001 From: Kyle Corry Date: Sat, 9 Dec 2023 08:15:43 -0500 Subject: [PATCH] Remove ARPosition and ARSize --- .../tools/augmented_reality/ARMarkerImpl.kt | 3 +- .../tools/augmented_reality/ARPosition.kt | 32 ---------------- .../tools/augmented_reality/ARSize.kt | 38 ------------------- .../AugmentedRealityFragment.kt | 4 +- .../augmented_reality/AugmentedRealityView.kt | 11 +++--- 5 files changed, 10 insertions(+), 78 deletions(-) delete mode 100644 app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARPosition.kt delete mode 100644 app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARSize.kt diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARMarkerImpl.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARMarkerImpl.kt index 1dad18936..604d12a2c 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARMarkerImpl.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARMarkerImpl.kt @@ -9,8 +9,7 @@ import com.kylecorry.trail_sense.tools.augmented_reality.position.GeographicPosi import com.kylecorry.trail_sense.tools.augmented_reality.position.SphericalPositionStrategy import kotlin.math.hypot -// TODO: Is the interface even needed? -// TODO: Use ARPosition and ARSize +// TODO: Are the helper methods needed, or can the constructor be called directly? class ARMarkerImpl private constructor( private val positionStrategy: ARPositionStrategy, private val canvasObject: CanvasObject, diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARPosition.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARPosition.kt deleted file mode 100644 index 96ba0cc7a..000000000 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARPosition.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.kylecorry.trail_sense.tools.augmented_reality - -import com.kylecorry.sol.units.Coordinate -import com.kylecorry.trail_sense.shared.camera.AugmentedRealityUtils - -// TODO: Use ARPositionStrategy instead -class ARPosition private constructor( - private val horizon: AugmentedRealityView.HorizonCoordinate?, - private val coordinate: Coordinate?, - private val altitude: Float?, -) { - - fun getHorizonCoordinate( - myLocation: Coordinate, - myElevation: Float - ): AugmentedRealityView.HorizonCoordinate { - return horizon ?: coordinate?.let { - AugmentedRealityUtils.getHorizonCoordinate(myLocation, myElevation, it, altitude) - } ?: AugmentedRealityView.HorizonCoordinate(0f, 0f, 1f) - } - - companion object { - fun horizon(horizon: AugmentedRealityView.HorizonCoordinate): ARPosition { - return ARPosition(horizon, null, null) - } - - fun geographic(coordinate: Coordinate, altitude: Float? = null): ARPosition { - return ARPosition(null, coordinate, altitude) - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARSize.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARSize.kt deleted file mode 100644 index 3e6e26e83..000000000 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARSize.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.kylecorry.trail_sense.tools.augmented_reality - -import com.kylecorry.sol.units.Coordinate -import com.kylecorry.sol.units.Distance -import com.kylecorry.trail_sense.shared.camera.AugmentedRealityUtils -import kotlin.math.hypot - -class ARSize private constructor( - private val angularSize: Float?, - actualSize: Distance?, - private val location: Coordinate?, - private val elevation: Float? -) { - - private val actualMeters = actualSize?.meters()?.distance - - fun getAngularSize(myLocation: Coordinate, myElevation: Float): Float { - if (actualMeters != null && location != null) { - val distance = hypot( - myLocation.distanceTo(location), - (elevation ?: myElevation) - myElevation - ) - return AugmentedRealityUtils.getAngularSize(actualMeters, distance) - } - return angularSize ?: 1f - } - - companion object { - fun angular(angularSize: Float): ARSize { - return ARSize(angularSize, null, null, null) - } - - fun geographic(size: Distance, location: Coordinate, elevation: Float? = null): ARSize { - return ARSize(null, size, location, elevation) - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt index 30c3cf91a..500fe71f4 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt @@ -37,6 +37,7 @@ import com.kylecorry.trail_sense.shared.permissions.alertNoCameraPermission import com.kylecorry.trail_sense.shared.permissions.requestCamera import com.kylecorry.trail_sense.shared.sensors.LocationSubsystem import com.kylecorry.andromeda.fragments.observeFlow +import com.kylecorry.trail_sense.tools.augmented_reality.position.GeographicPositionStrategy import kotlinx.coroutines.Dispatchers import java.time.Duration import java.time.LocalDate @@ -61,6 +62,7 @@ class AugmentedRealityFragment : BoundFragment( Distance.meters(userPrefs.navigation.maxBeaconDistance), onFocus = this::onBeaconFocused ) { + println(it) if (navigator.getDestinationId() != it.id) { navigator.navigateTo(it) } else { @@ -102,7 +104,7 @@ class AugmentedRealityFragment : BoundFragment( if (it == null) { binding.arView.clearGuide() } else { - binding.arView.guideTo(ARPosition.geographic(it.coordinate, it.elevation)) { + binding.arView.guideTo(GeographicPositionStrategy(it.coordinate, it.elevation)) { // Do nothing when reached } } diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityView.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityView.kt index 9a66da02b..f73ce847f 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityView.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityView.kt @@ -27,6 +27,7 @@ import com.kylecorry.trail_sense.shared.declination.DeclinationUtils import com.kylecorry.trail_sense.shared.sensors.SensorService import com.kylecorry.trail_sense.shared.text import com.kylecorry.trail_sense.shared.textDimensions +import com.kylecorry.trail_sense.tools.augmented_reality.position.ARPositionStrategy import java.time.Duration import kotlin.math.atan2 @@ -108,7 +109,7 @@ class AugmentedRealityView : CanvasView { private val layerLock = Any() // Guidance - private var guideLocation: ARPosition? = null + private var guideStrategy: ARPositionStrategy? = null private var guideThreshold: Float? = null private var onGuideReached: (() -> Unit)? = null @@ -155,17 +156,17 @@ class AugmentedRealityView : CanvasView { } fun guideTo( - location: ARPosition, + guideStrategy: ARPositionStrategy, thresholdDegrees: Float? = null, onReached: () -> Unit = { clearGuide() } ) { - guideLocation = location + this.guideStrategy = guideStrategy guideThreshold = thresholdDegrees onGuideReached = onReached } fun clearGuide() { - guideLocation = null + guideStrategy = null guideThreshold = null onGuideReached = null } @@ -224,7 +225,7 @@ class AugmentedRealityView : CanvasView { private fun drawGuidance() { // Draw an arrow around the reticle that points to the desired location - val coordinate = guideLocation?.getHorizonCoordinate(location, altitude) ?: return + val coordinate = guideStrategy?.getHorizonCoordinate(this) ?: return val threshold = guideThreshold val point = toPixel(coordinate) val center = PixelCoordinate(width / 2f, height / 2f)