+ Position() on resized objects is now supported via the averaging of Bounds() positions.

This commit is contained in:
Michael L Smith 2016-02-22 18:43:26 -08:00
parent 62a0a034a1
commit 4527a3cd33
3 changed files with 8 additions and 4 deletions

View File

@ -13,7 +13,9 @@ namespace OSCADSharp.ConsoleTests
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
var obj = new Cube(5, 10, 20) + new Sphere(10).Translate(-10, 5, 0);
var obj = new Cube(5, 5, 20)
.Translate(30, 0, 0).Rotate(0, 90, 0).Resize(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);

View File

@ -12,11 +12,12 @@ namespace OSCADSharp.UnitTests.Transforms
public class ResizeTests public class ResizeTests
{ {
[TestMethod] [TestMethod]
[ExpectedException(typeof(NotSupportedException))] public void Resize_BoundaryBasedPositionAfterResizeIsInExpectedLocation()
public void Resize_PositionNotSupportedAfterResize()
{ {
var pos = new Cube(5, 5, 20) var pos = new Cube(5, 5, 20)
.Translate(30, 0, 0).Rotate(0, 90, 0).Resize(2, 2, 2).Position(); .Translate(30, 0, 0).Rotate(0, 90, 0).Resize(2, 2, 2).Position();
Assert.AreEqual(new Vector3(1, 1, -13), pos);
} }
[TestMethod] [TestMethod]

View File

@ -50,7 +50,8 @@ namespace OSCADSharp.Transforms
public override Vector3 Position() public override Vector3 Position()
{ {
throw new NotSupportedException("Position is not supported on Resized objects."); var bounds = this.Bounds();
return Vector3.Average(bounds.BottomLeft, bounds.TopRight);
} }
public override Bounds Bounds() public override Bounds Bounds()