diff --git a/ExcellonScaler.cs b/ExcellonScaler.cs index bac7046..d8f3316 100644 --- a/ExcellonScaler.cs +++ b/ExcellonScaler.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Text.RegularExpressions; namespace DrillTools.Integration @@ -103,7 +104,7 @@ namespace DrillTools.Integration long xNew = (long)Math.Round(xOrig * kx); long yNew = (long)Math.Round(yOrig * ky); - return $"X{xNew}Y{yNew}"; + return $"X{FormatCoordinateValue(xNew)}Y{FormatCoordinateValue(yNew)}"; } /// @@ -148,7 +149,20 @@ namespace DrillTools.Integration long newEndX = cxNew + dx; long newEndY = cyNew + dy; - return $"X{newStartX}Y{newStartY}G85X{newEndX}Y{newEndY}"; + return + $"X{FormatCoordinateValue(newStartX)}Y{FormatCoordinateValue(newStartY)}" + + $"G85X{FormatCoordinateValue(newEndX)}Y{FormatCoordinateValue(newEndY)}"; + } + + /// + /// 将坐标数值格式化为钻带使用的 6 位坐标文本,负数保留负号。 + /// + private static string FormatCoordinateValue(long value) + { + if (value < 0) + return "-" + Math.Abs(value).ToString("D6", CultureInfo.InvariantCulture); + + return value.ToString("D6", CultureInfo.InvariantCulture); } } }