From 8c799bb3c2e838b46cd27bf7e2f4b2ee4656909b Mon Sep 17 00:00:00 2001 From: hoba Date: Wed, 12 Feb 2025 14:54:09 +0800 Subject: [PATCH] chore: GeodesicMesh use enum instead of string --- .../Editor/GeodesicMesh.cs | 74 ++++++++++--------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/Assets/UltraCombos.Metamesh/Editor/GeodesicMesh.cs b/Assets/UltraCombos.Metamesh/Editor/GeodesicMesh.cs index 0a2e44e..e3e0a62 100644 --- a/Assets/UltraCombos.Metamesh/Editor/GeodesicMesh.cs +++ b/Assets/UltraCombos.Metamesh/Editor/GeodesicMesh.cs @@ -1,10 +1,17 @@ -using System; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace Metamesh { + public enum Rotation + { + Unknown, + A, + B, + O, + } + public class PrimaryIsoTriangle { private int m; @@ -104,7 +111,7 @@ namespace Metamesh n1 = n / g; int fr; //face to the right of current face - string rot; //rotation about which vertex for fr + Rotation rot; //rotation about which vertex for fr int O; int A; int B; @@ -153,28 +160,28 @@ namespace Metamesh } - this.IDATA.edgematch = new List<(int, string, int, string)> - { - (1, "B", 0, ""), - (2, "B", 0, ""), - (3, "B", 0, ""), - (4, "B", 0, ""), - (0, "B", 0, ""), - (10, "O", 14, "A"), - (11, "O", 10, "A"), - (12, "O", 11, "A"), - (13, "O", 12, "A"), - (14, "O", 13, "A"), - (0, "O", 0, ""), - (1, "O", 0, ""), - (2, "O", 0, ""), - (3, "O", 0, ""), - (4, "O", 0, ""), - (19, "B", 5, "A"), - (15, "B", 6, "A"), - (16, "B", 7, "A"), - (17, "B", 8, "A"), - (18, "B", 9, "A"), + this.IDATA.edgematch = new List<(int, Rotation, int, Rotation)> + { + (1, Rotation.B, 0, Rotation.Unknown), + (2, Rotation.B, 0, Rotation.Unknown), + (3, Rotation.B, 0, Rotation.Unknown), + (4, Rotation.B, 0, Rotation.Unknown), + (0, Rotation.B, 0, Rotation.Unknown), + (10, Rotation.O, 14, Rotation.A), + (11, Rotation.O, 10, Rotation.A), + (12, Rotation.O, 11, Rotation.A), + (13, Rotation.O, 12, Rotation.A), + (14, Rotation.O, 13, Rotation.A), + (0, Rotation.O, 0, Rotation.Unknown), + (1, Rotation.O, 0, Rotation.Unknown), + (2, Rotation.O, 0, Rotation.Unknown), + (3, Rotation.O, 0, Rotation.Unknown), + (4, Rotation.O, 0, Rotation.Unknown), + (19, Rotation.B, 5, Rotation.A), + (15, Rotation.B, 6, Rotation.A), + (16, Rotation.B, 7, Rotation.A), + (17, Rotation.B, 8, Rotation.A), + (18, Rotation.B, 9, Rotation.A), }; /***edges AB to OB***** rotation about B*/ @@ -214,7 +221,7 @@ namespace Metamesh //for edge vertices fr = this.IDATA.edgematch[f].Item1; rot = this.IDATA.edgematch[f].Item2; - if (rot == "B") + if (rot == Rotation.B) { for (var i = 1; i < g; i++) { @@ -228,7 +235,7 @@ namespace Metamesh } } - if (rot == "O") + if (rot == Rotation.O) { for (var i = 1; i < g; i++) { @@ -244,7 +251,7 @@ namespace Metamesh fr = this.IDATA.edgematch[f].Item3; rot = this.IDATA.edgematch[f].Item4; - if (rot == "A") + if (rot == Rotation.A) { for (var i = 1; i < g; i++) { @@ -625,7 +632,7 @@ namespace Metamesh public string category; public Dictionary vertex; public List> face; - public List<(int, string, int, string)> edgematch; + public List<(int, Rotation, int, Rotation)> edgematch; public PolyhedronData( string name, @@ -754,7 +761,7 @@ namespace Metamesh nearTo[12].Add(new List { i, close[i][0] }); } } - + var near = Enumerable.Range(0, 12).ToDictionary(i => i); var nearIndex = 12; for (var i = 0; i < 12; i++) @@ -857,7 +864,8 @@ namespace Metamesh if (goldbergPolyhedronData.face.Count <= m) { if (goldbergPolyhedronData.face.Count != m) - Debug.LogWarning($"goldbergPolyhedronData.face.Count != m: {goldbergPolyhedronData.face.Count} != {m}"); + Debug.LogWarning( + $"goldbergPolyhedronData.face.Count != m: {goldbergPolyhedronData.face.Count} != {m}"); goldbergPolyhedronData.face.Add(tempFace); } else @@ -921,17 +929,17 @@ namespace Metamesh { primTri.MapToFace(f, geodesicData); geodesicData.InnerToData(f, primTri); - if (primTri.IDATA.edgematch[f].Item2 == "B") + if (primTri.IDATA.edgematch[f].Item2 == Rotation.B) { geodesicData.MapABOBtoDATA(f, primTri); } - if (primTri.IDATA.edgematch[f].Item2 == "O") + if (primTri.IDATA.edgematch[f].Item2 == Rotation.O) { geodesicData.MapOBOAtoDATA(f, primTri); } - if (primTri.IDATA.edgematch[f].Item4 == "A") + if (primTri.IDATA.edgematch[f].Item4 == Rotation.A) { geodesicData.MapBAOAtoDATA(f, primTri); }