import os import re import numpy as np import math def UnpackingMif(file_directory: str): try: x, y = [], [] readMif(file_directory, x, y) temp_square=Square(x, y) x.clear() y.clear() return temp_square except FileNotFoundError: return 0 def readMif(path: str, x, y): with open(path,'r', encoding='Windows-1251') as file: t = [] region = False for line in file: if 'Region' in line: region = True continue if region: t.append(line) t = t[1:-3] for ch in t: ch = re.sub('[\n]', '', ch) ch = ch.split(" ") if check_float(ch[0]) and check_float(ch[1]): y.append(round(float(ch[0]), 2)) x.append(round(float(ch[1]), 2)) else: continue def Square(x, y): area = 0.5 * np.abs(np.dot(x, np.roll(y, 1)) - np.dot(y, np.roll(x, 1))) rounded_area = math.ceil(area - 0.5) if (area % 1) >= 0.5 else round(area) return int(rounded_area) # Возвращаем целое число #return round(0.5 * np.abs(np.dot(x, np.roll(y, 1)) - np.dot(y, np.roll(x, 1))), 0) def check_float(var): try: float(var) except ValueError: return False return True