refactor: smooth

This commit is contained in:
cha0s 2021-03-28 16:33:08 -05:00
parent 775ba3e84c
commit ecb288b5d6
2 changed files with 12 additions and 15 deletions

View File

@ -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]);

View File

@ -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++) {