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

View file

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