diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2021-01-17 16:14:08 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2021-01-17 16:14:08 -0300 |
commit | 7b2524be8efae04a80691743b06018a6b0fdbe3e (patch) | |
tree | 6952e47fdac5f0ce4afbf4eb4e25227918783812 /src/poly.rs | |
parent | 444181ff1a47ff87d1b8db8e0300eb17698b2b21 (diff) | |
download | bezier-7b2524be8efae04a80691743b06018a6b0fdbe3e.tar.gz bezier-7b2524be8efae04a80691743b06018a6b0fdbe3e.zip |
Pass external data to the fragment shader
Diffstat (limited to 'src/poly.rs')
-rw-r--r-- | src/poly.rs | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/poly.rs b/src/poly.rs index 7d964a4..9c70048 100644 --- a/src/poly.rs +++ b/src/poly.rs @@ -3,6 +3,7 @@ mod iter; use crate::number::Number; use iter::Iter; use std::ops::{Add, Div, Mul, Sub}; +use std::fmt; #[derive(PartialEq, Debug, Clone)] pub struct Poly { @@ -29,7 +30,7 @@ impl Poly { } } - fn degree(&self) -> usize { + pub fn degree(&self) -> usize { self.degree } @@ -109,21 +110,17 @@ impl Div for &Poly { } } -pub fn gcd(a: &Poly, b: &Poly) -> Poly { - let (_, c) = a / b; - if c.is_zero() { - b.clone() - } else { - gcd(b, &c) - } -} - -pub fn derivative(p: &Poly) -> Poly { - let mut v = vec![0.0; p.degree()]; - for i in 0..v.len() { - v[i] = p.data[i + 1] * (i + 1) as Number; +impl fmt::Display for &Poly { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut s = String::new(); + for i in 0..self.data.len() { + s.push_str(&self.data[i].clone().to_string()); + if i < self.data.len() - 1 { + s.push_str(", "); + } + } + write!(f, "{}", s) } - Poly::new(v) } #[cfg(test)] |