From 1bd6ad3543426ca11b21b7c8ed5ca5d05c1d60dc Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Wed, 17 Feb 2016 22:57:20 -0800 Subject: [PATCH] + Updated Difference's Position() behavior to return the position of the first child (object being differenced) --- OSCADSharp/OSCADSharp.ConsoleTests/Program.cs | 16 ++++++---------- .../OSCADSharp.UnitTests/DifferenceTests.cs | 18 +++++++++++++----- OSCADSharp/OSCADSharp/Booleans/Difference.cs | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs index 40907f9..ea57b78 100644 --- a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs +++ b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs @@ -13,19 +13,15 @@ namespace OSCADSharp.ConsoleTests { static void Main(string[] args) { - //var obj = new Cube(5, 10, 20).Mirror(0, 0, 1).Mirror(0, 1, 0) - // .Rotate(15, -45, 120).Translate(-20, 10, 15).Rotate(90, 15, 25) - // .Translate(-10, -20, -20).Rotate(-90, -90, -45); - var obj = new Cube() + new Sphere() + new Sphere().Translate(2, 2, 2) - new Cylinder(2, 5) + new Text3D("Hey hey!"); - //var pos = obj.Position(); - //var cyl1 = new Cylinder(1, 100, true).Translate(pos); - //var cyl2 = new Cylinder(1, 100, true).Rotate(0, 90, 0).Translate(pos); - //var cyl3 = new Cylinder(1, 100, true).Rotate(90, 0, 0).Translate(pos); - //var axisHelper = cyl1.Union(cyl2, cyl3).Color("Red"); + var pos = obj.Position(); + var cyl1 = new Cylinder(1, 100, true).Translate(pos); + var cyl2 = new Cylinder(1, 100, true).Rotate(0, 90, 0).Translate(pos); + var cyl3 = new Cylinder(1, 100, true).Rotate(90, 0, 0).Translate(pos); + var axisHelper = cyl1.Union(cyl2, cyl3).Color("Red"); - string script = obj.ToString(); //obj.Union(axisHelper).ToString(); + string script = obj.Union(axisHelper).ToString(); File.WriteAllLines("test.scad", new string[] { script.ToString() }); //Console.ReadKey(); diff --git a/OSCADSharp/OSCADSharp.UnitTests/DifferenceTests.cs b/OSCADSharp/OSCADSharp.UnitTests/DifferenceTests.cs index 391dccf..10aeaa1 100644 --- a/OSCADSharp/OSCADSharp.UnitTests/DifferenceTests.cs +++ b/OSCADSharp/OSCADSharp.UnitTests/DifferenceTests.cs @@ -8,13 +8,21 @@ namespace OSCADSharp.UnitTests [TestClass] public class DifferenceTests { - [TestMethod] - [ExpectedException(typeof(NotSupportedException))] - public void Difference_PositionThrowsNotSupportedException() + /// + /// Note: The decision that Difference should yield the position of the + /// first child stems from the common use case of using Difference to bore out + /// holes for pegs, screws, supports, etc. It's often used in such a way that + /// the overall structure of the object being differenced is not greatly affected, + /// thus the position should not change. + /// -MLS 2/17/2016 + /// + [TestMethod] + public void Difference_PositionYieldsPositionOfFirstChild() { - var diff = new Sphere().Difference(new Cube()); + var sphere = new Sphere().Translate(.25, .25, 1); + var diff = sphere.Difference(new Cube()); - var pos = diff.Position(); + Assert.AreEqual(sphere.Position(), diff.Position()); } [TestMethod] diff --git a/OSCADSharp/OSCADSharp/Booleans/Difference.cs b/OSCADSharp/OSCADSharp/Booleans/Difference.cs index bd66924..6b00007 100644 --- a/OSCADSharp/OSCADSharp/Booleans/Difference.cs +++ b/OSCADSharp/OSCADSharp/Booleans/Difference.cs @@ -22,7 +22,7 @@ namespace OSCADSharp.Booleans public override Vector3 Position() { - throw new NotSupportedException("Position is not supported on Differenced objects."); + return children[0].Position(); } } }