corner-cases/cubelib Reference Documentation

CDEF:

cubelib_corner_t Overview

The cubelib_corner_t represents the corner of a cube.

  • There are 8 corners in a cube.

You can use it to:

  • Obtain a corner via 3 unit cube coordinates, i.e coordinates in \(\left\{0,1\right\}^3\), such as \((0,0,1)\) and \((1,0,1)\),
    • Retrieve x, y, z unit-cube coordinates,
  • Obrain a corner via 3 origin-centered cube coordinates, i.e coordinates in \(\left\{-1,+1\right\}^3\),, such as \((-1,-1,+1)\) and \((+1,-1,+1)\),
    • Retrieve x, y, z origin centered coordinates,
  • Obtain all (3) adjacent corners,

  • Push a corner in a direction, to a neighboring corner (no wrap around),

  • Move a corner in a direction, to a neighboring corner (with wrap around),

  • Obtain adjacent (3) faces,

  • Obtain or (3) adjacent edges,

  • Obtain the opposite corner,

  • Retrieve an index suitable for array storage,
    • The index is naturally in 3D morton-order for the cube-space,
    • And the inverse, retrieve a corner via its index

cubelib_direction_t Overview

The cubelib_direction_t represents a direction in the cube.

  • Directions and faces are related 1:1.
  • There are 6 directions for 6 faces.
  • Directions and faces and are convertible to each-other. They are separated because they intuitively separate certain functionality.

Once again, you can do things like:

  • Obtain a direction via 3 vector coordinates, representing the direction as a relative vector from origin

    , i.e coordinates in {0,-1,+1}^3, such as \((+0,0,+1)\) and \((0,-1,0)\),

    • Retrieve x, y, z vector coordinates,
  • Check if a direction is positive, i.e if it’s non-zero coordinate is positive,

  • Obtain the opposite direction,

  • Retrieve an index suitable for array storage,
    • And the inverse, retrieve a direction via its index
  • Convert it to a face.

cubelib_edge_t Overview

The cubelib_edge_t represents the edge of a cube.

  • There are 12 edges in a cube.

You can use it to:

  • Obtain the lower and upper corners of the edge,

  • Obtain all (4) adjacent edges,

  • Obtain all (2) adjacent faces,

  • Obtain the opposite edge,

  • Retrieve an index suitable for array storage,
    • And the inverse, retrieve a edge via its index

cubelib_face_t Overview

The cubelib_face_t represents the face of a cube.

  • There are 6 faces in a cube.

You can use it to:

  • Obtain the opposite face,

  • Obtain all (4) adjacent faces,

  • Obtain all (4) corners lying on the face,

  • Obtain all (4) edges. lying on the face,

  • Retrieve an index suitable for array storage,
    • And the inverse, retrieve a face via its index
  • Reason about sets of faces (using cubelib_face_set_t),

  • Convert it to a direction.

Usage

 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
#include <cubelib/cubelib.h>
#include <cubelib/formatters.hpp>
#include <iostream>
#include <cassert>

int main(){
  //get the far corner of the cube
  cubelib_corner_t corner0 = cubelib_get_corner_by_int3(+1,+1,+1);

  //one can think of the cube as having a length of 2, and lying in a 3D cartesian graph.
  //One can think of the cube's center lying at the origin of the space,
  // with the x-axis going off to the "right", the y-axis going "up", and the z-axis going into the
  // "depth" of space. The particulars of how you imagine this is up to you, as long as you remain consistent.
  
  

  cubelib_corner_t corner1 = cubelib_get_corner_by_int3(-1,-1,-1);
  
  
  //corner1 and corner0 are opposite corners of the cube
  assert(cubelib_is_corner_equal(cubelib_get_opposite_corner(corner1), corner0));
  
  //"push" the corner to the right
  corner1 = cubelib_corner_push(corner1, cubelib_get_direction_by_int3(+1, 0, 0));
  
  //corner1 will now be at (+1,-1,-1)
  
  
  //"push" the corner to the right, again
  corner1 = cubelib_corner_push(corner1, cubelib_get_direction_by_int3(+1, 0, 0));
  
  //nothing will change, there is no where to go in that direction
  //corner1 will now be at (+1,-1,-1)
  
  //get the "adjacent" corner in that direction; this will wrap the corner around the to its original
  // value of (-1,-1,-1)
  corner1 = cubelib_get_adjacent_corner(corner1, cubelib_get_direction_by_int3(+1, 0, 0));
  
  //get a new corner at (+1,-1,-1)
  cubelib_corner_t corner2 = cubelib_get_adjacent_corner(corner1, cubelib_get_direction_by_int3(+1, 0, 0));
  
  //the corners are adjacent
  assert(cubelib_is_corner_adjacent_corner(corner1, corner2));
  
  //now we can get an edge from the two adjacent corners
  cubelib_edge_t edge0 = cubelib_get_edge_by_corners(corner1,corner2);
  
  //a bit-wise set for reasoning about sets of corners
  uint32_t corner_set;
  
  //note that we can use the range-based for loop for cubelib, if using it from C++11
  for (auto face : cubelib_faces_on_edge[cubelib_get_edge_index(edge0)])
  {
    //we can now iterate over the 2 faces that are adjacent to this edge.
    
    //get all the corners that touch these faces
    for (auto corner : cubelib_corners_on_face[cubelib_get_face_index(face)])
    {
        corner_set |= 1 << cubelib_get_corner_index(corner);
    }
  }
  
  //remove the original corners
  corner_set &= ~uint32_t(1 << cubelib_get_corner_index(corner1));
  corner_set &= ~uint32_t(1 << cubelib_get_corner_index(corner2));
  
  //print all the corners on the faces of edge0, aside from the corners of the edge itself
  for (auto corner : cubelib_all_corners)
  {
    if (((corner_set >> cubelib_get_corner_index(corner)) & 1) == 0)
        continue;
    std::cout << corner << std::endl;
  }
  
  return 0;
}