Skip to main content

ContourOpts

Struct ContourOpts 

Source
pub struct ContourOpts { /* private fields */ }

Implementations§

Source§

impl ContourOpts

Source

pub fn x_edges(self, e: Vec<f64>) -> Self

Examples found in repository?
examples/gen_hero_svgs.rs (line 228)
206fn contour() -> String {
207    let n = 41;
208    let pi = std::f64::consts::PI;
209    let grid: Vec<Vec<f64>> = (0..n)
210        .map(|j| {
211            let y = -pi + 2.0 * pi * j as f64 / (n - 1) as f64;
212            (0..n)
213                .map(|i| {
214                    let x = -pi + 2.0 * pi * i as f64 / (n - 1) as f64;
215                    x.sin() * y.cos()
216                })
217                .collect()
218        })
219        .collect();
220    let edges: Vec<f64> = (0..=n).map(|i| -pi + 2.0 * pi * i as f64 / n as f64).collect();
221
222    Figure::new()
223        .size(PaperSize::Square)
224        .title("sin(x) · cos(y)")
225        .xlabel("x")
226        .ylabel("y")
227        .contour(grid, |c| {
228            c.x_edges(edges.clone())
229                .y_edges(edges.clone())
230                .levels(vec![-0.8, -0.4, 0.0, 0.4, 0.8])
231        })
232        .to_svg()
233}
More examples
Hide additional examples
examples/contour.rs (line 31)
3fn main() {
4    // 41×41 grid of sin(x) · cos(y) over [-π, π]².
5    let n = 41;
6    let pi = std::f64::consts::PI;
7    let grid: Vec<Vec<f64>> = (0..n)
8        .map(|j| {
9            let y = -pi + 2.0 * pi * j as f64 / (n - 1) as f64;
10            (0..n)
11                .map(|i| {
12                    let x = -pi + 2.0 * pi * i as f64 / (n - 1) as f64;
13                    x.sin() * y.cos()
14                })
15                .collect()
16        })
17        .collect();
18
19    let edges: Vec<f64> = (0..=n)
20        .map(|i| -pi + 2.0 * pi * i as f64 / n as f64)
21        .collect();
22
23    let levels = vec![-0.8, -0.4, 0.0, 0.4, 0.8];
24
25    let fig = Figure::new()
26        .size(PaperSize::Square)
27        .title("sin(x) · cos(y)")
28        .xlabel("x")
29        .ylabel("y")
30        .contour(grid, |c| {
31            c.x_edges(edges.clone())
32                .y_edges(edges.clone())
33                .levels(levels)
34                .label("isolines")
35        })
36        .legend_top_right();
37
38    std::fs::create_dir_all("out").expect("create out/");
39    std::fs::write("out/contour.svg", fig.to_svg()).expect("write svg");
40    println!("wrote out/contour.svg");
41}
Source

pub fn y_edges(self, e: Vec<f64>) -> Self

Examples found in repository?
examples/gen_hero_svgs.rs (line 229)
206fn contour() -> String {
207    let n = 41;
208    let pi = std::f64::consts::PI;
209    let grid: Vec<Vec<f64>> = (0..n)
210        .map(|j| {
211            let y = -pi + 2.0 * pi * j as f64 / (n - 1) as f64;
212            (0..n)
213                .map(|i| {
214                    let x = -pi + 2.0 * pi * i as f64 / (n - 1) as f64;
215                    x.sin() * y.cos()
216                })
217                .collect()
218        })
219        .collect();
220    let edges: Vec<f64> = (0..=n).map(|i| -pi + 2.0 * pi * i as f64 / n as f64).collect();
221
222    Figure::new()
223        .size(PaperSize::Square)
224        .title("sin(x) · cos(y)")
225        .xlabel("x")
226        .ylabel("y")
227        .contour(grid, |c| {
228            c.x_edges(edges.clone())
229                .y_edges(edges.clone())
230                .levels(vec![-0.8, -0.4, 0.0, 0.4, 0.8])
231        })
232        .to_svg()
233}
More examples
Hide additional examples
examples/contour.rs (line 32)
3fn main() {
4    // 41×41 grid of sin(x) · cos(y) over [-π, π]².
5    let n = 41;
6    let pi = std::f64::consts::PI;
7    let grid: Vec<Vec<f64>> = (0..n)
8        .map(|j| {
9            let y = -pi + 2.0 * pi * j as f64 / (n - 1) as f64;
10            (0..n)
11                .map(|i| {
12                    let x = -pi + 2.0 * pi * i as f64 / (n - 1) as f64;
13                    x.sin() * y.cos()
14                })
15                .collect()
16        })
17        .collect();
18
19    let edges: Vec<f64> = (0..=n)
20        .map(|i| -pi + 2.0 * pi * i as f64 / n as f64)
21        .collect();
22
23    let levels = vec![-0.8, -0.4, 0.0, 0.4, 0.8];
24
25    let fig = Figure::new()
26        .size(PaperSize::Square)
27        .title("sin(x) · cos(y)")
28        .xlabel("x")
29        .ylabel("y")
30        .contour(grid, |c| {
31            c.x_edges(edges.clone())
32                .y_edges(edges.clone())
33                .levels(levels)
34                .label("isolines")
35        })
36        .legend_top_right();
37
38    std::fs::create_dir_all("out").expect("create out/");
39    std::fs::write("out/contour.svg", fig.to_svg()).expect("write svg");
40    println!("wrote out/contour.svg");
41}
Source

