Modern Apps git

← Modern-Apps.git

measure: clear anchors when tracking is lost

Commit
e204dbb902817cba4c9b4dec4e37c533078bb2e0
Author
Vayun Mathur <[email protected]>
When
2026-11-07 20:15 UTC (28 days ago)
Parents
983feec
Symptom: after tracking was lost, previously placed anchors stayed
on screen with their distances still quoted, in a world frame the
engine could no longer re-observe.

Root cause: onTrackingUpdateImpl copied the new quality into state
and left anchors and derived measurements untouched, contradicting
the documented TrackingQuality.Lost contract.

Fix: on the transition into Lost, drop anchors and the derived
distance/area/perimeter and un-close the polygon.

Verification: :measure:compileDevKotlin and :measure:testDevUnitTest
green in the final batched run.

Diff

measure/src/main/java/com/vayunmathur/measure/platform/MeasureSensorOps.kt
diff --git a/measure/src/main/java/com/vayunmathur/measure/platform/MeasureSensorOps.kt b/measure/src/main/java/com/vayunmathur/measure/platform/MeasureSensorOps.ktindex 96ce37c620..2257087f92 100644--- a/measure/src/main/java/com/vayunmathur/measure/platform/MeasureSensorOps.kt+++ b/measure/src/main/java/com/vayunmathur/measure/platform/MeasureSensorOps.kt@@ -133,7 +133,23 @@ internal fun MeasureViewModel.setPixelsPerMmImpl(v: Float) { }  internal fun MeasureViewModel.onTrackingUpdateImpl(quality: TrackingQuality, hasPlane: Boolean) {-    arState.value = arState.value.copy(quality = quality, hasPlane = hasPlane)+    arState.value = if (quality == TrackingQuality.Lost) {+        // Anchors from before a loss sit in a world frame the engine can+        // no longer re-observe (see TrackingQuality.Lost); leaving them+        // on screen would keep quoting distances that are not anchored+        // to anything.+        arState.value.copy(+            quality = quality,+            hasPlane = hasPlane,+            anchors = emptyList(),+            distanceM = null,+            areaM2 = null,+            perimeterM = null,+            polygonClosed = false,+        )+    } else {+        arState.value.copy(quality = quality, hasPlane = hasPlane)+    } }  internal fun MeasureViewModel.setCameraPermissionImpl(granted: Boolean) {