示例#1
0
        public void ToFloatAxial()
        {
            FloatAxial floatAxial = new FloatCubic( 1f, 2f, 3f ).ToFloatAxial();

            Assert.That( floatAxial.q, Is.InRange<float>(  1f - EPSILON,  1f + EPSILON ) );
            Assert.That( floatAxial.r, Is.InRange<float>(  3f - EPSILON,  3f + EPSILON ) );
        }
示例#2
0
        public void Scale()
        {
            FloatCubic floatCubic = new FloatCubic( 1f, 2f, -3f ).Scale( 3f );

            Assert.That( floatCubic.x, Is.InRange<float>(  3f - EPSILON,  3f + EPSILON ) );
            Assert.That( floatCubic.y, Is.InRange<float>(  6f - EPSILON,  6f + EPSILON ) );
            Assert.That( floatCubic.z, Is.InRange<float>( -9f - EPSILON, -9f + EPSILON ) );
        }
示例#3
0
        public void ConstructorXYZ()
        {
            FloatCubic floatCubic = new FloatCubic( 1f, 2f, 3f );

            Assert.That( floatCubic.x, Is.EqualTo( 1f ) );
            Assert.That( floatCubic.y, Is.EqualTo( 2f ) );
            Assert.That( floatCubic.z, Is.EqualTo( 3f ) );
        }
示例#4
0
        public void ConstructorParameterless()
        {
            FloatCubic floatCubic = new FloatCubic();

            Assert.That( floatCubic.x, Is.EqualTo( 0f ) );
            Assert.That( floatCubic.y, Is.EqualTo( 0f ) );
            Assert.That( floatCubic.z, Is.EqualTo( 0f ) );
        }
示例#5
0
        public void ConstructorCubic()
        {
            FloatCubic floatCubic = new FloatCubic( new CubicHexCoord( 1, 2, 3 ) );

            Assert.That( floatCubic.x, Is.InRange<float>( 1f - EPSILON, 1f + EPSILON ) );
            Assert.That( floatCubic.y, Is.InRange<float>( 2f - EPSILON, 2f + EPSILON ) );
            Assert.That( floatCubic.z, Is.InRange<float>( 3f - EPSILON, 3f + EPSILON ) );
        }
示例#6
0
        Line(CubicHexCoord start, CubicHexCoord end)
        {
            int distance = CubicHexCoord.Distance(start, end);

            CubicHexCoord[] result = new CubicHexCoord[distance + 1];

            for (int i = 0; i <= distance; i++)
            {
                float xLerp = start.x + (end.x - start.x) * 1f / distance * i;
                float yLerp = start.y + (end.y - start.y) * 1f / distance * i;
                float zLerp = start.z + (end.z - start.z) * 1f / distance * i;

                result[i] = new FloatCubic(xLerp, yLerp, zLerp).Round();
            }

            return(result);
        }
示例#7
0
        /// <summary>
        /// Returns an array of CubicHexCoords that form the straightest path from the given start
        /// to the given end. The hexes in the line are determined by forming a straight line from 
        /// start to end and linearly interpolating and rounding each of the interpolated points to 
        /// the nearest hex position.
        /// </summary>
        /// <param name="start">The CubicHexCoord representing the first hex in the line.</param>
        /// <param name="end">The CubicHexCoord representing the last hex in the line.</param>
        /// <returns>An array of CubicHexCoords ordered as a line from start to end.</returns>
        public static CubicHexCoord[] Line( CubicHexCoord start, CubicHexCoord end )
        {
            int distance = CubicHexCoord.Distance( start, end );

            CubicHexCoord[] result = new CubicHexCoord[ distance + 1 ];

            for ( int i = 0; i <= distance; i++ )
            {
                float xLerp = start.x + ( end.x - start.x ) * 1f / distance * i;
                float yLerp = start.y + ( end.y - start.y ) * 1f / distance * i;
                float zLerp = start.z + ( end.z - start.z ) * 1f / distance * i;

                result[ i ] = new FloatCubic( xLerp, yLerp, zLerp ).Round();
            }

            return result;
        }