diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-10-05 09:31:02 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-10-05 09:42:39 +0200 |
| commit | 9e698917cb5b332cdbf1969ddfe3840239106c8d (patch) | |
| tree | 1125917c5d281aff8acfd94292b8a3d3e370bc2d /src/cube_array.c | |
| parent | 99fabe8592a4022313b1cb0581881ee1bc6b1c99 (diff) | |
| download | nissy-core-9e698917cb5b332cdbf1969ddfe3840239106c8d.tar.gz nissy-core-9e698917cb5b332cdbf1969ddfe3840239106c8d.zip | |
Implemented compose; some cleanup
Diffstat (limited to 'src/cube_array.c')
| -rw-r--r-- | src/cube_array.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/cube_array.c b/src/cube_array.c index a051610..b0b5e1e 100644 --- a/src/cube_array.c +++ b/src/cube_array.c | |||
| @@ -25,6 +25,7 @@ The third bit is needed because x+y+1 can exceed 4. | |||
| 25 | #include <stdio.h> | 25 | #include <stdio.h> |
| 26 | #endif | 26 | #endif |
| 27 | 27 | ||
| 28 | #include "constants.h" | ||
| 28 | #include "cube.h" | 29 | #include "cube.h" |
| 29 | 30 | ||
| 30 | #define _c_ufr 0U | 31 | #define _c_ufr 0U |
| @@ -713,6 +714,32 @@ inverse_inconsistent: | |||
| 713 | cube_t | 714 | cube_t |
| 714 | compose(cube_t c1, cube_t c2) | 715 | compose(cube_t c1, cube_t c2) |
| 715 | { | 716 | { |
| 717 | uint8_t i, piece, orien, aux, auy; | ||
| 718 | cube_t ret = {0}; | ||
| 719 | |||
| 720 | #ifdef DEBUG | ||
| 721 | if (!isconsistent(c1) || !isconsistent(c2)) | ||
| 722 | goto compose_inconsistent; | ||
| 723 | #endif | ||
| 724 | |||
| 725 | for (i = 0; i < 12; i++) { | ||
| 726 | piece = c2.e[i] & _pbits; | ||
| 727 | orien = (c2.e[i] ^ c1.e[piece]) & _eobit; | ||
| 728 | ret.e[i] = (c1.e[piece] & _pbits) | orien; | ||
| 729 | } | ||
| 730 | |||
| 731 | for (i = 0; i < 8; i++) { | ||
| 732 | piece = c2.c[i] & _pbits; | ||
| 733 | aux = (c2.c[i] & _cobits) + (c1.c[piece] & _cobits); | ||
| 734 | auy = (aux + _ctwist_cw) >> 2U; | ||
| 735 | orien = (aux + auy) & _cobits2; | ||
| 736 | ret.c[i] = (c1.c[piece] & _pbits) | orien; | ||
| 737 | } | ||
| 738 | |||
| 739 | return ret; | ||
| 740 | |||
| 741 | compose_inconsistent: | ||
| 742 | fprintf(stderr, "compose error, inconsistent cube\n"); | ||
| 716 | return errorcube; | 743 | return errorcube; |
| 717 | } | 744 | } |
| 718 | 745 | ||
