Skip to content

Commit

Permalink
Add |, &, and ~ logical operators for TriState.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Dec 6, 2024
1 parent a1a3343 commit ded9e8b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions include/lsst/sphgeom/TriState.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,44 @@ class TriState {
return not this->operator==(value);
}

/// @brief Compute the logical OR of two TriState values.
/// @param other Other TriState value.
/// @return True if either operand is known to be true, false if both
/// operands are known to be false, and unknown otherwise.
TriState operator|(TriState const & other) const {
if (*this == true || other == true) {
return TriState(true);
} else if (*this == false && other == false) {
return TriState(false);
} else {
return TriState();
}
}

/// @brief Compute the logical AND of two TriState values.
/// @param other Other TriState value.
/// @return False if either operand is known to be false, true if both
/// operands are known to be true, and unknown otherwise.
TriState operator&(TriState const & other) const {
if (*this == false || other == false) {
return TriState(false);
} else if (*this == true && other == true) {
return TriState(true);
} else {
return TriState();
}
}

/// @brief Compute the logical NOT of a TriState value.
/// @return True if the current state is known to be false, false if the
/// current state is known to be true, and unknown otherwise.
TriState operator~() const {
if (known()) {
return TriState(!_value);
}
return TriState();
}

/// @brief Check whether the state is known.
/// @return True is returned when state is known.
bool known() const { return _known; }
Expand Down
2 changes: 1 addition & 1 deletion tests/test_CompoundRegion.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import pickle
import unittest
from base64 import b64decode, b64encode
from base64 import b64encode

try:
import yaml
Expand Down

0 comments on commit ded9e8b

Please sign in to comment.