首页 > 解决方案 > Fill front and back sides of the path with different color in context of iOS CoreGraphics

问题描述

Provided we have a path that is "twisted" meaning part of it is oriented front side and part is back side. For example:

enter image description here

The path is build by lines between points A, B, C and D. From the docs I know there is CGPathFillRule.winding mode that is close to what I need:

This rule plots a ray from the interior of the region to be evaluated toward the bounds of the drawing, and sums the closed path elements that the ray crosses: +1 for counterclockwise paths, -1 for clockwise. If the sum is zero, the region is left empty; if the sum is nonzero, the region is filled.

But it fills the area if the described condition "is nonzero", and I need to separate it: "if greater than zero" and "if less than zero".

Is there a way to draw only front side at first then switch to other color and draw the back side. I know that this approach is possible and widely used in OpenGL graphics where polygons have front and back faces depending on CW or CCW points order.

标签: iospathcore-graphicsrender

解决方案


推荐阅读