Skip to content

Commit

Permalink
Merge pull request #151 from blenk13/main
Browse files Browse the repository at this point in the history
Adding indexFromCoord function to CartGrid class
  • Loading branch information
sebjameswml authored Nov 29, 2023
2 parents c5de1db + 888ff89 commit e1a1d2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 13 additions & 0 deletions morph/CartGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ namespace morph {
alignas(alignof(std::vector<float>)) std::vector<float> d_x;
alignas(alignof(std::vector<float>)) std::vector<float> d_y;

/*!
* For a given coordinate pair (x, y), the function returns the 1D index of the nearest cartgrid vertex
* This is a simplified version of "findRectNearest". findRectNearest can be used for non-recatngular grids.
* This function is for rectangular grids only.
*/
int indexFromCoord (morph::vec<float, 2>& coord)
{
int x_ind = std::round((coord.at(0) - x_minmax.min)/this->d); // Index of nearest column
int y_ind = std::round((coord.at(1) - y_minmax.min)/this->v); // Index of nearest row
int nc = int(((x_minmax.max - x_minmax.min)/this->d) + 1.0f); // Number of columns in rectangular cartgrid
return (nc * y_ind) + x_ind;
}

/*!
* Shift the supplied coordinates cds by the metric amounts x_shift and y_shift (to the
* nearest existing coordinate in the cartgrid) and return a vector of new coordinates. Only
Expand Down
2 changes: 0 additions & 2 deletions morph/Scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

#include <stdexcept>
#include <cmath>
#include <sstream>
#include <morph/MathAlgo.h>
#include <morph/number_type.h>
#include <morph/vvec.h>
Expand Down Expand Up @@ -315,7 +314,6 @@ namespace morph {
throw std::runtime_error ("Unknown scaling");
}
return rtn;

}

virtual void compute_autoscale (T input_min, T input_max)
Expand Down

0 comments on commit e1a1d2a

Please sign in to comment.