1

Resolved

LWPolyline.PoligonalVertexes

description

Hi,
I believe that I found mistake in PoligonalVertexes method.
This code should generate "Doors":
         var polyline = new LwPolyline();
            polyline.Vertexes.Add(new LwPolylineVertex(new Vector2(-6.235716494223, -11999.72844668765), 0));
            polyline.Vertexes.Add(new LwPolylineVertex(new Vector2(-6.235716494223, -11299.72844668765), -0.413065779627));
            polyline.Vertexes.Add(new LwPolylineVertex(new Vector2(695.01443924624, -11999.728446687381), 1120.86047433915));
            
            var vertexes = polyline.PoligonalVertexes(2, 1e-3, 1e-3);
If you try it, you will see that vertexes contains points that should not be there.

Here is my proposal to fix it.
LwPolyline.cs line 319:
if (index == this.Vertexes.Count - 1)
                {
                    p1 = new Vector2(vertex.Position.X, vertex.Position.Y);
                    p2 = new Vector2(this.vertexes[0].Position.X, this.vertexes[0].Position.Y);
                    // ignore bulge value of last vertex
                    bulge = 0;
                }
                else
                {
                    p1 = new Vector2(vertex.Position.X, vertex.Position.Y);
                    p2 = new Vector2(this.vertexes[index + 1].Position.X, this.vertexes[index + 1].Position.Y);
                }
Please let me know what you think abou thits.

Petr

comments

haplokuon wrote Jan 19 at 6:30 PM

There is a little bug in there but the fix you propose is only valid for open LwPolylines. Use this fix instead:
// ignore bulge value of last vertex for open polylines
if(!this.IsClosed) bulge = 0;
Or just set to zero the bulge of last vertex in open LwPolylines, instead of writing:
polyline.Vertexes.Add(new LwPolylineVertex(new Vector2(695.01443924624, -11999.728446687381), 1120.86047433915));
use:
polyline.Vertexes.Add(new LwPolylineVertex(new Vector2(695.01443924624, -11999.728446687381), 0));
Under normal circumstances only change the default bulge value of zero where necessary.

Daniel

icek wrote Jan 19 at 7:20 PM

Hello Daniel,
thank you for proper fix.
I had issue with imported dxf, so I need to fix PoligonalVertexes method. I think you should add this fix as well.

PS: PoligonalVertexes should probably be PolygonalVertexes :-)

Thank you
Petr

haplokuon wrote Jan 20 at 5:30 PM

Of course I will add that fix, although there is an easy workaround to avoid the problem, it is still a bug that needs to be fixed.

I will also rename the method to mend the typing error. Where is the spell check when you need it? But without it my English will look a lot worse.

Daniel

exelias wrote Jan 28 at 9:08 PM

Hello -

A couple more things I noticed:
Vector2 prevCurvePoint = new Vector2(this.vertexes[this.vertexes.Count - 1].Position.X, this.vertexes[this.vertexes.Count - 1].Position.Y);
This should be the last point in ocsVertexes.
if (!p1.Equals(p2, weldThreshold))
I think this conditional should be removed. The weldThreshold is only supposed to apply to points that are being added. If the vertices that are passed in to the function are already closer together than the weldThreshold, then all of them will be removed.