Esempio n. 1
0
        public StructuralIntegrity(List <T> matter)
        {
            this.matter = matter;
            structure.Add(matter[0], LocationF.Create(0, 0));

            for (var i = 1; i < matter.Count; i++)
            {
                var xDelta = matter[i].Left - matter[0].Left;
                var yDelta = matter[i].Top - matter[0].Top;
                structure.Add(matter[i], LocationF.Create(xDelta, yDelta));
            }
        }
Esempio n. 2
0
        public StructuralIntegrity(List <T> matter)
        {
            this.matter = matter;
            structure.Add(matter[0], LocationF.Create(0, 0));

            for (var i = 1; i < matter.Count; i++)
            {
                var xDelta = matter[i].Left - matter[0].Left;
                var yDelta = matter[i].Top - matter[0].Top;
                structure.Add(matter[i], LocationF.Create(xDelta, yDelta));
            }

            this.Added.SubscribeOnce(async() =>
            {
                while (this.Lifetime.IsExpired == false)
                {
                    Evaluate();
                    await Time.CurrentTime.YieldAsync();
                }
            });
        }
Esempio n. 3
0
 private void Show(LocationF l1, LocationF l2)
 {
     Debug.WriteLine(string.Format("from {0} to {1}", l1, l2));
     Debug.WriteLine(string.Format("dir={0}, distance={1}", l1.GetDirectionTo(l2), l1.GetDistanceTo(l2)));
 }
Esempio n. 4
0
        private async Task TestCantGoThroughWalls(Direction d, CliTestHarness app, SpaceTimePanel stPanel)
        {
            SpacialAwareness.OnNudge.SubscribeForLifetime((ev) => Assert.Fail("Nudging not allowed"), app);
            var st   = stPanel.SpaceTime;
            var wall = st.Add(new SpacialElement()
            {
                BackgroundColor = RGB.DarkRed
            });
            ILocationF movingObjectLocation;
            float      movementAngle;
            float      expected;
            Func <SpacialElement, float> actual;

            if (d == Direction.Right)
            {
                movingObjectLocation = LocationF.Create((int)(st.Width * .25f), st.Height * .5f - .5f);
                movementAngle        = 0;
                wall.ResizeTo(.1f, st.Height);
                wall.MoveTo((int)(st.Width * .75f), 0);

                expected = wall.Left;
                actual   = m => m.Right();
            }
            else if (d == Direction.Left)
            {
                movingObjectLocation = LocationF.Create((int)(st.Width * .75f), st.Height * .5f - .5f);
                movementAngle        = 180;
                wall.ResizeTo(.1f, st.Height);
                wall.MoveTo((int)(st.Width * .25f) - .1f, 0);

                expected = wall.Right();
                actual   = m => m.Left;
            }
            else if (d == Direction.Up)
            {
                movingObjectLocation = LocationF.Create(st.Width * .5f - .5f, (int)(st.Height * .75f));
                movementAngle        = 270;
                wall.ResizeTo(st.Width, .1f);
                wall.MoveTo(0, (int)(st.Height * .25f) - .1f);

                expected = wall.Bottom();
                actual   = m => m.Top;
            }
            else if (d == Direction.Down)
            {
                movingObjectLocation = LocationF.Create(st.Width * .5f - .5f, (int)(st.Height * .25f));
                movementAngle        = 90;
                wall.ResizeTo(st.Width, .1f);
                wall.MoveTo(0, (int)(st.Height * .75f));

                expected = wall.Top;
                actual   = m => m.Bottom();
            }
            else
            {
                throw new NotSupportedException();
            }

            for (var speed = 5; speed < 1000; speed *= 2)
            {
                Console.WriteLine($"Speed: {speed}");
                var movingObject = st.Add(new SpacialElement(1, 1, movingObjectLocation.Left, movingObjectLocation.Top)
                {
                    BackgroundColor = RGB.Blue
                });
                var v = new Velocity(movingObject);
                await st.DelayAsync(500);

                v.Angle = movementAngle;
                v.Speed = speed;
                await st.DelayAsync(20000);

                PhysicsTest.AssertClose(expected, actual(movingObject), .2f);
                Console.WriteLine($"Wall.Left == {expected}, movingObject.Right() == {actual(movingObject)}");
                movingObject.Lifetime.Dispose();
            }
        }