Пример #1
0
 public INodePoint NodePoint(UnitPoint unitPoint)
 {
     if (HitUtil.CircleHitPoint(this.P1, UCCanvas.GetThresholdWidth(this.radius), unitPoint))
     {
         return(new NodePointSingleDot(this));
     }
     return(null);
 }
Пример #2
0
        public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype)
        {
            float thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel);

            if (runningsnaptypes != null)
            {
                foreach (Type snaptype in runningsnaptypes)
                {
                    UnitPoint ptemp = UnitPoint.Empty;
                    if (snaptype == typeof(VertextSnapPoint))
                    {
                        ptemp = GetPointFromVertexId(eVertexId.LeftTopCorner);
                        if (HitUtil.CircleHitPoint(ptemp, thWidth, point))
                        {
                            return(new VertextSnapPoint(canvas, this, ptemp, (int)eVertexId.LeftTopCorner));//left top corner
                        }
                        ptemp = GetPointFromVertexId(eVertexId.RightBottomCorner);
                        if (HitUtil.CircleHitPoint(ptemp, thWidth, point))
                        {
                            return(new VertextSnapPoint(canvas, this, ptemp, (int)eVertexId.RightBottomCorner));//right bottom corner
                        }
                    }
                    if (snaptype == typeof(MidpointSnapPoint))
                    {
                        ptemp = GetPointFromVertexId(eVertexId.BottomEdgeMidPoint);
                        if (HitUtil.CircleHitPoint(ptemp, thWidth, point))
                        {
                            return(new MidpointSnapPoint(canvas, this, ptemp, (int)eVertexId.BottomEdgeMidPoint));//bottom edge center
                        }
                        ptemp = GetPointFromVertexId(eVertexId.TopEdgeMidPoint);
                        if (HitUtil.CircleHitPoint(ptemp, thWidth, point))
                        {
                            return(new MidpointSnapPoint(canvas, this, ptemp, (int)eVertexId.TopEdgeMidPoint));//top edge center
                        }
                        ptemp = GetPointFromVertexId(eVertexId.LeftEdgeMidPoint);
                        if (HitUtil.CircleHitPoint(ptemp, thWidth, point))
                        {
                            return(new MidpointSnapPoint(canvas, this, ptemp, (int)eVertexId.LeftEdgeMidPoint));//left edge center
                        }
                        ptemp = GetPointFromVertexId(eVertexId.RigthEdgeMidPoint);
                        if (HitUtil.CircleHitPoint(ptemp, thWidth, point))
                        {
                            return(new MidpointSnapPoint(canvas, this, ptemp, (int)eVertexId.RigthEdgeMidPoint));//right edge center
                        }
                    }
                    if (snaptype == typeof(CenterSnapPoint))
                    {
                        if (HitUtil.PointInPoint(m_center, point, thWidth))
                        {
                            return(new CenterSnapPoint(canvas, this, m_center));
                        }
                    }
                }
            }
            return(null);
        }
Пример #3
0
        private UnitPoint MidPoint(UnitPoint p1, UnitPoint p2, UnitPoint hitPoint)
        {
            UnitPoint midPoint = HitUtil.LineMidpoint(p1, p2);

            if (HitUtil.CircleHitPoint(midPoint, UCCanvas.GetThresholdWidth(), hitPoint))
            {
                return(midPoint);
            }
            return(UnitPoint.Empty);
        }
Пример #4
0
        UnitPoint MidPoint(ICanvas canvas, UnitPoint p1, UnitPoint p2, UnitPoint hitpoint)
        {
            UnitPoint mid     = HitUtil.LineMidpoint(p1, p2);
            float     thWidth = ThresholdWidth(canvas, Width);

            if (HitUtil.CircleHitPoint(mid, thWidth, hitpoint))
            {
                return(mid);
            }
            return(UnitPoint.Empty);
        }
Пример #5
0
        private UnitPoint MidPoint(ICanvas canvas, UnitPoint P1, UnitPoint P2, UnitPoint hitPoint)
        {
            UnitPoint midPoint       = HitUtil.LineMidpoint(P1, P2);
            float     thresholdWidth = UCCanvas.GetThresholdWidth();

            if (HitUtil.CircleHitPoint(midPoint, thresholdWidth, hitPoint))
            {
                return(midPoint);
            }
            return(UnitPoint.Empty);
        }
Пример #6
0
        public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint testPt, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype)
        {
            float thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel);

            if (runningsnaptypes != null)
            {
                foreach (Type snaptype in runningsnaptypes)
                {
                    if (snaptype == typeof(VertextSnapPoint))
                    {
                        if (HitUtil.CircleHitPoint(m_p1, thWidth, testPt))
                        {
                            return(new VertextSnapPoint(canvas, this, m_p1));
                        }
                        if (HitUtil.CircleHitPoint(m_p2, thWidth, testPt))
                        {
                            return(new VertextSnapPoint(canvas, this, m_p2));
                        }
                    }
                    if (snaptype == typeof(MidpointSnapPoint))
                    {
                        if (HitUtil.CircleHitPoint(m_center, thWidth, testPt))
                        {
                            return(new MidpointSnapPoint(canvas, this, m_center));
                        }
                    }
                }
                return(null);
            }
            if (usersnaptype == typeof(MidpointSnapPoint))
            {
                float[] midPt = { 0.0f, 0.0f };
                m_crv.Eval(0.5f, ref midPt[0], ref midPt[1]);
                return(new MidpointSnapPoint(canvas, this, new UnitPoint(midPt[0], midPt[1])));
            }
            if (usersnaptype == typeof(VertextSnapPoint))
            {
                double d1 = HitUtil.Distance(testPt, m_p1);
                double d2 = HitUtil.Distance(testPt, m_p2);
                if (d1 <= d2)
                {
                    return(new VertextSnapPoint(canvas, this, m_p1));
                }
                return(new VertextSnapPoint(canvas, this, m_p2));
            }
            if (usersnaptype == typeof(CenterSnapPoint))
            {
                return(new CenterSnapPoint(canvas, this, m_center));
            }
            return(null);
        }
Пример #7
0
        /// <summary>
        /// 判断线的端点是否在圆内,是则返回新构造的NodePointLine
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public INodePoint NodePoint(ICanvas canvas, UnitPoint point)
        {
            float thWidth = ThresholdWidth(canvas, Width);

            if (HitUtil.CircleHitPoint(m_p1, thWidth, point))
            {
                return(new RectangleTool(this, RectangleTool.ePoint.P1));
            }
            if (HitUtil.CircleHitPoint(m_p2, thWidth, point))
            {
                return(new RectangleTool(this, RectangleTool.ePoint.P2));
            }
            return(null);
        }
Пример #8
0
        public INodePoint NodePoint(UnitPoint unitPoint)
        {
            float thresholdWidth = UCCanvas.GetThresholdWidth();

            if (HitUtil.CircleHitPoint(this.P1, thresholdWidth, unitPoint))
            {
                return(new NodePointLine(this, NodePointLine.LinePoint.P1));
            }
            if (HitUtil.CircleHitPoint(this.P2, thresholdWidth, unitPoint))
            {
                return(new NodePointLine(this, NodePointLine.LinePoint.P2));
            }
            return(null);
        }
Пример #9
0
        /// <summary>
        /// 判断线的端点是否在圆内,是则返回新构造的NodePointLine
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public INodePoint NodePoint(ICanvas canvas, UnitPoint point)
        {
            float thWidth = ThresholdWidth(canvas, Width);

            if (HitUtil.CircleHitPoint(m_p1, thWidth, point))
            {
                return(new NodePointLine(this, NodePointLine.ePoint.P1));
            }
            if (HitUtil.CircleHitPoint(m_p2, thWidth, point))
            {
                return(new NodePointLine(this, NodePointLine.ePoint.P2));
            }
            return(null);
        }        /// <summary>
