Package gaphas :: Module constraint

Module constraint

source code

This module contains several flavors of constraint classes. Each has a method Constraint.solve_for(name) and a method Constraint.mark_dirty(v). These methods are used by the constraint solver (solver.Solver) to set the variables.

Variables should be of type solver.Variable.

See classes' documentation below for constraints description and for examples of their usage.

EqualsConstraint
Make 'a' and 'b' equal.
LessThanConstraint
Ensure one variable stays smaller than the other.
CenterConstraint
Ensures a Variable is kept between two other variables.
EquationConstraint
Solve a linear equation.
BalanceConstraint
Keeps three variables in line, maintaining a specific ratio.
LineConstraint
Solves the equation where a line is connected to a line or side at a specific point.

New constraint class should derive from Constraint class abstract class and implement Constraint.solve_for(Variable) method to update a variable with appropriate value.


Version: $Revision: 1794 $

Classes
  Constraint
Constraint base class.
  EqualsConstraint
Constraint, which ensures that two arguments a and b are equal, for example >>> from solver import Variable >>> a, b = Variable(1.0), Variable(2.0) >>> eq = EqualsConstraint(a, b) >>> eq.solve_for(a) >>> a Variable(2, 20) >>> a.value = 10.8 >>> eq.solve_for(b) >>> b Variable(10.8, 20)
  CenterConstraint
Simple Constraint, takes three arguments: 'a', 'b' and center.
  LessThanConstraint
Ensure smaller is less than bigger.
  EquationConstraint
Equation solver using attributes and introspection.
  BalanceConstraint
Ensure that a variable v is between values specified by band and in distance proportional from band[0].
  LineConstraint
Ensure a point is kept on a line.
Variables
  EPSILON = 1e-006
  ITERLIMIT = 1000