corner-cases/cubexx Reference Documentation¶
CDEF:
- Corners
- Directions
- Edges
- Faces
cubexx::corner_t Overview¶
The cubexx::corner_t represents the corner of a cube.
- There are 8 corners in a cube.
You can use it to:
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
Reason about sets of corners (using
cubexx::corner_set_t).
cubexx::direction_t Overview¶
The cubexx::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:
Check if a direction is positive, i.e if it’s non-zero coordinate is positive,
Obtain all (4) “adjacent” directions,
Obtain the opposite direction,
- Retrieve an index suitable for array storage,
- And the inverse, retrieve a direction via its index
Reason about sets of directions (using
cubexx::direction_set_t),Convert it to a face.
cubexx::edge_t Overview¶
The cubexx::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
Reason about sets of edges (using
cubexx::edge_set_t).
cubexx::face_t Overview¶
The cubexx::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
cubexx::face_set_t),Convert it to a direction.
cubexx::set_base_t Overview¶
cubexx comes with set types, which can be used to store and reason about combinations of
{corners,directions,edges,faces}. These set types inherit from the type cubexx::set_base_t.
The there is one set type for each {corners,directions,edges,faces}.
The set supports:
- insertion
- union
- difference
- erasure
- intersection
- membership testing
- iteration
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 | #include <cubexx/cubexx.hpp>
#include <cubexx/formatters.hpp>
#include <iostream>
#include <cassert>
int main(){
using cubexx::corner_t;
using cubexx::direction_t;
using cubexx::edge_t;
using cubexx::corner_set_t;
//get the far corner of the cube
corner_t corner0 = corner_t::get(+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.
corner_t corner1 = corner_t::get(-1,-1,-1);
//corner1 and corner0 are opposite corners of the cube
assert(corner1.opposite() == corner0);
//"push" the corner to the right
corner1 = corner1.push(direction_t::get(+1, 0, 0));
//corner1 will now be at (+1,-1,-1)
//"push" the corner to the right, again
corner1 = corner1.push(direction_t::get(+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 = corner1.adjacent(direction_t::get(+1, 0, 0));
//get a new corner at (+1,-1,-1)
corner_t corner2 = corner1.adjacent(direction_t::get(+1, 0, 0));
//the corners are adjacent
assert(corner1.is_adjacent(corner2));
//now we can get an edge from the two adjacent corners
edge_t edge0 = edge_t::get(corner1,corner2);
//a special bit-wise set for reasoning about sets of corners
corner_set_t corner_set;
for (auto face : edge0.faces())
{
//we can now iterate over the 2 faces that are adjacent to this edge.
//get all the corners that touch these faces
corner_set |= face.corners();
}
//remove the original corners
corner_set -= corner1;
corner_set -= corner2;
//print all the corners on the faces of edge0, aside from the corners of the edge itself
for (auto corner : corner_set)
{
std::cout << corner << std::endl;
}
return 0;
}
|