Skip to content

quiver: nan issue when u or v entries have a 0 #279

@acxz

Description

@acxz

Bug category

  • bug - compilation error
  • bug - compilation warning
  • bug - runtime error
  • bug - runtime warning
  • bug - logic error

Describe the bug

When an entry for u or v is all zeros, the scaling results in u_scaled/v_scaled to have nans due to a division by u_max, v_max.

Steps to Reproduce

#include <cmath>
#include <matplot/matplot.h>

int main() {
    using namespace matplot;

    // Produces 10 entries
    auto x = iota(0, 2.0 / 20, 2);
    auto y = iota(0, 2.0 / 20, 2);

    // Produces 10 entries
    std::vector<double> theta;
    for (int t = 0; t < x.size(); t++) {
        theta.push_back(0 + 2 * M_PI / x.size() * t);
    }

    auto u =
        transform(theta, [](double theta) { return 1; });
    auto v =
        transform(theta, [](double theta) { return 0; });

    quiver(x, y, u, v);
    show();
    return 0;
}

Output

Details Empty plot with the following console output:
Press ENTER to continue...           line 21: warning: Skipping data file with no valid points

multiplot> plot  '-' with vectors linecolor rgb "0x000071BC" dashtype 1 linewidth 0.5 linetype -1
                                                                                                 ^
           line 21: x range is invalid

           line 42: warning: Skipping data file with no valid points

multiplot> plot  '-' with vectors linecolor rgb "0x000071BC" dashtype 1 linewidth 0.5 linetype -1
                                                                                                 ^
           line 42: x range is invalid

         line 42: warning: refresh not possible and replot is disabled
         line 42: warning: refresh not possible and replot is disabled
         line 42: warning: refresh not possible and replot is disabled
         line 42: warning: refresh not possible and replot is disabled

Platform

  • cross-platform issue - linux
  • cross-platform issue - windows
  • cross-platform issue - macos

Environment Details:

  • OS: Archlinux
  • OS Version: Rolling
  • Compiler: gcc
  • Compiler version: gcc-12.1.0

Additional context

Related discussion, which prompted me in discovering this bug: #278

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions