Skip to content

Commit

Permalink
Refactored constraint addition logic in preparation for adding cluste…
Browse files Browse the repository at this point in the history
…r merge capability
  • Loading branch information
mlauer154 committed Feb 7, 2024
1 parent 52e6b96 commit 6c20422
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 226 deletions.
16 changes: 8 additions & 8 deletions pymead/core/constraint_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,32 +439,32 @@ def analyze(self, constraint: GeoCon):
for cnstr in point.geo_cons:
if isinstance(cnstr, DistanceConstraint) or isinstance(cnstr, DistanceConstraintWeak):
start_point = point
vertex = cnstr.p2 if cnstr.p2 is not point else cnstr.p1
p2 = cnstr.p2 if cnstr.p2 is not point else cnstr.p1
end_point = None

for sub_cnstr in vertex.geo_cons:
for sub_cnstr in p2.geo_cons:
if sub_cnstr is cnstr:
continue
if isinstance(sub_cnstr, RelAngle3Constraint) or isinstance(sub_cnstr, RelAngle3ConstraintWeak):
end_point = sub_cnstr.start_point
end_point = sub_cnstr.p1
elif (isinstance(sub_cnstr, Perp3Constraint) or isinstance(sub_cnstr, Parallel3Constraint) or
isinstance(sub_cnstr, AntiParallel3Constraint)):
end_point = sub_cnstr.p1
if end_point is not None:
rel_angle3_constraint_weak = RelAngle3ConstraintWeak(start_point, vertex, end_point, "ra3")
rel_angle3_constraint_weak = RelAngle3ConstraintWeak(start_point, p2, end_point, "ra3")
weak_constraints.append(rel_angle3_constraint_weak)
dof -= 1
break

for sub_cnstr in vertex.geo_cons:
for sub_cnstr in p2.geo_cons:
if sub_cnstr is cnstr:
continue

if isinstance(sub_cnstr, DistanceConstraint) or isinstance(sub_cnstr, DistanceConstraintWeak):
end_point = sub_cnstr.p1 if sub_cnstr.p1 not in [start_point, vertex] else sub_cnstr.p2
end_point = sub_cnstr.p1 if sub_cnstr.p1 not in [start_point, p2] else sub_cnstr.p2

if end_point is not None:
rel_angle3_constraint_weak = RelAngle3ConstraintWeak(start_point, vertex, end_point, "ra3")
rel_angle3_constraint_weak = RelAngle3ConstraintWeak(start_point, p2, end_point, "ra3")
weak_constraints.append(rel_angle3_constraint_weak)
dof -= 1
break
Expand All @@ -484,7 +484,7 @@ def analyze(self, constraint: GeoCon):
end_point = candidate_points[0]
abs_angle_constraint = AbsAngleConstraintWeak(start_point, end_point, "aa1")
weak_constraints.append(abs_angle_constraint)
# print(f"{abs_angle_constraint = }, {start_point = }, {end_point = }")
# print(f"{abs_angle_constraint = }, {p1 = }, {p3 = }")

weak_equations = []
for cnstr in weak_constraints:
Expand Down
14 changes: 7 additions & 7 deletions pymead/core/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,19 @@ class RelAngle3Constraint(GeoCon):

default_name = "RelAng3Con-1"

def __init__(self, start_point: Point, vertex: Point, end_point: Point, value: float or AngleParam, name: str = None):
self.start_point = start_point
self.vertex = vertex
self.end_point = end_point
def __init__(self, p1: Point, p2: Point, p3: Point, value: float or AngleParam, name: str = None):
self.p1 = p1
self.p2 = p2
self.p3 = p3
param = value if isinstance(value, Param) else AngleParam(value=value, name="unnamed")
super().__init__(param=param, name=name, child_nodes=[self.start_point, self.vertex, self.end_point], kind="a3")
super().__init__(param=param, name=name, child_nodes=[self.p1, self.p2, self.p3], kind="a3")

def __repr__(self):
return f"{self.__class__.__name__} {self.name()}<v={self.param().value()}>"

def get_dict_rep(self) -> dict:
return {"start_point": self.start_point.name(), "vertex": self.vertex.name(),
"end_point": self.end_point.name(), "value": self.param().name(),
return {"p1": self.p1.name(), "p2": self.p2.name(),
"p3": self.p3.name(), "value": self.param().name(),
"constraint_type": self.__class__.__name__}


Expand Down
Loading

0 comments on commit 6c20422

Please sign in to comment.