private void CheckSeg(DrawContext dc, CadLayer layer, FigureSegment fseg) { CadFigure fig = fseg.Figure; int idxA = fseg.Index0; int idxB = fseg.Index1; Vector3d a = fseg.Point0.vector; Vector3d b = fseg.Point1.vector; if (fig.StoreList != null && fig.StoreList.Count > 1) { if (!CheckStorePoint) { return; } a = fseg.StoredPoint0.vector; b = fseg.StoredPoint1.vector; } Vector3d cwp = dc.DevPointToWorldPoint(Target.Pos); Vector3d xfaceNormal = dc.DevVectorToWorldVector(Target.DirX); Vector3d yfaceNormal = dc.DevVectorToWorldVector(Target.DirY); Vector3d cx = CadMath.CrossSegPlane(a, b, cwp, xfaceNormal); Vector3d cy = CadMath.CrossSegPlane(a, b, cwp, yfaceNormal); if (!cx.IsValid() && !cy.IsValid()) { return; } Vector3d p = VectorExt.InvalidVector3d; double mind = double.MaxValue; Vector3d dcenter = dc.WorldPointToDevPoint(CadMath.CenterPoint(a, b)); double centerDist = (dcenter - Target.Pos).Norm(); if (CheckPriority == Priority.NONE || centerDist < Range) { StackArray <Vector3d> vtbl = default; vtbl[0] = cx; vtbl[1] = cy; vtbl.Length = 2; for (int i = 0; i < vtbl.Length; i++) { Vector3d v = vtbl[i]; if (!v.IsValid()) { continue; } Vector3d devv = dc.WorldPointToDevPoint(v); double td = (devv - Target.Pos).Norm(); if (td < mind) { mind = td; p = v; } } } else { if (CheckPriority == Priority.PRIORITY_X) { p = cx; } else if (CheckPriority == Priority.PRIORITY_Y) { p = cy; } if (p.IsInvalid()) { return; } Vector3d devv = dc.WorldPointToDevPoint(p); mind = (devv - Target.Pos).Norm(); } if (!p.IsValid()) { return; } if (mind > Range) { return; } if (mind < MinDist) { MarkSeg.Layer = layer; MarkSeg.FigSeg = fseg; MarkSeg.CrossPoint = p; MarkSeg.CrossPointScrn = dc.WorldPointToDevPoint(p); MarkSeg.Distance = mind; MinDist = mind; } }