packages

plot::contour

On this page

Contours of a grid, by marching triangles: each cell splits along one diagonal into two triangles over which the data is linear, so no saddle is ambiguous. Lines cross each triangle in at most one segment and join into polylines through the edges they share. Filled bands clip the same triangles against the band's two levels (Sutherland-Hodgman): an exact partition of the grid whose edges are the lines; the pieces then merge into outlines (shared edges drop out). Coordinates are in grid units: column, row.

Structs

PiecesSource

pub struct Pieces

Polylines (or polygons): piece i is the points starts[i]..starts[i + 1] of xy.

nabi
let p = plot::contour::lines([0.0, 1.0, 0.0, 1.0], 2, 2, 0.5);
assert(p.starts.len() == p.len() + 1);
  • pub xy: List<f64>§

    Source
  • pub starts: List<usize>§

    Source
  • pub fn len(self) -> usize§

    Source

    The number of pieces.

    nabi
    assert(plot::contour::lines([0.0, 0.0, 0.0, 0.0], 2, 2, 0.5).len() == 0);
    

Functions

linesSource

pub fn lines(z: List<f64>, rows: usize, cols: usize, level: f64) -> Pieces

The contour lines of z (rows x cols, row-major) at level.

nabi
// A bump in the middle of a 3 x 3 grid: one closed ring.
let z = [0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0];
let p = plot::contour::lines(z, 3, 3, 1.0);
assert(p.len() == 1 && p.xy[0] == p.xy[p.xy.len() - 2]);

bandSource

pub fn band(z: List<f64>, rows: usize, cols: usize, lo: f64, hi: f64, last: bool) -> Pieces

Polygons covering where lo <= z < hi (z <= hi when last) on the triangles' linear interpolant, merged into outlines with holes wound the other way (fill nonzero).

nabi
let z = [0.0, 1.0, 0.0, 1.0];
let p = plot::contour::band(z, 2, 2, 0.0, 0.5, false);
assert(p.len() > 0);