Esempio n. 1
0
        public void TestEvaluatAndProject()
        {
            Action <Line2d, double> test = (line, u) =>
            {
                Point2d p  = line.Evaluate(u);
                double  _u = line.Project(p);
                Assert.IsTrue(u.EpsilonEquals(_u));
                Point2d p2 = line.Evaluate(_u);
                Assert.IsTrue(p.EpsilonEquals(p2));
            };

            // Comprueba los métodos Evaluate y Project sobre lineas normalizadas.
            {
                Line2d lin = Line2d.NewNormal(new Point2d(50, 0), new Point2d(0, 50));
                test(lin, -10);
                test(lin, -1);
                test(lin, -0.5);
                test(lin, 0);
                test(lin, 0.5);
                test(lin, 1);
                test(lin, 10);
            }

            // Comprueba los métodos Evaluate y Project sobre lineas no normalizadas.
            {
                Line2d lin = Line2d.NewNonNormal(new Point2d(50, 0), new Point2d(0, 50));
                test(lin, -10);
                test(lin, -1);
                test(lin, -0.5);
                test(lin, 0);
                test(lin, 0.5);
                test(lin, 1);
                test(lin, 10);
            }
        }
Esempio n. 2
0
        public void TestIsOrthonormal()
        {
            // Comprueba el método IsNormal sobre lineas no normales.
            {
                // Caso normal.
                Assert.IsTrue(Line2d.NewNonNormal(new Point2d(1, 1), new Vector2d(1, 0)).IsNormal);
                Assert.IsTrue(Line2d.NewNonNormal(new Point2d(1, 1), new Vector2d(0, -1)).IsNormal);

                Assert.IsTrue(!Line2d.NewNonNormal(new Point2d(1, 1), new Vector2d(1, 1)).IsNormal);

                // Lineas degeneradas.
                Assert.IsTrue(!Line2d.NewNonNormal(new Point2d(1, 1), new Vector2d(0, 0)).IsNormal);
            }

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

                // Lineas degeneradas.
                Assert.IsTrue(!Line2d.NewNormal(new Point2d(1, 1), new Vector2d(0, 0)).IsNormal);
            }
        }
Esempio n. 3
0
 public void TestWhichSideRectangle()
 {
     {
         Line2d line = Line2d.NewNormal(new Point2d(0, 5), new Vector2d(1, 1));
         Assert.IsTrue(line.WhichSide(BoundingBox2d.FromExtents(0, 0, 1, 1)) == LineSide.Right);
         Assert.IsTrue(line.WhichSide(BoundingBox2d.FromExtents(0, 4, 2, 2)) == LineSide.Middle);
         Assert.IsTrue(line.WhichSide(BoundingBox2d.FromExtents(0, 6, 1, 1)) == LineSide.Middle);
         Assert.IsTrue(line.WhichSide(BoundingBox2d.FromExtents(0, 7, 1, 1)) == LineSide.Left);
     }
 }
Esempio n. 4
0
        public void TestDistance()
        {
            Func <Line2d, Point2d, bool> test = (line, p) =>
            {
                double u = line.Project(p);

                Point2d pEnPlano = line.Evaluate(u);

                Point2d closestPoint;
                double  d = line.Distance(p, out closestPoint);

                Point2d p3 = pEnPlano + line.Normal * d;

                bool pEqualsP3 = p.EpsilonEquals(p3);
                bool pEnPlanoEqualsClosestPoint = pEnPlano.EpsilonEquals(closestPoint);

                return(pEqualsP3 && pEnPlanoEqualsClosestPoint && p.DistanceTo(pEnPlano).EpsilonEquals(Math.Abs(d)));
            };

            // Comprueba los metodos Project, Evaluate y DistanceTo sobre lineas normalizados.
            {
                Line2d line = Line2d.NewNormal(new Point2d(50, 0), new Point2d(0, 50));
                Assert.IsTrue(test(line, new Point2d(0, 0)));
                Assert.IsTrue(test(line, new Point2d(100, 100)));
                Assert.IsTrue(test(line, new Point2d(25, 25)));

                Assert.IsTrue(line.Distance(new Point2d(0, 0)).EpsilonEquals(-35.355, 1e-3));
                Assert.IsTrue(line.Distance(new Point2d(100, 100)).EpsilonEquals(106.066, 1e-3));
                Assert.IsTrue(line.Distance(new Point2d(25, 25)).EpsilonEquals(0));
            }

            // Comprueba los metodos Project, Evaluate y DistanceTo sobre lineas no normalizados.
            {
                Line2d line = Line2d.NewNonNormal(new Point2d(50, 0), new Point2d(0, 50));
                Assert.IsTrue(test(line, new Point2d(0, 0)));
                Assert.IsTrue(test(line, new Point2d(100, 100)));
                Assert.IsTrue(test(line, new Point2d(25, 25)));

                Assert.IsTrue(line.Distance(new Point2d(0, 0)).EpsilonEquals(-35.355, 1e-3));
                Assert.IsTrue(line.Distance(new Point2d(100, 100)).EpsilonEquals(106.066, 1e-3));
                Assert.IsTrue(line.Distance(new Point2d(25, 25)).EpsilonEquals(0));
            }

            {
                Line2d line = Line2d.NewNormal(new Point2d(0, 5), new Vector2d(1, 1));
                Assert.IsTrue(line.Distance(new Point2d(0, 0)).EpsilonEquals(3.535, 1e-3));
                Assert.IsTrue(line.Distance(new Point2d(0, 5)).EpsilonEquals(0));
                Assert.IsTrue(line.Distance(new Point2d(0, 10)).EpsilonEquals(-3.535, 1e-3));
            }
        }
Esempio n. 5
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);
            }
        }