@nuintun/qrcode
Advanced tools
Comparing version 0.10.1 to 0.10.2
@@ -11,3 +11,5 @@ "use strict"; | ||
var MAX_FINDERPATTERNS_TO_SEARCH = 4; | ||
var distance = function (a, b) { return Math.sqrt(Math.pow((b.x - a.x), 2) + Math.pow((b.y - a.y), 2)); }; | ||
function distance(a, b) { | ||
return Math.sqrt(Math.pow((b.x - a.x), 2) + Math.pow((b.y - a.y), 2)); | ||
} | ||
function sum(values) { | ||
@@ -346,4 +348,2 @@ return values.reduce(function (a, b) { return a + b; }); | ||
} | ||
// const lengths = [q.top.endX - q.top.startX, q.bottom.endX - q.bottom.startX, q.bottom.y - q.top.y + 1]; | ||
// const size = sum(lengths) / lengths.length; | ||
var sizeScore = scorePattern({ x: Math.floor(x), y: Math.floor(y) }, [1, 1, 1], matrix); | ||
@@ -350,0 +350,0 @@ var score = sizeScore + distance({ x: x, y: y }, expectedAlignmentPattern); |
@@ -26,8 +26,8 @@ "use strict"; | ||
} | ||
function prepareData(version, errorCorrectionLevel, dataList) { | ||
var dLength = dataList.length; | ||
function prepareData(version, errorCorrectionLevel, chunks) { | ||
var dLength = chunks.length; | ||
var buffer = new BitBuffer_1.default(); | ||
var rsBlocks = RSBlock_1.default.getRSBlocks(version, errorCorrectionLevel); | ||
for (var i = 0; i < dLength; i++) { | ||
var data = dataList[i]; | ||
var data = chunks[i]; | ||
buffer.put(data.getMode(), 4); | ||
@@ -123,4 +123,4 @@ buffer.put(data.getLength(), data.getLengthInBits(version)); | ||
this.version = 0; | ||
this.chunks = []; | ||
this.moduleCount = 0; | ||
this.dataList = []; | ||
this.modules = []; | ||
@@ -191,3 +191,3 @@ this.autoVersion = this.version === 0; | ||
if (data instanceof QRData_1.default) { | ||
this.dataList.push(data); | ||
this.chunks.push(data); | ||
} | ||
@@ -197,3 +197,3 @@ else { | ||
if (type === '[object String]') { | ||
this.dataList.push(new QRByte_1.default(data)); | ||
this.chunks.push(new QRByte_1.default(data)); | ||
} | ||
@@ -210,4 +210,4 @@ else { | ||
QRCode.prototype.reset = function () { | ||
this.chunks = []; | ||
this.modules = []; | ||
this.dataList = []; | ||
this.moduleCount = 0; | ||
@@ -407,7 +407,7 @@ if (this.autoVersion) { | ||
var maxDataCount; | ||
var dataList = this.dataList; | ||
var chunks = this.chunks; | ||
var errorCorrectionLevel = this.errorCorrectionLevel; | ||
if (this.autoVersion) { | ||
for (this.version = 1; this.version <= 40; this.version++) { | ||
_a = prepareData(this.version, errorCorrectionLevel, dataList), buffer = _a[0], rsBlocks = _a[1], maxDataCount = _a[2]; | ||
_a = prepareData(this.version, errorCorrectionLevel, chunks), buffer = _a[0], rsBlocks = _a[1], maxDataCount = _a[2]; | ||
if (buffer.getLengthInBits() <= maxDataCount) | ||
@@ -418,3 +418,3 @@ break; | ||
else { | ||
_b = prepareData(this.version, errorCorrectionLevel, dataList), buffer = _b[0], rsBlocks = _b[1], maxDataCount = _b[2]; | ||
_b = prepareData(this.version, errorCorrectionLevel, chunks), buffer = _b[0], rsBlocks = _b[1], maxDataCount = _b[2]; | ||
} | ||
@@ -421,0 +421,0 @@ // calc module count |
@@ -9,3 +9,5 @@ /** | ||
var MAX_FINDERPATTERNS_TO_SEARCH = 4; | ||
var distance = function (a, b) { return Math.sqrt(Math.pow((b.x - a.x), 2) + Math.pow((b.y - a.y), 2)); }; | ||
function distance(a, b) { | ||
return Math.sqrt(Math.pow((b.x - a.x), 2) + Math.pow((b.y - a.y), 2)); | ||
} | ||
function sum(values) { | ||
@@ -344,4 +346,2 @@ return values.reduce(function (a, b) { return a + b; }); | ||
} | ||
// const lengths = [q.top.endX - q.top.startX, q.bottom.endX - q.bottom.startX, q.bottom.y - q.top.y + 1]; | ||
// const size = sum(lengths) / lengths.length; | ||
var sizeScore = scorePattern({ x: Math.floor(x), y: Math.floor(y) }, [1, 1, 1], matrix); | ||
@@ -348,0 +348,0 @@ var score = sizeScore + distance({ x: x, y: y }, expectedAlignmentPattern); |
@@ -24,8 +24,8 @@ /** | ||
} | ||
function prepareData(version, errorCorrectionLevel, dataList) { | ||
var dLength = dataList.length; | ||
function prepareData(version, errorCorrectionLevel, chunks) { | ||
var dLength = chunks.length; | ||
var buffer = new BitBuffer(); | ||
var rsBlocks = RSBlock.getRSBlocks(version, errorCorrectionLevel); | ||
for (var i = 0; i < dLength; i++) { | ||
var data = dataList[i]; | ||
var data = chunks[i]; | ||
buffer.put(data.getMode(), 4); | ||
@@ -121,4 +121,4 @@ buffer.put(data.getLength(), data.getLengthInBits(version)); | ||
this.version = 0; | ||
this.chunks = []; | ||
this.moduleCount = 0; | ||
this.dataList = []; | ||
this.modules = []; | ||
@@ -189,3 +189,3 @@ this.autoVersion = this.version === 0; | ||
if (data instanceof QRData) { | ||
this.dataList.push(data); | ||
this.chunks.push(data); | ||
} | ||
@@ -195,3 +195,3 @@ else { | ||
if (type === '[object String]') { | ||
this.dataList.push(new QRByte(data)); | ||
this.chunks.push(new QRByte(data)); | ||
} | ||
@@ -208,4 +208,4 @@ else { | ||
QRCode.prototype.reset = function () { | ||
this.chunks = []; | ||
this.modules = []; | ||
this.dataList = []; | ||
this.moduleCount = 0; | ||
@@ -405,7 +405,7 @@ if (this.autoVersion) { | ||
var maxDataCount; | ||
var dataList = this.dataList; | ||
var chunks = this.chunks; | ||
var errorCorrectionLevel = this.errorCorrectionLevel; | ||
if (this.autoVersion) { | ||
for (this.version = 1; this.version <= 40; this.version++) { | ||
_a = prepareData(this.version, errorCorrectionLevel, dataList), buffer = _a[0], rsBlocks = _a[1], maxDataCount = _a[2]; | ||
_a = prepareData(this.version, errorCorrectionLevel, chunks), buffer = _a[0], rsBlocks = _a[1], maxDataCount = _a[2]; | ||
if (buffer.getLengthInBits() <= maxDataCount) | ||
@@ -416,3 +416,3 @@ break; | ||
else { | ||
_b = prepareData(this.version, errorCorrectionLevel, dataList), buffer = _b[0], rsBlocks = _b[1], maxDataCount = _b[2]; | ||
_b = prepareData(this.version, errorCorrectionLevel, chunks), buffer = _b[0], rsBlocks = _b[1], maxDataCount = _b[2]; | ||
} | ||
@@ -419,0 +419,0 @@ // calc module count |
{ | ||
"name": "@nuintun/qrcode", | ||
"version": "0.10.1", | ||
"version": "0.10.2", | ||
"description": "QRCode encode and decode library.", | ||
@@ -5,0 +5,0 @@ "main": "es5/index.js", |
@@ -10,4 +10,4 @@ /** | ||
private version; | ||
private chunks; | ||
private moduleCount; | ||
private dataList; | ||
private modules; | ||
@@ -14,0 +14,0 @@ private autoVersion; |
434868