コード例 #1
0
        private void Connect(List <Vector2> points, int j, Rect bounds, bool closingUp = false)
        {
            Vector2 rightPoint     = points [points.Count - 1];
            Edge    newEdge        = _edges [j] as Edge;
            Side    newOrientation = _edgeOrientations [j];

            // the point that  must be connected to rightPoint:
            if (newEdge.clippedEnds [newOrientation] == null)
            {
                Debug.LogError("XXX: Null detected when there should be a Vector2!");
            }
            Vector2 newPoint = (Vector2)newEdge.clippedEnds [newOrientation];

            if (!CloseEnough(rightPoint, newPoint))
            {
                // The points do not coincide, so they must have been clipped at the bounds;
                // see if they are on the same border of the bounds:
                if (rightPoint.x != newPoint.x &&
                    rightPoint.y != newPoint.y)
                {
                    // They are on different borders of the bounds;
                    // insert one or two corners of bounds as needed to hook them up:
                    // (NOTE this will not be correct if the region should take up more than
                    // half of the bounds rect, for then we will have gone the wrong way
                    // around the bounds and included the smaller part rather than the larger)
                    int   rightCheck = BoundsCheck.Check(rightPoint, bounds);
                    int   newCheck = BoundsCheck.Check(newPoint, bounds);
                    float px, py;
                    if ((rightCheck & BoundsCheck.RIGHT) != 0)
                    {
                        px = bounds.xMax;
                        if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            py = bounds.yMax;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            py = bounds.yMin;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            if (rightPoint.y - bounds.y + newPoint.y - bounds.y < bounds.height)
                            {
                                py = bounds.yMin;
                            }
                            else
                            {
                                py = bounds.yMax;
                            }
                            points.Add(new Vector2(px, py));
                            points.Add(new Vector2(bounds.xMin, py));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.LEFT) != 0)
                    {
                        px = bounds.xMin;
                        if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            py = bounds.yMax;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            py = bounds.yMin;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            if (rightPoint.y - bounds.y + newPoint.y - bounds.y < bounds.height)
                            {
                                py = bounds.yMin;
                            }
                            else
                            {
                                py = bounds.yMax;
                            }
                            points.Add(new Vector2(px, py));
                            points.Add(new Vector2(bounds.xMax, py));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.TOP) != 0)
                    {
                        py = bounds.yMin;
                        if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            px = bounds.xMax;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            px = bounds.xMin;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            if (rightPoint.x - bounds.x + newPoint.x - bounds.x < bounds.width)
                            {
                                px = bounds.xMin;
                            }
                            else
                            {
                                px = bounds.xMax;
                            }
                            points.Add(new Vector2(px, py));
                            points.Add(new Vector2(px, bounds.yMax));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.BOTTOM) != 0)
                    {
                        py = bounds.yMax;
                        if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            px = bounds.xMax;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            px = bounds.xMin;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            if (rightPoint.x - bounds.x + newPoint.x - bounds.x < bounds.width)
                            {
                                px = bounds.xMin;
                            }
                            else
                            {
                                px = bounds.xMax;
                            }
                            points.Add(new Vector2(px, py));
                            points.Add(new Vector2(px, bounds.yMin));
                        }
                    }
                }
                if (closingUp)
                {
                    // newEdge's ends have already been added
                    return;
                }
                points.Add(newPoint);
            }
            if (newEdge.clippedEnds [SideHelper.Other(newOrientation)] == null)
            {
                Debug.LogError("XXX: Null detected when there should be a Vector2!");
            }
            Vector2 newRightPoint = (Vector2)newEdge.clippedEnds [SideHelper.Other(newOrientation)];

            if (!CloseEnough(points [0], newRightPoint))
            {
                points.Add(newRightPoint);
            }
        }
