From 90d36c681038ae2fc3570e52b47fc6025757c3c1 Mon Sep 17 00:00:00 2001 From: Kyle Corry Date: Fri, 2 Feb 2024 18:52:10 -0500 Subject: [PATCH] Limit nearby path points --- .../domain/position/GeographicARPoint.kt | 6 +++--- .../tools/augmented_reality/ui/layers/ARPathLayer.kt | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/domain/position/GeographicARPoint.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/domain/position/GeographicARPoint.kt index 595719232..3df06d4cf 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/domain/position/GeographicARPoint.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/domain/position/GeographicARPoint.kt @@ -12,9 +12,9 @@ import kotlin.math.hypot * @param actualDiameter The actual diameter of the point in meters, defaults to 1 meter */ class GeographicARPoint( - private val location: Coordinate, - private val elevation: Float? = null, - private val actualDiameter: Float = 1f + val location: Coordinate, + val elevation: Float? = null, + val actualDiameter: Float = 1f ) : ARPoint { override fun getAngularDiameter(view: AugmentedRealityView): Float { val distance = hypot( diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ui/layers/ARPathLayer.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ui/layers/ARPathLayer.kt index 95de7e8db..80bbac51f 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ui/layers/ARPathLayer.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ui/layers/ARPathLayer.kt @@ -28,6 +28,9 @@ class ARPathLayer(viewDistance: Distance) : ARLayer, IPathLayer { private var lastLocation = Coordinate.zero private val viewDistanceMeters = viewDistance.meters().distance + // A limit to ensure performance is not impacted + private val nearbyLimit = 20 + override fun draw(drawer: ICanvasDrawer, view: AugmentedRealityView) { lastLocation = view.location pointLayer.draw(drawer, view) @@ -86,8 +89,7 @@ class ARPathLayer(viewDistance: Distance) : ARLayer, IPathLayer { bounds, output, zValues = z, - zOutput = zOutput, - rdpFilterEpsilon = 10f + zOutput = zOutput ) // Step 3: Interpolate between the points for a higher resolution @@ -112,6 +114,12 @@ class ARPathLayer(viewDistance: Distance) : ARLayer, IPathLayer { finalPoints.add(GeographicARPoint(projectedCoordinate, elevation)) } + // Limit to the closest points + if (finalPoints.size > nearbyLimit) { + finalPoints.sortBy { it.location.distanceTo(location) } + return finalPoints.subList(0, nearbyLimit) + } + return finalPoints }