private CartographicIsland constructIslandFromBundle(Bundle b) { int rngSeed = b.getName().GetHashCode() + 200; RNG = new System.Random(rngSeed); #region VoronoiPlane TriangleNet.Configuration conf = new TriangleNet.Configuration(); List <Vertex> vertices = Helperfunctions.createPointsOnPlane(GlobalVar.voronoiCellScalefactor, GlobalVar.voronoiCellScalefactor, 50, 50, 1.0f, RNG); BoundedVoronoi voronoi = Helperfunctions.createRelaxedVoronoi(vertices, 1); #endregion #region initFirstCell VFace firstCell = Helperfunctions.closestCell(0, 0, voronoi); Dictionary <int, VFace> startingCandidates = new Dictionary <int, VFace>(); startingCandidates.Add(firstCell.ID, firstCell); #endregion List <Package> packages = b.getPackages(); CartographicIsland island = new CartographicIsland(b); island.setVoronoi(voronoi); #region sort package list packages.Sort((x, y) => x.getCompilationUnits().Count.CompareTo(y.getCompilationUnits().Count)); packages.Reverse(); #endregion //Compute maximal compilation unit count in bundle float maxCUCountInIsland = 0; foreach (Package package in packages) { long cuCount = package.getCuCount(); if (cuCount > maxCUCountInIsland) { maxCUCountInIsland = cuCount; } } #region construct regions foreach (Package package in packages) { float cohesionMult = (float)package.getCuCount() / maxCUCountInIsland; cohesionMult *= maxCohesion; cohesionMult = Mathf.Max(minCohesion, cohesionMult); Dictionary <int, VFace> newCandidates = constructRegionFromPackage(package, island, startingCandidates, cohesionMult); updateAndFuseCandidates(startingCandidates, newCandidates); } #endregion #region Shape island coast //Advance startingCandidates X cells outwards and ajdust the height of all vertices shapeCoastArea(startingCandidates, GlobalVar.islandHeightProfile); #endregion #region WeightedCenter & set coast List <VFace> coastlineList = new List <VFace>(); Vector3 weightedCenter = Vector3.zero; foreach (KeyValuePair <int, VFace> kvp in startingCandidates) { coastlineList.Add(kvp.Value); float x = (float)kvp.Value.generator.X; float z = (float)kvp.Value.generator.Y; Vector3 tilePos = new Vector3(x, 0, z); weightedCenter += tilePos; } weightedCenter /= startingCandidates.Count; island.setWeightedCenter(weightedCenter); island.setCoastlineCells(coastlineList); #endregion #region conservative Radius List <float> radii = new List <float>(); foreach (KeyValuePair <int, VFace> kvp in startingCandidates) { float x = (float)kvp.Value.generator.X - island.getWeightedCenter().x; float z = (float)kvp.Value.generator.Y - island.getWeightedCenter().z; float radius = Mathf.Sqrt(x * x + z * z); radii.Add(radius); } float maxRadius = Helperfunctions.computeMax(radii); island.setRadius(maxRadius); #endregion #region TnetMeshesConstruction foreach (List <VFace> cellMap in island.getPackageCells()) { island.addPackageMesh(constructTnetMeshFromCellmap(cellMap)); } island.setCoastlineMesh(constructTnetMeshFromCellmap(coastlineList)); #endregion #region link dependency vertex //Find graph vertex associated with the island BidirectionalGraph <GraphVertex, GraphEdge> depGraph = b.getParentProject().getDependencyGraph(); List <GraphVertex> allVertices = depGraph.Vertices.ToList(); GraphVertex vert = allVertices.Find(v => string.Equals(v.getName(), b.getName())); if (vert != null) { //Link GraphVertex-Island vert.setIsland(island); island.setDependencyVertex(vert); } #endregion return(island); }