Example #1
0
        static IEnumerable <CellMap <T> > GridCells <T>(this GridSpec <T> spec)
            where T : struct
        {
            var bit     = 0;
            var seg     = 0;
            var segbits = spec.CellSize;

            for (int row = 0, rowbit = 0; row < spec.RowCount; row++)
            {
                for (var col = 0; col < spec.ColCount; col++, bit++, rowbit++, segbits--)
                {
                    if (segbits == 0)
                    {
                        seg++;
                        segbits = spec.CellSize;
                    }

                    var offset = (byte)(spec.CellSize - segbits).Bits;
                    var pos    = CellIndex <T> .Define((ushort)seg, offset);

                    yield return(new CellMap <T>(pos.Segment, pos.Offset, pos.LinearIndex, row, col));
                }

                seg++;
                segbits = spec.CellSize;
            }
        }
Example #2
0
 public GridLayout(GridSpec <T> spec, IEnumerable <CellMap <T> > Cells)
 {
     this.GridSpec       = spec;
     this.RowCount       = spec.RowCount;
     this.ColCount       = spec.ColCount;
     this.BitCount       = spec.BitCount;
     this.RowCellCount   = spec.RowCellCount;
     this.TotalCellCount = spec.TotalCellCount;
     this.RowLayout      = CreateLayoutIndex(Cells);
     this.CellSize       = spec.CellSize;
     require(spec.RowCount == RowLayout.Count);
     require(spec.ColCount == RowLayout.First().Value.Length);
 }
Example #3
0
 public static GridLayout <T> CalcLayout <T>(this GridSpec <T> spec)
     where T : struct
 => new GridLayout <T>(spec, spec.GridCells());