mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 10:58:04 +08:00
Implement the Gaussian Blur node (#933)
This commit is contained in:
committed by
Keavon Chambers
parent
74bfd630a9
commit
a9601ab164
@@ -2,35 +2,32 @@ use graphene_core::{Cache, Node};
|
||||
use once_cell::sync::OnceCell;
|
||||
|
||||
/// Caches the output of a given Node and acts as a proxy
|
||||
pub struct CacheNode<CachedNode: Node<I>, I> {
|
||||
node: CachedNode,
|
||||
cache: OnceCell<CachedNode::Output>,
|
||||
pub struct CacheNode<T> {
|
||||
cache: OnceCell<T>,
|
||||
}
|
||||
impl<'n, CashedNode: Node<I> + Copy, I> Node<I> for &'n CacheNode<CashedNode, I> {
|
||||
type Output = &'n CashedNode::Output;
|
||||
fn eval(self, input: I) -> Self::Output {
|
||||
impl<'n, T> Node<T> for &'n CacheNode<T> {
|
||||
type Output = &'n T;
|
||||
fn eval(self, input: T) -> Self::Output {
|
||||
self.cache.get_or_init(|| {
|
||||
trace!("Creating new cache node");
|
||||
self.node.eval(input)
|
||||
input
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'n, CachedNode: Node<I>, I> CacheNode<CachedNode, I> {
|
||||
pub fn clear(&'n mut self) {
|
||||
self.cache = OnceCell::new();
|
||||
}
|
||||
pub fn new(node: CachedNode) -> CacheNode<CachedNode, I> {
|
||||
CacheNode { node, cache: OnceCell::new() }
|
||||
impl<T> Node<T> for CacheNode<T> {
|
||||
type Output = T;
|
||||
fn eval(self, input: T) -> Self::Output {
|
||||
input
|
||||
}
|
||||
}
|
||||
impl<CachedNode: Node<I>, I> Cache for CacheNode<CachedNode, I> {
|
||||
|
||||
impl<T> CacheNode<T> {
|
||||
pub fn new() -> CacheNode<T> {
|
||||
CacheNode { cache: OnceCell::new() }
|
||||
}
|
||||
}
|
||||
impl<T> Cache for CacheNode<T> {
|
||||
fn clear(&mut self) {
|
||||
self.cache = OnceCell::new();
|
||||
}
|
||||
}
|
||||
|
||||
/*use dyn_any::{DynAny, StaticType};
|
||||
#[derive(DynAny)]
|
||||
struct Boo<'a>(&'a u8);
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user