Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7a38ff9
fix: resolve boundary condition bug for exact-fit parts in rectangula…
Dexus Jul 9, 2025
e202650
fix: enable rectangle NFP optimization in background worker for exact…
Dexus Jul 10, 2025
7dffd16
clean: remove debug and test files
Dexus Jul 10, 2025
da3e467
fix: handle exact-fit cases in getInnerNfp to prevent clipper precisi…
Dexus Jul 10, 2025
b67103d
fix: correct NFP positioning for exact-fit cases
Dexus Jul 10, 2025
5d982a9
fix: prevent NaN fitness values from breaking genetic algorithm
Dexus Jul 10, 2025
db2c7e5
fix: prevent NaN utilisation values
Dexus Jul 10, 2025
6001b49
fix: correct utilisation calculation to track actual placed part areas
Dexus Jul 10, 2025
dbaa784
fix: revert to correct NFP positioning calculation for exact-fit cases
Dexus Jul 10, 2025
f3d402e
fix: prevent infinite loop when there are more parts than available s…
Dexus Jul 10, 2025
0a871ed
debug: add comprehensive logging to identify where placement gets stuck
Dexus Jul 10, 2025
9c57523
debug: add timeout and performance warnings for large part counts
Dexus Jul 10, 2025
61ab451
xx
Dexus Jul 10, 2025
16afcf8
Merge branch 'fix/boundary-condition-exact-fit' of https://github.com…
Dexus Jul 10, 2025
53f667e
debug
Dexus Jul 10, 2025
2fa6dbc
debug: add parallel processing debugging and timeout handling
Dexus Jul 10, 2025
6855e6a
fix: remove unsupported .catch() method from parallel.js promise
Dexus Jul 10, 2025
44e4229
fix: add null checks for parallel processing NFP results
Dexus Jul 10, 2025
c1083b5
xx
Dexus Jul 10, 2025
955c58a
fix: restrict rectangle NFP optimization to axis-aligned rotations only
Dexus Jul 10, 2025
b94b41d
xx
Dexus Jul 10, 2025
98081df
Merge branch 'fix/boundary-condition-exact-fit' of https://github.com…
Dexus Jul 10, 2025
fda7140
xx2
Dexus Jul 10, 2025
e5aa8c8
fix: correct NFP calculation for axis-aligned rectangles
Dexus Jul 10, 2025
2416970
fix: disable rectangle optimization for any rotation
Dexus Jul 10, 2025
7edd84e
fix: use original coordinates for placement calculations to fix rotat…
Dexus Jul 10, 2025
5a74f7a
debug: disable rectangle optimization and add NFP debug output
Dexus Jul 10, 2025
7b951ea
debug: add comprehensive file logging for placement analysis
Dexus Jul 10, 2025
80c2b61
xx2
Dexus Jul 10, 2025
f3711fb
fix: disable hole analysis that was filtering out parts incorrectly
Dexus Jul 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

**deepnest** is an Electron-based desktop application for nesting parts for CNC tools, laser cutters, and plotters. It's a fork of the original SVGNest and deepnest projects with performance improvements and new features.

Key technologies:
- **Electron** with Node.js backend
- **TypeScript** for type safety (compiled to JavaScript)
- **Custom nesting engine** with C/C++ components via native modules
- **Web-based UI** with SVG rendering
- **Genetic algorithm** for optimization
- **Clipper library** for polygon operations

## Common Development Commands

### Building and Running
```bash
# Install dependencies
npm install

# Build TypeScript to JavaScript
npm run build

# Start the application
npm run start

# Clean build artifacts
npm run clean

# Full clean including node_modules
npm run clean-all
```

### Testing
```bash
# Run Playwright tests (requires one-time setup)
npx playwright install chromium
npm run test

# Generate new tests interactively
npm run pw:codegen
```

### Code Quality
```bash
# Lint and format code (runs automatically via pre-commit hooks)
prettier --write **/*.{ts,html,css,scss,less,json}
eslint --fix **/*.{ts,html,css,scss,less,json}
```

### Distribution
```bash
# Create distribution package
npm run dist

# Build everything and create distribution
npm run dist-all
```

## Architecture

### Application Structure
- **main.js** - Electron main process entry point
- **main/** - Core application code
- **deepnest.js** - Main nesting algorithm and genetic optimization
- **background.js** - Background worker for intensive calculations
- **index.html** - Main UI
- **util/** - Utility modules (geometry, matrix operations, etc.)

### Key Components

1. **Main Process (main.js)**
- Creates Electron windows
- Handles IPC communication
- Manages background workers
- Handles file operations and settings

2. **Nesting Engine (deepnest.js)**
- `DeepNest` class - Main nesting logic
- `GeneticAlgorithm` class - Optimization algorithm
- SVG parsing and polygon processing
- Clipper library integration for geometry operations

3. **Background Workers**
- Separate renderer processes for CPU-intensive tasks
- Communicates via IPC with main process
- Prevents UI blocking during calculations

4. **TypeScript Utilities (main/util/)**
- Geometry operations
- Point, Vector, Matrix classes
- Polygon hull calculations
- SVG parsing utilities

### Key Algorithms
- **Genetic Algorithm** for part placement optimization
- **No-Fit Polygon (NFP)** calculation for collision detection
- **Polygon offsetting** using Clipper library
- **Curve simplification** with Douglas-Peucker algorithm

## Development Notes

### TypeScript Configuration
- Strict mode enabled with comprehensive type checking
- Outputs to `./build` directory
- Targets ES2023 with DOM and Node.js types

### Electron Configuration
- Uses `@electron/remote` for renderer process access
- Context isolation disabled for legacy compatibility
- Node integration enabled in renderers

### Testing
- Uses Playwright for end-to-end testing
- Headless mode disabled by default for debugging
- Screenshots and videos captured on test failure

### Native Dependencies
- Requires C++ build tools (Visual Studio on Windows)
- Uses `@deepnest/calculate-nfp` for performance-critical calculations
- Electron rebuild required after native module changes

### Environment Variables
- `deepnest_debug=1` - Opens dev tools
- `SAVE_PLACEMENTS_PATH` - Custom export directory
- `DEEPNEST_LONGLIST` - Keep more nesting results

## Important File Locations

- **Entry point**: `main.js`
- **Main UI**: `main/index.html`
- **Core logic**: `main/deepnest.js`
- **Background worker**: `main/background.js`
- **TypeScript source**: `main/util/*.ts`
- **Tests**: `tests/`
- **Build output**: `build/`

## Performance Considerations

- Nesting calculations run in background processes to prevent UI freezing
- Polygon simplification reduces complexity for better performance
- Genetic algorithm parameters can be tuned via configuration
- Native modules handle computationally intensive operations

## Debugging

Set `deepnest_debug=1` environment variable to enable Chrome DevTools in all Electron windows.

## Known Issues and Recent Fixes

### Boundary Condition Bug (Fixed)
- **Issue**: A 100mm x 100mm part could not be placed in a 100mm x 100mm bin
- **Root Cause**: The `noFitPolygonRectangle` function was never called from `noFitPolygon`, and exact-fit cases created degenerate polygons
- **Fix**:
- Added rectangle detection check in `noFitPolygon` function (`main/util/geometryutil.js:1594-1599`)
- Added special handling for exact-fit cases in `noFitPolygonRectangle` (`main/util/geometryutil.js:1581-1592`)
- **Files Modified**: `main/util/geometryutil.js`
Loading
Loading