Add boundary smoothing to polygon generation - #20
Draft
Kanahiro wants to merge 1 commit into
Draft
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 geometriesUpdated test assertions: Adjusted area tolerance in multiple test files to account for slight area changes from smoothing
pytest.approx()withrel=0.05orrel=0.02tolerancetest_polygon_maker.py,test_processing_algorithm.py, andtest_preview_session.pyRenamed and enhanced test class:
TestSimplificationtoTestSimplificationAndSmoothingtest_staircase_boundary_is_thinned_and_smoothedmax_turn_degrees()helper function to verify that stair-step corners (90-degree angles) are eliminatedUpdated 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 smoothingSMOOTH_ITERATIONS = 2: Number of Chaikin smoothing passesSMOOTH_OFFSET = 0.25: Chaikin offset as fraction of segment lengthThis approach balances visual quality (smooth corners) with computational efficiency and maintains area accuracy within acceptable tolerances.
https://claude.ai/code/session_014zaxaNkWQVvhjCkmHx9Tz8