diff --git a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs
index bed8d06..1b48911 100644
--- a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs
+++ b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs
@@ -15,30 +15,14 @@ namespace OSCADSharp.ConsoleTests
{
OSCADObject cube = new Cube(new Vector3(15, 15, 15));
- cube = cube.Color("Red")
- .Mirror(1, 0, 0)
- .Resize(10, 20, 10)
- .Rotate(90, 90, 0)
- .Scale(1, 1, 2)
- .Translate(10, 5, 2);
+ for (int i = 0; i < 1000; i++)
+ {
+ cube = cube.Translate(1, 0, 0);
+ }
- OSCADObject cylinder = new Cylinder(35.4, 50.8).Translate(10, 5, 2);
-
- var combined = cube.Intersection(cylinder).Color("Blue");
- combined = cube.Clone().Mirror(0, 0, 1).Union(combined);
-
- var text = new Text3D("Hello").Translate(-30, 0, 0);
-
- combined = text.Union(combined);
-
- string script = text.ToString();
-
- File.WriteAllLines("test.scad", new string[] { script.ToString() });
-
- var vec1 = new Vector3(5, 5, 5);
- var vec2 = new Vector3(10, 10, 10);
- Console.WriteLine(vec1 - vec2);
+ string script = cube.ToString();
+ //File.WriteAllLines("test.scad", new string[] { script.ToString() });
Console.ReadKey();
}
}
diff --git a/OSCADSharp/OSCADSharp.UnitTests/CubeTests.cs b/OSCADSharp/OSCADSharp.UnitTests/CubeTests.cs
index 1a7e636..9af5d5f 100644
--- a/OSCADSharp/OSCADSharp.UnitTests/CubeTests.cs
+++ b/OSCADSharp/OSCADSharp.UnitTests/CubeTests.cs
@@ -34,13 +34,13 @@ namespace OSCADSharp.UnitTests
}
[TestMethod]
- public void Cube_CloneYieldsEqualObject()
+ public void Cube_CloneYieldsSameScript()
{
var cube = new Cube(new Vector3(1.5, 5.5, 8.7));
var clone = cube.Clone();
- Assert.IsTrue(clone.Equals(cube));
+ Assert.IsTrue(clone.IsSameAs(cube));
}
[TestMethod]
diff --git a/OSCADSharp/OSCADSharp.UnitTests/SphereTests.cs b/OSCADSharp/OSCADSharp.UnitTests/SphereTests.cs
index 9d1c4f2..292fe69 100644
--- a/OSCADSharp/OSCADSharp.UnitTests/SphereTests.cs
+++ b/OSCADSharp/OSCADSharp.UnitTests/SphereTests.cs
@@ -55,7 +55,7 @@ namespace OSCADSharp.UnitTests
}
[TestMethod]
- public void Sphere_CloneYieldsEqualObject()
+ public void Sphere_CloneYieldsSameScript()
{
var sphere = new Sphere()
{
@@ -67,7 +67,7 @@ namespace OSCADSharp.UnitTests
var clone = sphere.Clone();
- Assert.IsTrue(sphere.Equals(clone));
+ Assert.IsTrue(sphere.IsSameAs(clone));
}
}
}
diff --git a/OSCADSharp/OSCADSharp/OSCADObject.cs b/OSCADSharp/OSCADSharp/OSCADObject.cs
index ec8e0f7..8358768 100644
--- a/OSCADSharp/OSCADSharp/OSCADObject.cs
+++ b/OSCADSharp/OSCADSharp/OSCADObject.cs
@@ -191,5 +191,17 @@ namespace OSCADSharp
///
/// Clone of this object
public abstract OSCADObject Clone();
+
+ ///
+ /// Indicates whether this OSCADObject is the same as another OSCADObject.
+ /// This processes the scripts for both objects and is computationally expensive.
+ /// DO NOT use on deeply nested structures.
+ ///
+ /// OSCADObject to compare to
+ /// True if scripts are exactly the same, false otherwise
+ public bool IsSameAs(OSCADObject other)
+ {
+ return this.ToString() == other.ToString();
+ }
}
}
diff --git a/OSCADSharp/OSCADSharp/Scripting/BlockFormatter.cs b/OSCADSharp/OSCADSharp/Scripting/BlockFormatter.cs
index 7ef2c90..87e9209 100644
--- a/OSCADSharp/OSCADSharp/Scripting/BlockFormatter.cs
+++ b/OSCADSharp/OSCADSharp/Scripting/BlockFormatter.cs
@@ -23,9 +23,12 @@ namespace OSCADSharp.Scripting
this.innerCode = innerCode;
}
- //TODO: Assess perf and find a better performing way to apply indentation
- // this approach will likely be a big performance drain with deeply nested structures.
- // -MLS 2/12/2016
+ // Assessed performance on this method by using Translate 1,000 times
+ // on a Cube and converting it to a string. It completed in about 12.5 seconds.
+ // This method was the bottleneck by far at 60% of the CPU time spent.
+ // Although this is probably okay for generating scripts (that is a huge script), we should
+ // refrain from using the stringified version of deeply nested objects for equivalence checks
+ // -MLS 2/13/2016
public override string ToString()
{
StringBuilder sb = new StringBuilder();
diff --git a/OSCADSharp/OSCADSharp/Solids/Cube.cs b/OSCADSharp/OSCADSharp/Solids/Cube.cs
index 1902770..2264b2c 100644
--- a/OSCADSharp/OSCADSharp/Solids/Cube.cs
+++ b/OSCADSharp/OSCADSharp/Solids/Cube.cs
@@ -76,24 +76,6 @@ namespace OSCADSharp.Solids
Center = this.Center
};
}
-
- public override bool Equals(object other)
- {
- if (other.GetType() == typeof(Cube))
- {
- Cube otherSphere = other as Cube;
- return this.GetHashCode() == other.GetHashCode();
- }
- else
- {
- return false;
- }
- }
-
- public override int GetHashCode()
- {
- return this.ToString().GetHashCode();
- }
#endregion
}
}
diff --git a/OSCADSharp/OSCADSharp/Solids/Sphere.cs b/OSCADSharp/OSCADSharp/Solids/Sphere.cs
index 4d8a00f..e3c16c2 100644
--- a/OSCADSharp/OSCADSharp/Solids/Sphere.cs
+++ b/OSCADSharp/OSCADSharp/Solids/Sphere.cs
@@ -80,28 +80,6 @@ namespace OSCADSharp.Solids
Radius = this.Radius
};
}
-
- public override bool Equals(object other)
- {
- // This logic is because we want to prevent the weird scenario
- // where perhaps this sphere is being compared to a string that's an
- // exact match to this sphere's string output. Since the hashcode is
- // borrowed from the string output
- if(other.GetType() == typeof(Sphere))
- {
- Sphere otherSphere = other as Sphere;
- return this.GetHashCode() == other.GetHashCode();
- }
- else
- {
- return false;
- }
- }
-
- public override int GetHashCode()
- {
- return this.ToString().GetHashCode();
- }
#endregion
}
}