Skip to content

Commit

Permalink
Merge pull request #68 from tscircuit/feat/size-of-svg
Browse files Browse the repository at this point in the history
feat: size of svg
  • Loading branch information
imrishabh18 authored Sep 13, 2024
2 parents d7c956b + e664b6f commit 3e95e57
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/lib/circuit-to-pcb-svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
} from "transformation-matrix"
import { createSvgObjectsFromPcbFabricationNotePath } from "./svg-object-fns/create-svg-objects-from-pcb-fabrication-note-path"
import { createSvgObjectsFromPcbFabricationNoteText } from "./svg-object-fns/create-svg-objects-from-pcb-fabrication-note-text"
import { createSvgObjectsFromPcbHole } from "./svg-object-fns/create-svg-objects-from-pcb-plated-hole"
import { createSvgObjectsFromPcbSilkscreenPath } from "./svg-object-fns/create-svg-objects-from-pcb-silkscreen-path"
import { createSvgObjectsFromPcbSilkscreenText } from "./svg-object-fns/create-svg-objects-from-pcb-silkscreen-text"
import { createSvgObjectsFromPcbTrace } from "./svg-object-fns/create-svg-objects-from-pcb-trace"
import { createSvgObjectsFromSmtPad } from "./svg-object-fns/create-svg-objects-from-smt-pads"
import { createSvgObjectsFromPcbHole } from "./svg-object-fns/create-svg-objects-from-pcb-plated-hole"

const OBJECT_ORDER: AnySoupElement["type"][] = [
"pcb_plated_hole",
Expand All @@ -31,7 +31,15 @@ interface PointObjectNotation {
y: number
}

function circuitJsonToPcbSvg(soup: AnySoupElement[]): string {
interface Options {
width?: number
height?: number
}

function circuitJsonToPcbSvg(
soup: AnySoupElement[],
options?: Options,
): string {
let minX = Number.POSITIVE_INFINITY
let minY = Number.POSITIVE_INFINITY
let maxX = Number.NEGATIVE_INFINITY
Expand All @@ -52,8 +60,8 @@ function circuitJsonToPcbSvg(soup: AnySoupElement[]): string {
const circuitWidth = maxX - minX + 2 * padding
const circuitHeight = maxY - minY + 2 * padding

const svgWidth = 800
const svgHeight = 600
const svgWidth = options?.width ?? 800
const svgHeight = options?.height ?? 600
const paths: PointObjectNotation[][] = []
for (const item of soup) {
if ("route" in item && item.route !== undefined) {
Expand Down

0 comments on commit 3e95e57

Please sign in to comment.