Ejemplo n.º 1
0
        /// <summary>
        /// Creates a pattern based on the given piece of the given input.
        /// </summary>
        /// <param name="inputMin">
        /// The position of this pattern's min corner in the input.
        /// </param>
        /// <param name="size">
        /// The size of this pattern along each axis (before transformation).
        /// </param>
        /// <param name="patternTransform">
        /// Transforms this pattern's region in the input.
        /// Note that using Rotate270CW or Rotate90CW results in the X and Y size swapping places.
        /// </param>
        public Pattern(Input input, Vector2i inputMin, Vector2i size, Transforms patternTransform)
        {
            Frequency = 1;

            //Get the size of this pattern after transformation.
            Vector2i transformedSize = size;

            switch (patternTransform)
            {
            case Transforms.MirrorX:
            case Transforms.MirrorY:
            case Transforms.Rotate180:
            case Transforms.None:
                break;

            case Transforms.Rotate270CW:
            case Transforms.Rotate90CW:
                transformedSize = new Vector2i(size.y, size.x);
                break;

            default: throw new NotImplementedException(patternTransform.ToString());
            }

            //Sample the pixel values from the input.
            Values = new Color[transformedSize.x, transformedSize.y];
            foreach (Vector2i patternPos in new Vector2i.Iterator(size))
            {
                Vector2i transformedPatternPos = patternPos.Transform(patternTransform, size);
                Vector2i inputPos = inputMin + patternPos;

                Values.Set(transformedPatternPos, input[inputPos]);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets/sets a pixel in this input.
        /// Automatically handles things like wrapping the position if this instance is periodic.
        /// </summary>
        public Color this[Vector2i pos]
        {
            get
            {
                Vector2i size = Size;
                if (PeriodicX)
                {
                    while (pos.x < 0)
                    {
                        pos.x += size.x;
                    }
                    pos.x %= size.x;
                }
                if (PeriodicY)
                {
                    while (pos.y < 0)
                    {
                        pos.y += size.y;
                    }
                    pos.y %= size.y;
                }

                return(data.Get(pos));
            }
            set
            {
                Vector2i size = Size;
                if (PeriodicX)
                {
                    while (pos.x < 0)
                    {
                        pos.x += size.x;
                    }
                    pos.x %= size.x;
                }
                if (PeriodicY)
                {
                    while (pos.y < 0)
                    {
                        pos.y += size.y;
                    }
                    pos.y %= size.y;
                }

                if (!IsInside(pos))
                {
                    return;
                }

                data.Set(pos, value);
            }
        }
Ejemplo n.º 3
0
 public      Color this[Vector2i pos]
 {
     get { return(Values.Get(pos)); }
     set { Values.Set(pos, value); }
 }