bitperm 0.1.0

Bit permutations and bit-packed polycube/grid structures in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
use arrayvec::*;

use crate::bitgrid8::BitGrid8;

// use itertools::Itertools;

// -----------------------------------------------------------------
// 8x8x8 cube space represented by [u64; 8]
// -----------------------------------------------------------------
// Position at (x,y,z) BitGrid8[z] = x + 8*y
// Rotations will happen from the center of the cube
//
// The operators >> and << implement unbounded_shr() and unbounded_shl(),
// so they may be used safely.

#[derive(
    Copy,
    Clone,
    Eq,
    PartialEq,
    Hash,
    PartialOrd,
    Ord,
    // BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign,
)]
pub struct BitCube8([BitGrid8; 8]);

pub struct BitCube4Rotations(pub ArrayVec<BitCube8, 24>);

impl From<[u64; 8]> for BitCube8 {
    fn from(arr: [u64; 8]) -> BitCube8 {
        BitCube8(arr.map(BitGrid8::from))
    }
}

/*
impl Into<D3> for BitCube8 {
    fn into(self) -> D3 {
        let block = D3::cube(1.0);
        (0..512)
            .filter(|ii| (self.0[ii>>6] >> (ii & 0x3f) & 1 == 1))
            .map(|ii| v3(ii&0x7, (ii>>3)&0x7, self.0[ii>>6]))
            .map(|xyz| block.clone().translate(xyz))
            .union()
            .translate(v3(-4,-4,-4))
            .scale(10)
            .color(ColorEnum::Red)
    }
}
*/

