;;; dag-draw-coord-transform.el --- Coordinate transformation layer -*- lexical-binding: t -*-

;; Copyright (C) 2024, 2025

;; Author: Generated by Claude
;; Keywords: internal

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;;; Commentary:

;; Coordinate Transformation - Anti-Corruption Layer
;;
;; BOUNDED CONTEXT: Anti-Corruption Layer (Transform)
;; UPSTREAM CONTEXT: GKNV Algorithm Context
;; DOWNSTREAM CONTEXT: ASCII Rendering Context
;; LAYER: Translation/Integration
;; AUTHORITY: doc/implementation-decisions.md (D5.1) + DDD pattern
;;
;; This module implements the anti-corruption layer between two bounded contexts:
;;
;; 1. GKNV Algorithm Context (world coordinates - float values)
;;    - Authority: "A Technique for Drawing Directed Graphs" paper
;;    - Coordinates: Continuous floating-point (x, y) positions
;;    - Units: Abstract "world units" from GKNV algorithm
;;    - Purpose: Optimal graph layout using network simplex
;;
;; 2. ASCII Rendering Context (grid coordinates - integer values)
;;    - Authority: Implementation decisions (D5.1-D5.8)
;;    - Coordinates: Discrete integer grid positions
;;    - Units: Character cells in terminal grid
;;    - Purpose: Rendering with box-drawing characters
;;
;; Anti-Corruption Layer Responsibilities:
;; - Translate between world coordinates and grid coordinates
;; - Maintain coordinate context (offsets, scaling factors)
;; - Ensure ASCII coordinates are always non-negative
;; - Preserve GKNV layout proportions during transformation
;; - Provide single source of truth for all coordinate conversions
;;
;; Key Concepts:
;; - World coordinates: GKNV output, can be negative, floating-point
;; - Grid coordinates: ASCII grid, always non-negative integers
;; - Scale factor: Conversion ratio between world and grid units
;; - Offset: Translation to ensure non-negative grid coordinates
;;
;; Bounded Context: Anti-Corruption Layer (Transform)
;; Upstream: GKNV Algorithm Context
;; Downstream: ASCII Rendering Context
;;
;; See doc/implementation-decisions.md (D5.1) for coordinate scaling decisions.

;;; Code:

(require 'ht)
(require 'dag-draw-core)


(defun dag-draw--world-to-grid-size (world-size scale)
  "Convert world size to grid size.

WORLD-SIZE is a number representing a dimension in world coordinates.
SCALE is a float representing the scaling factor.

Divides by SCALE, rounds to integer, and ensures minimum size of 1.

Returns an integer grid size (minimum 1) in character units."
  (max 1 (round (/ world-size scale))))




(provide 'dag-draw-coord-transform)

;;; dag-draw-coord-transform.el ends here
