Repository navigation
feat: add evenoddToNonzero to reorient subpaths for the nonzero rule - #101
Open
YevheniiKotyrlo wants to merge 3 commits into
Open
YevheniiKotyrlo wants to merge 3 commits into
YevheniiKotyrlo wants to merge 3 commits into
Conversation
A path filled with the evenodd rule leaves any region enclosed an even number of times empty, whatever the directions of its subpaths. Font outlines fill by the nonzero rule instead, where a hole stays empty only when its subpath winds against the subpath enclosing it. EVENODD_TO_NONZERO finds each subpath's tightest enclosing subpath and reverses every subpath that winds the same way as its enclosure, so the nonzero rule fills the same area. A path whose subpaths already alternate is returned as given.
3 of 4 tasks
evenoddToNonzero nested a subpath only in a strictly larger one holding most of its points by the crossing test, which counts a point on the left or top edge of an outline as inside it and one on the right or bottom edge as outside. A hole touching the right or bottom of its outline kept its direction, a subpath touching another from the left could land inside it, and a subpath drawn twice nested in neither copy. A point on the other subpath's outline now counts neither way, and subpaths of equal area nest in the order they are drawn, so the copies of a subpath drawn twice cancel out as evenodd paints them.
A subpath cancels out only when it repeats another point for point: from any of its points and in either direction, but drawn with the same commands. The same shape drawn with other commands, such as a circle's arcs starting elsewhere, flattens to a different outline and is not recognised as a repeat.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
SVGPathData#evenoddToNonzero()(SVGPathDataTransformer.EVENODD_TO_NONZERO): reorients the subpaths of anevenoddpath so thatnonzerofills the same area — each nested subpath winds against its enclosure, outermost ones keep their direction. Moved from fix(core): keep the holes of evenodd paths svgicons2svgfont#182 at @armano2's request; fonts fill bynonzero(It seems that fill-rule="evenodd" does not works correctly svgicons2svgfont#62).evenoddpaints it; the same shape drawn with other commands is not recognised as a repeat. Reversal goes throughREVERSE_PATH, so a reoriented path comes back absolute with cubic curves; a path that needs nothing is returned as given. It assumes no subpath crosses itself or another.src/tests/evenodd_to_nonzero.test.ts: 22 cases, including a subpath drawn twice and three times, holes touching each side of their outline, idempotency and an unmodified input.jest,eslint,tsc,prettierandcommitlintpass;metapak -sfails identically onmainon my Windows machine.Code quality
contributors
field of the
package.jsonfile. Beware to use the same format than for the author fieldfor the entries so that you'll get a mention in the
README.mdwith a link to your website.License
To get your contribution merged, you must check the following.