impl BitCube8 {
    /*
    /// Count the number of cubes (ones) in the BitCube
    pub fn count_cubes(self) -> u32 {
        (0..8)
            .map(|ii| self.0[ii].count_ones())
            .sum()
    }
    /// Produce all rotations of a BitCube
    /// Prefer a gray code path through all rotations
    pub fn rotate_all_set(self) -> HashSet<BitCube8> {
        let mut vec = Vec::new();
        let mut x = self;
        vec.push(x);
        for _ in 0..3 { x = x.rotate_z(); vec.push(x); }
        x = x.rotate_d(); vec.push(x);
        for _ in 0..3 { x = x.rotate_z(); vec.push(x); }
        x = x.rotate_d(); vec.push(x);
        for _ in 0..3 { x = x.rotate_z(); vec.push(x); }
        x = x.rotate_d(); vec.push(x);
        for _ in 0..3 { x = x.rotate_z(); vec.push(x); }
        x = x.rotate_y(); vec.push(x);
        for _ in 0..3 { x = x.rotate_z(); vec.push(x); }
        x = x.rotate_d();  // One wasted move. There is probably a gray code path that is shorter.
        x = x.rotate_y(); vec.push(x);
        for _ in 0..3 { x = x.rotate_z(); vec.push(x); }
        HashSet::from_iter(vec.iter().cloned())
    }

    /// Produce all rotations of a BitCube
    /// Prefer a gray code path through all rotations
    pub fn rotate_all_vec(self) -> ArrayVec::<BitCube8, 24> {
        let mut vec = ArrayVec::<BitCube8, 24>::new();
        let mut x = self;
        vec.push(x);
        for _ in 0..3 { x = x.rotate_z(); vec.push(x); }
        x = x.rotate_d(); vec.push(x);
        for _ in 0..3 { x = x.rotate_z(); vec.push(x); }
        x = x.rotate_d(); vec.push(x);
        for _ in 0..3 { x = x.rotate_z(); vec.push(x); }
        x = x.rotate_d(); vec.push(x);
        for _ in 0..3 { x = x.rotate_z(); vec.push(x); }
        x = x.rotate_y(); vec.push(x);
        for _ in 0..3 { x = x.rotate_z(); vec.push(x); }
        x = x.rotate_d();  // One wasted move. There is probably a gray code path that is shorter.
        x = x.rotate_y(); vec.push(x);
        for _ in 0..3 { x = x.rotate_z(); vec.push(x); }
        vec.sort_unstable();
        let symmetries = vec.partition_dedup().0.len();  // Move duplicates to the end.
        vec.truncate(symmetries);
        vec
    }

    /// Produce all rotations of a BitCube object translated towards origin.
    /// Prefer a gray code path through all rotations
    pub fn origin_rotate_all(self) -> ArrayVec::<BitCube8, 24> {
        let mut vec = ArrayVec::<BitCube8, 24>::new();
        let mut x = self.shift_to_origin();
        vec.push(x);
        for _ in 0..3 {
            for _ in 0..3 { x = x.rotate_z().shift_to_origin(); vec.push(x); }
            x = x.rotate_d().shift_to_origin(); vec.push(x);
        }
        for _ in 0..3 { x = x.rotate_z().shift_to_origin(); vec.push(x); }
        x = x.rotate_y().shift_to_origin(); vec.push(x);
        for _ in 0..3 { x = x.rotate_z().shift_to_origin(); vec.push(x); }
        x = x.rotate_d();  // One wasted move. There is probably a gray code path that is shorter.
        x = x.rotate_y().shift_to_origin(); vec.push(x);
        for _ in 0..3 { x = x.rotate_z().shift_to_origin(); vec.push(x); }
        vec.sort_unstable();
        let symmetries = vec.partition_dedup().0.len();  // Move duplicates to the end.
        vec.truncate(symmetries);
        vec
    }

    // 1100
    // 0100
    // 1000
    // 0000
    /// 2x2x2 Example: 01 23 | 45 67 => 45 01 | 67 23
    pub fn rotate_x(self) -> Self {
        let mut cube = self.0;
        // Swap 2x2 blocks front <-> back
        swap_mask_shift_u64(&mut cube, 0x00ff_00ff_00ff_00ff_u64, 8);
        // Swap diagonal 2x2 blocks
        swap_mask_shift_u64(&mut cube, 0x0000_0000_00ff_00ff_u64, 40);
        // Within 2x2 blocks swap front <-> back
        swap_mask_shift_u64(&mut cube, 0x0f0f_0f0f_0f0f_0f0f_u64, 4);
        // Within 2x2 blocks swap diagonal entries
        swap_mask_shift_u64(&mut cube, 0x0000_0f0f_0000_0f0f_u64, 20);
        BitCube8(cube)
    }

    /// 2x2x2 Example: 01 23 | 45 67 => 15 37 | 04 26
    /// 2x2x2 Example: 01 23 | 45 67 => 45 67 | 01 23
    pub fn rotate_y(self) -> Self {
        let mut cube = self.0;
        // Swap 2x2 blocks up <-> down
        swap_mask_shift_u64(&mut cube, 0x0000_0000_ffff_ffff_u64, 32);
        // Swap diagonal 2x2 blocks
        swap_mask_shift_u64(&mut cube, 0x0000_0000_3333_3333_u64, 34);
        // Within 2x2 blocks swap up <-> down
        swap_mask_shift_u64(&mut cube, 0x0000_ffff_0000_ffff_u64, 16);
        // Within 2x2 blocks swap diagonal entries
        swap_mask_shift_u64(&mut cube, 0x0000_5555_0000_5555_u64, 17);
        BitCube8(cube)
    }

    /// 2x2x2 Example: 01 23 | 45 67 => 20 31 | 64 75
    /// The z-rotation is the easiest to understand since the rotation happens in the xy-plane and
    /// is copied in the other dimension.
    /// 23 32 31
    /// 01 10 20
    pub fn rotate_z(self) -> Self {
        let mut cube = self.0;
        // Swap 2x2 squares left <-> right
        swap_mask_shift_u64(&mut cube, 0x3333_3333_3333_3333_u64, 2);
        // Swap diagonal 2x2 squares
        swap_mask_shift_u64(&mut cube, 0x0033_0033_0033_0033_u64, 10);
        // Within 2x2 squares swap left <-> right columns
        swap_mask_shift_u64(&mut cube, 0x5555_5555_5555_5555_u64, 1);
        // Within 2x2 squares swap diagonal entries
        swap_mask_shift_u64(&mut cube, 0x0505_0505_0505_0505_u64, 5);
        BitCube8(cube)
    }

    /// Rotate 120 degrees about the diagonal through the origin and center of the cube.
    /// 2x2x2 Example: 01 23 | 45 67 => 04 15 | 26 37
    /// Use two position involutions: 2 <-> 4 and 3 <-> 5, then 1 <-> 2 and 5 <-> 6.
    /// For the 4-cube, rotate the position of all the 2-cubes,
    /// then rotate all the 2-cubes in place.
    pub fn rotate_d(self) -> Self {
        let mut cube = self.0;
        // Swap sub-cubes 2 <-> 4 and 3 <-> 5
        swap_mask_shift_u64(&mut cube, 0x0000_0000_ff00_ff00_u64, 24);
        // Swap sub-cubes 1 <-> 2 and 5 <-> 6
        swap_mask_shift_u64(&mut cube, 0x00cc_00cc_00cc_00cc_u64, 6);
        // Swap 2 <-> 4 and 3 <-> 5 in each sub-cube
        swap_mask_shift_u64(&mut cube, 0x0000_f0f0_0000_f0f0_u64, 12);
        // Swap 1 <-> 2 and 5 <-> 6 in each sub-cube
        swap_mask_shift_u64(&mut cube, 0x0a0a_0a0a_0a0a_0a0a_u64, 3);
        BitCube4(cube)
    }

    pub fn shift_x(self, shift: i8) -> Self {
        match shift {
            0 => self,
            1 => (self << 1) & 0xeeee_eeee_eeee_eeee_u64,
            2 => Self((self.0.unbounded_shl(2)) & 0xdddd_dddd_dddd_dddd_u64),
            3 => Self((self.0.unbounded_shl(3)) & 0x8888_8888_8888_8888_u64),
            -1 => Self((self.0.unbounded_shr(1)) & 0x7777_7777_7777_7777_u64),
            -2 => Self((self.0.unbounded_shr(2)) & 0x3333_3333_3333_3333_u64),
            -3 => Self((self.0.unbounded_shr(3)) & 0x1111_1111_1111_1111_u64),
            _ => Self(0)
        }
    }

    /// Return none if the x-shift would move part of the polycube past an edge.
    pub fn bounded_shift_x(self, shift: i8) -> Option<Self> {
        let shifted = self.shift_x(shift);
        if self.count_cubes() == shifted.count_cubes() {
            Some(shifted)
        } else {
            None
        }
    }

    pub fn shift_y(self, shift: i8) -> Self {
        match shift {
            0 => self,
            1 => Self((self.0 << 4) & 0xfff0_fff0_fff0_fff0_u64),
            2 => Self((self.0 << 8) & 0xff00_ff00_ff00_ff00_u64),
            3 => Self((self.0 << 12) & 0xf000_f000_f000_f000_u64),
            -1 => Self((self.0 >> 4) & 0x0fff_0fff_0fff_0fff_u64),
            -2 => Self((self.0 >> 8) & 0x00ff_00ff_00ff_00ff_u64),
            -3 => Self((self.0 >> 12) & 0x000f_000f_000f_000f_u64),
            _ => Self(0)
        }
    }

    /// Return none if the y-shift would move part of the polycube past an edge.
    pub fn bounded_shift_y(self, shift: i8) -> Option<Self> {
        let shifted = self.shift_y(shift);
        if self.count_cubes() == shifted.count_cubes() {
            Some(shifted)
        } else {
            None
        }
    }

    pub fn shift_z(self, shift: i8) -> Self {
        match shift {
            0 => self,
            1 => Self((self.0 << 16) & 0xffff_ffff_ffff_0000_u64),
            2 => Self((self.0 << 32) & 0xffff_ffff_0000_0000_u64),
            3 => Self((self.0 << 48) & 0xffff_0000_0000_0000_u64),
            -1 => Self((self.0 >> 16) & 0x0000_ffff_ffff_ffff_u64),
            -2 => Self((self.0 >> 32) & 0x0000_0000_ffff_ffff_u64),
            -3 => Self((self.0 >> 48) & 0x0000_0000_0000_ffff_u64),
            _ => Self(0)
        }
    }

    /// Return none if the z-shift would move part of the polycube past an edge.
    pub fn bounded_shift_z(self, shift: i8) -> Option<Self> {
        let shifted = self.shift_z(shift);
        if self.count_cubes() == shifted.count_cubes() {
            Some(shifted)
        } else {
            None
        }
    }

    /// Given a piece in the 4-cube, shift it towards the origin so that it touches the x, y, and z
    /// planes
    pub fn shift_to_origin(self) -> Self {
        let mut shape = self.0;
        let z_shift = (shape.trailing_zeros() / 16) * 16;
        shape = shape.unbounded_shr(z_shift);
        let xy_proj = shape | shape.unbounded_shr(32);
        let xy_proj = xy_proj | xy_proj.unbounded_shr(16);
        let y_shift = (xy_proj.trailing_zeros() / 4) * 4;
        shape = shape.unbounded_shr(y_shift);
        let x_shift = xy_proj | xy_proj.unbounded_shr(8);
        let x_shift = x_shift | x_shift.unbounded_shr(4);
        shape = shape.unbounded_shr(x_shift.trailing_zeros());
        Self(shape)
    }

    pub fn overlap(self, other: Self) -> bool {
        self.0 & other.0 != 0
    }
    */
}

