using System; namespace CPF.ReoGrid.Views { internal struct GridRegion { public GridRegion(int startRow, int startCol, int endRow, int endCol) { this.startRow = startRow; this.startCol = startCol; this.endRow = endRow; this.endCol = endCol; } public bool Contains(CellPosition pos) { return this.Contains(pos.Row, pos.Col); } public bool Contains(int row, int col) { return this.startRow <= row && this.endRow >= row && this.startCol <= col && this.endCol >= col; } public bool Contains(RangePosition range) { return range.Row >= this.startRow && range.Col >= this.startCol && range.EndRow <= this.endRow && range.EndCol <= this.endCol; } public bool Intersect(RangePosition range) { return (range.Row < this.startRow && range.EndRow > this.startRow) || (range.Row < this.endRow && range.EndRow > this.endRow) || (range.Col < this.startCol && range.EndCol > this.startCol) || (range.Col < this.endCol && range.EndCol > this.endCol); } public bool IsOverlay(RangePosition range) { return this.Contains(range) || this.Intersect(range); } public override bool Equals(object obj) { bool flag = !(obj is GridRegion?); bool result; if (flag) { result = false; } else { GridRegion gridRegion = (GridRegion)obj; result = (this.startRow == gridRegion.startRow && this.startCol == gridRegion.startCol && this.endRow == gridRegion.endRow && this.endCol == gridRegion.endCol); } return result; } public override int GetHashCode() { return this.startRow ^ this.startCol ^ this.endRow ^ this.endCol; } public static bool operator ==(GridRegion gr1, GridRegion gr2) { return gr1.Equals(gr2); } public static bool operator !=(GridRegion gr1, GridRegion gr2) { return !gr1.Equals(gr2); } public bool IsEmpty { get { return this.Equals(GridRegion.Empty); } } public int Rows { get { return this.endRow - this.startRow + 1; } set { this.endRow = this.startRow + value - 1; } } public int Cols { get { return this.endCol - this.startCol + 1; } set { this.endCol = this.startCol + value - 1; } } public override string ToString() { return string.Format("VisibleRegion[{0},{1}-{2},{3}]", new object[] { this.startRow, this.startCol, this.endRow, this.endCol }); } public RangePosition ToRange() { return new RangePosition(this.startRow, this.startCol, this.endRow - this.startRow + 1, this.endCol - this.startCol + 1); } internal int startRow; internal int endRow; internal int startCol; internal int endCol; internal static readonly GridRegion Empty = new GridRegion { startRow = 0, startCol = 0, endRow = 0, endCol = 0 }; } }