+ Parameterized bindings for Rotate, scale

This commit is contained in:
Michael L Smith 2016-03-02 21:01:34 -08:00
parent cc293b1638
commit 534bba1408
5 changed files with 254 additions and 0 deletions

View File

@ -23,5 +23,17 @@ namespace OSCADSharp.UnitTests.Transforms
string script = cyl.ToString();
Assert.IsTrue(script.Contains("rotate(myRot)"));
}
[TestMethod]
public void Rotate_CanBindAngleWithParameters()
{
var xAngle = new Variable("xAngle", 30);
var yAngle = new Variable("yAngle", -20);
var cyl = new Cylinder().Rotate(xAngle, yAngle, 120);
string script = cyl.ToString();
Assert.IsTrue(script.Contains("rotate([xAngle, yAngle, 120])"));
}
}
}

View File

@ -47,5 +47,18 @@ namespace OSCADSharp.UnitTests.Transforms
string script = cube.ToString();
Assert.IsTrue(script.Contains("v = scaleVar"));
}
[TestMethod]
public void Scale_CanBindParameterizedScaleValue()
{
var x = new Variable("xS", 3);
var y = new Variable("yS", 4);
var z = new Variable("zS", 3);
var cube = new Cube().Scale(x, y, z);
string script = cube.ToString();
Assert.IsTrue(script.Contains("v = [xS, yS, zS]"));
}
}
}

View File

