Beispiel #1
0
        private void AreEqual(Ray2D rayA, Ray2D rayB, Vector2 point, Vector2 expected)
        {
            float delta = (point - expected).magnitude;

            Assert.True(delta < Geometry.Epsilon, string.Format("{0}\n{1}\npoint: {2} expected: {3:G9}\ndelta: {4:F8}",
                                                                rayA.ToString("G9"), rayB.ToString("G9"), point.ToString("G9"), expected.ToString("G9"), delta));
        }
Beispiel #2
0
        private void False_Intersect(Ray2D ray, Circle2 circle)
        {
            IntersectionRayCircle intersection;
            string message = string.Format(format, ray.ToString("F8"), circle);

            Assert.False(Intersect.RayCircle(ray.origin, ray.direction, circle.center, circle.radius, out intersection), message);
        }
        private void IsFalse_Intersect(Ray2D ray, Segment2 segment)
        {
            IntersectionRaySegment2 intersection;

            Assert.IsFalse(Geometry.IntersectRaySegment(ray.origin, ray.direction, segment.a, segment.b, out intersection),
                           ray.ToString("F8") + "\n" + segment.ToString("F8"));
        }
        private void IsFalse_Intersect(Ray2D ray, Segment2 segment)
        {
            string message = string.Format(format, ray.ToString("F8"), segment);

            Assert.IsFalse(Intersect.RaySegment(ray.origin, ray.direction, segment.a, segment.b, out _), message);
            Assert.IsFalse(Intersect.RaySegment(ray.origin, ray.direction, segment.b, segment.a, out _), message);
        }
        private void AreEqual_Distance(Ray2D ray, Segment2 segment, float expected = 0)
        {
            string message = string.Format(format, ray.ToString("F8"), segment);

            AreEqual(Distance.RaySegment(ray.origin, ray.direction, segment.a, segment.b), expected, message);
            AreEqual(Distance.RaySegment(ray.origin, ray.direction, segment.b, segment.a), expected, message);
        }
Beispiel #6
0
        public void ToStringTest()
        {
            var ray    = new Ray2D(new Point2D(3.45, -23.45653), new Vector2D(4.3482, -1209.23829));
            var result = $"Origin: [X: 3,45 Y: -23,46], Direction: [X: 4,35 Y: -1209,24]";

            Assert.AreEqual(result, ray.ToString());
        }
        private void AreEqual_Distance(Ray2D rayA, Ray2D rayB, float expected = 0)
        {
            string message = string.Format(format, rayA.ToString("F8"), rayB.ToString("F8"));

            AreEqual(Distance.RayRay(rayA, rayB), expected, message);
            AreEqual(Distance.RayRay(rayB, rayA), expected, message);
        }
Beispiel #8
0
        private void IsFalse_IntersectSwap(Line2 line, Ray2D ray)
        {
            string message = string.Format(format, line, ray.ToString("F8"));

            Assert.IsFalse(Intersect.LineRay(line.origin, line.direction, ray.origin, ray.direction, out _), message);
            Assert.IsFalse(Intersect.LineRay(line.origin, line.direction, ray.origin, -ray.direction, out _), message);
        }
        private void IsFalse_Intersect(Ray2D rayA, Ray2D rayB)
        {
            string message = string.Format(format, rayA.ToString("F8"), rayB.ToString("F8"));

            Assert.IsFalse(Intersect.RayRay(rayA, rayB, out _), message);
            Assert.IsFalse(Intersect.RayRay(rayB, rayA, out _), message);
        }
Beispiel #10
0
        private void IsFalse_Intersect(Line2 line, Ray2D ray)
        {
            IntersectionLineRay2 intersection;
            string message = string.Format(format, line, ray.ToString("F8"));

            Assert.IsFalse(Intersect.LineRay(line, ray, out intersection), message);
        }
        private void IsFalse_Intersect(Line2 line, Ray2D ray)
        {
            IntersectionLineRay2 intersection;

            Assert.IsFalse(Geometry.IntersectLineRay(line, ray, out intersection),
                           line.ToString("F8") + "\n" + ray.ToString("F8"));
        }
Beispiel #12
0
    static int ToString(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 1)
        {
            Ray2D  obj = LuaScriptMgr.GetNetObject <Ray2D>(L, 1);
            string o   = obj.ToString();
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 2)
        {
            Ray2D  obj  = LuaScriptMgr.GetNetObject <Ray2D>(L, 1);
            string arg0 = LuaScriptMgr.GetLuaString(L, 2);
            string o    = obj.ToString(arg0);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: Ray2D.ToString");
        }

        return(0);
    }
