haplokuon / netDxf

.net dxf Reader-Writer
MIT License
966 stars 393 forks source link

Issues loading a DXF file with splines with flag SplineTypeFlags.ClosedPeriodicSpline #441

Closed meffe1984 closed 1 year ago

meffe1984 commented 1 year ago

I'm having difficulties loading a Dxf file that contains some splines, with the flag SplineTypeFlags.ClosedPeriodicSpline on. I've found that, during DxfReader.ReadSpline(), in this case, the code tries to remove a range of elements from two lists: controlPoints and weights. This RemoveRange fails when performed on the weights list, because it's empty. I've analyzed the dxf and in fact found a spline that adds control points (code 30) but not weights (code 41), and the dxf is read by other programs but also old versions of netDxf (v. 1.1.2.0). Reading some autodesk documentation, it seems like the weights on a spline are optional, with a default value of 1, so maybe the weights list should be filled along with the control points (with value 1) and then, eventually, overwritten if values are present.

Here is the spline

SPLINE
  5
4BE32
330
1F
100
AcDbEntity
  8
Note
100
AcDbSpline
210
0.0
220
0.0
230
1.0
 70
  3339
 71
     3
 72
    42
 73
    38
 74
     0
 42
0.000000001
 43
0.0000000001
 40
0.0
 40
0.0
 40
0.0
 40
0.0
 40
1.0
 40
2.0
 40
3.0
 40
4.0
 40
5.0
 40
6.0
 40
7.0
 40
8.0
 40
9.0
 40
10.0
 40
11.0
 40
12.0
 40
13.0
 40
14.0
 40
15.0
 40
16.0
 40
17.0
 40
18.0
 40
19.0
 40
20.0
 40
21.0
 40
22.0
 40
23.0
 40
24.0
 40
25.0
 40
26.0
 40
27.0
 40
28.0
 40
29.0
 40
30.0
 40
31.0
 40
32.0
 40
33.0
 40
34.0
 40
35.0
 40
35.0
 40
35.0
 40
35.0
 10
22489.92457403875
 20
187.5575489194193
 30
0.0
 10
22490.96023380807
 20
187.5382063233122
 30
0.0
 10
22492.21655333421
 20
188.3696976943009
 30
0.0
 10
22492.62031925205
 20
191.0616158650734
 30
0.0
 10
22492.46746187785
 20
196.1413299450243
 30
0.0
 10
22492.67512545683
 20
199.8873509123875
 30
0.0
 10
22491.62545949212
 20
209.5533367689147
 30
0.0
 10
22491.14933905796
 20
228.2491554893151
 30
0.0
 10
22492.24419589264
 20
224.8135375564376
 30
0.0
 10
22496.15333909237
 20
227.7881221177799
 30
0.0
 10
22495.41157222155
 20
233.4470497360686
 30
0.0
 10
22499.67544583439
 20
233.1070622151373
 30
0.0
 10
22512.36625433979
 20
232.1526825554123
 30
0.0
 10
22517.95119354178
 20
232.5939688543125
 30
0.0
 10
22521.59335205098
 20
232.5264472906245
 30
0.0
 10
22532.30357864085
 20
232.7268692325692
 30
0.0
 10
22537.87992569295
 20
233.4791909728486
 30
0.0
 10
22540.19034913067
 20
232.1275920002521
 30
0.0
 10
22539.87457637065
 20
238.2681540947291
 30
0.0
 10
22539.94279679389
 20
238.4697022725207
 30
0.0
 10
22535.15160755459
 20
239.6986436201711
 30
0.0
 10
22523.75618615891
 20
238.6691718987989
 30
0.0
 10
22512.77333034654
 20
238.5851415478941
 30
0.0
 10
22499.30736226225
 20
238.0926247424222
 30
0.0
 10
22491.27088117407
 20
237.9169903986567
 30
0.0
 10
22487.79817825399
 20
238.3688006070051
 30
0.0
 10
22482.46701053683
 20
236.0906712863705
 30
0.0
 10
22482.35094997013
 20
234.7456429622477
 30
0.0
 10
22481.62696164127
 20
229.6058707641098
 30
0.0
 10
22483.09009086371
 20
227.7642313138189
 30
0.0
 10
22483.16748450814
 20
219.0880956465761
 30
0.0
 10
22483.99775537258
 20
217.728822725111
 30
0.0
 10
22483.5741219579
 20
217.3487801613413
 30
0.0
 10
22485.92577947209
 20
201.2754895878984
 30
0.0
 10
22486.60370135442
 20
196.6509807783038
 30
0.0
 10
22486.00259471833
 20
188.4857532709435
 30
0.0
 10
22488.88891426944
 20
187.5768915155264
 30
0.0
 10
22489.92457403875
 20
187.5575489194193
 30
0.0
haplokuon commented 1 year ago

I will fix this in the next update. Next time upload the full DXF instead of just a piece of it, it makes my life a lot easier.

meffe1984 commented 1 year ago

I will fix this in the next update. Next time upload the full DXF instead of just a piece of it, it makes my life a lot easier.

Thank you very much. I'm sorry for the partial dxf file but it is not mine and I prefer to not share the whole file.