fix: 3.175外围孔间距算法,兼容轮廓式分布和侧面凸出点
旧算法要求最上/最下排各≥2个点,无法处理角上只有单个孔的板边轮廓分布。 新算法:X间距取上下排边缘点的极值(过滤侧面凸出点),Y间距取所有点极值。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1935,20 +1935,30 @@ M30";
|
||||
if (points.Count < 4)
|
||||
return;
|
||||
|
||||
double topY = points.Max(point => point.Y);
|
||||
double bottomY = points.Min(point => point.Y);
|
||||
double minY = points.Min(point => point.Y);
|
||||
double maxY = points.Max(point => point.Y);
|
||||
|
||||
var topRowPoints = points.Where(point => Math.Abs(point.Y - topY) < 0.0001).ToList();
|
||||
var bottomRowPoints = points.Where(point => Math.Abs(point.Y - bottomY) < 0.0001).ToList();
|
||||
// X间距:取最上排和最下排点的X极值,过滤侧面凸出的异常点
|
||||
var edgePoints = points.Where(point => Math.Abs(point.Y - maxY) < 0.0001 || Math.Abs(point.Y - minY) < 0.0001).ToList();
|
||||
double edgeMinX = edgePoints.Min(point => point.X);
|
||||
double edgeMaxX = edgePoints.Max(point => point.X);
|
||||
|
||||
if (topRowPoints.Count < 2 || bottomRowPoints.Count < 2)
|
||||
return;
|
||||
double minX, maxX;
|
||||
if (Math.Abs(edgeMaxX - edgeMinX) > 0.0001)
|
||||
{
|
||||
// 上下排有多于1个不同的X值,说明是矩形布局
|
||||
minX = edgeMinX;
|
||||
maxX = edgeMaxX;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 上下排X全部相同(垂直排列),退回所有点的X极值
|
||||
minX = points.Min(point => point.X);
|
||||
maxX = points.Max(point => point.X);
|
||||
}
|
||||
|
||||
double leftX = Math.Min(topRowPoints.Min(point => point.X), bottomRowPoints.Min(point => point.X));
|
||||
double rightX = Math.Max(topRowPoints.Max(point => point.X), bottomRowPoints.Max(point => point.X));
|
||||
|
||||
Outer3175XSpacing = Math.Round(rightX - leftX, 3, MidpointRounding.AwayFromZero);
|
||||
Outer3175YSpacing = Math.Round(topY - bottomY, 3, MidpointRounding.AwayFromZero);
|
||||
Outer3175XSpacing = Math.Round(maxX - minX, 3, MidpointRounding.AwayFromZero);
|
||||
Outer3175YSpacing = Math.Round(maxY - minY, 3, MidpointRounding.AwayFromZero);
|
||||
HasOuter3175Spacing = true;
|
||||
|
||||
Debug.WriteLine($"[3.175外围孔] X间距={Outer3175XSpacing:F3}, Y间距={Outer3175YSpacing:F3}");
|
||||
|
||||
Reference in New Issue
Block a user