{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# 01. Basics\n\nCreate a point and a line, then inspect their types. The first cell explicitly selects pythonocc: it fails if the requested backend is unavailable, rather than silently using another kernel.\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-01-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-01-01"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Make two vertices and an edge\n\nA vertex represents a point. An edge connects two distinct vertices. Use the TopologicPy classes rather than importing a kernel directly.\n",
   "id": "tutorial-01-02"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "from topologicpy.Vertex import Vertex\nfrom topologicpy.Edge import Edge\nfrom topologicpy.Topology import Topology\n\nstart = Vertex.ByCoordinates(0, 0, 0)\nend = Vertex.ByCoordinates(3, 4, 0)\nedge = Edge.ByVertices([start, end])\n\nprint(\"Start:\", Vertex.Coordinates(start))\nprint(\"Type:\", Topology.TypeAsString(edge))\nprint(\"Length:\", Edge.Length(edge))\nassert Edge.Length(edge) == 5\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-01-03"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Tolerances and common errors\n\nA tolerance is a distance used when comparing geometry. Points closer than the tolerance may be treated as coincident. Avoid zero-length edges, use consistent units, and check returned objects before continuing. A version or backend assertion above usually means the wrong notebook kernel is selected.\n",
   "id": "tutorial-01-04"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "tolerance = 0.0001\nnearby = Vertex.ByCoordinates(0.00001, 0, 0)\ndistance = Vertex.Distance(start, nearby)\nprint(\"Within tolerance:\", distance < tolerance)\nassert Topology.IsInstance(edge, \"Edge\")\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-01-05"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Try it yourself\n\nChange the end point and predict the new edge length before running the cell.\n",
   "id": "tutorial-01-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
}
