From ecb288b5d65f3205e7d22f4299231da79721a3d0 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 28 Mar 2021 16:33:08 -0500 Subject: [PATCH] refactor: smooth --- packages/math/src/vertice.js | 15 +++------------ packages/topdown/src/resources/tiles.js | 12 +++++++++--- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/math/src/vertice.js b/packages/math/src/vertice.js index 6b6acc7..4f9a3f5 100644 --- a/packages/math/src/vertice.js +++ b/packages/math/src/vertice.js @@ -191,7 +191,7 @@ export function removeCollinear(vs) { return trimmed; } -export function smooth(sorted) { +export function smooth(sorted, angle) { const smoothed = []; if (0 === sorted.length) { return []; @@ -202,17 +202,8 @@ export function smooth(sorted) { const f = Vector.sub(sorted[i + 1], sorted[i]); const g = Vector.sub(sorted[i + 2], sorted[i + 1]); const o = Math.atan2(Vector.cross(f, g), Vector.dot(f, g)); - if (Math.abs(o) === Math.PI / 2 || Math.abs(o) === Math.PI / 4) { - const h = Vector.add(sorted[i + 1], Vector.scale(Vector.sub(g, f), 0.5)); - // eslint-disable-next-line no-use-before-define - if (0 === windingNumber(h, sorted)) { - sorted.splice(i + 1, 1); - i -= 1; - } - else { - smoothed.push(sorted[i]); - i += 1; - } + if (Math.abs(o) === angle) { + sorted.splice(i + 1, 1); } else { smoothed.push(sorted[i]); diff --git a/packages/topdown/src/resources/tiles.js b/packages/topdown/src/resources/tiles.js index fc7ccb1..e3e15b5 100644 --- a/packages/topdown/src/resources/tiles.js +++ b/packages/topdown/src/resources/tiles.js @@ -73,9 +73,15 @@ export default (latus) => { } } const hull = Vertice.removeCollinear( - Vertice.ortho( - Vertice.unique(body), - 2, + Vertice.smooth( + Vertice.smooth( + Vertice.ortho( + Vertice.unique(body), + 2, + ), + Math.PI / 2, + ), + Math.PI / 4, ), ); for (let i = 0; i < hull.length; i++) {