checkpoint kiri module migration work
This commit is contained in:
parent
e341b98849
commit
7d22cc1029
201 changed files with 41262 additions and 85 deletions
|
|
@ -519,6 +519,98 @@ export function shapeToPath(shape, points, closed) {
|
|||
return {index, faces};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a list of points approximating a circular arc.
|
||||
* @param {Point} start - the starting point of the arc.
|
||||
* @param {Point} end - the ending point of the arc.
|
||||
* @param {number} [arcdivs= 24] - the number of lines to use to represent PI radians
|
||||
* @param {number} opts.radius - the radius of the arc. If undefined, will use the
|
||||
* start and end points to infer the radius.
|
||||
* @param {boolean} opts.clockwise - whether the arc is clockwise or counter-clockwise.
|
||||
* generating the points.
|
||||
*
|
||||
* @return {Array<Point>} an array of points representing the arc.
|
||||
*/
|
||||
export function arcToPath (start, end, arcdivs=24, opts) {
|
||||
|
||||
let { clockwise, center, radius } = opts;
|
||||
|
||||
// @type {Point}
|
||||
if (end.x === undefined && end.x === undefined && center === undefined) {
|
||||
// bambu generates loop z or wipe loop arcs in place
|
||||
// console.log({ skip_empty_arc: rec });
|
||||
return;
|
||||
}
|
||||
|
||||
if (center) {
|
||||
// center = center.add(start);
|
||||
center.r = center.distTo2D(start);
|
||||
} else if (radius !== undefined) {
|
||||
let pd = { x: end.x - start.x, y: end.y - start.y }; //position delta
|
||||
let dst = Math.sqrt(pd.x * pd.x + pd.y * pd.y) / 2; // distance
|
||||
let pr2;
|
||||
if (Math.abs(dst - radius) < 0.001) {
|
||||
// center point radius
|
||||
pr2 = { x: (end.x + start.x) / 2, y: (end.y + start.y) / 2};
|
||||
} else {
|
||||
// triangulate
|
||||
pr2 = base.util.center2pr(start, end, radius, clockwise);
|
||||
}
|
||||
center.x = pr2.x;
|
||||
center.y = pr2.y;
|
||||
center.r = radius;
|
||||
} else {
|
||||
console.log({malfomed_arc: {radius,center, clockwise, start, end}});
|
||||
}
|
||||
|
||||
//deltas
|
||||
let dx = start.x - end.x;
|
||||
let dy = start.y - end.y;
|
||||
let dz = start.z - end.z;
|
||||
|
||||
// line angles
|
||||
let a1 = Math.atan2(center.y - start.y, center.x - start.x) + Math.PI;
|
||||
let a2 = Math.atan2(center.y - end.y, center.x - end.x) + Math.PI;
|
||||
let ad = base.util.thetaDiff(a1, a2, clockwise); // angle difference in radians
|
||||
let samePoint = Math.abs(ad) < 0.001
|
||||
let ofFull = Math.abs(ad)/(2*Math.PI);
|
||||
let steps = samePoint? arcdivs : Math.max(Math.floor( arcdivs * ofFull),4);
|
||||
let step = (samePoint? (Math.PI*2) : ad) / steps;
|
||||
let numPoints = steps/ step;
|
||||
let zStart = start.z;
|
||||
let zStep = dz / numPoints;
|
||||
let rot = a1 + step;
|
||||
|
||||
//unused deltas
|
||||
let da = Math.abs(a1 - a2);
|
||||
let dd = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
// LOG({index, da, dd, first: pos, last: rec, center, a1, a2, ad, step, steps, rot, line});
|
||||
// G0G1(false, [`X${center.x}`, `Y${center.y}`, `E1`]);
|
||||
|
||||
// under 1 degree arc and 5mm, convert to straight line
|
||||
// if (da < 0.005 && dd < 5) {
|
||||
// G0G1(false, [`X${end.x}`, `Y${end.y}`, `E1`]);
|
||||
// return ;
|
||||
// }
|
||||
|
||||
let arr = [] // point accumulator
|
||||
for (let i=0; i<=steps-2; i++) {
|
||||
if (isNaN(center.r) || isNaN(center.x) || isNaN(center.y)) {
|
||||
console.log({malfomed_arc: {radius, clockwise, start, end}});
|
||||
}
|
||||
arr.push(newPoint(
|
||||
center.x + Math.cos(rot) * center.r,
|
||||
center.y + Math.sin(rot) * center.r,
|
||||
zStart,
|
||||
));
|
||||
zStart += zStep;
|
||||
rot += step;
|
||||
}
|
||||
// console.log(arr,start,end);
|
||||
return arr
|
||||
}
|
||||
|
||||
export class FloatPacker {
|
||||
constructor(size, factor) {
|
||||
this.size = size;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||
|
||||
import { THREE } from '../ext/three.js';
|
||||
const { Vector3 } = THREE;
|
||||
|
||||
import { util, config, key } from './base.js';
|
||||
import { newLine } from './line.js';
|
||||
import { newSlope } from './slope.js';
|
||||
|
||||
const { Vector3 } = THREE;
|
||||
|
||||
export class Point {
|
||||
constructor(x = 0, y = 0, z = 0, key) {
|
||||
|
|
@ -122,11 +123,11 @@ export class Point {
|
|||
}
|
||||
|
||||
slopeTo(p) {
|
||||
return base.newSlope(this, p);
|
||||
return newSlope(this, p);
|
||||
}
|
||||
|
||||
lineTo(p, k) {
|
||||
return base.newLine(this, p, k);
|
||||
return newLine(this, p, k);
|
||||
}
|
||||
|
||||
isNear(p, dist) {
|
||||
|
|
@ -292,7 +293,7 @@ export class Point {
|
|||
np2 = newPoint(p2.x - oy, p2.y + ox, p2.z, key.NONE);
|
||||
np1.op = p1;
|
||||
np2.op = p2;
|
||||
return base.newLine(np1, np2, key.NONE);
|
||||
return newLine(np1, np2, key.NONE);
|
||||
}
|
||||
|
||||
offset(x, y, z) {
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
import { config } from './base.js';
|
||||
import { newPoint } from '../geo/point.js';
|
||||
|
||||
const { config } = base;
|
||||
|
||||
/**
|
||||
* converts a geometry point array into a kiri point array
|
||||
* with optional decimation
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@
|
|||
|
||||
import { base, config, util } from './base.js';
|
||||
import { ClipperLib } from '../ext/clip2.esm.js';
|
||||
import { THREE } from '../ext/three.js';
|
||||
import { newBounds } from './bounds.js';
|
||||
import { newPoint } from './point.js';
|
||||
import { newPoint, pointFromClipper } from './point.js';
|
||||
import { polygons } from './polygons.js';
|
||||
import { earcut } from '../geo/base.js';
|
||||
|
||||
|
|
@ -2044,7 +2043,7 @@ export class Polygon {
|
|||
return res.map(array => {
|
||||
let poly = newPolygon();
|
||||
for (let pt of array) {
|
||||
poly.push(base.pointFromClipper(pt, z));
|
||||
poly.push(pointFromClipper(pt, z));
|
||||
}
|
||||
return poly;
|
||||
});
|
||||
|
|
@ -2374,7 +2373,7 @@ export function fromClipperPath(path, z) {
|
|||
l = path.length;
|
||||
while (i < l) {
|
||||
// poly.push(newPoint(null,null,z,null,path[i++]));
|
||||
poly.push(base.pointFromClipper(path[i++], z));
|
||||
poly.push(pointFromClipper(path[i++], z));
|
||||
}
|
||||
return poly;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
import { base, util, paths, config } from './base.js';
|
||||
import { newPoint, pointFromClipper } from './point.js';
|
||||
import { newPolygon } from './polygon.js';
|
||||
import { newSlope } from './slope.js';
|
||||
import { ClipperLib } from '../ext/clip2.esm.js';
|
||||
|
||||
const { sqr, numOrDefault } = util;
|
||||
|
|
@ -598,7 +599,7 @@ export function offset(polys, dist, opts = {}) {
|
|||
let open = opts.open ? polys.filter(p => p.open) : [];
|
||||
if (open.length) {
|
||||
open = open.map(p => paths.pointsToPath(p.points, dist, true));
|
||||
open = open.map(p => base.newPolygon().setOpen().addPoints(p.right));
|
||||
open = open.map(p => newPolygon().setOpen().addPoints(p.right));
|
||||
}
|
||||
|
||||
// do not use clipper to offset open lines
|
||||
|
|
@ -763,7 +764,7 @@ export function fillArea(polys, angle, spacing, output, minLen, maxLen) {
|
|||
while (angle > 90) angle -= 180;
|
||||
|
||||
// X,Y ray slope derived from angle
|
||||
raySlope = base.newSlope(0,0,
|
||||
raySlope = newSlope(0,0,
|
||||
Math.cos(angle * DEG2RAD) * spacing,
|
||||
Math.sin(angle * DEG2RAD) * spacing
|
||||
);
|
||||
|
|
@ -835,8 +836,8 @@ export function fillArea(polys, angle, spacing, output, minLen, maxLen) {
|
|||
if (minlen && plen < minlen) continue;
|
||||
if (maxlen && plen > maxlen) continue;
|
||||
}
|
||||
let p1 = base.pointFromClipper(poly.m_polygon[0], zpos);
|
||||
let p2 = base.pointFromClipper(poly.m_polygon[1], zpos);
|
||||
let p1 = pointFromClipper(poly.m_polygon[0], zpos);
|
||||
let p2 = pointFromClipper(poly.m_polygon[1], zpos);
|
||||
let od = rayint.origin.distToLineNew(p1,p2) / spacing;
|
||||
lines.push([p1, p2, od]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue