Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should g.fillPoly handle a complex path? #1710

Closed
MaBecker opened this issue Dec 1, 2019 · 8 comments
Closed

Should g.fillPoly handle a complex path? #1710

MaBecker opened this issue Dec 1, 2019 · 8 comments

Comments

@MaBecker
Copy link
Contributor

MaBecker commented Dec 1, 2019

got some drawPoly that are not rendered like I though it should.

var flake1 = [114,120,126,120,126,150,150,168,144,180,126,168,126,192,114,192,114,168,96,180,90,168,114,150,114,120];
var flake2 = [114,20,126,20,126,50,150,68,144,80,126,68,126,92,114,92,114,68,96,80,90,68,114,50,114,20];

g.clear();
g.drawPoly(flake1);
g.fillPoly(flake2);

Bildschirmfoto 2019-12-01 um 14 46 47

@gfwilliams
Copy link
Member

Right now this is as expected - it's what I'd mentioned before about having a slower but more capable fillPoly implementation. The current one works on a scanline basis - filling from lowest X to highest X.

@MaBecker
Copy link
Contributor Author

MaBecker commented Dec 2, 2019

Thanks

@MaBecker MaBecker closed this as completed Dec 2, 2019
@MaBecker
Copy link
Contributor Author

MaBecker commented Dec 5, 2019

It's something I plan to improve at some point soon though - it'll likely decrease the rendering speed slightly but it definitely seems like a worthwhile addition.

Taken from the forums post

@MaBecker MaBecker reopened this Dec 5, 2019
@gfwilliams
Copy link
Member

Example algorithm posted here: http://forum.espruino.com/conversations/341492/#15015802

It looks simpler than what's there already really!

@gfwilliams
Copy link
Member

It's simple because it doesn't work properly :/

Current code is here: https://github.com/espruino/Espruino/compare/fillPoly_irregular

I had to modify it so it handled the topmost Y coordinate correctly (eg when drawing a diamond it'd miss off the top), and then also had to add a 'slope' so that it could handle the duplicate corners that would then be produced.

However drawing vector fonts still results in something like this:

................................
................................
................................
..#####...............#####.....
..#####..............######.....
...#####............######......
....#####..........######.......
....######........#######.......
.....######.......######........
......#####......######.........
......######....######..........
.......######..#######..........
........#############...........
.........######.................
.........###########............
..........#########.............
...........#######..............
...........######...............
...........######...............
..........########..............
.........######.................
.........##########.............
........######..####............
.......######...#####...........
......######.....#####..........
......######......####..........
.....######.......#####.........
....######.........#####........
...######...........#####.......
...######...........#####.......
..######.............#####......
.######...............#####.....

This is because the vector font is (currently) made out of a bunch of regular polygons, and there appear to be issues where they join

@gfwilliams
Copy link
Member

Ok, now fixed. Looks like the code mentioned initially actually does a standard polygon fill thing, which is to not fill the top and right hand pixels so that if you put polygons against each other you don't end up with overdraw - which is why the scanline code refused to draw the top pixel

My hacks will likely cause problems with more complex polygons since i'm effectively duplicating vertices at the corners :(

@MaBecker
Copy link
Contributor Author

MaBecker commented Dec 9, 2019

Bildschirmfoto 2019-12-09 um 20 18 16

Nice, many thanks

@gfwilliams
Copy link
Member

Ok, fixed with 4442951

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants