Esempio n. 1
0
        public static Line2D GetExtendLineWithIntersectPositions(Line2D line2D, Line2D[] extendLines, Vector2D[] intersectPositions, Rectangle2D2 rectIntersect)
        {
            if (extendLines.Length == 0)
            {
                return(null);
            }
            if (rectIntersect == null)
            {
                return(null);
            }
            if (intersectPositions.Length == 0)
            {
                return(null);
            }
            if (rectIntersect.Contains(line2D.Start) && rectIntersect.Contains(line2D.End) && intersectPositions.Length == 2)
            {
                var p1 = intersectPositions[0];
                var p2 = intersectPositions[1];
                if (line2D.Start.IsInLine(Line2D.Create(p1, line2D.End)))
                {
                    return(Line2D.Create(p1, p2));
                }
                return(Line2D.Create(p2, p1));
            }

            if (rectIntersect.Contains(line2D.Start))
            {
                return(Line2D.Create(intersectPositions.First(), line2D.End));
            }
            if (rectIntersect.Contains(line2D.End))
            {
                return(Line2D.Create(line2D.Start, intersectPositions.First()));
            }
            return(null);
        }
Esempio n. 2
0
        public override bool ObjectInRectangle(Rectangle2D2 rect, ICanvasScreenConvertable canvasProxy, bool anyPoint)
        {
            if (rect == null)
            {
                throw new ArgumentNullException(nameof(rect));
            }

            if (Ellipse2D == null)
            {
                return(false);
            }

            //无论是否为任意选中,若包含了,则能够选中;
            if (rect.Contains(Ellipse2D.Center) && rect.GetLines().All(p => p.Distance(Ellipse2D.Center) >= Ellipse2D.RadiusX))
            {
                return(true);
            }


            //若为任意点选中,矩形的四个顶点中,存在任意两点任意一点在椭圆内即可;
            if (anyPoint && rect.GetLines().Any(p => {
                var intersectPoints = Extension.IntersectWithLine(Ellipse2D, p);
                return((intersectPoints?.Length ?? 0) != 0);
            }))
            {
                return(rect.GetVertexes().Any(p => Ellipse2D.Contains(p)));
            }


            return(false);
        }
Esempio n. 3
0
        public static Line2D GetExtendMemberWithIntersectPositions(Line2D line2D, Line2D[] extendLines, Vector2D[] intersectPositions, Rectangle2D2 rectIntersect, double width, double gap)
        {
            if (extendLines.Length == 0)
            {
                return(null);
            }
            if (rectIntersect == null)
            {
                return(null);
            }
            if (intersectPositions.Length == 0)
            {
                return(null);
            }
            if (rectIntersect.Contains(line2D.Start) && rectIntersect.Contains(line2D.End) && intersectPositions.Length == 2)
            {
                var p1     = intersectPositions[0];
                var p2     = intersectPositions[1];
                var line1  = extendLines.First(x => p1.IsInLine(x));
                var angle1 = line1.Direction.AngleWith(line2D.Direction);
                var newP1  = GetExtendPoint(p1, -line2D.Direction, angle1, width, gap);
                var line2  = extendLines.First(x => p2.IsInLine(x));
                var angle2 = line2.Direction.AngleWith(line2D.Direction);
                var newP2  = GetExtendPoint(p2, line2D.Direction, angle2, width, gap);
                if (line2D.Start.IsInLine(Line2D.Create(p1, line2D.End)))
                {
                    return(Line2D.Create(newP1, newP2));
                }

                return(Line2D.Create(newP2, newP1));
            }

            if (rectIntersect.Contains(line2D.Start) && line2D.Start.IsInLine(Line2D.Create(intersectPositions.First(), line2D.End)))
            {
                var angle       = line2D.Direction.AngleWith(extendLines[0].Direction);
                var newEndPoint = GetExtendPoint(intersectPositions.First(), -line2D.Direction, angle, width, gap);
                return(Line2D.Create(newEndPoint, line2D.End));
            }

            if (rectIntersect.Contains(line2D.End) && line2D.End.IsInLine(Line2D.Create(intersectPositions.First(), line2D.Start)))
            {
                var angle       = line2D.Direction.AngleWith(extendLines[0].Direction);
                var newEndPoint = GetExtendPoint(intersectPositions.First(), line2D.Direction, angle, width, gap);
                return(Line2D.Create(line2D.Start, newEndPoint));
            }
            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// 判断某个矩形与某个线段的包含或相交(当<paramref name="anyPoint"/>为真时)关系;
        /// </summary>
        /// <param name="line2D"></param>
        /// <param name="rect"></param>
        /// <param name="anyPoint"></param>
        /// <returns></returns>
        public static bool LineInRectangle(Line2D line2D, Rectangle2D2 rect, bool anyPoint)
        {
            if (line2D == null)
            {
                return(false);
            }

            //若在完全在矩形内部,则返回为真;
            if (rect.Contains(line2D.Start) &&
                rect.Contains(line2D.End))
            {
                return(true);
            }
            //若任意可选为真,则矩形任意一条边与之存在相交即可;
            else if (anyPoint)
            {
                return(rect.GetLines()?.Any(p => p.Intersect(line2D) != null) ?? false);
            }
            return(false);
        }
Esempio n. 5
0
        public override bool ObjectInRectangle(Rectangle2D2 rect, ICanvasScreenConvertable canvasProxy, bool anyPoint)
        {
            if (rect == null)
            {
                throw new ArgumentNullException(nameof(rect));
            }

            if (Rectangle2D == null)
            {
                return(false);
            }

            //根据四个顶点的位置判断与指定矩形的包含关系;
            if (anyPoint)
            {
                return(Rectangle2D.GetVertexes()?.Any(p => rect.Contains(p)) ?? false);
            }
            else
            {
                return(Rectangle2D.GetVertexes()?.All(p => rect.Contains(p)) ?? false);
            }
        }