1 /*!
  2  * Raphael Path Methods Plugin 0.2
  3  *
  4  * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
  5  * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
  6  */
  7 
  8 Raphael.el.isAbsolute = true;
  9 Raphael.el.absolutely = function () {
 10     this.isAbsolute = 1;
 11     return this;
 12 };
 13 Raphael.el.relatively = function () {
 14     this.isAbsolute = 0;
 15     return this;
 16 };
 17 Raphael.el.moveTo = function (x, y) {
 18     this._last = {x: x, y: y};
 19     return this.attr({path: this.attrs.path + ["m", "M"][+this.isAbsolute] + parseFloat(x) + " " + parseFloat(y)});
 20 };
 21 Raphael.el.lineTo = function (x, y) {
 22     this._last = {x: x, y: y};
 23     return this.attr({path: this.attrs.path + ["l", "L"][+this.isAbsolute] + parseFloat(x) + " " + parseFloat(y)});
 24 };
 25 Raphael.el.arcTo = function (rx, ry, large_arc_flag, sweep_flag, x, y, angle) {
 26     this._last = {x: x, y: y};
 27     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(" ")});
 28 };
 29 Raphael.el.curveTo = function () {
 30     var args = Array.prototype.splice.call(arguments, 0, arguments.length),
 31         d = [0, 0, 0, 0, "s", 0, "c"][args.length] || "";
 32     this.isAbsolute && (d = d.toUpperCase());
 33     this._last = {x: args[args.length - 2], y: args[args.length - 1]};
 34     return this.attr({path: this.attrs.path + d + args});
 35 };
 36 Raphael.el.cplineTo = function (x, y, w) {
 37     this.attr({path: this.attrs.path + ["C", this._last.x + w, this._last.y, x - w, y, x, y]});
 38     this._last = {x: x, y: y};
 39     return this;
 40 };
 41 Raphael.el.qcurveTo = function () {
 42     var d = [0, 1, "t", 3, "q"][arguments.length],
 43         args = Array.prototype.splice.call(arguments, 0, arguments.length);
 44     if (this.isAbsolute) {
 45         d = d.toUpperCase();
 46     }
 47     this._last = {x: args[args.length - 2], y: args[args.length - 1]};
 48     return this.attr({path: this.attrs.path + d + args});
 49 };
 50 Raphael.el.addRoundedCorner = function (r, dir) {
 51     var rollback = this.isAbsolute;
 52     rollback && this.relatively();
 53     this._last = {x: r * (!!(dir.indexOf("r") + 1) * 2 - 1), y: r * (!!(dir.indexOf("d") + 1) * 2 - 1)};
 54     this.arcTo(r, r, 0, {"lu": 1, "rd": 1, "ur": 1, "dl": 1}[dir] || 0, this._last.x, this._last.y);
 55     rollback && this.absolutely();
 56     return this;
 57 };
 58 Raphael.el.andClose = function () {
 59     return this.attr({path: this.attrs.path + "z"});
 60 };
 61