polybooljs icon indicating copy to clipboard operation
polybooljs copied to clipboard

Support different fill rules (even/odd supported, add positive-only, etc)

Open velipso opened this issue 6 years ago • 4 comments

Currently, the library is specifically coded to work with even/odd fill rule. It would be nice if there was an option for other fill rules.

velipso avatar Oct 07 '17 23:10 velipso

@voidqk can you give some guidance on implementing non-zero?

teoxoy avatar Oct 01 '19 11:10 teoxoy

Hmm, I don't know.

Assuming you read my tutorial on the algorithm (here), I think changing the fill rules should only change the fill annotation logic. Then the rest of the algorithm should work fine -- all line intersection, segment selection, and segment chaining would probably work unmodified.

The non-zero fill rule is harder because it uses winding of the input... that would mean you'd have to add some extra data to the segments for which direction they were facing (?). The current algorithm throws away winding information almost immediately. That's why the GeoJSON code has to reconstruct the winding.

Writing the current fill annotation logic took me a while to get right -- it was hard for me to reason through how toggling segments worked, etc. I think introducing winding would make that even harder to reason about.

I do suspect it's possible though, and maybe there is a clever insight that I'm missing to make it easy..?

Sorry I can't be of more help.

velipso avatar Oct 01 '19 20:10 velipso

Thanks for the info! I will take a deeper look into it in the coming days.

teoxoy avatar Oct 02 '19 13:10 teoxoy

Some requirements changed and it looks like support for non-zero is not needed anymore. I think your comment is valuable for future work on this nonetheless. Thanks for the help!

teoxoy avatar Oct 14 '19 22:10 teoxoy