コード例 #1
0
 def apply(self, edge: Edge) -> bool:
     if try_set_relation(
             edge,
             FixedEdgeLengthVertexRelation(edge.v1, edge.v2, self.length)):
         edge.constraint = EdgeConstraint.FIXED_LENGTH
         return True
     return False
コード例 #2
0
    def apply(self, edge: Edge) -> bool:
        if [
                rel for rel in edge.v1.relations
                if rel.constraint == EdgeConstraint.HORIZONTAL
        ]:
            return False
        if [
                rel for rel in edge.v2.relations
                if rel.constraint == EdgeConstraint.HORIZONTAL
        ]:
            return False

        if try_set_relation(edge,
                            HorizontalEdgeVertexRelation(edge.v1, edge.v2)):
            edge.constraint = EdgeConstraint.HORIZONTAL
            return True
        return False
コード例 #3
0
    def apply(self, edge: Edge) -> bool:
        if not edge.constraint:
            return True

        matching_relations = [
            rel for rel in edge.v1.relations
            if rel.constraint == edge.constraint
        ]
        removed = [
            rel for rel in edge.v2.relations if rel in matching_relations
        ]
        if len(removed) != 1:
            return False

        edge.v1.relations.remove(removed[0])
        edge.v2.relations.remove(removed[0])

        edge.constraint = None
        return True