This application demonstrates polygon clipping (Cyrus-Beck, Sutherland-Hodgman, and concave-window clipping via ear clipping) and filling (seed-fill, scanline, LCA) in Swift 6 using Metal and SwiftUI.
It was originally developed as a Math course project on geometric algorithms.
Features
• Multiple Polygons: Load/store several polygons (convex, concave, or self-intersecting).
• Window Clipping:
• Convex window: Use Cyrus-Beck or Sutherland-Hodgman.
• Concave window: Decompose via ear clipping, then apply the chosen algorithm.
• Polygon Filling:
• Seed-Fill (recursive or stack-based).
• Scanline.
• LCA (Active Edge Table).
• Eraser, resizing, moving, pre-shaping, export... tools.
• Modern SwiftUI/Metal Interface:
• Pan & Zoom.
• Tool panel to select the clipping/filling algorithm.
• Real-time rendering with a single click or keyboard validation to trigger each algorithm.
Usage
- Open the app and select or create a new document (which contains polygons).
- Draw a polygon.
- Choose a clipping or filling algorithm in the side panel.
- Apply the operation (e.g., draw or adjust a window polygon, then press Enter) to see the resulting clipped/filled shape.
- Pan/Zoom to inspect details.
- Export your masterpiece and show it off! 🚀
That’s it! You can experiment with different polygons, windows, and filling techniques.