mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-11 13:38:33 +00:00
Bindings for:
+ Mirror + Resize + Scale + Rotate + Translate
This commit is contained in:
parent
7f7447e633
commit
13dbc41149
@ -72,6 +72,7 @@
|
||||
<Compile Include="Booleans\IntersectionTests.cs" />
|
||||
<Compile Include="Transforms\MinkowskiTests.cs" />
|
||||
<Compile Include="Transforms\ResizeTests.cs" />
|
||||
<Compile Include="Transforms\RotateTests.cs" />
|
||||
<Compile Include="Transforms\ScaleTests.cs" />
|
||||
<Compile Include="Transforms\TranslateTests.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -59,5 +59,15 @@ namespace OSCADSharp.UnitTests
|
||||
|
||||
var pos = cube.Mirror(1, 1, 0).Bounds();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Mirror_CanBindNormal()
|
||||
{
|
||||
var cube = new Cube(5, 20, 15).Mirror(1, 0, 0);
|
||||
cube.Bind("normal", new Scripting.Variable("myVar", new Vector3(1, 0, 0)));
|
||||
|
||||
string script = cube.ToString();
|
||||
Assert.IsTrue(script.Contains("mirror(myVar)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OSCADSharp.Scripting;
|
||||
using OSCADSharp.Solids;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -29,5 +30,19 @@ namespace OSCADSharp.UnitTests.Transforms
|
||||
Assert.AreEqual(new Vector3(5, 5, 5), bounds.TopRight);
|
||||
Assert.AreEqual(new Vector3(0, 0, 0), bounds.BottomLeft);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Resize_SizeBindingwithVectorAppearsInOutput()
|
||||
{
|
||||
var resizedCube = new Cube().Resize(5, 5, 10);
|
||||
|
||||
var sizeVar = new Variable("mySize", new Vector3(20, 30, 20));
|
||||
|
||||
resizedCube.Bind("size", sizeVar);
|
||||
|
||||
string script = resizedCube.ToString();
|
||||
|
||||
Assert.IsTrue(script.Contains("resize(mySize)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
27
OSCADSharp/OSCADSharp.UnitTests/Transforms/RotateTests.cs
Normal file
27
OSCADSharp/OSCADSharp.UnitTests/Transforms/RotateTests.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OSCADSharp.Scripting;
|
||||
using OSCADSharp.Solids;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OSCADSharp.UnitTests.Transforms
|
||||
{
|
||||
[TestClass]
|
||||
public class RotateTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Rotate_CanBindAngle()
|
||||
{
|
||||
var cyl = new Cylinder().Rotate(0, 90, 0);
|
||||
var rotVar = new Variable("myRot", new Vector3(120, 90, 30));
|
||||
|
||||
cyl.Bind("angle", rotVar);
|
||||
|
||||
string script = cyl.ToString();
|
||||
Assert.IsTrue(script.Contains("rotate(myRot)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OSCADSharp.Scripting;
|
||||
using OSCADSharp.Solids;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -34,5 +35,17 @@ namespace OSCADSharp.UnitTests.Transforms
|
||||
Assert.AreEqual(bounds.Y_Min, 0);
|
||||
Assert.AreEqual(bounds.Z_Min, 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Scale_CanBindScaleValue()
|
||||
{
|
||||
var cube = new Cube().Scale(2, 2, 2);
|
||||
var scaleVar = new Variable("scaleVar", new Vector3(5, 1, 2));
|
||||
|
||||
cube.Bind("scale", scaleVar);
|
||||
|
||||
string script = cube.ToString();
|
||||
Assert.IsTrue(script.Contains("v = scaleVar"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OSCADSharp.Scripting;
|
||||
using OSCADSharp.Solids;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -22,5 +23,17 @@ namespace OSCADSharp.UnitTests.Transforms
|
||||
Assert.AreEqual(boundsAfter.TopRight, boundsBefore.TopRight + new Vector3(5, 2, 3));
|
||||
Assert.AreEqual(boundsAfter.BottomLeft, boundsBefore.BottomLeft + new Vector3(5, 2, 3));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Translate_CanBindVector()
|
||||
{
|
||||
var cube = new Cube().Translate(10, 0, 0);
|
||||
var vec = new Variable("vec", new Vector3(0, 20, 30));
|
||||
|
||||
cube.Bind("vector", vec);
|
||||
|
||||
string script = cube.ToString();
|
||||
Assert.IsTrue(script.Contains("v = vec"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,9 +142,9 @@ namespace OSCADSharp
|
||||
/// <returns></returns>
|
||||
public static bool operator ==(Vector3 left, Vector3 right)
|
||||
{
|
||||
return left.X == right.X &&
|
||||
left.Y == right.Y &&
|
||||
left.Z == right.Z;
|
||||
return left?.X == right?.X &&
|
||||
left?.Y == right?.Y &&
|
||||
left?.Z == right?.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -155,9 +155,7 @@ namespace OSCADSharp
|
||||
/// <returns></returns>
|
||||
public static bool operator !=(Vector3 left, Vector3 right)
|
||||
{
|
||||
return !(left.X == right.X &&
|
||||
left.Y == right.Y &&
|
||||
left.Z == right.Z);
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using OSCADSharp.Scripting;
|
||||
using OSCADSharp.Bindings;
|
||||
using OSCADSharp.Scripting;
|
||||
using OSCADSharp.Spatial;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -17,7 +18,7 @@ namespace OSCADSharp.Transforms
|
||||
/// The normal vector of a plane intersecting the origin of the object,
|
||||
/// through which to mirror it.
|
||||
/// </summary>
|
||||
internal Vector3 Normal { get; set; } = new Vector3();
|
||||
internal Vector3 Normal { get; set; } = new BindableVector();
|
||||
|
||||
/// <summary>
|
||||
/// Creates an object that's mirrored on a plane
|
||||
@ -26,12 +27,14 @@ namespace OSCADSharp.Transforms
|
||||
/// <param name="normal">The normal vector of the plane on the object's origin to mirror upon</param>
|
||||
internal MirroredObject(OSCADObject obj, Vector3 normal) : base(obj)
|
||||
{
|
||||
this.Normal = normal;
|
||||
this.Normal = new BindableVector(normal);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string mirrorCommand = String.Format("mirror([{0}, {1}, {2}])", this.Normal.X, this.Normal.Y, this.Normal.Z);
|
||||
string normal = this.bindings.Contains("normal") ? this.bindings.Get("normal").BoundVariable.Name : this.Normal.ToString();
|
||||
|
||||
string mirrorCommand = String.Format("mirror({0})", normal);
|
||||
var formatter = new SingleBlockFormatter(mirrorCommand, this.obj.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
@ -89,9 +92,12 @@ namespace OSCADSharp.Transforms
|
||||
return new Bounds(newBottomLeft, newTopRight);
|
||||
}
|
||||
|
||||
private Bindings.Bindings bindings = new Bindings.Bindings(new Dictionary<string, string>() {
|
||||
{"normal", "normal"}
|
||||
});
|
||||
public override void Bind(string property, Variable variable)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
this.bindings.Add<MirroredObject>(this, property, variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OSCADSharp.Spatial;
|
||||
using OSCADSharp.Bindings;
|
||||
|
||||
namespace OSCADSharp.Transforms
|
||||
{
|
||||
@ -25,13 +26,14 @@ namespace OSCADSharp.Transforms
|
||||
/// <param name="size">The size to resize to, in terms of x/y/z dimensions</param>
|
||||
internal ResizedObject(OSCADObject obj, Vector3 size) : base(obj)
|
||||
{
|
||||
this.Size = size;
|
||||
Size = new BindableVector(size);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string resizeCommand = String.Format("resize([{0}, {1}, {2}])", this.Size.X.ToString(),
|
||||
this.Size.Y.ToString(), this.Size.Z.ToString());
|
||||
string size = this.bindings.Contains("size") ? this.bindings.Get("size").BoundVariable.Name : this.Size.ToString();
|
||||
|
||||
string resizeCommand = String.Format("resize({0})", size);
|
||||
var formatter = new SingleBlockFormatter(resizeCommand, this.obj.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
@ -62,9 +64,22 @@ namespace OSCADSharp.Transforms
|
||||
return new Bounds(oldBounds.BottomLeft * scaleMultiplier, oldBounds.TopRight * scaleMultiplier);
|
||||
}
|
||||
|
||||
|
||||
private Bindings.Bindings bindings = new Bindings.Bindings(new Dictionary<string, string>() {
|
||||
{ "size", "size" }
|
||||
});
|
||||
public override void Bind(string property, Variable variable)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var bindableVec = this.Size as BindableVector;
|
||||
|
||||
if(bindableVec != null && property == "x" || property == "y" || property == "z")
|
||||
{
|
||||
bindableVec.Bind(property, variable);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bindings.Add<ResizedObject>(this, property, variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using OSCADSharp.Scripting;
|
||||
using OSCADSharp.Bindings;
|
||||
using OSCADSharp.Scripting;
|
||||
using OSCADSharp.Spatial;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -16,7 +17,7 @@ namespace OSCADSharp.Transforms
|
||||
/// <summary>
|
||||
/// The angle to rotate, in terms of X/Y/Z euler angles
|
||||
/// </summary>
|
||||
internal Vector3 Angle { get; set; } = new Vector3();
|
||||
internal Vector3 Angle { get; set; } = new BindableVector();
|
||||
|
||||
/// <summary>
|
||||
/// Creates an object with rotation applied
|
||||
@ -25,13 +26,14 @@ namespace OSCADSharp.Transforms
|
||||
/// <param name="angle">The angle to rotate</param>
|
||||
internal RotatedObject(OSCADObject obj, Vector3 angle) : base(obj)
|
||||
{
|
||||
this.Angle = angle;
|
||||
this.Angle = new BindableVector(angle);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string rotateCommand = String.Format("rotate([{0}, {1}, {2}])",
|
||||
this.Angle.X.ToString(), this.Angle.Y.ToString(), this.Angle.Z.ToString());
|
||||
string angle = this.bindings.Contains("angle") ? this.bindings.Get("angle").BoundVariable.Name : this.Angle.ToString();
|
||||
|
||||
string rotateCommand = String.Format("rotate({0})", angle.ToString());
|
||||
var formatter = new SingleBlockFormatter(rotateCommand, this.obj.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
@ -56,9 +58,21 @@ namespace OSCADSharp.Transforms
|
||||
Matrix.GetRotatedPoint(oldBounds.TopRight, this.Angle.X, this.Angle.Y, this.Angle.Z));
|
||||
}
|
||||
|
||||
private Bindings.Bindings bindings = new Bindings.Bindings(new Dictionary<string, string>() {
|
||||
{ "angle", "angle" }
|
||||
});
|
||||
public override void Bind(string property, Variable variable)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var bindableVec = this.Angle as BindableVector;
|
||||
|
||||
if (bindableVec != null && property == "x" || property == "y" || property == "z")
|
||||
{
|
||||
bindableVec.Bind(property, variable);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bindings.Add<RotatedObject>(this, property, variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OSCADSharp.Spatial;
|
||||
using OSCADSharp.Bindings;
|
||||
|
||||
namespace OSCADSharp.Transforms
|
||||
{
|
||||
@ -16,7 +17,7 @@ namespace OSCADSharp.Transforms
|
||||
/// <summary>
|
||||
/// The scale factor to be applied
|
||||
/// </summary>
|
||||
internal Vector3 ScaleFactor { get; set; } = new Vector3(1, 1, 1);
|
||||
internal Vector3 ScaleFactor { get; set; } = new BindableVector(1, 1, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scaled object
|
||||
@ -25,13 +26,14 @@ namespace OSCADSharp.Transforms
|
||||
/// <param name="scale">Scale factor in x/y/z components</param>
|
||||
internal ScaledObject(OSCADObject obj, Vector3 scale) : base(obj)
|
||||
{
|
||||
this.ScaleFactor = scale;
|
||||
this.ScaleFactor = new BindableVector(scale);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string scaleCommand = String.Format("scale(v = [{0}, {1}, {2}])",
|
||||
this.ScaleFactor.X.ToString(), this.ScaleFactor.Y.ToString(), this.ScaleFactor.Z.ToString());
|
||||
string scale = this.bindings.Contains("scalefactor") ? this.bindings.Get("scalefactor").BoundVariable.Name : this.ScaleFactor.ToString();
|
||||
|
||||
string scaleCommand = String.Format("scale(v = {0})", scale);
|
||||
var formatter = new SingleBlockFormatter(scaleCommand, this.obj.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
@ -55,9 +57,22 @@ namespace OSCADSharp.Transforms
|
||||
return new Bounds(oldBounds.BottomLeft * this.ScaleFactor, oldBounds.TopRight * this.ScaleFactor);
|
||||
}
|
||||
|
||||
private Bindings.Bindings bindings = new Bindings.Bindings(new Dictionary<string, string>() {
|
||||
{ "scalefactor", "scalefactor" }
|
||||
});
|
||||
public override void Bind(string property, Variable variable)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var bindableVec = this.ScaleFactor as BindableVector;
|
||||
property = property == "scale" ? "scalefactor" : property;
|
||||
|
||||
if (bindableVec != null && property == "x" || property == "y" || property == "z")
|
||||
{
|
||||
bindableVec.Bind(property, variable);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bindings.Add<ScaledObject>(this, property, variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OSCADSharp.Spatial;
|
||||
using OSCADSharp.Bindings;
|
||||
|
||||
namespace OSCADSharp.Transforms
|
||||
{
|
||||
@ -22,13 +23,14 @@ namespace OSCADSharp.Transforms
|
||||
/// <param name="vector">Amount to translate by</param>
|
||||
internal TranslatedObject(OSCADObject obj, Vector3 vector) : base(obj)
|
||||
{
|
||||
this.Vector = vector;
|
||||
this.Vector = new BindableVector(vector);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string translateCommmand = String.Format("translate(v = [{0}, {1}, {2}])",
|
||||
this.Vector.X.ToString(), this.Vector.Y.ToString(), this.Vector.Z.ToString());
|
||||
string translation = this.bindings.Contains("vector") ? this.bindings.Get("vector").BoundVariable.Name : this.Vector.ToString();
|
||||
|
||||
string translateCommmand = String.Format("translate(v = {0})", translation);
|
||||
var formatter = new SingleBlockFormatter(translateCommmand, this.obj.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
@ -52,9 +54,21 @@ namespace OSCADSharp.Transforms
|
||||
return new Bounds(oldBounds.BottomLeft + this.Vector, oldBounds.TopRight + this.Vector);
|
||||
}
|
||||
|
||||
private Bindings.Bindings bindings = new Bindings.Bindings(new Dictionary<string, string>() {
|
||||
{ "vector", "vector" }
|
||||
});
|
||||
public override void Bind(string property, Variable variable)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var bindableVec = this.Vector as BindableVector;
|
||||
|
||||
if (bindableVec != null && property == "x" || property == "y" || property == "z")
|
||||
{
|
||||
bindableVec.Bind(property, variable);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bindings.Add<TranslatedObject>(this, property, variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user