Struct curve_sampling::Uniform

source ·
pub struct Uniform<F> { /* private fields */ }
Expand description

Options for uniform sampling graphs of function ℝ → ℝ. See Sampling::uniform.

Implementations§

Set the maximum number of evaluations of the function to build the sampling. Panic if n < 2.

Examples found in repository?
examples/latex_speed.rs (line 16)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() -> Result<(), Box<dyn Error>> {
    let path = "/tmp/latex_speed.tex";
    let mut fh = File::create(path)?;
    write!(fh, "\\documentclass[12pt,a4paper]{{article}}\n\
                \\usepackage{{tikz}}\n\
                \\begin{{document}}\n\
                \\begin{{tikzpicture}}\n")?;
    let n = 40_000;
    println!("Run \"latex {}\" measure LaTeX speed with {} points.\n",
             path, n);
    let s = Sampling::uniform(f64::sin, -6., 6.).n(n).build();
    s.latex().write(&mut fh)?;
    write!(fh, "\\end{{tikzpicture}}\n\
                \\end{{document}}")?;
    Ok(())
}

Set the zone of interest for the sampling. Segments that end up outside this box will not be refined.

Add initial values of t such that f(t) (see [Sampling :: uniform]) must be included into the sampling in addition to the n evaluations. Only the values between a and b are taken into account (other values are ignored).

Add initial points (t, f(t)) to include into the sampling in addition to the n evaluations. This allows you to use previous evaluations of f. Only the couples with first coordinate t between a and b (see [Sampling :: uniform]) are considered (other values are ignored).

Return a uniform sampling of the function.

Examples found in repository?
examples/latex_speed.rs (line 16)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() -> Result<(), Box<dyn Error>> {
    let path = "/tmp/latex_speed.tex";
    let mut fh = File::create(path)?;
    write!(fh, "\\documentclass[12pt,a4paper]{{article}}\n\
                \\usepackage{{tikz}}\n\
                \\begin{{document}}\n\
                \\begin{{tikzpicture}}\n")?;
    let n = 40_000;
    println!("Run \"latex {}\" measure LaTeX speed with {} points.\n",
             path, n);
    let s = Sampling::uniform(f64::sin, -6., 6.).n(n).build();
    s.latex().write(&mut fh)?;
    write!(fh, "\\end{{tikzpicture}}\n\
                \\end{{document}}")?;
    Ok(())
}
More examples
Hide additional examples
examples/arrows.rs (line 13)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
fn main() -> Result<(), Box<dyn Error>> {
    let s = Sampling::from_iter([[0., 0.], [1., 1.], [NAN, NAN],
                                 [1., 1.], [3., -1.]]);
    s.latex().arrow_pos(0.3).write(&mut File::create("/tmp/arrow0.tex")?)?;

    let s = Sampling::uniform(|x| -0.7 * (x - 1.).powi(2), 0., 2.5).build();
    s.latex().arrow_pos(0.6).write(&mut File::create("/tmp/arrow1.tex")?)?;


    File::create("/tmp/arrows.tex")?.write_all(
        r"\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=3cm, y=3cm]
  \draw[->] (-1.2, 0) -- (3.2, 0);
  \draw[->] (0, -1.2) -- (0, 1.7);
  \foreach \x in {-1, -0.5, 0.5, 1, 1.5,..., 3}{
    \draw (\x, 3pt) -- (\x, -3pt) node[below]{$\scriptstyle \x$};
  }
  \foreach \y in {-1, -0.5, 0.5, 1, 1.5}{
    \draw (3pt, \y) -- (-3pt, \y) node[left]{$\scriptstyle \y$};
  }
  \begin{scope}[color=blue, line width=1pt]
    \input{arrow0.tex}
  \end{scope}
  \begin{scope}[color=orange, line width=1pt]
    \input{arrow1.tex}
  \end{scope}
\end{tikzpicture}
\end{document}".as_bytes())?;

    std::env::set_current_dir("/tmp")?;
    Command::new("pdflatex")
        .args(["-interaction=batchmode", "arrows.tex"]).output()?;
    Ok(())
}

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.