Exemplo n.º 1
0
        public void PathIntersectionsTest0()
        {
            Scene scene = new Scene();
            FloatPortal p0 = new FloatPortal(scene);
            p0.SetTransform(new Transform2(new Vector2(1, 0)));
            FloatPortal p1 = new FloatPortal(scene);
            p1.SetTransform(new Transform2(new Vector2(10, -1)));
            p0.Linked = p1;
            p1.Linked = p0;

            PortalCommon.UpdateWorldTransform(scene);

            LineF ray = new LineF(new Vector2(0, 0), new Vector2(8, -1));
            PortalPath path = new PortalPath();
            path.Enter(p0);
            var intersections = Portal.PathIntersections(path, ray);
            Assert.AreEqual(1, intersections.Length);
            Assert.AreEqual(0.5, intersections[0].TFirst, PATH_INTERSECTION_DELTA);
            Assert.AreEqual(1.0 / 3, intersections[0].TLast, PATH_INTERSECTION_DELTA);
        }
Exemplo n.º 2
0
        public void PathIntersectionsTest2()
        {
            Scene scene = new Scene();
            FloatPortal p0 = new FloatPortal(scene);
            p0.SetTransform(new Transform2(new Vector2(1, 0)));
            FloatPortal p1 = new FloatPortal(scene);
            p1.SetTransform(new Transform2(new Vector2(2, 0), 1, (float)Math.PI));

            p0.Linked = p1;
            p1.Linked = p0;

            FloatPortal p2 = new FloatPortal(scene);
            p2.SetTransform(new Transform2(new Vector2(3, 0)));
            FloatPortal p3 = new FloatPortal(scene);
            p3.SetTransform(new Transform2(new Vector2(6, 3), 1, (float)Math.PI/2));

            p2.Linked = p3;
            p3.Linked = p2;

            PortalCommon.UpdateWorldTransform(scene);

            LineF ray = new LineF(new Vector2(0, 0), new Vector2(6, 2));
            PortalPath path = new PortalPath();
            path.Enter(p0);
            path.Enter(p2);

            var intersections = Portal.PathIntersections(path, ray);
            Assert.AreEqual(2, intersections.Length);
            Assert.AreEqual(0.5, intersections[0].TFirst, PATH_INTERSECTION_DELTA);
            Assert.AreEqual(1.0 / 3, intersections[0].TLast, PATH_INTERSECTION_DELTA);

            Assert.AreEqual(0.5, intersections[1].TFirst, PATH_INTERSECTION_DELTA);
            Assert.AreEqual(2.0 / 3, intersections[1].TLast, PATH_INTERSECTION_DELTA);
        }