tsdraft 0.2.0 → 0.2.1

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/svg.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { sweep } from "./drawing.js";
2
2
  import { extents } from "./extents.js";
3
3
  import { fmt } from "./format.js";
4
+ import { layerKey } from "./layers.js";
4
5
  /** Screen colors for the standard ACI colors 1 to 7. Other indexes draw in currentColor. */
5
6
  const ACI = {
6
7
  1: "#ff0000",
@@ -19,10 +20,11 @@ export function toSVG(drawing, options = {}) {
19
20
  const y = -(maxY + margin);
20
21
  const w = maxX - minX + margin * 2;
21
22
  const h = maxY - minY + margin * 2;
22
- const colors = new Map(drawing.layers.map((l) => [l.name, ACI[l.color] ?? "currentColor"]));
23
+ // Keyed as AutoCAD looks layers up, so an entity on `wall` takes the color of layer `WALL`.
24
+ const colors = new Map(drawing.layers.map((l) => [layerKey(l.name), ACI[l.color] ?? "currentColor"]));
23
25
  const stroke = options.strokeWidth ?? 1;
24
26
  const body = drawing.entities
25
- .map((e) => entityToSvg(e, colors.get(e.layer) ?? "currentColor"))
27
+ .map((e) => entityToSvg(e, colors.get(layerKey(e.layer)) ?? "currentColor"))
26
28
  .join("\n ");
27
29
  return [
28
30
  `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${fmt(x)} ${fmt(y)} ${fmt(w)} ${fmt(h)}">`,
@@ -52,6 +54,11 @@ function entityToSvg(e, color) {
52
54
  const large = sweep(e.startAngle, e.endAngle) > 180 ? 1 : 0;
53
55
  const start = `${fmt(cx + e.radius * Math.cos(a0))} ${fmt(cy + e.radius * Math.sin(a0))}`;
54
56
  const end = `${fmt(cx + e.radius * Math.cos(a1))} ${fmt(cy + e.radius * Math.sin(a1))}`;
57
+ // SVG draws nothing for an arc that ends where it starts, which is where rounding can
58
+ // put the ends of an arc that is all but a full turn.
59
+ if (start === end && large === 1) {
60
+ return `<circle cx="${fmt(cx)}" cy="${fmt(cy)}" r="${fmt(e.radius)}" ${s}/>`;
61
+ }
55
62
  // sweep-flag 1 is the positive-angle direction in local (Y-up) coordinates: counterclockwise.
56
63
  return `<path d="M ${start} A ${fmt(e.radius)} ${fmt(e.radius)} 0 ${large} 1 ${end}" ${s}/>`;
57
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdraft",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "2D CAD drawings as TypeScript: write the drawing in code, export DXF and SVG.",
5
5
  "keywords": [
6
6
  "2d",