mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Optimise and simplfy CompoundPath code, by moving scope into extend() call, and only compiling one fields object inside it that is return at the end.
This commit is contained in:
parent
e6dc189310
commit
4c2e1ee5c9
1 changed files with 17 additions and 19 deletions
|
@ -1,5 +1,5 @@
|
||||||
new function() {
|
CompoundPath = PathItem.extend(new function() {
|
||||||
|
|
||||||
function getCurrentPath(compoundPath) {
|
function getCurrentPath(compoundPath) {
|
||||||
if (compoundPath.children.length) {
|
if (compoundPath.children.length) {
|
||||||
return compoundPath.children[compoundPath.children.length - 1];
|
return compoundPath.children[compoundPath.children.length - 1];
|
||||||
|
@ -8,7 +8,7 @@ new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompoundPath = PathItem.extend({
|
var fields = {
|
||||||
initialize: function(items) {
|
initialize: function(items) {
|
||||||
this.base();
|
this.base();
|
||||||
this.children = [];
|
this.children = [];
|
||||||
|
@ -56,38 +56,36 @@ new function() {
|
||||||
this.children[i].smooth();
|
this.children[i].smooth();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
moveTo: function() {
|
moveTo: function() {
|
||||||
var path = new Path();
|
var path = new Path();
|
||||||
this.appendTop(path);
|
this.appendTop(path);
|
||||||
path.moveTo.apply(path, arguments);
|
path.moveTo.apply(path, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
moveBy: function() {
|
moveBy: function() {
|
||||||
if (!arguments.length) {
|
if (!arguments.length) {
|
||||||
|
// TODO: Shouldn't this be relative to the previous position
|
||||||
|
// in lack of an argument? This should then be corrected in
|
||||||
|
// Scriptographer too.
|
||||||
this.moveTo(0, 0);
|
this.moveTo(0, 0);
|
||||||
} else {
|
} else {
|
||||||
var point = Point.read(arguments);
|
var point = Point.read(arguments);
|
||||||
var curPath = this.getCurrentPath(this);
|
var curPath = getCurrentPath(this);
|
||||||
var current = curPath.segments[curPath.segments.length - 1].point;
|
var current = curPath.segments[curPath.segments.length - 1].point;
|
||||||
this.moveTo(current.add(point));
|
this.moveTo(current.add(point));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
var keys = ['lineTo', 'cubicCurveTo', 'curveTo', 'quadraticCurveTo',
|
var keys = ['lineTo', 'cubicCurveTo', 'quadraticCurveTo', 'curveTo',
|
||||||
'arcTo', 'lineBy', 'curveBy', 'arcBy'];
|
'arcTo', 'lineBy', 'curveBy', 'arcBy'];
|
||||||
var props = {};
|
for (var i = 0, l = keys.length; i < l; i++) {
|
||||||
|
fields[keys[i]] = function() {
|
||||||
function addProp(key) {
|
var path = getCurrentPath(this);
|
||||||
props[key] = function() {
|
path[keys[i]].apply(path, arguments);
|
||||||
var curPath = getCurrentPath(this);
|
|
||||||
curPath[key].apply(curPath, arguments);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0, l = keys.length; i < l; i++) {
|
return fields;
|
||||||
addProp(keys[i]);
|
|
||||||
}
|
|
||||||
CompoundPath.inject(props);
|
|
||||||
};
|
};
|
Loading…
Reference in a new issue