react-native-rectangle-doc-scanner 1.11.0 → 1.12.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 +33 -11
- package/package.json +1 -1
|
@@ -282,12 +282,12 @@ class RNRDocScannerView: UIView, AVCaptureVideoDataOutputSampleBufferDelegate, A
|
|
|
282
282
|
updateNativeOverlay(with: shouldDisplayOverlay ? observation : nil)
|
|
283
283
|
|
|
284
284
|
payload = [
|
|
285
|
-
"rectangleCoordinates": [
|
|
285
|
+
"rectangleCoordinates": shouldDisplayOverlay ? [
|
|
286
286
|
"topLeft": ["x": points[0].x, "y": points[0].y],
|
|
287
287
|
"topRight": ["x": points[1].x, "y": points[1].y],
|
|
288
288
|
"bottomRight": ["x": points[2].x, "y": points[2].y],
|
|
289
289
|
"bottomLeft": ["x": points[3].x, "y": points[3].y],
|
|
290
|
-
],
|
|
290
|
+
] : NSNull(),
|
|
291
291
|
"stableCounter": currentStableCounter,
|
|
292
292
|
"frameWidth": frameSize.width,
|
|
293
293
|
"frameHeight": frameSize.height,
|
|
@@ -339,7 +339,7 @@ class RNRDocScannerView: UIView, AVCaptureVideoDataOutputSampleBufferDelegate, A
|
|
|
339
339
|
let points: [CGPoint]
|
|
340
340
|
if let previous = self.smoothedOverlayPoints, previous.count == 4 {
|
|
341
341
|
points = zip(previous, orderedPoints).map { prev, next in
|
|
342
|
-
CGPoint(x: prev.x * 0.
|
|
342
|
+
CGPoint(x: prev.x * 0.75 + next.x * 0.25, y: prev.y * 0.75 + next.y * 0.25)
|
|
343
343
|
}
|
|
344
344
|
} else {
|
|
345
345
|
points = orderedPoints
|
|
@@ -389,17 +389,39 @@ 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
|
-
|
|
393
|
-
|
|
394
|
-
|
|
392
|
+
var topLeft = points[0]
|
|
393
|
+
var topRight = points[0]
|
|
394
|
+
var bottomRight = points[0]
|
|
395
|
+
var bottomLeft = points[0]
|
|
396
|
+
|
|
397
|
+
var minSum = CGFloat.greatestFiniteMagnitude
|
|
398
|
+
var maxSum = -CGFloat.greatestFiniteMagnitude
|
|
399
|
+
var minDiff = CGFloat.greatestFiniteMagnitude
|
|
400
|
+
var maxDiff = -CGFloat.greatestFiniteMagnitude
|
|
401
|
+
|
|
402
|
+
for point in points {
|
|
403
|
+
let sum = point.x + point.y
|
|
404
|
+
if sum < minSum {
|
|
405
|
+
minSum = sum
|
|
406
|
+
topLeft = point
|
|
407
|
+
}
|
|
408
|
+
if sum > maxSum {
|
|
409
|
+
maxSum = sum
|
|
410
|
+
bottomRight = point
|
|
395
411
|
}
|
|
396
|
-
return a.y < b.y
|
|
397
|
-
}
|
|
398
412
|
|
|
399
|
-
|
|
400
|
-
|
|
413
|
+
let diff = point.x - point.y
|
|
414
|
+
if diff < minDiff {
|
|
415
|
+
minDiff = diff
|
|
416
|
+
bottomLeft = point
|
|
417
|
+
}
|
|
418
|
+
if diff > maxDiff {
|
|
419
|
+
maxDiff = diff
|
|
420
|
+
topRight = point
|
|
421
|
+
}
|
|
422
|
+
}
|
|
401
423
|
|
|
402
|
-
return [
|
|
424
|
+
return [topLeft, topRight, bottomRight, bottomLeft]
|
|
403
425
|
}
|
|
404
426
|
|
|
405
427
|
// MARK: - Capture
|