Reads an ASCII DXF file into the same model the DWG reader gives, for the apps that list, convert or draw DXF content.
How the precision is kept
Each group value is typed by its code range: reals with parseFloat, whole numbers with parseInt in base 10. The only arithmetic is the conversion of the file's degrees to radians with one multiplication by π ÷ 180. A real that is not a finite number is read as 0.
Calculations under this policy
4 calculations in 1 source file. The code is read from the released app when this page loads. It is the calculation people run, not a copy kept for this page.
parseFloat gives the nearest 64-bit number to the decimal text. A real or whole-number value that is not finite is returned as 0, so a damaged number reads as zero and is not reported.
dxf-model.js
lines 27 to 38
CadCraft 0.8.2
/** The value of a group by its code range (DXF reference, "Group code value types"). */
function typed(code, v) {
if ((code >= 10 && code <= 59) || (code >= 110 && code <= 149) || (code >= 210 && code <= 239) || (code >= 460 && code <= 469) || (code >= 1010 && code <= 1059)) {
const x = parseFloat(v); return Number.isFinite(x) ? x : 0;
}
if ((code >= 60 && code <= 99) || (code >= 160 && code <= 179) || (code >= 270 && code <= 289) || (code >= 370 && code <= 389)
|| (code >= 400 && code <= 409) || (code >= 420 && code <= 429) || (code >= 440 && code <= 459) || (code >= 1060 && code <= 1071)) {
const x = parseInt(v, 10); return Number.isFinite(x) ? x : 0;
}
if (code >= 290 && code <= 299) return parseInt(v, 10) === 1;
return v;
}
Arc angles
64-bit
An arc's start and end angles in radians.
angle = degrees × (π ÷ 180)
The factor π ÷ 180 is computed once as a 64-bit constant and multiplied in, which can differ in the last digit from degrees × π ÷ 180 evaluated left to right as dxf.js does. The angles are not reduced modulo 2π here.
The direction vector of multi-line text, from the file's vector or from its rotation angle.
x axis = group 11 when present; otherwise (cos(a), sin(a)), a = degrees × (π ÷ 180)
The file's vector is copied when it has one. From an angle the vector is cosine and sine of the converted angle, so a 90 degree text gets x = 6.1e-17 and not 0.
The edges are kept as curves with their angles in radians; the turning direction is kept as a flag. Sampling into points is done by the code that uses the model; in CadCraft that is dwg-import.js.
dxf-model.js
lines 439 to 440
CadCraft 0.8.2
else if (type === 'arc') { const center = xy(10); const radius = at(40) ? take() : 0; const s = at(50) ? take() : 0, t = at(51) ? take() : 360; edges.push({ type, center, radius, startAngle: s * D2R, endAngle: t * D2R, ccw: at(73) ? take() === 1 : true }); }
else if (type === 'ellipse') { const center = xy(10), majorAxis = xy(11); const ratio = at(40) ? take() : 1; const s = at(50) ? take() : 0, t = at(51) ? take() : 360; edges.push({ type, center, majorAxis, ratio, startAngle: s * D2R, endAngle: t * D2R, ccw: at(73) ? take() === 1 : true }); }
In detail
Method
Typed by DXF group code range; angles × (π ÷ 180).
Number types
64-bit numbers; whole-number groups as integers.
Limits
A real value that cannot be read becomes 0 without a note. Hatch arc and ellipse edges keep their angles; they are not sampled here.
Approach: 64-bit, direct
Every value is a 64-bit number from input to result. Formulas are closed form or a direct solve, and every comparison uses a stated tolerance.