mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-23 11:18:27 +00:00
Added Cube position, Translate interpolation
This commit is contained in:
parent
49d2de3046
commit
2a7ee3ab63
@ -13,11 +13,15 @@ namespace OSCADSharp.ConsoleTests
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var cube = new Cube();
|
var cube = new Cube(50, 50, 50).Translate(10, 10, 0);
|
||||||
var sphere = new Sphere().Translate(0, 0, 2);
|
|
||||||
var hull = cube.Hull(sphere);
|
|
||||||
|
|
||||||
string script = hull.ToString();
|
var pos = cube.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 = cube.Union(axisHelper).ToString();
|
||||||
|
|
||||||
File.WriteAllLines("test.scad", new string[] { script.ToString() });
|
File.WriteAllLines("test.scad", new string[] { script.ToString() });
|
||||||
//Console.ReadKey();
|
//Console.ReadKey();
|
||||||
|
|||||||
@ -53,5 +53,37 @@ namespace OSCADSharp.UnitTests
|
|||||||
Assert.IsTrue(script.StartsWith("cube("));
|
Assert.IsTrue(script.StartsWith("cube("));
|
||||||
Assert.IsTrue(script.EndsWith(");"));
|
Assert.IsTrue(script.EndsWith(");"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Cube_InitialPositionForNonCenteredCubeIsHalfLengthWidthAndHeight()
|
||||||
|
{
|
||||||
|
var cube = new Cube(10, 10, 10);
|
||||||
|
|
||||||
|
Assert.IsTrue(cube.Position() == new Vector3(5, 5, 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Cube_InitialPositionIfCenteredIsOrigin()
|
||||||
|
{
|
||||||
|
var cube = new Cube(25, 25, 25, true);
|
||||||
|
|
||||||
|
Assert.AreEqual(new Vector3(), cube.Position());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Cube_PositionMovesWithCubeOnTranslate()
|
||||||
|
{
|
||||||
|
var cube = new Cube(50, 50, 50).Translate(10, 10, 0);
|
||||||
|
|
||||||
|
Assert.AreEqual(new Vector3(35, 35, 25), cube.Position());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Cube_PositionMovesWithCubeOnNegativeTranslate()
|
||||||
|
{
|
||||||
|
var cube = new Cube(50, 50, 50, true).Translate(-5, 0, -15);
|
||||||
|
|
||||||
|
Assert.AreEqual(new Vector3(-5, 0, -15), cube.Position());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -204,7 +204,6 @@ namespace OSCADSharp
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Utility Methods
|
#region Utility Methods
|
||||||
protected Vector3 position;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the computed position of this object.
|
/// Returns the computed position of this object.
|
||||||
///
|
///
|
||||||
|
|||||||
@ -79,7 +79,17 @@ namespace OSCADSharp.Solids
|
|||||||
|
|
||||||
public override Vector3 Position()
|
public override Vector3 Position()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
Vector3 position;
|
||||||
|
if(this.Center == false)
|
||||||
|
{
|
||||||
|
position = new Vector3(this.Size.X / 2, this.Size.Y / 2, this.Size.Z / 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
position = new Vector3();
|
||||||
|
}
|
||||||
|
|
||||||
|
return position;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,7 +46,31 @@ namespace OSCADSharp
|
|||||||
return new Vector3(this.X, this.Y, this.Z);
|
return new Vector3(this.X, this.Y, this.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Operators
|
#region Operators/Overrides
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
return this.GetHashCode() == obj.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return this.ToString().GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(Vector3 left, Vector3 right)
|
||||||
|
{
|
||||||
|
return left.X == right.X &&
|
||||||
|
left.Y == right.Y &&
|
||||||
|
left.Z == right.Z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(Vector3 left, Vector3 right)
|
||||||
|
{
|
||||||
|
return !(left.X == right.X &&
|
||||||
|
left.Y == right.Y &&
|
||||||
|
left.Z == right.Z);
|
||||||
|
}
|
||||||
|
|
||||||
public static Vector3 operator +(Vector3 left, Vector3 right)
|
public static Vector3 operator +(Vector3 left, Vector3 right)
|
||||||
{
|
{
|
||||||
return new Vector3(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
|
return new Vector3(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
|
||||||
|
|||||||
@ -53,7 +53,7 @@ namespace OSCADSharp.Transforms
|
|||||||
|
|
||||||
public override Vector3 Position()
|
public override Vector3 Position()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return this.obj.Position();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,7 +48,7 @@ namespace OSCADSharp.Transforms
|
|||||||
|
|
||||||
public override Vector3 Position()
|
public override Vector3 Position()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return this.obj.Position() + this.Vector;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user