var PolygonRender = require('./PolygonRender'); var Class = require('../../../utils/Class'); var Earcut = require('../../../geom/polygon/Earcut'); var GetAABB = require('../../../geom/polygon/GetAABB'); var GeomPolygon = require('../../../geom/polygon/Polygon'); var Shape = require('../Shape'); var Smooth = require('../../../geom/polygon/Smooth'); var Polygon = new Class({ Extends: Shape, Mixins: [PolygonRender] , initialize: function Polygon(scene, x, y, points, fillColor, fillAlpha){ if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } Shape.call(this, scene, 'Polygon', new GeomPolygon(points)); var bounds = GetAABB(this.geom); this.setPosition(x, y); this.setSize(bounds.width, bounds.height); if (fillColor !== undefined) { this.setFillStyle(fillColor, fillAlpha); } this.updateDisplayOrigin(); this.updateData(); } , smooth: function (iterations){ if (iterations === undefined) { iterations = 1; } for (var i = 0; i < iterations; i++ ){ Smooth(this.geom); } return this.updateData(); } , updateData: function (){ var path = [] ; var points = this.geom.points; for (var i = 0; i < (_AN_Read_length('length', points)); i++ ){ path.push(points[i].x, points[i].y); } path.push(points[0].x, points[0].y); this.pathIndexes = Earcut(path); this.pathData = path; return this; } } ); module.exports = Polygon;