react-native-rectangle-doc-scanner 1.2.0 → 1.3.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 +20 -11
- package/package.json +1 -1
- package/src/utils/overlay.tsx +24 -13
package/dist/utils/overlay.js
CHANGED
|
@@ -66,18 +66,27 @@ const orderQuad = (points) => {
|
|
|
66
66
|
if (points.length !== 4) {
|
|
67
67
|
return points;
|
|
68
68
|
}
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
const center = points.reduce((acc, point) => ({ x: acc.x + point.x / 4, y: acc.y + point.y / 4 }), { x: 0, y: 0 });
|
|
70
|
+
const sorted = [...points].sort((a, b) => {
|
|
71
|
+
const angleA = Math.atan2(a.y - center.y, a.x - center.x);
|
|
72
|
+
const angleB = Math.atan2(b.y - center.y, b.x - center.x);
|
|
73
|
+
return angleA - angleB;
|
|
74
|
+
});
|
|
75
|
+
// Ensure the first point is the top-left (smallest y, then smallest x)
|
|
76
|
+
let startIndex = 0;
|
|
77
|
+
for (let i = 1; i < sorted.length; i += 1) {
|
|
78
|
+
const current = sorted[i];
|
|
79
|
+
const candidate = sorted[startIndex];
|
|
80
|
+
if (current.y < candidate.y || (current.y === candidate.y && current.x < candidate.x)) {
|
|
81
|
+
startIndex = i;
|
|
82
|
+
}
|
|
76
83
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
return [
|
|
85
|
+
sorted[startIndex % 4],
|
|
86
|
+
sorted[(startIndex + 1) % 4],
|
|
87
|
+
sorted[(startIndex + 2) % 4],
|
|
88
|
+
sorted[(startIndex + 3) % 4],
|
|
89
|
+
];
|
|
81
90
|
};
|
|
82
91
|
const Overlay = ({ quad, color = '#e7a649', frameSize, showGrid = true, gridColor = 'rgba(231, 166, 73, 0.35)', gridLineWidth = 2, }) => {
|
|
83
92
|
const { width: screenWidth, height: screenHeight } = (0, react_native_1.useWindowDimensions)();
|
package/package.json
CHANGED
package/src/utils/overlay.tsx
CHANGED
|
@@ -52,22 +52,33 @@ const orderQuad = (points: Point[]): Point[] => {
|
|
|
52
52
|
return points;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const bottomRight = points.reduce((prev, curr) => (sum(curr) > sum(prev) ? curr : prev));
|
|
55
|
+
const center = points.reduce(
|
|
56
|
+
(acc, point) => ({ x: acc.x + point.x / 4, y: acc.y + point.y / 4 }),
|
|
57
|
+
{ x: 0, y: 0 },
|
|
58
|
+
);
|
|
60
59
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
const sorted = [...points].sort((a, b) => {
|
|
61
|
+
const angleA = Math.atan2(a.y - center.y, a.x - center.x);
|
|
62
|
+
const angleB = Math.atan2(b.y - center.y, b.x - center.x);
|
|
63
|
+
return angleA - angleB;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Ensure the first point is the top-left (smallest y, then smallest x)
|
|
67
|
+
let startIndex = 0;
|
|
68
|
+
for (let i = 1; i < sorted.length; i += 1) {
|
|
69
|
+
const current = sorted[i];
|
|
70
|
+
const candidate = sorted[startIndex];
|
|
71
|
+
if (current.y < candidate.y || (current.y === candidate.y && current.x < candidate.x)) {
|
|
72
|
+
startIndex = i;
|
|
73
|
+
}
|
|
64
74
|
}
|
|
65
75
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
return [
|
|
77
|
+
sorted[startIndex % 4],
|
|
78
|
+
sorted[(startIndex + 1) % 4],
|
|
79
|
+
sorted[(startIndex + 2) % 4],
|
|
80
|
+
sorted[(startIndex + 3) % 4],
|
|
81
|
+
];
|
|
71
82
|
};
|
|
72
83
|
|
|
73
84
|
export const Overlay: React.FC<OverlayProps> = ({
|