1use super::rgba_module_base::{RgbaModule, Rgba};
2use super::{ImplicitModule, ScalarParameter, InterpType};
3use super::curve::Curve;
4
5use std::rc::Rc;
6use std::cell::RefCell;
7
8pub struct RgbaCurve {
9 curve: Curve<Rgba>,
10 source: ScalarParameter,
11 itype: InterpType,
12}
13
14impl RgbaCurve {
15 pub fn with_interp_type(it: InterpType) -> RgbaCurve {
16 RgbaCurve {
17 curve: Curve::new(),
18 source: ScalarParameter::Value(0.0),
19 itype: it,
20 }
21 }
22
23 pub fn with_interp_type_capacity(it: InterpType, capacity: usize) -> RgbaCurve {
24 RgbaCurve {
25 curve: Curve::with_capacity(capacity),
26 source: ScalarParameter::Value(0.0),
27 itype: it,
28 }
29 }
30
31 pub fn push_point(&mut self, t: f64, r: f32, g: f32, b: f32, a: f32) {
32 self.curve.push_point(t, Rgba::with_all(r, g, b, a));
33 }
34
35 pub fn set_interp_type(&mut self, t: InterpType) {
36 self.itype = t;
37 }
38
39 pub fn set_source_value(&mut self, t: f64) {
40 self.source = ScalarParameter::Value(t);
41 }
42 pub fn set_source_module(&mut self, m: Rc<RefCell<ImplicitModule>>) {
43 self.source = ScalarParameter::Source(m);
44 }
45
46 pub fn clear_curve(&mut self) {
47 self.curve.clear();
48 }
49
50 #[inline(always)]
51 fn get(&mut self, t: f64) -> Rgba {
52 match self.itype {
53 InterpType::None => self.curve.no_interp(t),
54 InterpType::Linear => self.curve.linear_interp(t),
55 InterpType::Cubic => self.curve.cubic_interp(t),
56 InterpType::Quintic => self.curve.quintic_interp(t),
57 }
58 }
59}
60
61impl RgbaModule for RgbaCurve {
62 fn get_2d(&mut self, x: f64, y: f64) -> Rgba {
63 let t = self.source.get_2d(x, y);
64 self.get(t)
65 }
66 fn get_3d(&mut self, x: f64, y: f64, z: f64) -> Rgba {
67 let t = self.source.get_3d(x, y, z);
68 self.get(t)
69 }
70 fn get_4d(&mut self, x: f64, y: f64, z: f64, w: f64) -> Rgba {
71 let t = self.source.get_4d(x, y, z, w);
72 self.get(t)
73 }
74 fn get_6d(&mut self, x: f64, y: f64, z: f64, w: f64, u: f64, v: f64) -> Rgba {
75 let t = self.source.get_6d(x, y, z, w, u, v);
76 self.get(t)
77 }
78}