Skip to content

Add boundary smoothing to polygon generation - #20

Draft
Kanahiro wants to merge 1 commit into
masterfrom
claude/polygon-smoothing-tib5c6
Draft

Add boundary smoothing to polygon generation#20
Kanahiro wants to merge 1 commit into
masterfrom
claude/polygon-smoothing-tib5c6

Conversation

@Kanahiro

Copy link
Copy Markdown
Owner

Summary

This PR adds Chaikin corner-cutting smoothing to polygon boundaries after simplification, reducing pixel jaggedness while maintaining computational efficiency and area accuracy.

Key Changes

  • Boundary smoothing implementation: Added smooth_features() method that applies densification followed by iterative Chaikin smoothing to polygon geometries

    • Densifies boundaries to 3-cell segments before smoothing to cap corner rounding radius
    • Applies 2 iterations of smoothing with 0.25 offset for balanced visual quality and performance
    • Works directly on geometries rather than through processing algorithms for low per-click cost
  • Updated test assertions: Adjusted area tolerance in multiple test files to account for slight area changes from smoothing

    • Changed from exact area assertions to pytest.approx() with rel=0.05 or rel=0.02 tolerance
    • Affected tests across test_polygon_maker.py, test_processing_algorithm.py, and test_preview_session.py
  • Renamed and enhanced test class:

    • Renamed TestSimplification to TestSimplificationAndSmoothing
    • Renamed test method to test_staircase_boundary_is_thinned_and_smoothed
    • Added max_turn_degrees() helper function to verify that stair-step corners (90-degree angles) are eliminated
    • Updated assertions to verify smoothing effectiveness: max turn angle < 60° and vertex count ≤ 60
  • Updated test documentation: Clarified comments explaining that both thinning and smoothing work together to produce the final boundary

Implementation Details

The smoothing is integrated into the build_polygons() workflow after the simplification/cleaning step. Three new module-level constants control the smoothing behavior:

  • DENSIFY_INTERVAL_CELLS = 3.0: Controls maximum segment length before smoothing
  • SMOOTH_ITERATIONS = 2: Number of Chaikin smoothing passes
  • SMOOTH_OFFSET = 0.25: Chaikin offset as fraction of segment length

This approach balances visual quality (smooth corners) with computational efficiency and maintains area accuracy within acceptable tolerances.

https://claude.ai/code/session_014zaxaNkWQVvhjCkmHx9Tz8

Densify the simplified rings to a few mask cells per segment, then
apply Chaikin corner cutting (QgsGeometry.smooth) as the final
pipeline step. Densifying first caps the corner rounding radius at
about one cell, so long straight edges keep their shape while the
residual pixel staircase is rounded off. Working directly on the
geometries avoids extra processing-algorithm layer round-trips, so
the per-click cost stays low.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014zaxaNkWQVvhjCkmHx9Tz8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants