示例#1
0
文件: Tracer.cs 项目: icprog/cnc
        private static SelectClosestTraceResult SelectClosestTrace(Point2D from, LinkedList <Trace> traces)
        {
            SelectClosestTraceResult bestResult = new SelectClosestTraceResult();
            double minDistance = double.MaxValue;

            foreach (Trace trace in traces)
            {
                if (trace.IsLoop)
                {
                    LoopDistanceResult distToLoop = DistanceToLoop(from, trace);
                    if (distToLoop.Value < minDistance)
                    {
                        minDistance             = distToLoop.Value;
                        bestResult.LoopDistance = distToLoop;
                        bestResult.Trace        = trace;
                        bestResult.NeedReverse  = false;
                    }
                }
                else
                {
                    double tostart     = Utils.Distance(trace.Entities.First.Value.Info.Start, from);
                    double toend       = Utils.Distance(trace.Entities.Last.Value.Info.End, from);
                    double distance    = Math.Min(tostart, toend);
                    bool   needReverse = toend < tostart;
                    if (distance < minDistance)
                    {
                        minDistance            = distance;
                        bestResult.Trace       = trace;
                        bestResult.NeedReverse = needReverse;
                    }
                }
            }
            return(bestResult);
        }
示例#2
0
文件: Tracer.cs 项目: icprog/cnc
        public static Trace ChooseTrace(Point2D from, LinkedList <Trace> traces)
        {
            SelectClosestTraceResult closestTraceRes = SelectClosestTrace(from, traces);

            // если ближайшим оказался цикл то разрезаем его по ближней точке
            if (closestTraceRes.Trace.IsLoop)
            {
                Entity            ent       = closestTraceRes.LoopDistance.Entity;
                Point2D           closest   = closestTraceRes.LoopDistance.Closest;
                DistancePointType pointType = closestTraceRes.LoopDistance.PointType;
                closestTraceRes.Trace.SplitLoop(ent, closest, pointType);
            }
            else
            {
                if (closestTraceRes.NeedReverse)
                {
                    Trace reversed = closestTraceRes.Trace.CreateReversed();
                    traces.Find(closestTraceRes.Trace).Value = reversed;
                    closestTraceRes.Trace = reversed;
                }
            }
            return(closestTraceRes.Trace);
        }