def test_constrain(simple_assy, nested_assy): subassy1 = simple_assy.children[0] subassy2 = simple_assy.children[1] b1 = simple_assy.obj b2 = subassy1.obj b3 = subassy2.obj simple_assy.constrain(simple_assy.name, b1.Faces()[0], subassy1.name, b2.faces("<Z").val(), "Plane") simple_assy.constrain(simple_assy.name, b1.Faces()[0], subassy2.name, b3.faces("<Z").val(), "Axis") simple_assy.constrain( subassy1.name, b2.faces(">Z").val(), subassy2.name, b3.faces("<Z").val(), "Point", ) assert len(simple_assy.constraints) == 3 nested_assy.constrain("TOP@faces@>Z", "SECOND/BOTTOM@faces@<Z", "Plane") nested_assy.constrain("TOP@faces@>X", "SECOND/BOTTOM@faces@<X", "Axis") assert len(nested_assy.constraints) == 2 constraint = nested_assy.constraints[0] assert constraint.objects == ("TOP", "SECOND") assert (constraint.sublocs[0].wrapped.Transformation().TranslationPart(). IsEqual(gp_XYZ(), 1e-9)) assert constraint.sublocs[1].wrapped.IsEqual( nested_assy.objects["SECOND/BOTTOM"].loc.wrapped) simple_assy.solve() assert solve_result_check(simple_assy._solve_result) assert (simple_assy.loc.wrapped.Transformation().TranslationPart().IsEqual( gp_XYZ(2, -5, 0), 1e-9)) assert (simple_assy.children[0].loc.wrapped.Transformation(). TranslationPart().IsEqual(gp_XYZ(-1, 0.5, 0.5), 1e-6)) nested_assy.solve() assert solve_result_check(nested_assy._solve_result) assert (nested_assy.children[0].loc.wrapped.Transformation(). TranslationPart().IsEqual(gp_XYZ(2, -4, 0.75), 1e-6))
def testVectorConstructors(self): v1 = Vector(1, 2, 3) v2 = Vector((1, 2, 3)) v3 = Vector(gp_Vec(1, 2, 3)) v4 = Vector([1, 2, 3]) v5 = Vector(gp_XYZ(1, 2, 3)) for v in [v1, v2, v3, v4, v5]: self.assertTupleAlmostEquals((1, 2, 3), v.toTuple(), 4) v6 = Vector((1, 2)) v7 = Vector([1, 2]) v8 = Vector(1, 2) for v in [v6, v7, v8]: self.assertTupleAlmostEquals((1, 2, 0), v.toTuple(), 4) v9 = Vector() self.assertTupleAlmostEquals((0, 0, 0), v9.toTuple(), 4) v9.x = 1.0 v9.y = 2.0 v9.z = 3.0 self.assertTupleAlmostEquals((1, 2, 3), (v9.x, v9.y, v9.z), 4) with self.assertRaises(TypeError): Vector("vector") with self.assertRaises(TypeError): Vector(1, 2, 3, 4)
def test_PointInPlane_constraint(box_and_vertex): # add first constraint box_and_vertex.constrain( "vertex", box_and_vertex.children[0].obj.val(), "box", box_and_vertex.obj.faces(">X").val(), "PointInPlane", param=0, ) box_and_vertex.solve() x_pos = (box_and_vertex.children[0].loc.wrapped.Transformation(). TranslationPart().X()) assert x_pos == pytest.approx(0.5) # add a second PointInPlane constraint box_and_vertex.constrain("vertex", "box@faces@>Y", "PointInPlane", param=0) box_and_vertex.solve() vertex_translation_part = (box_and_vertex.children[0].loc.wrapped. Transformation().TranslationPart()) # should still be on the >X face from the first constraint assert vertex_translation_part.X() == pytest.approx(0.5) # now should additionally be on the >Y face assert vertex_translation_part.Y() == pytest.approx(1) # add a third PointInPlane constraint box_and_vertex.constrain("vertex", "box@faces@>Z", "PointInPlane", param=0) box_and_vertex.solve() # should now be on the >X and >Y and >Z corner assert (box_and_vertex.children[0].loc.wrapped.Transformation(). TranslationPart().IsEqual(gp_XYZ(0.5, 1, 1.5), 1e-6))
def fixed_point_cost(m1: gp_Pnt, t1: gp_Trsf, val: Tuple[float, float, float]): return (m1.Transformed(t1).XYZ() - gp_XYZ(*val)).Modulus()