Ejemplo n.º 1
0
        private void Connect(List <Point> points, int j, Rectangle bounds, bool Closing)
        {
            Point rightPoint = points[points.Count - 1];
            Edge  nEdge      = edges[j];
            LR    nOrient    = edgeOrientations[j];
            Point nPoint     = nEdge.GetClippedEnds()[nOrient];

            if (CloseEnough(rightPoint, nPoint))
            {
                if ((rightPoint.x != nPoint.x) && (rightPoint.y != nPoint.y))
                {
                    int rightCheck = BoundsCheck.Check(rightPoint, bounds);
                    int nCheck     = BoundsCheck.Check(nPoint, bounds);

                    double pX;
                    double pY;

                    if ((rightCheck & BoundsCheck.RIGHT) != 0)
                    {
                        pX = bounds.right;
                        if ((nCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            pY = bounds.bottom;
                            points.Add(new Point(pX, pY));
                        }
                        else if ((nCheck & BoundsCheck.TOP) != 0)
                        {
                            pY = bounds.top;
                            points.Add(new Point(pX, pY));
                        }
                        else if ((nCheck & BoundsCheck.LEFT) != 0)
                        {
                            if (((rightPoint.y - bounds.y + nPoint.y) - bounds.y) < bounds.height)
                            {
                                pY = bounds.top;
                            }
                            else
                            {
                                pY = bounds.bottom;
                            }
                            points.Add(new Point(pX, pY));
                            points.Add(new Point(bounds.left, pY));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.LEFT) != 0)
                    {
                        pX = bounds.left;
                        if ((nCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            pY = bounds.bottom;
                            points.Add(new Point(pX, pY));
                        }
                        else if ((nCheck & BoundsCheck.TOP) != 0)
                        {
                            pY = bounds.top;
                            points.Add(new Point(pX, pY));
                        }
                        else if ((nCheck & BoundsCheck.RIGHT) != 0)
                        {
                            if (((rightPoint.y - bounds.y + nPoint.y) - bounds.y) < bounds.height)
                            {
                                pY = bounds.top;
                            }
                            else
                            {
                                pY = bounds.bottom;
                            }
                            points.Add(new Point(pX, pY));
                            points.Add(new Point(bounds.right, pY));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.TOP) != 0)
                    {
                        pY = bounds.top;
                        if ((nCheck & BoundsCheck.RIGHT) != 0)
                        {
                            pX = bounds.right;
                            points.Add(new Point(pX, pY));
                        }
                        else if ((nCheck & BoundsCheck.LEFT) != 0)
                        {
                            pX = bounds.left;
                            points.Add(new Point(pX, pY));
                        }
                        else if ((nCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            if (((rightPoint.x - bounds.x + nPoint.x) - bounds.x) < bounds.width)
                            {
                                pX = bounds.left;
                            }
                            else
                            {
                                pX = bounds.right;
                            }
                            points.Add(new Point(pX, pY));
                            points.Add(new Point(pX, bounds.bottom));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.BOTTOM) != 0)
                    {
                        pY = bounds.bottom;
                        if ((nCheck & BoundsCheck.RIGHT) != 0)
                        {
                            pX = bounds.right;
                            points.Add(new Point(pX, pY));
                        }
                        else if ((nCheck & BoundsCheck.LEFT) != 0)
                        {
                            pX = bounds.left;
                            points.Add(new Point(pX, pY));
                        }
                        else if ((nCheck & BoundsCheck.TOP) != 0)
                        {
                            if (((rightPoint.x - bounds.x + nPoint.x) - bounds.x) < bounds.width)
                            {
                                pX = bounds.left;
                            }
                            else
                            {
                                pX = bounds.right;
                            }
                            points.Add(new Point(pX, pY));
                            points.Add(new Point(pX, bounds.top));
                        }
                    }
                }

                if (Closing)
                {
                    return;
                }
                points.Add(nPoint);
            }
            Point nRightPoint = nEdge.GetClippedEnds()[LR.Other(nOrient)];

            if (!CloseEnough(points[0], nRightPoint))
            {
                points.Add(nRightPoint);
            }
        }
Ejemplo n.º 2
0
 public void AddEdge(Edge e)
 {
     edges.Add(e);
 }