From: sfeam <sf...@us...> - 2017-10-29 22:22:35
|
On Sunday, 29 October 2017 13:26:39 Dima Kogan wrote: > Hi all, a non-version-control question for yall! > > I'm trying to plot a vector field (attached). The vectors start at an > evenly-spaced 20x20 grid. On my machine when I run the script, plotting > into an x11 terminal, I don't see all 400 vectors, I see maybe 1/4 of > them; the rest don't show up at all. It turns out what happens is this: > > do_plot() > { > ... > plot_vectors(); > ... > } > > plot_vectors() > { > ... > for(vectors) > { > double x1_data_coords, x2_data_coords, ...; > ... > int x1_terminal_coords = map_x(x1_data_coords); > int x2_terminal_coords = map_x(x2_data_coords); > ... > (terminal->arrow) (x1_terminal_coords, y1_terminal_coords, ...); > } > } > > arrow(int x1, int y1, ...) > { > if( x1 == x2 && y1 == y2 ) > return; > > ... > } > > > I.e. we convert the vector start/end to integer terminal coords; short > vectors become 0-vectors in this representation, so the > terminal-specific arrow() function plots nothing. > > This is a bug: checking for a 0-vector should happen before we convert > to integer pixel coordinates. I am not following the logic. If it is a 0-length vector then isn't it correct to not draw it? Even if you keep the floating point representation for a bit longer, at the time you convert to integer terminal coordinates it will again become 0-length and thus not drawn. What am I missing? Is the idea that you want to draw an arrowhead even if the shaft length is zero? Ethan > I'm attaching a patch series to fix this. The fundamental difference is > a change to the arrow() terminal callback to take FLOATING-POINT > terminal coordinates, so the vector direction, length can still be > accurately computed. This feels incomplete, since I suspect there're > other terminal functions that can benefit from such a change, but this > works. > > Note that these patches are made with 'git format-patch', so once the > conversion is complete, they should be applied with 'git am'. This > imports the patch series together with the commit metadata (author, > message, etc). > > > |