Skip to content

Commit

Permalink
Merge pull request #71 from tscircuit/arc-imports
Browse files Browse the repository at this point in the history
Fix Arc Imports
  • Loading branch information
seveibar authored Oct 16, 2024
2 parents 39bb0be + aca2d8b commit f1f861f
Show file tree
Hide file tree
Showing 3 changed files with 356 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/schemas/package-detail-shape-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ export const ShapeItemSchema = z
const [width, layer, , arcData] = shape.data.split("~")
// A rx ry x-axis-rotation large-arc-flag sweep-flag x y
// A rx ry x-axis-rotation large-arc-flag sweep-flag dx dy
const match = arcData.match(
/M\s*([\d.-]+)(?:\s*,\s*|\s+)([\d.-]+)\s*A\s*([\d.-]+)(?:\s*,\s*|\s+)([\d.-]+)\s*([\d.-]+)\s*([\d.-]+)\s*([\d.-]+)\s*([\d.-]+)(?:\s*,\s*|\s+)([\d.-]+)/,
)

if (!match) {
throw new Error(`Invalid arc data: ${arcData}`)
}

const [
,
startX,
Expand All @@ -208,9 +216,7 @@ export const ShapeItemSchema = z
sweepFlag,
endX,
endY,
] = arcData.match(
/M\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)\s*A\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)\s*([\d.]+)\s*([01])\s*([01])\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)/,
)!
] = match
const start: [number, number] = [Number(startX), Number(startY)]
const end: [number, number] = [Number(endX), Number(endY)]
return ArcSchema.parse({
Expand Down
Loading

0 comments on commit f1f861f

Please sign in to comment.