-
Notifications
You must be signed in to change notification settings - Fork 2
Implement per-corner circular convergence for ContourGen corner processing #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…dius detection Co-authored-by: philstopford <[email protected]>
Co-authored-by: philstopford <[email protected]>
|
@copilot : to be clear, this is about converging the bezier to a circular arc when the corner rounding radius (be it convex or concave) is >= the corner to edge midpoint distance. This should result in a circular effect, but allows for independent treatment on the other side (where the distance from corner to midpoint could be larger than the rounding radius and the bezier treatment should be largely the same as before). |
I've implemented per-corner circular convergence as you specified. The algorithm now checks each corner individually - if the radius is >= the distance from corner to edge midpoint, that specific corner uses circular arc generation. Other corners continue using bezier processing, allowing for mixed treatment within the same polygon. This addresses your clarification about independent treatment on each side where distances may vary. The change is in commit e1f2c54. |
Co-authored-by: philstopford <[email protected]>
Co-authored-by: philstopford <[email protected]>
|
@copilot : this doesn't seem right. For a square of 40x40 units, convex corner rounding radius of 20 yields:
For a convex corner rounding radius of 19, the system produces:
This indicates that there's something wrong with your approach. |
…er rounding Co-authored-by: philstopford <[email protected]>
You're absolutely right - my original implementation was creating a complete circle instead of proper rounded corners. The issue was that I was using the full radius when generating circular arcs, which caused all corners to converge into a perfect circle. I've fixed this by constraining the effective radius when circular convergence is detected. Now when radius >= distance from corner to edge midpoint, the algorithm:
For your 40x40 square example:
The fix is in commit 4321ab3 and now produces the mathematically correct behavior you specified. |


The ContourGen system was producing inefficient rounded squares instead of circular results when the convex corner radius exceeded the polygon's edge half-lengths. This fix implements intelligent per-corner circular convergence detection that automatically switches individual corners to circular arc generation when appropriate, based on feedback clarifying the requirements.
Problem
When applying large corner radii to simple polygons (like squares), the bezier-based corner rounding algorithm would create thousands of points to approximate what should mathematically be a perfect circle:
Solution
Implemented per-corner circular convergence detection in
contourGen.cs:ShouldUseCircularArc()- Evaluates each corner individually to determine if radius >= corner-to-edge-midpoint distanceGenerateCornerCircularArc()- Creates precise circular arcs for specific corners meeting convergence criteriaThe algorithm now works on a per-corner basis and triggers when:
Key Changes from Original Approach
Based on clarification feedback, the implementation was changed from an "all-or-nothing" polygon-wide circular convergence to a sophisticated per-corner analysis:
Results
For a 40x40 square with radius 20:
Performance Improvements:
Testing
Added comprehensive test coverage:
CircularConvergenceTests.cs- 5 unit tests covering various polygon types and per-corner scenariostest_circle_convergenceproject - Visual validation with SVG output generationThe fix implements the mathematically correct approach for per-corner circular convergence, providing both performance benefits and geometrically accurate results while maintaining full backward compatibility and proper corner rounding behavior.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.