Skip to content

Add path conversion, containment and intersection to Region - #423

Merged
JimBobSquarePants merged 1 commit into
mainfrom
js/region-path-ops
Sep 16, 2026
Merged

JimBobSquarePants merged 1 commit into
mainfrom
js/region-path-ops

Conversation

@JimBobSquarePants

Copy link
Copy Markdown
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Splits the Region additions out of #415 so they can land on their own, with tests.

New members on Region. They match SkRegion::setPath, SkRegion::contains(const SkRegion&) and SkRegion::intersects(const SkRegion&).

  • Region(IPath path, IntersectionRule intersectionRule) scan-converts a path into the integer pixels whose centres lie inside it. Rows and crossings use the same fixed-point rounding as Skia's non-antialiased scan converter.
  • Contains(Region region) returns true when every pixel of the argument is in this region.
  • Intersects(Region region) returns true when the two regions share at least one pixel.

One change from the #415 code. The integer clip used the ceiling of the path bounds on all four sides. That dropped pixels whose centres lie inside the path when the left or top edge had a fraction of 0.5 or less. The clip now rounds outwards, the same rounding DrawingClipDescriptor applies to clip bounds and the same as SkIRect::roundOut. Seven of the new tests fail with the old clip.

CA1517. The .NET 11 preview SDK reports CA1517 on MoveEdgeBackward, asking for ReadOnlySpan<RegionEdge>. The method writes link fields through the span indexer, and the suggested change gives CS8332 errors, so the rule is suppressed on that method with a pragma.

Tests in RegionTests:

  • Path conversion of a zero-area path, an integer rectangle and a fractional rectangle with hand-computed expected pixels.
  • A triangle, a concave polygon at positive and negative offsets, and nested rectangles under both fill rules, each checked pixel by pixel against IPath.Contains at pixel centres. Vertex coordinates are chosen so no crossing lands on a pixel centre.
  • Contains(Region) and Intersects(Region) on an L shape, empty regions, touching edges and interleaved islands, plus a pixel-membership check on path-built regions.
Run Result
Region and clip tests, net10.0 98 pass
Region and clip tests, net11.0 98 pass

Region(IPath, IntersectionRule) scan-converts a path into the integer
pixels whose centres lie inside it. Contains(Region) and
Intersects(Region) compare two regions band by band. The integer clip
rounds the path bounds outwards, the same rounding the library applies
to clip bounds, so no pixel whose centre lies inside the path is lost.
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.00787% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 79%. Comparing base (f5cc287) to head (57e4991).

Files with missing lines Patch % Lines
src/ImageSharp.Drawing/Region.cs 87% 15 Missing and 18 partials ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main    #423    +/-   ##
======================================
  Coverage     79%     79%            
======================================
  Files        232     232            
  Lines      27531   27785   +254     
  Branches    3129    3188    +59     
======================================
+ Hits       21955   22186   +231     
- Misses      4537    4547    +10     
- Partials    1039    1052    +13     
Flag Coverage Δ
unittests 79% <87%> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JimBobSquarePants JimBobSquarePants added this to the v4.0.0 milestone Sep 16, 2026
@JimBobSquarePants JimBobSquarePants added enhancement New feature or request API labels Sep 16, 2026
@JimBobSquarePants
JimBobSquarePants merged commit 65ff5fa into main Sep 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant