Implement Polygon Shapes #38

Open
opened 2026-03-27 23:18:17 +00:00 by thib8956 · 0 comments
Owner

Overview

Add support for freeform polygon shapes with custom vertices.

Current State

  • Fixed shapes: Rectangle, Circle, Triangle
  • No support for arbitrary polygons
  • Triangle has 3 fixed vertices based on position

Implementation Plan

1. SPolygon class

  • Create new SPolygon extending AbstractShape
  • Store list of Point vertices
  • Calculate bounds from vertices

2. Polygon creation

  • Click multiple points to define vertices
  • Press Enter or double-click to complete
  • Minimum 3 points for valid polygon

3. Resizing polygons

  • Scale proportionally when resized
  • Or adjust individual vertices (advanced)
  • Initial implementation: scale all vertices from center

4. Rendering

  • ShapeDraftman: draw polygon with Graphics2D.drawPolygon()
  • SVGDraftman: emit
  • HTMLDraftman: use clip-path polygon or SVG background

5. ShapeVisitor updates

  • Add visitPolygon(SPolygon) to ShapeVisitor interface
  • Update all visitor implementations

6. Attributes support

  • ColorAttributes: fill and stroke colors
  • SelectionAttributes: selection state
  • Hit testing: use Polygon.contains() or ray casting

Files to create/modify

  • Create: shapes/SPolygon.java
  • Modify: ShapeVisitor.java - add visitPolygon method
  • Modify: ui/ShapeDraftman.java - implement visitPolygon
  • Modify: ui/visitors/SVGDraftman.java - implement visitPolygon
  • Modify: ui/visitors/HTMLDraftman.java - implement visitPolygon
  • Modify: App.java - add Add Polygon menu item

Edge cases

  • Less than 3 points: invalid, do not create
  • Self-intersecting polygons: valid but fill may look odd
  • Very small polygons: minimum size constraints
  • Open polygon vs closed: always close the shape
## Overview Add support for freeform polygon shapes with custom vertices. ## Current State - Fixed shapes: Rectangle, Circle, Triangle - No support for arbitrary polygons - Triangle has 3 fixed vertices based on position ## Implementation Plan ### 1. SPolygon class - Create new SPolygon extending AbstractShape - Store list of Point vertices - Calculate bounds from vertices ### 2. Polygon creation - Click multiple points to define vertices - Press Enter or double-click to complete - Minimum 3 points for valid polygon ### 3. Resizing polygons - Scale proportionally when resized - Or adjust individual vertices (advanced) - Initial implementation: scale all vertices from center ### 4. Rendering - ShapeDraftman: draw polygon with Graphics2D.drawPolygon() - SVGDraftman: emit <polygon points="..."> - HTMLDraftman: use clip-path polygon or SVG background ### 5. ShapeVisitor updates - Add visitPolygon(SPolygon) to ShapeVisitor interface - Update all visitor implementations ### 6. Attributes support - ColorAttributes: fill and stroke colors - SelectionAttributes: selection state - Hit testing: use Polygon.contains() or ray casting ## Files to create/modify - Create: shapes/SPolygon.java - Modify: ShapeVisitor.java - add visitPolygon method - Modify: ui/ShapeDraftman.java - implement visitPolygon - Modify: ui/visitors/SVGDraftman.java - implement visitPolygon - Modify: ui/visitors/HTMLDraftman.java - implement visitPolygon - Modify: App.java - add Add Polygon menu item ## Edge cases - Less than 3 points: invalid, do not create - Self-intersecting polygons: valid but fill may look odd - Very small polygons: minimum size constraints - Open polygon vs closed: always close the shape
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: thib8956/new-shapes#38