measure: convert taps and projections in analysis pixels
- Commit
9a414e9255df8b2df139018793e4261aa3c81899- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 20:14 UTC (28 days ago)
- Parents
af038c9
Symptom: placed anchors were drawn compressed into the top-left of the viewfinder, and taps landed on a ray well away from the finger. Root cause: the native engine unprojects and projects with the analysis-stream intrinsics (640x480), but ArMeasurePage passed canvas pixels on both paths: rayToWorld received nx*canvasWidth (e.g. 1080-wide) as if it were an analysis pixel, and projectPoints was told the canvas size to normalise by, so a point at analysis x=640 came back as 640/1080 of the screen width. Fix: scale taps into analysis pixels and give projectPoints the analysis size (now internal in MeasureCamera) so its normalised output maps linearly onto the canvas. The viewfinder preview and the analysis stream cover the same field of view, so the linear canvas mapping is unchanged. Verification: :measure:compileDevKotlin green (run with the batched Kotlin fixes below); cargo tests unaffected.
Diff
measure/src/main/java/com/vayunmathur/measure/ui/ArMeasurePage.kt
diff --git a/measure/src/main/java/com/vayunmathur/measure/ui/ArMeasurePage.kt b/measure/src/main/java/com/vayunmathur/measure/ui/ArMeasurePage.ktindex 794098a212..8c0f8f94b1 100644--- a/measure/src/main/java/com/vayunmathur/measure/ui/ArMeasurePage.kt+++ b/measure/src/main/java/com/vayunmathur/measure/ui/ArMeasurePage.kt@@ -25,6 +25,7 @@ import com.vayunmathur.measure.platform.MeasureViewModel import com.vayunmathur.measure.platform.trackingQualityFrom import com.vayunmathur.measure.platform.updateDiagnosticsImpl import com.vayunmathur.measure.ui.components.MeasureBottomBar+import com.vayunmathur.measure.ui.components.ANALYSIS_SIZE import com.vayunmathur.measure.ui.components.MeasureCamera import kotlinx.coroutines.delay @@ -51,11 +52,15 @@ fun ArMeasurePage(backStack: NavBackStack<Route>, viewModel: MeasureViewModel) { flat[i * 3 + 1] = a.y flat[i * 3 + 2] = a.z }+ // The engine projects with analysis-stream intrinsics and+ // normalises by the size it is given, so it must be given the+ // analysis size, not the canvas size: passing canvas pixels+ // compressed every anchor into the top-left of the screen. val projected = MeasureNative.projectPoints( sessionHandle, flat,- canvasSize.width.toDouble(),- canvasSize.height.toDouble(),+ ANALYSIS_SIZE.width.toDouble(),+ ANALYSIS_SIZE.height.toDouble(), ) screenPoints = projected.toList().chunked(3).map { c -> Offset(c[0].toFloat() * canvasSize.width, c[1].toFloat() * canvasSize.height)@@ -71,10 +76,13 @@ fun ArMeasurePage(backStack: NavBackStack<Route>, viewModel: MeasureViewModel) { onCanvasSized = { canvasSize = it }, onTap = { nx, ny -> if (canvasSize != Size.Zero) {+ // rayToWorld unprojects with analysis-stream intrinsics, so+ // the tap must be scaled into analysis pixels, not canvas+ // pixels (the two differ by the screen/analysis ratio). val hit = MeasureNative.rayToWorld( sessionHandle,- nx * canvasSize.width,- ny * canvasSize.height,+ nx * ANALYSIS_SIZE.width,+ ny * ANALYSIS_SIZE.height, ) if (hit != null) { viewModel.addResolvedAnchor(hit[0], hit[1], hit[2], hit[3] > 0.5)
measure/src/main/java/com/vayunmathur/measure/ui/components/MeasureCamera.kt
diff --git a/measure/src/main/java/com/vayunmathur/measure/ui/components/MeasureCamera.kt b/measure/src/main/java/com/vayunmathur/measure/ui/components/MeasureCamera.ktindex 6b547c910b..63fe0ff979 100644--- a/measure/src/main/java/com/vayunmathur/measure/ui/components/MeasureCamera.kt+++ b/measure/src/main/java/com/vayunmathur/measure/ui/components/MeasureCamera.kt@@ -37,7 +37,7 @@ import java.util.concurrent.Executors typealias Diagnostics = (Double, Double, Double, Int, Int, Double) -> Unit /** Analysis resolution: enough texture for tracking, cheap enough to run every frame. */-private val ANALYSIS_SIZE = Size(640, 480)+internal val ANALYSIS_SIZE = Size(640, 480) /** * Camera viewfinder plus the frame pump that drives the VIO engine.