public void ScaleAndRotateMantainsCorrectAabb()
        {
            {
                // create a simple cube with translation
                var root = new Object3D();
                var cube = CubeObject3D.Create(20, 20, 20);
                cube.Matrix = Matrix4X4.CreateTranslation(50, 60, 10);
                root.Children.Add(cube);
                Assert.AreEqual(2, root.DescendantsAndSelf().Count());
                var preScaleAabb = root.GetAxisAlignedBoundingBox();

                // add a scale to it (that is not scaled)
                var scaleObject = new ScaleObject3D(cube);

                // ensure that the object did not move
                Assert.IsTrue(scaleObject.ScaleAbout.Equals(Vector3.Zero), "The objects have been moved to be scalling about 0.");
                Assert.AreEqual(4, root.DescendantsAndSelf().Count());
                var postScaleAabb = root.GetAxisAlignedBoundingBox();

                Assert.IsTrue(preScaleAabb.Equals(postScaleAabb, .001));

                Assert.AreEqual(cube, scaleObject.UntransformedChildren.First(), "There is no undo buffer, there should not have been a clone");

                var rotateScaleObject = new RotateObject3D_2(cube);
                // ensure that the object did not move
                Assert.AreEqual(6, root.DescendantsAndSelf().Count());
                var postRotateScaleAabb = root.GetAxisAlignedBoundingBox();

                Assert.IsTrue(preScaleAabb.Equals(postRotateScaleAabb, .001));

                Assert.AreEqual(cube, rotateScaleObject.UntransformedChildren.First(), "There is no undo buffer, there should not have been a clone");
            }
        }
        public async Task RotateMaintainsCorrectAabb()
        {
            {
                // create a simple cube with translation
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                cube.Matrix = Matrix4X4.CreateTranslation(50, 60, 10);
                root.Children.Add(cube);
                Assert.AreEqual(2, root.DescendantsAndSelf().Count());
                var preRotateAabb = root.GetAxisAlignedBoundingBox();

                // add a rotate to it (that is not rotated)
                var rotateObject = new RotateObject3D_2(cube);

                // ensure that the object did not move
                Assert.IsTrue(rotateObject.RotateAbout.Origin.Equals(new Vector3(50, 60, 10)));
                Assert.AreEqual(4, root.DescendantsAndSelf().Count());
                var postRotateAabb = root.GetAxisAlignedBoundingBox();

                Assert.IsTrue(preRotateAabb.Equals(postRotateAabb, .001));

                Assert.AreEqual(cube, rotateObject.UntransformedChildren.First(), "There is no undo buffer, there should not have been a clone");
            }
        }
예제 #3
0
        public async Task ScaleObjectMaintainsCorrectAabb()
        {
            // build cube with scale and undo
            {
                // create a simple cube with translation
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                cube.Matrix = Matrix4X4.CreateTranslation(50, 60, 10);
                root.Children.Add(cube);
                Assert.AreEqual(2, root.DescendantsAndSelf().Count());
                var preScaleAabb = root.GetAxisAlignedBoundingBox();

                var undoBuffer = new UndoBuffer();

                // add a scale to it (that is not scaled)
                var scaleObject = new ScaleObject3D();
                scaleObject.WrapItems(new IObject3D[] { cube }, undoBuffer);

                // ensure that the object did not move
                Assert.IsTrue(scaleObject.ScaleAbout.Equals(Vector3.Zero), "The objects have been moved to be scalling about 0.");
                Assert.AreEqual(4, root.DescendantsAndSelf().Count());
                var postScaleAabb = root.GetAxisAlignedBoundingBox();

                Assert.IsTrue(preScaleAabb.Equals(postScaleAabb, .001));

                Assert.AreNotEqual(cube, scaleObject.UntransformedChildren.First(), "There is an undo buffer, there should have been a clone");
            }

            // build cube with scale
            {
                // create a simple cube with translation
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                cube.Matrix = Matrix4X4.CreateTranslation(50, 60, 10);
                root.Children.Add(cube);
                Assert.AreEqual(2, root.DescendantsAndSelf().Count());
                var preScaleAabb = root.GetAxisAlignedBoundingBox();

                // add a scale to it (that is not scaled)
                var scaleObject = new ScaleObject3D(cube);

                // ensure that the object did not move
                Assert.IsTrue(scaleObject.ScaleAbout.Equals(Vector3.Zero), "The objects have been moved to be scalling about 0.");
                Assert.AreEqual(4, root.DescendantsAndSelf().Count());
                var postScaleAabb = root.GetAxisAlignedBoundingBox();

                Assert.IsTrue(preScaleAabb.Equals(postScaleAabb, .001));

                Assert.AreEqual(cube, scaleObject.UntransformedChildren.First(), "There is no undo buffer, there should not have been a clone");
            }
        }
        public async Task AabbCalculatedCorrectlyForCurvedFitObjects()
        {
            StartupMC();

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

            var fit = await FitToBoundsObject3D_3.Create(cube);

            fit.Width  = 50;
            fit.Depth  = 20;
            fit.Height = 20;
            fit.Invalidate(InvalidateType.Properties);

            Assert.IsTrue(fit.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-25, -10, -10), new Vector3(25, 10, 10)), 1.0));

            var curve = new CurveObject3D_3()
            {
                BendType = CurveObject3D_3.BendTypes.Diameter,
                Diameter = 50
            };

            curve.Children.Add(fit);
            await curve.Rebuild();

            var curveAabb = curve.GetAxisAlignedBoundingBox();

            root.Children.Add(curve);
            var rootAabb = root.GetAxisAlignedBoundingBox();

            Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-17.5, -9.9, -10), new Vector3(17.5, 11.97, 10)), 1.0));
        }
