From 1daf4f35a5dd2f500d95541797661c518f4e2713 Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Fri, 13 Dec 2019 01:40:50 +0100 Subject: Replace vectors with slices for plotting data --- src/main.rs | 2 +- src/plot/gnuplot.rs | 10 +++++----- src/plot/mod.rs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index d7e9609..ab88302 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use plot::Graph; fn main() { println!("Hello, world!"); plot::Gnuplot::plot3d( - vec![ + &[ [ 0.14285714285714296, 0.5714285714285717, diff --git a/src/plot/gnuplot.rs b/src/plot/gnuplot.rs index b0d63d8..ea52a18 100644 --- a/src/plot/gnuplot.rs +++ b/src/plot/gnuplot.rs @@ -8,7 +8,7 @@ pub struct Gnuplot; impl Gnuplot { fn exec_plot( - data: Vec<[f64; 6]>, + data: &[[f64; 6]], chunk_size: u32, start: usize, end: usize, @@ -43,27 +43,27 @@ impl Gnuplot { } impl super::Graph for Gnuplot { - fn plot3d(data: Vec<[f64; 6]>, chunk_size: u32) { + fn plot3d(data: &[[f64; 6]], chunk_size: u32) { let iterations = data.len() / chunk_size as usize; match Gnuplot::exec_plot(data, chunk_size, 1, iterations, "anim3d.plt") { Ok(mut process) => println!("opening gnuplot {:?}", process.wait()), Err(err) => println!("failed to start gnuplot: {}", err), } } - fn animate3d(data: Vec<[f64; 6]>, chunk_size: u32, start: usize, end: usize) { + fn animate3d(data: &[[f64; 6]], chunk_size: u32, start: usize, end: usize) { match Gnuplot::exec_plot(data, chunk_size, start, end, "anim3d.plt") { Ok(mut process) => println!("opening gnuplot {:?}", process.wait()), Err(err) => println!("failed to start gnuplot: {}", err), } } - fn plot2d(data: Vec<[f64; 6]>, chunk_size: u32) { + fn plot2d(data: &[[f64; 6]], chunk_size: u32) { let iterations = data.len() / chunk_size as usize; match Gnuplot::exec_plot(data, chunk_size, 1, iterations, "anim2d.plt") { Ok(mut process) => println!("opening gnuplot {:?}", process.wait()), Err(err) => println!("failed to start gnuplot: {}", err), } } - fn animate2d(data: Vec<[f64; 6]>, chunk_size: u32, start: usize, end: usize) { + fn animate2d(data: &[[f64; 6]], chunk_size: u32, start: usize, end: usize) { match Gnuplot::exec_plot(data, chunk_size, start, end, "anim2d.plt") { Ok(mut process) => println!("opening gnuplot {:?}", process.wait()), Err(err) => println!("failed to start gnuplot: {}", err), diff --git a/src/plot/mod.rs b/src/plot/mod.rs index 8773020..1124128 100644 --- a/src/plot/mod.rs +++ b/src/plot/mod.rs @@ -2,8 +2,8 @@ pub mod gnuplot; pub use gnuplot::Gnuplot; pub trait Graph { - fn plot3d(data: Vec<[f64; 6]>, chunk_size: u32); - fn animate3d(data: Vec<[f64; 6]>, chunk_size: u32, start: usize, end: usize); - fn plot2d(data: Vec<[f64; 6]>, chunk_size: u32); - fn animate2d(data: Vec<[f64; 6]>, chunk_size: u32, start: usize, end: usize); + fn plot3d(data: &[[f64; 6]], chunk_size: u32); + fn animate3d(data: &[[f64; 6]], chunk_size: u32, start: usize, end: usize); + fn plot2d(data: &[[f64; 6]], chunk_size: u32); + fn animate2d(data: &[[f64; 6]], chunk_size: u32, start: usize, end: usize); } -- cgit v1.2.3-70-g09d2