react-native-rectangle-doc-scanner 10.36.0 → 10.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -457,23 +457,41 @@ class CameraController(
457
457
  else -> 0
458
458
  }
459
459
 
460
- // Simple fit-center scaling like Camera2 did
461
- // The image analysis coordinates are in the image's coordinate space (imageWidth x imageHeight)
462
- // We just need to scale and center them to the view, matching how Camera2 worked.
460
+ // For sensor 90° (phones): coordinates are in sensor space, need 90° rotation
461
+ // For sensor (tablets): coordinates are already correct orientation
462
+
463
+ // First rotate coordinates if needed (sensor 90° means image is rotated 90° CW in sensor space)
464
+ fun rotatePoint(point: org.opencv.core.Point): org.opencv.core.Point {
465
+ return if (sensorOrientation == 90) {
466
+ // Rotate 90° CCW to convert from sensor space to display space
467
+ org.opencv.core.Point(
468
+ point.y,
469
+ imageWidth - point.x
470
+ )
471
+ } else {
472
+ point
473
+ }
474
+ }
475
+
476
+ // After rotation, determine final dimensions
477
+ val finalWidth = if (sensorOrientation == 90) imageHeight else imageWidth
478
+ val finalHeight = if (sensorOrientation == 90) imageWidth else imageHeight
463
479
 
464
- val scaleX = viewWidth / imageWidth.toFloat()
465
- val scaleY = viewHeight / imageHeight.toFloat()
466
- val scale = scaleX.coerceAtMost(scaleY) // Fit (preserve aspect ratio)
480
+ // Then apply fit-center scaling
481
+ val scaleX = viewWidth / finalWidth.toFloat()
482
+ val scaleY = viewHeight / finalHeight.toFloat()
483
+ val scale = scaleX.coerceAtMost(scaleY)
467
484
 
468
- val scaledWidth = imageWidth * scale
469
- val scaledHeight = imageHeight * scale
485
+ val scaledWidth = finalWidth * scale
486
+ val scaledHeight = finalHeight * scale
470
487
  val offsetX = (viewWidth - scaledWidth) / 2f
471
488
  val offsetY = (viewHeight - scaledHeight) / 2f
472
489
 
473
490
  fun transformPoint(point: org.opencv.core.Point): org.opencv.core.Point {
491
+ val rotated = rotatePoint(point)
474
492
  return org.opencv.core.Point(
475
- point.x * scale + offsetX,
476
- point.y * scale + offsetY
493
+ rotated.x * scale + offsetX,
494
+ rotated.y * scale + offsetY
477
495
  )
478
496
  }
479
497
 
@@ -484,11 +502,11 @@ class CameraController(
484
502
  transformPoint(rectangle.bottomRight)
485
503
  )
486
504
 
487
- Log.d(TAG, "[MAPPING] Simple fit-center: Image ${imageWidth}x${imageHeight}, " +
488
- "View ${viewWidth.toInt()}x${viewHeight.toInt()}, Scale: $scale, " +
489
- "Offset: ($offsetX, $offsetY)")
505
+ Log.d(TAG, "[MAPPING] Sensor: ${sensorOrientation}°, Image: ${imageWidth}x${imageHeight} → Final: ${finalWidth}x${finalHeight}")
506
+ Log.d(TAG, "[MAPPING] View: ${viewWidth.toInt()}x${viewHeight.toInt()}, Scale: $scale, Offset: ($offsetX, $offsetY)")
490
507
  Log.d(TAG, "[MAPPING] TL: (${rectangle.topLeft.x}, ${rectangle.topLeft.y}) → " +
491
- "(${result.topLeft.x}, ${result.topLeft.y})")
508
+ "Rotated: (${rotatePoint(rectangle.topLeft).x}, ${rotatePoint(rectangle.topLeft).y})" +
509
+ "Final: (${result.topLeft.x}, ${result.topLeft.y})")
492
510
 
493
511
  return result
494
512
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "10.36.0",
3
+ "version": "10.37.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",