Skip to content

Commit

Permalink
Add tests and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
FranzBangar committed May 19, 2024
1 parent bb84b27 commit 9eff26e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
10 changes: 3 additions & 7 deletions examples/stack/fusilli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
import classy_blocks as cb
from classy_blocks.base.transforms import Rotation, Translation

# TODO! direct imports
from classy_blocks.construct.flat.sketches.disk import Oval
from classy_blocks.construct.stack import TransformedStack

# Something resembling a pasta.
# Something resembling pasta.
cell_size = 0.05
oval_point_1 = [0, 0, 0]
oval_point_2 = [0, -1, 0]
Expand All @@ -18,9 +14,9 @@

mesh = cb.Mesh()

base = Oval(oval_point_1, oval_point_2, normal, oval_radius)
base = cb.Oval(oval_point_1, oval_point_2, normal, oval_radius)

stack = TransformedStack(
stack = cb.TransformedStack(
base,
[Translation([0, 0, 0.3]), Rotation(normal, np.pi / 6, [0, -0.5, 0])],
12,
Expand Down
4 changes: 2 additions & 2 deletions src/classy_blocks/construct/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def operations(self) -> List[Operation]:

@property
def parts(self):
return self.operations
return self.shapes

@property
def center(self):
Expand Down Expand Up @@ -97,7 +97,7 @@ def __init__(
shape = LoftedShape(sketch_1, sketch_2, sketch_mid)

self.shapes.append(shape)
sketch_1 = sketch_2
sketch_1 = sketch_2.copy()


class ExtrudedStack(TransformedStack):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_construct/test_operation/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,9 @@ def test_mirror_transform(self):

with self.assertWarns(Warning):
extrude.copy().transform([Mirror([0, 0, 1], [0, 0, 0])])

def test_mirror_transform_no_origin(self):
extrude = Extrude(self.loft.bottom_face, [0, 0, 1])
mirror = extrude.copy().transform([Mirror([0, 0, 1])]).invert()

np.testing.assert_equal(extrude.bottom_face.center, mirror.top_face.center)
6 changes: 6 additions & 0 deletions tests/test_construct/test_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def test_translate(self):

np.testing.assert_array_equal(self.cylinder.sketch_1.center, [1, 0, 0])

def test_translate_sketches(self):
"""Translate the cylinder and see what happens to sketches"""
cyl = self.cylinder.translate([1, 0, 0])

np.testing.assert_almost_equal(cyl.sketch_1.center, [1, 0, 0])

def test_cylinder_center(self):
"""Center of a cylinder"""
np.testing.assert_almost_equal(self.cylinder.center, [0.5, 0, 0])
Expand Down
21 changes: 20 additions & 1 deletion tests/test_construct/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ def round_base(self) -> cb.OneCoreDisk:
def square_base(self) -> cb.Grid:
return cb.Grid([0, 0, 0], [1, 1, 0], 2, 5)

def test_construct_extruded(self):
def test_construct_extruded_vector(self):
stack = cb.ExtrudedStack(self.round_base, [0, 0, 1], 4)

self.assertEqual(len(stack.grid), 4)
self.assertEqual(stack.shapes[-1].operations[0].top_face.center[2], 1)

def test_construct_extruded_amount(self):
stack = cb.ExtrudedStack(self.round_base, 1, 4)

self.assertEqual(len(stack.grid), 4)
self.assertEqual(stack.shapes[-1].operations[0].top_face.center[2], 1)

def test_construct_revolved(self):
_ = cb.RevolvedStack(self.round_base, np.pi / 6, [0, 1, 0], [2, 0, 0], 4)
Expand All @@ -39,6 +46,18 @@ def test_chop(self):
for shape in stack.shapes:
self.assertEqual(len(shape.grid[0][0].chops[2]), 1)

def test_center(self):
stack = cb.ExtrudedStack(self.round_base, 1, 4)

np.testing.assert_almost_equal(stack.center, [0, 0, 0.5])

def test_stack_transform(self):
stack = cb.ExtrudedStack(self.round_base, 1, 4)

stack.translate([0, 0, 1])

np.testing.assert_almost_equal(stack.center, [0, 0, 1.5])

def test_grid_square_axis0(self):
stack = cb.ExtrudedStack(self.square_base, 1, 3)

Expand Down
17 changes: 17 additions & 0 deletions tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,20 @@ def test_backport_empty(self):

with self.assertRaises(RuntimeError):
self.mesh.backport()

def test_delete(self):
boxes = [
Box([0, 0, 0], [1, 1, 1]),
Box([1, 0, 0], [2, 1, 1]),
Box([0, 1, 0], [1, 2, 1]),
Box([1, 1, 0], [2, 2, 1]),
]

for box in boxes:
self.mesh.add(box)

self.mesh.delete(boxes[0])

self.mesh.assemble()

self.assertEqual(len(self.mesh.blocks), 3)

0 comments on commit 9eff26e

Please sign in to comment.