From d3181b41c5fe5960fc6fec709d933fd1bdddca10 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 6 Sep 2018 00:17:07 +0100 Subject: [PATCH] Added smooth method --- src/gameobjects/shape/Polygon.js | 38 +++++++++++--------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/gameobjects/shape/Polygon.js b/src/gameobjects/shape/Polygon.js index 2b83d26c6..83498ee14 100644 --- a/src/gameobjects/shape/Polygon.js +++ b/src/gameobjects/shape/Polygon.js @@ -10,6 +10,7 @@ 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'); /** * @classdesc @@ -57,6 +58,18 @@ var Polygon = new Class({ this.updateData(); }, + smooth: function (iterations) + { + if (iterations === undefined) { iterations = 1; } + + for (var i = 0; i < iterations; i++) + { + Smooth(this.data); + } + + return this.updateData(); + }, + updateData: function () { var path = []; @@ -67,35 +80,10 @@ var Polygon = new Class({ path.push(points[i].x, points[i].y); } - // path = this.smooth(path); - this.pathIndexes = Earcut(path); this.pathData = path; return this; - }, - - smooth: function (path) - { - var n = path.length, - result = [], - i = 0, - resultIndex = 0, - p0x, p0y, p1x, p1y; - - for (i; i