Example #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);
            }
        }
Example #2
0
        private static void TestTransform(Point2d a, Point2d b, Point2d c, Point2d d)
        {
            Transform2 t = Transform2.Transform(a, b, c, d);

            Assert.IsTrue(c.EpsilonEquals(t.Transform(a), 0.001) &&
                          d.EpsilonEquals(t.Transform(b), 0.001) &&
                          c.Lerp(d, 0.5).EpsilonEquals(t.Transform(a.Lerp(b, 0.5)), 0.001));
        }
Example #3
0
        /**
         * This method removes the duplicate points of this polygon.
         * <example><pre>
         * Polygon2D poly = new Polygon2D(new[]
         * {
         *     new Point2d(0, 0), new Point2d(0, 0), new Point2d(0, 0),
         *     new Point2d(10, 0), new Point2d(10, 0), new Point2d(10, 0),
         *     new Point2d(10, 10), new Point2d(10, 10), new Point2d(10, 10),
         *     new Point2d(0, 10), new Point2d(0, 10), new Point2d(0, 10),
         *     new Point2d(0, 0), new Point2d(0, 0), new Point2d(0, 0),
         * });
         * poly.RemoveDuplicatePoints();
         * Polygon2D poly = new Polygon2D(new[] { new Point2d(0, 0), new Point2d(10, 0), new Point2d(10, 10), new Point2d(0, 10), });
         * </pre></example>
         */
        public static void RemoveDuplicatePoints(IList <Point2d> points, double epsilon = MathUtils.EPSILON)
        {
            for (int i = points.Count - 1; i >= 0; i--)
            {
                Point2d p     = points[i];
                Point2d pNext = points[(i + 1) % points.Count];

                if (p.EpsilonEquals(pNext, epsilon))
                {
                    points.RemoveAt(i);
                }
            }
        }
Example #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));
            }
        }
Example #5
0
        public void TestEvaluatAndProject()
        {
            Action <Triangle2d, double, double> test01 = (tri, u, v) =>
            {
                Point2d  p  = tri.Evaluate01(u, v);
                double[] uv = tri.Project01(p);
                Assert.IsTrue(u.EpsilonEquals(uv[0]) && v.EpsilonEquals(uv[1]));
                Point2d p2 = tri.Evaluate01(uv[0], uv[1]);
                Assert.IsTrue(p.EpsilonEquals(p2));
            };

            Action <Triangle2d, double, double> testBar = (tri, u, v) =>
            {
                Point2d  p   = tri.EvaluateBar(u, v);
                double[] uvw = tri.ProjectBar(p);
                Assert.IsTrue(u.EpsilonEquals(uvw[0]) && v.EpsilonEquals(uvw[1]) && (1 - u - v).EpsilonEquals(uvw[2]));
                Point2d p2 = tri.EvaluateBar(uvw[0], uvw[1], uvw[2]);
                Assert.IsTrue(p.EpsilonEquals(p2));
            };

            {
                Triangle2d tri = new Triangle2d(new Point2d(0, 5), new Point2d(5, 0), new Point2d(5, 5));

                test01(tri, 0, 0);
                test01(tri, 0.1, 0.1);
                test01(tri, 0.2, 0.2);
                test01(tri, 0.3, 0.3);
                test01(tri, 0, 0.3);
                test01(tri, 0.3, 0);

                Assert.IsTrue(tri.EvaluateBar(1, 0, 0).EpsilonEquals(tri.P0));
                Assert.IsTrue(tri.EvaluateBar(0, 1, 0).EpsilonEquals(tri.P1));
                Assert.IsTrue(tri.EvaluateBar(0, 0, 1).EpsilonEquals(tri.P2));

                testBar(tri, 0, 0);
                testBar(tri, 1, 0);
                testBar(tri, 0, 1);
                testBar(tri, 0.5, 0);
                testBar(tri, 0.5, 0.5);
                testBar(tri, 1.0 / 3.0, 1.0 / 3.0);
            }
        }
Example #6
0
        internal bool InnerTest(Point2d p)
        {
            Point2d x = p;

            // Per appartenere alla faccia devono essere tutte a sinistra dello spigolo
            for (int i = 0; i < 3; i++)
            {
                AM_Edge e = m_pEdges[i];
                if (x.EpsilonEquals(e.OrgCoord(), AM_Util.FLT_EPSILON))
                {
                    return(true);
                }

                if (AM_Edge.RightOf(x, e))
                {
                    return(false);
                }
            }

            return(true);
        }
        internal bool BuildVertexes(bool bForceEven)
        {
            int numSegments = NumSegments;

            for (int i = 0; i < numSegments; i++)
            {
                var crv = m_Curves[i];
                var pV1 = m_Vertexes[i];
                var pV2 = m_Vertexes[(i + 1) % m_Vertexes.Count];

                if (!IsClosed && i == numSegments - 1)
                {
                    pV2 = m_Vertexes[i + 1];
                }

                double space1 = pV1.Space;
                double space2 = pV2.Space;

                Point2d org  = pV1.Location;
                Point2d dest = pV2.Location;

                Point2d start = AM_Util.To2d(crv.PointAtStart);
                Point2d end   = AM_Util.To2d(crv.PointAtEnd);

                Debug.Assert(org.EpsilonEquals(start, AM_Util.FLT_EPSILON));
                Debug.Assert(dest.EpsilonEquals(end, AM_Util.FLT_EPSILON));

                m_GenPoint[i] = new List <Point4d>();

                if (!BuildPointFromSpace(bForceEven, org, dest, crv, space1, space2, m_GenPoint[i]))
                {
                }
            }

            return(true);
        }
Example #8
0
 internal bool IsEqual(Point2d coord, double toll)
 {
     return(m_Coord.EpsilonEquals(coord, toll));
 }