Exemplo n.º 1
0
        public static void RunTest4()
        {
            Rectangle rect    = new Rectangle(1, 1, 4, 4);
            Point     moveDir = new Point(0, 1);
            Point     p1      = new Point(1, 3);
            Point     p2      = new Point(4, 3);

            var delta = RectSegIntersection.GetOrthShiftUntilNoLongerOverlapRectSeg(rect, p1, p2, moveDir);
        }
Exemplo n.º 2
0
        public static void RunTest2()
        {
            Point     p1, p2;
            Rectangle rect1 = new Rectangle(1, 1, 4, 4);
            Point     pc1, pc2;
            double    a;


            p1 = new Point(-1, 0);
            p2 = new Point(2, 3);
            RectSegIntersection.ClipOnRect(rect1, p1, p2, out pc1, out pc2);

            a = RectSegIntersection.GetOverlapAmount(rect1, p1, p2);

            p1 = new Point(1, 0);
            p2 = new Point(5, 4);
            a  = RectSegIntersection.GetOverlapAmount(rect1, p1, p2);

            p1 = new Point(0, 4);
            p2 = new Point(4, 0);
            a  = RectSegIntersection.GetOverlapAmount(rect1, p1, p2);

            p1 = new Point(0, 4);
            p2 = new Point(4, 0);
            a  = RectSegIntersection.GetOverlapAmount(rect1, p1, p2);

            p1 = new Point(1, 5);
            p2 = new Point(5, 1);
            a  = RectSegIntersection.GetOverlapAmount(rect1, p1, p2);

            p1 = new Point(0, 1);
            p2 = new Point(5, 4);
            a  = RectSegIntersection.GetOverlapAmount(rect1, p1, p2);

            p1 = new Point(-1, 3);
            p2 = new Point(2, 6);
            a  = RectSegIntersection.GetOverlapAmount(rect1, p1, p2);

            bool intersect;

            p1        = new Point(-1, 3);
            p2        = new Point(2, 6);
            intersect = RectSegIntersection.Intersect(rect1, p1, p2);

            p1        = new Point(1, 2);
            p2        = new Point(1, 3);
            intersect = RectSegIntersection.Intersect(rect1, p1, p2);
            a         = RectSegIntersection.GetOverlapAmount(rect1, p1, p2);
        }
Exemplo n.º 3
0
        internal void InitNodePortEdges(IEnumerable <LgNodeInfo> nodes, IEnumerable <SymmetricSegment> segments)
        {
            NodePortEdges.Clear();
            NodeCenters.Clear();

            RTree <SymmetricSegment> rtree      = new RTree <SymmetricSegment>();
            RTree <Point>            pointRtree = new RTree <Point>();

            foreach (var seg in segments)
            {
                rtree.Add(new Rectangle(seg.A, seg.B), seg);

                pointRtree.Add(new Rectangle(seg.A), seg.A);
                pointRtree.Add(new Rectangle(seg.B), seg.B);
            }

            foreach (var node in nodes)
            {
                var bbox = node.BoundingBox.Clone();
                bbox.ScaleAroundCenter(0.9);
                NodePortEdges[node] = new List <SymmetricSegment>();
                var segInt = rtree.GetAllIntersecting(bbox).ToList();
                foreach (var seg in segInt)
                {
                    if (RectSegIntersection.Intersect(bbox, seg.A, seg.B))
                    {
                        NodePortEdges[node].Add(seg);
                    }
                    if (!(node.BoundingBox.Contains(seg.A) && node.BoundingBox.Contains(seg.B)))
                    {
                        Debug.Assert(false, "found long edge");
                    }
                }

                bbox = node.BoundingBox.Clone();
                bbox.ScaleAroundCenter(0.01);

                Point x;
                if (pointRtree.OneIntersecting(bbox, out x))
                {
                    NodeCenters[node] = x;
                }
            }
        }