예제 #5
0
        public async Task AabbCalculatedCorrectlyForCurvedFitObjects()
        {
            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 = 50;
            fit.SizeY = 20;
            fit.SizeZ = 20;

            Assert.IsTrue(fit.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-25, -10, -10), new Vector3(25, 10, 10)), 1.0));

            var curve = new CurveObject3D_2();

            curve.Children.Add(fit);
            await curve.Rebuild();

            var curveAabb = curve.GetAxisAlignedBoundingBox();

            root.Children.Add(curve);
            var rootAabb = root.GetAxisAlignedBoundingBox();

            Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-17.5, -9.9, -10), new Vector3(17.5, 11.97, 10)), 1.0));
        }
예제 #6
0
        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 SubtractTests()
        {
            // Subtract has correct number of results
            {
                var root  = new Object3D();
                var cubeA = await CubeObject3D.Create(20, 20, 20);

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

                var offsetCubeB = new TranslateObject3D(cubeB, 10);

                var subtract = new SubtractObject3D();
                subtract.Children.Add(cubeA);
                subtract.Children.Add(offsetCubeB);
                subtract.SelectedChildren.Add(offsetCubeB.ID);
                root.Children.Add(subtract);

                subtract.Subtract();
                subtract.Flatten(null);

                Assert.AreEqual(1, root.Children.Count());
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  0, 10, 10).Equals(rootAabb, .001));
            }

            // make sure the MatterCAD subtract function is working
            {
                var cubeA = await CubeObject3D.Create(20, 20, 20);

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

                var offsetCubeB = new TranslateObject3D(cubeB, 10);

                var subtract = cubeA.Minus(offsetCubeB);

                Assert.AreEqual(0, subtract.Children.Count());
                Assert.IsTrue(subtract.Mesh != null);
                var aabb = subtract.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  0, 10, 10).Equals(aabb, .001));
            }
        }
예제 #9
0
        public void AabbCalculatedCorrectlyForCurvedFitObjects()
        {
            var root = new Object3D();
            var cube = new CubeObject3D(20, 20, 20);
            var fit  = FitToBoundsObject3D_2.Create(cube);

            fit.SizeX = 50;
            fit.SizeY = 20;
            fit.SizeZ = 20;

            var curve = new CurveObject3D();

            curve.Children.Add(fit);
            curve.Invalidate(new InvalidateArgs(curve, InvalidateType.Properties));
            root.Children.Add(curve);
            var rootAabb = root.GetAxisAlignedBoundingBox();

            Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-25, 4, -10), new Vector3(25, 15, 10)), 1.0));
        }
