Skip to content

Commit

Permalink
Add vertical centering also
Browse files Browse the repository at this point in the history
  • Loading branch information
jefff committed Apr 23, 2020
1 parent 738d4b9 commit a52cda5
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 62 deletions.
14 changes: 12 additions & 2 deletions src/locator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions tests/end-to-end/148/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
22 changes: 11 additions & 11 deletions tests/end-to-end/61/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
110 changes: 109 additions & 1 deletion tests/end-to-end/82/output.json
Original file line number Diff line number Diff line change
@@ -1 +1,109 @@
null
{
"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
}
}
}
56 changes: 55 additions & 1 deletion tests/end-to-end/92/output.json
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@
null
{
"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
}
}
}
22 changes: 11 additions & 11 deletions tests/end-to-end/94/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions tests/end-to-end/96/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,32 +168,32 @@
],
"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,
"y": 66.5
},
"topLeftFinderPattern": {
"x": 72,
"y": 55.5
"y": 55
},
"bottomLeftFinderPattern": {
"x": 64.5,
"y": 188
"y": 187.5
},
"bottomRightAlignmentPattern": {
"x": 151.5,
Expand Down
Loading

0 comments on commit a52cda5

Please sign in to comment.