From c2ef3fce55382ea0336378eb30bd011a117eb888 Mon Sep 17 00:00:00 2001 From: Anders Gustafsson Date: Wed, 3 Jan 2018 15:17:14 +0100 Subject: [PATCH] P5-2008 fix inches on gores --- dist/image-editor.js | 8 +++++++- src/GoreHandler.js | 1 + src/utils/calc-crop.js | 7 ++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dist/image-editor.js b/dist/image-editor.js index cfd5372..033df6d 100644 --- a/dist/image-editor.js +++ b/dist/image-editor.js @@ -1136,6 +1136,7 @@ function GoreHandler(viewport) { * Then round up to get correct number of gores. */ var count = Math.ceil((bounds.width / step).toFixed(5)); + for (var i = 1; i < count; i++) { _lines.push(getLine(bounds.left + step * i)); } @@ -2237,6 +2238,7 @@ module.exports = assertKeyValuePair; function calcCrop(obj, width, height, units) { var cropRatio = width / height; var objRatio = obj.width / obj.height; + var inchToCm = units === "inch" ? 2.54 : 1; var returnValue = { image: obj, @@ -2259,7 +2261,11 @@ function calcCrop(obj, width, height, units) { } // Pixels per millimeter - returnValue.ppmm = returnValue.width / ((returnValue.dim.width * obj.scaleX) * 10); + var ppmm = returnValue.width / ((returnValue.dim.width * inchToCm * obj.scaleX) * 10); + + //Round to four decimal places to avoid precision issues. At least 4 decimals is needed though + //for correct calculation of number of gores on wide wallpaperes in editor. + returnValue.ppmm = Math.round(ppmm * 1e4) / 1e4; return returnValue; } diff --git a/src/GoreHandler.js b/src/GoreHandler.js index b1163bc..03b2f7b 100644 --- a/src/GoreHandler.js +++ b/src/GoreHandler.js @@ -54,6 +54,7 @@ function GoreHandler(viewport) { * Then round up to get correct number of gores. */ var count = Math.ceil((bounds.width / step).toFixed(5)); + for (var i = 1; i < count; i++) { _lines.push(getLine(bounds.left + step * i)); } diff --git a/src/utils/calc-crop.js b/src/utils/calc-crop.js index 5facce8..0eec85b 100644 --- a/src/utils/calc-crop.js +++ b/src/utils/calc-crop.js @@ -15,6 +15,7 @@ function calcCrop(obj, width, height, units) { var cropRatio = width / height; var objRatio = obj.width / obj.height; + var inchToCm = units === "inch" ? 2.54 : 1; var returnValue = { image: obj, @@ -37,7 +38,11 @@ function calcCrop(obj, width, height, units) { } // Pixels per millimeter - returnValue.ppmm = returnValue.width / ((returnValue.dim.width * obj.scaleX) * 10); + var ppmm = returnValue.width / ((returnValue.dim.width * inchToCm * obj.scaleX) * 10); + + //Round to four decimal places to avoid precision issues. At least 4 decimals is needed though + //for correct calculation of number of gores on wide wallpaperes in editor. + returnValue.ppmm = Math.round(ppmm * 1e4) / 1e4; return returnValue; }