Skip to content

Commit

Permalink
simplify some point operator functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
MFraters committed Jul 3, 2021
1 parent f0721c8 commit a33f5fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions include/world_builder/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace WorldBuilder
inline
double operator*(const Point<dim> &point_right) const
{
const std::array<double,dim> array = point_right.get_array();
const std::array<double,dim>& array = point_right.get_array();
double dot_product = 0;
for (unsigned int i = 0; i < dim; ++i)
dot_product += point[i] * array[i];
Expand All @@ -107,9 +107,9 @@ namespace WorldBuilder
Point<dim> operator*(const double scalar) const
{
// initialize the array to zero.
std::array<double,dim> array = Point<dim>(coordinate_system).get_array();
std::array<double,dim> array;
for (unsigned int i = 0; i < dim; ++i)
array[i] += point[i] * scalar;
array[i] = point[i] * scalar;
return Point<dim>(array,coordinate_system);
}

Expand All @@ -120,10 +120,10 @@ namespace WorldBuilder
Point<dim> operator/(const double scalar) const
{
// initialize the array to zero.
std::array<double,dim> array = Point<dim>(coordinate_system).get_array();
std::array<double,dim> array;
const double one_over_scalar = 1/scalar;
for (unsigned int i = 0; i < dim; ++i)
array[i] += point[i] * one_over_scalar;
array[i] = point[i] * one_over_scalar;
return Point<dim>(array,coordinate_system);
}

Expand Down
2 changes: 1 addition & 1 deletion source/point.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ namespace WorldBuilder
operator/(const double scalar, const Point<dim> &point)
{
// initialize the array to zero.
std::array<double,dim> array = Point<dim>(point.coordinate_system).get_array();
std::array<double,dim> array;
for (unsigned int i = 0; i < dim; ++i)
array[i] = scalar / point[i];
return Point<dim>(array,point.coordinate_system);
Expand Down

0 comments on commit a33f5fc

Please sign in to comment.