public VoronoiGraphImplemention(Voronoi v, int numLloyd, Random r, bool more) : base(v, numLloyd, r, more) { OCEAN = GetColor(ColorData.OCEAN); LAKE = GetColor(ColorData.LAKE); BEACH = GetColor(ColorData.BEACH); RIVER = GetColor(ColorData.RIVER); }
public static Vertex Intersect(HalfEdge hE0, HalfEdge hE1) { Edge e0; Edge e1; Edge e; HalfEdge hE; double determinant; double intersectionX; double intersectionY; bool rightOfSite; e0 = hE0.e; e1 = hE1.e; if (e0 == null || e1 == null) { return(null); } if (e0.GetRightSite() == e1.GetRightSite()) { return(null); } determinant = (e0.a * e1.b) - (e0.b * e1.a); if (determinant > -0.0000000001 && determinant < 0.0000000001) { return(null); } intersectionX = ((e0.c * e1.b) - (e1.c * e0.b)) / determinant; intersectionY = ((e1.c * e0.a) - (e0.c * e1.a)) / determinant; if (Voronoi.CompareByYThenX(e0.GetRightSite(), e1.GetRightSite()) < 0) { hE = hE0; e = e0; } else { hE = hE1; e = e1; } rightOfSite = intersectionX >= e.GetRightSite().coord.x; if ((rightOfSite && (hE.orientation == Orientation.LEFT)) || (!rightOfSite && (hE.orientation == Orientation.RIGHT))) { return(null); } return(Vertex.Create(intersectionX, intersectionY)); }
private void BuildGraph(Voronoi v) { Dictionary <Point, Center> pCMap = new Dictionary <Point, Center>(); List <Point> points = v.SiteCoords(); // For each point create a center foreach (Point p in points) { Center c = new Center(); c.loc = p; c.index = centers.Count; centers.Add(c); pCMap[p] = c; } // For each center, assign a region foreach (Center c in centers) { v.Region(c.loc); } List <Edge> libEdges = v.Edges(); Dictionary <int, Corner> pCRMap = new Dictionary <int, Corner>(); // For each edge in the voronoi edges foreach (Edge e in libEdges) { LineSegment vEdge = e.VoronoiEdge(); LineSegment dEdge = e.DelaunayLine(); DelaunayEdge dE = new DelaunayEdge(); dE.index = edges.Count; edges.Add(dE); // Setup midpoints for viable voronoi edges for noisy edge generation if (vEdge.p0 != null && vEdge.p1 != null) { dE.midPoint = InterpolatePoint(vEdge.p0, vEdge.p1, 0.5); } // Create corners for the voronoi vertices of the edge dE.v0 = MakeCorner(pCRMap, vEdge.p0); dE.v1 = MakeCorner(pCRMap, vEdge.p1); dE.d0 = pCMap[dEdge.p0]; dE.d1 = pCMap[dEdge.p1]; // Add borders for delaunay edges if (dE.d0 != null) { dE.d0.borders.Add(dE); } if (dE.d1 != null) { dE.d1.borders.Add(dE); } if (dE.v0 != null) { dE.v0.protrudes.Add(dE); } if (dE.v1 != null) { dE.v1.protrudes.Add(dE); } if (dE.d0 != null && dE.d1 != null) { AddToCenterList(dE.d0.neighbors, dE.d1); AddToCenterList(dE.d1.neighbors, dE.d0); } if (dE.v0 != null && dE.v1 != null) { AddToCornerList(dE.v0.adjacent, dE.v1); AddToCornerList(dE.v1.adjacent, dE.v0); } if (dE.d0 != null) { AddToCornerList(dE.d0.corners, dE.v0); AddToCornerList(dE.d0.corners, dE.v1); } if (dE.d1 != null) { AddToCornerList(dE.d1.corners, dE.v0); AddToCornerList(dE.d1.corners, dE.v1); } if (dE.v0 != null) { AddToCenterList(dE.v0.touches, dE.d0); AddToCenterList(dE.v0.touches, dE.d1); } if (dE.v1 != null) { AddToCenterList(dE.v1.touches, dE.d0); AddToCenterList(dE.v1.touches, dE.d1); } } }
public VoronoiGraph(Voronoi v, int numLloyd, Random r, bool more) { // MORE_RANDOM adds more height to everything using the random number generator this.MORE_RANDOM = more; this.r = r; // Angles used for Radial Map Generation bumps = r.Next(5) + 1; startAngle = r.NextDouble() * 2 * Math.PI; dipAngle = r.NextDouble() * 2 * Math.PI; dipWidth = r.NextDouble() * 0.5 + 0.2; // Gets the bounds bounds = v.GetPlotBounds(); // Applies Lloyd Relaxation to the points (moving the points to the center of the voronoi polygons, // then recreating the voronoi graph, makes things look more appealing to the eye) for (int i = 0; i < numLloyd; ++i) { List <Point> points = v.SiteCoords(); foreach (Point p in points) { List <Point> region = v.Region(p); double x = 0; double y = 0; foreach (Point c in region) { x += c.x; y += c.y; } x /= region.Count; y /= region.Count; p.x = x; p.y = y; } v = new Voronoi(points, v.GetPlotBounds()); } // Generates Simplex noise graph for Simplex Noise map generation MakeNoise(r.Next()); // Sets up the graph BuildGraph(v); // Fixes the corners because the Lloyd relaxation will have ruined them ImproveCorners(); // Assigns the elevations, determines oceans and land AssignCornerElevations(); AssignOceanCoastAndLand(); RedistributeElevations(LandCorners()); AssignPolygonElevations(); // Calculates the slopes, rivers, and general moisture CalculateDownSlopes(); CreateRivers(); AssignCornerMoisture(); RedistributeMoisture(LandCorners()); AssignPolygonMoisture(); // Assigns biomes based on height/moisture AssignBiomes(); // Creates noisy edges for each voronoi polygon for a more interesting look (toggleable) BuildNoisyEdges(); // Unused pixelCenterMap = new System.Drawing.Bitmap((int)bounds.width, (int)bounds.width); }