Skip to content

Commit

Permalink
Merge pull request #18 from Yatoom/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Yatoom authored Apr 6, 2021
2 parents b048606 + a39b4c8 commit bbd5b2e
Show file tree
Hide file tree
Showing 34 changed files with 1,139 additions and 171 deletions.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
9 changes: 9 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
==============
Public classes
==============

.. toctree::
:maxdepth: 2
:glob:

public/*
64 changes: 64 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
import sphinx_rtd_theme
import numpydoc


# -- Project information -----------------------------------------------------

project = 'Foronoi'
copyright = '2021, Jeroen van Hoof'
author = 'Jeroen van Hoof'

# The full version, including alpha/beta/rc tags
release = '1.0.0'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx_rtd_theme',
'sphinx.ext.napoleon',
'sphinx.ext.intersphinx',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']


autoclass_content = 'both'
48 changes: 48 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.. Foronoi documentation master file, created by
sphinx-quickstart on Sun Apr 4 20:32:46 2021.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to Foronoi's documentation!
===================================

Foronoi is a Python implementation of the Fortune's algorithm based on the description of "Computational Geometry:
Algorithms and Applications" by de Berg et al.

This algorithm is a sweep line algorithm that scans top down over the
cell points and traces out the lines via breakpoints in between parabola's (arcs). Once a new point is inserted, a check
is done to see if it will converge with the lines on the left or right. If that's the case, it will insert a so-called
circle-event which causes a new vertex (i.e. a cross-way between edges) to be created in the middle of the circle.

The algorithm keeps track of the status (everything above the line is handled) in a so-called status-structure. This
status-structure is a balanced binary search tree that keeps track of the positions of the arcs (in its leaf nodes) and
the breakpoints (in its internal nodes). This data structure allows for fast look-up times, so that the entire
algorithm can run in `O(n log n)` time.

This implementation includes some additional features to the standard algorithm. For example, this implementation is
able to clip the diagram to a bounding box in different shapes. And it will clean up zero-length edges that occur in
edge-cases where two events happen at the same time so that it is more practical to use.


.. image:: ../voronoi.gif
:width: 800
:alt: Voronoi diagram under construction

Table of contents
+++++++++++++++++

.. toctree::
:maxdepth: 2
:glob:

installation
api
private


Indices and tables
++++++++++++++++++

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
12 changes: 12 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Installation
===================

Manual
++++++
First, clone the repository and then install the package.

.. code-block:: bash
git clone https://github.com/Yatoom/voronoi.git
cd voronoi
python setup.py install
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
9 changes: 9 additions & 0 deletions docs/private.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
==============
Private classes
==============

.. toctree::
:maxdepth: 2
:glob:

private/*
6 changes: 6 additions & 0 deletions docs/private/arc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _arc:

Arc
=========
.. autoclass:: voronoi.nodes.Arc
:members:
7 changes: 7 additions & 0 deletions docs/public/algorithm.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _algorithm:

Algorithm
=========
.. autoclass:: voronoi.algorithm.Algorithm
:members:

7 changes: 7 additions & 0 deletions docs/public/coordinate.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _coordinate:

Coordinate
==========
.. autoclass:: voronoi.graph.Coordinate
:members:

6 changes: 6 additions & 0 deletions docs/public/half_edge.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _halfedge:

HalfEdge
=========
.. autoclass:: voronoi.graph.HalfEdge
:members:
6 changes: 6 additions & 0 deletions docs/public/point.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _point:

Point
=========
.. autoclass:: voronoi.graph.Point
:members:
6 changes: 6 additions & 0 deletions docs/public/polygon.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _polygon:

Polygon
=======
.. autoclass:: voronoi.graph.Polygon
:members:
6 changes: 6 additions & 0 deletions docs/public/vertex.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _vertex:

Vertex
=========
.. autoclass:: voronoi.graph.Vertex
:members:
6 changes: 6 additions & 0 deletions docs/public/visualization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _visualization:

Visualizer
==========
.. automodule:: voronoi.visualization.visualizer
:members:
6 changes: 6 additions & 0 deletions docs/public/voronoi.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _vertex:

Voronoi
=========
.. autoclass:: voronoi.Voronoi
:members:
2 changes: 1 addition & 1 deletion examples/bounding_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@

# Visualize the tree
TreeVisualizer() \
.plot(v.beach_line) \
.plot(v.status_tree) \
.render("output/tree.dot", view=True)
3 changes: 2 additions & 1 deletion examples/observers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

# Callback that saves the figure every step
# If no callback is provided, it will simply display the figure in a matplotlib window
callback=lambda observer, figure: figure.savefig(f"output/voronoi/{observer.n_messages:02d}.png")
callback=lambda observer, figure: figure.savefig(f"output/voronoi/{observer.n_messages:02d}.png"),
visualize_before_clipping=True
)
)

Expand Down
41 changes: 41 additions & 0 deletions examples/profiling_performance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from voronoi import Voronoi, Polygon
import cProfile
import pstats


def profiler(command, filename="profile.stats", n_stats=20):
"""Profiler for a python program
Runs cProfile and outputs ordered statistics that describe
how often and for how long various parts of the program are executed.
Parameters
----------
command: str
Command string to be executed.
filename: str
Name under which to store the stats.
n_stats: int or None
Number of top stats to show.
"""

cProfile.run(command, filename)
stats = pstats.Stats(filename).strip_dirs().sort_stats("cumtime")
return stats.print_stats(n_stats or {})


# Define some points (a.k.a sites or cell points)
points = [
(2.5, 2.5), (4, 7.5), (7.5, 2.5), (6, 7.5), (4, 4), (3, 3), (6, 3)
]

# Define a bounding box / polygon
polygon = Polygon([
(2.5, 10), (5, 10), (10, 5), (10, 2.5), (5, 0), (2.5, 0), (0, 2.5), (0, 5)
])

# Initialize the algorithm
v = Voronoi(polygon)

# Profile the construction of the voronoi diagram
profiler('v.create_diagram(points=points)')
Loading

0 comments on commit bbd5b2e

Please sign in to comment.