예제 #1
0
 public HalfEdge(Edge edge, Side side) {
     Edge = edge;
     Side = side;
     Vertex = null;
     Left = null;
     Right = null;
 }
예제 #2
0
파일: Geometry.cs 프로젝트: craigge/dx11
 public static void EndPoint(Edge edge, Side side, Site site, VoronoiGraph c) {
     edge.Endpoint[side] = site;
     var opSide = side == Side.Left ? Side.Right : Side.Left;
     if (edge.Endpoint[opSide] == null) {
         return;
     }
     c.PlotEndpoint(edge);
 }
예제 #3
0
 public void EndPoint(Edge edge, Side side, Site site) {
     edge.Endpoint[side] = site;
     var opSide = side == Side.Left ? Side.Right : Side.Left;
     if (edge.Endpoint[opSide] == null) {
         return;
     }
     PlotEndpoint(edge);
 }
예제 #4
0
파일: Site.cs 프로젝트: virus-404/dx11
        private void Connect(List <Site> points, int j, RectangleF bounds, bool closingUp = false)
        {
            var rightPoint     = points.Last();
            var newEdge        = Edges[j];
            var newOrientation = EdgeOrientations[j];
            // the point that  must be connected to rightPoint:
            var newPoint = newEdge.ClippedEndpoints[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 (Math.Abs(rightPoint.X - newPoint.X) > Geometry.Tolerance && Math.Abs(rightPoint.Y - newPoint.Y) > Geometry.Tolerance)
                {
                    // 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)
                    var rightCheck = BoundsCheck.Check(rightPoint, bounds);
                    var newCheck   = BoundsCheck.Check(newPoint, bounds);

                    if (rightCheck.HasFlag(BoundsCheck.Sides.Right))
                    {
                        if (newCheck.HasFlag(BoundsCheck.Sides.Bottom))
                        {
                            points.Add(new Site(bounds.Right, bounds.Bottom));
                        }
                        else if (newCheck.HasFlag(BoundsCheck.Sides.Top))
                        {
                            points.Add(new Site(bounds.Right, bounds.Top));
                        }
                        else if (newCheck.HasFlag(BoundsCheck.Sides.Left))
                        {
                            var py = ((rightPoint.Y - bounds.Y + newPoint.Y - bounds.Y) < bounds.Height) ? bounds.Top : bounds.Bottom;
                            points.Add(new Site(bounds.Right, py));
                            points.Add(new Site(bounds.Left, py));
                        }
                    }
                    else if (rightCheck.HasFlag(BoundsCheck.Sides.Left))
                    {
                        if (newCheck.HasFlag(BoundsCheck.Sides.Bottom))
                        {
                            points.Add(new Site(bounds.Left, bounds.Bottom));
                        }
                        else if (newCheck.HasFlag(BoundsCheck.Sides.Top))
                        {
                            points.Add(new Site(bounds.Left, bounds.Top));
                        }
                        else if (newCheck.HasFlag(BoundsCheck.Sides.Right))
                        {
                            var py = ((rightPoint.Y - bounds.Y + newPoint.Y - bounds.Y) < bounds.Height) ? bounds.Top : bounds.Bottom;
                            points.Add(new Site(bounds.Left, py));
                            points.Add(new Site(bounds.Right, py));
                        }
                    }
                    else if (rightCheck.HasFlag(BoundsCheck.Sides.Top))
                    {
                        if (newCheck.HasFlag(BoundsCheck.Sides.Right))
                        {
                            points.Add(new Site(bounds.Right, bounds.Top));
                        }
                        else if (newCheck.HasFlag(BoundsCheck.Sides.Left))
                        {
                            points.Add(new Site(bounds.Left, bounds.Top));
                        }
                        else if (newCheck.HasFlag(BoundsCheck.Sides.Bottom))
                        {
                            var px = ((rightPoint.X - bounds.X + newPoint.X - bounds.X) < bounds.Width) ? bounds.Left : bounds.Right;
                            points.Add(new Site(px, bounds.Top));
                            points.Add(new Site(bounds.Left, bounds.Bottom));
                        }
                    }
                    else if (rightCheck.HasFlag(BoundsCheck.Sides.Bottom))
                    {
                        if (newCheck.HasFlag(BoundsCheck.Sides.Right))
                        {
                            points.Add(new Site(bounds.Right, bounds.Bottom));
                        }
                        else if (newCheck.HasFlag(BoundsCheck.Sides.Left))
                        {
                            points.Add(new Site(bounds.Left, bounds.Bottom));
                        }
                        else if (newCheck.HasFlag(BoundsCheck.Sides.Bottom))
                        {
                            var px = ((rightPoint.X - bounds.X + newPoint.X - bounds.X) < bounds.Width) ? bounds.Left : bounds.Right;
                            points.Add(new Site(px, bounds.Bottom));
                            points.Add(new Site(bounds.Left, bounds.Top));
                        }
                    }
                }
                if (closingUp)
                {
                    // newEdge's ends have already been added
                    return;
                }
                points.Add(newPoint);
            }
            var newRightPoint = newEdge.ClippedEndpoints[Side.Other(newOrientation)];

            if (!CloseEnough(points.First(), newRightPoint))
            {
                points.Add(newRightPoint);
            }
        }