@ -35,6 +35,8 @@ namespace OSCADSharp
#endregion
#region Transforms
#region Color
/// <summary>
/// Applies Color and/or Opacity to this object
/// </summary>
@ -56,6 +58,7 @@ namespace OSCADSharp
{
return new ColoredObject(this, colorName, opacity);
}
#endregion
#region Mirror
/// <summary>
@ -295,6 +298,7 @@ namespace OSCADSharp
}
#endregion
#region Rotate
/// <summary>
/// Rotates about a specified X/Y/Z euler angle
/// </summary>
@ -305,6 +309,16 @@ namespace OSCADSharp
return new RotatedObject(this, angle);
}
/// <summary>
/// Rotates about a specified X/Y/Z euler angle variable
/// </summary>
/// <param name="angle">The angle(s) to rotate</param>
/// <returns>A rotated object</returns>
public OSCADObject Rotate(Variable angle)
{
return new RotatedObject(this, angle);
}
/// <summary>
/// Rotates about a specified X/Y/Z euler angle
/// </summary>
@ -317,6 +331,92 @@ namespace OSCADSharp
return this.Rotate(new Vector3(x, y, z));
}
/// <summary>
/// Rotates about a specified X/Y/Z euler variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A rotated object</returns>
public OSCADObject Rotate(Variable x, Variable y, Variable z)
{
return new RotatedObject(this, new Vector3(), x, y, z);
}
/// <summary>
/// Rotates about a specified X/Y/Z euler with one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A rotated object</returns>
public OSCADObject Rotate(Variable x, double y, double z)
{
return new RotatedObject(this, new Vector3(0, y, z), x, null, null);
}
/// <summary>
/// Rotates about a specified X/Y/Z euler with one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A rotated object</returns>
public OSCADObject Rotate(double x, Variable y, double z)
{
return new RotatedObject(this, new Vector3(x, 0, z), null, y, null);
}
/// <summary>
/// Rotates about a specified X/Y/Z euler with one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A rotated object</returns>
public OSCADObject Rotate(double x, double y, Variable z)
{
return new RotatedObject(this, new Vector3(x, y, 0), null, null, z);
}
/// <summary>
/// Rotates about a specified X/Y/Z euler with one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A rotated object</returns>
public OSCADObject Rotate(Variable x, double y, Variable z)
{
return new RotatedObject(this, new Vector3(0, y, 0), x, null, z);
}
/// <summary>
/// Rotates about a specified X/Y/Z euler with one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A rotated object</returns>
public OSCADObject Rotate(double x, Variable y, Variable z)
{
return new RotatedObject(this, new Vector3(x, 0, 0), null, y, z);
}
/// <summary>
/// Rotates about a specified X/Y/Z euler with one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A rotated object</returns>
public OSCADObject Rotate(Variable x, Variable y, double z)
{
return new RotatedObject(this, new Vector3(0, 0, z), x, y, null);
}
#endregion
#region Scale
/// <summary>
/// Rescales an object by an X/Y/Z scale factor
/// </summary>
@ -327,6 +427,16 @@ namespace OSCADSharp
return new ScaledObject(this, scale);
}
/// <summary>
/// Rescales an object by an X/Y/Z scale factor variable
/// </summary>
/// <param name="scale">The scale to apply. For example 1, 2, 1 would yield 2x scale on the Y axis</param>
/// <returns>A scaled object</returns>
public OSCADObject Scale(Variable scale)
{
return new ScaledObject(this, scale);
}
/// <summary>
/// Rescales an object by an X/Y/Z scale factor
/// </summary>
@ -339,6 +449,91 @@ namespace OSCADSharp
return this.Scale(new Vector3(x, y, z));
}
/// <summary>
/// Rescales an object by an X/Y/Z scale factor variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A scaled object</returns>
public OSCADObject Scale(Variable x, Variable y, Variable z)
{
return new ScaledObject(this, new Vector3(), x, y, z);
}
/// <summary>
/// Rescales an object by one or more X/Y/Z scale factor variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A scaled object</returns>
public OSCADObject Scale(Variable x, double y, double z)
{
return new ScaledObject(this, new Vector3(0, y, z), x, null, null);
}
/// <summary>
/// Rescales an object by one or more X/Y/Z scale factor variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A scaled object</returns>
public OSCADObject Scale(double x, Variable y, double z)
{
return new ScaledObject(this, new Vector3(x, 0, z), null, y, null);
}
/// <summary>
/// Rescales an object by one or more X/Y/Z scale factor variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A scaled object</returns>
public OSCADObject Scale(double x, double y, Variable z)
{
return new ScaledObject(this, new Vector3(x, y, 0), null, null, z);
}
/// <summary>
/// Rescales an object by one or more X/Y/Z scale factor variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A scaled object</returns>
public OSCADObject Scale(Variable x, double y, Variable z)
{
return new ScaledObject(this, new Vector3(0, y, 0), x, null, z);
}
/// <summary>
/// Rescales an object by one or more X/Y/Z scale factor variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A scaled object</returns>
public OSCADObject Scale(double x, Variable y, Variable z)
{
return new ScaledObject(this, new Vector3(x, 0, 0), null, y, z);
}
/// <summary>
/// Rescales an object by one or more X/Y/Z scale factor variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A scaled object</returns>
public OSCADObject Scale(Variable x, Variable y, double z)
{
return new ScaledObject(this, new Vector3(0, 0, z), x, y, null);
}
#endregion
/// <summary>
/// Translates an object by the specified amount
/// </summary>

View File

@ -29,6 +29,23 @@ namespace OSCADSharp.Transforms
this.Angle = new BindableVector(angle);
}
internal RotatedObject(OSCADObject obj, Variable normal) : base(obj)
{
this.Bind("angle", normal);
}
internal RotatedObject(OSCADObject obj, Vector3 angle, Variable x, Variable y, Variable z) : base(obj)
{
this.Angle = new BindableVector(angle);
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 angle = this.bindings.Contains("angle") ? this.bindings.Get("angle").BoundVariable.Name : this.Angle.ToString();

View File

@ -29,6 +29,23 @@ namespace OSCADSharp.Transforms
this.ScaleFactor = new BindableVector(scale);
}
internal ScaledObject(OSCADObject obj, Variable normal) : base(obj)
{
this.Bind("scalefactor", normal);
}
internal ScaledObject(OSCADObject obj, Vector3 scale, Variable x, Variable y, Variable z) : base(obj)
{
this.ScaleFactor = new BindableVector(scale);
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 scale = this.bindings.Contains("scalefactor") ? this.bindings.Get("scalefactor").BoundVariable.Name : this.ScaleFactor.ToString();