improve open poly offsetting. change gerber trace 3d interpetation

This commit is contained in:
Stewart Allen 2024-07-01 20:52:49 -04:00
commit 619468ee00
4 changed files with 77 additions and 24 deletions

View file

@ -1495,7 +1495,6 @@ class Polygon {
toClipper(inout) {
let poly = this,
cur = [],
out = inout || [];
out.push(poly.points.map(p => p.toClipper()));
if (poly.inner) {
@ -1519,6 +1518,37 @@ class Polygon {
return POLY.expand([this], -offset, this.getZ(), output);
}
/**
* ofsetting an open line uses a different procedure and options
*
* @param {number} distance
* @param {'square'|'round'|'miter'} type
* @returns {Polygon[]}
*/
offset_open(distance, type = 'miter') {
if (this.isOpen()) {
let cjnt = clib.JoinType,
cety = clib.EndType,
coff = new clib.ClipperOffset(),
ctre = new clib.PolyTree(),
entt = {
'square' : cety.etOpenSquare,
'round' : cety.etOpenRound,
'miter' : cety.etOpenSquare
}[type] || cety.etOpenSquare,
jntt = {
'square': cjnt.jtSquare,
'round': cjnt.jtRound,
'miter': cjnt.jtMiter
}[type] || cjnt.jtMiter;
coff.AddPaths(this.toClipper(), jntt, entt);
coff.Execute(ctre, distance * config.clipper);
return POLY.fromClipperTree(ctre, this.getZ(), null, null, 0);
} else {
return this.offset(distance);
}
}
/**
* todo need something more clever for polygons that overlap with
* todo differing resolutions (like circles)

View file

@ -34,7 +34,7 @@ const POLYS = base.polygons = {
offset,
trimTo,
expand,
expand_lines,
// expand_lines,
points,
length,
route,
@ -508,18 +508,18 @@ function sumCirc(polys) {
* @param {number} distance offset
* @param {number} [z] defaults to 0
*/
function expand_lines(poly, distance, z) {
let fact = config.clipper,
cjnt = clib.JoinType,
cety = clib.EndType,
coff = new clib.ClipperOffset(),
ctre = new clib.PolyTree();
// function expand_lines(poly, distance, z) {
// let fact = config.clipper,
// cjnt = clib.JoinType,
// cety = clib.EndType,
// coff = new clib.ClipperOffset(),
// ctre = new clib.PolyTree();
coff.AddPaths(poly.toClipper(), cjnt.jtMiter, cety.etOpenSquare);
coff.Execute(ctre, distance * fact);
// coff.AddPaths(poly.toClipper(), cjnt.jtMiter, cety.etOpenSquare);
// coff.Execute(ctre, distance * fact);
return fromClipperTree(ctre, z, null, null, 0);
}
// return fromClipperTree(ctre, z, null, null, 0);
// }
/**
* @param {Polygon[]} polys