+ Position interpolation for single-axis mirroring.

This commit is contained in:
Michael L Smith 2016-02-15 21:45:38 -08:00
parent 294ae7e357
commit 07c845bcbd
4 changed files with 47 additions and 2 deletions

View File

@ -13,7 +13,7 @@ namespace OSCADSharp.ConsoleTests
{
static void Main(string[] args)
{
var obj = new Text3D("Hello, it's Meeeee.");
var obj = new Cube(5, 10, 20).Mirror(0, 0, 1);
var pos = obj.Position();
var cyl1 = new Cylinder(1, 100, true).Translate(pos);

View File

@ -0,0 +1,35 @@
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 MirrorTests
{
[TestMethod]
public void Mirror_SingleAxisMirrorInvertsPosition()
{
var cube = new Cube(5, 10, 20);
var xMirror = cube.Clone().Mirror(1, 0, 0);
var yMirror = cube.Clone().Mirror(0, 1, 0);
var zMirror = cube.Clone().Mirror(0, 0, 1);
var pos = cube.Position().Clone();
pos.X = -pos.X;
Assert.AreEqual(pos, xMirror.Position());
pos = cube.Position().Clone();
pos.Y = -pos.Y;
Assert.AreEqual(pos, yMirror.Position());
pos = cube.Position().Clone();
pos.Z = -pos.Z;
Assert.AreEqual(pos, zMirror.Position());
}
}
}

View File

@ -56,6 +56,7 @@
<Compile Include="CylinderTests.cs" />
<Compile Include="HullTests.cs" />
<Compile Include="InterpolationTests.cs" />
<Compile Include="MirrorTests.cs" />
<Compile Include="OSCADObjectTests.cs" />
<Compile Include="SphereTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -1,4 +1,5 @@
using OSCADSharp.Scripting;
using OSCADSharp.Spatial;
using System;
using System.Collections.Generic;
using System.Linq;
@ -50,9 +51,17 @@ namespace OSCADSharp.Transforms
return new MirroredObject(obj, this.Normal);
}
// TODO: This will yield incorrect positions if mirroring on multiple axes
// fix mirrored positions for multiple-axis mirroring
public override Vector3 Position()
{
throw new NotImplementedException();
var pos = obj.Position();
double x = this.Normal.X != 0 ? pos.X * -1 : pos.X;
double y = this.Normal.Y != 0 ? pos.Y * -1 : pos.Y;
double z = this.Normal.Z != 0 ? pos.Z * -1 : pos.Z;
return new Vector3(x, y, z);
}
}
}