{
  "version": 3,
  "sources": ["../../src/util/createArcForLWPolyline.ts"],
  "sourcesContent": ["import { V2 } from 'vecks'\n\ntype Point = [number, number]\n\n/**\n * Create the arcs point for a LWPOLYLINE. The start and end are excluded\n *\n * See diagram.png in this directory for description of points and angles used.\n */\nexport default function createArcForLWPolyline(\n  from: Point,\n  to: Point,\n  bulge: number,\n  resolution?: number\n): Point[] {\n  // Resolution in degrees\n  if (!resolution) {\n    resolution = 5\n  }\n\n  // If the bulge is < 0, the arc goes clockwise. So we simply\n  // reverse a and b and invert sign\n  // Bulge = tan(theta/4)\n  let theta: number\n  let a: V2\n  let b: V2\n\n  if (bulge < 0) {\n    theta = Math.atan(-bulge) * 4\n    a = new V2(from[0], from[1])\n    b = new V2(to[0], to[1])\n  } else {\n    // Default is counter-clockwise\n    theta = Math.atan(bulge) * 4\n    a = new V2(to[0], to[1])\n    b = new V2(from[0], from[1])\n  }\n\n  const ab = b.sub(a)\n  const lengthAB = ab.length()\n  const c = a.add(ab.multiply(0.5))\n\n  // Distance from center of arc to line between form and to points\n  const lengthCD = Math.abs(lengthAB / 2 / Math.tan(theta / 2))\n  const normAB = ab.norm()\n\n  let d: V2\n  if (theta < Math.PI) {\n    const normDC = new V2(\n      normAB.x * Math.cos(Math.PI / 2) - normAB.y * Math.sin(Math.PI / 2),\n      normAB.y * Math.cos(Math.PI / 2) + normAB.x * Math.sin(Math.PI / 2),\n    )\n    // D is the center of the arc\n    d = c.add(normDC.multiply(-lengthCD))\n  } else {\n    const normCD = new V2(\n      normAB.x * Math.cos(Math.PI / 2) - normAB.y * Math.sin(Math.PI / 2),\n      normAB.y * Math.cos(Math.PI / 2) + normAB.x * Math.sin(Math.PI / 2),\n    )\n    // D is the center of the arc\n    d = c.add(normCD.multiply(lengthCD))\n  }\n\n  // Add points between start start and eng angle relative\n  // to the center point\n  const startAngle = (Math.atan2(b.y - d.y, b.x - d.x) / Math.PI) * 180\n  let endAngle = (Math.atan2(a.y - d.y, a.x - d.x) / Math.PI) * 180\n  if (endAngle < startAngle) {\n    endAngle += 360\n  }\n  const r = b.sub(d).length()\n\n  const startInter =\n    Math.floor(startAngle / resolution) * resolution + resolution\n  const endInter = Math.ceil(endAngle / resolution) * resolution - resolution\n\n  const points: V2[] = []\n  for (let i = startInter; i <= endInter; i += resolution) {\n    points.push(\n      d.add(\n        new V2(\n          Math.cos((i / 180) * Math.PI) * r,\n          Math.sin((i / 180) * Math.PI) * r,\n        ),\n      ),\n    )\n  }\n  // Maintain the right ordering to join the from and to points\n  if (bulge < 0) {\n    points.reverse()\n  }\n  return points.map((p): Point => [p.x, p.y])\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmB;AASJ,SAAR,uBACL,MACA,IACA,OACA,YACS;AAET,MAAI,CAAC,YAAY;AACf,iBAAa;AAAA,EACf;AAKA,MAAI;AACJ,MAAI;AACJ,MAAI;AAEJ,MAAI,QAAQ,GAAG;AACb,YAAQ,KAAK,KAAK,CAAC,KAAK,IAAI;AAC5B,QAAI,IAAI,gBAAG,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AAC3B,QAAI,IAAI,gBAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;AAAA,EACzB,OAAO;AAEL,YAAQ,KAAK,KAAK,KAAK,IAAI;AAC3B,QAAI,IAAI,gBAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;AACvB,QAAI,IAAI,gBAAG,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AAAA,EAC7B;AAEA,QAAM,KAAK,EAAE,IAAI,CAAC;AAClB,QAAM,WAAW,GAAG,OAAO;AAC3B,QAAM,IAAI,EAAE,IAAI,GAAG,SAAS,GAAG,CAAC;AAGhC,QAAM,WAAW,KAAK,IAAI,WAAW,IAAI,KAAK,IAAI,QAAQ,CAAC,CAAC;AAC5D,QAAM,SAAS,GAAG,KAAK;AAEvB,MAAI;AACJ,MAAI,QAAQ,KAAK,I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