diff --git a/src/locator/index.ts b/src/locator/index.ts index a33aa691..b22c4442 100644 --- a/src/locator/index.ts +++ b/src/locator/index.ts @@ -217,13 +217,23 @@ function recenterLocation(matrix: BitMatrix, p: Point): Point { while (matrix.get(leftX, Math.round(p.y))) { leftX--; } - let rightX = Math.round(p.x); while (matrix.get(rightX, Math.round(p.y))) { rightX++; } + const x = (leftX + rightX) / 2; + + let topY = Math.round(p.y); + while (matrix.get(Math.round(x), topY)) { + topY--; + } + let bottomY = Math.round(p.y); + while (matrix.get(Math.round(x), bottomY)) { + bottomY++; + } + const y = (topY + bottomY) / 2; - return { x: (leftX + rightX) / 2, y: p.y }; + return { x, y }; } interface Quad { diff --git a/tests/end-to-end/148/output.json b/tests/end-to-end/148/output.json index 6922d0df..4df0ed05 100644 --- a/tests/end-to-end/148/output.json +++ b/tests/end-to-end/148/output.json @@ -21,35 +21,35 @@ "location": { "topRightCorner": { "x": 263.49999999999994, - "y": 292.49999999999994 + "y": 291.375 }, "topLeftCorner": { - "x": 290.6357772807236, - "y": 234.69908351972865 + "x": 290.79762807324306, + "y": 234.26604686604492 }, "bottomRightCorner": { - "x": 207.16596877093724, - "y": 266.00026171089854 + "x": 207.9274477212262, + "y": 264.60245217347966 }, "bottomLeftCorner": { - "x": 233.5, - "y": 208.49999999999994 + "x": 233.49999999999997, + "y": 208.125 }, "topRightFinderPattern": { "x": 258.5, - "y": 278.5 + "y": 277.5 }, "topLeftFinderPattern": { "x": 276.5, - "y": 240 + "y": 239.5 }, "bottomLeftFinderPattern": { "x": 238.5, - "y": 222.5 + "y": 222 }, "bottomRightAlignmentPattern": { - "x": 232.6604148394045, - "y": 256.43984443522334 + "x": 232.84618068755663, + "y": 255.48041599830515 } } } \ No newline at end of file diff --git a/tests/end-to-end/61/output.json b/tests/end-to-end/61/output.json index 71a079da..5808bccc 100644 --- a/tests/end-to-end/61/output.json +++ b/tests/end-to-end/61/output.json @@ -108,32 +108,32 @@ ], "location": { "topRightCorner": { - "x": 207.74905277460078, - "y": 35.92342050272172 + "x": 207.7810586662029, + "y": 35.39166271880641 }, "topLeftCorner": { - "x": 37.28418186638301, - "y": 40.82136923413848 + "x": 37.31970355694221, + "y": 39.672933251301814 }, "bottomRightCorner": { - "x": 199.730516256019, - "y": 207.08099785827298 + "x": 199.80450482609717, + "y": 207.49761061850413 }, "bottomLeftCorner": { - "x": 37.55287125013931, - "y": 204.8002517828075 + "x": 37.57948911702004, + "y": 204.27384025598016 }, "topRightFinderPattern": { "x": 185.5, - "y": 58 + "y": 57.5 }, "topLeftFinderPattern": { "x": 57, - "y": 61 + "y": 60 }, "bottomLeftFinderPattern": { "x": 56.5, - "y": 186 + "y": 185.5 }, "bottomRightAlignmentPattern": { "x": 163.5, diff --git a/tests/end-to-end/82/output.json b/tests/end-to-end/82/output.json index ec747fa4..942fd023 100644 --- a/tests/end-to-end/82/output.json +++ b/tests/end-to-end/82/output.json @@ -1 +1,109 @@ -null \ No newline at end of file +{ + "binaryData": [ + 104, + 116, + 116, + 112, + 58, + 47, + 47, + 99, + 111, + 100, + 101, + 46, + 103, + 111, + 111, + 103, + 108, + 101, + 46, + 99, + 111, + 109, + 47, + 112, + 47, + 122, + 120, + 105, + 110, + 103, + 47 + ], + "data": "http://code.google.com/p/zxing/", + "chunks": [ + { + "type": "byte", + "bytes": [ + 104, + 116, + 116, + 112, + 58, + 47, + 47, + 99, + 111, + 100, + 101, + 46, + 103, + 111, + 111, + 103, + 108, + 101, + 46, + 99, + 111, + 109, + 47, + 112, + 47, + 122, + 120, + 105, + 110, + 103, + 47 + ], + "text": "http://code.google.com/p/zxing/" + } + ], + "location": { + "topRightCorner": { + "x": 161.6951269176281, + "y": 61.745332923199555 + }, + "topLeftCorner": { + "x": 77.03759523249865, + "y": 51.8409703690389 + }, + "bottomRightCorner": { + "x": 147.85112998168927, + "y": 146.5334877662124 + }, + "bottomLeftCorner": { + "x": 67.25061775575521, + "y": 142.30094367891465 + }, + "topRightFinderPattern": { + "x": 148.5, + "y": 73 + }, + "topLeftFinderPattern": { + "x": 88, + "y": 66.5 + }, + "bottomLeftFinderPattern": { + "x": 80.5, + "y": 131 + }, + "bottomRightAlignmentPattern": { + "x": 131, + "y": 124 + } + } +} \ No newline at end of file diff --git a/tests/end-to-end/92/output.json b/tests/end-to-end/92/output.json index ec747fa4..e0930425 100644 --- a/tests/end-to-end/92/output.json +++ b/tests/end-to-end/92/output.json @@ -1 +1,55 @@ -null \ No newline at end of file +{ + "binaryData": [ + 50, + 48, + 50, + 49, + 50, + 48, + 48, + 48, + 48, + 48 + ], + "data": "2021200000", + "chunks": [ + { + "type": "numeric", + "text": "2021200000" + } + ], + "location": { + "topRightCorner": { + "x": 190.37500000000003, + "y": 123.24999999999999 + }, + "topLeftCorner": { + "x": 140.82437472806706, + "y": 120.1954804763799 + }, + "bottomRightCorner": { + "x": 189.37498917656237, + "y": 172.48075757475945 + }, + "bottomLeftCorner": { + "x": 140.125, + "y": 169.74999999999997 + }, + "topRightFinderPattern": { + "x": 182, + "y": 131 + }, + "topLeftFinderPattern": { + "x": 149, + "y": 129 + }, + "bottomLeftFinderPattern": { + "x": 148.5, + "y": 162 + }, + "bottomRightAlignmentPattern": { + "x": 174.47561880331884, + "y": 156.4352817881895 + } + } +} \ No newline at end of file diff --git a/tests/end-to-end/94/output.json b/tests/end-to-end/94/output.json index 345292e1..4190200c 100644 --- a/tests/end-to-end/94/output.json +++ b/tests/end-to-end/94/output.json @@ -168,32 +168,32 @@ ], "location": { "topRightCorner": { - "x": 209.43221529461573, - "y": 29.431156910287495 + "x": 209.51355745730348, + "y": 28.862689046730146 }, "topLeftCorner": { - "x": 29.145842438461127, - "y": 26.288965769230416 + "x": 29.23676041336614, + "y": 25.808825443291582 }, "bottomRightCorner": { - "x": 195.7418483157054, - "y": 169.63160944945972 + "x": 195.8683092978863, + "y": 169.81926539702602 }, "bottomLeftCorner": { - "x": 44.50153747551136, - "y": 168.25769867169186 + "x": 44.55958093441372, + "y": 167.70884194729203 }, "topRightFinderPattern": { "x": 194.5, - "y": 42 + "y": 41.5 }, "topLeftFinderPattern": { "x": 44.5, - "y": 39.5 + "y": 39 }, "bottomLeftFinderPattern": { "x": 55.5, - "y": 159 + "y": 158.5 }, "bottomRightAlignmentPattern": { "x": 175.25, diff --git a/tests/end-to-end/96/output.json b/tests/end-to-end/96/output.json index 0b9f6805..dfae6abe 100644 --- a/tests/end-to-end/96/output.json +++ b/tests/end-to-end/96/output.json @@ -168,20 +168,20 @@ ], "location": { "topRightCorner": { - "x": 172.95121886567557, - "y": 56.88733241612363 + "x": 172.95423865294515, + "y": 56.92325495516057 }, "topLeftCorner": { - "x": 62.51835881359606, - "y": 41.665152482731365 + "x": 62.52318449791687, + "y": 41.112591119588885 }, "bottomRightCorner": { - "x": 163.76170764727038, - "y": 189.3912966928725 + "x": 163.7681469521871, + "y": 189.47785056515463 }, "bottomLeftCorner": { - "x": 53.702422326956096, - "y": 201.05378793308296 + "x": 53.70662900165528, + "y": 200.49500388855432 }, "topRightFinderPattern": { "x": 165, @@ -189,11 +189,11 @@ }, "topLeftFinderPattern": { "x": 72, - "y": 55.5 + "y": 55 }, "bottomLeftFinderPattern": { "x": 64.5, - "y": 188 + "y": 187.5 }, "bottomRightAlignmentPattern": { "x": 151.5, diff --git a/tests/end-to-end/cupcake-2/output.json b/tests/end-to-end/cupcake-2/output.json index 850d3630..cb0c1c4b 100644 --- a/tests/end-to-end/cupcake-2/output.json +++ b/tests/end-to-end/cupcake-2/output.json @@ -50,24 +50,24 @@ ], "location": { "topRightCorner": { - "x": 127.46105750170044, - "y": 34.76208030378532 + "x": 127.46497636162992, + "y": 34.06874732856506 }, "topLeftCorner": { - "x": 41.94779823920208, - "y": 105.74971229104122 + "x": 41.953364086855075, + "y": 105.74936541101754 }, "bottomRightCorner": { - "x": 189.69872798105325, - "y": 96.54143904933944 + "x": 189.71164362381936, + "y": 96.54063410843052 }, "bottomLeftCorner": { - "x": 99.62052210326115, - "y": 177.4448242207865 + "x": 99.62566806959562, + "y": 178.13716773984265 }, "topRightFinderPattern": { "x": 124, - "y": 52.5 + "y": 52 }, "topLeftFinderPattern": { "x": 62, @@ -75,7 +75,7 @@ }, "bottomLeftFinderPattern": { "x": 104, - "y": 155 + "y": 155.5 }, "bottomRightAlignmentPattern": { "x": 150.25, diff --git a/tests/end-to-end/report.json b/tests/end-to-end/report.json index 9e99945a..c8cfddc5 100644 --- a/tests/end-to-end/report.json +++ b/tests/end-to-end/report.json @@ -1,7 +1,7 @@ { "counts": { - "failed": 42, - "successful": 212 + "failed": 40, + "successful": 214 }, "tests": { "0": true, @@ -85,7 +85,7 @@ "79": true, "80": false, "81": false, - "82": false, + "82": true, "83": true, "84": true, "85": false, @@ -95,7 +95,7 @@ "89": true, "90": true, "91": true, - "92": false, + "92": true, "93": true, "94": true, "95": true,