react-native-rectangle-doc-scanner 7.63.0 → 7.64.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.
@@ -669,56 +669,28 @@ class CameraController(
669
669
  val centerX = viewRect.centerX()
670
670
  val centerY = viewRect.centerY()
671
671
 
672
- fun buildTransform(appliedRotation: Int): Pair<Matrix, FloatArray> {
673
- val candidate = Matrix()
674
- val swap = appliedRotation == 90 || appliedRotation == 270
675
- val bufferWidth = if (swap) preview.height.toFloat() else preview.width.toFloat()
676
- val bufferHeight = if (swap) preview.width.toFloat() else preview.height.toFloat()
677
- val bufferRect = RectF(0f, 0f, bufferWidth, bufferHeight)
678
- bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
679
-
680
- candidate.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
681
- val scale = max(viewWidth / bufferRect.width(), viewHeight / bufferRect.height())
682
- candidate.postScale(scale, scale, centerX, centerY)
683
- if (appliedRotation != 0) {
684
- candidate.postRotate(appliedRotation.toFloat(), centerX, centerY)
685
- }
686
-
687
- val pts = floatArrayOf(
688
- 0f, 0f,
689
- bufferWidth, 0f,
690
- 0f, bufferHeight,
691
- bufferWidth, bufferHeight
692
- )
693
- candidate.mapPoints(pts)
694
- return Pair(candidate, pts)
695
- }
672
+ val appliedRotation = rotationDegrees
673
+ val swap = appliedRotation == 90 || appliedRotation == 270
674
+ val bufferWidth = if (swap) preview.height.toFloat() else preview.width.toFloat()
675
+ val bufferHeight = if (swap) preview.width.toFloat() else preview.height.toFloat()
676
+ val bufferRect = RectF(0f, 0f, bufferWidth, bufferHeight)
677
+ bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
696
678
 
697
- fun scoreCoverage(pts: FloatArray): Float {
698
- val minX = min(min(pts[0], pts[2]), min(pts[4], pts[6]))
699
- val maxX = max(max(pts[0], pts[2]), max(pts[4], pts[6]))
700
- val minY = min(min(pts[1], pts[3]), min(pts[5], pts[7]))
701
- val maxY = max(max(pts[1], pts[3]), max(pts[5], pts[7]))
702
-
703
- val left = max(viewRect.left, minX)
704
- val top = max(viewRect.top, minY)
705
- val right = min(viewRect.right, maxX)
706
- val bottom = min(viewRect.bottom, maxY)
707
- val intersection = if (right > left && bottom > top) (right - left) * (bottom - top) else 0f
708
- val viewArea = viewRect.width() * viewRect.height()
709
- return if (viewArea > 0f) intersection / viewArea else 0f
679
+ val matrix = Matrix()
680
+ matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
681
+ val scale = max(viewWidth / bufferRect.width(), viewHeight / bufferRect.height())
682
+ matrix.postScale(scale, scale, centerX, centerY)
683
+ if (appliedRotation != 0) {
684
+ matrix.postRotate(appliedRotation.toFloat(), centerX, centerY)
710
685
  }
711
686
 
712
- val positive = rotationDegrees
713
- val negative = if (rotationDegrees == 0) 0 else (360 - rotationDegrees) % 360
714
- val (matrixPos, ptsPos) = buildTransform(positive)
715
- val (matrixNeg, ptsNeg) = buildTransform(negative)
716
- val scorePos = scoreCoverage(ptsPos)
717
- val scoreNeg = scoreCoverage(ptsNeg)
718
-
719
- val appliedRotation = if (scoreNeg > scorePos) negative else positive
720
- val appliedMatrix = if (appliedRotation == positive) matrixPos else matrixNeg
721
- val appliedPts = if (appliedRotation == positive) ptsPos else ptsNeg
687
+ val pts = floatArrayOf(
688
+ 0f, 0f,
689
+ bufferWidth, 0f,
690
+ 0f, bufferHeight,
691
+ bufferWidth, bufferHeight
692
+ )
693
+ matrix.mapPoints(pts)
722
694
 
723
695
  Log.d(
724
696
  TAG,
@@ -726,17 +698,17 @@ class CameraController(
726
698
  "view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}"
727
699
  )
728
700
 
729
- previewView.setTransform(appliedMatrix)
730
- latestTransform = Matrix(appliedMatrix)
701
+ previewView.setTransform(matrix)
702
+ latestTransform = Matrix(matrix)
731
703
  latestBufferWidth = preview.width
732
704
  latestBufferHeight = preview.height
733
705
  latestTransformRotation = appliedRotation
734
706
 
735
707
  Log.d(
736
708
  TAG,
737
- "[TRANSFORM] appliedRotation=$appliedRotation scores pos=$scorePos neg=$scoreNeg viewClass=${previewView.javaClass.name} " +
738
- "isTextureView=${previewView is TextureView} matrix=$appliedMatrix " +
739
- "pts=[${appliedPts[0]},${appliedPts[1]} ${appliedPts[2]},${appliedPts[3]} ${appliedPts[4]},${appliedPts[5]} ${appliedPts[6]},${appliedPts[7]}]"
709
+ "[TRANSFORM] viewClass=${previewView.javaClass.name} isTextureView=${previewView is TextureView} " +
710
+ "buffer=${bufferWidth}x${bufferHeight} scale=$scale center=${centerX}x${centerY} matrix=$matrix " +
711
+ "pts=[${pts[0]},${pts[1]} ${pts[2]},${pts[3]} ${pts[4]},${pts[5]} ${pts[6]},${pts[7]}]"
740
712
  )
741
713
  val recomputed = computeRotationDegrees()
742
714
  if (rotationDegrees != recomputed) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.63.0",
3
+ "version": "7.64.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",