Rename Path#addSegment() to #_add(), to make sure it's supposed to be a private method.

This commit is contained in:
Jürg Lehni 2011-03-03 12:51:47 +00:00
parent 53b091b871
commit d4d6d652ec
2 changed files with 16 additions and 12 deletions

View file

@ -12,11 +12,11 @@ Path.inject({ statics: new function() {
Line: function() { Line: function() {
var path = new Path(); var path = new Path();
if (arguments.length == 2) { if (arguments.length == 2) {
path.addSegment(new Segment(arguments[0])); path._add(new Segment(arguments[0]));
path.addSegment(new Segment(arguments[1])); path._add(new Segment(arguments[1]));
} else if (arguments.length == 4) { } else if (arguments.length == 4) {
path.addSegment(Segment.read(arguments[0], arguments[1])); path._add(Segment.read(arguments[0], arguments[1]));
path.addSegment(Segment.read(arguments[2], arguments[3])); path._add(Segment.read(arguments[2], arguments[3]));
} }
return path; return path;
}, },
@ -74,7 +74,7 @@ Path.inject({ statics: new function() {
var size = new Size(rect.width, rect.height); var size = new Size(rect.width, rect.height);
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
var segment = ovalSegments[i]; var segment = ovalSegments[i];
path.addSegment(new Segment( path._add(new Segment(
segment.point.multiply(size).add(topLeft), segment.point.multiply(size).add(topLeft),
segment.handleIn.multiply(size), segment.handleIn.multiply(size),
segment.handleOut.multiply(size) segment.handleOut.multiply(size)

View file

@ -13,7 +13,7 @@ Path = PathItem.extend({
|| typeof segments[0] != 'object') || typeof segments[0] != 'object')
segments = arguments; segments = arguments;
for (var i = 0, l = segments.length; i < l; i++) for (var i = 0, l = segments.length; i < l; i++)
this.addSegment(new Segment(segments[i])); this._add(new Segment(segments[i]));
}, },
/** /**
@ -113,7 +113,11 @@ Path = PathItem.extend({
} }
}, },
addSegment: function(segment) { /**
* Private method that adds a segment to the segment list. It assumes that
* the passed object is a segment already and does not perform any checks.
*/
_add: function(segment) {
segment.path = this; segment.path = this;
this._segments.push(segment); this._segments.push(segment);
}, },
@ -121,7 +125,7 @@ Path = PathItem.extend({
add: function() { add: function() {
var segment = Segment.read(arguments); var segment = Segment.read(arguments);
if (segment) if (segment)
this.addSegment(segment); this._add(segment);
return segment; return segment;
}, },
@ -148,13 +152,13 @@ Path = PathItem.extend({
moveTo: function() { moveTo: function() {
var segment = Segment.read(arguments); var segment = Segment.read(arguments);
if (segment && !this._segments.length) if (segment && !this._segments.length)
this.addSegment(segment); this._add(segment);
}, },
lineTo: function() { lineTo: function() {
var segment = Segment.read(arguments); var segment = Segment.read(arguments);
if (segment) if (segment)
this.addSegment(segment); this._add(segment);
}, },
/** /**
@ -169,7 +173,7 @@ Path = PathItem.extend({
handle1.x - current.point.x, handle1.x - current.point.x,
handle1.y - current.point.y); handle1.y - current.point.y);
// And add the new segment, with handleIn set to c2 // And add the new segment, with handleIn set to c2
this.addSegment( this._add(
new Segment(to, handle2.subtract(to), new Point()) new Segment(to, handle2.subtract(to), new Point())
); );
}, },
@ -297,7 +301,7 @@ Path = PathItem.extend({
var inPoint = new Point( var inPoint = new Point(
centerX + (relx + z * rely) * radius - pt.x, centerX + (relx + z * rely) * radius - pt.x,
centerY + (rely - z * relx) * radius - pt.y); centerY + (rely - z * relx) * radius - pt.y);
this.addSegment(new Segment(pt, inPoint, out)); this._add(new Segment(pt, inPoint, out));
} }
angle += inc; angle += inc;
} }