polygon miter paths. bump rev 2.3.D6
This commit is contained in:
parent
a4b6713acc
commit
4c00a41a2a
8 changed files with 83 additions and 8 deletions
4
notes.md
4
notes.md
|
|
@ -1,5 +1,9 @@
|
||||||
# Kiri:Moto todo
|
# Kiri:Moto todo
|
||||||
|
|
||||||
|
NEXT
|
||||||
|
- contour outside part boundaries
|
||||||
|
- fdm first level height render
|
||||||
|
|
||||||
## `C` cosmetic, `F` functional, `P` performance, `B` bug fix
|
## `C` cosmetic, `F` functional, `P` performance, `B` bug fix
|
||||||
|
|
||||||
* `F` detect and report slow framerates
|
* `F` detect and report slow framerates
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "grid-apps",
|
"name": "grid-apps",
|
||||||
"version": "2.3.D5",
|
"version": "2.3.D6",
|
||||||
"description": "grid.space 3d slice & modeling tools",
|
"description": "grid.space 3d slice & modeling tools",
|
||||||
"author": "Stewart Allen <sa@grid.space>",
|
"author": "Stewart Allen <sa@grid.space>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
var AP = Array.prototype;
|
var AP = Array.prototype;
|
||||||
|
|
||||||
/** ******************************************************************
|
/** ******************************************************************
|
||||||
* array prototype helpers
|
* Array prototype helpers
|
||||||
******************************************************************* */
|
******************************************************************* */
|
||||||
|
|
||||||
if (!AP.flat) {
|
if (!AP.flat) {
|
||||||
|
|
@ -148,7 +148,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
/** ******************************************************************
|
/** ******************************************************************
|
||||||
* string prototype helpers
|
* String prototype helpers
|
||||||
******************************************************************* */
|
******************************************************************* */
|
||||||
|
|
||||||
String.prototype.reverse = function() {
|
String.prototype.reverse = function() {
|
||||||
|
|
@ -167,4 +167,13 @@
|
||||||
return Math.max(min,Math.min(max,val));
|
return Math.max(min,Math.min(max,val));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** ******************************************************************
|
||||||
|
* Number static helpers
|
||||||
|
******************************************************************* */
|
||||||
|
|
||||||
|
Number.prototype.round = function(digits) {
|
||||||
|
const pow = Math.pow(10,digits || 3);
|
||||||
|
return Math.round(this.valueOf() * pow) / pow;
|
||||||
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -221,8 +221,62 @@
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
PRO.miter = function() {
|
function slopeDiff(s1, s2) {
|
||||||
|
const n1 = s1.angle;//(s1.angle + 360) % 360;
|
||||||
|
const n2 = s2.angle;//(s2.angle + 360) % 360;
|
||||||
|
let diff = n2 - n1;
|
||||||
|
while (diff < -180) diff += 360;
|
||||||
|
while (diff > 180) diff -= 360;
|
||||||
|
return Math.abs(diff);
|
||||||
|
}
|
||||||
|
|
||||||
|
PRO.miter = function(debug) {
|
||||||
|
if (this.length < 3) return this;
|
||||||
|
|
||||||
// todo - to eliminate path sharps in renders
|
// todo - to eliminate path sharps in renders
|
||||||
|
const slo = [], pa = this.points, pln = pa.length, open = this.open;
|
||||||
|
let last;
|
||||||
|
for (let i=1; i<pln; i++) {
|
||||||
|
slo.push(pa[i-1].slopeTo(last = pa[i]));
|
||||||
|
}
|
||||||
|
if (!open) {
|
||||||
|
slo.push(last.slopeTo(pa[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
const ang = new Array(pln).fill(0);
|
||||||
|
let redo = false;
|
||||||
|
const aln = open ? pln - 1 : pln;
|
||||||
|
for (let i=1; i<aln; i++) {
|
||||||
|
ang[i] = slopeDiff(slo[i-1], slo[i]);
|
||||||
|
redo |= ang[i] < 90;
|
||||||
|
}
|
||||||
|
if (!open) {
|
||||||
|
// ang[pln-1] = slopeDiff(slo[pln-2], slo[pln-1]);
|
||||||
|
ang[0] = slopeDiff(slo[pln-1], slo[0]);
|
||||||
|
redo |= ang[pln-1] > 90;
|
||||||
|
redo |= ang[0] > 90;
|
||||||
|
}
|
||||||
|
if (redo) {
|
||||||
|
const newp = newPolygon();
|
||||||
|
// newp.debug = this.debug = true;
|
||||||
|
newp.open = open;
|
||||||
|
for (let i=0; i<pln; i++) {
|
||||||
|
const p = pa[(i+pln) % pln];
|
||||||
|
const d = ang[(i+pln) % pln];
|
||||||
|
if (d > 90) {
|
||||||
|
const s = slo[(i+pln) % pln];
|
||||||
|
const pp = pa[(i+pln-1) % pln];
|
||||||
|
const ps = slo[(i+pln-1) % pln];
|
||||||
|
newp.push(p.follow(p.slopeTo(pp), 0.005));
|
||||||
|
newp.push(p.follow(s, 0.005));
|
||||||
|
} else {
|
||||||
|
p.parent = newp;
|
||||||
|
newp.push(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newp;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
PRO.createConvexHull = function(points) {
|
PRO.createConvexHull = function(points) {
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@
|
||||||
PRO.invert = function() {
|
PRO.invert = function() {
|
||||||
this.dx = -this.dx;
|
this.dx = -this.dx;
|
||||||
this.dy = -this.dy;
|
this.dy = -this.dy;
|
||||||
this.angle = 360 - this.angle;
|
this.angle = 180 - this.angle;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
const KIRI = self.kiri, BASE = self.base, POLY = BASE.polygons;
|
const KIRI = self.kiri, BASE = self.base, POLY = BASE.polygons, newPolygon = BASE.newPolygon;
|
||||||
|
|
||||||
class Render {
|
class Render {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -164,6 +164,14 @@
|
||||||
|
|
||||||
polys.forEach(poly => {
|
polys.forEach(poly => {
|
||||||
const contour = [];
|
const contour = [];
|
||||||
|
poly = poly.miter();
|
||||||
|
// if (poly.debug) {
|
||||||
|
// const save = this.current;
|
||||||
|
// this.setLayer('debug.acute', 0xff0000).addPoly(poly, {thin:true});
|
||||||
|
// this.setLayer('debug.start', 0x00ff00).addPoly(newPolygon().centerRectangle(poly.first(),1,1), {thin:true});
|
||||||
|
// this.setLayer('debug.end', 0x0000ff).addPoly(newPolygon().centerRectangle(poly.last(),0.8,0.8), {thin:true});
|
||||||
|
// this.current = save;
|
||||||
|
// }
|
||||||
poly.points.forEach(p => {
|
poly.points.forEach(p => {
|
||||||
contour.push(new THREE.Vector2(p.x, p.y));
|
contour.push(new THREE.Vector2(p.x, p.y));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
let terms = {
|
let terms = {
|
||||||
COPYRIGHT: "Copyright (C) Stewart Allen <sa@grid.space> - All Rights Reserved",
|
COPYRIGHT: "Copyright (C) Stewart Allen <sa@grid.space> - All Rights Reserved",
|
||||||
LICENSE: "See the license.md file included with the source distribution",
|
LICENSE: "See the license.md file included with the source distribution",
|
||||||
VERSION: "2.3.D5"
|
VERSION: "2.3.D6"
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof(module) === 'object') {
|
if (typeof(module) === 'object') {
|
||||||
|
|
|
||||||
|
|
@ -484,7 +484,7 @@
|
||||||
lastOut = out;
|
lastOut = out;
|
||||||
});
|
});
|
||||||
if (lastOut.emit) {
|
if (lastOut.emit) {
|
||||||
pushPrint(lastOut.tool, current)
|
// pushPrint(lastOut.tool, current)
|
||||||
} else {
|
} else {
|
||||||
moves.push(current);
|
moves.push(current);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue