Login  Register

Re: how to check if every entity/polyline on your drawing is closed? and strange behaviour of creating polylines

Posted by LordOfBikes on Jan 29, 2022; 8:22pm
URL: https://forum.librecad.org/how-to-check-if-every-entity-polyline-on-your-drawing-is-closed-and-strange-behaviour-of-creating-pos-tp5721401p5721406.html

No problem, you're welcome.

So with your explanation I could reproduce your issue.
But your steps are missing an important step. It makes a difference if you select the tool first or the entities.

On the first iteration it is no problem. You have 4 single 2-Point lines building a closed rectangle. The result is a closed polyline, no matter what is selected first.
On the second iteration, you select the polyline first and then fire the "Create Polyline ..." tool.
This applies the tool on the existing, closed polyline and this program path seems to have an issue.

When you deselect all entities before you fire the "Create Polyline ..." tool, you are expected to select the entities for the polyline and finish the selection with ENTER. In this mode, it is not possible to select the polyline, because an already closed polyline could not be part of another polyline. The command history shows an error message.
So here it is prohibited to select an illegal entity, presumably to protect the code which fails when the polyline is already selected when the tool is fired.

So it seems that the "Create Polyline ..." tool gives what is expected on first hit. But using the tool a second time on an already closed polyline, the issue arise.
But this only happens when the polyline is selected first and then the tool.


From DXF point of view lines and polylines are totally different. Lines are independent entities with a starting and ending point. But a polyline is collection of vertices, connected with straight lines or arcs.
The polyline format in DXF is bad for rendering and thus inside LibreCAD a polyline is not a container of vertices, but of lines and arcs. Presumably KLayout handle this that way too.
Now you can think of the closed flag as a switch which defines if the first and last vertex of the polyline is connected.
In your Polygon case, the start point is 90,0 and the end point is 140,0. Connecting the 4 vertices you'll have an upside down U shaped path from 3 lines. And the closed flag is responsible for the 4th line on the bottom from 140,0 to 90,0 which closes the area.
In the Path case there seems to be an issue with KLayout, because 50,0 exists 4 times. Normally there should be 5 coordinates and the first point 50,50 is equal to the last point. This gives 4 lines and a closed shape too.

An open polyline is commonly used in CAM applications, where a continuous tool path is required. And there are surely other use cases too, so open polylines have their right to exist.

What I want to say with my recommendation for an OR approach is that KLayout or other applications should not only count on the closed flag, but also create a Polygon when first and last vertex of a polyline is equal, this would be less restrictive and avoid issues.
Because the intention of a draftsman drawing a polyline, ending on the starting point, is a closed polyline. He don't care or even know about closed flag.
investing less than half an hour into Search function can save hours or days of waiting for a solution