Fix Segment#getHandleIn/OutIfSet and a newly introduced drawing error in Path#draw.

This commit is contained in:
Jürg Lehni 2011-03-06 11:18:35 +00:00
parent 7bea7e36de
commit 56c10f9196
2 changed files with 16 additions and 16 deletions

View file

@ -248,8 +248,8 @@ var Path = this.Path = PathItem.extend({
} else {
if (clockwise === null)
clockwise = true;
var middle = current._point.add(to).divide(2);
var step = middle.subtract(current._point);
var middle = current._point.add(to).divide(2),
step = middle.subtract(current._point);
through = clockwise
? middle.subtract(-step.y, step.x)
: middle.add(-step.y, step.x);
@ -360,18 +360,17 @@ var Path = this.Path = PathItem.extend({
ctx.beginPath();
var segments = this._segments,
length = segments.length,
outX, outY;
handleOut, outX, outY;
for (var i = 0; i < length; i++) {
var segment = segments[i],
point = segment._point,
x = point.x,
y = point.y,
handleIn = segment._handleIn,
handleOut = segment._handleOut;
handleIn = segment._handleIn;
if (i == 0) {
ctx.moveTo(x, y);
} else {
if (handleOut.isZero() && handleIn.isZero()) {
if (handleIn.isZero() && handleOut.isZero()) {
ctx.lineTo(x, y);
} else {
ctx.bezierCurveTo(
@ -381,6 +380,7 @@ var Path = this.Path = PathItem.extend({
);
}
}
handleOut = segment._handleOut;
outX = handleOut.x + x;
outY = handleOut.y + y;
}

View file

@ -48,24 +48,19 @@ var Segment = this.Segment = Base.extend({
return this._handleIn;
},
getHandleInIfSet: function() {
return this._handleIn.x == this._handleIn.y == 0
? null : this._handleIn;
},
setHandleIn: function() {
this._handleIn = Point.read(arguments);
// Update corner accordingly
// this.corner = !this._handleIn.isParallel(this._handleOut);
},
getHandleOut: function() {
return this._handleOut;
getHandleInIfSet: function() {
return this._handleIn.x == 0 && this._handleIn.y == 0
? null : this._handleIn;
},
getHandleOutIfSet: function() {
return this._handleOut.x == this._handleOut.y == 0
? null : this._handleOut;
getHandleOut: function() {
return this._handleOut;
},
setHandleOut: function() {
@ -74,6 +69,11 @@ var Segment = this.Segment = Base.extend({
// this.corner = !this._handleIn.isParallel(this._handleOut);
},
getHandleOutIfSet: function() {
return this._handleOut.x == 0 && this._handleOut.y == 0
? null : this._handleOut;
},
getIndex: function() {
// TODO: Cache and update indices instead of searching?
return this.path ? this.path._segments.indexOf(this) : -1;