added LeftHandedConstraint, RightHandedConstraint etc. Small bugfixes.
This commit is contained in:
parent
99b304c882
commit
fd0438c86d
|
@ -13,6 +13,7 @@ from notify import Notifier, Listener
|
||||||
from tolerance import tol_eq
|
from tolerance import tol_eq
|
||||||
from intersections import angle_3p, distance_2p
|
from intersections import angle_3p, distance_2p
|
||||||
from selconstr import SelectionConstraint
|
from selconstr import SelectionConstraint
|
||||||
|
from geosolver.intersections import is_left_handed, is_right_handed
|
||||||
|
|
||||||
# ----------- GeometricProblem -------------
|
# ----------- GeometricProblem -------------
|
||||||
|
|
||||||
|
@ -348,7 +349,7 @@ class GeometricSolver (Listener):
|
||||||
parent.subs.append(map[inp])
|
parent.subs.append(map[inp])
|
||||||
|
|
||||||
# combine clusters due to selection
|
# combine clusters due to selection
|
||||||
if False:
|
if True:
|
||||||
for method in self.dr.methods():
|
for method in self.dr.methods():
|
||||||
if isinstance(method, PrototypeMethod):
|
if isinstance(method, PrototypeMethod):
|
||||||
incluster = method.inputs()[0]
|
incluster = method.inputs()[0]
|
||||||
|
@ -837,3 +838,26 @@ class RigidConstraint(ParametricConstraint):
|
||||||
return "RigidConstraint("+str(self._variables)+")"
|
return "RigidConstraint("+str(self._variables)+")"
|
||||||
|
|
||||||
|
|
||||||
|
class RightHandedConstraint (SelectionConstraint):
|
||||||
|
"""A selection constraint for 4 points to have a right-handed orientation"""
|
||||||
|
def __init__(self, v1, v2, v3, v4):
|
||||||
|
SelectionConstraint.__init__(self, is_right_handed, [v1,v2,v3,v4])
|
||||||
|
|
||||||
|
|
||||||
|
class LeftHandedConstraint (SelectionConstraint):
|
||||||
|
"""A selection constraint for 4 points to have a left-handed orientation"""
|
||||||
|
def __init__(self, v1, v2, v3, v4):
|
||||||
|
SelectionConstraint.__init__(self, is_left_handed, [v1,v2,v3,v4])
|
||||||
|
|
||||||
|
class NotRightHandedConstraint (SelectionConstraint):
|
||||||
|
"""A selection constraint for 4 points to not have a left-handed orientation, i.e. right-handed or in-plane"""
|
||||||
|
def __init__(self, v1, v2, v3, v4):
|
||||||
|
SelectionConstraint.__init__(self, fnot(is_right_handed), [v1,v2,v3,v4])
|
||||||
|
|
||||||
|
class NotLeftHandedConstraint (SelectionConstraint):
|
||||||
|
"""A selection constraint for 4 points to not have a left-handed orientation, i.e. right-handed or in-plane"""
|
||||||
|
def __init__(self, v1, v2, v3, v4):
|
||||||
|
SelectionConstraint.__init__(self, fnot(is_left_handed), [v1,v2,v3,v4])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
17
test/test.py
17
test/test.py
|
@ -6,7 +6,6 @@ from geosolver.vector import vector
|
||||||
from geosolver.randomproblem import *
|
from geosolver.randomproblem import *
|
||||||
from geosolver.diagnostic import diag_select, diag_print
|
from geosolver.diagnostic import diag_select, diag_print
|
||||||
from geosolver.selconstr import fnot
|
from geosolver.selconstr import fnot
|
||||||
from geosolver.intersections import is_left_handed, is_right_handed
|
|
||||||
import geosolver.tolerance as tolerance
|
import geosolver.tolerance as tolerance
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
@ -481,8 +480,8 @@ def selection_problem():
|
||||||
problem.add_constraint(DistanceConstraint('v2', 'v5', 10.0))
|
problem.add_constraint(DistanceConstraint('v2', 'v5', 10.0))
|
||||||
problem.add_constraint(DistanceConstraint('v3', 'v5', 10.0))
|
problem.add_constraint(DistanceConstraint('v3', 'v5', 10.0))
|
||||||
|
|
||||||
problem.add_constraint(SelectionConstraint(is_left_handed, ['v1','v2','v3','v4']))
|
#problem.add_constraint(SelectionConstraint(is_right_handed, ['v1','v2','v4','v5']))
|
||||||
problem.add_constraint(SelectionConstraint(is_right_handed, ['v1','v2','v4','v5']))
|
problem.add_constraint(RightHandedConstraint('v1','v2','v4','v5'))
|
||||||
|
|
||||||
return problem
|
return problem
|
||||||
|
|
||||||
|
@ -742,9 +741,9 @@ def test(problem, use_prototype=True):
|
||||||
print problem
|
print problem
|
||||||
solver = GeometricSolver(problem, use_prototype)
|
solver = GeometricSolver(problem, use_prototype)
|
||||||
#solver.set_prototype_selection(use_prototype)
|
#solver.set_prototype_selection(use_prototype)
|
||||||
print "drplan:"
|
#print "drplan:"
|
||||||
print solver.dr
|
#print solver.dr
|
||||||
print "number of top-level rigids:",len(solver.dr.top_level())
|
#print "number of top-level rigids:",len(solver.dr.top_level())
|
||||||
result = solver.get_result()
|
result = solver.get_result()
|
||||||
print "result:"
|
print "result:"
|
||||||
print result
|
print result
|
||||||
|
@ -885,21 +884,21 @@ def selection_test():
|
||||||
print len(solver.get_solutions()), "solutions"
|
print len(solver.get_solutions()), "solutions"
|
||||||
|
|
||||||
# remove and add constraint
|
# remove and add constraint
|
||||||
print "removing s1"
|
print "removing selection-constraint"
|
||||||
problem.rem_constraint(s1)
|
problem.rem_constraint(s1)
|
||||||
|
|
||||||
# solve again
|
# solve again
|
||||||
print len(solver.get_solutions()), "solutions"
|
print len(solver.get_solutions()), "solutions"
|
||||||
|
|
||||||
# remove and add constraint
|
# remove and add constraint
|
||||||
print "adding s1"
|
print "re-adding selection constraint"
|
||||||
problem.add_constraint(s1)
|
problem.add_constraint(s1)
|
||||||
|
|
||||||
# solve again
|
# solve again
|
||||||
print len(solver.get_solutions()), "solutions"
|
print len(solver.get_solutions()), "solutions"
|
||||||
|
|
||||||
# remove distance
|
# remove distance
|
||||||
print "removing and re-adding d15"
|
print "removing and re-adding distance v1-v5"
|
||||||
problem.rem_constraint(problem.get_distance("v1","v5"))
|
problem.rem_constraint(problem.get_distance("v1","v5"))
|
||||||
problem.add_constraint(DistanceConstraint('v1', 'v5', 10.0))
|
problem.add_constraint(DistanceConstraint('v1', 'v5', 10.0))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user