예제 #10
0
        public override Task Rebuild()
        {
            IObject3D cancerRibbonStl = Object3D.Load("Cancer_Ribbon.stl", CancellationToken.None);

            cancerRibbonStl = new RotateObject3D(cancerRibbonStl, MathHelper.DegreesToRadians(90));

            var letterPrinter = new TypeFacePrinter(NameToWrite.ToUpper(), new StyledTypeFace(ApplicationController.GetTypeFace(Font), 12));

            IObject3D nameMesh = new Object3D()
            {
                Mesh = VertexSourceToMesh.Extrude(letterPrinter, 5)
            };

            AxisAlignedBoundingBox textBounds = nameMesh.GetAxisAlignedBoundingBox();
            var textArea = new Vector2(25, 6);

            double scale = Math.Min(textArea.X / textBounds.XSize, textArea.Y / textBounds.YSize);

            nameMesh = new ScaleObject3D_3(nameMesh, scale, scale, 2 / textBounds.ZSize);
            nameMesh = new AlignObject3D(nameMesh, FaceAlign.Bottom | FaceAlign.Front, cancerRibbonStl, FaceAlign.Top | FaceAlign.Front, 0, 0, -1);
            nameMesh = new SetCenterObject3D(nameMesh, cancerRibbonStl.GetCenter(), true, false, false);

            nameMesh = new RotateObject3D(nameMesh, 0, 0, MathHelper.DegreesToRadians(50));
            nameMesh = new TranslateObject3D(nameMesh, -37, -14, -1);

            // output two meshes for card holder and text
            this.Children.Modify(list =>
            {
                list.Clear();
                list.Add(cancerRibbonStl);
                list.Add(nameMesh);
            });

            this.Mesh = null;
            this.Invalidate(InvalidateType.Children);
            return(Task.CompletedTask);
        }
        public async void DoAabbCalculatedCorrectlyForCurvedFitObjects()
        {
            var root = new Object3D();
            var cube = CubeObject3D.Create(20, 20, 20);
            var fit  = FitToBoundsObject3D_2.Create(cube).Result;

            fit.SizeX = 50;
            fit.SizeY = 20;
            fit.SizeZ = 20;

            Assert.IsTrue(fit.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-25, -10, -10), new Vector3(25, 10, 10)), 1.0));

            var curve = new CurveObject3D_2();

            curve.Children.Add(fit);
            await curve.Rebuild();

            var curveAabb = curve.GetAxisAlignedBoundingBox();

            root.Children.Add(curve);
            var rootAabb = root.GetAxisAlignedBoundingBox();

            Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-17.5, -9.2, -10), new Vector3(17.5, 9.2, 10)), 1.0));
        }
        public async Task CombineTests()
        {
            StartupMC();

            // Combine has correct results
            {
                var root  = new Object3D();
                var cubeA = await CubeObject3D.Create(20, 20, 20);

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

                var offsetCubeB = new TranslateObject3D(cubeB, 10);
                Assert.IsTrue(offsetCubeB.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(
                                                                                 0, -10, -10,
                                                                                 20, 10, 10), .001));

                var union = new CombineObject3D_2();
                union.Children.Add(cubeA);
                union.Children.Add(offsetCubeB);
                root.Children.Add(union);

                Assert.IsTrue(union.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(
                                                                           -10, -10, -10,
                                                                           20, 10, 10), .001));

                Assert.IsTrue(root.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(
                                                                          -10, -10, -10,
                                                                          20, 10, 10), .001));

                union.Combine();
                Assert.IsTrue(union.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(
                                                                           -10, -10, -10,
                                                                           20, 10, 10), .001));

                union.Flatten(null);

                Assert.AreEqual(1, root.Children.Count());
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  20, 10, 10).Equals(rootAabb, .001));
            }

            // Combine has correct results when inner content is changed
            {
                var root  = new Object3D();
                var cubeA = await CubeObject3D.Create(20, 20, 20);

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

                var union = new CombineObject3D_2();
                union.Children.Add(cubeA);
                union.Children.Add(cubeB);
                root.Children.Add(union);

                union.Combine();

                Assert.AreEqual(5, root.Descendants().Count());
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  10, 10, 10).Equals(rootAabb, .001));

                var offsetCubeB = new TranslateObject3D(cubeB, 10);

                union.Combine();
                Assert.AreEqual(7, root.Descendants().Count());
                rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  20, 10, 10).Equals(rootAabb, .001));
            }

            // now make sure undo has the right results for flatten
            {
                var root  = new Object3D();
                var cubeA = await CubeObject3D.Create(20, 20, 20);

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

                var offsetCubeB = new TranslateObject3D(cubeB, 10);

                var combine = new CombineObject3D_2();
                combine.Children.Add(cubeA);
                combine.Children.Add(offsetCubeB);
                root.Children.Add(combine);
                Assert.AreEqual(5, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 cubeB, 4 offset cubeB, 5 offset sourceItem");

                combine.Combine();
                Assert.AreEqual(7, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 wrapped cubeA, 4 cubeB, 5 offset cubeB, 6 offset sourceItem, wrapped cubeB");
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  20, 10, 10).Equals(rootAabb, .001));

                var undoBuffer = new UndoBuffer();
                combine.Flatten(undoBuffer);

                Assert.AreEqual(1, root.Descendants().Count());
                Assert.AreEqual(1, root.Children.Count());
                rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  20, 10, 10).Equals(rootAabb, .001));

                undoBuffer.Undo();
                Assert.AreEqual(7, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 wrapped cubeA, 4 cubeB, 5 offset cubeB, 6 offset sourceItem, wrapped cubeB");
            }

            // now make sure undo has the right results for remove
            {
                var root  = new Object3D();
                var cubeA = await CubeObject3D.Create(20, 20, 20);

                cubeA.Name = "cubeA";
                var cubeB = await CubeObject3D.Create(20, 20, 20);

                cubeB.Name = "cubeB";

                var combine = new CombineObject3D_2();
                combine.Children.Add(cubeA);
                combine.Children.Add(cubeB);
                root.Children.Add(combine);
                Assert.AreEqual(3, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 cubeB");

                combine.Combine();
                Assert.AreEqual(5, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 wrapped cubeA, 4 cubeB, 5 wrapped cubeB");
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  10, 10, 10).Equals(rootAabb, .001));

                var undoBuffer = new UndoBuffer();
                combine.Remove(undoBuffer);

                Assert.AreEqual(2, root.Descendants().Count(), "Should have the 1 cubeA, 2 cubeB");
                rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  10, 10, 10).Equals(rootAabb, .001));

                undoBuffer.Undo();
                Assert.AreEqual(5, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 wrapped cubeA, 4 cubeB, 5 wrapped cubeB");
            }

            // now make sure undo has the right results for remove
            {
                var root  = new Object3D();
                var cubeA = await CubeObject3D.Create(20, 20, 20);

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

                var offsetCubeB = new TranslateObject3D(cubeB, 10);

                var combine = new CombineObject3D_2();
                combine.Children.Add(cubeA);
                combine.Children.Add(offsetCubeB);
                root.Children.Add(combine);
                Assert.AreEqual(5, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 cubeB, 4 offset cubeB, 5 offset sourceItem");

                combine.Combine();
                Assert.AreEqual(7, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 wrapped cubeA, 4 cubeB, 5 offset cubeB, 6 offset sourceItem, wrapped cubeB");
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  20, 10, 10).Equals(rootAabb, .001));

                var undoBuffer = new UndoBuffer();
                combine.Remove(undoBuffer);

                Assert.AreEqual(4, root.Descendants().Count(), "Should have the 1 cubeA, 2 cubeB, 3 offset cubeB, 4 offset sourceItem");
                rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  20, 10, 10).Equals(rootAabb, .001));

                undoBuffer.Undo();
                Assert.AreEqual(7, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 wrapped cubeA, 4 cubeB, 5 offset cubeB, 6 offset sourceItem, wrapped cubeB");
            }

            // make sure the MatterCAD add function is working
            {
                var cubeA = await CubeObject3D.Create(20, 20, 20);

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

                var offsetCubeB = new TranslateObject3D(cubeB, 10);

                var plus = cubeA.Plus(offsetCubeB, true);

                Assert.AreEqual(0, plus.Children.Count());
                Assert.IsTrue(plus.Mesh != null);
                var aabb = plus.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  20, 10, 10).Equals(aabb, .001));
            }

            // test single object combine
            {
                var root  = new Object3D();
                var cubeA = await CubeObject3D.Create(20, 20, 20);

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

                var offsetCubeB = new TranslateObject3D(cubeB, 10);

                var group = new Object3D();
                group.Children.Add(cubeA);
                group.Children.Add(offsetCubeB);

                var union = new CombineObject3D_2();
                union.Children.Add(group);

                root.Children.Add(union);

                union.Combine();
                Assert.AreEqual(8, root.Descendants().Count(), "group, union, wa, a, wtb, tb, b");

                union.Flatten(null);
                Assert.AreEqual(1, root.Descendants().Count(), "Should have the union result");

                Assert.AreEqual(1, root.Children.Count());
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(new AxisAlignedBoundingBox(
                                  -10, -10, -10,
                                  20, 10, 10).Equals(rootAabb, .001));
            }
        }
        public async Task AabbCalculatedCorrectlyForPinchedFitObjects()
        {
            StartupMC();

            // build without pinch
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                root.Children.Add(cube);
                Assert.IsTrue(root.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001));
                root.Children.Remove(cube);
                var fit = await FitToBoundsObject3D_3.Create(cube);

                fit.Width  = 50;
                fit.Depth  = 20;
                fit.Height = 20;
                fit.Invalidate(InvalidateType.Properties);
                root.Children.Add(fit);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-25, -10, -10), new Vector3(25, 10, 10)), .001));
            }

            // build with pinch
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                var fit = await FitToBoundsObject3D_3.Create(cube);

                fit.Width  = 50;
                fit.Depth  = 20;
                fit.Height = 20;

                var pinch = new PinchObject3D_3();
                pinch.Children.Add(fit);
                await pinch.Rebuild();

                root.Children.Add(pinch);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001));
            }

            // build with translate
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                var translate = new TranslateObject3D(cube, 11, 0, 0);

                root.Children.Add(translate);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001));
            }

            // build with pinch and translate
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                var translate = new TranslateObject3D(cube, 11, 0, 0);

                var pinch = new PinchObject3D_3();
                pinch.Children.Add(translate);
                root.Children.Add(pinch);
                await pinch.Rebuild();

                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001));
            }

            // build with pinch and translate
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                var fit = await FitToBoundsObject3D_3.Create(cube);

                fit.Width  = 50;
                fit.Depth  = 20;
                fit.Height = 20;

                var translate = new TranslateObject3D(fit, 11, 0, 0);

                var pinch = new PinchObject3D_3();
                pinch.Children.Add(translate);
                await pinch.Rebuild();

                root.Children.Add(pinch);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001));
            }
        }
