Esempio n. 1
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. 2
0
        protected override DrawObject[] TrimDrawObject(Line line, DrawObjectTrimingInfo trimingInfo)
        {
            Vector2D[]   intersectPositions = trimingInfo.IntersectPositions;
            Rectangle2D2 trimArea           = trimingInfo.TrimArea;

            if (line == null)
            {
                return(null);
            }

            if (intersectPositions == null)
            {
                return(null);
            }

            if (trimArea == null)
            {
                return(null);
            }

            //将交点集合筛选(需在线段上,不包括端点),并沿线段起始到终止方向进行排序;
            intersectPositions = intersectPositions.
                                 Where(p => p.IsInLine(line.Line2D)).
                                 OrderBy(p => p.Distance(line.Line2D.Start)).
                                 ToArray();

            ///得到矩形与线段的所有交点(最多两个),通过该交点集合的与<param name="intersectPositions"/>的关系,进行裁剪;
            var rectInserserctPositions = trimArea.GetLines().
                                          Select(p => p.Intersect(line.Line2D)).
                                          Where(p => p != null).
                                          Distinct(Vector2DEqualityComparer.StaticInstance).
                                          ToArray();

            return(GetTrimedLineWithIntersectPositions(line, intersectPositions, rectInserserctPositions));
        }
Esempio n. 3
0
        /// <summary>
        /// 检查某个坐标是否处于某个矩形内部;
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static bool Contains(this Rectangle2D2 rect, Vector2D point)
        {
            if (rect == null)
            {
                throw new ArgumentNullException(nameof(rect));
            }

            if (point == null)
            {
                throw new ArgumentNullException(nameof(point));
            }

            return(point.IsInRegion(rect.GetLines().ToList()));
        }
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);
        }