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

Polygons with holes #13

Closed
micycle1 opened this issue Mar 28, 2021 · 3 comments
Closed

Polygons with holes #13

micycle1 opened this issue Mar 28, 2021 · 3 comments

Comments

@micycle1
Copy link

micycle1 commented Mar 28, 2021

yes it works with holes, they have to defined as a separate loop in a backwards direction

I'm following this but I'm unable to get it to behave with holes. I've tried every combination of exterior & interior coordinates directions. Examples:

No hole

image

Exterior loop CCW, interior loop (hole) CW

exCCWinCW

Exterior loop CCW, interior loop CCW

exCCWinCCW

Exterior loop CW, interior loop CCW

exCWinCCW

Exterior loop CW, interior loop CW

exCWinCW

Code

Polygon polygon;
Machine speed = new Machine(1); // every edge same speed
Skeleton skeleton;
LoopL<org.twak.camp.Edge> loopL = new LoopL<>(); // list of loops
ArrayList<Corner> corners = new ArrayList<>();
Loop<org.twak.camp.Edge> loop = new Loop<>();

LinearRing exterior = polygon.getExteriorRing();
if (!Orientation.isCCW(exterior.getCoordinates())) {
	exterior = exterior.reverse(); // exterior should be CCW
}

Coordinate[] coords = exterior.getCoordinates();
for (int j = 0; j < coords.length - 1; j++) {
	double a = coords[j].x;
	double b = coords[j].y;
	corners.add(new Corner(a, b));
}
for (int j = 0; j < corners.size() - 1; j++) {
	org.twak.camp.Edge edge = new org.twak.camp.Edge(corners.get(j),
			corners.get((j + 1) % (corners.size() - 1)));
	edge.machine = speed;
	loop.append(edge);
}
loopL.add(loop);

for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
	corners = new ArrayList<>();
	LinearRing hole = polygon.getInteriorRingN(i);
	if (Orientation.isCCW(hole.getCoordinates())) {
		hole = hole.reverse(); // holes should be clockwise
	}
	for (int j = 0; j < hole.getNumPoints() - 1; j++) {
		corners.add(new Corner(hole.getCoordinates()[j].x, hole.getCoordinates()[j].y));
	}
	loop = new Loop<>();
	for (int j = 0; j < corners.size() - 1; j++) {
		org.twak.camp.Edge edge = new org.twak.camp.Edge(corners.get(j),
				corners.get((j + 1) % (corners.size() - 1)));
		edge.machine = speed;
		loop.append(edge);
	}
	loopL.add(loop);
}
@twak
Copy link
Owner

twak commented Mar 29, 2021 via email

@twak
Copy link
Owner

twak commented Mar 31, 2021

Confirmed holes works. Code in WeightedPointEditorWithHoles. Closing.

image

@twak twak closed this as completed Mar 31, 2021
@micycle1
Copy link
Author

micycle1 commented Apr 1, 2021

I think the problem was that the coordinates weren't closed (didn't have same start and end coordinate) (though I thought this wouldn't be a problem since Edges should connect the shape anyway).

image

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