{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# 03. Topological Queries and Relationships\n\nExplore the boundary of a box and ask which faces touch one of its edges.\n\n**Goal:** Complete one small workflow. Run the cells from top to bottom in a fresh kernel.\n\n**Extra dependencies:** None beyond the base environment.\n\nAll examples use metres unless stated otherwise.\n",
   "id": "tutorial-03-00"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "import os\nos.environ[\"TOPOLOGICPY_CORE_BACKEND\"] = \"pythonocc\"\n\nimport topologicpy\nfrom topologicpy.Core import Core\n\nassert topologicpy.__version__ == \"0.9.86\", \"Use TopologicPy 0.9.86 for these tutorials.\"\nassert type(Core.Backend()).__name__ == \"PythonOCCBackend\", \"Restart with the pythonocc backend.\"\nprint(\"TopologicPy\", topologicpy.__version__, \"—\", type(Core.Backend()).__name__)\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-03-01"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Traverse a topology\n\nA solid contains faces, edges and vertices. Query these objects instead of assuming their internal order.\n",
   "id": "tutorial-03-02"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "from topologicpy.Cell import Cell\nfrom topologicpy.Topology import Topology\n\nbox = Cell.Prism(width=4, length=3, height=2)\nfaces = Topology.Faces(box)\nedges = Topology.Edges(box)\nvertices = Topology.Vertices(box)\nprint(\"Faces, edges, vertices:\", len(faces), len(edges), len(vertices))\nassert [len(faces), len(edges), len(vertices)] == [6, 12, 8]\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-03-03"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Ask about incidence\n\nThe host topology supplies the context for an adjacency query. Each boundary edge of this closed box belongs to two faces.\n",
   "id": "tutorial-03-04"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "edge = edges[0]\ntouching_faces = Topology.AdjacentTopologies(edge, box, topologyType=\"Face\")\nprint(\"Faces incident to the selected edge:\", len(touching_faces))\nprint(\"Euler characteristic:\", len(vertices) - len(edges) + len(faces))\nassert len(touching_faces) == 2\nassert len(vertices) - len(edges) + len(faces) == 2\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-03-05"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Try it yourself\n\nRepeat the query for a vertex: how many faces meet there?\n",
   "id": "tutorial-03-06"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (TopologicPy tutorials)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