Beispiel #13
0
        private void AreEqual_DistanceToRay(Ray2D rayA, Ray2D rayB, float expected)
        {
            float distance = Geometry.DistanceToRay(rayA, rayB);
            float delta    = Mathf.Abs(expected - distance);

            Assert.True(delta < Geometry.Epsilon, string.Format("{0}\n{1}\ndistance: {2:G9} expected: {3:G9}\ndelta: {4:F8}",
                                                                rayA.ToString("G9"), rayB.ToString("G9"), distance, expected, delta));
        }
        private void True_IntersectPoint(Ray2D ray, Circle2 circle, Vector2 expected)
        {
            string message = string.Format(format, ray.ToString("F8"), circle);

            Assert.True(Intersect.RayCircle(ray.origin, ray.direction, circle.center, circle.radius, out IntersectionRayCircle intersection), message);
            Assert.AreEqual(IntersectionType.Point, intersection.type, message);
            AreEqual(intersection.pointA, expected, message);
        }
Beispiel #15
0
        private void False_Intersect(Ray2D ray, Vector2 point, int expected = 0)
        {
            string message = string.Format(format, ray.ToString("F8"), point.ToString("F8"));

            Assert.False(Intersect.PointRay(point, ray.origin, ray.direction), message);
            Assert.False(Intersect.PointRay(point, ray.origin, ray.direction, out int side), message);
            Assert.AreEqual(expected, side, message);
        }
Beispiel #16
0
        private void AreEqual_ClosestPoints(Line2 line, Ray2D ray, Vector2 lineExpected, Vector2 rayExpected)
        {
            string message = string.Format(format, line, ray.ToString("F8"));

            Closest.LineRay(line, ray, out Vector2 linePoint, out Vector2 rayPoint);
            AreEqual(linePoint, lineExpected, message);
            AreEqual(rayPoint, rayExpected, message);
        }
Beispiel #17
0
        private void IsTrue_IntersectPoint(Line2 line, Ray2D ray, Vector2 expected)
        {
            string message = string.Format(format, line, ray.ToString("F8"));

            Assert.IsTrue(Intersect.LineRay(line, ray, out IntersectionLineRay2 intersection), message);
            Assert.AreEqual(IntersectionType.Point, intersection.type);
            AreEqual(intersection.point, expected);
        }
        private void IsTrue_IntersectRay(Ray2D rayA, Ray2D rayB, Vector2 expectedOrigin, Vector2 expectedDirection)
        {
            string message = string.Format(format, rayA.ToString("F8"), rayB.ToString("F8"));

            Assert.IsTrue(Intersect.RayRay(rayA, rayB, out IntersectionRayRay2 intersection), message);
            Assert.AreEqual(IntersectionType.Ray, intersection.type, message);
            AreEqual(intersection.pointA, expectedOrigin, message);
            AreEqual(intersection.pointB, expectedDirection, message);
        }
Beispiel #19
0
        private void True_Intersect(Ray2D ray, Vector2 point)
        {
            int    side;
            string message = string.Format(format, ray.ToString("F8"), point.ToString("F8"));

            Assert.True(Intersect.PointRay(point, ray.origin, ray.direction), message);
            Assert.True(Intersect.PointRay(point, ray.origin, ray.direction, out side), message);
            Assert.AreEqual(0, side, message);
        }
Beispiel #20
0
        private void Intersect_Coincident(Ray2D ray)
        {
            IntersectionRayRay2 intersection;

            Assert.IsTrue(Geometry.IntersectRayRay(ray, ray, out intersection), ray.ToString("F8"));
            Assert.AreEqual(intersection.type, IntersectionType.Ray);
            AreEqual(intersection.pointA, ray.origin);
            AreEqual(intersection.pointB, ray.direction);
        }
        private void AreEqual_ClosestPoints(Ray2D rayA, Ray2D rayB, Vector2 expectedA1, Vector2 expectedB1, Vector2 expectedA2, Vector2 expectedB2)
        {
            string message = string.Format(format, rayA.ToString("F8"), rayB.ToString("F8"));

            Closest.RayRay(rayA, rayB, out Vector2 pointA, out Vector2 pointB);
            AreEqual(pointA, expectedA1, message);
            AreEqual(pointB, expectedB1, message);
            Closest.RayRay(rayB, rayA, out pointA, out pointB);
            AreEqual(pointA, expectedA2, message);
            AreEqual(pointB, expectedB2, message);
        }
