Change version to 1.0 RC1
[raphael] / plugins / raphael.path.methods.js
index bd358cc..bce7036 100644 (file)
@@ -1,91 +1,53 @@
 Raphael.el.isAbsolute = true;
 Raphael.el.absolutely = function () {
-    if (this.type != "path") {
-        return this;
-    }
-    this.isAbsolute = true;
+    this.isAbsolute = 1;
     return this;
 };
 Raphael.el.relatively = function () {
-    if (this.type != "path") {
-        return this;
-    }
-    this.isAbsolute = false;
+    this.isAbsolute = 0;
     return this;
 };
 Raphael.el.moveTo = function (x, y) {
-    if (this.type != "path") {
-        return this;
-    }
-    var d = this.isAbsolute ? "M" : "m";
-    d += +parseFloat(x).toFixed(3) + " " + (+parseFloat(y).toFixed(3)) + " ";
-    this.attr({path: this.attrs.path + d});
-    return this;
+    this._last = {x: x, y: y};
+    return this.attr({path: this.attrs.path + ["m", "M"][+this.isAbsolute] + parseFloat(x) + " " + parseFloat(y)});
 };
 Raphael.el.lineTo = function (x, y) {
-    if (this.type != "path") {
-        return this;
-    }
-    var d = this.isAbsolute ? "L" : "l";
-    d += +parseFloat(x).toFixed(3) + " " + (+parseFloat(y).toFixed(3)) + " ";
-    this.attr({path: this.attrs.path + d});
-    return this;
+    this._last = {x: x, y: y};
+    return this.attr({path: this.attrs.path + ["l", "L"][+this.isAbsolute] + parseFloat(x) + " " + parseFloat(y)});
 };
-Raphael.el.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y) {
-    if (this.type != "path") {
-        return this;
-    }
-    var d = this.isAbsolute ? "A" : "a";
-    d += [+parseFloat(rx).toFixed(3), +parseFloat(ry).toFixed(3), 0, large_arc_flag, sweep_flag, +parseFloat(x).toFixed(3), +parseFloat(y).toFixed(3)].join(" ");
-    this.attr({path: this.attrs.path + d});
-    return this;
+Raphael.el.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y, angle) {
+    this._last = {x: x, y: y};
+    return this.attr({path: this.attrs.path + ["a", "A"][+this.isAbsolute] + [parseFloat(rx), parseFloat(ry), +angle, large_arc_flag, sweep_flag, parseFloat(x), parseFloat(y)].join(" ")});
 };
 Raphael.el.curveTo = function () {
-    if (this.type != "path") {
-        return this;
-    }
     var args = Array.prototype.splice.call(arguments, 0, arguments.length),
         d = [0, 0, 0, 0, "s", 0, "c"][args.length] || "";
-    if (this.isAbsolute) {
-        d = d.toUpperCase();
-    }
-    this.attr({path: this.attrs.path + d + args});
+    this.isAbsolute && (d = d.toUpperCase());
+    this._last = {x: args[args.length - 2], y: args[args.length - 1]};
+    return this.attr({path: this.attrs.path + d + args});
+};
+Raphael.el.cplineTo = function (x, y, w) {
+    this.attr({path: this.attrs.path + ["C", this._last.x + w, this._last.y, x - w, y, x, y]});
+    this._last = {x: x, y: y};
     return this;
 };
 Raphael.el.qcurveTo = function () {
-    if (this.type != "path") {
-        return this;
-    }
     var d = [0, 1, "t", 3, "q"][arguments.length],
         args = Array.prototype.splice.call(arguments, 0, arguments.length);
     if (this.isAbsolute) {
         d = d.toUpperCase();
     }
-    this.attr({path: this.attrs.path + d + args});
-    return this;
+    this._last = {x: args[args.length - 2], y: args[args.length - 1]};
+    return this.attr({path: this.attrs.path + d + args});
 };
 Raphael.el.addRoundedCorner = function (r, dir) {
-    if (this.type != "path") {
-        return this;
-    }
-    var rollback = this.isAbsolute,
-        o = this;
-    if (rollback) {
-        this.relatively();
-        rollback = function () {
-            o.absolutely();
-        };
-    } else {
-        rollback = function () {};
-    }
-    this.arcTo(r, r, 0, {"lu": 1, "rd": 1, "ur": 1, "dl": 1}[dir] || 0, r * (!!(dir.indexOf("r") + 1) * 2 - 1), r * (!!(dir.indexOf("d") + 1) * 2 - 1));
-    rollback();
+    var rollback = this.isAbsolute;
+    rollback && this.relatively();
+    this._last = {x: r * (!!(dir.indexOf("r") + 1) * 2 - 1), y: r * (!!(dir.indexOf("d") + 1) * 2 - 1)};
+    this.arcTo(r, r, 0, {"lu": 1, "rd": 1, "ur": 1, "dl": 1}[dir] || 0, this._last.x, this._last.y);
+    rollback && this.absolutely();
     return this;
 };
 Raphael.el.andClose = function () {
-    if (this.type != "path") {
-        return this;
-    }
-    this.attr({path: this.attrs.path + "z"});
-    return this;
-};
\ No newline at end of file
+    return this.attr({path: this.attrs.path + "z"});
+};