Skip to content

Commit

Permalink
Limit nearby path points
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Feb 2, 2024
1 parent cfc58b8 commit 90d36c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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

}
Expand Down

0 comments on commit 90d36c6

Please sign in to comment.