+ Implemented Position on Cylinder, Sphere, Text3D

+ Made the executive decision that Text3D in OSCADSharp is always centered in script output, to facilitate correct position calculation.
This commit is contained in:
Michael L Smith 2016-02-15 21:00:43 -08:00
parent 12eb89adbb
commit 8831610bda
8 changed files with 75 additions and 6 deletions

View File

@ -13,15 +13,15 @@ namespace OSCADSharp.ConsoleTests
{
static void Main(string[] args)
{
var cube = new Cube(13, 13, 13).Rotate(90, 37.5, -180);
var obj = new Text3D("Hello, it's Meeeee.");
var pos = cube.Position();
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 = cube.Union(axisHelper).ToString();
string script = obj.Union(axisHelper).ToString();
File.WriteAllLines("test.scad", new string[] { script.ToString() });
//Console.ReadKey();

View File

@ -23,5 +23,21 @@ namespace OSCADSharp.UnitTests
Assert.IsTrue(script.Contains("h = 12.1"));
Assert.IsTrue(script.Contains("center = true"));
}
[TestMethod]
public void Cylinder_UncenteredPositionZValueIsHalfTheHeight()
{
var cylinder = new Cylinder(3, 40);
Assert.AreEqual(new Vector3(0, 0, 20), cylinder.Position());
}
[TestMethod]
public void Cylinder_CenteredCylinderPositionIsZero()
{
var cylinder = new Cylinder(5, 20, true);
Assert.AreEqual(new Vector3(), cylinder.Position());
}
}
}

View File

@ -59,6 +59,7 @@
<Compile Include="OSCADObjectTests.cs" />
<Compile Include="SphereTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Text3DTests.cs" />
<Compile Include="UnionTests.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -69,5 +69,13 @@ namespace OSCADSharp.UnitTests
Assert.IsTrue(sphere.IsSameAs(clone));
}
[TestMethod]
public void Sphere_PositionIsAtZero()
{
var sphere = new Sphere();
Assert.AreEqual(new Vector3(), sphere.Position());
}
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OSCADSharp.Solids;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp.UnitTests
{
[TestClass]
public class Text3DTests
{
[TestMethod]
public void Text_PositionIsCentered()
{
var text = new Text3D("Bom chicka bow wow");
Assert.AreEqual(new Vector3(), text.Position());
}
}
}

View File

@ -140,7 +140,17 @@ namespace OSCADSharp.Solids
public override Vector3 Position()
{
throw new NotImplementedException();
Vector3 position;
if (this.Center == false)
{
position = new Vector3(0, 0, this.Height / 2);
}
else
{
position = new Vector3();
}
return position;
}
#endregion
}

View File

@ -83,7 +83,7 @@ namespace OSCADSharp.Solids
public override Vector3 Position()
{
throw new NotImplementedException();
return new Vector3();
}
#endregion
}

View File

@ -116,6 +116,11 @@ namespace OSCADSharp.Solids
sb.Append("\"");
appendIfValueNotNullOrEmpty("size", this.Size?.ToString(), sb);
// Text is always centered in OSCADSharp to ensure correctness of
// position interpolation
appendIfValueNotNullOrEmpty("halign", "\"center\"", sb);
appendIfValueNotNullOrEmpty("valign", "\"center\"", sb);
appendIfValueNotNullOrEmpty("font", this.Font, sb);
appendIfValueNotNullOrEmpty("spacing", this.Spacing?.ToString(), sb);
appendIfValueNotNullOrEmpty("direction", this.TextDirection?.ToString(), sb);
@ -127,9 +132,16 @@ namespace OSCADSharp.Solids
return formatter.ToString();
}
/// <summary>
/// In reaction to the need for this value to be correct, halign and valign will always
/// be "center" by default, since non-centered text would vary dramatically in position based upon
/// the font of the text
/// - MLS 2/15/2016
/// </summary>
/// <returns></returns>
public override Vector3 Position()
{
throw new NotImplementedException();
return new Vector3();
}
#endregion
}