geometrix 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -300,15 +300,17 @@ declare abstract class AContour {
300
300
  abstract draw(ctx: CanvasRenderingContext2D, cAdjust: tCanvasAdjust, color: string): void;
301
301
  abstract extractSkeleton(): AContour;
302
302
  abstract generateContour(): AContour;
303
- abstract generatePoints(): Point[];
303
+ abstract generatePoints(dnb: number): Point[];
304
+ abstract getEnvelop(): [number, number, number, number, boolean];
304
305
  abstract generateLines(): Line[];
305
306
  abstract check(): string;
306
307
  abstract toSvg(yCeiling: number, color?: string): string;
307
308
  abstract toDxfSeg(): DxfSeg[];
308
309
  abstract toPax(): tPaxContour;
309
310
  abstract getPerimeter(): number;
311
+ abstract generateRevertOrientation(): AContour;
310
312
  }
311
- declare function midArcPoint(px1: number, py1: number, seg: Segment1): Point;
313
+ declare function midArcPoint(px1: number, py1: number, seg: Segment1, dnb: number): Point[];
312
314
  /**
313
315
  * class `Contour`
314
316
  *
@@ -365,7 +367,9 @@ declare class Contour extends AContour {
365
367
  draw(ctx: CanvasRenderingContext2D, cAdjust: tCanvasAdjust, color?: string): void;
366
368
  extractSkeleton(): Contour;
367
369
  generateContour(): Contour;
368
- generatePoints(): Point[];
370
+ generatePoints(dnb: number): Point[];
371
+ getOrientation(iPts: Point[], extremX: number): boolean;
372
+ getEnvelop(): [number, number, number, number, boolean];
369
373
  generateLines(): Line[];
370
374
  /** @internal */
371
375
  checkContour(ctr: Contour): void;
@@ -374,6 +378,7 @@ declare class Contour extends AContour {
374
378
  toDxfSeg(): DxfSeg[];
375
379
  toPax(): tPaxContourPath;
376
380
  getPerimeter(): number;
381
+ generateRevertOrientation(): AContour;
377
382
  }
378
383
  /**
379
384
  * class `ContourCircle`
@@ -394,13 +399,15 @@ declare class ContourCircle extends AContour {
394
399
  draw(ctx: CanvasRenderingContext2D, cAdjust: tCanvasAdjust, color?: string): void;
395
400
  extractSkeleton(): ContourCircle;
396
401
  generateContour(): ContourCircle;
397
- generatePoints(): Point[];
402
+ generatePoints(dnb: number): Point[];
403
+ getEnvelop(): [number, number, number, number, boolean];
398
404
  generateLines(): Line[];
399
405
  check(): string;
400
406
  toSvg(yCeiling: number, color?: string): string;
401
407
  toDxfSeg(): DxfSeg[];
402
408
  toPax(): tPaxContourCircle;
403
409
  getPerimeter(): number;
410
+ generateRevertOrientation(): AContour;
404
411
  }
405
412
  declare function contour(ix: number, iy: number, icolor?: string): Contour;
406
413
  declare function contourCircle(ix: number, iy: number, iRadius: number, icolor?: string): ContourCircle;
package/dist/index.js CHANGED
@@ -1704,16 +1704,17 @@ function paxPath() {
1704
1704
  // src/contour.ts
1705
1705
  var AContour = class {
1706
1706
  };
1707
- function midArcPoint(px1, py1, seg) {
1707
+ function midArcPoint(px1, py1, seg, dnb) {
1708
1708
  const seg2 = arcSeg1To2(px1, py1, seg);
1709
1709
  const p3 = point(seg2.pc.cx, seg2.pc.cy);
1710
- const a12h = withinPiPi((seg2.a2 - seg2.a1) / 2);
1711
- let a3 = seg2.a1 + a12h;
1712
- if (Math.sign(a12h) > 0 && !seg.arcCcw || Math.sign(a12h) < 0 && seg.arcCcw) {
1713
- a3 += Math.PI;
1710
+ const a12h = withinZero2Pi(seg2.a2 - seg2.a1);
1711
+ const a12g = seg.arcCcw ? a12h : a12h - 2 * Math.PI;
1712
+ const a12f = a12g / dnb;
1713
+ const rPts = [];
1714
+ for (let idx = 1; idx < dnb; idx++) {
1715
+ rPts.push(p3.translatePolar(seg2.a1 + idx * a12f, seg.radius));
1714
1716
  }
1715
- const p4 = p3.translatePolar(a3, seg.radius);
1716
- return p4;
1717
+ return rPts;
1717
1718
  }
1718
1719
  var Contour = class _Contour extends AContour {
1719
1720
  /** @internal */
@@ -2245,18 +2246,15 @@ var Contour = class _Contour extends AContour {
2245
2246
  }
