Skip to content

Commit

Permalink
Rename pos/neg to remove ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj committed Jan 20, 2024
1 parent bafa987 commit 0b23d87
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/orange/transform/SignedPermutation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace celeritas
*/
SignedPermutation::SignedPermutation()
: SignedPermutation{
SignedAxes{{{pos, Axis::x}, {pos, Axis::y}, {pos, Axis::z}}}}
SignedAxes{{{psign, Axis::x}, {psign, Axis::y}, {psign, Axis::z}}}}
{
}

Expand All @@ -30,9 +30,9 @@ SignedPermutation::SignedPermutation(SignedAxes permutation) : compressed_{0}
for (auto ax : {Axis::z, Axis::y, Axis::x})
{
auto new_ax_sign = permutation[ax];
CELER_VALIDATE(new_ax_sign.first == pos || new_ax_sign.first == neg,
<< "invalid permutation sign '" << new_ax_sign.first
<< "'");
CELER_VALIDATE(
new_ax_sign.first == psign || new_ax_sign.first == msign,
<< "invalid permutation sign '" << new_ax_sign.first << "'");
CELER_VALIDATE(new_ax_sign.second < Axis::size_,
<< "invalid permutation axis");
CELER_VALIDATE(!encountered_ax[new_ax_sign.second],
Expand All @@ -42,7 +42,7 @@ SignedPermutation::SignedPermutation(SignedAxes permutation) : compressed_{0}

// Push back "flip bit"
compressed_ <<= 1;
compressed_ |= (new_ax_sign.first == neg ? 0b1 : 0b0);
compressed_ |= (new_ax_sign.first == msign ? 0b1 : 0b0);
// Push back "new axis"
compressed_ <<= 2;
compressed_ |= to_int(new_ax_sign.second);
Expand All @@ -64,7 +64,7 @@ auto SignedPermutation::permutation() const -> SignedAxes
result[ax].second = to_axis(temp & 0b11);
temp >>= 2;
// Push back "flip bit"
result[ax].first = temp & 0b1 ? neg : pos;
result[ax].first = temp & 0b1 ? msign : psign;
temp >>= 1;
}
return result;
Expand Down Expand Up @@ -93,8 +93,8 @@ SignedPermutation make_permutation(Axis ax, QuarterTurn theta)

auto to_sign = [](int v) {
if (v < 0)
return SignedPermutation::neg;
return SignedPermutation::pos;
return SignedPermutation::msign;
return SignedPermutation::psign;
};

int const cost = cos(theta);
Expand Down
11 changes: 6 additions & 5 deletions src/orange/transform/SignedPermutation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ namespace celeritas
* where \f$ \mathbf{e}_u \f$ is has exactly one entry with a value \f$ \pm 1
\f$ and the other entries being zero.
*
* TODO: implement error checking to prevent reflection.
*
* The underlying storage are a compressed series of bits in little-endian form
* that indicate the positions of the nonzero entry followed by the sign:
* \verbatim
Expand All @@ -42,14 +40,17 @@ namespace celeritas
* \endverbatim
* This allows the "rotate up" to simply copy one value at a time into a new
* position, and optionally flip the sign of the result.
*
* TODO: implement error checking to prevent reflection.
*/
class SignedPermutation
{
public:
//! Characters used for explicit construction
enum Sign : char
{
pos = '+',
neg = '-'
psign = '+',
msign = '-'
};

//!@{
Expand All @@ -64,7 +65,7 @@ class SignedPermutation
// Construct with an identity permutation
SignedPermutation();

//! Construct with the permutation vector
// Construct with the permutation vector
explicit SignedPermutation(SignedAxes permutation);

// Construct inline from storage
Expand Down
2 changes: 1 addition & 1 deletion test/orange/transform/SignedPermutation.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ std::string to_string(SignedPermutation::SignedAxes const& p)
std::string result;
for (auto ax : range(Axis::size_))
{
result.push_back(p[ax].first == SignedPermutation::pos ? '+' : '-');
result.push_back(p[ax].first);
result.push_back(to_char(p[ax].second));
result.push_back(',');
}
Expand Down

0 comments on commit 0b23d87

Please sign in to comment.