Cut-Ready Stained Glass SVGs with Browser JavaScript

Zusammenfassung

Pixel shares an article on building cut-ready stained glass SVGs with a zero-dependency browser JavaScript geometry module. It explains how shared half-edges prevent shredded vinyl, copper foil kerf offsets keep panels frame-sized, and concave fracture checks help avoid glass breakage.

DEV Community

Generating Cut-Ready Stained Glass SVGs in Pure Browser JS: Shared Half-Edges, Copper Foil Kerf Offsets & Concave Fracture Checks

Feed a segmented image into a standard raster-to-SVG tracer (potrace, imagetracerjs, or Illustrator Image Trace), send that SVG to a Cricut Maker to cut adhesive vinyl stencils for stained glass, and three physical bugs show up at the workbench within twenty minutes: Shredded vinyl bridges: Every interior line between two glass pieces gets sliced twice by the plotter blade, peeling narrow 1 mm stencil tracks right off the backing sheet. Panels that outgrow their wood frames: Cut 14 glass pieces across an 18" window panel from zero-gap polygons, wrap each edge in 7/32" copper foil tape, tin the seams with 60/40 solder, and your finished glass panel ends up nearly 1/2" wider than the oak frame you milled for it. Impossible inside corners: Vector tracers happily output 250° L-notches and crescent pockets that look fine on a monitor, then snap straight across the waist the second you squeeze running pliers on 3 mm cathedral glass. While building the client-side vector engine behind Stained Glass Pattern Generator, I pulled the core geometry algorithms into a standalone, zero-dependency ES module: stained-glass-svg-math (with an interactive field verifier on GitHub Pages). Here is how each physical constraint translates into clean browser JavaScript. Bug 1: Double-Stroked Polygon Edges Shred Cricut Stencils When you segment a photo into integer region IDs (via superpixels, K-means palette clustering, or Voronoi cells, like we do in our photo to stained glass pattern converter), the naive way to build an SVG is to walk the contour of Region 1, emit a , walk Region 2, and emit another . Along every shared interior seam, Region 1 emits directed edge (u -> v) and Region 2 emits the opposite twin (v -> u). On screen, two overlapping 1px strokes look like a single black line. On a vinyl cutter or CO2 laser, the toolhead physically traverses that seam twice. The fix is topological half-edge deduplication over the 2D label grid before any path simplification happens: Emit directed unit boundary half-edges around every grid cell (r, c) wherever a neighbor has a different region ID (using null for outside the canvas). Collapse opposite half-edges (u -> v) and (v -> u) onto a canonical undirected edge key min(u, v) | max(u, v). Count vertex degrees in the deduplicated undirected graph. Any vertex with degree >= 3 is a topological solder junction (a 3-way T-joint or 4-way X-joint). Trace maximal open chains between junctions, locking junction coordinates before running collinear or Ramer-Douglas-Peucker simplification so adjacent pieces never tear open into T-cracks. export function extractCanonicalUnitEdges(grid) {
const rows = grid.length;
const cols = grid[0].length;
const unitEdges = new Map();
let directedHalfEdgeCount = 0;

const addHalfEdge = (sx, sy, ex, ey, region, neighbor) => {
directedHalfEdgeCount++;
const forward = sx < ex || (sx === ex && sy < ey);
const key = forward
? ${sx},${sy}|${ex},${ey}
: ${ex},${ey}|${sx},${sy};

if (!unitEdges.has(key)) {
  unitEdges.set(key, {
    ax: forward ? sx : ex,
    ay: forward ? sy : ey,
    bx: forward ? ex : sx,
    by: forward ? ey : sy,
    isInteriorSeam: neighbor !== null,
    regions: neighbor === null ? [region] : [region, neighbor],
  });
}

};

for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
const id = grid[r][c];
if (r === 0 || grid[r - 1][c] !== id)
addHalfEdge(c, r, c + 1, r, id, r > 0 ? grid[r - 1][c] : null);
if (c + 1 === cols || grid[r][c + 1] !== id)
addHalfEdge(c + 1, r, c + 1, r + 1, id, c + 1 < cols ? grid[r][c + 1] : null);
if (r + 1 === rows || grid[r + 1][c] !== id)
addHalfEdge(c + 1, r + 1, c, r + 1, id, r + 1 < rows ? grid[r + 1][c] : null);
if (c === 0 || grid[r][c - 1] !== id)
addHalfEdge(c, r + 1, c, r, id, c > 0 ? grid[r][c - 1] : null);
}
}

return {
directedHalfEdgeC...
Cut-Ready Stained Glass SVGs with Browser JavaScript
Powered by Readybot.io

Das Neueste von Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …