|
6 | 6 |
|
7 | 7 | import trimesh |
8 | 8 |
|
9 | | -from flitter.model import Matrix44 |
| 9 | +from flitter.model import Vector, Matrix44 |
10 | 10 | from flitter.render.window.models import Model |
11 | 11 |
|
12 | 12 | from . import utils |
@@ -208,3 +208,69 @@ def test_invalidate_dependency(self): |
208 | 208 | self.assertIsNot(model.get_bounds(), bounds) |
209 | 209 | self.assertIsNot(model.get_trimesh(), mesh) |
210 | 210 | self.assertIsNot(model.get_manifold(), manifold) |
| 211 | + |
| 212 | + |
| 213 | +class TestStructuring(utils.TestCase): |
| 214 | + def test_flatten(self): |
| 215 | + self.assertEqual(Model.box().flatten().name, 'flatten(!box)') |
| 216 | + self.assertEqual(Model.box().flatten().flatten().name, 'flatten(!box)') |
| 217 | + self.assertEqual(Model.box().flatten().snap_edges().name, 'flatten(!box)') |
| 218 | + |
| 219 | + def test_invert(self): |
| 220 | + self.assertEqual(Model.box().invert().name, 'invert(!box)') |
| 221 | + self.assertEqual(Model.box().invert().invert().name, '!box') |
| 222 | + self.assertEqual(Model.box().invert().repair().name, 'invert(repair(!box))') |
| 223 | + self.assertEqual(Model.box().invert().snap_edges().name, 'invert(snap_edges(!box))') |
| 224 | + M = Matrix44.translate(1) |
| 225 | + self.assertEqual(Model.box().invert().transform(M).name, f'invert(!box@{hex(M.hash(False))[2:]})') |
| 226 | + |
| 227 | + def test_repair(self): |
| 228 | + self.assertEqual(Model.box().repair().name, 'repair(!box)') |
| 229 | + self.assertEqual(Model.box().repair().repair().name, 'repair(!box)') |
| 230 | + |
| 231 | + def test_snap_edges(self): |
| 232 | + self.assertEqual(Model.box().snap_edges(0).name, 'flatten(!box)') |
| 233 | + self.assertEqual(Model.box().snap_edges().name, 'snap_edges(!box)') |
| 234 | + self.assertEqual(Model.box().snap_edges(0.05).name, 'snap_edges(!box)') |
| 235 | + self.assertEqual(Model.box().snap_edges(0.25).name, 'snap_edges(!box, 0.25)') |
| 236 | + self.assertEqual(Model.box().snap_edges(0.05, 0.25).name, 'snap_edges(!box, 0.05, 0.25)') |
| 237 | + self.assertEqual(Model.box().snap_edges(0.25, 0.25).name, 'snap_edges(!box, 0.25, 0.25)') |
| 238 | + |
| 239 | + def test_transform(self): |
| 240 | + self.assertEqual(Model.box().transform(Matrix44()).name, '!box') |
| 241 | + M = Matrix44.translate(1) |
| 242 | + H = hex(M.hash(False))[2:] |
| 243 | + self.assertEqual(Model.box().transform(M).name, f'!box@{H}') |
| 244 | + self.assertEqual(Model.box().transform(M).repair().name, f'repair(!box)@{H}') |
| 245 | + M2 = Matrix44.translate(2) |
| 246 | + H2 = hex(M2.hash(False))[2:] |
| 247 | + self.assertEqual(Model.box().transform(M).transform(M).name, f'!box@{H2}') |
| 248 | + |
| 249 | + def test_uvremap(self): |
| 250 | + self.assertEqual(Model.box().uv_remap('sphere').name, 'uv_remap(!box, sphere)') |
| 251 | + |
| 252 | + def test_slice(self): |
| 253 | + P = Vector((0, 0, 0)) |
| 254 | + N = Vector((1, 0, 0)) |
| 255 | + H = hex(P.hash(False) ^ N.hash(False))[2:] |
| 256 | + self.assertEqual(Model.box().slice(P, N).name, f'slice(!box, {H})') |
| 257 | + self.assertEqual(Model.box().slice(P, N).repair().name, f'slice(!box, {H})') |
| 258 | + |
| 259 | + def test_union(self): |
| 260 | + self.assertIsNone(Model.union()) |
| 261 | + self.assertEqual(Model.union(Model.box()).name, '!box') |
| 262 | + self.assertEqual(Model.union(Model.box(), Model.box()).name, '!box') |
| 263 | + self.assertEqual(Model.union(Model.box(), Model.sphere()).name, 'union(!box, !sphere)') |
| 264 | + self.assertEqual(Model.union(Model.box(), Model.union(Model.sphere(), Model.cylinder())).name, 'union(!box, !sphere, !cylinder)') |
| 265 | + |
| 266 | + def test_intersect(self): |
| 267 | + self.assertIsNone(Model.intersect()) |
| 268 | + self.assertEqual(Model.intersect(Model.box()).name, '!box') |
| 269 | + self.assertEqual(Model.intersect(Model.box(), Model.box()).name, '!box') |
| 270 | + self.assertEqual(Model.intersect(Model.box(), Model.sphere()).name, 'intersect(!box, !sphere)') |
| 271 | + |
| 272 | + def test_difference(self): |
| 273 | + self.assertIsNone(Model.difference()) |
| 274 | + self.assertEqual(Model.difference(Model.box()).name, '!box') |
| 275 | + self.assertIsNone(Model.difference(Model.box(), Model.box())) |
| 276 | + self.assertEqual(Model.difference(Model.box(), Model.sphere()).name, 'difference(!box, !sphere)') |
0 commit comments