package main
import (
"fmt"
"math"
"os"
)
func WriteSVG(filename string, gf *GerberFile, bounds *Bounds) error {
b := *bounds
widthMM := b.MaxX - b.MinX
heightMM := b.MaxY - b.MinY
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
// Use mm directly for SVG
fmt.Fprintf(f, `\n")
return nil
}
func writeSVGAperture(f *os.File, cx, cy float64, ap Aperture, isMacro bool) {
switch ap.Type {
case "C":
if len(ap.Modifiers) > 0 {
r := ap.Modifiers[0] / 2
fmt.Fprintf(f, ``+"\n", cx, cy, r)
}
case "R":
if len(ap.Modifiers) >= 2 {
w, h := ap.Modifiers[0], ap.Modifiers[1]
fmt.Fprintf(f, ``+"\n", cx-w/2, cy-h/2, w, h)
}
case "O":
if len(ap.Modifiers) >= 2 {
w, h := ap.Modifiers[0], ap.Modifiers[1]
r := w / 2
if h < w {
r = h / 2
}
fmt.Fprintf(f, ``+"\n", cx-w/2, cy-h/2, w, h, r, r)
}
case "P":
if len(ap.Modifiers) >= 2 {
dia, numV := ap.Modifiers[0], int(ap.Modifiers[1])
r := dia / 2
rot := 0.0
if len(ap.Modifiers) >= 3 {
rot = ap.Modifiers[2]
}
fmt.Fprintf(f, ``+"\n")
}
}
}