react-native-rectangle-doc-scanner 0.13.0 → 0.14.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/dist/DocScanner.js +23 -8
- package/package.json +1 -1
- package/src/DocScanner.tsx +27 -9
package/dist/DocScanner.js
CHANGED
|
@@ -184,14 +184,17 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
|
|
|
184
184
|
const rectY = rectValue.y ?? rectValue?.topLeft?.y ?? 0;
|
|
185
185
|
const rectW = rectValue.width ?? rectValue?.size?.width ?? 0;
|
|
186
186
|
const rectH = rectValue.height ?? rectValue?.size?.height ?? 0;
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
187
|
+
// Validate that we have a valid rectangle
|
|
188
|
+
if (rectW > 0 && rectH > 0) {
|
|
189
|
+
approxArray = [
|
|
190
|
+
{ x: rectX, y: rectY },
|
|
191
|
+
{ x: rectX + rectW, y: rectY },
|
|
192
|
+
{ x: rectX + rectW, y: rectY + rectH },
|
|
193
|
+
{ x: rectX, y: rectY + rectH },
|
|
194
|
+
];
|
|
195
|
+
if (__DEV__) {
|
|
196
|
+
console.log('[DocScanner] boundingRect fallback', approxArray);
|
|
197
|
+
}
|
|
195
198
|
}
|
|
196
199
|
}
|
|
197
200
|
catch (err) {
|
|
@@ -205,6 +208,18 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
|
|
|
205
208
|
}
|
|
206
209
|
step = `contour_${i}_convex`;
|
|
207
210
|
reportStage(step);
|
|
211
|
+
// Validate points before processing
|
|
212
|
+
const isValidPoint = (pt) => {
|
|
213
|
+
return typeof pt.x === 'number' && typeof pt.y === 'number' &&
|
|
214
|
+
!isNaN(pt.x) && !isNaN(pt.y) &&
|
|
215
|
+
isFinite(pt.x) && isFinite(pt.y);
|
|
216
|
+
};
|
|
217
|
+
if (!approxArray.every(isValidPoint)) {
|
|
218
|
+
if (__DEV__) {
|
|
219
|
+
console.warn('[DocScanner] invalid points in approxArray', approxArray);
|
|
220
|
+
}
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
208
223
|
const points = approxArray.map((pt) => ({
|
|
209
224
|
x: pt.x / ratio,
|
|
210
225
|
y: pt.y / ratio,
|
package/package.json
CHANGED
package/src/DocScanner.tsx
CHANGED
|
@@ -215,15 +215,18 @@ export const DocScanner: React.FC<Props> = ({
|
|
|
215
215
|
const rectW = rectValue.width ?? rectValue?.size?.width ?? 0;
|
|
216
216
|
const rectH = rectValue.height ?? rectValue?.size?.height ?? 0;
|
|
217
217
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
218
|
+
// Validate that we have a valid rectangle
|
|
219
|
+
if (rectW > 0 && rectH > 0) {
|
|
220
|
+
approxArray = [
|
|
221
|
+
{ x: rectX, y: rectY },
|
|
222
|
+
{ x: rectX + rectW, y: rectY },
|
|
223
|
+
{ x: rectX + rectW, y: rectY + rectH },
|
|
224
|
+
{ x: rectX, y: rectY + rectH },
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
if (__DEV__) {
|
|
228
|
+
console.log('[DocScanner] boundingRect fallback', approxArray);
|
|
229
|
+
}
|
|
227
230
|
}
|
|
228
231
|
} catch (err) {
|
|
229
232
|
if (__DEV__) {
|
|
@@ -238,6 +241,21 @@ export const DocScanner: React.FC<Props> = ({
|
|
|
238
241
|
|
|
239
242
|
step = `contour_${i}_convex`;
|
|
240
243
|
reportStage(step);
|
|
244
|
+
|
|
245
|
+
// Validate points before processing
|
|
246
|
+
const isValidPoint = (pt: { x: number; y: number }) => {
|
|
247
|
+
return typeof pt.x === 'number' && typeof pt.y === 'number' &&
|
|
248
|
+
!isNaN(pt.x) && !isNaN(pt.y) &&
|
|
249
|
+
isFinite(pt.x) && isFinite(pt.y);
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
if (!approxArray.every(isValidPoint)) {
|
|
253
|
+
if (__DEV__) {
|
|
254
|
+
console.warn('[DocScanner] invalid points in approxArray', approxArray);
|
|
255
|
+
}
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
|
|
241
259
|
const points: Point[] = approxArray.map((pt: { x: number; y: number }) => ({
|
|
242
260
|
x: pt.x / ratio,
|
|
243
261
|
y: pt.y / ratio,
|