Decompose SVG or DXF paths into individual <line> and <path> segments.
- Input formats: SVG or DXF
- Output format: Always SVG with individual elements
- Path decomposition: Converts complex paths into individual
<line>and<path>segments - Duplicate removal: Automatically removes duplicate line segments (including reversed duplicates)
- Geometric support: Handles lines, arcs, cubic Bézier curves, and quadratic Bézier curves
- DXF features: Supports LINE, ARC, and LWPOLYLINE entities with proper viewBox calculation
- Cutting machine friendly: Perfect for Cricut Design Space or Silhouette Studio
This project uses a Python virtual environment managed with direnv and make.
-
Copy the
direnvconfiguration file:cp .envrc.dist .envrc
-
Allow
direnvto create the virtual environment:direnv allow
This will create a virtual environment inside a
.direnvdirectory. -
Install the runtime dependencies:
make install
For development work including testing and code quality tools:
# Install development dependencies
pip install -r requirements-dev.txt
# Install pre-commit hooks (optional)
pre-commit installDevelopment tools included:
pytestwith coverage reportingblackfor code formattingflake8for lintingmypyfor type checkingpre-commitfor git hooks
Once the environment is set up, you can run the script directly. The virtual environment will be automatically activated if you are using direnv.
./decompose-vector.py input.svg output.svg./decompose-vector.py input.dxf output.svg./decompose-vector.py samples/Hexagon_box.dxf test_output.svg# Run all tests with coverage
pytest --cov=. --cov-report=term-missing
# Run specific test file
pytest tests/test_svg_processing.py -v
# Run tests with verbose output
pytest -v# Format code
black .
# Lint code
flake8 .
# Type check
mypy .
# Run pre-commit hooks manually
pre-commit run --all-files# Install dependencies
make install
# Clean virtual environment
make clean
# Show available targets
make helpThis is a single-file application with the following key components:
decompose-vector.py: Main application scriptdecompose_svg(): Handles SVG input processingdecompose_dxf(): Handles DXF input processing- Utility functions: Point normalization, duplicate detection, geometric calculations
- Line segments
- Arc segments
- Cubic Bézier curves
- Quadratic Bézier curves
- Complex path decomposition
- LINE entities
- ARC entities
- LWPOLYLINE entities (exploded into individual segments)
- Automatic viewBox calculation based on modelspace extents
- DXF unit preservation in SVG output
- Each decomposed segment gets a unique ID
- All elements use black stroke with no fill
- XML output is properly formatted
- Duplicate line segments are automatically removed