Construct a constraint. :param objects: object names referenced in the constraint :param args: subshapes (e.g. faces or edges) of the objects :param sublocs: locations of the objects (only relevant if the objects are nested in a sub-assembly) :param kind: co
(
self,
objects: Tuple[str, ...],
args: Tuple[Shape, ...],
sublocs: Tuple[Location, ...],
kind: ConstraintKind,
param: Any = None,
)
| 113 | param: Any |
| 114 | |
| 115 | def __init__( |
| 116 | self, |
| 117 | objects: Tuple[str, ...], |
| 118 | args: Tuple[Shape, ...], |
| 119 | sublocs: Tuple[Location, ...], |
| 120 | kind: ConstraintKind, |
| 121 | param: Any = None, |
| 122 | ): |
| 123 | """ |
| 124 | Construct a constraint. |
| 125 | |
| 126 | :param objects: object names referenced in the constraint |
| 127 | :param args: subshapes (e.g. faces or edges) of the objects |
| 128 | :param sublocs: locations of the objects (only relevant if the objects are nested in a sub-assembly) |
| 129 | :param kind: constraint kind |
| 130 | :param param: optional arbitrary parameter passed to the solver |
| 131 | """ |
| 132 | |
| 133 | # validate |
| 134 | if not instance_of(kind, ConstraintKind): |
| 135 | raise ValueError(f"Unknown constraint {kind}.") |
| 136 | |
| 137 | if kind in CompoundConstraints: |
| 138 | kinds, convert_compound = CompoundConstraints[kind] |
| 139 | for k, p in zip(kinds, convert_compound(param)): |
| 140 | self._validate(args, k, p) |
| 141 | else: |
| 142 | self._validate(args, kind, param) |
| 143 | |
| 144 | # convert here for simple constraints |
| 145 | convert = ConstraintInvariants[kind][-1] |
| 146 | param = convert(param) if convert else param |
| 147 | |
| 148 | # store |
| 149 | self.objects = objects |
| 150 | self.args = args |
| 151 | self.sublocs = sublocs |
| 152 | self.kind = kind |
| 153 | self.param = param |
| 154 | |
| 155 | def _validate(self, args: Tuple[Shape, ...], kind: ConstraintKind, param: Any): |
| 156 |
nothing calls this directly
no test coverage detected