예제 #14
0
        public async Task AabbCalculatedCorrectlyForPinchedFitObjects()
        {
            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.InitPluginFinder();
            AppContext.Platform.ProcessCommandline();

            // build without pinch
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                root.Children.Add(cube);
                Assert.IsTrue(root.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001));
                root.Children.Remove(cube);
                var fit = await FitToBoundsObject3D_2.Create(cube);

                fit.SizeX = 50;
                fit.SizeY = 20;
                fit.SizeZ = 20;
                root.Children.Add(fit);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-25, -10, -10), new Vector3(25, 10, 10)), .001));
            }

            // build with pinch
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                var fit = await FitToBoundsObject3D_2.Create(cube);

                fit.SizeX = 50;
                fit.SizeY = 20;
                fit.SizeZ = 20;

                var pinch = new PinchObject3D_2();
                pinch.Children.Add(fit);
                await pinch.Rebuild();

                root.Children.Add(pinch);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001));
            }

            // build with translate
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                var translate = new TranslateObject3D(cube, 11, 0, 0);

                root.Children.Add(translate);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001));
            }

            // build with pinch and translate
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                var translate = new TranslateObject3D(cube, 11, 0, 0);

                var pinch = new PinchObject3D_2();
                pinch.Children.Add(translate);
                root.Children.Add(pinch);
                await pinch.Rebuild();

                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001));
            }

            // build with pinch and translate
            {
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                var fit = await FitToBoundsObject3D_2.Create(cube);

                fit.SizeX = 50;
                fit.SizeY = 20;
                fit.SizeZ = 20;

                var translate = new TranslateObject3D(fit, 11, 0, 0);

                var pinch = new PinchObject3D_2();
                pinch.Children.Add(translate);
                await pinch.Rebuild();

                root.Children.Add(pinch);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001));
            }
        }
