{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "434d2730",
   "metadata": {},
   "source": [
    "# 18-16 · Geometria prostokąta\n",
    "\n",
    "Praktyka do sekcji [„Geometria prostokąta”](/pl/chapters/rozdzial-18/18-16-geometriya-pryamougolnika.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd46bd21",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "normalize_bounds() przenosi współrzędne do (left, top, right bottom) niezależnie od kierunku oporu."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "89590abd",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3df23157",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:51:48.374696Z",
     "iopub.status.busy": "2026-09-03T00:51:48.374519Z",
     "iopub.status.idle": "2026-09-03T00:51:48.399829Z",
     "shell.execute_reply": "2026-09-03T00:51:48.399330Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(10, 10, 100, 80) (10, 10, 100, 80)\n"
     ]
    }
   ],
   "source": [
    "def normalize_bounds(x1, y1, x2, y2):\n",
    "    \"\"\"Приводит две произвольные противоположные точки к (left, top, right, bottom).\"\"\"\n",
    "    return min(x1, x2), min(y1, y2), max(x1, x2), max(y1, y2)\n",
    "\n",
    "\n",
    "r_vniz_vpravo = normalize_bounds(10, 10, 100, 80)\n",
    "r_vverh_vlevo = normalize_bounds(100, 80, 10, 10)\n",
    "print(r_vniz_vpravo, r_vverh_vlevo)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5c408af",
   "metadata": {},
   "source": [
    "## Podstawowa praktyka zadań ★"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3963f090",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:51:48.401529Z",
     "iopub.status.busy": "2026-09-03T00:51:48.401348Z",
     "iopub.status.idle": "2026-09-03T00:51:48.404871Z",
     "shell.execute_reply": "2026-09-03T00:51:48.404297Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Все четыре направления дают одинаковые нормализованные границы.\n"
     ]
    }
   ],
   "source": [
    "assert r_vniz_vpravo == (10, 10, 100, 80)\n",
    "assert r_vverh_vlevo == (10, 10, 100, 80)\n",
    "assert normalize_bounds(100, 10, 10, 80) == (10, 10, 100, 80)  # вниз-влево\n",
    "assert normalize_bounds(10, 80, 100, 10) == (10, 10, 100, 80)  # вверх-вправо\n",
    "assert normalize_bounds(50, 50, 50, 50) == (50, 50, 50, 50)    # без перетаскивания\n",
    "print(\"Все четыре направления дают одинаковые нормализованные границы.\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