Пример #10
0
        /// <summary>
        /// 获取中点,返回四边中点
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="hitpoint"></param>
        /// <returns></returns>
        UnitPoint MidPoint(ICanvas canvas, UnitPoint p1, UnitPoint p2, UnitPoint hitpoint)
        {
            //MessageBox.Show("Mid");
            UnitPoint p3 = new UnitPoint(p1.X, p2.Y);
            UnitPoint p4 = new UnitPoint(p2.X, p1.Y);
            //UnitPoint mid1 = HitUtil.LineMidpoint(p1, p3);
            //UnitPoint mid2 = HitUtil.LineMidpoint(p1, p4);
            //UnitPoint mid3 = HitUtil.LineMidpoint(p3, p2);
            //UnitPoint mid4 = HitUtil.LineMidpoint(p4, p2);
            //UnitPoint mid5 = HitUtil.LineMidpoint(p1, p2);
            UnitPoint mid6    = HitUtil.LineMidpoint(p3, p3);
            UnitPoint mid7    = HitUtil.LineMidpoint(p4, p4);
            float     thWidth = ThresholdWidth(canvas, Width);

            Console.WriteLine("thWidth" + thWidth + "");
            //if (HitUtil.CircleHitPoint(mid1, thWidth, hitpoint))
            //{
            //    return mid1;
            //}
            //if (HitUtil.CircleHitPoint(mid2, thWidth, hitpoint))
            //{
            //    return mid2;
            //}
            //if (HitUtil.CircleHitPoint(mid3, thWidth, hitpoint))
            //{
            //    return mid3;
            //}
            //if (HitUtil.CircleHitPoint(mid4, thWidth, hitpoint))
            //{
            //    return mid4;
            //}
            //if (HitUtil.CircleHitPoint(mid5, thWidth, hitpoint))
            //{
            //    return mid5;
            //}
            if (HitUtil.CircleHitPoint(mid6, thWidth, hitpoint))
            {
                return(mid6);
            }
            if (HitUtil.CircleHitPoint(mid7, thWidth, hitpoint))
            {
                return(mid7);
            }

            return(UnitPoint.Empty);
        }
Пример #11
0
        public INodePoint NodePoint(ICanvas canvas, UnitPoint point)
        {
            float thWidth = 0.0f;

            if (canvas != null)
            {
                thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel);
            }
            if (HitUtil.CircleHitPoint(m_p1, thWidth, point))
            {
                return(new NodePointMultiConnectionLine(this, NodePointMultiConnectionLine.ePoint.P1));
            }
            if (HitUtil.CircleHitPoint(m_p2, thWidth, point))
            {
                return(new NodePointMultiConnectionLine(this, NodePointMultiConnectionLine.ePoint.P2));
            }
            return(null);
        }
Пример #12
0
        public INodePoint NodePoint(ICanvas canvas, UnitPoint point)
        {
            float thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel);

            if (HitUtil.CircleHitPoint(m_p1, thWidth, point))
            {
                return(new NodePointRectBase(this, NodePointRectBase.ePoint.P1));
            }
            if (HitUtil.CircleHitPoint(m_p3, thWidth, point))
            {
                return(new NodePointRectBase(this, NodePointRectBase.ePoint.P3));
            }
            if (HitUtil.CircleHitPoint(m_center, thWidth, point))
            {
                return(new NodePointRectBase(this, NodePointRectBase.ePoint.Center));
            }
            return(null);
        }
Пример #13
0
 public INodePoint NodePoint(ICanvas canvas, UnitPoint point)
 {
     try
     {
         float thWidth = ThresholdWidth(canvas, Width);
         if (HitUtil.CircleHitPoint(m_p1, thWidth, point))
         {
             return(new NodePointLine(this, NodePointLine.ePoint.P1));
         }
         if (HitUtil.CircleHitPoint(m_p2, thWidth, point))
         {
             return(new NodePointLine(this, NodePointLine.ePoint.P2));
         }
         return(null);
     }
     catch (Exception ex)
     { throw ex; }
 }
