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

DXF polyline circle like shape wrongly recognized as tiny arc segment #1839

Open
igorthy opened this issue Sep 15, 2019 · 3 comments
Open

DXF polyline circle like shape wrongly recognized as tiny arc segment #1839

igorthy opened this issue Sep 15, 2019 · 3 comments

Comments

@igorthy
Copy link

igorthy commented Sep 15, 2019

Hi,

I have a DFX file which I reduced to single block containing single polyline shape.
In Autocad 2019 it looks like:
bug
If you read it into memory/write shapefile with DXF driver it translates polyline to single line segment.
It is true for gdal 3.0.0 and for 3.0.1 releases.
DXF file attached (after download change extension to dxf):

polyline.txt

Any help highly appreciated.

@rouault rouault changed the title DFX polyline circle like shape wrongly recognized as single line segment DXF polyline circle like shape wrongly recognized as single line segment Sep 16, 2019
@rouault
Copy link
Member

rouault commented Sep 16, 2019

CC @atlight

@igorthy
Copy link
Author

igorthy commented Sep 25, 2019

I got a chance to debug this problem during last weekend and find the place where it goes wrong
but I didn't have yet the time to work on solution.
The shape inside DXF file is polyline defined by two points (very close to each other) and a bulge factor.
In ogrdxf_polyline_smooth.cpp file there is a method DXFSmoothPolyline::EmitArc that calculates arc parameters for subsequent OGRGeometryFactory::approximateArcAngles call.
This calculation need to be reviewed. First it seems that there is some issue with clockwise/anticlockwise choice of algorithm.
When I reversed the sign of bulge value in DXF file the method generated the correct linestring BUT
at wrong location.

It would be very nice if someone could fix this quickly.
I will try to fix it myself when I'll have an opportunity.
Thanks

@igorthy
Copy link
Author

igorthy commented Oct 1, 2019

I believe I have a fix for this issue.
I debugged through calculation done in DXFSmoothPolyline::EmitArc (see ogrdxf_polyline_smooth.cpp file).
I found out that clockwise arc calculated correctly but exactly same anticlockwise arc calculated wrong as tiny arc.
It seemed like it has to do something with starting and ending angles.
See these lines:

    if(!bClockwise && (ogrArcStartAngle < ogrArcEndAngle))
        ogrArcEndAngle = -180.0 + (linedir * a);

    if(bClockwise && (ogrArcStartAngle > ogrArcEndAngle))
        ogrArcEndAngle += 360.0;

These lines make sure that ogrArcStartAngle and ogrArcEndAngle angles agree with clockwise/anticlockwise arc direction.
I expected it to be symmetrical with respect to variable substitution.
So in first two-liner I replaced
ogrArcEndAngle = -180.0 + (linedir * a);
with
ogrArcStartAngle += 360.0; or ogrArcEndAngle -= 360.0;

This resolves the issue I described in this thread.
I don't mean to underestimate the existing line but it seems wrong to me.
I guess it might work for certain private cases.

Following the same "symmetry" argument I don't quite understand why there is a concern about the case:

    if(bClockwise && (linedir == 1.0))
        a += (linedir * 180.0);

but not about something like:

    if(!bClockwise && (linedir == -1.0))
        a += (linedir * 180.0);

@igorthy igorthy changed the title DXF polyline circle like shape wrongly recognized as single line segment DXF polyline circle like shape wrongly recognized as tiny arc segment Oct 1, 2019
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