From 5487af3d9558a75f4a014cee81f007a5dee9be25 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Mon, 29 Feb 2016 18:34:19 -0800 Subject: [PATCH] Reworked Sphere to support binding either Diameter or Radius --- .../OSCADSharp.UnitTests/Solids/SphereTests.cs | 16 ++++++++++++++++ OSCADSharp/OSCADSharp/Solids/Sphere.cs | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/OSCADSharp/OSCADSharp.UnitTests/Solids/SphereTests.cs b/OSCADSharp/OSCADSharp.UnitTests/Solids/SphereTests.cs index 1f306a3..77bcad2 100644 --- a/OSCADSharp/OSCADSharp.UnitTests/Solids/SphereTests.cs +++ b/OSCADSharp/OSCADSharp.UnitTests/Solids/SphereTests.cs @@ -132,5 +132,21 @@ namespace OSCADSharp.UnitTests string script = sphere.ToString(); Assert.IsTrue(script.Contains("r = mySphereRadius")); } + + [TestMethod] + public void Sphere_BindingDiameterSetsDiameterInOutput() + { + string variableName = "diam"; + double diam = 20; + + Variables.Global.Add(variableName, diam); + + var sphere = new Sphere(); + sphere.Bind("Diameter", Variables.Global["diam"]); + Assert.IsTrue(sphere.Diameter == diam); + + string script = sphere.ToString(); + Assert.IsTrue(script.Contains("d = diam")); + } } } diff --git a/OSCADSharp/OSCADSharp/Solids/Sphere.cs b/OSCADSharp/OSCADSharp/Solids/Sphere.cs index 5cbb331..6e254d1 100644 --- a/OSCADSharp/OSCADSharp/Solids/Sphere.cs +++ b/OSCADSharp/OSCADSharp/Solids/Sphere.cs @@ -75,7 +75,16 @@ namespace OSCADSharp.Solids { StatementBuilder sb = new StatementBuilder(this.bindings); sb.Append("sphere("); - sb.AppendValuePairIfExists("r", this.Radius); + + if (this.bindings.Contains("d")) + { + sb.AppendValuePairIfExists("d", this.Diameter); + } + else + { + sb.AppendValuePairIfExists("r", this.Radius); + } + sb.AppendValuePairIfExists("$fn", this.Resolution, true); sb.AppendValuePairIfExists("$fa", this.MinimumAngle, true); sb.AppendValuePairIfExists("$fs", this.MinimumFragmentSize, true); @@ -123,7 +132,11 @@ namespace OSCADSharp.Solids private Bindings bindings = new Bindings(new Dictionary() { - { "radius", "r" } + { "radius", "r" }, + { "minimumangle", "$fa" }, + { "minimumFragmentsize", "$fs" }, + { "resolution", "$fn" }, + { "diameter", "d" } }); ///