/// <summary> /// 頂点の設定。始点と終点が結ばれていること /// </summary> public void SetVertices(List <Vector2> vertices, Color color) { //包括矩形から原点からのオフセットを求め適用する Rect rect = GeomUtil.CalculateRect(vertices); for (int i = 0; i < vertices.Count; ++i) { vertices[i] -= rect.center; } this.vertices = vertices; //座標をずらす transform.localPosition = rect.center; //改めて包括矩形を求める inclusionRect = GeomUtil.CalculateRect(vertices); //ポリゴンの生成 //末尾を削除(一時的) vertices.RemoveAt(vertices.Count - 1); polygon = new ConcavePolygon(vertices); //末尾に先頭を追加 vertices.Add(vertices[0]); //簡易メッシュの確保 drawEMesh = polygon.ToEasyMesh(color); subEMesh = polygon.ToEasyMesh(color); //描画用メッシュの領域確保 drawEMeshes = new EasyMesh[2]; //色 SetPolygonColor(color); draw = true; }
/// <summary> /// LineEditorのMaker終了イベント /// </summary> private void OnMakerExit(List <Vector2> vertices) { if (vertices == null) { return; } if (vertices.Count < 4) { return; } vertices.RemoveAt(vertices.Count - 1); //とりまテスト ConcavePolygonObject polyObj = Instantiate <ConcavePolygonObject>(polyObjPrefab); polyObj.name = polyObj.name; ConcavePolygon polygon = new ConcavePolygon(vertices); //ランチャーの解析 PartsPolygon pPoly = new PartsPolygon(polygon); List <Launcher> launchers = pPoly.ParseLauncher(); for (int i = 0; i < launchers.Count; ++i) { markerPool.PopItem(launchers[i].point).Visible(); } //表示 polyObj.SetPolygon(polygon); polyObj.onClick.AddListener(OnPolygonClick); polyObjDic.Add(polyObj.gameObject, polyObj); }
/// <summary> /// 頂点の設定 /// </summary> public void SetVertices(List <Vector2> vertices) { //包括矩形から原点からのオフセットを求め適用する Rect rect = GeomUtil.CalculateRect(vertices); for (int i = 0; i < vertices.Count; ++i) { vertices[i] -= rect.center; } this.vertices = vertices; //座標をずらす transform.localPosition = rect.center; //改めて包括矩形を求める inclusionRect = GeomUtil.CalculateRect(vertices); //ポリゴンの生成 vertices.RemoveAt(vertices.Count - 1); //末尾を一時的に削除 polygon = new ConcavePolygon(vertices); vertices.Add(vertices[0]); //末尾に始点を追加 //簡易メッシュの確保 drawEMesh = polygon.ToEasyMesh(polygonColor); targetColorEMesh = polygon.ToEasyMesh(polygonColor); //描画用簡易メッシュ領域の確保 eMeshes = new EasyMesh[2]; //コールバック onVertexChanged.Invoke(this); draw = true; }
public PartsPolygon(ConcavePolygon polygon) { this.polygon = polygon; }
public static List <AtomicRegion> GetAtomicRegions(List <Point> figurePoints, List <Circle> circles, List <Polygon>[] polygons) { List <AtomicRegion> originalAtoms = new List <AtomicRegion>(); Dictionary <Circle, int> circGranularity = new Dictionary <Circle, int>(); // // Convert all circles to atomic regions identifying their chord / radii substructure. // if (circles.Any()) { // Construct the granularity for when we construct arcs. circles = new List <Circle>(circles.OrderBy(c => c.radius)); double currRadius = circles[0].radius; int gran = 1; foreach (Circle circle in circles) { List <AtomicRegion> circleAtoms = circle.Atomize(figurePoints); // Make this circle the owner of the atomic regions. foreach (AtomicRegion atom in circleAtoms) { atom.AddOwner(circle); circle.AddAtomicRegion(atom); } originalAtoms.AddRange(circleAtoms); // // Granularity // if (circle.radius > currRadius) { gran++; } circGranularity[circle] = gran; } } // // Make all of the polygons an atomic region. // Also, convert any concave polygon into atoms by extending sides inward. // for (int n = Polygon.MIN_POLY_INDEX; n < Polygon.MAX_EXC_POLY_INDEX; n++) { foreach (Polygon poly in polygons[n]) { // Handle any concave polygons. ConcavePolygon concave = poly as ConcavePolygon; if (concave != null) { List <AtomicRegion> concaveAtoms = concave.Atomize(figurePoints); originalAtoms.AddRange(concaveAtoms); poly.AddAtomicRegions(concaveAtoms); } // Basic polygon: make it a shape atomic region. else { ShapeAtomicRegion shapeAtom = new ShapeAtomicRegion(poly); shapeAtom.AddOwner(poly); originalAtoms.Add(shapeAtom); } } } // // Since circles and Concave Polygons were atomized, there may be duplicate atomic regions. // originalAtoms = RemoveDuplicates(originalAtoms); List <AtomicRegion> workingAtoms = new List <AtomicRegion>(originalAtoms); // // Combine all of the atomic regions together. // List <AtomicRegion> composed = ComposeAllRegions(figurePoints, workingAtoms, circGranularity); composed = RemoveContained(composed); // // Run the graph-based algorithm one last time to identify any pathological regions (exterior to all shapes). // // Identify those pathological regions as well as any lost (major arcs). // List <AtomicRegion> lost = new List <AtomicRegion>(); List <AtomicRegion> pathological = new List <AtomicRegion>(); List <AtomicRegion> pathologicalID = IdentifyPathological(figurePoints, composed, circles, circGranularity); pathologicalID = RemoveRedundantSemicircle(pathologicalID); foreach (AtomicRegion atom in composed) { if (!pathologicalID.Contains(atom)) { bool containment = false; foreach (AtomicRegion pathAtom in pathologicalID) { if (atom.Contains(pathAtom)) { containment = true; break; } } if (!containment) { lost.Add(atom); } } } foreach (AtomicRegion atom in pathologicalID) { if (!composed.Contains(atom)) { pathological.Add(atom); } } List <AtomicRegion> finalAtomSet = new List <AtomicRegion>(); finalAtomSet.AddRange(composed); finalAtomSet.AddRange(pathological); return(finalAtomSet); }