Skip to content

Commit

Permalink
refactor: pass by value instead of reference for primitive types
Browse files Browse the repository at this point in the history
  • Loading branch information
FaaizHaikal committed Jan 5, 2025
1 parent d42f4a6 commit 2033394
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions include/keisan/interpolation/polynom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class Polynom
{
public:
Polynom(
const std::vector<double> & coefficients = {0.0}, const double & domain_min = 0.0,
const double & domain_max = 0.0);
const std::vector<double> & coefficients = {0.0}, double domain_min = 0.0,
double domain_max = 0.0);

bool is_in_domain(const double & x) const;
bool is_in_domain(double x) const;

double operator()(const double & x) const;
double operator()(double x) const;

bool operator==(const Polynom & other) const;
bool operator!=(const Polynom & other) const;
Expand Down
7 changes: 3 additions & 4 deletions include/keisan/interpolation/polynom.impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
namespace keisan
{

Polynom::Polynom(
const std::vector<double> & coefficients, const double & domain_min, const double & domain_max)
Polynom::Polynom(const std::vector<double> & coefficients, double domain_min, double domain_max)
: coefficients(coefficients), domain_min(domain_min), domain_max(domain_max)
{
}

bool Polynom::is_in_domain(const double & x) const { return x >= domain_min && x <= domain_max; }
bool Polynom::is_in_domain(double x) const { return x >= domain_min && x <= domain_max; }

double Polynom::operator()(const double & x) const
double Polynom::operator()(double x) const
{
double result = 0.0;

Expand Down
2 changes: 1 addition & 1 deletion include/keisan/interpolation/spline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Spline
public:
Spline(const std::vector<Polynom> & polynoms);

double operator()(const double & x) const;
double operator()(double x) const;

std::vector<Polynom> get_polynoms() const;

Expand Down
2 changes: 1 addition & 1 deletion include/keisan/interpolation/spline.impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Spline::Spline(const std::vector<Polynom> & polynoms)
this->polynoms = polynoms;
}

double Spline::operator()(const double & x) const
double Spline::operator()(double x) const
{
for (const auto & polynom : polynoms) {
if (polynom.is_in_domain(x)) {
Expand Down

0 comments on commit 2033394

Please sign in to comment.