diff --git a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs
index 14dea4f..b6a77fa 100644
--- a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs
+++ b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs
@@ -14,7 +14,7 @@ namespace OSCADSharp.ConsoleTests
static void Main(string[] args)
{
- var obj = new Text3D("Whaat is thissss?");
+ var obj = new Sphere(30);
var pos = obj.Position();
var cyl1 = new Cylinder(1, 100, true).Translate(pos);
diff --git a/OSCADSharp/OSCADSharp.UnitTests/Solids/SphereTests.cs b/OSCADSharp/OSCADSharp.UnitTests/Solids/SphereTests.cs
index 2cc55d3..e0c5509 100644
--- a/OSCADSharp/OSCADSharp.UnitTests/Solids/SphereTests.cs
+++ b/OSCADSharp/OSCADSharp.UnitTests/Solids/SphereTests.cs
@@ -86,5 +86,34 @@ namespace OSCADSharp.UnitTests
Assert.AreEqual(new Vector3(15, 15, 15), obj.Bounds().TopRight);
Assert.AreEqual(new Vector3(-15, -15, -15), obj.Bounds().BottomLeft);
}
+
+ [TestMethod]
+ public void Sphere_ScriptOutputDoesNotContainResolutionValuesIfNotSpecified()
+ {
+ var sphere = new Sphere();
+
+ string script = sphere.ToString();
+
+ Assert.IsTrue(!script.Contains("$fn"));
+ Assert.IsTrue(!script.Contains("$fa"));
+ Assert.IsTrue(!script.Contains("$fs"));
+ }
+
+ [TestMethod]
+ public void Sphere_ScriptOutpuHasResolutionValuesIfSpecified()
+ {
+ var sphere = new Sphere()
+ {
+ Resolution = 40,
+ MinimumAngle = 5,
+ MinimumFragmentSize = 2
+ };
+
+ string script = sphere.ToString();
+
+ Assert.IsTrue(script.Contains("$fn"));
+ Assert.IsTrue(script.Contains("$fa"));
+ Assert.IsTrue(script.Contains("$fs"));
+ }
}
}
diff --git a/OSCADSharp/OSCADSharp/Solids/Sphere.cs b/OSCADSharp/OSCADSharp/Solids/Sphere.cs
index 766decb..20d2d56 100644
--- a/OSCADSharp/OSCADSharp/Solids/Sphere.cs
+++ b/OSCADSharp/OSCADSharp/Solids/Sphere.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSCADSharp.Spatial;
+using OSCADSharp.Scripting;
namespace OSCADSharp.Solids
{
@@ -30,19 +31,19 @@ namespace OSCADSharp.Solids
/// Minimum angle (in degrees) of each cylinder fragment.
/// ($fa in OpenSCAD)
///
- public int MinimumAngle { get; set; } = 12;
+ public int? MinimumAngle { get; set; }
///
/// Fragment size in mm
/// ($fs in OpenSCAD)
///
- public int MinimumFragmentSize { get; set; } = 2;
+ public int? MinimumFragmentSize { get; set; }
///
/// Number of fragments in 360 degrees. Values of 3 or more override MinimumAngle and MinimumCircumferentialLength
/// ($fn in OpenSCAD)
///
- public int Resolution { get; set; } = 0;
+ public int? Resolution { get; set; }
#endregion
#region Constructors
@@ -70,9 +71,16 @@ namespace OSCADSharp.Solids
/// Script for this object
public override string ToString()
{
- return String.Format("sphere($fn = {0}, $fa = {1}, $fs = {2}, r = {3});{4}",
- this.Resolution.ToString(), this.MinimumAngle.ToString(),
- this.MinimumFragmentSize.ToString(), this.Radius.ToString(), Environment.NewLine);
+ StatementBuilder sb = new StatementBuilder();
+ sb.Append("sphere(");
+ sb.AppendValuePairIfExists("r", this.Radius);
+ sb.AppendValuePairIfExists("$fn", this.Resolution, true);
+ sb.AppendValuePairIfExists("$fa", this.MinimumAngle, true);
+ sb.AppendValuePairIfExists("$fs", this.MinimumFragmentSize, true);
+ sb.Append(");");
+ sb.Append(Environment.NewLine);
+
+ return sb.ToString();
}
///