Beispiel #1
0
        public void PointMapsCorrectly(int X, int Y, long correctX, long correctY)
        {
            var translator = new LocationTranslator(FixedLocation.Zero, new Rectangle(0, 0, 100, 100), 20.0d);

            var location = translator.ToFixedLocation(new Point(X, Y));

            Assert.AreEqual(correctX, location.X);
            Assert.AreEqual(correctY, location.Y);
        }
Beispiel #2
0
        public void LocationMapsCorrectly(long X, long Y, int correctX, int correctY)
        {
            var translator = new LocationTranslator(FixedLocation.Zero, new Rectangle(0, 0, 100, 100), 20.0d);

            var point = translator.ToPoint(new FixedLocation(X, Y));

            Assert.AreEqual(correctX, point.X);
            Assert.AreEqual(correctY, point.Y);
        }
Beispiel #3
0
        public void CenterIsZeroLocation()
        {
            var translator = new LocationTranslator(FixedLocation.Zero, new Rectangle(0, 0, 100, 100), 20.0d);

            var location = translator.ToFixedLocation(new Point(50, 50));

            Assert.AreEqual(0, location.X);
            Assert.AreEqual(0, location.Y);
        }
Beispiel #4
0
        public void ZeroLocationIsCentered()
        {
            var translator = new LocationTranslator(FixedLocation.Zero, new Rectangle(0, 0, 100, 100), 20.0d);

            var point = translator.ToPoint(FixedLocation.Zero);

            Assert.AreEqual(50, point.X);
            Assert.AreEqual(50, point.Y);
        }
Beispiel #5
0
        public void Display(IEnumerable <IBody> toShow, ILocation center, double distancePerPixel)
        {
            var newToDraw   = new DrawObject[toShow.Count()];
            var toShowArray = toShow.ToArray();

            translator = new LocationTranslator(center, ClientRectangle, distancePerPixel);

            Parallel.For(0, newToDraw.Length, n =>
            {
                var body    = toShowArray[n];
                bool isStar = body is Star;
                bool isShip = body is Ship;

                var drawObject = new DrawObject()
                {
                    name = body.Name, color = Color.Green
                };
                if (isStar)
                {
                    drawObject.color = Color.Red;
                }
                if (body is Asteroid)
                {
                    drawObject.color = Color.Blue;
                }
                if (isShip)
                {
                    drawObject.color = Color.Yellow;
                }

                drawObject.location = translator.ToPoint(body.Location);
                var zoomMod         = 50000000 / distancePerPixel;
                double drawSize     = (zoomMod * Math.Pow(body.Mass, 1.0d / 3.0d));

                if (drawSize <= 1.0d)
                {
                    if (drawSize > 0.01)
                    {
                        drawSize = 1.0d;
                    }
                    else if (!isStar && !isShip)
                    {
                        drawSize = 0.0d;
                    }

                    if (!isStar && !isShip)
                    {
                        drawObject.name = null;
                    }
                }
                drawObject.size = (int)drawSize;

                newToDraw[n] = drawObject;
            });

            lock (lockObject)
            {
                toDraw = newToDraw;
            }

            this.Invalidate();
        }