Skip to content

Commit

Permalink
avoid using <numbers> for getting pi
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshi84 committed Apr 28, 2024
1 parent 73e69fa commit 17f02d7
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <filesystem>
#include <functional>
#include <memory>
#include <numbers>
#include <cmath>
#include <numeric>
#include <fstream>
#include <sstream>
Expand All @@ -25,6 +25,8 @@
#include "random.h"

namespace globals {
extern const float pi;

// Given as command line arguments
extern std::string input_file;
extern std::string output_ext;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ std::shared_ptr<cyHairFile> cmd::exec::filter(std::shared_ptr<cyHairFile> hairfi
const float s = (la + lb + lc) / 2.0f;
const float A = std::sqrt(s * (s - la) * (s - lb) * (s - lc));
const float circumradius_reciprocal = A > 0.0f ? 1.0f / (la * lb * lc / (4.0f * A)) : 0.0f;
const float turning_angle = 180.0f - std::acos(std::clamp((la * la + lb * lb - lc * lc) / (2.0f * la * lb), -1.0f, 1.0f)) * 180.0f / std::numbers::pi_v<float>;
const float turning_angle = 180.0f - std::acos(std::clamp((la * la + lb * lb - lc * lc) / (2.0f * la * lb), -1.0f, 1.0f)) * 180.0f / globals::pi;

max_point_circumradius_reciprocal = std::max(max_point_circumradius_reciprocal, circumradius_reciprocal);
min_point_circumradius_reciprocal = std::min(min_point_circumradius_reciprocal, circumradius_reciprocal);
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/getcurvature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ std::shared_ptr<cyHairFile> cmd::exec::getcurvature(std::shared_ptr<cyHairFile>
const VectorXf tangent_cross_norm = tangent_cross.rowwise().norm();
const VectorXf turning_angle = tangent_cross_norm.array().asin();

const VectorXi is_straight = (turning_angle.array() < ::param.angle_threshold * std::numbers::pi / 180.0).cast<int>();
const VectorXi is_straight = (turning_angle.array() < ::param.angle_threshold * globals::pi / 180.0).cast<int>();

// If the strand is completely straight, simply set binormal to a random vector
if (is_straight.sum() == nsegs[i]-1) {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ std::shared_ptr<cyHairFile> cmd::exec::stats(std::shared_ptr<cyHairFile> hairfil
const float s = (la + lb + lc) / 2.0f;
const float A = std::sqrt(s * (s - la) * (s - lb) * (s - lc));
const float circumradius_reciprocal = A > 0.0f ? 1.0f / (la * lb * lc / (4.0f * A)) : 0.0f;
const float turning_angle = 180.0f - std::acos(std::clamp((la * la + lb * lb - lc * lc) / (2.0f * la * lb), -1.0f, 1.0f)) * 180.0f / std::numbers::pi_v<float>;
const float turning_angle = 180.0f - std::acos(std::clamp((la * la + lb * lb - lc * lc) / (2.0f * la * lb), -1.0f, 1.0f)) * 180.0f / globals::pi;

PointInfo point_info;
point_info.idx = offset + j + 1;
Expand Down
2 changes: 2 additions & 0 deletions src/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "io.h"

namespace globals {
const float pi = std::acos(-1.0f);

// Given as command line arguments
std::string input_file;
std::string output_ext;
Expand Down

0 comments on commit 17f02d7

Please sign in to comment.