MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / test_voxel

Function test_voxel

tests/test_voxel.cpp:31–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29}
30
31static void test_voxel(Vec3<int> voxel_size)
32{
33 VoxelMap v{voxel_size};
34 if (v.size != voxel_size)
35 {
36 LogError("Unexpected size %s", v.size);
37 exit(EXIT_FAILURE);
38 }
39 // Ensure everything is '0' at init, and anything outside the bounds should be '0' too
40 for (int z = -16; z < voxel_size.z + 32; z++)
41 {
42 for (int y = -64; y < voxel_size.y + 64; y++)
43 {
44 for (int x = -1; x < voxel_size.x + 99; x++)
45 {
46 check_voxel({x, y, z}, v, false);
47 }
48 }
49 }
50
51 // An empty map should have a center in the 'middle'
52 v.calculateCentre();
53 if (v.getCentre() != v.size / 2)
54 {
55 LogError("Unexpected centre %s for empty map", v.getCentre());
56 exit(EXIT_FAILURE);
57 }
58
59 // Add a slice with a set voxel:
60 auto slice = mksp<VoxelSlice>(Vec2<int>{voxel_size.x, voxel_size.y});
61
62 if (slice->size != Vec2<int>{voxel_size.x, voxel_size.y})
63 {
64 LogError("Unexpected slice size %s", slice->size);
65 exit(EXIT_FAILURE);
66 }
67 // Ensure everything is '0' at init, and anything outside the bounds should be '0' too
68 for (int y = -64; y < voxel_size.y + 64; y++)
69 {
70 for (int x = -1; x < voxel_size.z + 99; x++)
71 {
72 check_slice({x, y}, *slice, false);
73 }
74 }
75
76 // Set one bit to true and check that
77 Vec2<int> bit_position = {2, 6};
78 if (bit_position.x > voxel_size.x)
79 {
80 bit_position.x = voxel_size.x - 1;
81 LogInfo("Clamping bit position x to %d", bit_position.x);
82 }
83 if (bit_position.y >= voxel_size.y)
84 {
85 bit_position.y = voxel_size.y - 1;
86 LogInfo("Clamping bit position y to %d", bit_position.y);
87 }
88

Callers 1

mainFunction · 0.85

Calls 5

check_voxelFunction · 0.85
check_sliceFunction · 0.85
calculateCentreMethod · 0.80
setBitMethod · 0.80
setSliceMethod · 0.80

Tested by

no test coverage detected