コード例 #2
0
        private void Connect(List <Vector2> Vector2s, int j, Rect bounds, bool closingUp)
        {
            Vector2 rightVector2   = Vector2s[Vector2s.Count - 1];
            Edge    newEdge        = _edges[j] as Edge;
            LR      newOrientation = _edgeOrientations[j];
            // the Vector2 that  must be connected to rightVector2:
            Vector2 newVector2 = newEdge.ClippedEnds[newOrientation];

            if (!CloseEnough(rightVector2, newVector2))
            {
                // The Vector2s do not coincide, so they must have been clipped at the bounds;
                // see if they are on the same border of the bounds:
                if (rightVector2.x != newVector2.x &&
                    rightVector2.y != newVector2.y)
                {
                    // They are on different borders of the bounds;
                    // insert one or two corners of bounds as needed to hook them up:
                    // (NOTE this will not be corRect if the region should take up more than
                    // half of the bounds Rect, for then we will have gone the wrong way
                    // around the bounds and included the smaller part rather than the larger)
                    int   rightCheck = BoundsCheck.Check(rightVector2, bounds);
                    int   newCheck = BoundsCheck.Check(newVector2, bounds);
                    float px, py;
                    //throw new NotImplementedException("Modified, might not work");
                    if (rightCheck == BoundsCheck.RIGHT)
                    {
                        px = bounds.right;
                        if (newCheck == BoundsCheck.BOTTOM)
                        {
                            py = bounds.bottom;
                            Vector2s.Add(new Vector2(px, py));
                        }
                        else if (newCheck == BoundsCheck.TOP)
                        {
                            py = bounds.top;
                            Vector2s.Add(new Vector2(px, py));
                        }
                        else if (newCheck == BoundsCheck.LEFT)
                        {
                            if (rightVector2.y - bounds.y + newVector2.y - bounds.y < bounds.height)
                            {
                                py = bounds.top;
                            }
                            else
                            {
                                py = bounds.bottom;
                            }
                            Vector2s.Add(new Vector2(px, py));
                            Vector2s.Add(new Vector2(bounds.left, py));
                        }
                    }
                    else if (rightCheck == BoundsCheck.LEFT)
                    {
                        px = bounds.left;
                        if (newCheck == BoundsCheck.BOTTOM)
                        {
                            py = bounds.bottom;
                            Vector2s.Add(new Vector2(px, py));
                        }
                        else if (newCheck == BoundsCheck.TOP)
                        {
                            py = bounds.top;
                            Vector2s.Add(new Vector2(px, py));
                        }
                        else if (newCheck == BoundsCheck.RIGHT)
                        {
                            if (rightVector2.y - bounds.y + newVector2.y - bounds.y < bounds.height)
                            {
                                py = bounds.top;
                            }
                            else
                            {
                                py = bounds.bottom;
                            }
                            Vector2s.Add(new Vector2(px, py));
                            Vector2s.Add(new Vector2(bounds.right, py));
                        }
                    }
                    else if (rightCheck == BoundsCheck.TOP)
                    {
                        py = bounds.top;
                        if (newCheck == BoundsCheck.RIGHT)
                        {
                            px = bounds.right;
                            Vector2s.Add(new Vector2(px, py));
                        }
                        else if (newCheck == BoundsCheck.LEFT)
                        {
                            px = bounds.left;
                            Vector2s.Add(new Vector2(px, py));
                        }
                        else if (newCheck == BoundsCheck.BOTTOM)
                        {
                            if (rightVector2.x - bounds.x + newVector2.x - bounds.x < bounds.width)
                            {
                                px = bounds.left;
                            }
                            else
                            {
                                px = bounds.right;
                            }
                            Vector2s.Add(new Vector2(px, py));
                            Vector2s.Add(new Vector2(px, bounds.bottom));
                        }
                    }
                    else if (rightCheck == BoundsCheck.BOTTOM)
                    {
                        py = bounds.bottom;
                        if (newCheck == BoundsCheck.RIGHT)
                        {
                            px = bounds.right;
                            Vector2s.Add(new Vector2(px, py));
                        }
                        else if (newCheck == BoundsCheck.LEFT)
                        {
                            px = bounds.left;
                            Vector2s.Add(new Vector2(px, py));
                        }
                        else if (newCheck == BoundsCheck.TOP)
                        {
                            if (rightVector2.x - bounds.x + newVector2.x - bounds.x < bounds.width)
                            {
                                px = bounds.left;
                            }
                            else
                            {
                                px = bounds.right;
                            }
                            Vector2s.Add(new Vector2(px, py));
                            Vector2s.Add(new Vector2(px, bounds.top));
                        }
                    }
                }
                if (closingUp)
                {
                    // newEdge's ends have already been added
                    return;
                }
                Vector2s.Add(newVector2);
            }
            Vector2 newRightVector2 = newEdge.ClippedEnds[LR.Other(newOrientation)];

            if (!CloseEnough(Vector2s[0], newRightVector2))
            {
                Vector2s.Add(newRightVector2);
            }
        }
