smooth gyroid poly lines
This commit is contained in:
parent
6280093a52
commit
29ae84380c
3 changed files with 65 additions and 2 deletions
|
|
@ -139,7 +139,37 @@ var gs_base_gyroid = exports;
|
|||
} while (added);
|
||||
} while (cleared < sparse.length);
|
||||
|
||||
return {edge, points, dir, polys};
|
||||
return {edge, points, dir, polys: polys.map(poly => filter(poly))};
|
||||
}
|
||||
|
||||
function filter(poly) {
|
||||
if (poly.length === 1) {
|
||||
return poly;
|
||||
}
|
||||
let nuchain = [];
|
||||
let e1 = poly[0];
|
||||
let e2 = null;
|
||||
let last = poly.length - 1;
|
||||
for (let i=1; i<poly.length; i++) {
|
||||
let el = poly[i];
|
||||
if (e1.x === el.x || e1.y === el.y) {
|
||||
e2 = el;
|
||||
if (i < last) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (e2) {
|
||||
nuchain.push({x:(e1.x + e2.x)/2, y:(e1.y + e2.y)/2});
|
||||
e2 = null;
|
||||
} else {
|
||||
nuchain.push(e1);
|
||||
if (i === last) {
|
||||
nuchain.push(el);
|
||||
}
|
||||
}
|
||||
e1 = el;
|
||||
}
|
||||
return nuchain;
|
||||
}
|
||||
|
||||
function dist(a, b, dir) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
var exports = {
|
||||
COPYRIGHT:"Copyright (C) 2014-2019 Stewart Allen <sa@grid.space> - All Rights Reserved",
|
||||
LICENSE:"See the license.md file included with the source distribution",
|
||||
VERSION:"1.2.6"
|
||||
VERSION:"1.2.6a"
|
||||
};
|
||||
if (!module) var module = {};
|
||||
module.exports = exports;
|
||||
|
|
|
|||
|
|
@ -192,9 +192,42 @@
|
|||
} while (added);
|
||||
} while (cleared < sparse.length);
|
||||
|
||||
// simplify poly
|
||||
polys = polys.map(poly => filter(poly));
|
||||
|
||||
return zcache[zkey] = {edge, points, dir, polys};
|
||||
}
|
||||
|
||||
function filter(poly) {
|
||||
if (poly.length === 1) {
|
||||
return poly;
|
||||
}
|
||||
let nuchain = [];
|
||||
let e1 = poly[0];
|
||||
let e2 = null;
|
||||
let last = poly.length - 1;
|
||||
for (let i=1; i<poly.length; i++) {
|
||||
let el = poly[i];
|
||||
if (e1.x === el.x || e1.y === el.y) {
|
||||
e2 = el;
|
||||
if (i < last) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (e2) {
|
||||
nuchain.push({x:(e1.x + e2.x)/2, y:(e1.y + e2.y)/2});
|
||||
e2 = null;
|
||||
} else {
|
||||
nuchain.push(e1);
|
||||
if (i === last) {
|
||||
nuchain.push(el);
|
||||
}
|
||||
}
|
||||
e1 = el;
|
||||
}
|
||||
return nuchain;
|
||||
}
|
||||
|
||||
function dist(a, b, dir) {
|
||||
let dx = a.x - b.x;
|
||||
let dy = a.y - b.y;
|
||||
|
|
|
|||
Loading…
Reference in a new issue