Before writing a routine, you must check that the conditions are logically flawless.
From the length between polyline nodes,
we need to distinguish between lines to be taken and lines not to be taken.
Once the loop is run once, these two white lines in the example must survive.
Since the rule is not grid snap 1.5 because the result's nodes do not fall to 1.5,
deleting the right line must be done by looping once more with the result of the first loop.
The left white line will survive though.
Since the general routine makes judgments by comparing the front and back points,
a new routine may be needed to estimate the edges using extension lines at the nodes at both ends.
Extract the coordinates of each point of the polyline,
first extract the cases where both sides are 1.5 or more from the length of the line segment (points marked with a 1.5 radius circle),
and then draw only one side. After marking the point (marked by x) that is greater than 1.5,
then draw a line first when there are continuous circles,
draw directly towards the next point x on the circle.
Now, we need to find the included angle in all coordinates other than 0 90 180 270 and remove that node.
You also need to decide which side of the line to align it with.
This is the guessing based on only the nodes,
but if there is a condition that the area should not be modified in a way that makes it smaller,
your example can be valid.
In this case, you must add a routine to determine the area of the closed area
and a routine to determine whether a point is inside or outside the closed polyline.
It will become more complicated than guessing based on just the nodes.