Пример #14
0
        /// <summary>
        /// 根据给定类型返回点的快照信息
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="point"></param>
        /// <param name="otherobj"></param>
        /// <param name="runningsnaptypes"></param>
        /// <param name="usersnaptype"></param>
        /// <returns></returns>
        ISnapPoint IDrawObject.SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype)
        {
            float thWidth = ThresholdWidth(canvas, Width);

            if (runningsnaptypes != null)
            {
                foreach (Type snaptype in runningsnaptypes)
                {
                    if (snaptype == typeof(VertextSnapPoint))
                    {
                        if (HitUtil.CircleHitPoint(m_p1, thWidth, point))
                        {
                            return(new VertextSnapPoint(canvas, this, m_p1));
                        }
                        if (HitUtil.CircleHitPoint(m_p2, thWidth, point))
                        {
                            return(new VertextSnapPoint(canvas, this, m_p2));
                        }
                        if (HitUtil.CircleHitPoint(m_p3, thWidth, point))
                        {
                            return(new VertextSnapPoint(canvas, this, m_p3));
                        }
                        if (HitUtil.CircleHitPoint(m_p4, thWidth, point))
                        {
                            return(new VertextSnapPoint(canvas, this, m_p4));
                        }
                        return(null);
                    }
                    if (snaptype == typeof(MidpointSnapPoint))
                    {
                        //UnitPoint p = MidPoint(canvas, m_p1, m_p2, point);
                        //if (p != UnitPoint.Empty)
                        //    return new MidpointSnapPoint(canvas, this, p);
                        return(null);
                    }
                    if (snaptype == typeof(IntersectSnapPoint))
                    {
                        return(null);
                    }
                }
            }
            return(null);
        }
Пример #15
0
        public eVertexId GetVertexIdFromPoint(UnitPoint pt)
        {
            float threshold = 1e-10f;
            float halfWidth, halfHeight;

            GetHalfWidthAndHeight(out halfWidth, out halfHeight);
            if (HitUtil.CircleHitPoint(m_p1, threshold, pt))
            {
                return(eVertexId.LeftTopCorner);
            }
            else if (HitUtil.CircleHitPoint(m_p3, threshold, pt))
            {
                return(eVertexId.RightBottomCorner);
            }

            UnitPoint ptemp = new UnitPoint(Center.X, Center.Y - halfHeight);

            if (HitUtil.CircleHitPoint(ptemp, threshold, pt))
            {
                return(eVertexId.BottomEdgeMidPoint);
            }

            ptemp = new UnitPoint(Center.X, Center.Y + halfHeight);
            if (HitUtil.CircleHitPoint(ptemp, threshold, pt))
            {
                return(eVertexId.TopEdgeMidPoint);
            }

            ptemp = new UnitPoint(Center.X - halfWidth, Center.Y);
            if (HitUtil.CircleHitPoint(ptemp, threshold, pt))
            {
                return(eVertexId.LeftEdgeMidPoint);
            }

            ptemp = new UnitPoint(Center.X + halfWidth, Center.Y);
            if (HitUtil.CircleHitPoint(ptemp, threshold, pt))
            {
                return(eVertexId.RigthEdgeMidPoint);
            }
            return(eVertexId.None);
        }
