Generate clean SVG paths for laser cutting from C# shapes with edge overlap removal
$ dotnet add package SharpCutSvgSharpCut is a modern, precise C# library for generating and manipulating 2D vector shapes for laser cutting, CNC, and more. It supports compound shapes, edge merging, geometric utilities, and clean SVG export.
using SharpCut;
using SharpCut.Models;
// Define a simple rectangle
Rectangle rectangle = new Rectangle(0, 0, 100, 50);
// Create document, add the shape, resize and export
SvgDocument svg = new SvgDocument();
svg.Add(rectangle, copy: true);
svg.ResizeToFitContent(margin: 5, offsetContent: true);
string content = svg.Export();
using SharpCut;
using SharpCut.Models;
using SharpCut.Builders;
// Base panel
Rectangle panelBase = new Rectangle(x: 5, y: 5, width: 160, height: 50);
// Small vertical finger joint shape
Rectangle cut = new Rectangle(width: 3, height: 25);
// Distribute tabs evenly along the bottom of the base panel
List<Rectangle> placedCuts = cut.PlaceCopiesOnPoints(
points: panelBase.GetEdge(Side.Bottom).GetDistributedPoints(2),
origin: Origin.BottomCenter
);
// Build compound shape and clean overlapping edges
CompoundShape compoundShape = new CompoundShape(panelBase, placedCuts);
// Export to SVG
SvgDocument svg = new SvgDocument(strokeWidth: 0.1f, unit: "mm");
svg.Add(compoundShape, copy: true);
svg.ResizeToFitContent(margin: 5, offsetContent: true);
string exportedSvg = svg.Export();
SharpCut.Models – geometry: Point, Edge, Rectangle, Shape, CompoundShape, Origin, SideSharpCut.Builders – logic: ShapeBuilder for deduplicating edgesSharpCut – output: SvgDocument for exporting shapes as SVGSharpCut uses MSTest with comprehensive coverage:
EdgeTestsPointTestsRectangleTestsShapeTestsShapeBuilderTestsSvgDocumentTestsRun tests via:
dotnet test
MIT License (You can do whatever you want with the code, please feel free to contribute if you have any improvement suggestions)