Skip to content

Conversation

@Dexus
Copy link
Member

@Dexus Dexus commented Jul 10, 2025

No description provided.

Dexus and others added 9 commits July 9, 2025 19:32
…tions

- Created new Polygon class in main/util/polygon.ts as modern replacement for array-based polygons
- Uses existing Point class for type-safe coordinate handling
- Implements all commonly used polygon operations from geometryutil.js:
  - Geometric calculations: area(), bounds(), centroid(), perimeter()
  - Spatial queries: contains() with point-in-polygon testing
  - Transformations: translate(), rotate(), scale() with immutable and in-place variants
  - Utility methods: isRectangle(), reverse(), winding direction control
- Provides conversion methods for legacy array format and Clipper integration
- Includes static factory methods for creating rectangles and circles
- Maintains compatibility with existing offsetx/offsety and children properties
- Supports both immutable operations (return new instances) and in-place modifications
- Updated HullPolygon.ts to accept both new Polygon class and legacy Point[] arrays
- Added backwards compatibility with PolygonArray type alias
- Modified all static methods to handle both polygon types:
  - area(): delegates to Polygon.area() when possible
  - centroid(): delegates to Polygon.centroid() when possible
  - hull(): returns new Polygon instance instead of Point[]
  - contains(): uses Polygon.contains() with null-to-false conversion
  - length(): delegates to Polygon.perimeter() when possible
- Maintains full backwards compatibility while enabling new Polygon class usage

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Updated key polygon functions in geometryutil.js to use new Polygon class:
  - getPolygonBounds(): delegates to polygon.bounds() when available
  - pointInPolygon(): delegates to polygon.contains() when available
  - polygonArea(): delegates to polygon.area() when available
  - isRectangle(): delegates to polygon.isRectangle() when available
  - rotatePolygon(): delegates to polygon.rotate() when available
- Added global window export to polygon.ts for JavaScript compatibility
- Maintains full backwards compatibility with array-based polygon format
- Functions automatically detect Polygon class instances and use optimized methods

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Added Polygon class import to deepnest.js
- Updated getHull() function to handle both Polygon instances and arrays
- Added instanceof checks to use Polygon methods when available
- Maintains backwards compatibility with existing array-based polygon format
- HullPolygon.hull() results are converted to arrays for consistency with existing code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Added Polygon class import to background.js
- Updated getHull() function to handle Polygon instances:
  - Uses HullPolygon.hull() directly for Polygon objects
  - Converts results to arrays for compatibility with existing code
- Updated rotatePolygon() function to handle Polygon instances:
  - Uses Polygon.rotate() method when available
  - Preserves exact property from original points
  - Maintains children handling for nested polygons
- Maintains full backwards compatibility with array-based polygon format

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Added Polygon class import to svgparser.js
- Updated polygonify() method to return Polygon instances:
  - Converts array of {x, y} points to Point instances
  - Creates and returns new Polygon from Point array
  - Maintains all existing SVG element support (rect, circle, ellipse, path, polygon, polyline)
- Preserves existing coincident point removal logic
- SVG parsing now directly produces Polygon objects ready for nesting operations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Re-added Vector import and implemented proper vector-based operations
- Added getEdgeNormal() method to get perpendicular edge vectors
- Added getEdgeVector() method to get edge direction vectors
- isRectangle() method already uses Vector through Point.to() for dot products
- Enhanced geometric capabilities with proper vector mathematics
- Fixed unused import issue identified in code review

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add GEOMETRIC_TOLERANCE for floating-point comparisons
- Add angle conversion constants (DEG_TO_RAD, RAD_TO_DEG)
- Add mathematical constants (TWO_PI)
- Add default values for geometric operations
- Add configuration constants (DEFAULT_CLIPPER_SCALE)
- Replace TOL constant with GEOMETRIC_TOLERANCE in polygon.ts and vector.ts
- Replace angle conversion calculations with DEG_TO_RAD in polygon.ts and matrix.ts
- Replace 2 * Math.PI with TWO_PI in polygon.ts
- Replace hardcoded 32 with DEFAULT_CIRCLE_SEGMENTS in polygon.ts
- Replace hardcoded 10000000 with DEFAULT_CLIPPER_SCALE in test file
- Remove duplicate constant definitions across files
@Dexus Dexus self-assigned this Jul 10, 2025
@Dexus Dexus added the enhancement New feature or request label Jul 10, 2025
- Add constants.js for JavaScript compatibility with centralized constants
- Update geometryutil.js to use GEOMETRIC_TOLERANCE, DEG_TO_RAD, and RAD_TO_DEG
- Update deepnest.js to use DEFAULT_CLIPPER_SCALE throughout
- Update background.js to use DEFAULT_CLIPPER_SCALE for all clipper operations
- Update svgparser.js to use RAD_TO_DEG and TWO_PI constants
- Add constants.js script loading to index.html and background.html
- Ensure backward compatibility with fallback values in geometryutil.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant