# [OpenJDK 2D-Dev] RFR JDK-8184429: Path clipper added in Marlin2D & MarlinFX 0.8.0

Jim Graham james.graham at oracle.com
Thu Aug 31 23:55:19 UTC 2017

```I want to elaborate on winding count issues for segments to the left of the clip for both winding modes.

All curves have the property that the winding count of any sample point to the right of them is identical to the winding
count of a line from their starting point to their ending point.

Consider a quad.  If it is monotonic, then the observation should be fairly obvious as the curve only ever has one
crossing for any scanline and only the X location of that crossing varies and it only varies within the bounds of the X
coordinates of all of 3 defining points.  Once you are to the right of all 3 X coordinates, the winding count is
uniformly a single value over the entire Y range of the (monotonic) quad.

Consider a quad with a vertical reversal.  If one of the endpoints is higher than the other, then in the area between
the Y coordinates of the endpoints it will increase or decrease the winding count by only 1, and the sign of that
winding count change will be identical to a segment that connects the two endpoints.  For the rest of the quad, the part
where it doubles back on itself, those 2 parts of the path cancel each other out.  You either have a downward portion
that curves into an upward portion, or vice versa.  In both cases, that portion has a resulting winding count of 0
because the direction of those 2 parts of the curve are opposite.

A cubic is more complicated with more cases to consider, but if you diagram it out you can see that the winding count
contribution off to the right of the cubic will be identical in all cases to the winding count contribution of a line
segment joining the two endpoints.  You can have up to 3 reversals, but all reversals that are above or below the end
points will be paired with each other and all reversals within the Y range of the end points will either result in 1 or
3 competing pieces and the 1 or the majority of the 3 will be in the same direction/sign as the direction/sign of the
segment between the endpoints.  If there are 3 then 2 will cancel out and the remaining one will be the same direction
as the endpoint line segment.

So, all path segments, regardless of line/quad/cubic that lie entirely to the left of the clip have identical winding
count to a simple line segment.

And with the proper winding count computed, the winding mode has no impact, the same winding count is appropriate and
accurate whether the entire path is EO or NZ...

...jim

On 8/31/17 4:15 PM, Jim Graham wrote:
>> For the Even-odd filling rule, I think it needs exact segment intersections on the left side, so I am focused on the
>> Non-zero filling rule for now.
>
> They are identical.  All that matters is that you have the proper starting winding count as you enter the clip from the
> left.  They could be replaced by either a segment with the same "Y range" as I mention above, or they could be replaced
> by having a value in the segments list that is "starting count", so if you have a segment that is out-left and it goes
> from Y=10 to Y=20, you simply add (or subtract for reversed lines) one to the "starting count" field for all scanlines
> from 10->20.
```