react-native-rectangle-doc-scanner 1.10.0 → 1.11.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.
@@ -389,32 +389,17 @@ class RNRDocScannerView: UIView, AVCaptureVideoDataOutputSampleBufferDelegate, A
389
389
  private func orderPoints(_ points: [CGPoint]) -> [CGPoint] {
390
390
  guard points.count == 4 else { return points }
391
391
 
392
- let center = points.reduce(CGPoint.zero) { partial, point in
393
- CGPoint(x: partial.x + point.x / 4.0, y: partial.y + point.y / 4.0)
394
- }
395
-
396
- let angles = points.map { point -> (CGPoint, CGFloat) in
397
- let angle = atan2(point.y - center.y, point.x - center.x)
398
- return (point, angle)
399
- }
400
-
401
- let sorted = angles.sorted { $0.1 < $1.1 }.map { $0.0 }
402
-
403
- var startIndex = 0
404
- for index in 1..<sorted.count {
405
- let candidate = sorted[index]
406
- let current = sorted[startIndex]
407
- if candidate.y < current.y || (candidate.y == current.y && candidate.x < current.x) {
408
- startIndex = index
392
+ let sortedByY = points.sorted { a, b in
393
+ if a.y == b.y {
394
+ return a.x < b.x
409
395
  }
396
+ return a.y < b.y
410
397
  }
411
398
 
412
- return [
413
- sorted[startIndex % 4],
414
- sorted[(startIndex + 1) % 4],
415
- sorted[(startIndex + 2) % 4],
416
- sorted[(startIndex + 3) % 4],
417
- ]
399
+ let top = sortedByY.prefix(2).sorted { $0.x < $1.x }
400
+ let bottom = sortedByY.suffix(2).sorted { $0.x < $1.x }
401
+
402
+ return [top[0], top[1], bottom[1], bottom[0]]
418
403
  }
419
404
 
420
405
  // MARK: - Capture
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",