aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/sub-path.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/sub-path.js')
-rwxr-xr-xjs/lib/geom/sub-path.js34
1 files changed, 20 insertions, 14 deletions
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js
index f765b715..ba277197 100755
--- a/js/lib/geom/sub-path.js
+++ b/js/lib/geom/sub-path.js
@@ -54,7 +54,7 @@ var GLSubpath = function GLSubpath() {
54 //drawing context 54 //drawing context
55 this._world = null; 55 this._world = null;
56 this._canvas = null; //todo this might be unnecessary (but faster) since we can get it from the world 56 this._canvas = null; //todo this might be unnecessary (but faster) since we can get it from the world
57 57
58 //tool that owns this subpath 58 //tool that owns this subpath
59 this._drawingTool = null; 59 this._drawingTool = null;
60 60
@@ -207,24 +207,25 @@ GLSubpath.prototype.geomType = function () {
207GLSubpath.prototype.setWidth = function (newW) { 207GLSubpath.prototype.setWidth = function (newW) {
208 var strokeWidth = this._strokeWidth; 208 var strokeWidth = this._strokeWidth;
209 var halfStrokeWidth = strokeWidth*0.5; 209 var halfStrokeWidth = strokeWidth*0.5;
210 if (newW<1) { 210 var minWidth = 1+strokeWidth;
211 newW=1; //clamp minimum width to 1 211 if (newW<minWidth) {
212 newW=minWidth;
212 } 213 }
213 214
214 //scale the contents of this subpath to lie within this width 215 //scale the contents of this subpath to lie within this width
215 //determine the scale factor by comparing with the old width 216 //determine the scale factor by comparing with the old width
216 var oldWidth = this._BBoxMax[0]-this._BBoxMin[0]; 217 var oldCanvasWidth = this._BBoxMax[0]-this._BBoxMin[0];
217 if (oldWidth<1) { 218 if (oldCanvasWidth<minWidth) {
218 oldWidth=1; 219 oldCanvasWidth=minWidth;
219 } 220 }
220 221
221 var scaleX = newW/oldWidth; 222 var scaleX = (newW-strokeWidth)/(oldCanvasWidth-strokeWidth);
222 if (scaleX===1) { 223 if (scaleX===1) {
223 return; //no need to do anything 224 return; //no need to do anything
224 } 225 }
225 226
226 //scale the anchor point positions such that the width of the bbox is the newW 227 //scale the anchor point positions such that the width of the bbox is the newW
227 var origX = this._BBoxMin[0]; //this should always be zero since we only deal with local coordinates 228 var origX = halfStrokeWidth;//this is the left edge //this._BBoxMin[0]; //this should always be zero since we only deal with local coordinates
228 var numAnchors = this._Anchors.length; 229 var numAnchors = this._Anchors.length;
229 for (var i=0;i<numAnchors;i++){ 230 for (var i=0;i<numAnchors;i++){
230 //compute the distance from the bboxMin 231 //compute the distance from the bboxMin
@@ -241,23 +242,27 @@ GLSubpath.prototype.setWidth = function (newW) {
241}; 242};
242 243
243GLSubpath.prototype.setHeight = function (newH) { 244GLSubpath.prototype.setHeight = function (newH) {
244 if (newH<1) { 245 var strokeWidth = this._strokeWidth;
245 newH=1; //clamp minimum width to 1 246 var halfStrokeWidth = strokeWidth*0.5;
247 var minHeight = 1+strokeWidth;
248
249 if (newH<minHeight) {
250 newH=minHeight; //clamp minimum width to 1
246 } 251 }
247 //scale the contents of this subpath to lie within this height 252 //scale the contents of this subpath to lie within this height
248 //determine the scale factor by comparing with the old height 253 //determine the scale factor by comparing with the old height
249 var oldHeight = this._BBoxMax[1]-this._BBoxMin[1]; 254 var oldHeight = this._BBoxMax[1]-this._BBoxMin[1];
250 if (oldHeight<1){ 255 if (oldHeight<minHeight){
251 oldHeight=1; 256 oldHeight=minHeight;
252 } 257 }
253 258
254 var scaleY = newH/oldHeight; 259 var scaleY = (newH-strokeWidth)/(oldHeight-strokeWidth);
255 if (scaleY===1){ 260 if (scaleY===1){
256 return; //no need to do anything 261 return; //no need to do anything
257 } 262 }
258 263
259 //scale the anchor point positions such that the height of the bbox is the newH 264 //scale the anchor point positions such that the height of the bbox is the newH
260 var origY = this._BBoxMin[1]; 265 var origY = halfStrokeWidth;// this._BBoxMin[1];//this is the top edge
261 var numAnchors = this._Anchors.length; 266 var numAnchors = this._Anchors.length;
262 for (var i=0;i<numAnchors;i++){ 267 for (var i=0;i<numAnchors;i++){
263 //compute the distance from the bboxMin 268 //compute the distance from the bboxMin
@@ -270,6 +275,7 @@ GLSubpath.prototype.setHeight = function (newH) {
270 this._Anchors[i].setNextPos(this._Anchors[i].getNextX(), origY + nextW*scaleY,this._Anchors[i].getNextZ()); 275 this._Anchors[i].setNextPos(this._Anchors[i].getNextX(), origY + nextW*scaleY,this._Anchors[i].getNextZ());
271 } 276 }
272 this.makeDirty(); 277 this.makeDirty();
278 this.computeBoundingBox(true, false);
273}; 279};
274 280
275GLSubpath.prototype.setWorld = function (world) { 281GLSubpath.prototype.setWorld = function (world) {