Skip to content

Commit

Permalink
Minor cleanup of conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
mlund committed Jul 2, 2024
1 parent 6ba5bd0 commit e890321
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/atomdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,15 @@ void to_json(json& j, const AtomData& a)
}

/// Handles optional translational and rotational displacement
void set_dp_and_dprot(const json& j, AtomData& a)
void set_dp_and_dprot(const json& j, AtomData& atomdata)
{
a.dp = get_optional<double>(j, "dp");
if (a.dp.has_value()) { // Later use C++23 `and_then()`
a.dp = a.dp.value() * 1.0_angstrom;
// todo: use `std::optional::and_then()` when C++23 is available
if (const auto dp = get_optional<double>(j, "dp")) {
atomdata.dp = dp.value() * 1.0_angstrom;
}
a.dprot = get_optional<double>(j, "dprot");
if (a.dprot.has_value()) { // Later use C++23 `and_then()`
a.dprot = a.dprot.value() * 1.0_rad;
if (std::fabs(a.dprot.value()) > 2.0 * pc::pi) {
if (const auto dprot = get_optional<double>(j, "dprot")) {
atomdata.dprot = dprot.value() * 1.0_rad;
if (std::fabs(atomdata.dprot.value()) > 2.0 * pc::pi) {
faunus_logger->warn("rotational displacement should be between [0:2π]");
}
}
Expand Down

0 comments on commit e890321

Please sign in to comment.