Skip to content

Commit

Permalink
Expanded Path utility methods
Browse files Browse the repository at this point in the history
- Added absolute commands with the "To"-suffix.
- Renamed "bezier" command to the more common "curve".
- The "curve" command now accepts 0, 1 or 2 control points (represented by the SVG Path commands: t, q, c)
  • Loading branch information
sebmarkbage committed Jul 10, 2010
1 parent 9b64838 commit 6b12845
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions Source/ART.Path.js
Expand Up @@ -176,6 +176,28 @@ var extrapolate = function(parts, precision){

};

/* Utility command factories */

var point = function(c){
return function(x, y){
return this.push(c, x, y);
};
};

var arc = function(c, cc){
return function(x, y, rx, ry, outer){
return this.push(c, Math.abs(rx || x), Math.abs(ry || rx || y), 0, outer ? 1 : 0, cc, x, y);
};
};

var curve = function(t, q, c){
return function(c1x, c1y, c2x, c2y, ex, ey){
var args = Array.slice(arguments), l = args.length;
args.unshift(l < 4 ? t : l < 6 ? q : c);
return this.push.apply(this, args);
};
};

/* Path Class */

ART.Path = new Class({
Expand Down Expand Up @@ -214,28 +236,23 @@ ART.Path = new Class({

/*utility*/

move: function(x, y){
return this.push('m', x, y);
},
move: point('m'),
moveTo: point('M'),

line: function(x, y){
return this.push('l', x, y);
},
line: point('l'),
lineTo: point('L'),

close: function(){
return this.push('z');
},
curve: curve('t', 'q', 'c'),
curveTo: curve('T', 'Q', 'C'),

bezier: function(c1x, c1y, c2x, c2y, ex, ey){
return this.push('c', c1x, c1y, c2x, c2y, ex, ey);
},
arc: arc('a', 1),
arcTo: arc('A', 1),

arc: function(x, y, rx, ry, large){
return this.push('a', Math.abs(rx || x), Math.abs(ry || rx || y), 0, large ? 1 : 0, 1, x, y);
},
counterArc: arc('a', 0),
counterArcTo: arc('A', 0),

counterArc: function(x, y, rx, ry, large){
return this.push('a', Math.abs(rx || x), Math.abs(ry || rx || y), 0, large ? 1 : 0, 0, x, y);
close: function(){
return this.push('z');
},

/* transformation, measurement */
Expand Down

0 comments on commit 6b12845

Please sign in to comment.