public List<Triangle2D> tesselatePolygon(Polygon2D poly) {
List<Triangle2D> triangles = new ArrayList<Triangle2D>();
Rect bounds = poly.getBounds();
// a Voronoi diagram relies on a Delaunay triangulation behind the
// scenes
Voronoi voronoi = new Voronoi(rootSize);
// add perimeter points
for (Vec2D v : poly.vertices) {
voronoi.addPoint(v);
}
// add random inliers
for (Vec2D v : createInsidePoints(poly, bounds)) {
voronoi.addPoint(v);
}
// get filtered delaunay triangles:
// ignore any triangles which share a vertex with the initial root
// triangle or whose centroid is outside the polygon
for (Triangle2D t : voronoi.getTriangles()) {
if (MathUtils.abs(t.a.x) != Voronoi.DEFAULT_SIZE
&& MathUtils.abs(t.a.y) != Voronoi.DEFAULT_SIZE) {
if (poly.containsPoint(t.computeCentroid())) {
triangles.add(t);
}