From 5670ae79bf4bc8ef683a197afc41474d8244d89c Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Tue, 17 Mar 2026 07:57:54 -0400 Subject: [PATCH] feat(core): add ShapeDefinition base class Co-Authored-By: Claude Opus 4.6 (1M context) --- OpenNest.Core/Shapes/ShapeDefinition.cs | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 OpenNest.Core/Shapes/ShapeDefinition.cs diff --git a/OpenNest.Core/Shapes/ShapeDefinition.cs b/OpenNest.Core/Shapes/ShapeDefinition.cs new file mode 100644 index 0000000..2e57f1e --- /dev/null +++ b/OpenNest.Core/Shapes/ShapeDefinition.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using OpenNest.Converters; +using OpenNest.Geometry; + +namespace OpenNest.Shapes +{ + public abstract class ShapeDefinition + { + public string Name { get; set; } + + protected ShapeDefinition() + { + var typeName = GetType().Name; + Name = typeName.EndsWith("Shape") + ? typeName.Substring(0, typeName.Length - 5) + : typeName; + } + + public abstract Drawing GetDrawing(); + + protected Drawing CreateDrawing(List entities) + { + var pgm = ConvertGeometry.ToProgram(entities); + + if (pgm == null) + throw new InvalidOperationException( + $"Failed to create program for shape '{Name}'. Check that parameters produce valid geometry."); + + return new Drawing(Name, pgm); + } + } +}