public async Task AabbCalculatedCorrectlyForAlignedFitObject()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            // Automation runner must do as much as program.cs to spin up platform
            string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms";

            AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider);
            AppContext.Platform.ProcessCommandline();

            var root = new Object3D();
            var cube = await CubeObject3D.Create(20, 20, 20);

            var fit = await FitToBoundsObject3D_2.Create(cube);

            fit.SizeX = 10;
            fit.SizeY = 10;
            fit.SizeZ = 6;

            Assert.IsTrue(fit.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-5, -5, -10), new Vector3(5, 5, -4)), .01));

            var bigCube = await CubeObject3D.Create(20, 20, 20);

            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .01));

            var align = new AlignObject3D();

            align.Children.Add(bigCube);
            align.Children.Add(fit);

            await align.Rebuild();

            align.XAlign   = Align.Center;
            align.YAlign   = Align.Center;
            align.ZAlign   = Align.Max;
            align.Advanced = true;
            align.ZOffset  = 1;

            await align.Rebuild();

            var alignAabb = align.GetAxisAlignedBoundingBox();

            Assert.IsTrue(alignAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 11)), .01));

            alignAabb = align.GetAxisAlignedBoundingBox();
            root.Children.Add(align);
            var rootAabb = root.GetAxisAlignedBoundingBox();

            Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 11)), .01));
        }
        public async Task AabbCalculatedCorrectlyForAlignedFitObject()
        {
            StartupMC();

            var root = new Object3D();
            var cube = await CubeObject3D.Create(20, 20, 20);

            var fit = await FitToBoundsObject3D_3.Create(cube);

            fit.Width  = 10;
            fit.Depth  = 10;
            fit.Height = 6;
            fit.Invalidate(InvalidateType.Properties);

            Assert.IsTrue(fit.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-5, -5, -10), new Vector3(5, 5, -4)), .01));

            var bigCube = await CubeObject3D.Create(20, 20, 20);

            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .01));

            var align = new AlignObject3D();

            align.Children.Add(bigCube);
            align.Children.Add(fit);

            await align.Rebuild();

            align.XAlign   = Align.Center;
            align.YAlign   = Align.Center;
            align.ZAlign   = Align.Max;
            align.Advanced = true;
            align.ZOffset  = 1;

            await align.Rebuild();

            var alignAabb = align.GetAxisAlignedBoundingBox();

            Assert.IsTrue(alignAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 11)), .01));

            alignAabb = align.GetAxisAlignedBoundingBox();
            root.Children.Add(align);
            var rootAabb = root.GetAxisAlignedBoundingBox();

            Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 11)), .01));
        }
        public async Task AlignObjectHasCorrectPositionsOnXAxis()
        {
            StartupMC();

            var scene = new InteractiveScene();

            var cube = await CubeObject3D.Create(20, 20, 20);

            cube.Matrix = Matrix4X4.CreateTranslation(50, 60, 10);
            Assert.IsTrue(cube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 50, 0), new Vector3(60, 70, 20)), .01));
            scene.Children.Add(cube);

            var bigCube = await CubeObject3D.Create(40, 40, 40);

            bigCube.Matrix = Matrix4X4.CreateTranslation(20, 20, 20);
            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(40, 40, 40)), .01));
            scene.Children.Add(bigCube);

            // select them
            scene.SelectedItem = cube;
            scene.AddToSelection(bigCube);

            // create an align of them
            var align = new AlignObject3D();

            align.AddSelectionAsChildren(scene, scene.SelectedItem);

            var unalignedBounds = align.GetAxisAlignedBoundingBox();

            // assert the align in built correctly
            Assert.AreEqual(1, scene.Children.Count);
            Assert.AreEqual(2, align.Children.Count);
            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(60, 70, 40)), 1.0));

            align.SelectedChild = new SelectedChildren()
            {
                cube.ID.ToString()
            };

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(unalignedBounds, 1.0));

            // turn align on
            align.XAlign = Align.Min;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 0, 0), new Vector3(80, 70, 40)), 1.0));

            // turn it off
            align.XAlign = Align.None;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(unalignedBounds, 1.0));

            // turn it back on
            align.XAlign = Align.Min;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 0, 0), new Vector3(80, 70, 40)), 1.0));

            // remove the align and assert stuff moved back to where it started
            align.Remove(null);
            Assert.IsTrue(cube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 50, 0), new Vector3(60, 70, 20)), .01));
            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(40, 40, 40)), .01));
        }
        public async Task AlignObjectHasCorrectPositionsOnXAxis()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            // Automation runner must do as much as program.cs to spin up platform
            string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms";

            AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider);
            AppContext.Platform.ProcessCommandline();

            var scene = new InteractiveScene();

            var cube = await CubeObject3D.Create(20, 20, 20);

            cube.Matrix = Matrix4X4.CreateTranslation(50, 60, 10);
            Assert.IsTrue(cube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 50, 0), new Vector3(60, 70, 20)), .01));
            scene.Children.Add(cube);

            var bigCube = await CubeObject3D.Create(40, 40, 40);

            bigCube.Matrix = Matrix4X4.CreateTranslation(20, 20, 20);
            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(40, 40, 40)), .01));
            scene.Children.Add(bigCube);

            // select them
            scene.SelectedItem = cube;
            scene.AddToSelection(bigCube);

            // create an align of them
            var align = new AlignObject3D();

            align.AddSelectionAsChildren(scene, scene.SelectedItem);

            var unalignedBounds = align.GetAxisAlignedBoundingBox();

            // assert the align in built correctly
            Assert.AreEqual(1, scene.Children.Count);
            Assert.AreEqual(2, align.Children.Count);
            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(60, 70, 40)), 1.0));

            align.SelectedChild = new SelectedChildren()
            {
                cube.ID.ToString()
            };

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(unalignedBounds, 1.0));

            // turn align on
            align.XAlign = Align.Min;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 0, 0), new Vector3(80, 70, 40)), 1.0));

            // turn it off
            align.XAlign = Align.None;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(unalignedBounds, 1.0));

            // turn it back on
            align.XAlign = Align.Min;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 0, 0), new Vector3(80, 70, 40)), 1.0));

            // remove the align and assert stuff moved back to where it started
            align.Remove(null);
            Assert.IsTrue(cube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 50, 0), new Vector3(60, 70, 20)), .01));
            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(40, 40, 40)), .01));
        }