From 2ac02d5cd4fbf68b584e3b28a9aa0f14ea3e2700 Mon Sep 17 00:00:00 2001 From: Alex Blenkinsop Date: Wed, 22 Nov 2023 15:19:31 +0000 Subject: [PATCH 1/2] Removing unused arg (datum) warning that throws an error in PRs --- morph/Scale.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/morph/Scale.h b/morph/Scale.h index 1a4b3983..27964756 100644 --- a/morph/Scale.h +++ b/morph/Scale.h @@ -40,7 +40,6 @@ #include #include -#include #include #include #include @@ -315,7 +314,6 @@ namespace morph { throw std::runtime_error ("Unknown scaling"); } return rtn; - } virtual void compute_autoscale (T input_min, T input_max) From 888ff895e77098a6b24b2edda5c9f77b1a997bd4 Mon Sep 17 00:00:00 2001 From: Alex Blenkinsop Date: Wed, 29 Nov 2023 13:31:45 +0000 Subject: [PATCH 2/2] Adding indexFromCoords function --- morph/CartGrid.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/morph/CartGrid.h b/morph/CartGrid.h index 34fc5323..99abc013 100644 --- a/morph/CartGrid.h +++ b/morph/CartGrid.h @@ -20,6 +20,7 @@ #include #include #include +#include // If the CartGrid::save and CartGrid::load methods are required, define // CARTGRID_COMPILE_LOAD_AND_SAVE. A link to libhdf5 will be required in your program. @@ -86,6 +87,19 @@ namespace morph { alignas(alignof(std::vector)) std::vector d_x; alignas(alignof(std::vector)) std::vector 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& 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