Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
fweik committed Sep 25, 2018
1 parent 758a3c8 commit 2cfc028
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
11 changes: 5 additions & 6 deletions src/core/shapes/Torus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@

namespace Shapes {

int Torus::calculate_dist(const double *ppos, double *dist,
double *vec) const {
int Torus::calculate_dist(const double *ppos, double *dist, double *vec) const {
/* Coordinate transform to cylinder coords
with origin at m_center. */
Vector3d const c_dist = Vector3d(ppos, ppos + 3) - m_center;
auto const z = e_z * c_dist;
auto const r_vec = c_dist - z * e_z;
auto const r = r_vec.norm();

*dist = (sqrt(Utils::sqr(r - m_rad) + z*z) - m_tube_rad) * m_direction;
Vector3d const dir_vec = c_dist - r_vec * m_rad/r;
auto const dir_vec_norm = dir_vec/dir_vec.norm();
*dist = (sqrt(Utils::sqr(r - m_rad) + z * z) - m_tube_rad) * m_direction;
Vector3d const dir_vec = c_dist - r_vec * m_rad / r;
auto const dir_vec_norm = dir_vec / dir_vec.norm();
vec[0] = dir_vec_norm[0] * m_direction;
vec[1] = dir_vec_norm[1] * m_direction;
vec[2] = dir_vec_norm[2] * m_direction;

return 0;
}
}
} // namespace Shapes
12 changes: 5 additions & 7 deletions src/core/shapes/Torus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ class Torus : public Shape {
Vector3d e_z;

/** @brief Calculate derived parameters. */
void precalc() {
e_z = m_normal / m_normal.norm();
}
void precalc() { e_z = m_normal / m_normal.norm(); }

public:
Torus()
: m_center({0.0, 0.0, 0.0}), m_normal({1.0, 0.0, 0.0}), m_rad(0.0),
m_tube_rad(0.0), m_direction(1.0) { precalc(); }

m_tube_rad(0.0), m_direction(1.0) {
precalc();
}

double radius() const { return m_rad; }
void set_radius(double const &radius) {
Expand All @@ -55,7 +54,6 @@ class Torus : public Shape {

int calculate_dist(const double *ppos, double *dist,
double *vec) const override;

};
}
} // namespace Shapes
#endif
1 change: 0 additions & 1 deletion src/python/espressomd/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ class Stomatocyte(ScriptInterfaceHelper):


@script_interface_register

class Torus(ScriptInterfaceHelper):

"""
Expand Down
13 changes: 8 additions & 5 deletions src/script_interface/shapes/Torus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ namespace Shapes {
class Torus : public Shape {
using CoreShape = ::Shapes::Torus;
std::shared_ptr<::Shapes::Torus> m_torus;

public:
Torus() : m_torus(new ::Shapes::Torus()) {
add_parameters({{"radius", m_torus, &CoreShape::set_radius, &CoreShape::radius},
{"tube_radius", m_torus, &CoreShape::set_tube_radius, &CoreShape::tube_radius},
{"normal", m_torus, &CoreShape::set_normal, &CoreShape::normal},
{"center", m_torus, &CoreShape::center},
{"direction", m_torus, &CoreShape::direction}});
add_parameters(
{{"radius", m_torus, &CoreShape::set_radius, &CoreShape::radius},
{"tube_radius", m_torus, &CoreShape::set_tube_radius,
&CoreShape::tube_radius},
{"normal", m_torus, &CoreShape::set_normal, &CoreShape::normal},
{"center", m_torus, &CoreShape::center},
{"direction", m_torus, &CoreShape::direction}});
}

std::shared_ptr<::Shapes::Shape> shape() const override { return m_torus; }
Expand Down

0 comments on commit 2cfc028

Please sign in to comment.