diff --git a/lib/estimators/TSR.js b/lib/estimators/TSR.js index 88a0f39..465323f 100644 --- a/lib/estimators/TSR.js +++ b/lib/estimators/TSR.js @@ -57,7 +57,7 @@ module.exports = function (domain, range) { // Denominator i.e. determinant // It is zero iff domain[i] = domain[j] for every i and j in [0, n). // In other words, iff all the domain points are the same or there is only one domain point. - const det = N * a2 + N * b2 - a1 * a1 - b1 * b1 + const det = N * a2 - a1 * a1 + N * b2 - b1 * b1 if (Math.abs(det) < TOLERANCE) { // The domain points are the same. diff --git a/test/estimators/TSR.test.js b/test/estimators/TSR.test.js index 7e66f4a..7fd0335 100644 --- a/test/estimators/TSR.test.js +++ b/test/estimators/TSR.test.js @@ -96,4 +96,17 @@ module.exports = (ts) => { t.end() }) + + ts.test(title + 'avoids precision errors', (t) => { + const dom = [{ x: 314.24933946532116, y: 807.8879779776474 }] + const ran = [{ x: 314.24933946532116, y: 824.4274168968749 }] + + t.transformsEqual( + estimateTSR(dom, ran), + { a: 1, b: 0, x: ran[0].x - dom[0].x, y: ran[0].y - dom[0].y }, + 'simple translation, no scaling or rotation' + ) + + t.end() + }) }