public void ShouldNot_Int2_Equals()
        {
            var value = new Int2(1);

            Assert.IsTrue(!value.Equals(2));
            Assert.IsTrue(!value.Equals((object)2));
            Assert.IsTrue(!value.Equals(new Int2(2)));
            Assert.IsTrue(!value.Equals(new UInt2(2)));
            Assert.IsTrue(!value.Equals((object)new Int2(2)));
            Assert.IsTrue(value != new Int2(2));
            Assert.IsTrue(value != new UInt2(2));
            Assert.IsTrue(value != (object)new Int2(2));
            Assert.IsTrue(value != 2);
            Assert.IsTrue(value != 2L);

            Assert.IsFalse(value == new Int2(2));
            Assert.IsFalse(value == new UInt2(2));
            Assert.IsFalse(value == (object)new Int2(2));
            Assert.IsFalse(value == 2);
            Assert.IsFalse(value == 2L);

            Assert.IsFalse(new Int2(-1) == new UInt2(1));
            Assert.IsFalse(new Int2(-1).Equals(new UInt2(1)));
            Assert.IsTrue(new Int2(-1) != new UInt2(1));
        }
Esempio n. 2
0
        public static T[] Resize <T>(T[] pixels, Int2 originalSize, Int2 newSize)
        {
            if (originalSize.Equals(newSize))
            {
                return(pixels.ToArray());
            }

            var originalWidth  = originalSize.X;
            var originalLength = originalSize.Y;
            var newWidth       = newSize.X;
            var newLength      = newSize.Y;

            int GetOriginalIndex(int x, int y) =>
            (int)Math.Round(MathUtil.Lerp(0, originalLength, MathUtil.InverseLerp(0, newLength, y)), MidpointRounding.AwayFromZero) * originalWidth +
            (int)Math.Round(MathUtil.Lerp(0, originalWidth, MathUtil.InverseLerp(0, newWidth, x)), MidpointRounding.AwayFromZero);

            T[] newPixels = new T[newWidth * newLength];
            for (int y = 0; y < newLength; ++y)
            {
                for (int x = 0; x < newWidth; ++x)
                {
                    newPixels[y * newWidth + x] = pixels[GetOriginalIndex(x, y)];
                }
            }

            return(newPixels);
        }
        public void Should_Int2_Equals()
        {
            var value = new Int2(1);

            Assert.IsTrue(value.Equals(1));
            Assert.IsTrue(value.Equals((object)1));
            Assert.IsTrue(value.Equals(new Int2(1)));
            Assert.IsTrue(value.Equals(new UInt2(1)));
            Assert.IsTrue(value.Equals((object)new Int2(1)));
            Assert.IsTrue(value == new Int2(1));
            Assert.IsTrue(value == new UInt2(1));
            Assert.IsTrue(value == (object)new Int2(1));
            Assert.IsTrue(value == 1);
            Assert.IsTrue(value == 1L);
            Assert.IsTrue(1 == value);
        }
Esempio n. 4
0
        public static T[] Resize <T>(T[] pixels, Int2 originalSize, Int2 newSize)
        {
            if (originalSize.X < 1 || originalSize.Y < 1)
            {
                throw new ArgumentException($"{nameof(originalSize)}.{nameof(originalSize.X)} and {nameof(originalSize.Y)} should be greater than 0.");
            }
            if (newSize.X < 1 || newSize.Y < 1)
            {
                throw new ArgumentException($"{nameof(newSize)}.{nameof(newSize.X)} and {nameof(newSize.Y)} should be greater than 0.");
            }

            if (originalSize.Equals(newSize))
            {
                return(pixels.ToArray());
            }

            var originalWidth  = originalSize.X;
            var originalLength = originalSize.Y;
            var newWidth       = newSize.X;
            var newLength      = newSize.Y;

            var scaleX = (newWidth - 1) == 0 ? 0d : ((double)(originalWidth - 1)) / (newWidth - 1);
            var scaleY = (newLength - 1) == 0 ? 0d : ((double)(originalLength - 1)) / (newLength - 1);

            int GetOriginalIndex(int x, int y) =>
            (int)Math.Round(y * scaleY, MidpointRounding.AwayFromZero) * originalWidth +
            (int)Math.Round(x * scaleX, MidpointRounding.AwayFromZero);

            var newPixels = new T[newWidth * newLength];

            for (int y = 0; y < newLength; ++y)
            {
                for (int x = 0; x < newWidth; ++x)
                {
                    newPixels[y * newWidth + x] = pixels[GetOriginalIndex(x, y)];
                }
            }

            return(newPixels);
        }
Esempio n. 5
0
    public static HashSet <PlatformGroup> ProcuduralInit(Int2 start, Int2 goal, float randomness, int blockFactor)
    {
        //generate one random path (may has circuit)
        randomness = Mathf.Clamp01(randomness);
        Int2        curr = start;
        List <Int2> path = new List <Int2>();

        path.Add(curr);
        Direction currDir = Direction.Forward;
        Direction nextDir = currDir;

        while (!curr.Equals(goal))
        {
            if (curr._z == goal._z)
            {
                if (curr._x > goal._x)
                {
                    nextDir = Direction.Left;
                }
                else
                {
                    nextDir = Direction.Right;
                }
            }
            else
            {
                int allowed = 0;
                if (curr._x > 0 && currDir != Direction.Right)
                {
                    allowed = allowed | (int)Direction.Left;
                }
                if (curr._x < gridSystem.gridSizeX - 1 && currDir != Direction.Left)
                {
                    allowed = allowed | (int)Direction.Right;
                }
                //if (curr._z > 0 && currDir != Direction.Forward) allowed |= (int)Direction.Backward;
                if (curr._z < goal._z)
                {
                    allowed |= (int)Direction.Forward;
                }

                //make a turn
                if (URandom.value <= randomness || (allowed & (int)currDir) == 0)
                {
                    int best = 0;
                    if (curr._x < goal._x)
                    {
                        best |= (int)Direction.Right;
                    }
                    else if (curr._x > goal._x)
                    {
                        best |= (int)Direction.Left;
                    }

                    if (curr._z < goal._z)
                    {
                        best |= (int)Direction.Forward;
                    }
                    //else if (curr._z > goal._z) best |= (int)Direction.Backward;

                    best &= allowed;

                    do
                    {
                        nextDir = (Direction)(1 << URandom.Range(0, 3));
                    }while (currDir == nextDir || ((int)nextDir & allowed) == 0);
                }
            }
            switch (nextDir)
            {
            case Direction.Left: curr._x--; break;

            case Direction.Right: curr._x++; break;

            //case Direction.Backward: curr._z--; break;
            case Direction.Forward: curr._z++; break;
            }
            path.Add(curr);
            currDir = nextDir;
        }

        //reverse path
        path.Reverse();

        //offset segments

        throw new NotImplementedException();
    }
Esempio n. 6
0
 public bool Equals(Move other)
 {
     return(Pos.Equals(other.Pos) && From.Equals(other.From) && ValidLanding == other.ValidLanding);
 }