react-native-rectangle-doc-scanner 10.49.0 → 10.50.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.
@@ -506,28 +506,25 @@ class DocumentDetector {
506
506
  return RectangleQuality.TOO_FAR
507
507
  }
508
508
 
509
- // Check angle quality: edges should not be too skewed
510
- // More lenient threshold: 20% of edge length
511
- val topAngleThreshold = max(60.0, topEdgeLength * 0.20)
512
- val bottomAngleThreshold = max(60.0, bottomEdgeLength * 0.20)
513
- val leftAngleThreshold = max(60.0, leftEdgeLength * 0.20)
514
- val rightAngleThreshold = max(60.0, rightEdgeLength * 0.20)
515
-
516
- val topYDiff = abs(rectangle.topRight.y - rectangle.topLeft.y)
517
- val bottomYDiff = abs(rectangle.bottomLeft.y - rectangle.bottomRight.y)
518
- val leftXDiff = abs(rectangle.topLeft.x - rectangle.bottomLeft.x)
519
- val rightXDiff = abs(rectangle.topRight.x - rectangle.bottomRight.x)
520
-
521
- // Check if edges are too skewed (perspective too extreme)
522
- if (topYDiff > topAngleThreshold ||
523
- bottomYDiff > bottomAngleThreshold ||
524
- leftXDiff > leftAngleThreshold ||
525
- rightXDiff > rightAngleThreshold) {
509
+ // Check angle quality using angle ratio instead of absolute difference
510
+ // Edges should be roughly horizontal/vertical (not too skewed)
511
+ val topAngleRatio = if (topEdgeLength > 0) abs(rectangle.topRight.y - rectangle.topLeft.y) / topEdgeLength else 0.0
512
+ val bottomAngleRatio = if (bottomEdgeLength > 0) abs(rectangle.bottomLeft.y - rectangle.bottomRight.y) / bottomEdgeLength else 0.0
513
+ val leftAngleRatio = if (leftEdgeLength > 0) abs(rectangle.topLeft.x - rectangle.bottomLeft.x) / leftEdgeLength else 0.0
514
+ val rightAngleRatio = if (rightEdgeLength > 0) abs(rectangle.topRight.x - rectangle.bottomRight.x) / rightEdgeLength else 0.0
515
+
516
+ // Allow up to 30% skew (sin(~17°) 0.3)
517
+ val maxSkewRatio = 0.3
518
+
519
+ if (topAngleRatio > maxSkewRatio ||
520
+ bottomAngleRatio > maxSkewRatio ||
521
+ leftAngleRatio > maxSkewRatio ||
522
+ rightAngleRatio > maxSkewRatio) {
526
523
  if (BuildConfig.DEBUG) {
527
- Log.d(TAG, "[QUALITY] BAD_ANGLE (skew): topY=$topYDiff>${String.format("%.1f", topAngleThreshold)}, " +
528
- "bottomY=$bottomYDiff>${String.format("%.1f", bottomAngleThreshold)}, " +
529
- "leftX=$leftXDiff>${String.format("%.1f", leftAngleThreshold)}, " +
530
- "rightX=$rightXDiff>${String.format("%.1f", rightAngleThreshold)}")
524
+ Log.d(TAG, "[QUALITY] BAD_ANGLE (skew): top=${String.format("%.2f", topAngleRatio)}, " +
525
+ "bottom=${String.format("%.2f", bottomAngleRatio)}, " +
526
+ "left=${String.format("%.2f", leftAngleRatio)}, " +
527
+ "right=${String.format("%.2f", rightAngleRatio)} > $maxSkewRatio")
531
528
  }
532
529
  return RectangleQuality.BAD_ANGLE
533
530
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "10.49.0",
3
+ "version": "10.50.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",