From 68f76395e98b78eff5ba69755c868055199abbd1 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Wed, 30 Jan 2013 14:37:47 -0700 Subject: [PATCH] Image corrections; thanks to Marco Morazan for helping track these down --- image/private/kernel.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/image/private/kernel.js b/image/private/kernel.js index 8fe4d12..dc8e916 100644 --- a/image/private/kernel.js +++ b/image/private/kernel.js @@ -221,7 +221,7 @@ var isScene = function(x) { ////////////////////////////////////////////////////////////////////// // SceneImage: primitive-number primitive-number (listof image) -> Scene var SceneImage = function(width, height, children, withBorder) { - BaseImage.call(this, 0, 0); + BaseImage.call(this, Math.floor(width/2), Math.floor(height/2)); this.width = width; this.height = height; this.children = children; // arrayof [image, number, number] @@ -544,39 +544,40 @@ OverlayImage.prototype.equals = function(other, aUnionFind) { // based on http://stackoverflow.com/questions/3276467/adjusting-div-width-and-height-after-rotated var RotateImage = function(angle, img) { var sin = Math.sin(angle * Math.PI / 180), - cos = Math.cos(angle * Math.PI / 180); - + cos = Math.cos(angle * Math.PI / 180); + var width = img.getWidth(); + var height = img.getHeight(); + // (w,0) rotation - var x1 = Math.floor(cos * img.getWidth()), - y1 = Math.floor(sin * img.getWidth()); + var x1 = (cos * width), + y1 = (sin * width); // (0,h) rotation - var x2 = Math.floor(-sin * img.getHeight()), - y2 = Math.floor( cos * img.getHeight()); + var x2 = (-sin * height), + y2 = ( cos * height); // (w,h) rotation - var x3 = Math.floor(cos * img.getWidth() - sin * img.getHeight()), - y3 = Math.floor(sin * img.getWidth() + cos * img.getHeight()); + var x3 = (cos * width - sin * height), + y3 = (sin * width + cos * height); var minX = Math.min(0, x1, x2, x3), - maxX = Math.max(0, x1, x2, x3), - minY = Math.min(0, y1, y2, y3), - maxY = Math.max(0, y1, y2, y3); + maxX = Math.max(0, x1, x2, x3), + minY = Math.min(0, y1, y2, y3), + maxY = Math.max(0, y1, y2, y3); var rotatedWidth = maxX - minX, - rotatedHeight = maxY - minY; + rotatedHeight = maxY - minY; // resize the image BaseImage.call(this, Math.floor(rotatedWidth / 2), Math.floor(rotatedHeight / 2)); - this.img = img; - this.width = rotatedWidth; - this.height = rotatedHeight; + this.width = Math.floor(rotatedWidth); + this.height = Math.floor(rotatedHeight); this.angle = angle; - this.translateX = -minX; - this.translateY = -minY; + this.translateX = Math.floor(-minX); + this.translateY = Math.floor(-minY); }; RotateImage.prototype = heir(BaseImage.prototype); @@ -1669,4 +1670,4 @@ EXPORTS.isColor = isColor; EXPORTS.colorRed = colorRed; EXPORTS.colorGreen = colorGreen; EXPORTS.colorBlue = colorBlue; -EXPORTS.colorAlpha = colorAlpha; \ No newline at end of file +EXPORTS.colorAlpha = colorAlpha;