Skip to content

Commit

Permalink
use the new SkPathOps::AsWinding for converting fill type from even o…
Browse files Browse the repository at this point in the history
…dd to non-zero winding

was added in https://bugs.chromium.org/p/skia/issues/detail?id=7682

Should provide a better fix for #10

The old logic is still kept in case the new AsWinding function returns False (failure), but
probably should not be needed.
  • Loading branch information
anthrotype committed Aug 17, 2018
1 parent a0e2190 commit 8a68db6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/python/pathops/_pathops.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ from ._skia.core cimport (
from ._skia.pathops cimport (
Op,
Simplify,
AsWinding,
SkOpBuilder,
SkPathOp,
kDifference_SkPathOp,
Expand Down Expand Up @@ -945,6 +946,13 @@ cpdef bint winding_from_even_odd(Path path, bint truetype=False) except False:
The outermost contours are set to counter-clockwise direction, unless
'truetype' is True.
"""
if AsWinding(path.path, &path.path):
if path.clockwise ^ truetype:
path.reverse()
return True

# in the unlikely event the built-in method fails, try our naive approach

cdef int i, j
cdef bint inverse = not truetype
cdef bint is_clockwise, is_even
Expand Down Expand Up @@ -1206,12 +1214,12 @@ cpdef Path simplify(Path path, fix_winding=True, keep_starting_points=True):
first_points = path.firstPoints
cdef Path result = Path()
if Simplify(path.path, &result.path):
return result
raise PathOpsError("operation did not succeed")
if fix_winding:
winding_from_even_odd(result)
if keep_starting_points:
restore_starting_points(result, first_points)
raise PathOpsError("operation did not succeed")
return result


cdef class OpBuilder:
Expand All @@ -1228,13 +1236,13 @@ cdef class OpBuilder:

cpdef Path resolve(self):
cdef Path result = Path()
if self.builder.resolve(&result.path):
if self.fix_winding:
winding_from_even_odd(result)
if self.keep_starting_points:
restore_starting_points(result, self.first_points)
return result
raise PathOpsError("operation did not succeed")
if not self.builder.resolve(&result.path):
raise PathOpsError("operation did not succeed")
if self.fix_winding:
winding_from_even_odd(result)
if self.keep_starting_points:
restore_starting_points(result, self.first_points)
return result


# Doctests
Expand Down
2 changes: 2 additions & 0 deletions src/python/pathops/_skia/pathops.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ cdef extern from "SkPathOps.h":

bint Simplify(const SkPath& path, SkPath* result)

bint AsWinding(const SkPath& path, SkPath* result)

cdef cppclass SkOpBuilder:

SkOpBuilder() except +
Expand Down

0 comments on commit 8a68db6

Please sign in to comment.