2246
2247
  return rContour;
2247
2248
  }
2248
- generatePoints() {
2249
+ generatePoints(dnb) {
2249
2250
  const rPoints = [];
2250
- rPoints.push(...this.debugPoints);
2251
- const seg0 = this.segments[0];
2252
- rPoints.push(point(seg0.px, seg0.py));
2253
2251
  let px1 = 0;
2254
2252
  let py1 = 0;
2255
2253
  for (const seg of this.segments) {
2256
2254
  if (seg.sType === 1 /* eArc */) {
2257
2255
  try {
2258
- const p4 = midArcPoint(px1, py1, seg);
2259
- rPoints.push(p4);
2256
+ const pts = midArcPoint(px1, py1, seg, dnb);
2257
+ rPoints.push(...pts);
2260
2258
  } catch (emsg) {
2261
2259
  console.log("err453: " + emsg);
2262
2260
  }
@@ -2269,6 +2267,50 @@ var Contour = class _Contour extends AContour {
2269
2267
  }
2270
2268
  return rPoints;
2271
2269
  }
2270
+ getOrientation(iPts, extremX) {
2271
+ const pts = iPts.slice(1);
2272
+ let sign = 0;
2273
+ let pt1 = pts.at(-3);
2274
+ let pt2 = pts.at(-2);
2275
+ let pt3 = pts.at(-1);
2276
+ for (const pt of pts) {
2277
+ pt1 = pt2;
2278
+ pt2 = pt3;
2279
+ pt3 = pt;
2280
+ if (pt2.cx === extremX) {
2281
+ const vx = pt1.cx - pt2.cx;
2282
+ const vy = pt1.cy - pt2.cy;
2283
+ const ux = pt3.cx - pt2.cx;
2284
+ const uy = pt3.cy - pt2.cy;
2285
+ const pv = ux * vy - uy * vx;
2286
+ sign = Math.sign(pv);
2287
+ }
2288
+ }
2289
+ if (0 === sign) {
2290
+ throw `err299: Orientation hasn't been found with point number ${pts.length}`;
2291
+ }
2292
+ const rOrientation = sign > 0 ? true : false;
2293
+ return rOrientation;
2294
+ }
2295
+ getEnvelop() {
2296
+ const pts = this.generatePoints(24);
2297
+ const lx = [];
2298
+ const ly = [];
2299
+ for (const pt of pts) {
2300
+ lx.push(pt.cx);
2301
+ ly.push(pt.cy);
2302
+ }
2303
+ const rXmin = Math.min(...lx);
2304
+ const rXmax = Math.max(...lx);
2305
+ const rYmin = Math.min(...ly);
2306
+ const rYmax = Math.max(...ly);
2307
+ const rOrientation = this.getOrientation(pts, rXmin);
2308
+ const orient2 = this.getOrientation(pts, rXmax);
2309
+ if (orient2 !== rOrientation) {
2310
+ throw `err390: orientation unstable ${rOrientation} ${orient2} with ${pts.length} points`;
2311
+ }
2312
+ return [rXmin, rXmax, rYmin, rYmax, rOrientation];
2313
+ }
2272
2314
  generateLines() {
2273
2315
  const rLines = [];
2274
2316
  rLines.push(...this.debugLines);
@@ -2391,6 +2433,16 @@ var Contour = class _Contour extends AContour {
2391
2433
  }
2392
2434
  return rPerimeter;
2393
2435
  }
2436
+ generateRevertOrientation() {
2437
+ const seg0 = this.segments[0];
2438
+ const rContour = new _Contour(seg0.px, seg0.py);
2439
+ for (const seg of this.segments) {
2440
+ if (isSeg(seg.sType)) {
2441
+ rContour.addSeg(seg);
2442
+ }
2443
+ }
2444
+ return rContour;
2445
+ }
2394
2446
  };
2395
2447
  var ContourCircle = class _ContourCircle extends AContour {
2396
2448
  circle = true;
@@ -2443,16 +2495,26 @@ var ContourCircle = class _ContourCircle extends AContour {
2443
2495
  const rContour = new _ContourCircle(this.px, this.py, this.radius, this.imposedColor);
2444
2496
  return rContour;
2445
2497
  }
2446
- generatePoints() {
2498
+ generatePoints(dnb) {
2447
2499
  const rPoints = [];
2448
2500
  const p1 = point(this.px, this.py);
2501
+ const kp = dnb * 2;
2449
2502
  rPoints.push(p1);
2450
- for (let i = 0; i < 4; i++) {
2451
- const p2 = p1.translatePolar(i * Math.PI / 2, this.radius);
2503
+ for (let i = 0; i < kp; i++) {
2504
+ const p2 = p1.translatePolar(i * 2 * Math.PI / kp, this.radius);
2452
2505
  rPoints.push(p2);
2453
2506
  }
2454
2507
  return rPoints;
2455
2508
  }
2509
+ getEnvelop() {
2510
+ return [
2511
+ this.px - this.radius,
2512
+ this.px + this.radius,
2513
+ this.py - this.radius,
2514
+ this.py + this.radius,
2515
+ true
2516
+ ];
2517
+ }
2456
2518
  generateLines() {
2457
2519
  return [];
2458
2520
  }
@@ -2476,6 +2538,10 @@ var ContourCircle = class _ContourCircle extends AContour {
2476
2538
  const rPerimeter = 2 * Math.PI * this.radius;
2477
2539
  return rPerimeter;
2478
2540
  }
2541
+ generateRevertOrientation() {
2542
+ const rContour = new _ContourCircle(this.px, this.py, this.radius, this.imposedColor);
2543
+ return rContour;
2544
+ }
2479
2545
  };
2480
2546
  function contour(ix, iy, icolor = "") {
2481
2547
  return new Contour(ix, iy, icolor);
@@ -2537,7 +2603,7 @@ var Figure = class _Figure {
2537
2603
  const oneFace = [];
2538
2604
  for (const oneCtr of iFace) {
2539
2605
  const roundedContour = oneCtr.generateContour();
2540
- this.addPoints(roundedContour.generatePoints());
2606
+ this.addPoints(roundedContour.generatePoints(2));
2541
2607
  this.addLines(roundedContour.generateLines());
2542
2608
  oneFace.push(roundedContour);
2543
2609
  this.mainBList.push(oneCtr.extractSkeleton());
@@ -2554,13 +2620,13 @@ var Figure = class _Figure {
2554
2620
  }
2555
2621
  addSecond(icontour) {
2556
2622
  const roundedContour = icontour.generateContour();
2557
- this.addPoints(roundedContour.generatePoints());
2623
+ this.addPoints(roundedContour.generatePoints(2));
2558
2624
  this.addLines(roundedContour.generateLines());
2559
2625
  this.secondList.push(roundedContour);
2560
2626
  this.secondBList.push(icontour.extractSkeleton());
2561
2627
  }
2562
2628
  addDynamics(icontour) {
2563
- this.addPoints(icontour.generatePoints());
2629
+ this.addPoints(icontour.generatePoints(2));
2564
2630
  this.addLines(icontour.generateLines());
2565
2631
  this.dynamicsList.push(icontour);
2566
2632
  }
@@ -3786,7 +3852,7 @@ function fcFaceContour(paxCtr, outName) {
3786
3852
  } else if (seg.typ === 2 /* eArc */) {
3787
3853
  try {
3788
3854
  const seg1 = convPaxToSeg1(seg);
3789
- const p4 = midArcPoint(px1, py1, seg1);
3855
+ const p4 = midArcPoint(px1, py1, seg1, 2)[0];
3790
3856
  rStr += ` P${fid3(pIdx)} = App.Vector(${ff6(p4.cx)}, ${ff6(p4.cy)}, 0)
3791
3857
  `;
3792
3858
  pIdx += 1;
@@ -4089,7 +4155,7 @@ var MinMaxPoint = class {
4089
4155
  pts.push(point(this.xMax, this.yMax));
4090
4156
  }
4091
4157
  for (const ctr of aCtr) {
4092
- pts.push(...ctr.generatePoints());
4158
+ pts.push(...ctr.generatePoints(2));
4093
4159
  }
4094
4160
  const [Xmin, Xmax, Ymin, Ymax] = pointMinMax(pts);
4095
4161
  this.xMin = Xmin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geometrix",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "The 2D geometry engine of the parametrix",
5
5
  "private": false,
6
6
  "repository": {
@@ -69,15 +69,15 @@
69
69
  "devDependencies": {
70
70
  "@eslint/js": "^9.10.0",
71
71
  "@types/eslint__js": "^8.42.3",
72
- "@types/node": "^22.13.1",
73
- "eslint": "^9.20.0",
72
+ "@types/node": "^22.13.4",
73
+ "eslint": "^9.20.1",
74
74
  "eslint-config-prettier": "^10.0.1",
75
75
  "npm-run-all2": "^7.0.2",
76
- "prettier": "^3.5.0",
76
+ "prettier": "^3.5.1",
77
77
  "rimraf": "^6.0.1",
78
78
  "tsup": "^8.3.6",
79
79
  "typescript": "^5.7.3",
80
- "typescript-eslint": "^8.23.0",
81
- "vitest": "^3.0.5"
80
+ "typescript-eslint": "^8.24.1",
81
+ "vitest": "^3.0.6"
82
82
  }
83
83
  }