Пример #16
0
        public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint unitPoint, List <IDrawObject> drawObjects, Type[] runningSnapTypes, Type userSnapType)
        {
            float thWidth = UCCanvas.GetThresholdWidth();

            if (runningSnapTypes != null)
            {
                foreach (Type snaptype in runningSnapTypes)
                {
                    if (snaptype == typeof(VertextSnapPoint))
                    {
                        if (HitUtil.CircleHitPoint(this.LeftTopPoint, thWidth, unitPoint))
                        {
                            return(new VertextSnapPoint(canvas, this, this.LeftTopPoint));
                        }
                        if (HitUtil.CircleHitPoint(this.RightTopPoint, thWidth, unitPoint))
                        {
                            return(new VertextSnapPoint(canvas, this, this.RightTopPoint));
                        }
                        if (HitUtil.CircleHitPoint(this.RightBottomPoint, thWidth, unitPoint))
                        {
                            return(new VertextSnapPoint(canvas, this, this.RightBottomPoint));
                        }
                        if (HitUtil.CircleHitPoint(this.LeftBottomPoint, thWidth, unitPoint))
                        {
                            return(new VertextSnapPoint(canvas, this, this.LeftBottomPoint));
                        }
                    }
                    if (snaptype == typeof(MidpointSnapPoint))
                    {
                        UnitPoint p = MidPoint(this.LeftTopPoint, this.RightTopPoint, unitPoint);
                        if (p != UnitPoint.Empty)
                        {
                            return(new MidpointSnapPoint(canvas, this, p));
                        }
                    }
                }
                return(null);
            }
            return(null);
        }
Пример #17
0
        /// <summary>
        /// 图形控制点是否被选中
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public INodePoint NodePoint(ICanvas canvas, UnitPoint point)
        {
            float thWidth = ThresholdWidth(canvas, Width);

            if (HitUtil.CircleHitPoint(m_p1, thWidth, point))
            {
                return(new BezierCurveTool(this, BezierCurveTool.ePoint.P1));
            }
            if (HitUtil.CircleHitPoint(m_p2, thWidth, point))
            {
                return(new BezierCurveTool(this, BezierCurveTool.ePoint.P2));
            }
            if (HitUtil.CircleHitPoint(m_p3, thWidth, point))
            {
                return(new BezierCurveTool(this, BezierCurveTool.ePoint.P3));
            }
            if (HitUtil.CircleHitPoint(m_p4, thWidth, point))
            {
                return(new BezierCurveTool(this, BezierCurveTool.ePoint.P4));
            }
            return(null);
        }
Пример #18
0
        /// <summary>
        /// 根据给定类型返回点的快照信息
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="point"></param>
        /// <param name="otherobj"></param>
        /// <param name="runningsnaptypes"></param>
        /// <param name="usersnaptype"></param>
        /// <returns></returns>
        ISnapPoint IDrawObject.SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype)
        {
            float thWidth = ThresholdWidth(canvas, Width);

            if (runningsnaptypes != null)
            {
                foreach (Type snaptype in runningsnaptypes)
                {
                    if (snaptype == typeof(VertextSnapPoint))
                    {
                        if (HitUtil.CircleHitPoint(m_p1, thWidth, point))
                        {
                            return(new VertextSnapPoint(canvas, this, m_p1));
                        }
                        if (HitUtil.CircleHitPoint(m_p2, thWidth, point))
                        {
                            return(new VertextSnapPoint(canvas, this, m_p2));
                        }
                    }
                    if (snaptype == typeof(MidpointSnapPoint))
                    {
                        UnitPoint p = MidPoint(canvas, m_p1, m_p2, point);
                        if (p != UnitPoint.Empty)
                        {
                            return(new MidpointSnapPoint(canvas, this, p));
                        }
                    }
                    if (snaptype == typeof(IntersectSnapPoint))
                    {
                        Rectangle rectangle = Utils.FindObjectTypeInList(this, otherobj, typeof(Rectangle)) as Rectangle;
                        if (rectangle == null)
                        {
                            continue;
                        }
                        UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, rectangle.m_p1, rectangle.m_p2);
                        if (p != UnitPoint.Empty)
                        {
                            return(new IntersectSnapPoint(canvas, this, p));
                        }
                    }
                }
                return(null);
            }

            if (usersnaptype == typeof(MidpointSnapPoint))
            {
                return(new MidpointSnapPoint(canvas, this, HitUtil.LineMidpoint(m_p1, m_p2)));
            }
            if (usersnaptype == typeof(IntersectSnapPoint))
            {
                Rectangle rectangle = Utils.FindObjectTypeInList(this, otherobj, typeof(Rectangle)) as Rectangle;
                if (rectangle == null)
                {
                    return(null);
                }
                UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, rectangle.m_p1, rectangle.m_p2);
                if (p != UnitPoint.Empty)
                {
                    return(new IntersectSnapPoint(canvas, this, p));
                }
            }
            if (usersnaptype == typeof(VertextSnapPoint))
            {
                double d1 = HitUtil.Distance(point, m_p1);
                double d2 = HitUtil.Distance(point, m_p2);
                if (d1 <= d2)
                {
                    return(new VertextSnapPoint(canvas, this, m_p1));
                }
                return(new VertextSnapPoint(canvas, this, m_p2));
            }
            if (usersnaptype == typeof(NearestSnapPoint))
            {
                UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point);
                if (p != UnitPoint.Empty)
                {
                    return(new NearestSnapPoint(canvas, this, p));
                }
            }
            if (usersnaptype == typeof(PerpendicularSnapPoint))
            {
                UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point);
                if (p != UnitPoint.Empty)
                {
                    return(new PerpendicularSnapPoint(canvas, this, p));
                }
            }
            return(null);
        }
