From 1b763fc11cc1de706491fac03de6b38bbdd839f2 Mon Sep 17 00:00:00 2001 From: Nicolas Predella Date: Thu, 15 Oct 2026 14:13:28 +0300 Subject: [PATCH] big refactor --- core/pdf_exporter/depth_rasterizer.py | 37 --------------------------- infra/csv_handling.py | 24 ----------------- infra/json_handling.py | 13 ---------- 3 files changed, 74 deletions(-) delete mode 100644 core/pdf_exporter/depth_rasterizer.py delete mode 100644 infra/csv_handling.py delete mode 100644 infra/json_handling.py diff --git a/core/pdf_exporter/depth_rasterizer.py b/core/pdf_exporter/depth_rasterizer.py deleted file mode 100644 index 75b324c..0000000 --- a/core/pdf_exporter/depth_rasterizer.py +++ /dev/null @@ -1,37 +0,0 @@ -""" -SA2 Performance Profiling & Vector Edge Debug Export Module. -Saves input vector edge debug data and cProfile statistics when debug_sa2 is enabled. -""" -from typing import Any -import numpy as np -from numpy.typing import NDArray - - -def save_sa2_debug_data( - edges: NDArray[np.float64] | None, - obj_name: str, - filepath: str | Any -) -> None: - """ - Saves debug edge vector data files in the same folder as the output PDF: - - {name}_sa2_debug_edges.txt (Input 2D edge vector coordinates fed to SA2) - """ - if filepath is None: - return - from pathlib import Path - pdf_path = Path(filepath) - out_dir = pdf_path.parent - out_dir.mkdir(parents=True, exist_ok=True) - - clean_name = pdf_path.stem if pdf_path.suffix.lower() == ".pdf" else str(obj_name) - base_prefix = out_dir / f"{clean_name}_sa2_debug" - - # Save input edge coordinates as text file - if edges is not None and len(edges) > 0: - txt_file = f"{base_prefix}_edges.txt" - with open(txt_file, "w") as f: - f.write(f"# SA2 Input 2D Edges Debug for {clean_name}\n") - f.write(f"# Format: x1 y1 x2 y2\n") - for segment in edges: - (x1, y1), (x2, y2) = segment[0], segment[1] - f.write(f"{x1:.4f} {y1:.4f} {x2:.4f} {y2:.4f}\n") diff --git a/infra/csv_handling.py b/infra/csv_handling.py deleted file mode 100644 index 684ce63..0000000 --- a/infra/csv_handling.py +++ /dev/null @@ -1,24 +0,0 @@ -from functools import lru_cache - -import csv -import os - -@lru_cache(maxsize=128) -def _load_csv(filename: str, mtime: float, encoding: str | None = None) -> tuple[tuple[str, ...], ...]: - with open(filename, 'r', newline='', encoding=encoding) as f: - reader = csv.reader(f) - return tuple(tuple(row) for row in reader) - -def parse_csv_to_tuples(filename: str) -> list[tuple[str, ...]]: - current_mtime = os.path.getmtime(filename) - data: tuple[tuple[str, ...], ...] = _load_csv(filename, current_mtime) - return sorted(data, key=lambda x: x[1]) - -def parse_csv_to_dict(filename: str) -> dict[str, list[str]]: - current_mtime = os.path.getmtime(filename) - data: tuple[tuple[str, ...], ...] = _load_csv(filename, current_mtime, encoding='utf-8-sig') - result = {} - for row in data: - if row: - result[row[0]] = list(row[1:]) - return result \ No newline at end of file diff --git a/infra/json_handling.py b/infra/json_handling.py deleted file mode 100644 index 106eb79..0000000 --- a/infra/json_handling.py +++ /dev/null @@ -1,13 +0,0 @@ -import os, json - -def dict_from_json(path): - with open(path, 'r') as file: - return json.load(file) - -def dump_dict_to_json(dictionary, path): - folder = os.path.dirname(path) - if folder and not os.path.exists(folder): - os.makedirs(folder, exist_ok=True) - - with open(path, 'w') as file: - json.dump(dictionary, file, indent=2) \ No newline at end of file