Skip to content

Commit

Permalink
DXF: Don't assume the knot vector starts with 0 when generating a spline
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.osgeo.org/gdal/trunk@41250 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
atlight committed Jan 12, 2018
1 parent c98fc01 commit e1ab235
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
74 changes: 73 additions & 1 deletion autotest/ogr/data/additional-entities.dxf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ AC1027
9
$HANDSEED
5
2CC0
EEFFF
0
ENDSEC
0
Expand Down Expand Up @@ -1573,6 +1573,78 @@ AcDbEntity
6
Continuous
0
SPLINE
5
EEFA2
330
EEEEE
100
AcDbEntity
8
0
100
AcDbSpline
210
-0.0871669981298796
220
0.0027239686914402
230
0.9961899891243605
70
8
71
3
72
8
73
4
74
0
42
0.000000001
43
0.0000000001
40
0.9999632527533043
40
0.9999632527533043
40
0.9999632527533043
40
0.9999632527533043
40
1.0
40
1.0
40
1.0
40
1.0
10
0.0
20
20.0
30
0.0
10
5.4
20
18.3
30
0.0
10
7.8
20
13.3
30
0.0
10
8.9
20
4.5
30
0.0
0
ENDSEC
0
SECTION
Expand Down
8 changes: 8 additions & 0 deletions autotest/ogr/ogr_dxf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3719,6 +3719,14 @@ def ogr_dxf_52():
f.DumpReadable()
return 'fail'

# Also throw in a test of a weird SPLINE generated by a certain CAD package
# with a knot vector that does not start at zero
f = lyr.GetNextFeature()
if ogrtest.check_feature_geometry(f, 'LINESTRING (0 20,0.513272464826192 19.8251653183892,1.00815682586353 19.629626397244,1.48499546839613 19.4132825350102,1.94413077770813 19.1760330301337,2.38590513908363 18.9177771810603,2.81066093780676 18.6384142862359,3.21874055916165 18.3378436441062,3.61048638843241 18.0159645531172,3.98624081090316 17.6726763117148,4.34634621185803 17.3078782183446,4.69114497658114 16.9214695714527,5.02097949035661 16.5133496694848,5.33619213846856 16.0834178108867,5.63712530620111 15.6315732941045,5.92412137883838 15.1577154175837,6.1975227416645 14.6617434797705,6.45767177996359 14.1435567791104,6.70491087901976 13.6030546140496,6.93958242411715 13.0401362830336,7.16202880053986 12.4547010845085,7.37259239357203 11.8466483169201,7.57161558849776 11.2158772787141,7.7594407706012 10.5622872683365,7.93641032516645 9.88577758423314,8.10286663747763 9.18624752484979,8.25915209281888 8.46359638863234,8.4056090764743 7.71772347402662,8.54257997372803 6.94852807947849,8.67040716986418 6.1559095034338,8.78943305016688 5.33976704433838,8.9 4.5)') != 0:
gdaltest.post_reason( 'Wrong geometry on SPLINE' )
f.DumpReadable()
return 'fail'

return 'success'

###############################################################################
Expand Down
9 changes: 6 additions & 3 deletions gdal/ogr/ogrsf_frmts/dxf/intronurbs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,15 @@ void rbspline2( int npts,int k,int p1,double b[],double h[],

/* calculate the points on the rational B-spline curve */

double t = 0.0;
const double step = ((double)knots[nplusc])/((double)(p1-1));
double t = knots[1];
const double step = (knots[nplusc]-knots[1])/((double)(p1-1));

const double eps = 5e-6 * (knots[nplusc]-knots[1]);

for( int i1 = 1; i1<= p1; i1++ )
{
if( (double)knots[nplusc] - t < 5e-6 )
/* avoid undershooting the final knot */
if( (double)knots[nplusc] - t < eps )
{
t = (double)knots[nplusc];
}
Expand Down

0 comments on commit e1ab235

Please sign in to comment.