Fix a couple of bugs in shape drawing code, and switch to consistently use this.currentSegment rather than this._segments[this._segments.length - 1], to use the internal check for a starting point.

This commit is contained in:
Jürg Lehni 2011-02-13 15:12:25 +00:00
parent a579b8bd3d
commit 771d9d0efe

View file

@ -109,7 +109,7 @@ PathItem = Item.extend(new function() {
// First modify the current segment: // First modify the current segment:
var current = this.currentSegment; var current = this.currentSegment;
// Convert to relative values: // Convert to relative values:
current.handleOut.set( current.handleOut = new Point(
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
@ -128,10 +128,10 @@ PathItem = Item.extend(new function() {
// and the cubic is A B C D, // and the cubic is A B C D,
// B = E + 1/3 (A - E) // B = E + 1/3 (A - E)
// C = E + 1/3 (D - E) // C = E + 1/3 (D - E)
var current = this._segments[this._segments.length - 1]; var current = this.currentSegment;
var x1 = current.point.x; var x1 = current.point.x;
var y1 = current.point.y; var y1 = current.point.y;
cubicCurveTo( this.cubicCurveTo(
handle.add(current.point.subtract(handle).multiply(1/3)), handle.add(current.point.subtract(handle).multiply(1/3)),
handle.add(to.subtract(handle).multiply(1/3)), handle.add(to.subtract(handle).multiply(1/3)),
to to
@ -143,7 +143,7 @@ PathItem = Item.extend(new function() {
to = new Point(to); to = new Point(to);
if(parameter == null) if(parameter == null)
parameter = 0.5; parameter = 0.5;
var current = this._segments[this._segments.length - 1]; var current = this.currentSegment.point;
// handle = (through - (1 - t)^2 * current - t^2 * to) / (2 * (1 - t) * t) // handle = (through - (1 - t)^2 * current - t^2 * to) / (2 * (1 - t) * t)
var t1 = 1 - parameter; var t1 = 1 - parameter;
var handle = through.subtract( var handle = through.subtract(
@ -159,22 +159,21 @@ PathItem = Item.extend(new function() {
arcTo: function(to, clockwise) { arcTo: function(to, clockwise) {
var through, to; var through, to;
// Get the start point:
var current = this.currentSegment;
if(arguments[1] && typeof arguments[1] != 'boolean') { if(arguments[1] && typeof arguments[1] != 'boolean') {
through = new Point(arguments[0]); through = new Point(arguments[0]);
to = new Point(arguments[1]); to = new Point(arguments[1]);
} else { } else {
if(clockwise === null) if(clockwise === null)
clockwise = true; clockwise = true;
var current = this._segments[this._segments.length - 1].point; var middle = current.point.add(to).divide(2);
var middle = current.add(to).divide(2); var step = middle.subtract(current.point);
var step = middle.subtract(current);
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);
} }
// Get the start point:
var current = this._segments[this._segments.length - 1];
var x1 = current.point.x, x2 = through.x, x3 = to.x; var x1 = current.point.x, x2 = through.x, x3 = to.x;
var y1 = current.point.y, y2 = through.y, y3 = to.y; var y1 = current.point.y, y2 = through.y, y3 = to.y;
@ -250,7 +249,7 @@ PathItem = Item.extend(new function() {
lineBy: function() { lineBy: function() {
var vector = Point.read(arguments); var vector = Point.read(arguments);
if(vector) { if(vector) {
var current = this._segments[this._segments.length - 1]; var current = this.currentSegment;
this.lineTo(current.point.add(vector)); this.lineTo(current.point.add(vector));
} }
}, },
@ -357,14 +356,14 @@ PathItem = Item.extend(new function() {
curveBy: function(throughVector, toVector, parameter) { curveBy: function(throughVector, toVector, parameter) {
throughVector = Point.read(throughVector); throughVector = Point.read(throughVector);
toVector = Point.read(toVector); toVector = Point.read(toVector);
var current = this._segments[this._segments.length - 1].point; var current = this.currentSegment.point;
this.curveTo(current.add(throughVector), current.add(toVector), parameter); this.curveTo(current.add(throughVector), current.add(toVector), parameter);
}, },
arcBy: function(throughVector, toVector) { arcBy: function(throughVector, toVector) {
throughVector = Point.read(throughVector); throughVector = Point.read(throughVector);
toVector = Point.read(toVector); toVector = Point.read(toVector);
var current = this._segments[this._segments.length - 1].point; var current = this.currentSegment.point;
this.arcBy(current.add(throughVector), current.add(toVector)); this.arcBy(current.add(throughVector), current.add(toVector));
}, },