pub fn levels(self, l: Vec<f64>) -> Self

Examples found in repository?
examples/gen_hero_svgs.rs (line 230)
206fn contour() -> String {
207    let n = 41;
208    let pi = std::f64::consts::PI;
209    let grid: Vec<Vec<f64>> = (0..n)
210        .map(|j| {
211            let y = -pi + 2.0 * pi * j as f64 / (n - 1) as f64;
212            (0..n)
213                .map(|i| {
214                    let x = -pi + 2.0 * pi * i as f64 / (n - 1) as f64;
215                    x.sin() * y.cos()
216                })
217                .collect()
218        })
219        .collect();
220    let edges: Vec<f64> = (0..=n).map(|i| -pi + 2.0 * pi * i as f64 / n as f64).collect();
221
222    Figure::new()
223        .size(PaperSize::Square)
224        .title("sin(x) · cos(y)")
225        .xlabel("x")
226        .ylabel("y")
227        .contour(grid, |c| {
228            c.x_edges(edges.clone())
229                .y_edges(edges.clone())
230                .levels(vec![-0.8, -0.4, 0.0, 0.4, 0.8])
231        })
232        .to_svg()
233}
More examples
Hide additional examples
examples/contour.rs (line 33)
3fn main() {
4    // 41×41 grid of sin(x) · cos(y) over [-π, π]².
5    let n = 41;
6    let pi = std::f64::consts::PI;
7    let grid: Vec<Vec<f64>> = (0..n)
8        .map(|j| {
9            let y = -pi + 2.0 * pi * j as f64 / (n - 1) as f64;
10            (0..n)
11                .map(|i| {
12                    let x = -pi + 2.0 * pi * i as f64 / (n - 1) as f64;
13                    x.sin() * y.cos()
14                })
15                .collect()
16        })
17        .collect();
18
19    let edges: Vec<f64> = (0..=n)
20        .map(|i| -pi + 2.0 * pi * i as f64 / n as f64)
21        .collect();
22
23    let levels = vec![-0.8, -0.4, 0.0, 0.4, 0.8];
24
25    let fig = Figure::new()
26        .size(PaperSize::Square)
27        .title("sin(x) · cos(y)")
28        .xlabel("x")
29        .ylabel("y")
30        .contour(grid, |c| {
31            c.x_edges(edges.clone())
32                .y_edges(edges.clone())
33                .levels(levels)
34                .label("isolines")
35        })
36        .legend_top_right();
37
38    std::fs::create_dir_all("out").expect("create out/");
39    std::fs::write("out/contour.svg", fig.to_svg()).expect("write svg");
40    println!("wrote out/contour.svg");
41}
Source

pub fn origin(self, o: Origin) -> Self

Source

pub fn stroke(self, s: Stroke) -> Self

Source

pub fn stroke_width(self, w: f64) -> Self

Source

pub fn label(self, s: impl Into<String>) -> Self

Examples found in repository?
examples/contour.rs (line 34)
3fn main() {
4    // 41×41 grid of sin(x) · cos(y) over [-π, π]².
5    let n = 41;
6    let pi = std::f64::consts::PI;
7    let grid: Vec<Vec<f64>> = (0..n)
8        .map(|j| {
9            let y = -pi + 2.0 * pi * j as f64 / (n - 1) as f64;
10            (0..n)
11                .map(|i| {
12                    let x = -pi + 2.0 * pi * i as f64 / (n - 1) as f64;
13                    x.sin() * y.cos()
14                })
15                .collect()
16        })
17        .collect();
18
19    let edges: Vec<f64> = (0..=n)
20        .map(|i| -pi + 2.0 * pi * i as f64 / n as f64)
21        .collect();
22
23    let levels = vec![-0.8, -0.4, 0.0, 0.4, 0.8];
24
25    let fig = Figure::new()
26        .size(PaperSize::Square)
27        .title("sin(x) · cos(y)")
28        .xlabel("x")
29        .ylabel("y")
30        .contour(grid, |c| {
31            c.x_edges(edges.clone())
32                .y_edges(edges.clone())
33                .levels(levels)
34                .label("isolines")
35        })
36        .legend_top_right();
37
38    std::fs::create_dir_all("out").expect("create out/");
39    std::fs::write("out/contour.svg", fig.to_svg()).expect("write svg");
40    println!("wrote out/contour.svg");
41}

Trait Implementations§

Source§

impl Debug for ContourOpts

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ContourOpts

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.