From a92f2d1f9fdf04f64790390ae18050b9b80dd453 Mon Sep 17 00:00:00 2001 From: Gavin Ridley Date: Wed, 5 Apr 2023 11:50:45 -0400 Subject: [PATCH] avoid segfault with idiomatic thresholding, rays through pixel centers --- src/plot.cpp | 12 +++++++----- .../plot_projections/results_true.dat | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 8912bb9b0..1f629e901 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1273,8 +1273,10 @@ void ProjectionPlot::create_output() const // Generate the starting position/direction of the ray if (orthographic_width_ == 0.0) { // perspective projection - double this_phi = -horiz_fov_radians / 2.0 + dphi * horiz; - double this_mu = -vert_fov_radians / 2.0 + dmu * vert + M_PI / 2.0; + double this_phi = + -horiz_fov_radians / 2.0 + dphi * horiz + 0.5 * dphi; + double this_mu = + -vert_fov_radians / 2.0 + dmu * vert + M_PI / 2.0 + 0.5 * dmu; Direction camera_local_vec; camera_local_vec.x = std::cos(this_phi) * std::sin(this_mu); camera_local_vec.y = std::sin(this_phi) * std::sin(this_mu); @@ -1436,9 +1438,9 @@ void ProjectionPlot::create_output() const if (i * i + j * j < wireframe_thickness_ * wireframe_thickness_) { // Check if wireframe pixel is out of bounds - int w_i = std::max(std::min(horiz + i, pixels_[0]), 0); - int w_j = std::max(std::min(vert + j, pixels_[1]), 0); - data(i, j) = wireframe_color_; + int w_i = std::max(std::min(horiz + i, pixels_[0] - 1), 0); + int w_j = std::max(std::min(vert + j, pixels_[1] - 1), 0); + data(w_i, w_j) = wireframe_color_; } } } diff --git a/tests/regression_tests/plot_projections/results_true.dat b/tests/regression_tests/plot_projections/results_true.dat index 64410ac93..a2cb57b1e 100644 --- a/tests/regression_tests/plot_projections/results_true.dat +++ b/tests/regression_tests/plot_projections/results_true.dat @@ -1 +1 @@ -a8c00451d0766c73a1c03769a12524fa4e08246e253fedd9f75c1b81889d3a71ff7782197090ca3aff4f58d8c863203028347338b3a1e3d78af14e3716482b96 \ No newline at end of file +6448093f8acaa2af02452ec1b29461ffaf89628bb002cc8873a3a6831fe5d613645a197033597e5a064896388f19d0782f05e78ce474354ae2a76c35ff4551d7 \ No newline at end of file