/*
impl BitOr for BitCube4 {
    type Output = Self;

    fn bitor(self, other: Self) -> Self::Output {
        Self(self.0 | other.0)
    }
}

impl BitOrAssign for BitCube4 {
    // rhs is the "right-hand side" of the expression `a |= b`
    fn bitor_assign(&mut self, rhs: Self) {
        *self = Self(self.0 | rhs.0)
    }
}


impl BitAnd for BitCube4 {
    type Output = Self;

    fn bitand(self, other: Self) -> Self::Output {
        Self(self.0 & other.0)
    }
}

impl BitAndAssign for BitCube4 {
    // rhs is the "right-hand side" of the expression `a &= b`
    fn bitand_assign(&mut self, rhs: Self) {
        *self = Self(self.0 & rhs.0)
    }
}

impl BitAnd<u64> for BitCube4 {
    type Output = Self;

    fn bitand(self, rhs: u64) -> Self::Output {
        Self(self.0 & rhs)
    }
}

// impl fmt::Debug for BitCube4 {
    // fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        // write!(f, "BitCube4({:#018x})\n{:}", self.0, self)
    // }
// }

impl fmt::Debug for BitCube8 {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "BitCube8({:#018x})", self.0)
    }
}

impl fmt::Display for BitCube8 {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}",
            (0..4)
            .map(|x| { let x = self.0 >> (4 * (3-x));
                (0..4)
                .map(|y| format!("{:04b}", (x >> (16*y)) & 0xf))
                .map(|s| s.chars().rev().collect())
                .collect::<Vec<String>>()
                .join(" ")
            })
            .collect::<Vec<String>>()
            .join("\n")
            )
    }
}

*/
#[cfg(test)]
mod test {
    /*
    use super::*;
    use crate::bitlib::*;

        #[test]
        fn test_debug() {
            assert_eq!(format!("{:?}", BitCube8::from(ORDER)),
                "BitCube8(0xfedcba9876543210)"
            );

        }

        #[test]
        fn test_display() {
            assert_eq!(format!("{:}", BitCube8::from(ORDER)),
                "1100 1110 1101 1111\n0100 0110 0101 0111\n1000 1010 1001 1011\n0000 0010 0001 0011"
            );

        }
        #[test]
        fn test_bitor() {
            assert_eq!(BitCube4::from(FULL) | BitCube4::from(FULL), BitCube4::from(FULL));
            assert_eq!(BitCube4::from(ALL) | BitCube4::from(ALL), BitCube4::from(ALL));
            assert_eq!(BitCube4::from(BC4_CENTER_X) | BitCube4::from(BC4_CENTER_Y) | BitCube4::from(BC4_CENTER_Z), BitCube4::from(BC4_CENTER_ALL));
        }

        #[test]
        fn test_shift_x() {
            assert_eq!(BitCube4::from(FULL).shift_x(1),
                       BitCube4(0xeeee_eeee_eeee_eeee_u64)
                       );
        }

        #[test]
        fn test_shift_y() {
            assert_eq!(BitCube4::from(FULL).shift_y(1),
                       BitCube4(0xfff0_fff0_fff0_fff0_u64)
                       );
        }

        #[test]
        fn test_shift_z() {
            assert_eq!(BitCube4::from(FULL).shift_z(1),
                       BitCube4(0xffff_ffff_ffff_0000_u64)
                       );
        }

        #[test]
        fn test_bounded_shift_x() {
            assert_eq!(BitCube4::from(FULL).bounded_shift_x(1), None);
            assert_eq!(BitCube4::from(BC4_CENTER_X).bounded_shift_x(1), None);
            assert_eq!(BitCube4::from(BC4_CENTER_Y).bounded_shift_x(1), Some(BitCube4(0x0000cccccccc0000)));
            assert_eq!(BitCube4::from(BC4_CENTER_Z).bounded_shift_x(1), Some(BitCube4(0x0cc00cc00cc00cc0)));
        }

        #[test]
        fn test_bounded_shift_y() {
            assert_eq!(BitCube4::from(FULL).bounded_shift_y(1), None);
            assert_eq!(BitCube4::from(BC4_CENTER_X).bounded_shift_y(1), Some(BitCube4(0x0000ff00ff000000)));
            assert_eq!(BitCube4::from(BC4_CENTER_Y).bounded_shift_y(1), None);
            assert_eq!(BitCube4::from(BC4_CENTER_Z).bounded_shift_y(1), Some(BitCube4(0x6600660066006600)));
        }

        #[test]
        fn test_bounded_shift_z() {
            assert_eq!(BitCube4::from(FULL).bounded_shift_z(1), None);
            assert_eq!(BitCube4::from(BC4_CENTER_X).bounded_shift_z(1), Some(BitCube4(0x0ff00ff000000000)));
            assert_eq!(BitCube4::from(BC4_CENTER_Y).bounded_shift_z(1), Some(BitCube4(0x6666666600000000)));
            assert_eq!(BitCube4::from(BC4_CENTER_Z).bounded_shift_z(1), None);
        }

        #[test]
        fn test_shift_to_origin() {
            assert_eq!(BitCube4::from(FULL).shift_to_origin(), BitCube4::from(FULL));
            assert_eq!((BitCube4::from(BC4_CENTER_X) | BitCube4::from(BC4_CENTER_Y)).shift_to_origin(), BitCube4(0x0000_0000_6ff6_6ff6));
        }

        #[test]
        fn test_rotate_x() {
            assert_eq!(BitCube4::from(FULL).rotate_x(), BitCube4::from(FULL));
            assert_eq!(BitCube4::from(BC4_CENTER_X).rotate_x(), BitCube4::from(BC4_CENTER_X));
            assert_eq!(BitCube4::from(BC4_CENTER_Y).rotate_x(), BitCube4::from(BC4_CENTER_Z));
            assert_eq!(BitCube4::from(BC4_CENTER_Z).rotate_x(), BitCube4::from(BC4_CENTER_Y));
            assert_eq!(BitCube4(0xf).rotate_x(), BitCube4(0xf000));
            assert_eq!(BitCube4(0xf000).rotate_x(), BitCube4(0xf000000000000000));
        }

        #[test]
        fn test_rotate_y() {
            assert_eq!(BitCube4::from(FULL).rotate_y(), BitCube4::from(FULL));
            assert_eq!(BitCube4::from(UPPER_RIGHT_2X4X2).rotate_y(), BitCube4::from(LOWER_RIGHT_2X4X2));
            assert_eq!(BitCube4::from(LOWER_RIGHT_2X4X2).rotate_y(), BitCube4::from(LOWER_LEFT_2X4X2));
            assert_eq!(BitCube4::from(BC4_CENTER_X).rotate_y(), BitCube4::from(BC4_CENTER_Z));
            assert_eq!(BitCube4::from(BC4_CENTER_Y).rotate_y(), BitCube4::from(BC4_CENTER_Y));
            assert_eq!(BitCube4::from(BC4_CENTER_Z).rotate_y(), BitCube4::from(BC4_CENTER_X));
            assert_eq!(BitCube4(0xf).rotate_y(), BitCube4(0x0001000100010001));
        }

        #[test]
        fn test_rotate_z() {
            assert_eq!(BitCube4::from(FULL).rotate_z(), BitCube4::from(FULL));
            assert_eq!(BitCube4::from(BC4_CENTER_X).rotate_z(), BitCube4::from(BC4_CENTER_Y));
            assert_eq!(BitCube4::from(BC4_CENTER_Y).rotate_z(), BitCube4::from(BC4_CENTER_X));
            assert_eq!(BitCube4::from(BC4_CENTER_Z).rotate_z(), BitCube4::from(BC4_CENTER_Z));
            assert_eq!(BitCube4(0xf).rotate_z(), BitCube4(0x8888));
        }

        #[test]
        fn test_rotate_d() {
            assert_eq!(BitCube4::from(FULL).rotate_d(), BitCube4::from(FULL));
            assert_eq!(BitCube4::from(SUBCUBE_0).rotate_d(), BitCube4::from(SUBCUBE_0));
            assert_eq!(BitCube4::from(SUBCUBE_1).rotate_d(), BitCube4::from(SUBCUBE_2));
            assert_eq!(BitCube4::from(SUBCUBE_2).rotate_d(), BitCube4::from(SUBCUBE_4));
            assert_eq!(BitCube4::from(SUBCUBE_4).rotate_d(), BitCube4::from(SUBCUBE_1));
            assert_eq!(BitCube4::from(SUBCUBE_3).rotate_d(), BitCube4::from(SUBCUBE_6));
            assert_eq!(BitCube4::from(SUBCUBE_6).rotate_d(), BitCube4::from(SUBCUBE_5));
            assert_eq!(BitCube4::from(SUBCUBE_5).rotate_d(), BitCube4::from(SUBCUBE_3));
            assert_eq!(BitCube4::from(SUBCUBE_7).rotate_d(), BitCube4::from(SUBCUBE_7));
            assert_eq!(BitCube4::from(BC4_CENTER_X).rotate_d(), BitCube4::from(BC4_CENTER_Y));
            assert_eq!(BitCube4::from(BC4_CENTER_Y).rotate_d(), BitCube4::from(BC4_CENTER_Z));
            assert_eq!(BitCube4::from(BC4_CENTER_Z).rotate_d(), BitCube4::from(BC4_CENTER_X));
            assert_eq!(BitCube4(0x1011f).rotate_d(), BitCube4(0x0000000100011113));
        }

        #[test]
        fn test_overlap() {
            assert!(BitCube4::from(BC4_CENTER_X).overlap(BitCube4::from(BC4_CENTER_Y)));
        }

        #[test]
        fn test_from_bitperm3() {
            assert_eq!(BitCube4::from(BitCube3(0o777777777)), BitCube4(0x77707770777));
            assert_eq!(BitCube4::from(BitCube3(0o700000000)), BitCube4(0x70000000000));
            assert_eq!(BitCube4::from(BitCube3(0o76543210)), BitCube4(0x7605430210));

        }

        #[test]
        fn test_rotate_all_set() {
            assert_eq!(BitCube4::rotate_all_set(BitCube4::from(BC4_CENTER_ALL)), HashSet::from([BitCube4::from(BC4_CENTER_ALL)]));
            assert_eq!(BitCube4::rotate_all_set(BitCube4::from(BC4_CENTER_X)), HashSet::from([BitCube4::from(BC4_CENTER_X), BitCube4::from(BC4_CENTER_Y), BitCube4::from(BC4_CENTER_Z)]));
            assert_eq!(BitCube4::rotate_all_set(BitCube4::from(SUBCUBE_0)).len(), 8);
            assert_eq!(BitCube4::rotate_all_set(BitCube4::from(SUBCUBE_0)), HashSet::from([BitCube4::from(SUBCUBE_0), BitCube4::from(SUBCUBE_1), BitCube4::from(SUBCUBE_2), BitCube4::from(SUBCUBE_3), BitCube4::from(SUBCUBE_4), BitCube4::from(SUBCUBE_5), BitCube4::from(SUBCUBE_6), BitCube4::from(SUBCUBE_7)]));
            assert_eq!(BitCube4::rotate_all_set(BitCube4(0x3)).len(), 24);
        }

        #[test]
        fn test_rotate_all_vec() {
            assert_eq!(BitCube4::rotate_all_vec(BitCube4::from(BC4_CENTER_ALL)).as_slice(), &[BitCube4::from(BC4_CENTER_ALL)]);
            assert_eq!(BitCube4::rotate_all_vec(BitCube4::from(BC4_CENTER_X)).as_slice(), &[BitCube4::from(BC4_CENTER_X), BitCube4::from(BC4_CENTER_Y), BitCube4::from(BC4_CENTER_Z)]);
            assert_eq!(BitCube4::rotate_all_vec(BitCube4::from(SUBCUBE_0)).len(), 8);
            assert_eq!(BitCube4::rotate_all_vec(BitCube4::from(SUBCUBE_0)).as_slice(), &[BitCube4(0x0000000000330033), BitCube4(0x0000000000cc00cc), BitCube4(0x0000000033003300), BitCube4(0x00000000cc00cc00), BitCube4(0x0033003300000000), BitCube4(0x00cc00cc00000000), BitCube4(0x3300330000000000), BitCube4(0xcc00cc0000000000)]);
            assert_eq!(BitCube4::rotate_all_vec(BitCube4::from(SUBCUBE_0)).as_slice(), &[BitCube4::from(SUBCUBE_0), BitCube4::from(SUBCUBE_1), BitCube4::from(SUBCUBE_2), BitCube4::from(SUBCUBE_3), BitCube4::from(SUBCUBE_4), BitCube4::from(SUBCUBE_5), BitCube4::from(SUBCUBE_6), BitCube4::from(SUBCUBE_7)]);
            assert_eq!(BitCube4::rotate_all_vec(BitCube4(0x3)).len(), 24);

        }

        #[test]
        fn test_origin_rotate_all() {
            assert_eq!(BitCube4::origin_rotate_all(BitCube4::from(BC4_CENTER_ALL)).as_slice(), &[BitCube4::from(BC4_CENTER_ALL)]);
            assert_eq!(BitCube4::origin_rotate_all(BitCube4::from(BC4_CENTER_X)).as_slice(), &[BitCube4(0x0000000000ff00ff), BitCube4(0x0000000033333333), BitCube4(0x0033003300330033)]);
            assert_eq!(BitCube4::origin_rotate_all(BitCube4::from(SUBCUBE_0)).len(), 1);
            assert_eq!(BitCube4::origin_rotate_all(BitCube4::from(SUBCUBE_0)).as_slice(), &[BitCube4::from(SUBCUBE_0)]);
            assert_eq!(BitCube4::origin_rotate_all(BitCube4(0x3)).len(), 3);
            assert_eq!(BitCube4::origin_rotate_all(BitCube4(0x1011f)).len(), 24);

        }
    */
}