Exemple #1
0
        public void Equals_GivenPointsWithDifferentCoords_ShouldReturnFalse()
        {
            // Arrange.
            var p1 = new Point2d(10, 20);
            var p2 = new Point2d(1, 2);

            // Act & Assert.
            Assert.False(p1.Equals(p2));
            Assert.False(p1 == p2);
            Assert.True(p1 != p2);
            Assert.AreNotEqual(p1, p2);
        }
        private static IEnumerable <Point2d> PerpendicularDistanceSafe(this IEnumerable <Point2d> points, double tol2)
        {
            IEnumerator <Point2d> enumer = points.GetEnumerator();

            if (!enumer.MoveNext())
            {
                yield break;
            }

            Point2d p0 = enumer.Current;

            // the first point is always part of the simplification
            yield return(p0);

            if (!enumer.MoveNext())
            {
                yield break;
            }

            Point2d p1   = enumer.Current;
            Point2d last = p1;

            while (enumer.MoveNext())
            {
                Point2d p2 = enumer.Current;

                // test p1 against line segment S(p0, p2)
                if (segment_distance2(p0, p2, p1) < tol2)
                {
                    yield return(p2);

                    last = p2;

                    // move up by two points
                    p0 = p2;

                    // protect against advancing p2 beyond last
                    if (!enumer.MoveNext())
                    {
                        break;
                    }
                    p1 = enumer.Current;
                }
                else
                {
                    yield return(p1);

                    last = p1;

                    // move up by one point
                    p0 = p1;
                    p1 = p2;
                }
            }

            // make sure the last point is part of the simplification
            if (!p1.Equals(last))
            {
                yield return(p1);
            }
        }
        public static void PerpendicularDistance(this IEnumerable <Point2d> points, double tol, Action <Point2d> result, out int removed)
        {
            removed = 0;

            double tol2 = tol * tol; // squared distance tolerance

            // validate input and check if simplification required
            if (tol2.EpsilonEquals(0))
            {
                foreach (Point2d p in points)
                {
                    result(p);
                }
                return;
            }

            IEnumerator <Point2d> enumer = points.GetEnumerator();

            if (!enumer.MoveNext())
            {
                return;
            }

            Point2d p0 = enumer.Current;

            // the first point is always part of the simplification
            result(p0);

            if (!enumer.MoveNext())
            {
                return;
            }

            Point2d p1   = enumer.Current;
            Point2d last = p1;

            while (enumer.MoveNext())
            {
                Point2d p2 = enumer.Current;

                // test p1 against line segment S(p0, p2)
                if (segment_distance2(p0, p2, p1) < tol2)
                {
                    result(p2);
                    last = p2;

                    // move up by two points
                    p0 = p2;

                    // protect against advancing p2 beyond last
                    if (!enumer.MoveNext())
                    {
                        break;
                    }
                    p1 = enumer.Current;

                    removed++;
                }
                else
                {
                    result(p1);
                    last = p1;

                    // move up by one point
                    p0 = p1;
                    p1 = p2;
                }
            }

            // make sure the last point is part of the simplification
            if (!p1.Equals(last))
            {
                result(p1);
            }
        }