      1 (function() {
      2
      3   var fabric = this.fabric || (this.fabric = { });
      4
      5   if (fabric.Triangle) {
      6     fabric.warn('fabric.Triangle is already defined');
      7     return;
      8   }
      9
     10   /**
     11    * @class Triangle
     12    * @extends fabric.Object
     13    */
     14   fabric.Triangle = fabric.util.createClass(fabric.Object, /** @scope fabric.Triangle.prototype */ {
     15
     16     /**
     17      * @property
     18      * @type String
     19      */
     20     type: 'triangle',
     21
     22     /**
     23      * Constructor
     24      * @method initialize
     25      * @param options {Object} options object
     26      * @return {Object} thisArg
     27      */
     28     initialize: function(options) {
     29       options = options || { };
     30
     31       this.callSuper('initialize', options);
     32
     33       this.set('width', options.width || 100)
     34           .set('height', options.height || 100);
     35     },
     36
     37     /**
     38      * @private
     39      * @method _render
     40      * @param ctx {CanvasRenderingContext2D} Context to render on
     41      */
     42     _render: function(ctx) {
     43       var widthBy2 = this.width / 2,
     44           heightBy2 = this.height / 2;
     45
     46       ctx.beginPath();
     47       ctx.moveTo(-widthBy2, heightBy2);
     48       ctx.lineTo(0, -heightBy2);
     49       ctx.lineTo(widthBy2, heightBy2);
     50       ctx.closePath();
     51
     52       if (this.fill) {
     53         ctx.fill();
     54       }
     55       if (this.stroke) {
     56         ctx.stroke();
     57       }
     58     },
     59
     60     /**
     61      * Returns complexity of an instance
     62      * @method complexity
     63      * @return {Number} complexity of this instance
     64      */
     65     complexity: function() {
     66       return 1;
     67     }
     68   });
     69
     70   /**
     71    * Returns fabric.Triangle instance from an object representation
     72    * @static
     73    * @method Canvas.Trangle.fromObject
     74    * @param object {Object} object to create an instance from
     75    * @return {Object} instance of Canvas.Triangle
     76    */
     77   fabric.Triangle.fromObject = function(object) {
     78     return new fabric.Triangle(object);
     79   };
     80 })();