mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-27 21:08:29 +00:00
+ Initial Bounds implementation for Cube, Cylinder, Sphere and (sort of) Text3D
This commit is contained in:
parent
6865c19886
commit
fd677aa909
@ -13,8 +13,7 @@ namespace OSCADSharp.ConsoleTests
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var obj = new Cube(5, 5, 20)
|
var obj = new Text3D("BBBB", 16);
|
||||||
.Translate(30, 0, 0).Rotate(0, 90, 0).Scale(2, 2, 2);
|
|
||||||
|
|
||||||
var pos = obj.Position();
|
var pos = obj.Position();
|
||||||
var cyl1 = new Cylinder(1, 100, true).Translate(pos);
|
var cyl1 = new Cylinder(1, 100, true).Translate(pos);
|
||||||
@ -22,7 +21,10 @@ namespace OSCADSharp.ConsoleTests
|
|||||||
var cyl3 = new Cylinder(1, 100, true).Rotate(90, 0, 0).Translate(pos);
|
var cyl3 = new Cylinder(1, 100, true).Rotate(90, 0, 0).Translate(pos);
|
||||||
var axisHelper = cyl1.Union(cyl2, cyl3).Color("Red");
|
var axisHelper = cyl1.Union(cyl2, cyl3).Color("Red");
|
||||||
|
|
||||||
string script = obj.Union(axisHelper).ToString();
|
var topCorner = new Sphere().Translate(obj.Bounds().TopRight);
|
||||||
|
var botCorner = new Sphere().Translate(obj.Bounds().BottomLeft);
|
||||||
|
|
||||||
|
string script = (obj + topCorner + botCorner).ToString();
|
||||||
|
|
||||||
File.WriteAllLines("test.scad", new string[] { script.ToString() });
|
File.WriteAllLines("test.scad", new string[] { script.ToString() });
|
||||||
//Console.ReadKey();
|
//Console.ReadKey();
|
||||||
|
|||||||
@ -85,5 +85,23 @@ namespace OSCADSharp.UnitTests
|
|||||||
|
|
||||||
Assert.AreEqual(new Vector3(-5, 0, -15), cube.Position());
|
Assert.AreEqual(new Vector3(-5, 0, -15), cube.Position());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Cube_BoundsAreInExpectedPositionNotCentered()
|
||||||
|
{
|
||||||
|
var obj = new Cube(5, 5, 20, false);
|
||||||
|
|
||||||
|
Assert.AreEqual(new Vector3(5, 5, 20), obj.Bounds().TopRight);
|
||||||
|
Assert.AreEqual(new Vector3(), obj.Bounds().BottomLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Cube_BoundsAreInExpectedPositionCentered()
|
||||||
|
{
|
||||||
|
var obj = new Cube(5, 5, 20, true);
|
||||||
|
|
||||||
|
Assert.AreEqual(new Vector3(2.5, 2.5, 10), obj.Bounds().TopRight);
|
||||||
|
Assert.AreEqual(new Vector3(-2.5, -2.5, -10), obj.Bounds().BottomLeft);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,5 +39,23 @@ namespace OSCADSharp.UnitTests
|
|||||||
|
|
||||||
Assert.AreEqual(new Vector3(), cylinder.Position());
|
Assert.AreEqual(new Vector3(), cylinder.Position());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Cylinder_BoundsAreInExpectedPositionNotCentered()
|
||||||
|
{
|
||||||
|
var obj = new Cylinder(5, 20);
|
||||||
|
|
||||||
|
Assert.AreEqual(new Vector3(2.5, 2.5, 20), obj.Bounds().TopRight);
|
||||||
|
Assert.AreEqual(new Vector3(-2.5, -2.5, 0), obj.Bounds().BottomLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Cylinder_BoundsAreInExpectedPositionCentered()
|
||||||
|
{
|
||||||
|
var obj = new Cylinder(5, 20, true);
|
||||||
|
|
||||||
|
Assert.AreEqual(new Vector3(2.5, 2.5, 10), obj.Bounds().TopRight);
|
||||||
|
Assert.AreEqual(new Vector3(-2.5, -2.5, -10), obj.Bounds().BottomLeft);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,5 +77,14 @@ namespace OSCADSharp.UnitTests
|
|||||||
|
|
||||||
Assert.AreEqual(new Vector3(), sphere.Position());
|
Assert.AreEqual(new Vector3(), sphere.Position());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Sphere_BoundsAreInExpectedPositionCentered()
|
||||||
|
{
|
||||||
|
var obj = new Sphere(30);
|
||||||
|
|
||||||
|
Assert.AreEqual(new Vector3(15, 15, 15), obj.Bounds().TopRight);
|
||||||
|
Assert.AreEqual(new Vector3(-15, -15, -15), obj.Bounds().BottomLeft);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,5 +18,14 @@ namespace OSCADSharp.UnitTests
|
|||||||
|
|
||||||
Assert.AreEqual(new Vector3(), text.Position());
|
Assert.AreEqual(new Vector3(), text.Position());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Text_BoundsBasedOnFontSize()
|
||||||
|
{
|
||||||
|
var obj = new Text3D("BBBB", 16);
|
||||||
|
|
||||||
|
Assert.AreEqual(new Vector3(32, 8, 0.5), obj.Bounds().TopRight);
|
||||||
|
Assert.AreEqual(new Vector3(-32, -8, -0.5), obj.Bounds().BottomLeft);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,7 +113,15 @@ namespace OSCADSharp.Solids
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Bounds Bounds()
|
public override Bounds Bounds()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if(Center == false)
|
||||||
|
{
|
||||||
|
return new Bounds(new Vector3(), new Vector3(this.Size.X, this.Size.Y, this.Size.Z));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new Bounds(new Vector3(-this.Size.X / 2, -this.Size.Y / 2, -this.Size.Z / 2),
|
||||||
|
new Vector3(this.Size.X / 2, this.Size.Y / 2, this.Size.Z / 2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -174,7 +174,16 @@ namespace OSCADSharp.Solids
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Bounds Bounds()
|
public override Bounds Bounds()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if(this.Center == false)
|
||||||
|
{
|
||||||
|
return new Bounds(new Vector3(-this.Radius, -this.Radius, 0),
|
||||||
|
new Vector3(this.Radius, this.Radius, this.Height));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new Bounds(new Vector3(-this.Radius, -this.Radius, -this.Height / 2),
|
||||||
|
new Vector3(this.Radius, this.Radius, this.Height / 2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,7 +106,8 @@ namespace OSCADSharp.Solids
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Bounds Bounds()
|
public override Bounds Bounds()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return new Bounds(new Vector3(-this.Radius, -this.Radius, -this.Radius),
|
||||||
|
new Vector3(this.Radius, this.Radius, this.Radius));
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -144,11 +144,18 @@ namespace OSCADSharp.Solids
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the approximate boundaries of this OpenSCAD object
|
/// Returns the approximate boundaries of this OpenSCAD object
|
||||||
|
///
|
||||||
|
/// Disclaimer: The bounds for text are particularly inaccurate, since
|
||||||
|
/// OSCADSharp doesn't have all font data necessary to calculate the
|
||||||
|
/// boundaries for all the possible fonts that could be used
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Bounds Bounds()
|
public override Bounds Bounds()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
double fontSize = this.Size ?? 8;
|
||||||
|
double xAmount = fontSize * this.Text.Length;
|
||||||
|
|
||||||
|
return new Bounds(new Vector3(-xAmount/2, -fontSize/2, -.5), new Vector3(xAmount / 2, fontSize / 2, .5));
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user