public generateVoronoi ( Array xValuesIn, Array yValuesIn, double minX, double maxX, double minY, double maxY ) : List |
||
xValuesIn | Array | |
yValuesIn | Array | |
minX | double | |
maxX | double | |
minY | double | |
maxY | double | |
리턴 | List |
// === Map methods === public Map(int w_in, int h_in, int regions_in, int dist, int relaxSteps) { width = w_in; height = h_in; regions = regions_in; distanceTwixtSites = dist; colors = new Color[width*height]; ClearColors(Color.black); double[] xVal = new double[regions], yVal = new double[regions]; // used by voronoi below // === Generating === // Generate random points for (int j=0;j<regions;j++) { xVal[j] = Random.Range(0,width-1); yVal[j] = Random.Range(0,height-1); } // Generate voronoi cells graph Voronoi voroObject = new Voronoi ( distanceTwixtSites ); List<GraphEdge> regionBorders = voroObject.generateVoronoi ( xVal, yVal, 0, width-1, 0, height-1 ); for (int i=0; i<relaxSteps; i++) { // Relax voronoi cell centers sites = RelaxVoronoi(regionBorders); foreach (Site s in sites.Values) { xVal[s.id] = s.coordLocation.x; yVal[s.id] = s.coordLocation.y; } // Regenerate cells regionBorders = voroObject.generateVoronoi ( xVal, yVal, 0, width-1, 0, height-1 ); } // Final smoothing regionBorders = voroObject.generateVoronoi ( xVal, yVal, 0, width-1, 0, height-1 ); sites = RelaxVoronoi(regionBorders); GenerateEdgeMap(); // GenerateAdjacencyMap(); }
List <GraphEdge> MakeVoronoiGraph(List <PointF> sites, int width, int height) { double[] xVal = new double[sites.Count]; double[] yVal = new double[sites.Count]; for (int i = 0; i < sites.Count; i++) { xVal[i] = sites[i].X; yVal[i] = sites[i].Y; } return(voroObject.generateVoronoi(xVal, yVal, 0, width, 0, height)); }