diff --git a/OSCADSharp/OSCADSharp.UnitTests/Transforms/MirrorTests.cs b/OSCADSharp/OSCADSharp.UnitTests/Transforms/MirrorTests.cs
index d5c7213..6ccec09 100644
--- a/OSCADSharp/OSCADSharp.UnitTests/Transforms/MirrorTests.cs
+++ b/OSCADSharp/OSCADSharp.UnitTests/Transforms/MirrorTests.cs
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using OSCADSharp.Scripting;
using OSCADSharp.Solids;
using System;
using System.Collections.Generic;
@@ -69,5 +70,25 @@ namespace OSCADSharp.UnitTests
string script = cube.ToString();
Assert.IsTrue(script.Contains("mirror(myVar)"));
}
+
+ [TestMethod]
+ public void Mirror_CanBindNormalWithParameter()
+ {
+ var cube = new Cube(5, 20, 15).Mirror(new Scripting.Variable("myVar", new Vector3(1, 0, 0)));
+
+ string script = cube.ToString();
+ Assert.IsTrue(script.Contains("mirror(myVar)"));
+ }
+
+ [TestMethod]
+ public void Mirror_VariablesForXandZ()
+ {
+ var x = new Variable("xComp", 0);
+ var z = new Variable("zComp", 1);
+
+ var cube = new Cube().Mirror(x, 0, z);
+ string script = cube.ToString();
+ Assert.IsTrue(script.Contains("mirror([xComp, 0, zComp])"));
+ }
}
}
diff --git a/OSCADSharp/OSCADSharp.UnitTests/Transforms/ResizeTests.cs b/OSCADSharp/OSCADSharp.UnitTests/Transforms/ResizeTests.cs
index e1daa2e..c32a2d1 100644
--- a/OSCADSharp/OSCADSharp.UnitTests/Transforms/ResizeTests.cs
+++ b/OSCADSharp/OSCADSharp.UnitTests/Transforms/ResizeTests.cs
@@ -44,5 +44,17 @@ namespace OSCADSharp.UnitTests.Transforms
Assert.IsTrue(script.Contains("resize(mySize)"));
}
+
+ [TestMethod]
+ public void Resize_ParameterizedSizeBindingAppearsInOutput()
+ {
+ var xAmount = new Variable("xAmt", 15);
+
+ var resizedCube = new Cube().Resize(xAmount, 5, 10);
+
+ string script = resizedCube.ToString();
+
+ Assert.IsTrue(script.Contains("resize([xAmt, 5, 10])"));
+ }
}
}
diff --git a/OSCADSharp/OSCADSharp/OSCADObject.cs b/OSCADSharp/OSCADSharp/OSCADObject.cs
index c262b06..cefac40 100644
--- a/OSCADSharp/OSCADSharp/OSCADObject.cs
+++ b/OSCADSharp/OSCADSharp/OSCADObject.cs
@@ -51,12 +51,13 @@ namespace OSCADSharp
///
/// Color name variable to apply
/// (optional)Opacity variable
- ///
+ /// A colored object
public OSCADObject Color(Variable colorName, Variable opacity = null)
{
return new ColoredObject(this, colorName, opacity);
}
+ #region Mirror
///
/// Mirrors the object about a plane, as specified by the normal
///
@@ -67,6 +68,16 @@ namespace OSCADSharp
{
return new MirroredObject(this, normal);
}
+
+ ///
+ /// Mirrors the object on a plane represented in a variable
+ ///
+ /// Variable for the normal vector of the plane
+ /// A mirrored object
+ public OSCADObject Mirror(Variable normal)
+ {
+ return new MirroredObject(this, normal);
+ }
///
/// Mirrors the object about a plane, as specified by the normal
@@ -81,6 +92,92 @@ namespace OSCADSharp
return this.Mirror(new Vector3(x, y, z));
}
+ ///
+ /// Mirrors an object about a plane with variables for some components of the normal
+ ///
+ ///
+ ///
+ ///
+ /// A mirrored object
+ public OSCADObject Mirror(Variable x, Variable y, Variable z)
+ {
+ return new MirroredObject(this, new Vector3(), x, y, z);
+ }
+
+ ///
+ /// Mirrors an object about a plane with variables for some components of the normal
+ ///
+ ///
+ ///
+ ///
+ /// A mirrored object
+ public OSCADObject Mirror(Variable x, double y, double z)
+ {
+ return new MirroredObject(this, new Vector3(0, y, z), x, null, null);
+ }
+
+ ///
+ /// Mirrors an object about a plane with variables for some components of the normal
+ ///
+ ///
+ ///
+ ///
+ /// A mirrored object
+ public OSCADObject Mirror(double x, Variable y, double z)
+ {
+ return new MirroredObject(this, new Vector3(x, 0, z), null, y, null);
+ }
+
+ ///
+ /// Mirrors an object about a plane with variables for some components of the normal
+ ///
+ ///
+ ///
+ ///
+ /// A mirrored object
+ public OSCADObject Mirror(double x, double y, Variable z)
+ {
+ return new MirroredObject(this, new Vector3(x, y, 0), null, null, z);
+ }
+
+ ///
+ /// Mirrors an object about a plane with variables for some components of the normal
+ ///
+ ///
+ ///
+ ///
+ /// A mirrored object
+ public OSCADObject Mirror(Variable x, Variable y, double z)
+ {
+ return new MirroredObject(this, new Vector3(0, 0, z), x, y, null);
+ }
+
+ ///
+ /// Mirrors an object about a plane with variables for some components of the normal
+ ///
+ ///
+ ///
+ ///
+ /// A mirrored object
+ public OSCADObject Mirror(double x, Variable y, Variable z)
+ {
+ return new MirroredObject(this, new Vector3(x, 0, 0), null, y, z);
+ }
+
+ ///
+ /// Mirrors an object about a plane with variables for some components of the normal
+ ///
+ ///
+ ///
+ ///
+ /// A mirrored object
+ public OSCADObject Mirror(Variable x, double y, Variable z)
+ {
+ return new MirroredObject(this, new Vector3(0, y, 0), x, null, z);
+ }
+ #endregion
+
+ #region Resize
///
/// Resizes to a specified set of X/Y/Z dimensions
///
@@ -91,6 +188,16 @@ namespace OSCADSharp
return new ResizedObject(this, newsize);
}
+ ///
+ /// Resizes to a specified set of X/Y/Z dimensions using a variable
+ ///
+ /// The X/Y/Z dimensions
+ /// A resized object
+ public OSCADObject Resize(Variable newsize)
+ {
+ return new ResizedObject(this, newsize);
+ }
+
///
/// Resizes to a specified set of X/Y/Z dimensions
///
@@ -103,6 +210,91 @@ namespace OSCADSharp
return this.Resize(new Vector3(x, y, z));
}
+ ///
+ /// Resizes to a specified set of X/Y/Z dimensions using one or more variables
+ ///
+ ///
+ ///
+ ///
+ /// A resized object
+ public OSCADObject Resize(Variable x, Variable y, Variable z)
+ {
+ return new ResizedObject(this, new Vector3(), x, y, z);
+ }
+
+ ///
+ /// Resizes to a specified set of X/Y/Z dimensions using one or more variables
+ ///
+ ///
+ ///
+ ///
+ /// A resized object
+ public OSCADObject Resize(Variable x, double y, double z)
+ {
+ return new ResizedObject(this, new Vector3(0, y, z), x, null, null);
+ }
+
+ ///
+ /// Resizes to a specified set of X/Y/Z dimensions using one or more variables
+ ///
+ ///
+ ///
+ ///
+ /// A resized object
+ public OSCADObject Resize(double x, Variable y, double z)
+ {
+ return new ResizedObject(this, new Vector3(x, 0, z), null, y, null);
+ }
+
+ ///
+ /// Resizes to a specified set of X/Y/Z dimensions using one or more variables
+ ///
+ ///
+ ///
+ ///
+ /// A resized object
+ public OSCADObject Resize(double x, double y, Variable z)
+ {
+ return new ResizedObject(this, new Vector3(x, y, 0), null, null, z);
+ }
+
+ ///
+ /// Resizes to a specified set of X/Y/Z dimensions using one or more variables
+ ///
+ ///
+ ///
+ ///
+ /// A resized object
+ public OSCADObject Resize(Variable x, double y, Variable z)
+ {
+ return new ResizedObject(this, new Vector3(0, y, 0), x, null, z);
+ }
+
+ ///
+ /// Resizes to a specified set of X/Y/Z dimensions using one or more variables
+ ///
+ ///
+ ///
+ ///
+ /// A resized object
+ public OSCADObject Resize(double x, Variable y, Variable z)
+ {
+ return new ResizedObject(this, new Vector3(x, 0, 0), null, y, z);
+ }
+
+ ///
+ /// Resizes to a specified set of X/Y/Z dimensions using one or more variables
+ ///
+ ///
+ ///
+ ///
+ /// A resized object
+ public OSCADObject Resize(Variable x, Variable y, double z)
+ {
+ return new ResizedObject(this, new Vector3(0, 0, z), x, y, null);
+ }
+ #endregion
+
///
/// Rotates about a specified X/Y/Z euler angle
///
diff --git a/OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs b/OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs
index 7e892cb..c914b68 100644
--- a/OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs
+++ b/OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs
@@ -38,10 +38,10 @@ namespace OSCADSharp.Transforms
///
internal ColoredObject(OSCADObject obj, Variable colorName, Variable opacity) : base(obj)
{
- this.bindings.Add(this, "color", colorName);
+ this.Bind("color", colorName);
if(opacity != null)
{
- this.bindings.Add(this, "opacity", opacity);
+ this.Bind("opacity", opacity);
}
}
@@ -79,8 +79,6 @@ namespace OSCADSharp.Transforms
{"color", "color" },
{"opacity", "opacity" }
});
- private Variable colorName;
- private Variable opacity;
public override void Bind(string property, Variable variable)
{
diff --git a/OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs b/OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs
index 4f96f36..f8fda95 100644
--- a/OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs
+++ b/OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs
@@ -29,6 +29,23 @@ namespace OSCADSharp.Transforms
{
this.Normal = new BindableVector(normal);
}
+
+ internal MirroredObject(OSCADObject obj, Variable normal) : base(obj)
+ {
+ this.Bind("normal", normal);
+ }
+
+ internal MirroredObject(OSCADObject obj, Vector3 normal, Variable x, Variable y, Variable z) : base(obj)
+ {
+ this.Normal = new BindableVector(normal);
+
+ if (x != null)
+ this.Bind("x", x);
+ if (y != null)
+ this.Bind("y", y);
+ if (z != null)
+ this.Bind("z", z);
+ }
public override string ToString()
{
@@ -97,7 +114,16 @@ namespace OSCADSharp.Transforms
});
public override void Bind(string property, Variable variable)
{
- this.bindings.Add(this, property, variable);
+ var bindableVec = this.Normal as BindableVector;
+
+ if (bindableVec != null && property == "x" || property == "y" || property == "z")
+ {
+ bindableVec.Bind(property, variable);
+ }
+ else
+ {
+ this.bindings.Add(this, property, variable);
+ }
}
}
}
diff --git a/OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs b/OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs
index 9cbb561..18e24fa 100644
--- a/OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs
+++ b/OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs
@@ -29,6 +29,23 @@ namespace OSCADSharp.Transforms
Size = new BindableVector(size);
}
+ internal ResizedObject(OSCADObject obj, Variable size) : base(obj)
+ {
+ this.Bind("size", size);
+ }
+
+ internal ResizedObject(OSCADObject obj, Vector3 size, Variable x, Variable y, Variable z) :base(obj)
+ {
+ this.Size = new BindableVector(size);
+
+ if (x != null)
+ this.Bind("x", x);
+ if (y != null)
+ this.Bind("y", y);
+ if (z != null)
+ this.Bind("z", z);
+ }
+
public override string ToString()
{
string size = this.bindings.Contains("size") ? this.bindings.Get("size").BoundVariable.Name : this.Size.ToString();