Variables and Position¶
The most basic class for a solvable value is Variable. It acts a lot like a float, which makes
it easy to work with.
Next to that there’s Position, which is a coordinate (x, y) defined by two variables.
To support connections between variables, a MatrixProjection class is available. It translates
a position to a common coordinate space, based on Item.matrix_i2c. Normally, it’s only Ports that
deal with item-to-common translation of positions.
- class gaphas.solver.Variable(value: SupportsFloat = 0.0, strength: int = 20)[source]¶
Representation of a variable in the constraint solver.
Each Variable has a
valueand astrength. In a constraint the weakest variables are changed.You can even do some calculating with it. The Variable always represents a float variable.
The
variabledecorator can be used to easily define variables in classes.- add_handler(handler: Callable[[Variable, float], None]) None[source]¶
Add a handler, to be invoked when the value changes.
- property strength: int¶
Strength.
Variables can have different strengths. The higher the number, the stronger the variable.
Variables can be VERY_WEAK (0), up to REQUIRED (100).
Other constants are
WEAK (10)
NORMAL (20)
STRONG (30), and
VERY_STRONG (40).
- gaphas.solver.variable(strength=20, varname=None)[source]¶
Easy-to-use drop Variable descriptor.
>>> class A(object): ... x = variable(varname='_v_x') ... y = variable(STRONG) ... def __init__(self): ... self.x = 12 >>> a = A() >>> a.x Variable(12, 20) >>> a._v_x Variable(12, 20) >>> a.x = 3 >>> a.x Variable(3, 20) >>> a.y Variable(0, 30)