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

Result from fillPolygon is sometimes incorrect for concave polygons #700

Closed
JohnDeptuch opened this issue Dec 20, 2024 · 3 comments
Closed

Comments

@JohnDeptuch
Copy link

When I run the following the polygon is filled incorrectly.

import 'dart:io';
import 'package:image/image.dart';
 
void main() {
  final i0 = Image(width: 200, height: 200);
 
  final vertices = <Point>[
    Point(50, 50),
    Point(50, 150),
    Point(150, 150),
    Point(150, 50),
    Point(100, 100),
  ];
 
  fillPolygon(i0, vertices: vertices, color: ColorRgb8(176, 0, 0));
  drawPolygon(i0, vertices: vertices, color: ColorRgb8(0, 255, 0));
  File('fillpolygon.png')
    ..createSync()
    ..writeAsBytesSync(encodePng(i0));
}

fillpolygon

@brendan-duncan
Copy link
Owner

Yeah, sorry, the drawing functions are pretty rudimentary. The fillPolgon doesn't support concave polygons. I can see about doing a proper fillPolygon when I get a chance.

@brendan-duncan
Copy link
Owner

I had a few minutes, so I rewrote fillPolygon to use a ray-cast fill method that can better handle complex concave polygons.
fillPolygon2

@JohnDeptuch
Copy link
Author

It's now working for me. Thanks for the fast response.

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