Skip to content

Commit

Permalink
address code review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Young <[email protected]>
  • Loading branch information
TactfulDeity committed Nov 15, 2024
1 parent 0b3007b commit 3beea37
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 11 deletions.
11 changes: 9 additions & 2 deletions avogadro/core/color3f.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <array>

namespace Avogadro::Core {
namespace detail {
/** Used to represent Maximum RGB value as a float. */
constexpr float k_MaxRGBColorValue = 255.0f;
} // namespace detail

/**
* @class Color3f color3f.h <avogadro/core/color3f.h>
Expand Down Expand Up @@ -87,11 +91,14 @@ class Color3f

inline Color3f::Color3f(float r, float g, float b) : m_data({ r, g, b }) {}

// clang-format off
inline Color3f::Color3f(int r, int g, int b)
: m_data({ static_cast<float>(r) / 255.0f, static_cast<float>(g) / 255.0f,
static_cast<float>(b) / 255.0f })
: m_data({static_cast<float>(r) / detail::k_MaxRGBColorValue,
static_cast<float>(g) / detail::k_MaxRGBColorValue,
static_cast<float>(b) / detail::k_MaxRGBColorValue})
{
}
// clang-format on

inline void Color3f::set(float r, float g, float b)
{
Expand Down
2 changes: 1 addition & 1 deletion avogadro/core/crystaltools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ bool CrystalTools::niggliReduce(Molecule& molecule, Options opts)
*/
#define NIGGLI_DEBUG(step)

// Allow ADL for swap
// Allow Argument Dependent Lookup for swap
using std::swap;

// Perform iterative reduction:
Expand Down
3 changes: 2 additions & 1 deletion avogadro/core/gaussiansettools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ double GaussianSetTools::calculateSpinDensity(const Vector3& position) const

bool GaussianSetTools::isValid() const
{
return m_molecule && dynamic_cast<GaussianSet*>(m_molecule->basisSet());
return (m_molecule != nullptr) &&
(dynamic_cast<GaussianSet*>(m_molecule->basisSet()) != nullptr);
}

inline bool GaussianSetTools::isSmall(double val) const
Expand Down
2 changes: 1 addition & 1 deletion avogadro/core/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void Layer::removeLayer(size_t layer)

void Layer::swapLayer(Index a, Index b)
{
// Allow ADL for swap
// Allow Argument Dependent Lookup for swap
using std::swap;

swap(m_atomAndLayers[a], m_atomAndLayers[b]);
Expand Down
4 changes: 2 additions & 2 deletions avogadro/core/molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,15 +564,15 @@ Molecule::AtomType Molecule::addAtom(unsigned char number, Vector3 position3d)

void Molecule::swapBond(Index a, Index b)
{
// Allow ADL for swap
// Allow Argument Dependent Lookup for swap
using std::swap;

m_graph.swapEdgeIndices(a, b);
swap(m_bondOrders[a], m_bondOrders[b]);
}
void Molecule::swapAtom(Index a, Index b)
{
// Allow ADL for swap
// Allow Argument Dependent Lookup for swap
using std::swap;

Index max = a > b ? a : b;
Expand Down
25 changes: 24 additions & 1 deletion avogadro/core/ringperceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,26 @@ namespace {
class DistanceMatrix
{
public:
// swap function marked friend so it can only be found via Argument Dependent
// Lookup (ADL)
friend void swap(DistanceMatrix& first, DistanceMatrix& second)
{
// Enable ADL for the swap
using std::swap;

swap(first.m_size, second.m_size);
swap(first.m_values, second.m_values);
}

// construction and destruction
DistanceMatrix(size_t size);
DistanceMatrix(const DistanceMatrix& other);
~DistanceMatrix();

DistanceMatrix(const DistanceMatrix& other);

// intentional pass-by-value to leverage previous copy ctor
DistanceMatrix& operator=(DistanceMatrix other);

// operators
size_t operator()(size_t i, size_t j) const;
size_t& operator()(size_t i, size_t j);
Expand All @@ -51,6 +66,14 @@ DistanceMatrix::DistanceMatrix(const DistanceMatrix& other)
m_values);
}

DistanceMatrix& DistanceMatrix::operator=(DistanceMatrix other)
{
// will use friend swap function via Argument Dependent Lookup
swap(*this, other);

return *this;
}

DistanceMatrix::~DistanceMatrix()
{
delete[] m_values;
Expand Down
2 changes: 1 addition & 1 deletion avogadro/core/slaterset.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class AVOGADROCORE_EXPORT SlaterSet : public BasisSet
MatrixX& normalizedMatrix() { return m_normalized; }
MatrixX& densityMatrix() { return m_density; }

// Does nothing?
// Nonfunctional - Included for backwards compatibility
void outputAll();

private:
Expand Down
5 changes: 3 additions & 2 deletions avogadro/core/slatersettools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ double SlaterSetTools::calculateSpinDensity(const Vector3&) const

bool SlaterSetTools::isValid() const
{
return m_molecule && dynamic_cast<SlaterSet*>(m_molecule->basisSet());
return (m_molecule != nullptr) &&
(dynamic_cast<SlaterSet*>(m_molecule->basisSet()) != nullptr);
}

inline bool SlaterSetTools::isSmall(double val) const
{
return val > -1e-20 && val < 1e-20;
return std::abs(val) < 1e-20;
}

std::vector<double> SlaterSetTools::calculateValues(
Expand Down

0 comments on commit 3beea37

Please sign in to comment.