def test_conditional_solid_reconstruction_parameters(self): """tests that a new cadquery solid with a new unique hash is created when the shape properties of points, radius or distance are changed""" # points test_shape = paramak.ExtrudeCircleShape(points=[(30, 0)], radius=5, distance=20) test_shape.solid initial_hash_value = test_shape.hash_value test_shape.points = [(40, 0)] test_shape.solid assert test_shape.solid is not None assert test_shape.hash_value != initial_hash_value # radius test_shape = paramak.ExtrudeCircleShape(points=[(30, 0)], radius=5, distance=20) test_shape.solid initial_hash_value = test_shape.hash_value test_shape.radius = 10 test_shape.solid assert test_shape.solid is not None assert test_shape.hash_value != initial_hash_value # distance test_shape = paramak.ExtrudeCircleShape(points=[(30, 0)], radius=5, distance=20) test_shape.solid initial_hash_value = test_shape.hash_value test_shape.distance = 30 test_shape.solid assert test_shape.solid is not None assert test_shape.hash_value != initial_hash_value
def test_stl_filename_duplication_Extrude_Circle(): """checks ValueError is raised when ExtrudeCircleShapes with duplicate stl filenames are added""" test_shape = paramak.ExtrudeCircleShape( points=[(20, 20)], radius=10, distance=10, stl_filename="filename.stl" ) test_shape2 = paramak.ExtrudeCircleShape( points=[(20, 20)], radius=10, distance=10, stl_filename="filename.stl" ) test_shape.rotation_angle = 360 test_shape.create_solid() my_reactor = paramak.Reactor([test_shape, test_shape2]) my_reactor.export_stl()
def test_stl_filename_None(): test_shape = paramak.ExtrudeCircleShape(points=[(20, 20)], radius=10, distance=10, stl_filename=None) my_reactor = paramak.Reactor([test_shape]) my_reactor.export_stl()
def test_cut_modification(self): """Creates a BlanketCutterParallels parametric component and with another shape cut out and checks that a solid can be produced.""" cut_shape = paramak.ExtrudeCircleShape(1, 1, points=[(0, 0)]) self.test_shape.cut = cut_shape assert self.test_shape.solid is not None
def test_extruded_shape_relative_volume(self): """creates two extruded shapes with different placement angles using \ circles and checks their relative volumes are correct""" test_shape1 = paramak.ExtrudeCircleShape(points=[(30, 0)], radius=10, distance=20, azimuth_placement_angle=0) test_shape2 = paramak.ExtrudeCircleShape( points=[(30, 0)], radius=10, distance=20, azimuth_placement_angle=[0, 90, 180, 270], ) assert test_shape1.volume * 4 == pytest.approx(test_shape2.volume)
def test_absolute_shape_volume(self): """creates extruded shapes using circles and checks the volumes are correct""" test_shape = paramak.ExtrudeCircleShape(points=[(30, 0)], radius=10, distance=20) test_shape.create_solid() assert test_shape.solid is not None assert test_shape.volume == pytest.approx(math.pi * 10**2 * 20) test_shape2 = paramak.ExtrudeCircleShape(points=[(30, 0)], radius=10, distance=10) test_shape2.create_solid() assert test_shape2.solid is not None assert 2 * test_shape2.volume == pytest.approx(test_shape.volume)
def test_initial_solid_construction(self): """tests that a cadquery solid with a unique hash is constructed when .solid is called""" test_shape = paramak.ExtrudeCircleShape(points=[(0, 0), (0, 20), (20, 20), (20, 0)], radius=10, distance=20) assert test_shape.hash_value is None assert test_shape.solid is not None assert type(test_shape.solid).__name__ == "Workplane" assert test_shape.hash_value is not None
def test_cut_volume(self): """creates an extruded shape with one placement angle using circles with \ another shape cut out and checks the volume is correct""" inner_shape = paramak.ExtrudeCircleShape(points=[(30, 0)], radius=5, distance=20) outer_shape = paramak.ExtrudeCircleShape(points=[(30, 0)], radius=10, distance=20) outer_shape_with_cut = paramak.ExtrudeCircleShape(points=[(30, 0)], radius=10, distance=20, cut=inner_shape) assert inner_shape.volume == pytest.approx(math.pi * 5**2 * 20) assert outer_shape.volume == pytest.approx(math.pi * 10**2 * 20) assert outer_shape_with_cut.volume == pytest.approx( (math.pi * 10**2 * 20) - (math.pi * 5**2 * 20))
def test_solid_return(self): """tests that the same cadquery solid with the same unique hash is returned when shape.solid is called again when no changes have been made to the shape""" test_shape = paramak.ExtrudeCircleShape(points=[(0, 0), (0, 20), (20, 20), (20, 0)], radius=10, distance=20) assert test_shape.solid is not None assert test_shape.hash_value is not None initial_hash_value = test_shape.hash_value assert test_shape.solid is not None assert test_shape.hash_value is not None assert initial_hash_value == test_shape.hash_value
def test_hash_value_update(self): """tests that the hash_value of the shape is not updated until a new solid has been created""" test_shape = paramak.ExtrudeCircleShape(points=[(0, 0), (0, 20), (20, 20)], radius=10, distance=20) test_shape.solid assert test_shape.hash_value is not None initial_hash_value = test_shape.hash_value test_shape.distance = 30 assert test_shape.hash_value == initial_hash_value test_shape.solid assert test_shape.hash_value != initial_hash_value
def test_conditional_solid_reconstruction(self): """tests that a new cadquery solid with a new unique hash is constructed when .solid is called again after changes have been made to the shape""" test_shape = paramak.ExtrudeCircleShape(points=[(0, 0), (0, 20), (20, 20)], radius=10, distance=20) assert test_shape.solid is not None assert test_shape.hash_value is not None initial_hash_value = test_shape.hash_value test_shape.distance = 30 assert test_shape.solid is not None assert test_shape.hash_value is not None assert initial_hash_value != test_shape.hash_value
def main(): # rotate examples # this makes a rectangle and rotates it to make a solid rotated_straights = paramak.RotateStraightShape(rotation_angle=180, points=[(400, 100), (400, 200), (600, 200), (600, 100)]) rotated_straights.export_stp("rotated_straights.stp") rotated_straights.export_html("rotated_straights.html") # this makes a banana shape and rotates it to make a solid rotated_spline = paramak.RotateSplineShape(rotation_angle=180, points=[ (500, 0), (500, -20), (400, -300), (300, -300), (400, 0), (300, 300), (400, 300), (500, 20), ]) rotated_spline.export_stp("rotated_spline.stp") rotated_spline.export_html("rotated_spline.html") # this makes a shape with straight, spline and circular edges and rotates # it to make a solid rotated_mixed = paramak.RotateMixedShape(rotation_angle=180, points=[ (100, 0, "straight"), (200, 0, "circle"), (250, 50, "circle"), (200, 100, "straight"), (150, 100, "spline"), (140, 75, "spline"), (110, 45, "spline"), ]) rotated_mixed.export_stp("rotated_mixed.stp") rotated_mixed.export_html("rotated_mixed.html") # this makes a circular shape and rotates it to make a solid rotated_circle = paramak.RotateCircleShape(rotation_angle=180, points=[(50, 0)], radius=5, workplane="XZ") rotated_circle.export_stp("rotated_circle.stp") rotated_circle.export_html("rotated_circle.html") # extrude examples # this makes a banana shape with straight edges and rotates it to make a # solid extruded_straight = paramak.ExtrudeStraightShape(distance=200, points=[ (300, -300), (400, 0), (300, 300), (400, 300), (500, 0), (400, -300), ]) extruded_straight.export_stp("extruded_straight.stp") extruded_straight.export_html("extruded_straight.html") # this makes a banana shape and rotates it to make a solid extruded_spline = paramak.ExtrudeSplineShape(distance=200, points=[ (500, 0), (500, -20), (400, -300), (300, -300), (400, 0), (300, 300), (400, 300), (500, 20), ]) extruded_spline.export_stp("extruded_spline.stp") extruded_spline.export_html("extruded_spline.html") # this makes a banana shape straight top and bottom edges and extrudes it # to make a solid extruded_mixed = paramak.ExtrudeMixedShape( distance=100, points=[ (100, 0, "straight"), (200, 0, "circle"), (250, 50, "circle"), (200, 100, "straight"), (150, 100, "spline"), (140, 75, "spline"), (110, 45, "spline"), ], ) extruded_mixed.export_stp("extruded_mixed.stp") extruded_mixed.export_html("extruded_mixed.html") # this makes a circular shape and extrudes it to make a solid extruded_circle = paramak.ExtrudeCircleShape(points=[(20, 0)], radius=20, distance=200) extruded_circle.export_stp("extruded_circle.stp") extruded_circle.export_html("extruded_circle.html") # sweep examples # this makes a banana shape with straight edges and sweeps it along a # spline to make a solid sweep_straight = paramak.SweepStraightShape(points=[(-150, 300), (-50, 300), (50, 0), (-50, -300), (-150, -300), (-50, 0)], path_points=[(50, 0), (150, 400), (400, 500), (650, 600), (750, 1000)], workplane="XY", path_workplane="XZ") sweep_straight.export_stp("sweep_straight.stp") sweep_straight.export_html("sweep_straight.html") # this makes a banana shape with spline edges and sweeps it along a spline # to make a solid sweep_spline = paramak.SweepSplineShape(points=[(50, 0), (50, -20), (-50, -300), (-150, -300), (-50, 0), (-150, 300), (-50, 300), (50, 20)], path_points=[(50, 0), (150, 400), (400, 500), (650, 600), (750, 1000)], workplane="XY", path_workplane="XZ") sweep_spline.export_stp("sweep_spline.stp") sweep_spline.export_html("sweep_spline.html") # this makes a shape with straight, spline and circular edges and sweeps # it along a spline to make a solid sweep_mixed = paramak.SweepMixedShape(points=[(-80, -50, "straight"), (20, -50, "circle"), (70, 0, "circle"), (20, 50, "straight"), (-30, 50, "spline"), (-40, 25, "spline"), (-70, -5, "spline")], path_points=[(50, 0), (150, 400), (400, 500), (650, 600), (750, 1000)], workplane="XY", path_workplane="XZ") sweep_mixed.export_stp("sweep_mixed.stp") sweep_mixed.export_html("sweep_mixed.html") # this makes a circular shape and sweeps it to make a solid sweep_circle = paramak.SweepCircleShape(radius=40, path_points=[(50, 0), (150, 400), (400, 500), (650, 600), (750, 1000)], workplane="XY", path_workplane="XZ") sweep_circle.export_stp("sweep_circle.stp") sweep_circle.export_html("sweep_circle.html")
def main(): # rotate examples # this makes a rectangle and rotates it to make a solid rotated_straights = paramak.RotateStraightShape( points=[(400, 100), (400, 200), (600, 200), (600, 100)]) rotated_straights.rotation_angle = 180 rotated_straights.export_stp("rotated_straights.stp") rotated_straights.export_html("rotated_straights.html") # this makes a banana shape and rotates it to make a solid rotated_spline = paramak.RotateSplineShape(points=[ (500, 0), (500, -20), (400, -300), (300, -300), (400, 0), (300, 300), (400, 300), (500, 20), ]) rotated_spline.rotation_angle = 180 rotated_spline.export_stp("rotated_spline.stp") rotated_spline.export_html("rotated_spline.html") # this makes a shape with straight, spline and circular edges and rotates it to make a solid rotated_mixed = paramak.RotateMixedShape(points=[ (100, 0, 'straight'), (200, 0, 'circle'), (250, 50, 'circle'), (200, 100, 'straight'), (150, 100, 'spline'), (140, 75, 'spline'), (110, 45, 'spline'), ]) rotated_mixed.rotation_angle = 180 rotated_mixed.export_stp("rotated_mixed.stp") rotated_mixed.export_html("rotated_mixed.html") # this makes a circular shape and rotates it to make a solid rotated_circle = paramak.RotateCircleShape(points=[(50, 0)], radius=5, workplane="XZ") rotated_circle.rotation_angle = 180 rotated_circle.export_stp("rotated_circle.stp") rotated_circle.export_html("rotated_circle.html") # extrude examples # this makes a banana shape with straight edges and rotates it to make a solid extruded_straight = paramak.ExtrudeStraightShape( points=[ (300, -300), (400, 0), (300, 300), (400, 300), (500, 0), (400, -300), ], distance=200, ) extruded_straight.export_stp("extruded_straight.stp") extruded_straight.export_html("extruded_straight.html") # this makes a banana shape and rotates it to make a solid extruded_spline = paramak.ExtrudeSplineShape( points=[ (500, 0), (500, -20), (400, -300), (300, -300), (400, 0), (300, 300), (400, 300), (500, 20), ], distance=200, ) extruded_spline.export_stp("extruded_spline.stp") extruded_spline.export_html("extruded_spline.html") # this makes a banana shape straight top and bottom edges and extrudes it to make a solid extruded_mixed = paramak.ExtrudeMixedShape( points=[ (100, 0, 'straight'), (200, 0, 'circle'), (250, 50, 'circle'), (200, 100, 'straight'), (150, 100, 'spline'), (140, 75, 'spline'), (110, 45, 'spline'), ], distance=100, ) extruded_mixed.export_stp("extruded_mixed.stp") extruded_mixed.export_html("extruded_mixed.html") # this makes a circular shape and extrudes it to make a solid extruded_circle = paramak.ExtrudeCircleShape(points=[(20, 0)], radius=20, distance=200) extruded_circle.export_stp("extruded_circle.stp") extruded_circle.export_html("extruded_circle.html")