diff options
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-x | js/lib/geom/anchor-point.js | 4 | ||||
-rwxr-xr-x | js/lib/geom/brush-stroke.js | 16 | ||||
-rwxr-xr-x | js/lib/geom/circle.js | 4 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 20 | ||||
-rwxr-xr-x | js/lib/geom/sub-path.js | 853 |
5 files changed, 338 insertions, 559 deletions
diff --git a/js/lib/geom/anchor-point.js b/js/lib/geom/anchor-point.js index 0e9f65ea..d254681c 100755 --- a/js/lib/geom/anchor-point.js +++ b/js/lib/geom/anchor-point.js | |||
@@ -221,6 +221,10 @@ GLAnchorPoint.prototype.getNext = function() { | |||
221 | return [this._nextX, this._nextY, this._nextZ]; | 221 | return [this._nextX, this._nextY, this._nextZ]; |
222 | }; | 222 | }; |
223 | 223 | ||
224 | GLAnchorPoint.prototype.getAllPos = function() { | ||
225 | return [[this._prevX, this._prevY, this._prevZ],[this._x, this._y, this._z],[this._nextX, this._nextY, this._nextZ]]; | ||
226 | }; | ||
227 | |||
224 | //return the square of distance from passed in point to the anchor position | 228 | //return the square of distance from passed in point to the anchor position |
225 | GLAnchorPoint.prototype.getDistanceSq = function (x, y, z) { | 229 | GLAnchorPoint.prototype.getDistanceSq = function (x, y, z) { |
226 | return (this._x - x) * (this._x - x) + (this._y - y) * (this._y - y) + (this._z - z) * (this._z - z); | 230 | return (this._x - x) * (this._x - x) + (this._y - y) * (this._y - y) + (this._z - z) * (this._z - z); |
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js index 743dab85..efd21c4a 100755 --- a/js/lib/geom/brush-stroke.js +++ b/js/lib/geom/brush-stroke.js | |||
@@ -416,7 +416,7 @@ var BrushStroke = function GLBrushStroke() { | |||
416 | this._LocalPoints[i][1]+= halfheight; | 416 | this._LocalPoints[i][1]+= halfheight; |
417 | 417 | ||
418 | //store the original points | 418 | //store the original points |
419 | this._OrigLocalPoints .push([this._LocalPoints[i][0],this._LocalPoints[i][1],this._LocalPoints[i][2]]); | 419 | this._OrigLocalPoints.push([this._LocalPoints[i][0],this._LocalPoints[i][1],this._LocalPoints[i][2]]); |
420 | } | 420 | } |
421 | //update the bbox with the same adjustment as was made for the local points above | 421 | //update the bbox with the same adjustment as was made for the local points above |
422 | this._BBoxMax[0]+= halfwidth;this._BBoxMin[0]+= halfwidth; | 422 | this._BBoxMax[0]+= halfwidth;this._BBoxMin[0]+= halfwidth; |
@@ -544,6 +544,10 @@ var BrushStroke = function GLBrushStroke() { | |||
544 | var bboxWidth = bboxMax[0] - bboxMin[0]; | 544 | var bboxWidth = bboxMax[0] - bboxMin[0]; |
545 | var bboxHeight = bboxMax[1] - bboxMin[1]; | 545 | var bboxHeight = bboxMax[1] - bboxMin[1]; |
546 | 546 | ||
547 | if (!this._canvas){ | ||
548 | //set the canvas by querying the world | ||
549 | this._canvas = this.getWorld().getCanvas(); | ||
550 | } | ||
547 | if (this._canvas) { | 551 | if (this._canvas) { |
548 | var newLeft = Math.round(this._stageWorldCenter[0] - 0.5 * bboxWidth); | 552 | var newLeft = Math.round(this._stageWorldCenter[0] - 0.5 * bboxWidth); |
549 | var newTop = Math.round(this._stageWorldCenter[1] - 0.5 * bboxHeight); | 553 | var newTop = Math.round(this._stageWorldCenter[1] - 0.5 * bboxHeight); |
@@ -553,7 +557,7 @@ var BrushStroke = function GLBrushStroke() { | |||
553 | 557 | ||
554 | CanvasController.setProperty(this._canvas, "width", bboxWidth+"px"); | 558 | CanvasController.setProperty(this._canvas, "width", bboxWidth+"px"); |
555 | CanvasController.setProperty(this._canvas, "height", bboxHeight+"px"); | 559 | CanvasController.setProperty(this._canvas, "height", bboxHeight+"px"); |
556 | this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas); | 560 | //this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas); |
557 | } | 561 | } |
558 | 562 | ||
559 | 563 | ||
@@ -665,8 +669,8 @@ var BrushStroke = function GLBrushStroke() { | |||
665 | this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto> | 669 | this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto> |
666 | 670 | ||
667 | retObject.stageWorldCenter = [this._stageWorldCenter[0],this._stageWorldCenter[1],this._stageWorldCenter[2]]; | 671 | retObject.stageWorldCenter = [this._stageWorldCenter[0],this._stageWorldCenter[1],this._stageWorldCenter[2]]; |
668 | retObject.planeMat = [this._planeMat[0],this._planeMat[1],this._planeMat[2],this._planeMat[3]]; | 672 | retObject.planeMat = this._planeMat; |
669 | retObject.planeMatInv = [this._planeMatInv[0],this._planeMatInv[1],this._planeMatInv[2],this._planeMatInv[3]]; | 673 | retObject.planeMatInv = this._planeMatInv; |
670 | retObject.dragPlane = [this._dragPlane[0],this._dragPlane[1],this._dragPlane[2],this._dragPlane[3]]; | 674 | retObject.dragPlane = [this._dragPlane[0],this._dragPlane[1],this._dragPlane[2],this._dragPlane[3]]; |
671 | 675 | ||
672 | //stroke appearance properties | 676 | //stroke appearance properties |
@@ -694,8 +698,8 @@ var BrushStroke = function GLBrushStroke() { | |||
694 | this._copyCoordinates3D(jo.origLocalPoints, this._OrigLocalPoints); //todo <ditto> | 698 | this._copyCoordinates3D(jo.origLocalPoints, this._OrigLocalPoints); //todo <ditto> |
695 | 699 | ||
696 | this._stageWorldCenter = [jo.stageWorldCenter[0],jo.stageWorldCenter[1],jo.stageWorldCenter[2]]; | 700 | this._stageWorldCenter = [jo.stageWorldCenter[0],jo.stageWorldCenter[1],jo.stageWorldCenter[2]]; |
697 | this._planeMat = [jo.planeMat[0], jo.planeMat[1],jo.planeMat[2],jo.planeMat[3]]; | 701 | this._planeMat = jo.planeMat; |
698 | this._planeMatInv = [jo.planeMatInv[0],jo.planeMatInv[1],jo.planeMatInv[2],jo.planeMatInv[3]]; | 702 | this._planeMatInv = jo.planeMatInv; |
699 | this._dragPlane = [jo.dragPlane[0],jo.dragPlane[1],jo.dragPlane[2],jo.dragPlane[3]]; | 703 | this._dragPlane = [jo.dragPlane[0],jo.dragPlane[1],jo.dragPlane[2],jo.dragPlane[3]]; |
700 | 704 | ||
701 | //stroke appearance properties | 705 | //stroke appearance properties |
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index 1073c2db..218dcfa6 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js | |||
@@ -457,9 +457,9 @@ var Circle = function GLCircle() { | |||
457 | if(this._fillColor.gradientMode) { | 457 | if(this._fillColor.gradientMode) { |
458 | if(this._fillColor.gradientMode === "radial") { | 458 | if(this._fillColor.gradientMode === "radial") { |
459 | gradient = ctx.createRadialGradient(xCtr, yCtr, 0, | 459 | gradient = ctx.createRadialGradient(xCtr, yCtr, 0, |
460 | xCtr, yCtr, Math.max(yScale, xScale)); | 460 | xCtr, yCtr, Math.max(this._width, this._height)/2); |
461 | } else { | 461 | } else { |
462 | gradient = ctx.createLinearGradient(0, this._height/2, this._width, this._height/2); | 462 | gradient = ctx.createLinearGradient(lineWidth/2, this._height/2, this._width-lineWidth, this._height/2); |
463 | } | 463 | } |
464 | colors = this._fillColor.color; | 464 | colors = this._fillColor.color; |
465 | 465 | ||
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 91b1d426..fcd1c1bd 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -356,7 +356,9 @@ var Rectangle = function GLRectangle() { | |||
356 | // various declarations | 356 | // various declarations |
357 | var pt, rad, ctr, startPt, bPts; | 357 | var pt, rad, ctr, startPt, bPts; |
358 | var width = Math.round(this.getWidth()), | 358 | var width = Math.round(this.getWidth()), |
359 | height = Math.round(this.getHeight()); | 359 | height = Math.round(this.getHeight()), |
360 | hw = 0.5*width, | ||
361 | hh = 0.5*height; | ||
360 | 362 | ||
361 | pt = [inset, inset]; // top left corner | 363 | pt = [inset, inset]; // top left corner |
362 | 364 | ||
@@ -364,6 +366,12 @@ var Rectangle = function GLRectangle() { | |||
364 | var trRad = this._trRadius; | 366 | var trRad = this._trRadius; |
365 | var blRad = this._blRadius; | 367 | var blRad = this._blRadius; |
366 | var brRad = this._brRadius; | 368 | var brRad = this._brRadius; |
369 | // limit the radii to half the rectangle dimension | ||
370 | var minDimen = hw < hh ? hw : hh; | ||
371 | if (tlRad > minDimen) tlRad = minDimen; | ||
372 | if (blRad > minDimen) blRad = minDimen; | ||
373 | if (brRad > minDimen) brRad = minDimen; | ||
374 | if (trRad > minDimen) trRad = minDimen; | ||
367 | 375 | ||
368 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) { | 376 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) { |
369 | ctx.rect(pt[0], pt[1], width - 2*inset, height - 2*inset); | 377 | ctx.rect(pt[0], pt[1], width - 2*inset, height - 2*inset); |
@@ -452,13 +460,13 @@ var Rectangle = function GLRectangle() { | |||
452 | // render the fill | 460 | // render the fill |
453 | ctx.beginPath(); | 461 | ctx.beginPath(); |
454 | if (this._fillColor) { | 462 | if (this._fillColor) { |
455 | inset = Math.ceil( lw ) + 0.5; | 463 | inset = Math.ceil( lw ) - 0.5; |
456 | 464 | ||
457 | if(this._fillColor.gradientMode) { | 465 | if(this._fillColor.gradientMode) { |
458 | if(this._fillColor.gradientMode === "radial") { | 466 | if(this._fillColor.gradientMode === "radial") { |
459 | gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(w/2, h/2)-inset); | 467 | gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(w, h)/2); |
460 | } else { | 468 | } else { |
461 | gradient = ctx.createLinearGradient(inset, h/2, w-2*inset, h/2); | 469 | gradient = ctx.createLinearGradient(inset/2, h/2, w-inset, h/2); |
462 | } | 470 | } |
463 | colors = this._fillColor.color; | 471 | colors = this._fillColor.color; |
464 | 472 | ||
@@ -486,11 +494,11 @@ var Rectangle = function GLRectangle() { | |||
486 | // render the stroke | 494 | // render the stroke |
487 | ctx.beginPath(); | 495 | ctx.beginPath(); |
488 | if (this._strokeColor) { | 496 | if (this._strokeColor) { |
489 | inset = Math.ceil( 0.5*lw ) + 0.5; | 497 | inset = Math.ceil( 0.5*lw ) - 0.5; |
490 | 498 | ||
491 | if(this._strokeColor.gradientMode) { | 499 | if(this._strokeColor.gradientMode) { |
492 | if(this._strokeColor.gradientMode === "radial") { | 500 | if(this._strokeColor.gradientMode === "radial") { |
493 | gradient = ctx.createRadialGradient(w/2, h/2, Math.min(h/2, w/2)-inset, w/2, h/2, Math.max(h/2, w/2)); | 501 | gradient = ctx.createRadialGradient(w/2, h/2, Math.min(h, w)/2-inset, w/2, h/2, Math.max(h, w)/2); |
494 | } else { | 502 | } else { |
495 | gradient = ctx.createLinearGradient(0, h/2, w, h/2); | 503 | gradient = ctx.createLinearGradient(0, h/2, w, h/2); |
496 | } | 504 | } |
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js index 7046673e..56c94df3 100755 --- a/js/lib/geom/sub-path.js +++ b/js/lib/geom/sub-path.js | |||
@@ -11,29 +11,6 @@ var GeomObj = require("js/lib/geom/geom-obj").GeomObj; | |||
11 | var AnchorPoint = require("js/lib/geom/anchor-point").AnchorPoint; | 11 | var AnchorPoint = require("js/lib/geom/anchor-point").AnchorPoint; |
12 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | 12 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; |
13 | 13 | ||
14 | // TODO Those function do not seems to be used. We should remove them | ||
15 | function SubpathOffsetPoint(pos, mapPos) { | ||
16 | this.Pos = [pos[0],pos[1],pos[2]]; | ||
17 | this.CurveMapPos = [mapPos[0], mapPos[1], mapPos[2]]; | ||
18 | } | ||
19 | |||
20 | function SubpathOffsetTriangle(v0, v1, v2) { | ||
21 | this.v0 = v0; | ||
22 | this.v1 = v1; | ||
23 | this.v2 = v2; | ||
24 | this.n = [0,0,1]; //replace with the actual cross product later | ||
25 | } | ||
26 | |||
27 | function sortNumberAscending(a,b){ | ||
28 | return a-b; | ||
29 | } | ||
30 | function sortNumberDescending(a,b){ | ||
31 | return b-a; | ||
32 | } | ||
33 | function SegmentIntersections(){ | ||
34 | this.paramArray = []; | ||
35 | } | ||
36 | |||
37 | /////////////////////////////////////////////////////////////////////// | 14 | /////////////////////////////////////////////////////////////////////// |
38 | // Class GLSubpath | 15 | // Class GLSubpath |
39 | // representation a sequence of cubic bezier curves. | 16 | // representation a sequence of cubic bezier curves. |
@@ -44,49 +21,42 @@ var GLSubpath = function GLSubpath() { | |||
44 | /////////////////////////////////////////////////// | 21 | /////////////////////////////////////////////////// |
45 | // Instance variables | 22 | // Instance variables |
46 | /////////////////////////////////////////////////// | 23 | /////////////////////////////////////////////////// |
24 | |||
25 | // NOTE: | ||
26 | // This class contains functionality to store piecewise cubic bezier paths. | ||
27 | // The coordinates of the paths are always in local, canvas space. | ||
28 | // That is, the Z coordinate can be ignored (for now), and the paths are essentially in 2D. | ||
29 | // All coordinates of the '_Samples' should lie within [0,0] and [width, height], | ||
30 | // where width and height refer to the dimensions of the canvas for this path. | ||
31 | // Whenever the the canvas dimensions change, the coordinates of the anchor points | ||
32 | // and _Samples must be re-computed. | ||
33 | |||
47 | this._Anchors = []; | 34 | this._Anchors = []; |
48 | this._BBoxMin = [0, 0, 0]; | 35 | this._BBoxMin = [0, 0, 0]; |
49 | this._BBoxMax = [0, 0, 0]; | 36 | this._BBoxMax = [0, 0, 0]; |
37 | this._canvasCenterLocalCoord = [0,0,0]; | ||
38 | |||
5 |