1
2
3
4
5
6
7
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use litequad::prelude::Conf;
use crate::{render, Matrix, LineDesc, Desc};
pub struct Plot3D {
pub xs: Matrix,
pub ys: Matrix,
pub zs: Matrix,
pub line_desc: Vec<LineDesc>,
pub desc: Desc,
}
impl Plot3D {
pub fn new<A: Plot3DArg>(args: A) -> Plot3D {
args.as_plot()
}
pub fn add<A: Plot3DArg>(&mut self, args: A) {
let plot = args.as_plot();
self.xs.push(plot.xs[0].clone());
self.ys.push(plot.ys[0].clone());
self.zs.push(plot.zs[0].clone());
self.line_desc.push(plot.line_desc[0])
}
pub fn show(self) {
let conf = Conf {
window_width: 595,
window_height: 595,
..Default::default()
};
litequad::Window::from_config(conf, render::plot3d::run(self));
}
}
pub trait Plot3DArg {
fn as_plot(&self) -> Plot3D;
}
impl<const N: usize> Plot3DArg for ([f64; N], [f64; N], [f64; N]) {
fn as_plot(&self) -> Plot3D {
Plot3D {
xs: vec![self.0.to_vec()],
ys: vec![self.1.to_vec()],
zs: vec![self.2.to_vec()],
line_desc: vec![Default::default()],
desc: Default::default(),
}
}
}
impl<const N: usize> Plot3DArg for ([f64; N], [f64; N], [f64; N], &str) {
fn as_plot(&self) -> Plot3D {
Plot3D {
xs: vec![self.0.to_vec()],
ys: vec![self.1.to_vec()],
zs: vec![self.2.to_vec()],
line_desc: vec![self.3.into()],
desc: Default::default(),
}
}
}
impl<const N: usize> Plot3DArg for (&[f64; N], &[f64; N], &[f64; N], &str) {
fn as_plot(&self) -> Plot3D {
Plot3D {
xs: vec![self.0.to_vec()],
ys: vec![self.1.to_vec()],
zs: vec![self.2.to_vec()],
line_desc: vec![self.3.into()],
desc: Default::default(),
}
}
}
impl<const N: usize> Plot3DArg for (&[f64; N], &[f64; N], &[f64; N]) {
fn as_plot(&self) -> Plot3D {
Plot3D {
xs: vec![self.0.to_vec()],
ys: vec![self.1.to_vec()],
zs: vec![self.2.to_vec()],
line_desc: vec![Default::default()],
desc: Default::default(),
}
}
}
impl Plot3DArg for (&[f64], &[f64], &[f64], &str) {
fn as_plot(&self) -> Plot3D {
Plot3D {
xs: vec![self.0.to_vec()],
ys: vec![self.1.to_vec()],
zs: vec![self.2.to_vec()],
line_desc: vec![self.3.into()],
desc: Default::default(),
}
}
}
impl Plot3DArg for (&[f64], &[f64], &[f64]) {
fn as_plot(&self) -> Plot3D {
Plot3D {
xs: vec![self.0.to_vec()],
ys: vec![self.1.to_vec()],
zs: vec![self.2.to_vec()],
line_desc: vec![Default::default()],
desc: Default::default(),
}
}
}