haplokuon / netDxf

.net dxf Reader-Writer
MIT License
995 stars 405 forks source link

The direction of the annotation leader is unintentionally reversed #294

Open kyosukeSakurai opened 3 years ago

kyosukeSakurai commented 3 years ago

The direction of the annotation leader is unintentionally reversed

Load & Save the sample data (SampleX.dxf). SAMPLE_X.zip

In the previous netDxf version, Leader group code '211' becomes '1'. When opened with a viewer such as AutoCAD, the correct display is as shown below. image

In the new netDxf version, Leader group code '211' becomes '-1'. When opened with a viewer such as AutoCAD, the display is incorrect as shown below. image

I think it is a bug in the new version, so please check it.

Ref. ) Leader group code https://help.autodesk.com/view/ACD/2020/ENU/?guid=GUID-396B2369-F89F-47D7-8223-8B7FB794F9F3

See 'WriteLeader' on DxfWriter.cs. 211 is set at the line below:  this.chunk.Write (211, xDir.X);

There is a possible way to fix it, but how about it?

I'm trying to fix the #294 and #293 failure at the same time. Please check the attached file. I would like to cooperate with early improvement. If you are unsure of the intent of the correction, please let me know. SampleCode.zip

haplokuon commented 3 years ago

I will continue the discussion in the older issue since the origin of those problems seems to be the same.

kyosukeSakurai commented 3 years ago

If issues #293 and #294 are solved, we can see the following issues.

If the annotation leader line has an acute angle, Load and save will make it impossible to reproduce the acute angle. image

Sample code:

var dxfDoc = DxfDocument.Load( filename );
dxfDoc.Save( filename );

SAMPLE_C.zip

I think the following processing is needed to be fixed. Line 4511 on DXFReader.cs

            if (hasHookline && wcsVertexes.Count >= 3)
            {
        // When 1st, 2nd and 3rd points make up an acute angle, not to delete the 2nd point 
               //  because it need to be restored. See 'WriteLeader' on 'DxfWriter.cs'.
                var x1 = wcsVertexes[2].X - wcsVertexes[1].X;
                var x2 = wcsVertexes[1].X - wcsVertexes[0].X;
                if ((x1 * x2) > 0)
                {
                    wcsVertexes.RemoveAt(wcsVertexes.Count - 2);
                }
            }

Line 364 on Leader.cs

              // Recalculate and add Hookline only if there are two vertices.
              if (this.vertexes.Count == 2)
              {
                      this.vertexes.Insert(this.vertexes.Count - 1, this.CalculateHookLine());
              }

FixedCode.zip