Пример #19
0
        public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint unitPoint, List <IDrawObject> drawObjects, Type[] runningSnapTypes, Type userSnapType)
        {
            float thWidth = UCCanvas.GetThresholdWidth();

            if (runningSnapTypes != null)
            {
                foreach (Type snaptype in runningSnapTypes)
                {
                    if (snaptype == typeof(VertextSnapPoint))
                    {
                        if (HitUtil.CircleHitPoint(this.P1, thWidth, unitPoint))
                        {
                            return(new VertextSnapPoint(canvas, this, this.P1));
                        }
                        if (HitUtil.CircleHitPoint(this.P2, thWidth, unitPoint))
                        {
                            return(new VertextSnapPoint(canvas, this, this.P2));
                        }
                    }
                    if (snaptype == typeof(MidpointSnapPoint))
                    {
                        UnitPoint p = MidPoint(canvas, this.P1, this.P2, unitPoint);
                        if (p != UnitPoint.Empty)
                        {
                            return(new MidpointSnapPoint(canvas, this, p));
                        }
                    }
                    if (snaptype == typeof(IntersectSnapPoint))
                    {
                        Line otherline = Utils.Utils.FindObjectTypeInList(this, drawObjects, typeof(Line)) as Line;
                        if (otherline == null)
                        {
                            continue;
                        }
                        UnitPoint p = HitUtil.LinesIntersectPoint(this.P1, this.P2, otherline.P1, otherline.P2);
                        if (p != UnitPoint.Empty)
                        {
                            return(new IntersectSnapPoint(canvas, this, p));
                        }
                    }
                }
                return(null);
            }

            if (userSnapType == typeof(MidpointSnapPoint))
            {
                return(new MidpointSnapPoint(canvas, this, HitUtil.LineMidpoint(this.P1, this.P2)));
            }
            if (userSnapType == typeof(IntersectSnapPoint))
            {
                Line otherline = Utils.Utils.FindObjectTypeInList(this, drawObjects, typeof(Line)) as Line;
                if (otherline == null)
                {
                    return(null);
                }
                UnitPoint p = HitUtil.LinesIntersectPoint(this.P1, this.P2, otherline.P1, otherline.P2);
                if (p != UnitPoint.Empty)
                {
                    return(new IntersectSnapPoint(canvas, this, p));
                }
            }
            if (userSnapType == typeof(VertextSnapPoint))
            {
                double d1 = HitUtil.Distance(unitPoint, this.P1);
                double d2 = HitUtil.Distance(unitPoint, this.P2);
                if (d1 <= d2)
                {
                    return(new VertextSnapPoint(canvas, this, this.P1));
                }
                return(new VertextSnapPoint(canvas, this, this.P2));
            }
            if (userSnapType == typeof(NearestSnapPoint))
            {
                UnitPoint p = HitUtil.NearestPointOnLine(this.P1, this.P2, unitPoint);
                if (p != UnitPoint.Empty)
                {
                    return(new NearestSnapPoint(canvas, this, p));
                }
            }
            if (userSnapType == typeof(PerpendicularSnapPoint))
            {
                UnitPoint p = HitUtil.NearestPointOnLine(this.P1, this.P2, unitPoint);
                if (p != UnitPoint.Empty)
                {
                    return(new PerpendicularSnapPoint(canvas, this, p));
                }
            }
            return(null);
        }
