react-native-rectangle-doc-scanner 1.10.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.
@@ -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.85 + next.x * 0.15, y: prev.y * 0.85 + next.y * 0.15)
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,32 +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
- 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 }
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
411
+ }
402
412
 
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
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
409
421
  }
410
422
  }
411
423
 
412
- return [
413
- sorted[startIndex % 4],
414
- sorted[(startIndex + 1) % 4],
415
- sorted[(startIndex + 2) % 4],
416
- sorted[(startIndex + 3) % 4],
417
- ]
424
+ return [topLeft, topRight, bottomRight, bottomLeft]
418
425
  }
419
426
 
420
427
  // 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.12.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",