Beispiel #22
0
        private void IsTrue_IntersectRay(Line2 line, Ray2D ray)
        {
            string message = string.Format(format, line, ray.ToString("F8"));

            Assert.IsTrue(Intersect.LineRay(line.origin, line.direction, ray.origin, ray.direction, out IntersectionLineRay2 intersection), message);
            Assert.AreEqual(IntersectionType.Ray, intersection.type, message);
            AreEqual(intersection.point, ray.origin, message);
            Assert.IsTrue(Intersect.LineRay(line.origin, line.direction, ray.origin, -ray.direction, out intersection), message);
            Assert.AreEqual(IntersectionType.Ray, intersection.type, message);
            AreEqual(intersection.point, ray.origin, message);
        }
        private void AreEqual_ClosestPoints(Ray2D ray, Segment2 segment, Vector2 expectedRay, Vector2 expectedSegment)
        {
            string message = string.Format(format, ray.ToString("F8"), segment);

            Closest.RaySegment(ray.origin, ray.direction, segment.a, segment.b, out Vector2 rayPoint, out Vector2 segmentPoint);
            AreEqual(rayPoint, expectedRay, message);
            AreEqual(segmentPoint, expectedSegment, message);
            Closest.RaySegment(ray.origin, ray.direction, segment.b, segment.a, out rayPoint, out segmentPoint);
            AreEqual(rayPoint, expectedRay, message);
            AreEqual(segmentPoint, expectedSegment, message);
        }
        private void IsTrue_IntersectPoint(Ray2D ray, Segment2 segment, Vector2 expected)
        {
            string message = string.Format(format, ray.ToString("F8"), segment);

            Assert.IsTrue(Intersect.RaySegment(ray.origin, ray.direction, segment.a, segment.b, out IntersectionRaySegment2 intersection), message);
            Assert.AreEqual(IntersectionType.Point, intersection.type, message);
            AreEqual(intersection.pointA, expected, message);
            Assert.IsTrue(Intersect.RaySegment(ray.origin, ray.direction, segment.b, segment.a, out intersection), message);
            Assert.AreEqual(IntersectionType.Point, intersection.type, message);
            AreEqual(intersection.pointA, expected, message);
        }
Beispiel #25
0
        private void IsTrue_IntersectPoint(Ray2D rayA, Ray2D rayB, Vector2 expected)
        {
            IntersectionRayRay2 intersection;
            string message = string.Format(format, rayA.ToString("F8"), rayB.ToString("F8"));

            Assert.IsTrue(Intersect.RayRay(rayA, rayB, out intersection), message);
            Assert.AreEqual(IntersectionType.Point, intersection.type, message);
            AreEqual(intersection.pointA, expected, message);
            Assert.IsTrue(Intersect.RayRay(rayB, rayA, out intersection), message);
            Assert.AreEqual(IntersectionType.Point, intersection.type, message);
            AreEqual(intersection.pointA, expected, message);
        }
        private void IsTrue_IntersectSegment(Ray2D rayA, Ray2D rayB)
        {
            string message = string.Format(format, rayA.ToString("F8"), rayB.ToString("F8"));

            Assert.IsTrue(Intersect.RayRay(rayA, rayB, out IntersectionRayRay2 intersection), message);
            Assert.AreEqual(IntersectionType.Segment, intersection.type, message);
            AreEqual(intersection.pointA, rayA.origin, message);
            AreEqual(intersection.pointB, rayB.origin, message);
            Assert.IsTrue(Intersect.RayRay(rayB, rayA, out intersection), message);
            Assert.AreEqual(IntersectionType.Segment, intersection.type, message);
            AreEqual(intersection.pointA, rayB.origin, message);
            AreEqual(intersection.pointB, rayA.origin, message);
        }
Beispiel #27
0
 private void IsFalse_IntersectRayRay(Ray2D rayA, Ray2D rayB, out IntersectionRayRay2 intersection)
 {
     Assert.IsFalse(Geometry.IntersectRayRay(rayA, rayB, out intersection), rayA.ToString("F8") + "\n" + rayB.ToString("F8"));
 }
Beispiel #28
0
        private void AreEqual_ClosestPoint(Ray2D ray, Vector2 point, Vector2 expected)
        {
            string message = string.Format(format, ray.ToString("F8"), point.ToString("F8"));

            AreEqual(Closest.PointRay(point, ray), expected, message);
        }
Beispiel #29
0
        private void AreEqual_Distance(Ray2D ray, Vector2 point, float expected = 0)
        {
            string message = string.Format(format, ray.ToString("F8"), point.ToString("F8"));

            AreEqual(Distance.PointRay(point, ray), expected, message);
        }
Beispiel #30
0
        private void AreEqual_Distance(Line2 line, Ray2D ray, float expected = 0)
        {
            string message = string.Format(format, line, ray.ToString("F8"));

            AreEqual(Distance.LineRay(line, ray), expected, message);
        }