Skip to content

Commit

Permalink
Fix clang-tidy warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaander committed Feb 3, 2025
1 parent dfd0b04 commit b200a8d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
36 changes: 22 additions & 14 deletions freud/environment/AngularSeparation.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
// Copyright (c) 2010-2024 The Regents of the University of Michigan
// This file is from the freud project, released under the BSD 3-Clause License.

#include <cmath>
#include <memory>
#include <vector>

#include "AngularSeparation.h"
#include "ManagedArray.h"
#include "NeighborComputeFunctional.h"
#include "NeighborQuery.h"
#include "VectorMath.h"
#include "utils.h"

/*! \file AngularSeparation.cc
Expand All @@ -13,7 +20,7 @@ namespace freud { namespace environment {

float computeSeparationAngle(const quat<float>& ref_q, const quat<float>& q)
{
quat<float> R = q * conj(ref_q);
const quat<float> R = q * conj(ref_q);
auto theta = float(2.0 * std::acos(util::clamp(R.s, -1, 1)));
return theta;
}
Expand All @@ -25,20 +32,20 @@ float computeSeparationAngle(const quat<float>& ref_q, const quat<float>& q)
float computeMinSeparationAngle(const quat<float>& ref_q, const quat<float>& q, const quat<float>* equiv_qs,
unsigned int n_equiv_quats)
{
quat<float> qconst = equiv_qs[0];
const quat<float> qconst = equiv_qs[0];
// here we undo a rotation represented by one of the equivalent orientations
quat<float> qtemp = q * conj(qconst);
const quat<float> qtemp = q * conj(qconst);

// start with the quaternion before it has been rotated by equivalent rotations
float min_angle = computeSeparationAngle(ref_q, q);

// loop through all equivalent rotations and see if they have smaller angles with ref_q
for (unsigned int i = 0; i < n_equiv_quats; ++i)
{
quat<float> qe = equiv_qs[i];
quat<float> qtest = qtemp * qe;
const quat<float> qe = equiv_qs[i];
const quat<float> qtest = qtemp * qe;

float angle_test = computeSeparationAngle(ref_q, qtest);
const float angle_test = computeSeparationAngle(ref_q, qtest);

if (angle_test < min_angle)
{
Expand All @@ -49,12 +56,12 @@ float computeMinSeparationAngle(const quat<float>& ref_q, const quat<float>& q,
return min_angle;
}

void AngularSeparationNeighbor::compute(const std::shared_ptr<locality::NeighborQuery> nq,
void AngularSeparationNeighbor::compute(const std::shared_ptr<locality::NeighborQuery>& nq,
const quat<float>* orientations, const vec3<float>* query_points,
const quat<float>* query_orientations, unsigned int n_query_points,
const quat<float>* equiv_orientations,
unsigned int n_equiv_orientations,
const std::shared_ptr<locality::NeighborList> nlist,
const std::shared_ptr<locality::NeighborList>& nlist,
const locality::QueryArgs& qargs)
{
// This function requires a NeighborList object, so we always make one and store it locally.
Expand All @@ -68,14 +75,15 @@ void AngularSeparationNeighbor::compute(const std::shared_ptr<locality::Neighbor
size_t bond(m_nlist->find_first_index(begin));
for (size_t i = begin; i < end; ++i)
{
quat<float> q = orientations[i];
const quat<float> q = orientations[i];

for (; bond < tot_num_neigh && (*m_nlist->getNeighbors())(bond, 0) == i; ++bond)
{
const size_t j((*m_nlist->getNeighbors())(bond, 1));
quat<float> query_q = query_orientations[j];
const quat<float> query_q = query_orientations[j];

float theta = computeMinSeparationAngle(q, query_q, equiv_orientations, n_equiv_orientations);
const float theta
= computeMinSeparationAngle(q, query_q, equiv_orientations, n_equiv_orientations);
(*m_angles)[bond] = theta;
}
}
Expand All @@ -92,11 +100,11 @@ void AngularSeparationGlobal::compute(const quat<float>* global_orientations, un
util::forLoopWrapper(0, n_points, [&](size_t begin, size_t end) {
for (size_t i = begin; i < end; ++i)
{
quat<float> q = orientations[i];
const quat<float> q = orientations[i];
for (unsigned int j = 0; j < n_global; j++)
{
quat<float> global_q = global_orientations[j];
float theta
const quat<float> global_q = global_orientations[j];
const float theta
= computeMinSeparationAngle(q, global_q, equiv_orientations, n_equiv_orientations);
(*m_angles)(i, j) = theta;
}
Expand Down
4 changes: 2 additions & 2 deletions freud/environment/AngularSeparation.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ class AngularSeparationNeighbor
~AngularSeparationNeighbor() = default;

//! Compute the angular separation between neighbors
void compute(const std::shared_ptr<locality::NeighborQuery> nq, const quat<float>* orientations,
void compute(const std::shared_ptr<locality::NeighborQuery>& nq, const quat<float>* orientations,
const vec3<float>* query_points, const quat<float>* query_orientations,
unsigned int n_query_points, const quat<float>* equiv_orientations,
unsigned int n_equiv_orientations, const std::shared_ptr<locality::NeighborList> nlist,
unsigned int n_equiv_orientations, const std::shared_ptr<locality::NeighborList>& nlist,
const locality::QueryArgs& qargs);

//! Returns the last computed neighbor angle array
Expand Down
17 changes: 15 additions & 2 deletions freud/environment/LocalDescriptors.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
// Copyright (c) 2010-2024 The Regents of the University of Michigan
// This file is from the freud project, released under the BSD 3-Clause License.

#include <algorithm>
#include <cmath>
#include <complex>
#include <limits>
#include <math.h> // NOLINT(modernize-deprecated-headers): Use std::numbers when c++20 is default.
#include <memory>
#include <stdexcept>
#include <vector>

#include "Box.h"
#include "LocalDescriptors.h"
#include "ManagedArray.h"
#include "NeighborComputeFunctional.h"
#include "NeighborList.h"
#include "NeighborQuery.h"
#include "VectorMath.h"
#include "diagonalize.h"
#include "utils.h"

/*! \file LocalDescriptors.cc
\brief Computes local descriptors.
Expand All @@ -18,10 +31,10 @@ LocalDescriptors::LocalDescriptors(unsigned int l_max, bool negative_m,
: m_l_max(l_max), m_negative_m(negative_m), m_nSphs(0), m_orientation(orientation)
{}

void LocalDescriptors::compute(const std::shared_ptr<locality::NeighborQuery> nq,
void LocalDescriptors::compute(const std::shared_ptr<locality::NeighborQuery>& nq,
const vec3<float>* query_points, unsigned int n_query_points,
const quat<float>* orientations,
const std::shared_ptr<locality::NeighborList> nlist,
const std::shared_ptr<locality::NeighborList>& nlist,
const locality::QueryArgs& qargs, unsigned int max_num_neighbors)
{
// This function requires a NeighborList object, so we always make one and store it locally.
Expand Down
4 changes: 2 additions & 2 deletions freud/environment/LocalDescriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class LocalDescriptors

//! Compute the local neighborhood descriptors given some
//! positions and the number of particles
void compute(const std::shared_ptr<locality::NeighborQuery> nq, const vec3<float>* query_points,
void compute(const std::shared_ptr<locality::NeighborQuery>& nq, const vec3<float>* query_points,
unsigned int n_query_points, const quat<float>* orientations,
const std::shared_ptr<locality::NeighborList> nlist, const locality::QueryArgs& qargs,
const std::shared_ptr<locality::NeighborList>& nlist, const locality::QueryArgs& qargs,
unsigned int max_num_neighbor);

//! Get a reference to the last computed spherical harmonic array
Expand Down

0 comments on commit b200a8d

Please sign in to comment.