Пример #1
0
        /// <summary>
        /// Plano con el vector normalizado.
        /// </summary>
        public static Line2d NewNormal(Point2d origin, Vector2d direction)
        {
            Vector2d vx = direction.Unit;

            Line2d line = new Line2d(origin, vx);

            if (vx.IsZero)
            {
                line.evaluated   |= Evaluated.IsDegenerate;
                line.isDegenerate = true;
            }
            else
            {
                line.evaluated |= Evaluated.IsNormal;
                line.isNormal   = true;
            }

            return(line);
        }
Пример #2
0
        public void TestIsDegenerate()
        {
            // Comprueba el método IsNormal sobre lineas no normales.
            {
                // Caso normal.
                Assert.IsTrue(!Line2d.NewNonNormal(new Point2d(1, 1), new Vector2d(1, 0)).IsDegenerate);
                Assert.IsTrue(!Line2d.NewNonNormal(new Point2d(1, 1), new Vector2d(0, -1)).IsDegenerate);
                Assert.IsTrue(!Line2d.NewNonNormal(new Point2d(1, 1), new Vector2d(1, 1)).IsDegenerate);

                // Planos degenerados.
                Assert.IsTrue(Line2d.NewNonNormal(new Point2d(1, 1), new Vector2d(0, 0)).IsDegenerate);
            }

            // Comprueba el método IsNormal sobre lineas normales.
            {
                // Caso normal.
                Assert.IsTrue(!Line2d.NewNormal(new Point2d(1, 1), new Vector2d(10, 0)).IsDegenerate);
                Assert.IsTrue(!Line2d.NewNormal(new Point2d(1, 1), new Vector2d(5, 89)).IsDegenerate);
                Assert.IsTrue(!Line2d.NewNormal(new Point2d(1, 1), new Vector2d(1, 1)).IsDegenerate);

                // Planos degenerados.
                Assert.IsTrue(Line2d.NewNormal(new Point2d(1, 1), new Vector2d(0, 0)).IsDegenerate);
            }
        }
Пример #3
0
        public void TestWhichSide()
        {
            // Comprueba el método WhichSide sobre lineas normalizadas.
            {
                Line2d line = Line2d.NewNormal(new Point2d(50, 0), new Point2d(0, 50));
                Assert.IsTrue(line.WhichSide(new Point2d(0, 0)) == LineSide.Left);
                Assert.IsTrue(line.WhichSide(new Point2d(100, 100)) == LineSide.Right);
                Assert.IsTrue(line.WhichSide(new Point2d(25, 25)) == LineSide.Middle);
            }

            // Comprueba el método WhichSide sobre lineas no normalizadas.
            {
                Line2d line = Line2d.NewNonNormal(new Point2d(50, 0), new Point2d(0, 50));
                Assert.IsTrue(line.WhichSide(new Point2d(0, 0)) == LineSide.Left);
                Assert.IsTrue(line.WhichSide(new Point2d(100, 100)) == LineSide.Right);
                Assert.IsTrue(line.WhichSide(new Point2d(25, 25)) == LineSide.Middle);
            }
            {
                Line2d line = Line2d.NewNormal(new Point2d(0, 5), new Vector2d(1, 1));
                Assert.IsTrue(line.WhichSide(new Point2d(0, 0)) == LineSide.Right);
                Assert.IsTrue(line.WhichSide(new Point2d(0, 5)) == LineSide.Middle);
                Assert.IsTrue(line.WhichSide(new Point2d(0, 10)) == LineSide.Left);
            }
        }