Esempio n. 1
0
            /// <summary>
            /// 外枠との交点を求める.
            /// 複数の交点がある場合,line.Startに最も近い点を返す.
            /// </summary>
            public virtual Point GetIntersectionPoint(Line line)
            {
                /// 単純にBoundsの矩形との交点を求める

                var lLine = _owner.LeftLine;
                var tLine = _owner.TopLine;
                var rLine = _owner.RightLine;
                var bLine = _owner.BottomLine;

                var pts = new List <Point>(4);

                if (line.IntersectsWith(lLine))
                {
                    pts.Add(line.GetIntersectionPoint(lLine));
                }
                if (line.IntersectsWith(tLine))
                {
                    pts.Add(line.GetIntersectionPoint(tLine));
                }
                if (line.IntersectsWith(rLine))
                {
                    pts.Add(line.GetIntersectionPoint(rLine));
                }
                if (line.IntersectsWith(bLine))
                {
                    pts.Add(line.GetIntersectionPoint(bLine));
                }

                return(pts.Count == 0? Point.Empty: pts.FindMin(pt => (int)PointUtil.GetDistance(line.Start, pt)));
            }
 /// <summary>
 /// 外枠との交点を求める.
 /// 複数の交点がある場合,line.Startに最も近い点を返す.
 /// </summary>
 public virtual Point GetIntersectionPoint(Line line)
 {
     using (_owner._ResourceCache.UseResource()) {
         var path = _owner._OutlinePathResouce;
         var ipts = new List <Point>();
         var pts  = path.PathPoints;
         for (int i = 0, len = pts.Length; i < len; ++i)
         {
             var pt1 = Point.Round(pts[i]);
             var pt2 = Point.Round(i + 1 < len? pts[i + 1]: pts[0]);
             if (pt1 != pt2)
             {
                 var l = new Line(pt1, pt2);
                 if (line.IntersectsWith(l))
                 {
                     ipts.Add(line.GetIntersectionPoint(l));
                 }
             }
         }
         return(ipts.Count == 0? Point.Empty: ipts.FindMin(pt => (int)PointUtil.GetDistance(line.Start, pt)));
     }
 }