Skip to content

Commit

Permalink
Merge pull request #65 from tscircuit/fix-fab-note-closing
Browse files Browse the repository at this point in the history
fix fab note path closing
  • Loading branch information
seveibar authored Sep 11, 2024
2 parents f23b69b + 1aeeae7 commit 69712ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ export function createSvgObjectsFromPcbFabricationNotePath(
): SvgObject[] {
if (!fabNotePath.route || !Array.isArray(fabNotePath.route)) return []

let path = fabNotePath.route
.map((point: any, index: number) => {
const [x, y] = applyToPoint(transform, [point.x, point.y])
return index === 0 ? `M ${x} ${y}` : `L ${x} ${y}`
})
.join(" ")

// Close the path if it's not already closed
// Close the path if the first and last points are the same
const firstPoint = fabNotePath.route[0]
const lastPoint = fabNotePath.route[fabNotePath.route.length - 1]
if (firstPoint!.x !== lastPoint!.x || firstPoint!.y !== lastPoint!.y) {
path += " Z"
}
const isClosed =
firstPoint!.x === lastPoint!.x && firstPoint!.y === lastPoint!.y

const path =
fabNotePath.route
.slice(0, isClosed ? -1 : undefined)
.map((point: any, index: number) => {
const [x, y] = applyToPoint(transform, [point.x, point.y])
return index === 0 ? `M ${x} ${y}` : `L ${x} ${y}`
})
.join(" ") + (isClosed ? " Z" : "")

return [
{
name: "path",
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/fabnotes.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 69712ef

Please sign in to comment.