Class NcOutputDecimalDigits
- Namespace
- Hi.NcParsers.NcWriteback
- Assembly
- HiMech.dll
The decimal-digit counts the NC-optimization text writers use for the numeric words they rewrite, split into the three tag families the optimizer touches: coordinate words (X/Y/Z/I/J/K/R), rotary words (A/B/C, degrees) and the F word. Controllers alarm on words finer than their least input increment, so the digit counts must follow the SOURCE program instead of a fixed format — a source stated to three decimals must never come back optimized with a fourth (Scan(IEnumerable<string>, Func<string, IReadOnlyList<(int Start, int Length)>>) / Resolve(IEnumerable<string>, Func<string, IReadOnlyList<(int Start, int Length)>>)); the coordinate and rotary floors keep the re-interpolation resolution meaningful when the source states fewer.
Consumed by BOTH optimization output paths — the frozen HardNc
NcOptProc and the SoftNc SoftNcOptProc /
NcPatchWriter — from the same scan, so the Soft-vs-Hard
byte parity gates hold under any source digit count. The historical
hard-coded behavior (coordinates "F4", F "F2") is
HardNcLegacy; assign it to Fixed to restore
the pre-scan output shape process-wide.
public class NcOutputDecimalDigits
- Inheritance
-
NcOutputDecimalDigits
- Inherited Members
- Extension Methods
Remarks
The word-suppression tolerances travel with the digit counts: a
tolerance finer than the printed resolution emits words whose text
quantizes to the previous value. The derivations reproduce the frozen
HardNc constants exactly at the legacy digit counts
(posTolerance_mm = 1e-5, angleTolerance_rad = 1e-6 at four
digits — NcOptProc's RebuildPosSyntaxToNcLine),
and RoundFeedrate(double) reproduces the oracle's F2 grid
(Math.Round(x*100)/100) at two digits.
Constructors
NcOutputDecimalDigits(int, int, int)
Creates a fixed digit set (each count 0..15).
public NcOutputDecimalDigits(int coordinateDigits, int rotaryDigits, int feedrateDigits)
Parameters
Fields
MaxScannedDigits
Scan cap per family: beyond this the feedrate grid power leaves the double-exact integer range and the formats stop meaning anything physical.
public const int MaxScannedDigits = 9
Field Value
MinCoordinateDigits
Scan floor of CoordinateDigits — never coarser than 0.001 mm, or splition re-interpolation and compensation lose their meaning.
public const int MinCoordinateDigits = 3
Field Value
MinFeedrateDigits
Scan floor of FeedrateDigits — integer F words are the common source form and replay exactly.
public const int MinFeedrateDigits = 0
Field Value
MinRotaryDigits
Scan floor of RotaryDigits (0.001°).
public const int MinRotaryDigits = 3
Field Value
Properties
AngleTolerance_rad
Rotary-word suppression tolerance in radians. Scaled from the frozen
HardNc constant (1e-6 rad at the legacy four digits) by the
printed resolution.
public double AngleTolerance_rad { get; }
Property Value
CoordinateDigits
Decimal digits of coordinate words (X/Y/Z/I/J/K/R, mm).
public int CoordinateDigits { get; }
Property Value
CoordinateFormat
Numeric format of coordinate words, e.g. “F4” (see
FormatTagNumber(double, string) for the trailing-zero
trim).
public string CoordinateFormat { get; }
Property Value
FeedrateDigits
Decimal digits of the F word (mm/min).
public int FeedrateDigits { get; }
Property Value
FeedrateFormat
Numeric format of the F word.
public string FeedrateFormat { get; }
Property Value
Fixed
Process-wide fixed override: when non-null, Resolve(IEnumerable<string>, Func<string, IReadOnlyList<(int Start, int Length)>>)
returns it instead of scanning the source. Assign
HardNcLegacy to restore the historical fixed
“F4”/“F2” output shape. Null (the default) follows the
source digits.
public static NcOutputDecimalDigits Fixed { get; set; }
Property Value
HardNcLegacy
The historical hard-coded output shape: four decimals on coordinate and rotary words, two on the F word.
public static NcOutputDecimalDigits HardNcLegacy { get; }
Property Value
PosTolerance_mm
Coordinate-word suppression tolerance in mm: an axis whose motion
against the previous output line stays within it keeps the source
token text. One tenth of the printed resolution — 1e-5 at the
legacy four digits (the frozen HardNc constant).
public double PosTolerance_mm { get; }
Property Value
RotaryDigits
Decimal digits of rotary words (A/B/C, degrees).
public int RotaryDigits { get; }
Property Value
RotaryFormat
Numeric format of rotary words.
public string RotaryFormat { get; }
Property Value
Methods
Resolve(IEnumerable<string>, Func<string, IReadOnlyList<(int Start, int Length)>>)
The digit set an optimization run must use for the given played source: Fixed when set, otherwise Scan(IEnumerable<string>, Func<string, IReadOnlyList<(int Start, int Length)>>) over the source texts.
public static NcOutputDecimalDigits Resolve(IEnumerable<string> sourceBlockTexts, Func<string, IReadOnlyList<(int Start, int Length)>> commentSpanProvider)
Parameters
sourceBlockTextsIEnumerable<string>The played source line/block texts (null entries are skipped).
commentSpanProviderFunc<string, IReadOnlyList<(int Start, int Length)>>The brand comment-span provider (see GetCommentSpanProvider(string)); may be null (no masking).
Returns
RoundFeedrate(double)
Rounds a feedrate in mm/min to the F-word output grid — the value the
printed text parses back to. At the legacy two digits this is the
oracle's Math.Round(x*100)/100; every modal-F comparison must
round BOTH sides through this so representational errors cancel.
public double RoundFeedrate(double feedrate_mmdmin)
Parameters
feedrate_mmdmindouble
Returns
Scan(IEnumerable<string>, Func<string, IReadOnlyList<(int Start, int Length)>>)
Scans the played source texts for the maximum stated decimal-digit
count per tag family (comment spans masked; trailing zeros count —
they are the post's stated precision) and returns it floored at
MinCoordinateDigits / MinRotaryDigits /
MinFeedrateDigits and capped at
MaxScannedDigits. A word with no fractional digits
(X10, X10., F500.) states zero decimals.
public static NcOutputDecimalDigits Scan(IEnumerable<string> sourceBlockTexts, Func<string, IReadOnlyList<(int Start, int Length)>> commentSpanProvider)
Parameters
sourceBlockTextsIEnumerable<string>The played source line/block texts (null entries are skipped).
commentSpanProviderFunc<string, IReadOnlyList<(int Start, int Length)>>The brand comment-span provider (see GetCommentSpanProvider(string)); may be null (no masking).
Returns
ScanOmitsLeadingZero(IEnumerable<string>, Func<string, IReadOnlyList<(int Start, int Length)>>)
Reports how the source program spells numbers below one, over the same
tag families and masking as Scan(IEnumerable<string>, Func<string, IReadOnlyList<(int Start, int Length)>>):
true when the bare-dot form (X.348) prevails,
false when the zero-led form (X0.348) does,
and null when the source states no such word at all
and the question has no answer.
This is a report, not a policy: nothing applies it on its own, because the output style is process-wide (OmitLeadingZero) and the Soft-vs-Hard byte parity gates assume the zero-led default. A caller that wants the optimized program to diff cleanly against its source assigns the result to that knob.
public static bool? ScanOmitsLeadingZero(IEnumerable<string> sourceBlockTexts, Func<string, IReadOnlyList<(int Start, int Length)>> commentSpanProvider)
Parameters
sourceBlockTextsIEnumerable<string>The played source line/block texts (null entries are skipped).
commentSpanProviderFunc<string, IReadOnlyList<(int Start, int Length)>>The brand comment-span provider (see GetCommentSpanProvider(string)); may be null (no masking).
Returns
- bool?
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.