Пример #1
0
        public void CalcHemisphere_SouthWest()
        {
            var res = CoordinateHelper.CalcHemisphere(swCoord);

            Assert.AreEqual(CoordinateHelper.Hemisphere.SouthWest, res);
        }
        /// <summary>
        /// Finds the available neighbours, depending on the logical location of this satellite, in the provided direction.
        /// </summary>
        /// <param name="direction">The direction for which the neighbour is searched for. Can be Up, Down, Left and Right.</param>
        /// <returns>The Satellite neighbour in the specified direction.</returns>
        private Satellite FindNeighbour(NeighbourDirection direction)
        {
            Satellite neighbour = null;

            if (direction == NeighbourDirection.Up)
            {
                neighbour = _constellation[_thisSatellite.SatPosition.OrbitNumber][(_thisSatellite.SatPosition.SatNumber + 1) % _conf.NumberOfSatellitesPerOrbit];
            }
            if (direction == NeighbourDirection.Down)
            {
                neighbour = _constellation[_thisSatellite.SatPosition.OrbitNumber][(_thisSatellite.SatPosition.SatNumber + _conf.NumberOfSatellitesPerOrbit - 1) % _conf.NumberOfSatellitesPerOrbit];
            }

            var hemisphere = CoordinateHelper.CalcHemisphere(_thisSatellite.Location);

            if (direction == NeighbourDirection.Right && _conf.NumberOfOrbits > 1)
            {
                var neighbourOrbitRight = 0;
                var rightCrossSeamOrbit = 0;

                if (hemisphere == CoordinateHelper.Hemisphere.NorthEast || hemisphere == CoordinateHelper.Hemisphere.SouthEast) //If this satellite is in the eastern hemisphere
                {
                    neighbourOrbitRight = (_thisSatellite.SatPosition.OrbitNumber + 1) % _conf.NumberOfOrbits;                  //Calculate number of next orbit
                    rightCrossSeamOrbit = _conf.MinimumOrbitNumber;

                    if (neighbourOrbitRight > 0)                                                               //If orbit to my right is NOT across the seam
                    {
                        neighbour = _constellation[neighbourOrbitRight][_thisSatellite.SatPosition.SatNumber]; //My right neighbour is my initial neighbour
                    }
                }
                else if (hemisphere == CoordinateHelper.Hemisphere.NorthWest || hemisphere == CoordinateHelper.Hemisphere.SouthWest)    //If this satellite is in the western hemisphere (mirrored constellation)
                {
                    neighbourOrbitRight = (_thisSatellite.SatPosition.OrbitNumber + (_conf.NumberOfOrbits - 1)) % _conf.NumberOfOrbits; //Calculate number of next orbit
                    rightCrossSeamOrbit = _conf.MaximumOrbitNumber;

                    if (neighbourOrbitRight < _conf.MaximumOrbitNumber) //If orbit to my right is NOT across the seam
                    {
                        neighbour = _constellation[neighbourOrbitRight][_thisSatellite.SatPosition.SatNumber];
                    }
                }

                //If my orbit is the last one, i.e. right neighbour is crossing the seam AND cross-seam communication is enabled (otherwise this satellite has no right neighbour right now)
                if (neighbourOrbitRight == rightCrossSeamOrbit && _conf.CrossSeamCommunicationEnabled)
                {
                    var ticks = _thisSatellite.LogicalPosition.SatNumber - _thisSatellite.SatPosition.SatNumber;
                    if (ticks < 0)                                                                                                                            //How many ticks since original position
                    {
                        ticks = _conf.NumberOfSatellitesPerOrbit - Math.Abs(_thisSatellite.LogicalPosition.SatNumber - _thisSatellite.SatPosition.SatNumber); //10
                    }

                    //Original neighbour position
                    var initNb = (_conf.NumberOfSatellitesPerOrbit - _thisSatellite.SatPosition.SatNumber - (_conf.NumberOfSatellitesPerOrbit / 2)) % _conf.NumberOfSatellitesPerOrbit;
                    if (initNb < 0)
                    {
                        initNb = _conf.NumberOfSatellitesPerOrbit - Math.Abs(initNb);
                    }

                    //Current neighbour
                    var newNb = initNb - (ticks * 2) % _conf.NumberOfSatellitesPerOrbit; //Each "tick" shifts cross-seam neighbours by 2
                    if (newNb < 0)
                    {
                        newNb = _conf.NumberOfSatellitesPerOrbit - Math.Abs(newNb);
                    }

                    neighbour = _constellation[neighbourOrbitRight][newNb];
                }
            }
            if (direction == NeighbourDirection.Left && _conf.NumberOfOrbits > 1)
            {
                var neighbourOrbitLeft = 0;
                var leftCrossSeamOrbit = 0;

                if (hemisphere == CoordinateHelper.Hemisphere.NorthEast || hemisphere == CoordinateHelper.Hemisphere.SouthEast)      //If this satellite is in the eastern hemisphere
                {
                    neighbourOrbitLeft = (_thisSatellite.SatPosition.OrbitNumber + _conf.NumberOfOrbits - 1) % _conf.NumberOfOrbits; //Calculate number of next orbit
                    leftCrossSeamOrbit = _conf.MaximumOrbitNumber;

                    if (neighbourOrbitLeft != leftCrossSeamOrbit)                                             //If orbit to my right is NOT across the seam
                    {
                        neighbour = _constellation[neighbourOrbitLeft][_thisSatellite.SatPosition.SatNumber]; //My right neighbour is my initial neighbour
                    }
                }
                else if (hemisphere == CoordinateHelper.Hemisphere.NorthWest || hemisphere == CoordinateHelper.Hemisphere.SouthWest) //If this satellite is in the western hemisphere (mirrored constellation)
                {
                    neighbourOrbitLeft = (_thisSatellite.SatPosition.OrbitNumber + 1) % _conf.NumberOfOrbits;                        //Calculate number of next orbit
                    leftCrossSeamOrbit = _conf.MinimumOrbitNumber;

                    if (neighbourOrbitLeft != leftCrossSeamOrbit) //If orbit to my right is NOT across the seam
                    {
                        neighbour = _constellation[neighbourOrbitLeft][_thisSatellite.SatPosition.SatNumber];
                    }
                }

                //If my orbit is the last one, i.e. right neighbour is crossing the seam AND cross-seam communication is enabled (otherwise this satellite has no right neighbour right now)
                if (neighbourOrbitLeft == leftCrossSeamOrbit && _conf.CrossSeamCommunicationEnabled)
                {
                    var ticks = _thisSatellite.LogicalPosition.SatNumber - _thisSatellite.SatPosition.SatNumber;
                    if (ticks < 0) //How many ticks since original position
                    {
                        ticks = _conf.NumberOfSatellitesPerOrbit - Math.Abs(_thisSatellite.LogicalPosition.SatNumber - _thisSatellite.SatPosition.SatNumber);
                    }

                    //Original neighbour position
                    var initNb = (_conf.NumberOfSatellitesPerOrbit - _thisSatellite.SatPosition.SatNumber - (_conf.NumberOfSatellitesPerOrbit / 2)) % _conf.NumberOfSatellitesPerOrbit;
                    if (initNb < 0)
                    {
                        initNb = _conf.NumberOfSatellitesPerOrbit - Math.Abs(initNb);
                    }

                    //Current neighbour
                    var newNb = initNb - (ticks * 2) % _conf.NumberOfSatellitesPerOrbit;
                    if (newNb < 0)
                    {
                        newNb = _conf.NumberOfSatellitesPerOrbit - Math.Abs(newNb);
                    }

                    neighbour = _constellation[neighbourOrbitLeft][newNb];
                }
            }

            return(neighbour);
        }
Пример #3
0
        public void CalcHemisphere_NorthEast()
        {
            var res = CoordinateHelper.CalcHemisphere(neCoord);

            Assert.AreEqual(CoordinateHelper.Hemisphere.NorthEast, res);
        }