コード例 #3
0
ファイル: Site.cs プロジェクト: yinweli/unityAddon
        private void Connect(ref List <Vector2f> points, int j, Rectf bounds, bool closingUp = false)
        {
            Vector2f rightPoint     = points[points.Count - 1];
            Edge     newEdge        = edges[j];
            LR       newOrientation = edgeOrientations[j];

            // The point that must be conected to rightPoint:
            Vector2f newPoint = newEdge.ClippedEnds[newOrientation];

            if (!CloseEnough(rightPoint, newPoint))
            {
                // The points do not coincide, so they must have been clipped at the bounds;
                // see if they are on the same border of the bounds:
                if (rightPoint.x != newPoint.x && rightPoint.y != newPoint.y)
                {
                    // They are on different borders of the bounds;
                    // insert one or two corners of bounds as needed to hook them up:
                    // (NOTE this will not be correct if the region should take up more than
                    // half of the bounds rect, for then we will have gone the wrong way
                    // around the bounds and included the smaller part rather than the larger)
                    int   rightCheck = BoundsCheck.Check(rightPoint, bounds);
                    int   newCheck = BoundsCheck.Check(newPoint, bounds);
                    float px, py;
                    if ((rightCheck & BoundsCheck.RIGHT) != 0)
                    {
                        px = bounds.right;

                        if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            py = bounds.bottom;
                            points.Add(new Vector2f(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            py = bounds.top;
                            points.Add(new Vector2f(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            if (rightPoint.y - bounds.y + newPoint.y - bounds.y < bounds.height)
                            {
                                py = bounds.top;
                            }
                            else
                            {
                                py = bounds.bottom;
                            }
                            points.Add(new Vector2f(px, py));
                            points.Add(new Vector2f(bounds.left, py));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.LEFT) != 0)
                    {
                        px = bounds.left;

                        if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            py = bounds.bottom;
                            points.Add(new Vector2f(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            py = bounds.top;
                            points.Add(new Vector2f(px, py));
                        }
                        else if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            if (rightPoint.y - bounds.y + newPoint.y - bounds.y < bounds.height)
                            {
                                py = bounds.top;
                            }
                            else
                            {
                                py = bounds.bottom;
                            }
                            points.Add(new Vector2f(px, py));
                            points.Add(new Vector2f(bounds.right, py));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.TOP) != 0)
                    {
                        py = bounds.top;

                        if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            px = bounds.right;
                            points.Add(new Vector2f(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            px = bounds.left;
                            points.Add(new Vector2f(px, py));
                        }
                        else if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            if (rightPoint.x - bounds.x + newPoint.x - bounds.x < bounds.width)
                            {
                                px = bounds.left;
                            }
                            else
                            {
                                px = bounds.right;
                            }
                            points.Add(new Vector2f(px, py));
                            points.Add(new Vector2f(px, bounds.bottom));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.BOTTOM) != 0)
                    {
                        py = bounds.bottom;

                        if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            px = bounds.right;
                            points.Add(new Vector2f(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            px = bounds.left;
                            points.Add(new Vector2f(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            if (rightPoint.x - bounds.x + newPoint.x - bounds.x < bounds.width)
                            {
                                px = bounds.left;
                            }
                            else
                            {
                                px = bounds.right;
                            }
                            points.Add(new Vector2f(px, py));
                            points.Add(new Vector2f(px, bounds.top));
                        }
                    }
                }
                if (closingUp)
                {
                    // newEdge's ends have already been added
                    return;
                }
                points.Add(newPoint);
            }
            Vector2f newRightPoint = newEdge.ClippedEnds[LR.Other(newOrientation)];

            if (!CloseEnough(points[0], newRightPoint))
            {
                points.Add(newRightPoint);
            }
        }
コード例 #4
0
        private void Connect(List <Point> points, int j, Rect bounds, bool closingUp = false)
        {
            Point rightPoint     = points[points.Count - 1];
            Edge  newEdge        = _edges[j] as Edge;
            Side  newOrientation = _edgeOrientations[j];

            // the point that  must be connected to rightPoint:
            if (newEdge.clippedEnds[newOrientation] == null)
            {
                Debug.WriteLine("XXX: Null detected when there should be a Point!", "Error");
            }
            Point newPoint = (Point)newEdge.clippedEnds[newOrientation];

            if (!CloseEnough(rightPoint, newPoint))
            {
                // The points do not coincide, so they must have been clipped at the bounds;
                // see if they are on the same border of the bounds:
                if (rightPoint.X != newPoint.X &&
                    rightPoint.Y != newPoint.Y)
                {
                    // They are on different borders of the bounds;
                    // insert one or two corners of bounds as needed to hook them up:
                    // (NOTE this will not be correct if the region should take up more than
                    // half of the bounds rect, for then we will have gone the wrong way
                    // around the bounds and included the smaller part rather than the larger)
                    int    rightCheck = BoundsCheck.Check(rightPoint, bounds);
                    int    newCheck = BoundsCheck.Check(newPoint, bounds);
                    double px, py;
                    if ((rightCheck & BoundsCheck.RIGHT) != 0)
                    {
                        px = bounds.Right;
                        if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            py = bounds.Bottom;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            py = bounds.Top;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            if (rightPoint.Y - bounds.Y + newPoint.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 ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            py = bounds.Bottom;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            py = bounds.Top;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            if (rightPoint.Y - bounds.Y + newPoint.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 ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            px = bounds.Right;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            px = bounds.Left;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            if (rightPoint.X - bounds.X + newPoint.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 ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            px = bounds.Right;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            px = bounds.Left;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            if (rightPoint.X - bounds.X + newPoint.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 (closingUp)
                {
                    // newEdge's ends have already been added
                    return;
                }
                points.Add(newPoint);
            }
            if (newEdge.clippedEnds[SideHelper.Other(newOrientation)] == null)
            {
                Debug.WriteLine("XXX: Null detected when there should be a Point!", "Error");
            }
            Point newRightPoint = (Point)newEdge.clippedEnds[SideHelper.Other(newOrientation)];

            if (!CloseEnough(points[0], newRightPoint))
            {
                points.Add(newRightPoint);
            }
        }
コード例 #5
0
        private void Connect(List <PointF> PointFs, int j, RectangleF bounds, bool closingUp)
        {
            PointF rightPointF    = PointFs[PointFs.Count - 1];
            Edge   newEdge        = _edges[j] as Edge;
            LR     newOrientation = _edgeOrientations[j];
            // the PointF that  must be connected to rightPointF:
            PointF newPointF = newEdge.ClippedEnds[newOrientation];

            if (!CloseEnough(rightPointF, newPointF))
            {
                // The PointFs do not coincide, so they must have been clipped at the bounds;
                // see if they are on the same border of the bounds:
                if (rightPointF.X != newPointF.X &&
                    rightPointF.Y != newPointF.Y)
                {
                    // They are on different borders of the bounds;
                    // insert one or two corners of bounds as needed to hook them up:
                    // (NOTE this will not be corRectangleF if the region should take up more than
                    // half of the bounds RectangleF, for then we will have gone the wrong way
                    // around the bounds and included the smaller part rather than the larger)
                    int   rightCheck = BoundsCheck.Check(rightPointF, bounds);
                    int   newCheck = BoundsCheck.Check(newPointF, bounds);
                    float px, py;
                    //throw new NotImplementedException("Modified, might not work");
                    if (rightCheck == BoundsCheck.RIGHT)
                    {
                        px = bounds.Right;
                        if (newCheck == BoundsCheck.BOTTOM)
                        {
                            py = bounds.Bottom;
                            PointFs.Add(new PointF(px, py));
                        }
                        else if (newCheck == BoundsCheck.TOP)
                        {
                            py = bounds.Top;
                            PointFs.Add(new PointF(px, py));
                        }
                        else if (newCheck == BoundsCheck.LEFT)
                        {
                            if (rightPointF.Y - bounds.Y + newPointF.Y - bounds.Y < bounds.Height)
                            {
                                py = bounds.Top;
                            }
                            else
                            {
                                py = bounds.Bottom;
                            }
                            PointFs.Add(new PointF(px, py));
                            PointFs.Add(new PointF(bounds.Left, py));
                        }
                    }
                    else if (rightCheck == BoundsCheck.LEFT)
                    {
                        px = bounds.Left;
                        if (newCheck == BoundsCheck.BOTTOM)
                        {
                            py = bounds.Bottom;
                            PointFs.Add(new PointF(px, py));
                        }
                        else if (newCheck == BoundsCheck.TOP)
                        {
                            py = bounds.Top;
                            PointFs.Add(new PointF(px, py));
                        }
                        else if (newCheck == BoundsCheck.RIGHT)
                        {
                            if (rightPointF.Y - bounds.Y + newPointF.Y - bounds.Y < bounds.Height)
                            {
                                py = bounds.Top;
                            }
                            else
                            {
                                py = bounds.Bottom;
                            }
                            PointFs.Add(new PointF(px, py));
                            PointFs.Add(new PointF(bounds.Right, py));
                        }
                    }
                    else if (rightCheck == BoundsCheck.TOP)
                    {
                        py = bounds.Top;
                        if (newCheck == BoundsCheck.RIGHT)
                        {
                            px = bounds.Right;
                            PointFs.Add(new PointF(px, py));
                        }
                        else if (newCheck == BoundsCheck.LEFT)
                        {
                            px = bounds.Left;
                            PointFs.Add(new PointF(px, py));
                        }
                        else if (newCheck == BoundsCheck.BOTTOM)
                        {
                            if (rightPointF.X - bounds.X + newPointF.X - bounds.X < bounds.Width)
                            {
                                px = bounds.Left;
                            }
                            else
                            {
                                px = bounds.Right;
                            }
                            PointFs.Add(new PointF(px, py));
                            PointFs.Add(new PointF(px, bounds.Bottom));
                        }
                    }
                    else if (rightCheck == BoundsCheck.BOTTOM)
                    {
                        py = bounds.Bottom;
                        if (newCheck == BoundsCheck.RIGHT)
                        {
                            px = bounds.Right;
                            PointFs.Add(new PointF(px, py));
                        }
                        else if (newCheck == BoundsCheck.LEFT)
                        {
                            px = bounds.Left;
                            PointFs.Add(new PointF(px, py));
                        }
                        else if (newCheck == BoundsCheck.TOP)
                        {
                            if (rightPointF.X - bounds.X + newPointF.X - bounds.X < bounds.Width)
                            {
                                px = bounds.Left;
                            }
                            else
                            {
                                px = bounds.Right;
                            }
                            PointFs.Add(new PointF(px, py));
                            PointFs.Add(new PointF(px, bounds.Top));
                        }
                    }
                }
                if (closingUp)
                {
                    // newEdge's ends have already been added
                    return;
                }
                PointFs.Add(newPointF);
            }
            PointF newRightPointF = newEdge.ClippedEnds[LR.Other(newOrientation)];

            if (!CloseEnough(PointFs[0], newRightPointF))
            {
                PointFs.Add(newRightPointF);
            }
        }
コード例 #6
0
ファイル: Site.cs プロジェクト: imoduatv/Bottle-Shooting-Game
        private void Connect(List <Vector2> points, int j, Rect bounds, bool closingUp = false)
        {
            Vector2 vector = points[points.Count - 1];
            Edge    edge   = _edges[j];
            Side    side   = _edgeOrientations[j];

            if (!edge.clippedEnds[side].HasValue)
            {
                UnityEngine.Debug.LogError("XXX: Null detected when there should be a Vector2!");
            }
            Vector2 value = edge.clippedEnds[side].Value;

            if (!CloseEnough(vector, value))
            {
                if (vector.x != value.x && vector.y != value.y)
                {
                    int num  = BoundsCheck.Check(vector, bounds);
                    int num2 = BoundsCheck.Check(value, bounds);
                    if ((num & BoundsCheck.RIGHT) != 0)
                    {
                        float xMax = bounds.xMax;
                        if ((num2 & BoundsCheck.BOTTOM) != 0)
                        {
                            float yMax = bounds.yMax;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.TOP) != 0)
                        {
                            float yMax = bounds.yMin;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.LEFT) != 0)
                        {
                            float yMax = (!(vector.y - bounds.y + value.y - bounds.y < bounds.height)) ? bounds.yMax : bounds.yMin;
                            points.Add(new Vector2(xMax, yMax));
                            points.Add(new Vector2(bounds.xMin, yMax));
                        }
                    }
                    else if ((num & BoundsCheck.LEFT) != 0)
                    {
                        float xMax = bounds.xMin;
                        if ((num2 & BoundsCheck.BOTTOM) != 0)
                        {
                            float yMax = bounds.yMax;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.TOP) != 0)
                        {
                            float yMax = bounds.yMin;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.RIGHT) != 0)
                        {
                            float yMax = (!(vector.y - bounds.y + value.y - bounds.y < bounds.height)) ? bounds.yMax : bounds.yMin;
                            points.Add(new Vector2(xMax, yMax));
                            points.Add(new Vector2(bounds.xMax, yMax));
                        }
                    }
                    else if ((num & BoundsCheck.TOP) != 0)
                    {
                        float yMax = bounds.yMin;
                        if ((num2 & BoundsCheck.RIGHT) != 0)
                        {
                            float xMax = bounds.xMax;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.LEFT) != 0)
                        {
                            float xMax = bounds.xMin;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.BOTTOM) != 0)
                        {
                            float xMax = (!(vector.x - bounds.x + value.x - bounds.x < bounds.width)) ? bounds.xMax : bounds.xMin;
                            points.Add(new Vector2(xMax, yMax));
                            points.Add(new Vector2(xMax, bounds.yMax));
                        }
                    }
                    else if ((num & BoundsCheck.BOTTOM) != 0)
                    {
                        float yMax = bounds.yMax;
                        if ((num2 & BoundsCheck.RIGHT) != 0)
                        {
                            float xMax = bounds.xMax;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.LEFT) != 0)
                        {
                            float xMax = bounds.xMin;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.TOP) != 0)
                        {
                            float xMax = (!(vector.x - bounds.x + value.x - bounds.x < bounds.width)) ? bounds.xMax : bounds.xMin;
                            points.Add(new Vector2(xMax, yMax));
                            points.Add(new Vector2(xMax, bounds.yMin));
                        }
                    }
                }
                if (closingUp)
                {
                    return;
                }
                points.Add(value);
            }
            if (!edge.clippedEnds[SideHelper.Other(side)].HasValue)
            {
                UnityEngine.Debug.LogError("XXX: Null detected when there should be a Vector2!");
            }
            Vector2 value2 = edge.clippedEnds[SideHelper.Other(side)].Value;

            if (!CloseEnough(points[0], value2))
            {
                points.Add(value2);
            }
        }