{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0cb64746",
   "metadata": {},
   "source": [
    "# 18-17 · Геометрия овала\n",
    "\n",
    "Практика к разделу [«Геометрия овала»](../../site/chapters/glava-18/18-17-geometriya-ovala.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6b4a854",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Переводить координаты между «центр + радиус» и ограничивающим прямоугольником create_oval."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0be74eb",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ee4af0cd",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:51:50.680680Z",
     "iopub.status.busy": "2026-09-03T00:51:50.680522Z",
     "iopub.status.idle": "2026-09-03T00:51:50.703759Z",
     "shell.execute_reply": "2026-09-03T00:51:50.702521Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(30, 30, 70, 70) (50.0, 50.0)\n"
     ]
    }
   ],
   "source": [
    "def bounds_from_center(cx, cy, r):\n",
    "    return cx - r, cy - r, cx + r, cy + r\n",
    "\n",
    "\n",
    "def center_from_bounds(x1, y1, x2, y2):\n",
    "    return (x1 + x2) / 2, (y1 + y2) / 2\n",
    "\n",
    "\n",
    "bounds = bounds_from_center(50, 50, 20)\n",
    "center = center_from_bounds(*bounds)\n",
    "print(bounds, center)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "754e652d",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "874250b8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:51:50.705529Z",
     "iopub.status.busy": "2026-09-03T00:51:50.705342Z",
     "iopub.status.idle": "2026-09-03T00:51:50.708739Z",
     "shell.execute_reply": "2026-09-03T00:51:50.708112Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Круг — это овал, чей ограничивающий прямоугольник является квадратом.\n"
     ]
    }
   ],
   "source": [
    "assert bounds == (30, 30, 70, 70)\n",
    "assert center == (50.0, 50.0)\n",
    "assert bounds_from_center(0, 0, 10) == (-10, -10, 10, 10)\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
}
