-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotators.hxx
114 lines (89 loc) · 2.96 KB
/
rotators.hxx
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// yass: Yet Another Soma Solver
// Copyright (C) 2021 Mark R. Rubin aka "thanks4opensource"
//
// This file is part of yass.
//
// The yass program is free software: you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// The yass program is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// (LICENSE.txt) along with the yass program. If not, see
// <https://www.gnu.org/licenses/gpl.html>
#ifndef ROTATORS_H
#define ROTATORS_H
#if SOMA_MATRIX_ROTATION + SOMA_LAMBDA_ROTATION != 1
#error #define one and only one of SOMA_MATRIX_ROTATION or SOMA_LAMBDA_ROTATION
#endif
#include "position.hxx"
namespace soma {
// Utility for rotating Position objects around X,Y,Z coordinate system axes
// Two compile-time chosen techniques:
// 1) 3x3 matrix multiply of X,Y,Z values
// 2) Lambda functions to permute X,Y,Z components
// 24 different rotations: Original +Z coordinate axis rotated to
// one of +X, -X, +Y, -Y, +Z, -Z axes, and then 4 possible
// 90 degree rotations around that axis
//
class Rotators {
public:
enum {
POSX_POSY_POSZ = 0,
NEGY_POSX_POSZ = 1,
NEGX_NEGY_POSZ = 2,
POSY_NEGX_POSZ = 3,
NEGX_POSY_NEGZ = 4,
NEGY_NEGX_NEGZ = 5,
POSX_NEGY_NEGZ = 6,
POSY_POSX_NEGZ = 7,
POSX_NEGZ_POSY = 8,
POSZ_POSX_POSY = 9,
NEGX_POSZ_POSY = 10,
NEGZ_NEGX_POSY = 11,
POSX_POSZ_NEGY = 12,
NEGZ_POSX_NEGY = 13,
NEGX_NEGZ_NEGY = 14,
POSZ_NEGX_NEGY = 15,
NEGZ_POSY_POSX = 16,
NEGY_NEGZ_POSX = 17,
POSZ_NEGY_POSX = 18,
POSY_POSZ_POSX = 19,
POSZ_POSY_NEGX = 20,
NEGY_POSZ_NEGX = 21,
NEGZ_NEGY_NEGX = 22,
POSY_NEGZ_NEGX = 23,
MAX_NUMBER_OF_ORIENTATIONS,
};
static const unsigned Z_MIRRORED_OFFSET = MAX_NUMBER_OF_ORIENTATIONS ,
X_MIRRORED_OFFSET = MAX_NUMBER_OF_ORIENTATIONS * 2;
#ifdef SOMA_MATRIX_ROTATION
using RotatorGetter = const int(*)[3];
static RotatorGetter rotator(
const unsigned index)
{
return rotations[index];
}
#endif
#ifdef SOMA_LAMBDA_ROTATION
using RotatorGetter = Position(*)(Position);
static RotatorGetter rotator(
const unsigned index)
{
return rotations[index];
}
#endif
#ifdef SOMA_MATRIX_ROTATION
static const int rotations[MAX_NUMBER_OF_ORIENTATIONS * 3][3][3];
#endif
#ifdef SOMA_LAMBDA_ROTATION
static Position (*rotations[MAX_NUMBER_OF_ORIENTATIONS * 3])(const Position);
#endif
}; // class Rotators
} // namespace soma
#endif // ifndef ROTATORS_H