From 65e51c082e368bd16e36352f0643e63df8801175 Mon Sep 17 00:00:00 2001 From: MeltyPlayer Date: Sat, 4 Jan 2025 23:46:40 -0600 Subject: [PATCH] Removed the dependence on DynamicProperties. --- .../Vrml/Vrml/src/util/DynamicProperties.cs | 42 ------------------- .../Formats/Vrml/Vrml/src/util/EarClipping.cs | 33 ++++++--------- .../Formats/Vrml/Vrml/src/util/Vector3m.cs | 2 - 3 files changed, 13 insertions(+), 64 deletions(-) delete mode 100644 FinModelUtility/Formats/Vrml/Vrml/src/util/DynamicProperties.cs diff --git a/FinModelUtility/Formats/Vrml/Vrml/src/util/DynamicProperties.cs b/FinModelUtility/Formats/Vrml/Vrml/src/util/DynamicProperties.cs deleted file mode 100644 index 59caf9fc2..000000000 --- a/FinModelUtility/Formats/Vrml/Vrml/src/util/DynamicProperties.cs +++ /dev/null @@ -1,42 +0,0 @@ -namespace vrml.util; - -internal enum PropertyConstants { - Marked, FaceListIndex, Median, IncidentEdges, HeVertexIndex -} - -internal class DynamicProperties { - private Dictionary _properties - = new Dictionary(); - - public int Count { - get { return this._properties.Count; } - } - - internal void AddProperty(PropertyConstants key, object value) { - this._properties.Add(key, value); - } - - internal bool ExistsKey(PropertyConstants key) { - if (this._properties.ContainsKey(key)) - return true; - return false; - } - - internal object GetValue(PropertyConstants key) { - return this._properties[key]; - } - - internal void ChangeValue(PropertyConstants key, object value) { - if (!this.ExistsKey(key)) - throw new Exception("Key " + key + " was not found."); - this._properties[key] = value; - } - - internal void Clear() { - this._properties.Clear(); - } - - internal void RemoveKey(PropertyConstants key) { - this._properties.Remove(key); - } -} \ No newline at end of file diff --git a/FinModelUtility/Formats/Vrml/Vrml/src/util/EarClipping.cs b/FinModelUtility/Formats/Vrml/Vrml/src/util/EarClipping.cs index 4e6a54350..093fdd350 100644 --- a/FinModelUtility/Formats/Vrml/Vrml/src/util/EarClipping.cs +++ b/FinModelUtility/Formats/Vrml/Vrml/src/util/EarClipping.cs @@ -42,23 +42,22 @@ private void CalcNormal_(List points) { private void LinkAndAddToList_(Polygon polygon, List points) { ConnectionEdge prev = null, first = null; - Dictionary pointsHashSet - = new Dictionary(); + Dictionary)> pointsHashSet = new(); int pointCount = 0; for (int i = 0; i < points.Count; i++) { // we don't wanna have duplicates Vector3m p0; + List incidentEdges; if (pointsHashSet.ContainsKey(points[i])) { - p0 = pointsHashSet[points[i]]; + (p0, incidentEdges) = pointsHashSet[points[i]]; } else { p0 = points[i]; - pointsHashSet.Add(p0, p0); - List list = new List(); - p0.DynamicProperties.AddProperty(PropertyConstants.IncidentEdges, list); + incidentEdges = new List(); + pointsHashSet.Add(p0, (p0, incidentEdges)); pointCount++; } - ConnectionEdge current = new ConnectionEdge(p0, polygon); + ConnectionEdge current = new(p0, polygon, incidentEdges); first = (i == 0) ? current : first; // remember first @@ -185,6 +184,8 @@ private List FindNonConvexPoints_(Polygon p) { } internal class ConnectionEdge { + public List IncidentEdges { get; } = new(); + protected bool Equals(ConnectionEdge other) { return this.next_.Origin.Equals(other.next_.Origin) && this.Origin.Equals(other.Origin); @@ -207,27 +208,21 @@ public override int GetHashCode() { } } - internal Vector3m Origin { get; set; } + internal Vector3m Origin { get; } internal ConnectionEdge prev_; internal ConnectionEdge next_; internal Polygon Polygon { get; set; } - public ConnectionEdge(Vector3m p0, Polygon parentPolygon) { + public ConnectionEdge(Vector3m p0, Polygon parentPolygon, List incidentEdges) { this.Origin = p0; this.Polygon = parentPolygon; - this.AddIncidentEdge(this); + this.IncidentEdges = incidentEdges; + this.IncidentEdges.Add(this); } public override string ToString() { return "Origin: " + this.Origin + " Next: " + this.next_.Origin; } - - internal void AddIncidentEdge(ConnectionEdge next) { - var list - = (List) this.Origin.DynamicProperties.GetValue( - PropertyConstants.IncidentEdges); - list.Add(next); - } } internal class Polygon { @@ -249,9 +244,7 @@ internal IEnumerable GetPolygonCirculator() { internal void Remove(ConnectionEdge cur) { cur.prev_.next_ = cur.next_; cur.next_.prev_ = cur.prev_; - var incidentEdges = - (List) cur.Origin.DynamicProperties.GetValue( - PropertyConstants.IncidentEdges); + var incidentEdges = cur.IncidentEdges; int index = incidentEdges.FindIndex(x => x.Equals(cur)); Debug.Assert(index >= 0); incidentEdges.RemoveAt(index); diff --git a/FinModelUtility/Formats/Vrml/Vrml/src/util/Vector3m.cs b/FinModelUtility/Formats/Vrml/Vrml/src/util/Vector3m.cs index 96c0cefe0..5088f5311 100644 --- a/FinModelUtility/Formats/Vrml/Vrml/src/util/Vector3m.cs +++ b/FinModelUtility/Formats/Vrml/Vrml/src/util/Vector3m.cs @@ -3,8 +3,6 @@ namespace vrml.util; public class Vector3m { - internal DynamicProperties DynamicProperties = new DynamicProperties(); - public Vector3m(ERational x, ERational y, ERational z) { this.X = x; this.Y = y;