units module#
Coordinate grid and number formatting for every file this package writes.
Everything is metric. Gerber files declare %FSLAX46Y46*% with %MOMM*%, so a coordinate integer is a nanometer; XNC declares METRIC and writes decimal millimeters off the same integers. All rounding goes through this module so a point shared by a copper file and a drill file serializes identically in both.
- NM_PER_MM = 1000000#
Coordinate units per millimeter under FSLAX46Y46 with MOMM.
- DECIMALS = 6#
Decimal places in the coordinate format, and in every emitted decimal.
- HALF_STEP = 5e-07#
the largest error rounding can hide.
- Type:
Half the output grid step in mm
- nm(value)[source]#
Quantize a millimeter value onto the 1 nm output grid.
- Raises:
ValueError – the value is not finite.
- Return type:
- Parameters:
value (float)
- decimal(value)[source]#
Format a millimeter or degree value as a Gerber decimal.
Used for AD parameters, AM primitive parameters and XNC tool diameters, all of which take decimals rather than coordinate integers.
- xnc_decimal(value)[source]#
Format a millimeter value for an XNC coordinate or tool diameter.
The value comes off the 1 nm grid, so a drill hit and the copper around it agree exactly. Trailing zeros are trimmed, but never the decimal point: XNC permits a bare integer (“zero therefore must be encoded as 0”, 2.6), and readers descended from legacy Excellon reject one, because in that format a coordinate without a decimal point needs a number format the file does not carry. Writing 30.0 rather than 30 is a decimal either way and costs nothing.