public double this[GridIndex i] { get { if (CanIndex(i)) { return(m_Data[i.I, i.J]); } else { throw new IndexOutOfRangeException(); } } set { if (CanIndex(i)) { m_Data[i.I, i.J] = value; } else { throw new IndexOutOfRangeException(); } } }
public GridRegion Shrink(int margin) { var pos = new GridIndex(Pos.I + margin, Pos.J + margin); var size = new GridSize(Size.Width - 2 * margin, Size.Height - 2 * margin); if (size.Height < 0 || size.Width < 0) { throw new InvalidOperationException("Region cannot shrink."); } return(new GridRegion(pos, size)); }
public GridRegion(GridIndex pos, GridSize size) { if (pos == null) { throw new ArgumentException("pos can't be null."); } if (size == null) { throw new ArgumentException("size can't be null."); } Pos = pos; Size = size; }
public bool IsInside(GridIndex index) { return(index.I >= Pos.I && index.I < Pos.I + Size.Height && index.J >= Pos.J && index.J < Pos.J + Size.Width); }
public bool CanIndex(GridIndex index) => Bounds.IsInside(index) && !Inaccessable.IsInside(index);
public bool CanIndex(GridIndex index) => Bounds.IsInside(index);