コード例 #1
0
ファイル: CubeTests.cs プロジェクト: wwkkww1983/OSCADSharp
        public void Cube_BoundsAreInExpectedPositionNotCentered()
        {
            var obj = new Cube(5, 5, 20, false);

            Assert.AreEqual(new Vector3(5, 5, 20), obj.Bounds().TopRight);
            Assert.AreEqual(new Vector3(), obj.Bounds().BottomLeft);
        }
コード例 #2
0
ファイル: CubeTests.cs プロジェクト: wwkkww1983/OSCADSharp
        public void Cube_BoundsAreInExpectedPositionCentered()
        {
            var obj = new Cube(5, 5, 20, true);

            Assert.AreEqual(new Vector3(2.5, 2.5, 10), obj.Bounds().TopRight);
            Assert.AreEqual(new Vector3(-2.5, -2.5, -10), obj.Bounds().BottomLeft);
        }
コード例 #3
0
ファイル: MirrorTests.cs プロジェクト: wwkkww1983/OSCADSharp
        public void Mirror_SingleAxisMirrorInvertsBounds()
        {
            OSCADObject cube         = new Cube(5, 10, 20);
            var         boundsBefore = cube.Bounds();

            cube = cube.Mirror(0, 1, 0);

            Assert.AreEqual(cube.Bounds().YMax, boundsBefore.YMin);
        }
コード例 #4
0
        public void Resize_ResizeScalesBoundariesToFit()
        {
            var obj = new Cube(20, 20, 10).Resize(5, 5, 5);

            var bounds = obj.Bounds();

            Assert.AreEqual(new Vector3(5, 5, 5), bounds.TopRight);
            Assert.AreEqual(new Vector3(0, 0, 0), bounds.BottomLeft);
        }
コード例 #5
0
        public void Translate_BoundsMoveWhenObjectIsTranslated()
        {
            var cube         = new Cube();
            var boundsBefore = cube.Bounds();
            var boundsAfter  = cube.Translate(5, 2, 3).Bounds();

            Assert.AreEqual(boundsAfter.TopRight, boundsBefore.TopRight + new Vector3(5, 2, 3));
            Assert.AreEqual(boundsAfter.BottomLeft, boundsBefore.BottomLeft + new Vector3(5, 2, 3));
        }
コード例 #6
0
        private void markVisited(ref bool[,] visited, Cube cube, Point start)
        {
            var bounds = cube.Bounds();

            for (int x = start.X; x < start.X + bounds.Length && x < this.width; x++)
            {
                for (int y = start.Y; y < start.Y + bounds.Width && y < this.height; y++)
                {
                    visited[x, y] = true;
                }
            }
        }
コード例 #7
0
        public void Scale_BoundsScaleWithObject()
        {
            var obj = new Cube(5, 5, 5).Scale(2, 2, 3);

            var bounds = obj.Bounds();

            Assert.AreEqual(bounds.XMax, 10);
            Assert.AreEqual(bounds.YMax, 10);
            Assert.AreEqual(bounds.ZMax, 15);

            Assert.AreEqual(bounds.XMin, 0);
            Assert.AreEqual(bounds.YMin, 0);
            Assert.AreEqual(bounds.ZMin, 0);
        }
コード例 #8
0
        public void Union_BoundsForUnionedObjectsBecomeExtremitiesOfBoth()
        {
            var obj = new Cube(5, 10, 20) + new Sphere(10).Translate(-10, 5, 0);

            var bounds = obj.Bounds();

            Assert.AreEqual(20, bounds.ZMax);
            Assert.AreEqual(10, bounds.YMax);
            Assert.AreEqual(5, bounds.XMax);

            Assert.AreEqual(-5, bounds.ZMin);
            Assert.AreEqual(0, bounds.YMin);
            Assert.AreEqual(-15, bounds.XMin);
        }
コード例 #9
0
        private static OSCADObject makeStandCap()
        {
            OSCADObject center = new Cube(Inches.One - Inches.Sixteenth, Inches.Half - Inches.Sixteenth, Inches.Quarter, true);

            OSCADObject outerColumn = new Cylinder(Inches.One, Inches.One, true).Resize(Inches.One * 1.5, Inches.Half * 1.5, Inches.One);
            var         bnds        = center.Bounds();

            OSCADObject top = new Cylinder(Inches.One, Inches.One, true)
                              .Resize(Inches.One * 2.25, Inches.Half * 2.25, Inches.Quarter);
            OSCADObject cutout = new Cylinder(Inches.One, Inches.One, true)
                                 .Resize(Inches.One * 2.1, Inches.Half * 2.1, Inches.Quarter);

            top = top - cutout.Translate(0, 0, Inches.Quarter / 2);


            OSCADObject brim = top.Clone();

            var obj = center + top.Translate(0, 0, bnds.Height / 2 + Inches.Sixteenth / 2);

            return(obj);
        }
コード例 #10
0
        private TraversalDirection traversePixels(ref Point start, bool[,] visited, Color color, Cube cube)
        {
            var direction = TraversalDirection.Bidirectional;
            var bounds    = cube.Bounds();

            //Bidirectional
            visited[start.X, start.Y] = true;
            Point next = new Point(start.X + 1, start.Y + 1);

            if (next.X >= this.width || next.Y >= this.height)
            {
                direction = TraversalDirection.None;
            }
            else
            {
                if (pixelCanBeTraversed(ref visited, next, color))
                {
                    visited[next.X, next.Y] = true;
                    cube.Size.X            += 1;
                    cube.Size.Y            += 1;
                }
                else
                {
                    direction = TraversalDirection.None;
                }
            }

            if (direction != TraversalDirection.None)
            {
                return(direction);
            }

            //X-axis
            direction = TraversalDirection.X_Only;
            next.Y    = start.Y;

            if (next.X >= this.width || next.Y >= this.height)
            {
                direction = TraversalDirection.None;
            }
            else
            {
                if (pixelCanBeTraversed(ref visited, next, color))
                {
                    visited[next.X, next.Y] = true;
                    cube.Size.X            += 1;
                }
                else
                {
                    direction = TraversalDirection.None;
                }
            }

            if (direction != TraversalDirection.None)
            {
                return(direction);
            }

            //Y-Axis
            direction = TraversalDirection.Y_Only;
            next.X    = start.X;
            next.Y    = start.Y + 1;

            if (next.X >= this.width || next.Y >= this.height)
            {
                direction = TraversalDirection.None;
            }
            else
            {
                if (pixelCanBeTraversed(ref visited, next, color))
                {
                    visited[next.X, next.Y] = true;
                    cube.Size.Y            += 1;
                }
                else
                {
                    direction = TraversalDirection.None;
                }
            }

            return(direction);
        }