This repository has no description
1use std::hash::Hash;
2
3#[cfg(feature = "web")]
4use wasm_bindgen::prelude::*;
5
6#[cfg_attr(feature = "web", wasm_bindgen)]
7#[derive(Debug, Clone, Copy, PartialEq)]
8pub enum FilterType {
9 Glow,
10 NaturalShadow,
11 Saturation,
12}
13
14#[cfg_attr(feature = "web", wasm_bindgen)]
15#[derive(Debug, Clone, Copy)]
16pub struct Filter {
17 pub kind: FilterType,
18 pub parameter: f32,
19}
20
21#[cfg_attr(feature = "web", wasm_bindgen)]
22impl Filter {
23 pub fn name(&self) -> String {
24 match self.kind {
25 FilterType::Glow => "glow",
26 FilterType::NaturalShadow => "natural-shadow-filter",
27 FilterType::Saturation => "saturation",
28 }
29 .to_owned()
30 }
31
32 pub fn glow(intensity: f32) -> Self {
33 Self {
34 kind: FilterType::Glow,
35 parameter: intensity,
36 }
37 }
38
39 pub fn id(&self) -> String {
40 format!(
41 "filter-{}-{}",
42 self.name(),
43 self.parameter.to_string().replace('.', "_")
44 )
45 }
46}
47
48impl PartialEq for Filter {
49 fn eq(&self, other: &Self) -> bool {
50 // TODO use way less restrictive epsilon
51 self.kind == other.kind
52 && (self.parameter - other.parameter).abs() < f32::EPSILON
53 }
54}
55
56impl Hash for Filter {
57 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
58 self.id().hash(state)
59 }
60}
61
62impl Eq for Filter {}