react-native-rectangle-doc-scanner 1.1.0 → 1.2.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/utils/overlay.js +12 -4
- package/package.json +1 -1
- package/src/utils/overlay.tsx +15 -4
package/dist/utils/overlay.js
CHANGED
|
@@ -66,10 +66,18 @@ const orderQuad = (points) => {
|
|
|
66
66
|
if (points.length !== 4) {
|
|
67
67
|
return points;
|
|
68
68
|
}
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
69
|
+
const sum = (p) => p.x + p.y;
|
|
70
|
+
const diff = (p) => p.x - p.y;
|
|
71
|
+
const topLeft = points.reduce((prev, curr) => (sum(curr) < sum(prev) ? curr : prev));
|
|
72
|
+
const bottomRight = points.reduce((prev, curr) => (sum(curr) > sum(prev) ? curr : prev));
|
|
73
|
+
const remaining = points.filter((p) => p !== topLeft && p !== bottomRight);
|
|
74
|
+
if (remaining.length !== 2) {
|
|
75
|
+
return [topLeft, bottomRight, ...remaining];
|
|
76
|
+
}
|
|
77
|
+
const [candidate1, candidate2] = remaining;
|
|
78
|
+
const topRight = diff(candidate1) > diff(candidate2) ? candidate1 : candidate2;
|
|
79
|
+
const bottomLeft = topRight === candidate1 ? candidate2 : candidate1;
|
|
80
|
+
return [topLeft, topRight, bottomRight, bottomLeft];
|
|
73
81
|
};
|
|
74
82
|
const Overlay = ({ quad, color = '#e7a649', frameSize, showGrid = true, gridColor = 'rgba(231, 166, 73, 0.35)', gridLineWidth = 2, }) => {
|
|
75
83
|
const { width: screenWidth, height: screenHeight } = (0, react_native_1.useWindowDimensions)();
|
package/package.json
CHANGED
package/src/utils/overlay.tsx
CHANGED
|
@@ -52,11 +52,22 @@ const orderQuad = (points: Point[]): Point[] => {
|
|
|
52
52
|
return points;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const bottom = sorted.slice(2, 4).sort((a, b) => a.x - b.x);
|
|
55
|
+
const sum = (p: Point) => p.x + p.y;
|
|
56
|
+
const diff = (p: Point) => p.x - p.y;
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
const topLeft = points.reduce((prev, curr) => (sum(curr) < sum(prev) ? curr : prev));
|
|
59
|
+
const bottomRight = points.reduce((prev, curr) => (sum(curr) > sum(prev) ? curr : prev));
|
|
60
|
+
|
|
61
|
+
const remaining = points.filter((p) => p !== topLeft && p !== bottomRight);
|
|
62
|
+
if (remaining.length !== 2) {
|
|
63
|
+
return [topLeft, bottomRight, ...remaining];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const [candidate1, candidate2] = remaining;
|
|
67
|
+
const topRight = diff(candidate1) > diff(candidate2) ? candidate1 : candidate2;
|
|
68
|
+
const bottomLeft = topRight === candidate1 ? candidate2 : candidate1;
|
|
69
|
+
|
|
70
|
+
return [topLeft, topRight, bottomRight, bottomLeft];
|
|
60
71
|
};
|
|
61
72
|
|
|
62
73
|
export const Overlay: React.FC<OverlayProps> = ({
|