示例#1
0
文件: Geometry.cs 项目: icprog/cnc
        public override DistanceResult Distance(Point2D from)
        {
            DistanceResult res      = new DistanceResult();
            double         angle    = CalcAngle(from);
            double         endAngle = Utils.NormalizeAngle(StartAngle + SweepAngle);

            if (IsAngleOnArc(angle) && angle != StartAngle && angle != endAngle)
            {
                double distFromCntr = Utils.Distance(from, Center);
                res.Value     = Math.Abs(distFromCntr - Radius);
                res.Closest   = CalcPoint(angle);
                res.PointType = DistancePointType.Other;
            }
            else
            {
                Point2D startPoint = CalcPoint(StartAngle);
                Point2D endPoint   = CalcPoint(endAngle);
                double  l1         = Utils.Distance(from, startPoint);
                double  l2         = Utils.Distance(from, endPoint);
                if (l1 <= l2)
                {
                    res.Value     = l1;
                    res.Closest   = startPoint;
                    res.PointType = DistancePointType.Start;
                }
                else
                {
                    res.Value     = l2;
                    res.Closest   = endPoint;
                    res.PointType = DistancePointType.End;
                }
            }
            return(res);
        }
示例#2
0
文件: Geometry.cs 项目: icprog/cnc
        public override DistanceResult Distance(Point2D from)
        {
            DistanceResult res = new DistanceResult();
            double         d1  = Utils.Distance(from, StartPoint);
            double         d2  = Utils.Distance(from, EndPoint);
            Point2D        closest;
            double         dm = Utils.DistanceXYFromLine(from, StartPoint, EndPoint, out closest);

            if (d1 <= d2 && d1 <= dm)
            {
                res.Value     = d1;
                res.Closest   = StartPoint;
                res.PointType = DistancePointType.Start;
            }
            else if (d2 <= dm)
            {
                res.Value     = d2;
                res.Closest   = EndPoint;
                res.PointType = DistancePointType.End;
            }
            else
            {
                res.Value     = dm;
                res.Closest   = closest;
                res.PointType = DistancePointType.Other;
            }
            return(res);
        }
示例#3
0
文件: Tracer.cs 项目: icprog/cnc
        private static LoopDistanceResult DistanceToLoop(Point2D from, Trace trace)
        {
            LoopDistanceResult minDist = new LoopDistanceResult();

            minDist.Value = double.MaxValue;
            foreach (Entity ent in trace.Entities)
            {
                DistanceResult dist = ent.Distance(from);
                if (minDist.Value > dist.Value)
                {
                    minDist.Value     = dist.Value;
                    minDist.Entity    = ent;
                    minDist.Closest   = dist.Closest;
                    minDist.PointType = dist.PointType;
                }
            }
            return(minDist);
        }
示例#4
0
        public void Visit(Arc arc)
        {
            // проверяем указывает ли на дугу
            DistanceResult dist = arc.Distance(Cursor);

            Match = dist.Value < Epsilon / 2;
            if (Match)
            {
                switch (dist.PointType)
                {
                case DistancePointType.Start:
                    MatchPoint = true;
                    Pt         = dist.Closest;
                    break;

                case DistancePointType.End:
                    MatchPoint = true;
                    Pt         = dist.Closest;
                    break;
                }
            }
        }