Пример #1
0
        public void FirstIntersectionWithEllipse(string rs, string es, string eps)
        {
            var ray      = Ray.Parse(rs);
            var ellipse  = Ellipse.Parse(es);
            var expected = eps == "null" ? (Point?)null : Point.Parse(eps);
            var actual   = ray.FirstIntersectionWith(ellipse);

            PointAssert.AreEqual(expected, actual, 2);
        }
Пример #2
0
        public void IntersectWithRectangleStartingOutside(string ls, string rs, string eps)
        {
            var l        = Line.Parse(ls);
            var rect     = Rect.Parse(rs);
            var expected = eps == "null" ? (Point?)null : Point.Parse(eps);
            var actual   = l.ClosestIntersection(rect);

            PointAssert.AreEqual(expected, actual, 2);
        }
Пример #3
0
        public void FirstIntersectionWithCircle(string ls, string cs, string eps)
        {
            var ray      = Ray.Parse(ls);
            var circle   = Circle.Parse(cs);
            var expected = eps == "null" ? (Point?)null : Point.Parse(eps);
            var actual   = ray.FirstIntersectionWith(circle);

            PointAssert.AreEqual(expected, actual, 2);
        }
Пример #4
0
        public void ClosestIntersection(string ls, string cs, string eps)
        {
            var l        = Line.Parse(ls);
            var circle   = Circle.Parse(cs);
            var expected = eps is "null" ? (Point?)null : Point.Parse(eps);
            var actual   = circle.ClosestIntersection(l);

            PointAssert.AreEqual(expected, actual, 2);
        }
        public void PointOnCircumference(string es, string vs, string eps)
        {
            var ellipse   = Ellipse.Parse(es);
            var direction = Vector.Parse(vs);
            var expected  = Point.Parse(eps);
            var actual    = ellipse.PointOnCircumference(direction);

            PointAssert.AreEqual(expected, actual, 2);
        }
        public void PointAtAngle(string es, double angle, string eps)
        {
            var ellipse   = Ellipse.Parse(es);
            var expected  = Point.Parse(eps);
            var direction = new Vector(1, 0).Rotate(angle);
            var actual    = ellipse.PointOnCircumference(direction);

            PointAssert.AreEqual(expected, actual, 2);
            Assert.AreEqual(ellipse.CenterPoint.DistanceTo(actual), ellipse.RadiusInDirection(direction), 1E-3);
        }
Пример #7
0
        public void FirstIntersectionWithRectFromOutsideRoundtrips(string rs)
        {
            var rect  = Rect.Parse(rs);
            var xAxis = new Vector(1, 0);

            for (var i = -180; i < 180; i++)
            {
                var direction   = xAxis.Rotate(i);
                var fromCenter  = new Ray(rect.CenterPoint(), direction);
                var pointOnRect = fromCenter.FirstIntersectionWith(rect).GetValueOrDefault();
                var ray         = new Ray(pointOnRect + direction, direction.Negated());
                var actual      = ray.FirstIntersectionWith(rect);
                PointAssert.AreEqual(pointOnRect, actual, 2);

                if (rect.ClosestCornerPoint(pointOnRect)
                    .DistanceTo(pointOnRect) < 0.01)
                {
                    continue;
                }

                Vector wallNormal;
                if (Math.Abs(pointOnRect.X - rect.Left) < Constants.Tolerance)
                {
                    wallNormal = new Vector(-1, 0);
                }
                else if (Math.Abs(pointOnRect.X - rect.Right) < Constants.Tolerance)
                {
                    wallNormal = new Vector(1, 0);
                }
                else if (Math.Abs(pointOnRect.Y - rect.Bottom) < Constants.Tolerance)
                {
                    wallNormal = new Vector(0, 1);
                }
                else
                {
                    wallNormal = new Vector(0, -1);
                }

                for (var j = -89; j < 89; j++)
                {
                    var rayDirection = wallNormal.Rotate(j);
                    ray    = new Ray(pointOnRect + rayDirection, rayDirection.Negated());
                    actual = ray.FirstIntersectionWith(rect);
                    if (!NullablePointComparer.TwoDigits.Equals(pointOnRect, actual))
                    {
                        Debugger.Break();
                    }

                    PointAssert.AreEqual(pointOnRect, actual, 2);
                }
            }
        }
Пример #8
0
        public void FirstIntersectionWithEllipseFromInsideRoundtrips(string es)
        {
            var ellipse = Ellipse.Parse(es);
            var xv      = new Vector(1, 0);

            for (var i = -180; i < 180; i++)
            {
                var direction = xv.Rotate(i);
                var expected  = ellipse.PointOnCircumference(direction);
                var ray       = new Ray(ellipse.CenterPoint, direction);
                var actual    = ray.FirstIntersectionWith(ellipse);
                PointAssert.AreEqual(expected, actual, 2);
            }
        }
Пример #9
0
        public void FirstIntersectionWithCircleFromOutsideRoundtrips(string cs)
        {
            var circle = Circle.Parse(cs);
            var xv     = new Vector(1, 0);

            for (var i = -180; i < 180; i++)
            {
                var direction            = xv.Rotate(i);
                var pointOnCircumference = circle.PointOnCircumference(direction);
                var ray    = new Ray(pointOnCircumference + direction, direction.Negated());
                var actual = ray.FirstIntersectionWith(circle);
                PointAssert.AreEqual(pointOnCircumference, actual, 2);
            }
        }
Пример #10
0
        public void FirstIntersectionWithEllipseFromOutsideRoundtrips(string es)
        {
            var ellipse = Ellipse.Parse(es);
            var xv      = new Vector(1, 0);

            for (var i = -180; i < 180; i++)
            {
                var fromCenterDirection  = xv.Rotate(i);
                var pointOnCircumference = ellipse.PointOnCircumference(fromCenterDirection);
                var ray    = new Ray(pointOnCircumference + fromCenterDirection, fromCenterDirection.Negated());
                var actual = ray.FirstIntersectionWith(ellipse);
                PointAssert.AreEqual(pointOnCircumference, actual, 2);
                for (var j = -70; j < 70; j++)
                {
                    var direction = fromCenterDirection.Rotate(j);
                    ray    = new Ray(pointOnCircumference + direction, direction.Negated());
                    actual = ray.FirstIntersectionWith(ellipse);
                    PointAssert.AreEqual(pointOnCircumference, actual, 2);
                }
            }
        }
Пример #11
0
        public void IntersectWithRectangleStartingInside(string ls, string rs, string eps)
        {
            var l        = Line.Parse(ls);
            var rect     = Rect.Parse(rs);
            var expected = Point.Parse(eps);
            var actual   = l.ClosestIntersection(rect);

            PointAssert.AreEqual(expected, actual, 2);

            actual = l.Flip().ClosestIntersection(rect);
            PointAssert.AreEqual(expected, actual, 2);

            var l2 = l.RotateAroundStartPoint(0.01);

            actual = l2.ClosestIntersection(rect);
            PointAssert.AreEqual(expected, actual, 2);

            var l3 = l.RotateAroundStartPoint(-0.01);

            actual = l3.ClosestIntersection(rect);
            PointAssert.AreEqual(expected, actual, 2);
        }