Skip to content

Commit 3494d0a

Browse files
authored
Merge pull request #11 from quant-sci/add-docs
feat: add docs with sphinx
2 parents 72da294 + 95040ef commit 3494d0a

16 files changed

Lines changed: 731 additions & 0 deletions

.readthedocs.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Read the Docs configuration
2+
# https://docs.readthedocs.io/en/stable/config-file/v2.html
3+
4+
version: 2
5+
6+
build:
7+
os: ubuntu-24.04
8+
tools:
9+
python: "3.12"
10+
11+
sphinx:
12+
configuration: docs/conf.py
13+
14+
python:
15+
install:
16+
- method: pip
17+
path: .
18+
- requirements: docs/requirements.txt

docs/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Minimal makefile for Sphinx documentation
2+
3+
SPHINXOPTS ?=
4+
SPHINXBUILD ?= sphinx-build
5+
SOURCEDIR = .
6+
BUILDDIR = _build
7+
8+
help:
9+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
10+
11+
.PHONY: help Makefile
12+
13+
# Catch-all target: route unknown targets to sphinx-build.
14+
%: Makefile
15+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/_static/.gitkeep

Whitespace-only changes.

docs/api/algorithms.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Algorithms
2+
==========
3+
4+
Classical computational-geometry algorithms.
5+
6+
Convex hull
7+
-----------
8+
9+
.. automodule:: cgeom.algorithms._convexhull
10+
:members:
11+
:undoc-members:
12+
:show-inheritance:
13+
14+
Delaunay triangulation
15+
----------------------
16+
17+
.. automodule:: cgeom.algorithms._delaunay
18+
:members:
19+
:undoc-members:
20+
:show-inheritance:
21+
22+
Voronoi diagram
23+
---------------
24+
25+
.. automodule:: cgeom.algorithms._voronoi
26+
:members:
27+
:undoc-members:
28+
:show-inheritance:
29+
30+
Minimum enclosing circle
31+
------------------------
32+
33+
.. automodule:: cgeom.algorithms._mincircle
34+
:members:
35+
:undoc-members:
36+
:show-inheritance:
37+
38+
Segment intersection
39+
--------------------
40+
41+
.. automodule:: cgeom.algorithms._intersection
42+
:members:
43+
:undoc-members:
44+
:show-inheritance:
45+
46+
Polygon triangulation
47+
---------------------
48+
49+
.. automodule:: cgeom.algorithms._triangulation
50+
:members:
51+
:undoc-members:
52+
:show-inheritance:

docs/api/elements.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Elements
2+
========
3+
4+
Geometric primitives and the Pydantic input-validation models.
5+
6+
Primitives
7+
----------
8+
9+
.. automodule:: cgeom.elements.elements
10+
:members:
11+
:undoc-members:
12+
:show-inheritance:
13+
14+
Input models
15+
------------
16+
17+
.. automodule:: cgeom.elements.models
18+
:members:
19+
:undoc-members:
20+
:show-inheritance:

docs/api/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# API reference
2+
3+
Auto-generated reference documentation for the `cgeom` package, built from the
4+
in-source docstrings.
5+
6+
```{toctree}
7+
:maxdepth: 2
8+
9+
elements
10+
algorithms
11+
visualization
12+
```

docs/api/visualization.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Visualization
2+
=============
3+
4+
Matplotlib-based plotting helpers, one per algorithm.
5+
6+
.. automodule:: cgeom.visualization._plotting
7+
:members:
8+
:undoc-members:
9+
:show-inheritance:

