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.
- package/ios/RNRDocScannerView.swift +8 -23
- package/package.json +1 -1
|
@@ -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
|
|
393
|
-
|
|
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
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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
|