gaphas/docs/constraints.rst
Dan Yeaw 84aeb6c80b
Update docs: rerun quickstart, rename txt to rst, add requirements.txt
- Rename all .txt doc files to .rst to make it more clear that they are
  restructured text.
- Add requirements.txt for Sphinx
- Rerun sphinx-quickstart to make compatible with the latest Sphinx
  version.
- Fix module names from gaphor to gaphas
- Fix warnings about incorrect indent following :mod: lines
- Fix TypeError for class Segmant: function object has no attribute
  '__mro__'

Signed-off-by: Dan Yeaw <dan@yeaw.me>
2018-12-28 17:07:07 -05:00

63 lines
2.0 KiB
ReStructuredText

Constraints
===========
Introduction
------------
There are problems related to canvas items, which can be solved in
`declarative way <http://en.wikipedia.org/wiki/Declarative_programming>`_
allowing for simpler and less error prone implementation of canvas item.
For example, if an item should be a rectangle, then it could be declared
that
- bottom-right vertex should be below and on the right side of top-left
vertex
- two top rectangle vertices should be always at the same y-axis
- two left rectangle vertices should be always at the same x-axis
- ...
Above rules are constraints, which need to be applied to a rectangular
item. The rules can be satisfied (constraints can be solved) using
`constraint solver <http://en.wikipedia.org/wiki/Constraint_satisfaction_problem>`_.
Gaphas implements its own constraint solver (`gaphas.solver` module).
Items can be constrained using APIs defined in `Canvas` and `Item` classes.
Constraints API
---------------
The `Canvas` class constraints API supports adding a constraint to
constraint solver. Instance of a constraint has to be created and then
added using `Canvas.add_constraint` method. For example, it allows to
declare that two variables should be equal.
The `Item` class constraint API is more abstract, it allows to constraint
positions, i.e.
- positions of two item handles should be on the same x-axis
- position should be always on a line
If this API does not provide some constraint declaration, then one can
fallback to `Canvas` class constraint API.
Examples
--------
Item API
^^^^^^^^
Canvas API
^^^^^^^^^^
Further Reading
---------------
Theory and examples related to constraint solving
- http://en.wikipedia.org/wiki/Declarative_programming
- http://en.wikipedia.org/wiki/Constraint_satisfaction_problem
- http://norvig.com/sudoku.html
There are other projects providing constraint solvers
- http://adaptagrams.sourceforge.net/
- http://minion.sourceforge.net/
- http://labix.org/python-constraint
- http://www.cs.washington.edu/research/constraints/cassowary/