From 730b54d703030374fda5fe1762d841b56b511783 Mon Sep 17 00:00:00 2001 From: Michael L Smith Date: Thu, 3 Mar 2016 19:51:01 -0800 Subject: [PATCH] Added a sphere constructor that takes variables to pre-bind internal values --- .../Solids/SphereTests.cs | 17 +++++++++++++++++ OSCADSharp/OSCADSharp/Solids/Sphere.cs | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/OSCADSharp/OSCADSharp.UnitTests/Solids/SphereTests.cs b/OSCADSharp/OSCADSharp.UnitTests/Solids/SphereTests.cs index f9f2d10..30ebb2e 100644 --- a/OSCADSharp/OSCADSharp.UnitTests/Solids/SphereTests.cs +++ b/OSCADSharp/OSCADSharp.UnitTests/Solids/SphereTests.cs @@ -166,5 +166,22 @@ namespace OSCADSharp.UnitTests Assert.IsTrue(script.Contains("$fa = angle")); Assert.IsTrue(script.Contains("$fs = fragSize")); } + + [TestMethod] + public void Sphere_CanCreateSphereWithBindingsFromConstructor() + { + var diam = new Variable("width", Sizes.OneInch); + var resolution = new Variable("rez", 100); + + var sphere = new Sphere(diam, resolution); + + Assert.AreEqual(diam.Value, sphere.Diameter); + Assert.AreEqual(resolution.Value, sphere.Resolution); + + string script = sphere.ToString(); + + Assert.IsTrue(script.Contains("d = width")); + Assert.IsTrue(script.Contains("$fn = rez")); + } } } diff --git a/OSCADSharp/OSCADSharp/Solids/Sphere.cs b/OSCADSharp/OSCADSharp/Solids/Sphere.cs index f51ba3d..88d3ad9 100644 --- a/OSCADSharp/OSCADSharp/Solids/Sphere.cs +++ b/OSCADSharp/OSCADSharp/Solids/Sphere.cs @@ -65,6 +65,25 @@ namespace OSCADSharp.Solids { this.Diameter = diameter; } + + /// + /// Creates a sphere with one more more pre-bound properties + /// + /// + /// + /// + /// + public Sphere(Variable diameter = null, Variable resolution = null, Variable minimumAngle = null, Variable minimumFragmentSize = null) + { + if (diameter != null) + this.Bind("diameter", diameter); + if (resolution != null) + this.Bind("resolution", resolution); + if (minimumAngle != null) + this.Bind("minimumangle", minimumAngle); + if (minimumFragmentSize != null) + this.Bind("minimumfragmentsize", minimumFragmentSize); + } #endregion #region Overrides