Пример #20
0
        public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobjs, Type[] runningsnaptypes, Type usersnaptype)
        {
            try
            {
                if (Type == LineType.Line || Type == LineType.Dote)
                {
                    float thWidth = ThresholdWidth(canvas, Width);
                    if (runningsnaptypes != null)
                    {
                        foreach (Type snaptype in runningsnaptypes)
                        {
                            if (snaptype == typeof(VertextSnapPoint))
                            {
                                if (HitUtil.CircleHitPoint(m_p1, thWidth, point))
                                {
                                    return(new VertextSnapPoint(canvas, this, m_p1));
                                }
                                if (HitUtil.CircleHitPoint(m_p2, thWidth, point))
                                {
                                    return(new VertextSnapPoint(canvas, this, m_p2));
                                }
                            }
                            //if (snaptype == typeof(MidpointSnapPoint))
                            //{
                            //    UnitPoint p = MidPoint(canvas, m_p1, m_p2, point);
                            //    if (p != UnitPoint.Empty)
                            //        return new MidpointSnapPoint(canvas, this, p);
                            //}
                            if (snaptype == typeof(IntersectSnapPoint))
                            {
                                LineTool otherline = Utiles.FindObjectTypeInList(this, otherobjs, typeof(LineTool)) as LineTool;
                                if (otherline == null)
                                {
                                    continue;
                                }
                                UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, otherline.m_p1, otherline.m_p2);
                                if (p != UnitPoint.Empty)
                                {
                                    return(new IntersectSnapPoint(canvas, this, p));
                                }
                            }
                        }
                        return(null);
                    }

                    //if (usersnaptype == typeof(MidpointSnapPoint))
                    //    return new MidpointSnapPoint(canvas, this, HitUtil.LineMidpoint(m_p1, m_p2));
                    if (usersnaptype == typeof(IntersectSnapPoint))
                    {
                        LineTool otherline = Utiles.FindObjectTypeInList(this, otherobjs, typeof(LineTool)) as LineTool;
                        if (otherline == null)
                        {
                            return(null);
                        }
                        UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, otherline.m_p1, otherline.m_p2);
                        if (p != UnitPoint.Empty)
                        {
                            return(new IntersectSnapPoint(canvas, this, p));
                        }
                    }
                    if (usersnaptype == typeof(VertextSnapPoint))
                    {
                        double d1 = HitUtil.Distance(point, m_p1);
                        double d2 = HitUtil.Distance(point, m_p2);
                        if (d1 <= d2)
                        {
                            return(new VertextSnapPoint(canvas, this, m_p1));
                        }
                        return(new VertextSnapPoint(canvas, this, m_p2));
                    }
                    if (usersnaptype == typeof(NearestSnapPoint))
                    {
                        UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point);
                        if (p != UnitPoint.Empty)
                        {
                            return(new NearestSnapPoint(canvas, this, p));
                        }
                    }
                    if (usersnaptype == typeof(PerpendicularSnapPoint))
                    {
                        UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point);
                        if (p != UnitPoint.Empty)
                        {
                            return(new PerpendicularSnapPoint(canvas, this, p));
                        }
                    }
                }
                return(null);
            }
            catch (Exception ex)
            { throw ex; }
        }