react-native-rectangle-doc-scanner 0.41.0 → 0.42.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.
@@ -103,6 +103,7 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
103
103
  const SNAP_CENTER_DISTANCE = 12;
104
104
  const BLEND_DISTANCE = 65; // pixels; softly ease between similar shapes
105
105
  const MAX_CENTER_DELTA = 85;
106
+ const REJECT_CENTER_DELTA = 145;
106
107
  const MAX_AREA_SHIFT = 0.45;
107
108
  const HISTORY_RESET_DISTANCE = 70;
108
109
  const MIN_AREA_RATIO = 0.0035;
@@ -174,6 +175,18 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
174
175
  const candidateArea = (0, quad_1.quadArea)(candidate);
175
176
  const centerDelta = Math.hypot(candidateCenter.x - anchorCenter.x, candidateCenter.y - anchorCenter.y);
176
177
  const areaShift = anchorArea > 0 ? Math.abs(anchorArea - candidateArea) / anchorArea : 0;
178
+ if (centerDelta >= REJECT_CENTER_DELTA || areaShift > 1.2) {
179
+ missingFrameCountRef.current += 1;
180
+ if (missingFrameCountRef.current <= 2) {
181
+ setQuad(anchor);
182
+ return;
183
+ }
184
+ smoothingBufferRef.current = [];
185
+ anchorQuadRef.current = null;
186
+ lastQuadRef.current = null;
187
+ setQuad(null);
188
+ return;
189
+ }
177
190
  if (delta <= SNAP_DISTANCE && centerDelta <= SNAP_CENTER_DISTANCE && areaShift <= 0.08) {
178
191
  candidate = anchor;
179
192
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -119,6 +119,7 @@ export const DocScanner: React.FC<Props> = ({
119
119
  const SNAP_CENTER_DISTANCE = 12;
120
120
  const BLEND_DISTANCE = 65; // pixels; softly ease between similar shapes
121
121
  const MAX_CENTER_DELTA = 85;
122
+ const REJECT_CENTER_DELTA = 145;
122
123
  const MAX_AREA_SHIFT = 0.45;
123
124
  const HISTORY_RESET_DISTANCE = 70;
124
125
  const MIN_AREA_RATIO = 0.0035;
@@ -207,6 +208,21 @@ export const DocScanner: React.FC<Props> = ({
207
208
  const centerDelta = Math.hypot(candidateCenter.x - anchorCenter.x, candidateCenter.y - anchorCenter.y);
208
209
  const areaShift = anchorArea > 0 ? Math.abs(anchorArea - candidateArea) / anchorArea : 0;
209
210
 
211
+ if (centerDelta >= REJECT_CENTER_DELTA || areaShift > 1.2) {
212
+ missingFrameCountRef.current += 1;
213
+
214
+ if (missingFrameCountRef.current <= 2) {
215
+ setQuad(anchor);
216
+ return;
217
+ }
218
+
219
+ smoothingBufferRef.current = [];
220
+ anchorQuadRef.current = null;
221
+ lastQuadRef.current = null;
222
+ setQuad(null);
223
+ return;
224
+ }
225
+
210
226
  if (delta <= SNAP_DISTANCE && centerDelta <= SNAP_CENTER_DISTANCE && areaShift <= 0.08) {
211
227
  candidate = anchor;
212
228
  } else if (delta <= BLEND_DISTANCE && centerDelta <= MAX_CENTER_DELTA && areaShift <= MAX_AREA_SHIFT) {