ABRG-Models / morphologica

A library of supporting code for numerical modelling (JSON config, HDF5 data, Modern OpenGL visualization)
https://abrg-models.github.io/morphologica/
Apache License 2.0
260 stars 30 forks source link

Correct rounding error in number of pixel computation and grid drawing #259

Closed fabien-colonnier closed 1 month ago

fabien-colonnier commented 1 month ago

I realized the indexing of the grid was wrong due to a rounding error. I corrected it and tested it is correct while updating grid_border example to have different width and height. It highlighted another error in the full grid drawing with an added column. It is corrected too.

sebjameswml commented 1 month ago

Just apply this diff - essentially just changing step to 0.64f so that the text for the grids in grid_border all show.

diff --git a/examples/grid_border.cpp b/examples/grid_border.cpp
index 9fc7051e..04994027 100644
--- a/examples/grid_border.cpp
+++ b/examples/grid_border.cpp
@@ -42,7 +42,7 @@ int main()
         data[ri][0] =  static_cast<double>(std::rand()) / RAND_MAX ; // Range 0->1
     }

-    float step = 0.6f;
+    float step = 0.64f;
     // Add a GridVisual to display the Grid within the morph::Visual scene
     morph::vec<float, 3> offset = { -step * grid.width(), step * grid.height(), 0.0f };

@@ -175,7 +175,7 @@ int main()
     gv->setVectorData (&data);
     gv->cm.setType (morph::ColourMapType::Twilight);
     gv->zScale.setParams(0.0f, 0.0f);
-    
+
     gv->showgrid = true;
     gv->grid_colour = morph::colour::red;
     gv->grid_thickness = 0.2f;

Then it'll be good to merge.

fabien-colonnier commented 1 month ago

Thanks for spotting it, I corrected it. Let me know if there is anything else to change