Struct curve_sampling::Uniform
source · pub struct Uniform<F> { /* private fields */ }
Expand description
Options for uniform sampling graphs of function ℝ → ℝ.
See Sampling::uniform
.
Implementations§
source§impl<F> Uniform<F>where
F: FnMut(f64) -> f64,
impl<F> Uniform<F>where F: FnMut(f64) -> f64,
sourcepub fn n(self, n: usize) -> Self
pub fn n(self, n: usize) -> Self
Set the maximum number of evaluations of the function
to build the sampling. Panic if n < 2
.
Examples found in repository?
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(())
}
sourcepub fn viewport(self, vp: BoundingBox) -> Self
pub fn viewport(self, vp: BoundingBox) -> Self
Set the zone of interest for the sampling. Segments that end up outside this box will not be refined.
sourcepub fn init<'a, I>(self, ts: I) -> Selfwhere
I: IntoIterator<Item = &'a f64>,
pub fn init<'a, I>(self, ts: I) -> Selfwhere I: IntoIterator<Item = &'a f64>,
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).
sourcepub fn init_pt<'a, I>(self, pts: I) -> Selfwhere
I: IntoIterator<Item = &'a (f64, f64)>,
pub fn init_pt<'a, I>(self, pts: I) -> Selfwhere I: IntoIterator<Item = &'a (f64, f64)>,
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).
source§impl<F> Uniform<F>where
F: FnMut(f64) -> f64,
impl<F> Uniform<F>where F: FnMut(f64) -> f64,
sourcepub fn build(self) -> Sampling
pub fn build(self) -> Sampling
Return a uniform sampling of the function.
Examples found in repository?
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
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(())
}