for(Vector2f vec: nonConvexPointsParallel) {
Line prepost = nonConvexPointOutsideSegment.get(vec);
List<Line> lines1 = segmentMap.get(prepost.getPoint(0));
List<Line> lines2 = segmentMap.get(prepost.getPoint(1));
for(Line line1: lines1) {
Vector2f point1 = line1.getPoint(0);
if(point1 == prepost.getPoint(0)) point1 = line1.getPoint(1);
for(Line line2: lines2) {
Vector2f point2 = line2.getPoint(0);
if(point2 == prepost.getPoint(1)) point2 = line2.getPoint(1);
if(point2 == point1) {
if(getLine(vec, point1) == null) {
addSegment(vec, point1);
}
}
}
}
}
}
// If there are no cut-outs and no concave points the first point get connected to all but the one before and after
if(nonConvexPoints.size() == 0 && shape.getCutOuts().size() == 0) {
Vector2f point = shape.getOutline().get(1);
for(int i = 3; i < shape.getOutline().size(); i++) {
Vector2f point2 = shape.getOutline().get(i);
addSegment(point, point2);
}
}
// Build a list of all points for construction of triangles
ArrayList<Vector2f> points = new ArrayList<Vector2f>();
points.addAll(shape.getOutline());
for(List<Vector2f> cutOut: shape.getCutOuts()) {
points.addAll(cutOut);
}
ArrayList<Vector2f> insidePoints = new ArrayList<Vector2f>(points);
// Testing: drawing
// for(Line segment: segments) {
// renderer.drawLine(segment.getPoint1().x, segment.getPoint1().y, segment.getPoint2().x, segment.getPoint2().y, 0.001f, new Color4f(1,1,1,1));
// }
// for(Vector2f point: points) {
// renderer.drawPoint(point.x, point.y, 3f, new Color4f(1,1,1,1));
// }
// for(Vector2f point: nonConvexPoints) {
// renderer.drawPoint(point.x, point.y, 6f, new Color4f(1,0,0,1));
// }
// for(Vector2f point: nonConvexPointsParallel) {
// renderer.drawPoint(point.x, point.y, 6f, new Color4f(0,1,0,1));
// }
ArrayList<Triangle> triangles = new ArrayList<Triangle>();
// create triangles with the calculated segments by processing each point
while(points.size() > 0) {
Vector2f point1 = points.get(points.size() - 1);
Vector2f point2;
Vector2f point3;
// process each combination of segments starting at the current point
List<Line> pointSegments = segmentMap.get(point1);
for(Line line: pointSegments) {