When constraints depend on one another, they must be updated in a specific order to prevent circular dependencies and ensure correct transformations. The system uses a recursive update pattern with a pending set to detect cycles.
Dependency Update Algorithm
To update a constraint, the system checks if it has already been processed. If not, it recursively updates all of its dependencies before processing the constraint itself. If a constraint is encountered that is already in the pending set, a circular dependency error is thrown.
let constraintsPending = empty set of Constraint
let constraintsDone = empty set of Constraint
function updateConstraint( constraint )
if not constraintsDone.has( constraint ) then
if constraintPending.has( constraint ) then
throw "Circular dependency detected"
end if
constraintsPending.add( constraint )
foreach dependency in constraint.dependencies do
updateConstraint( dependency )
end foreach
constraintsPending.delete( constraint )
process constraint
constraintsDone.add( constraint )
end if
end function
function updateConstraints
foreach constraint in constraints do
updateConstraint( constraint )
end foreach
end function