예제 #15
0
        public async Task AutoArrangeChildrenTests()
        {
            // arrange a single item around the origin
            {
                var      scene = new InteractiveScene();
                Object3D cube1;
                scene.Children.Add(cube1 = new Object3D()
                {
                    Mesh   = PlatonicSolids.CreateCube(20, 20, 20),
                    Matrix = Matrix4X4.CreateTranslation(34, 22, 10)
                });

                Assert.IsTrue(new AxisAlignedBoundingBox(24, 12, 0, 44, 32, 20).Equals(cube1.GetAxisAlignedBoundingBox(), .001));

                await scene.AutoArrangeChildren(Vector3.Zero);

                Assert.IsTrue(new AxisAlignedBoundingBox(-10, -10, 0, 10, 10, 20).Equals(cube1.GetAxisAlignedBoundingBox(), .001));
            }

            // arrange a single item around a typical bed center
            {
                var      scene = new InteractiveScene();
                Object3D cube1;
                scene.Children.Add(cube1 = new Object3D()
                {
                    Mesh   = PlatonicSolids.CreateCube(20, 20, 20),
                    Matrix = Matrix4X4.CreateTranslation(34, 22, 10)
                });

                Assert.IsTrue(new AxisAlignedBoundingBox(24, 12, 0, 44, 32, 20).Equals(cube1.GetAxisAlignedBoundingBox(), .001));

                await scene.AutoArrangeChildren(new Vector3(100, 100, 0));

                Assert.IsTrue(new AxisAlignedBoundingBox(90, 90, 0, 110, 110, 20).Equals(cube1.GetAxisAlignedBoundingBox(), .001));
            }

            // arrange 4 items
            {
                var scene = new InteractiveScene();
                for (int i = 0; i < 4; i++)
                {
                    scene.Children.Add(new Object3D()
                    {
                        Mesh   = PlatonicSolids.CreateCube(20, 20, 20),
                        Matrix = Matrix4X4.CreateTranslation(i * 134, i * -122, 10)
                    });
                }

                var sceneAabb = scene.GetAxisAlignedBoundingBox();
                Assert.Greater(sceneAabb.XSize, 160);
                Assert.Greater(sceneAabb.YSize, 160);

                await scene.AutoArrangeChildren(Vector3.Zero);

                sceneAabb = scene.GetAxisAlignedBoundingBox();
                Assert.Less(sceneAabb.XSize, 60);
                Assert.Less(sceneAabb.YSize, 75);
            }

            // arrange 4 items, starting with 1 selected
            {
                var      scene = new InteractiveScene();
                Object3D child = null;
                for (int i = 0; i < 4; i++)
                {
                    scene.Children.Add(child = new Object3D()
                    {
                        Mesh   = PlatonicSolids.CreateCube(20, 20, 20),
                        Matrix = Matrix4X4.CreateTranslation(i * 134, i * -122, 10)
                    });
                }

                scene.SelectedItem = child;

                var sceneAabb = scene.GetAxisAlignedBoundingBox();
                Assert.Greater(sceneAabb.XSize, 160);
                Assert.Greater(sceneAabb.YSize, 160);

                await scene.AutoArrangeChildren(Vector3.Zero);

                sceneAabb = scene.GetAxisAlignedBoundingBox();
                Assert.Less(sceneAabb.XSize, 60);
                Assert.Less(sceneAabb.YSize, 75);
            }
        }
