Fix for an issue where Rotating/Translating an object, then using Scale would yield the wrong Position() value.

This commit is contained in:
Michael Smith 2016-02-19 17:33:30 -08:00
parent f1f699afe4
commit 80c400dee8
4 changed files with 27 additions and 2 deletions

View File

@ -13,7 +13,8 @@ namespace OSCADSharp.ConsoleTests
{
static void Main(string[] args)
{
var obj = new Cube() + new Sphere() + new Sphere().Translate(2, 2, 2) - new Cylinder(2, 5) + new Text3D("Hey hey!");
var obj = new Cube(5, 5, 20)
.Translate(30, 0, 0).Rotate(0, 90, 0).Scale(2, 2, 2);
var pos = obj.Position();
var cyl1 = new Cylinder(1, 100, true).Translate(pos);

View File

@ -65,6 +65,7 @@
<Compile Include="Booleans\DifferenceTests.cs" />
<Compile Include="Booleans\IntersectionTests.cs" />
<Compile Include="Transforms\MinkowskiTests.cs" />
<Compile Include="Transforms\ScaleTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OSCADSharp\OSCADSharp.csproj">

View File

@ -0,0 +1,23 @@
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.Transforms
{
[TestClass]
public class ScaleTests
{
[TestMethod]
public void Scale_TranslateRotateScaleStillYieldsCorrectPosition()
{
var obj = new Cube(5, 5, 20)
.Translate(30, 0, 0).Rotate(0, 90, 0).Scale(2, 2, 2);
Assert.AreEqual(new Vector3(20, 5, -65), obj.Position());
}
}
}

View File

@ -51,7 +51,7 @@ namespace OSCADSharp.Transforms
public override Vector3 Position()
{
return obj.Position();
return obj.Position() * this.ScaleFactor;
}
}
}