Skip to content

Instantly share code, notes, and snippets.

@rowanj
Created March 20, 2012 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowanj/2131755 to your computer and use it in GitHub Desktop.
Save rowanj/2131755 to your computer and use it in GitHub Desktop.
#import <iostream>
struct Octree {
Octree() : index(created++){}
void print_index()
{
std::cout << "print_index() " << index << std::endl;
}
int index;
static int created;
};
int Octree::created = 0;
namespace detail
{
const unsigned int X_BIT = 1 << 0;
const unsigned int Y_BIT = 1 << 1;
const unsigned int Z_BIT = 1 << 2;
}
struct Nodes{
Octree subtree[8];
Octree& operator()(bool x, bool y, bool z)
{
return subtree
[
(x ? detail::X_BIT : 0) |
(y ? detail::Y_BIT : 0) |
(z ? detail::Z_BIT : 0)
];
}
};
int main()
{
Nodes nodes;
nodes(false, false, false).print_index();
nodes(false, false, true).print_index();
nodes(true, true, true).print_index();
return 0;
}
@rowanj
Copy link
Author

rowanj commented Mar 20, 2012

Dantes:test rowanj$ clang++ -o octree octree.cpp && ./octree
print_index() 0
print_index() 4
print_index() 7
Dantes:test rowanj$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment