aboutsummaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authorPushkar Joshi2012-06-11 14:06:09 -0700
committerPushkar Joshi2012-06-11 14:06:09 -0700
commit76db3eb0aa4ffe9e75812db570c793e9f852f853 (patch)
tree53c351050d19ad9d6f218319ef4d51679379e6b5 /assets
parentce9439ffaa82d5a2dd93dfa39da4f513c31f6824 (diff)
downloadninja-76db3eb0aa4ffe9e75812db570c793e9f852f853.tar.gz
fix the brush tool runtime: update the brush coordinates to account for change in bounding box due to smoothing
Diffstat (limited to 'assets')
-rw-r--r--assets/canvas-runtime.js35
1 files changed, 34 insertions, 1 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js
index fe5f839c..c2ab0bd8 100644
--- a/assets/canvas-runtime.js
+++ b/assets/canvas-runtime.js
@@ -2107,7 +2107,40 @@ NinjaCvsRt.RuntimeBrushStroke = Object.create(NinjaCvsRt.RuntimeGeomObj, {
2107 } 2107 }
2108 this._LocalPoints = newPoints.slice(0); 2108 this._LocalPoints = newPoints.slice(0);
2109 } 2109 }
2110 } 2110
2111 // *** compute the bounding box *********
2112 var BBoxMin = [Infinity, Infinity, Infinity];
2113 var BBoxMax = [-Infinity, -Infinity, -Infinity];
2114 if (numPoints === 0) {
2115 BBoxMin = [0, 0, 0];
2116 BBoxMax = [0, 0, 0];
2117 } else {
2118 for (var i=0;i<numPoints;i++){
2119 var pt = this._LocalPoints[i];
2120 for (var d = 0; d < 3; d++) {
2121 if (BBoxMin[d] > pt[d]) {
2122 BBoxMin[d] = pt[d];
2123 }
2124 if (BBoxMax[d] < pt[d]) {
2125 BBoxMax[d] = pt[d];
2126 }
2127 }//for every dimension d from 0 to 2
2128 }
2129 }
2130
2131 //increase the bbox given the stroke width and the angle (in case of calligraphic brush)
2132 var bboxPadding = this._strokeWidth*0.5;
2133 for (var d = 0; d < 3; d++) {
2134 BBoxMin[d]-= bboxPadding;
2135 BBoxMax[d]+= bboxPadding;
2136 }//for every dimension d from 0 to 2
2137
2138 //******* update the local coords so that the bbox min is at the origin ******
2139 for (var i=0;i<numPoints;i++) {
2140 this._LocalPoints[i][0]-= BBoxMin[0];
2141 this._LocalPoints[i][1]-= BBoxMin[1];
2142 }
2143 }//if we need to do smoothing
2111 } 2144 }
2112 }, 2145 },
2113 2146