79 lines
2.3 KiB
Python
79 lines
2.3 KiB
Python
|
||
|
||
class Coord:
|
||
def __init__(self, row, col):
|
||
self.row = row
|
||
self.col = col
|
||
|
||
def shift(self, down=0, right=0, up=0, left=0) -> "Coord":
|
||
return Coord(self.row + down - up,
|
||
self.col + right - left)
|
||
|
||
def replace(self, row=None, col=None) -> "Coord":
|
||
return Coord(self.row if row is None else row,
|
||
self.col if col is None else col)
|
||
|
||
def cell(self, reader: "ExcelSheetReader") -> "TranschendentnostCell":
|
||
return reader.cell(self.row, self.col)
|
||
|
||
def __repr__(self):
|
||
import utils
|
||
return utils.excel_coordinate(self.row, self.col)
|
||
|
||
def as_numbers(self):
|
||
return self.row, self.col
|
||
|
||
def __hash__(self):
|
||
return hash((self.row, self.col))
|
||
|
||
def __eq__(self, other):
|
||
if not isinstance(other, Coord):
|
||
# don't attempt to compare against unrelated types
|
||
return NotImplemented
|
||
|
||
return self.row == other.row and self.col == other.col
|
||
|
||
|
||
class Merged:
|
||
def __init__(self, coord1, coord2):
|
||
self.low: Coord = coord1
|
||
self.high: Coord = coord2
|
||
|
||
def height(self):
|
||
return self.high.row - self.low.row + 1
|
||
|
||
def width(self):
|
||
return self.high.col - self.low.col + 1
|
||
|
||
def cell(self, reader: "ExcelSheetReader") -> "TranschendentnostCell":
|
||
return reader.cell(self.low.row, self.low.col)
|
||
|
||
|
||
def is_pseudo_merged(self):
|
||
"""Псевдо-мержнутая значит размеом 1x1, оно же если начало совпадает с концом"""
|
||
return self.low == self.high
|
||
|
||
def as_numbers(self):
|
||
low = self.low.as_numbers()
|
||
high = self.high.as_numbers()
|
||
return low[0], low[1], high[0], high[1] # rlo, clo, rhi, chi
|
||
|
||
def __hash__(self):
|
||
return hash((self.low, self.high))
|
||
|
||
def __eq__(self, other):
|
||
if not isinstance(other, Merged):
|
||
# don't attempt to compare against unrelated types
|
||
return NotImplemented
|
||
|
||
return self.low == other.low and self.high == other.high
|
||
|
||
def __contains__(self, key):
|
||
if not isinstance(key, Coord):
|
||
return NotImplemented
|
||
|
||
row = key.row
|
||
col = key.col
|
||
|
||
return (self.low.row <= row <= self.high.row) and (self.low.col <= col <= self.high.col)
|