|
3 | 3 |
|
4 | 4 | import numpy as np |
5 | 5 |
|
6 | | -from classy_blocks.base.exceptions import InconsistentGradingsError |
7 | | -from classy_blocks.cbtyping import DirectionType |
| 6 | +from classy_blocks.base.exceptions import InconsistentGradingsError, UndefinedGradingsError |
| 7 | +from classy_blocks.cbtyping import DirectionType, GradingSpecType |
8 | 8 | from classy_blocks.construct.edges import Arc |
9 | 9 | from classy_blocks.construct.operations.box import Box |
10 | 10 | from classy_blocks.construct.operations.connector import Connector |
@@ -150,3 +150,70 @@ def test_propagated_count(self): |
150 | 150 |
|
151 | 151 | for block in self.mesh.blocks: |
152 | 152 | self.assertTrue(" ( 10 10 10 ) simpleGrading" in formats.format_block(block)) |
| 153 | + |
| 154 | + |
| 155 | +class BoxEdgeChopTests(unittest.TestCase): |
| 156 | + """Edge chopping on a single operation""" |
| 157 | + |
| 158 | + def setUp(self): |
| 159 | + self.box = Box([0, 0, 0], [1, 1, 1]) |
| 160 | + self.mesh = Mesh() |
| 161 | + |
| 162 | + self.mesh.add(self.box) |
| 163 | + |
| 164 | + def finalize(self): |
| 165 | + self.mesh.assemble() |
| 166 | + self.mesh.grade() |
| 167 | + |
| 168 | + def get_grading(self, direction: DirectionType, i_wire: int) -> list[GradingSpecType]: |
| 169 | + self.finalize() |
| 170 | + |
| 171 | + return self.mesh.blocks[0].axes[direction].wires[i_wire].grading.specification |
| 172 | + |
| 173 | + def test_edge_chop_solo_fail(self): |
| 174 | + """Cannot use edge chopping if the mesh is not fully defined""" |
| 175 | + self.box.chop_edge(0, 1, count=30) |
| 176 | + |
| 177 | + with self.assertRaises(UndefinedGradingsError): |
| 178 | + self.finalize() |
| 179 | + |
| 180 | + def test_edge_chop_solo_success(self): |
| 181 | + for i in get_args(DirectionType): |
| 182 | + self.box.chop(i, count=(i + 1) * 5) |
| 183 | + |
| 184 | + self.box.chop_edge(0, 1, start_size=0.05) |
| 185 | + |
| 186 | + self.finalize() |
| 187 | + |
| 188 | + # one edge is graded, the rest are simple |
| 189 | + self.assertAlmostEqual(self.get_grading(0, 0)[0][2], 9.043586, places=5) |
| 190 | + self.assertAlmostEqual(self.get_grading(0, 1)[0][2], 1) |
| 191 | + |
| 192 | + def test_edge_chop_multiple(self): |
| 193 | + """Do multiple chops and let the last chop define the remaining count automatically""" |
| 194 | + |
| 195 | + self.box.chop(0, count=20) |
| 196 | + self.box.chop(1, count=10) |
| 197 | + self.box.chop(2, count=10) |
| 198 | + |
| 199 | + self.box.chop_edge(0, 1, length_ratio=0.49, start_size=0.1) # 5 cells |
| 200 | + self.box.chop_edge(0, 1, length_ratio=0.51, end_size=0.05) # the rest |
| 201 | + |
| 202 | + self.finalize() |
| 203 | + |
| 204 | + self.assertEqual(self.get_grading(0, 0)[0][1], 5) |
| 205 | + self.assertEqual(self.get_grading(0, 0)[1][1], 15) |
| 206 | + |
| 207 | + def test_clear(self): |
| 208 | + for i in get_args(DirectionType): |
| 209 | + self.box.chop(i, count=(i + 1) * 5) |
| 210 | + self.box.chop_edge(0, 1, start_size=0.5) |
| 211 | + self.box.chop_edge(1, 2, count=30) |
| 212 | + |
| 213 | + self.box.chops.clear() |
| 214 | + |
| 215 | + self.assertListEqual(self.box.chops.axis_chops[0], []) |
| 216 | + self.assertListEqual(self.box.chops.axis_chops[1], []) |
| 217 | + self.assertListEqual(self.box.chops.axis_chops[2], []) |
| 218 | + |
| 219 | + self.assertFalse(self.box.chops.is_edge_chopped) |
0 commit comments