docs/conf.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""Sphinx configuration for the compute-geometry documentation."""
2+
3+
import os
4+
import sys
5+
from datetime import date
6+
7+
# Make the cgeom package importable for autodoc.
8+
sys.path.insert(0, os.path.abspath(".."))
9+
10+
# -- Project information -----------------------------------------------------
11+
12+
project = "compute-geometry"
13+
author = "Kleyton da Costa"
14+
copyright = f"{date.today().year}, {author}"
15+
16+
# Pull the version straight from the installed package metadata.
17+
try:
18+
from importlib.metadata import version as _version
19+
20+
release = _version("compute-geometry")
21+
except Exception: # pragma: no cover - fallback when not installed
22+
release = "0.1.2"
23+
version = ".".join(release.split(".")[:2])
24+
25+
# -- General configuration ---------------------------------------------------
26+
27+
extensions = [
28+
"sphinx.ext.autodoc",
29+
"sphinx.ext.autosummary",
30+
"sphinx.ext.napoleon",
31+
"sphinx.ext.viewcode",
32+
"sphinx.ext.intersphinx",
33+
"myst_parser",
34+
"sphinx_copybutton",
35+
]
36+
37+
templates_path = ["_templates"]
38+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
39+
40+
source_suffix = {
41+
".rst": "restructuredtext",
42+
".md": "markdown",
43+
}
44+
45+
# -- Autodoc / autosummary ---------------------------------------------------
46+
47+
autosummary_generate = True
48+
autodoc_member_order = "bysource"
49+
autodoc_typehints = "description"
50+
autodoc_default_options = {
51+
"members": True,
52+
"undoc-members": True,
53+
"show-inheritance": True,
54+
}
55+
56+
# Napoleon understands the Google-style docstrings used across the codebase.
57+
napoleon_google_docstring = True
58+
napoleon_numpy_docstring = False
59+
napoleon_include_init_with_doc = True
60+
napoleon_use_rtype = False
61+
62+
# -- Intersphinx -------------------------------------------------------------
63+
64+
intersphinx_mapping = {
65+
"python": ("https://docs.python.org/3", None),
66+
"numpy": ("https://numpy.org/doc/stable/", None),
67+
"matplotlib": ("https://matplotlib.org/stable/", None),
68+
}
69+
70+
# -- MyST --------------------------------------------------------------------
71+
72+
myst_enable_extensions = [
73+
"colon_fence",
74+
"deflist",
75+
"smartquotes",
76+
]
77+
myst_heading_anchors = 3
78+
79+
# -- HTML output (Furo theme) ------------------------------------------------
80+
81+
html_theme = "furo"
82+
html_title = "compute-geometry"
83+
html_static_path = ["_static"]
84+
html_logo = "../public/logo.svg"
85+
html_favicon = "../public/logo.svg"
86+
87+
html_theme_options = {
88+
"sidebar_hide_name": True,
89+
"navigation_with_keys": True,
90+
"source_repository": "https://github.com/kleyt0n/compute-geometry",
91+
"source_branch": "main",
92+
"source_directory": "docs/",
93+
"light_css_variables": {
94+
"color-brand-primary": "#0466c8",
95+
"color-brand-content": "#0466c8",
96+
},
97+
"dark_css_variables": {
98+
"color-brand-primary": "#5b8def",
99+
"color-brand-content": "#5b8def",
100+
},
101+
}

docs/guide/algorithms.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Algorithms
2+
3+
The `cgeom.algorithms` module bundles classical computational-geometry
4+
algorithms. Each is a class constructed from a set of points (or segments) and
5+
validated through the matching Pydantic input model.
6+
7+
```python
8+
from cgeom.algorithms import (
9+
ConvexHull,
10+
DelaunayTriangulation,
11+
VoronoiDiagram,
12+
MinimumCircle,
13+
SegmentIntersection,
14+
PolygonTriangulation,
15+
)
16+
```
17+
18+
## ConvexHull
19+
20+
Computes the convex hull of a point set with the Gift Wrapping (Jarvis march)
21+
algorithm.
22+
23+
```python
24+
points = [(326, 237), (373, 209), (378, 265), (443, 241),
25+
(396, 231), (416, 270), (361, 335), (324, 297)]
26+
27+
hull = ConvexHull(points)
28+
hull.convex_hull() # ordered hull vertices [[x, y], ...]
29+
hull.get_indexes() # indices of the input points on the hull
30+
```
31+
32+
Construction requires at least 3 non-collinear points.
33+
34+
## DelaunayTriangulation
35+
36+
Builds the Delaunay triangulation of a point set.
37+
38+
```python
39+
dt = DelaunayTriangulation(points)
40+
dt.triangulate() # list of index triples
41+
dt.get_edges() # unique edges
42+
dt.get_circumcircles() # circumcircle of each triangle
43+
```
44+
45+
## VoronoiDiagram
46+
47+
Builds the Voronoi diagram — the dual of the Delaunay triangulation.
48+
49+
```python
50+
import numpy as np
51+
52+
points = np.loadtxt("examples/points1.txt")
53+
voronoi = VoronoiDiagram(points)
54+
cells = voronoi.build_voronoi_diagram()
55+
```
56+
57+
## MinimumCircle
58+
59+
Finds the smallest enclosing circle of a point set.
60+
61+
```python
62+
mc = MinimumCircle()
63+
mc.minimum_circle([(0, 0), (1, 0), (0, 1), (1, 1)]) # [[cx, cy], radius]
64+
```
65+
66+
## SegmentIntersection
67+
68+
Reports all pairwise intersections of a set of segments. The primary method uses
69+
the Bentley–Ottmann sweep-line algorithm; a brute-force method is provided for
70+
verification.
71+
72+
```python
73+
segments = [
74+
[[0, 0], [4, 4]],
75+
[[0, 4], [4, 0]],
76+
[[0, 2], [4, 2]],
77+
[[2, 0], [2, 4]],
78+
]
79+
80+
si = SegmentIntersection(segments)
81+
si.find_intersections() # sweep line
82+
si.find_intersections_brute_force() # verification
83+
si.get_intersection_pairs() # (i, j, point) tuples
84+
```
85+
86+
## PolygonTriangulation
87+
88+
Triangulates a simple polygon.
89+
90+
```python
91+
pt = PolygonTriangulation([[0, 0], [4, 0], [4, 4], [0, 4]])
92+
pt.triangulate()
93+
```
94+
95+
## Input validation
96+
97+
Every algorithm validates its input through a Pydantic model in
98+
`cgeom.elements.models` (for example, `ConvexHullInput`,
99+
`DelaunayTriangulationInput`). Invalid input — wrong shape, non-numeric values,
100+
too few points, or degenerate configurations — raises
101+
`pydantic.ValidationError` at construction time.
102+
103+
See the [API reference](../api/algorithms) for full signatures.

0 commit comments

Comments
 (0)