Skip to content

Commit

Permalink
fix(downsample_mask): make excluded() function resilient to roundin…
Browse files Browse the repository at this point in the history
…g errors

Signed-off-by: Max SCHMELLER <[email protected]>
  • Loading branch information
mojomex committed Jan 16, 2025
1 parent 88fb3d6 commit 91fc4b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ inline void dither(

auto should_keep = [denominator](uint32_t numerator, uint32_t pos) {
for (uint32_t i = 0; i < numerator; ++i) {
size_t dithered_pos = std::round(denominator / static_cast<double>(numerator) * i);
auto dithered_pos =
static_cast<size_t>(std::round(denominator / static_cast<double>(numerator) * i));
if (dithered_pos == pos) return true;
}
return false;
Expand Down Expand Up @@ -125,7 +126,7 @@ class DownsampleMaskFilter
{
double azi_normalized = (point.azimuth - azimuth_range_.min) / azimuth_range_.extent();

auto x = static_cast<ssize_t>(azi_normalized * mask_.cols());
auto x = static_cast<ssize_t>(std::round(azi_normalized * static_cast<double>(mask_.cols())));
auto y = point.channel;

bool x_out_of_bounds = x < 0 || x >= mask_.cols();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ TEST(TestDownsampleMask, TestFilter)
for (int32_t azimuth_mdeg = azi_range_mdeg.min - 1; azimuth_mdeg < azi_range_mdeg.max + 1;
azimuth_mdeg += azi_step_mdeg) {
for (uint8_t channel = 0; channel < n_channels + 1; ++channel) {
NebulaPoint p;
NebulaPoint p{};
p.channel = channel;
p.azimuth = nebula::drivers::deg2rad(azimuth_mdeg / 1000.);

Expand Down

0 comments on commit 91fc4b8

Please sign in to comment.