예제 #16
0
        public void AabbCalculatedCorrectlyForPinchedFitObjects()
        {
            // build without pinch
            {
                var root = new Object3D();
                var cube = new CubeObject3D(20, 20, 20);
                root.Children.Add(cube);
                Assert.IsTrue(root.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001));
                root.Children.Remove(cube);
                var fit = FitToBoundsObject3D_2.Create(cube);

                fit.SizeX = 50;
                fit.SizeY = 20;
                fit.SizeZ = 20;
                root.Children.Add(fit);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-25, -10, -10), new Vector3(25, 10, 10)), .001));
            }

            // build with pinch
            {
                var root = new Object3D();
                var cube = new CubeObject3D(20, 20, 20);
                root.Children.Add(cube);
                var fit = FitToBoundsObject3D_2.Create(cube);

                fit.SizeX = 50;
                fit.SizeY = 20;
                fit.SizeZ = 20;

                var pinch = new PinchObject3D();
                pinch.Children.Add(fit);
                root.Children.Add(pinch);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001));
            }

            // build with translate
            {
                var root = new Object3D();
                var cube = new CubeObject3D(20, 20, 20);

                var translate = new TranslateObject3D(cube, 11, 0, 0);

                root.Children.Add(translate);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001));
            }

            // build with pinch and translate
            {
                var root = new Object3D();
                var cube = new CubeObject3D(20, 20, 20);

                var translate = new TranslateObject3D(cube, 11, 0, 0);

                var pinch = new PinchObject3D();
                pinch.Children.Add(translate);
                root.Children.Add(pinch);
                pinch.Invalidate(new InvalidateArgs(pinch, InvalidateType.Properties));
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001));
            }

            // build with pinch and translate
            {
                var root = new Object3D();
                var cube = new CubeObject3D(20, 20, 20);
                var fit  = FitToBoundsObject3D_2.Create(cube);

                fit.SizeX = 50;
                fit.SizeY = 20;
                fit.SizeZ = 20;

                var translate = new TranslateObject3D(fit, 11, 0, 0);

                var pinch = new PinchObject3D();
                pinch.Children.Add(translate);
                pinch.Invalidate(new InvalidateArgs(pinch, InvalidateType.Properties));
                root.Children.Add(pinch);
                var rootAabb = root.GetAxisAlignedBoundingBox();
                Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001));
            }
        }