Exemplo n.º 1
0
        public static IExplicitShape <GridPoint2> Translate(this IExplicitShape <GridPoint2> shape, GridPoint2 n)
        {
            var newBounds = GridRect.Translate(shape.Bounds, n);
            var newShape  = ImplicitShape.Translate(shape, n).ToExplicit(newBounds);

            return(newShape);
        }
Exemplo n.º 2
0
            public ExplicitShape2 Intersection(ExplicitShape2 shape2)
            {
                var newRect  = GridRect.Intersection(storageBounds, shape2.storageBounds);
                var newShape = ImplicitShape.Intersection(implicitShape, shape2.implicitShape);

                return(new ExplicitShape2(newShape, newRect));
            }
Exemplo n.º 3
0
            public ExplicitShape2 Union(ExplicitShape2 shape2)
            {
                var newRect  = GridRect.UnionBoundingBox(storageBounds, shape2.storageBounds);
                var newShape = ImplicitShape.Union(implicitShape, shape2.implicitShape);

                return(new ExplicitShape2(newShape, newRect));
            }
Exemplo n.º 4
0
            public ExplicitShape2 Translate(GridPoint2 offset)
            {
                var map = Map.Translate(offset);

                var newRect  = GridRect.Translate(storageBounds, offset);
                var newShape = ImplicitShape.Transform(implicitShape, map);

                return(new ExplicitShape2(newShape, newRect));
            }
Exemplo n.º 5
0
        public static IExplicitShape <GridPoint2> SwapXY(this IExplicitShape <GridPoint2> shape)
        {
            var bounds = shape.Bounds;
            var point  = bounds.Point;
            var size   = bounds.Size;

            var newBounds = new GridRect(
                new GridPoint2(point.Y, point.X), new GridPoint2(size.Y, size.X));

            return(ImplicitShape.SwapXY(shape).ToExplicit(newBounds));
        }
Exemplo n.º 6
0
        public static Grid2 <float> ImageToGreyScaleGrid(Texture2D texture, int xOffset, int yOffset)
        {
            var dimensions    = new GridPoint2(texture.width, texture.height);
            var storageRect   = new GridRect(GridPoint2.Zero, dimensions);
            var implicitShape = ImplicitShape.Parallelogram(dimensions);
            var explicitShape = implicitShape.ToExplicit(storageRect);

            var grid        = new Grid2 <float>(explicitShape);
            var textureData = texture.GetPixels().Select(c => c.grayscale).ToArray();

            grid.Fill(p => textureData[(p.X + xOffset) % texture.width + (texture.width * ((p.Y + yOffset) % texture.height))]);

            return(grid);
        }
Exemplo n.º 7
0
            public BitmaskShape2(string[] shape)
            {
                int max    = shape.Max(row => row.Length);
                var bounds = new GridRect(GridPoint2.Zero, new GridPoint2(max, shape.Length));

                grid = new Grid2 <bool>(bounds);

                foreach (var point in grid.Points)
                {
                    if (point.X < shape[point.Y].Length)
                    {
                        grid[point] = shape[point.Y][point.X] != '0';
                    }
                    else
                    {
                        grid[point] = false;
                    }
                }
            }