diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2017-02-10 12:19:46 -0500 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2017-02-10 12:19:46 -0500 |
commit | 0ef0c0ce1d904be2b4e1f4da62dc029d8572c983 (patch) | |
tree | 12978013d870186240c08d1fdd6a7ce8781bca93 /lib/geometry.c | |
parent | 9a93a3b88a604672f557950e6c7f3fe815bcf163 (diff) | |
parent | 901b9f16494f37890be17ef4bb66e6efc6873340 (diff) | |
download | fuse_networks-0ef0c0ce1d904be2b4e1f4da62dc029d8572c983.tar.gz fuse_networks-0ef0c0ce1d904be2b4e1f4da62dc029d8572c983.tar.bz2 fuse_networks-0ef0c0ce1d904be2b4e1f4da62dc029d8572c983.zip |
Merge branch 'tmp'
Diffstat (limited to 'lib/geometry.c')
-rw-r--r-- | lib/geometry.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/geometry.c b/lib/geometry.c new file mode 100644 index 0000000..ec788f1 --- /dev/null +++ b/lib/geometry.c @@ -0,0 +1,55 @@ + +#include "fracture.h" + +int edge_to_verts(unsigned int width, bool periodic, unsigned int edge, + bool index) { + assert(edge < pow(width, 2)); + + int x = edge / width + 1; + int y = edge % width + 1; + + if (periodic) { + return (((index ^ (x % 2)) + 2 * ((y + (index ^ (!(x % 2)))) / 2) - 1) % + width + + (x - index) * width) / + 2; + } else { + return ((index ^ (x % 2)) + 2 * ((y + (index ^ (!(x % 2)))) / 2) + + (x - index) * (width + 1) - 1) / + 2; + } +} + +int dual_edge_to_verts(unsigned int width, bool periodic, unsigned int edge, + bool index) { + assert(edge < pow(width, 2)); + + int x = edge / width + 1; + int y = edge % width + 1; + + if (periodic) { + return (((index ^ (!(x % 2))) + 2 * ((y + (index ^ (x % 2))) / 2) - 1) % + width + + (x - index) * width) / + 2; + } else { + return ((index ^ (!(x % 2))) + 2 * ((y + (index ^ (x % 2))) / 2) + + (x - index) * (width + 1) - 1) / + 2; + } +} + +double dual_vert_to_coord(unsigned int width, bool periodic, unsigned int vert, + bool index) { + if (periodic) { + if (index) + return (2 * vert) % width + (2 * vert / width) % 2; + else + return 2 * vert / width; + } else { + if (index) + return (2 * vert) % (width + 1); + else + return (2 * vert) / (width + 1); + } +} |