Download node-graph/gcore/src/logic.rs from openfree/graphite2: direct link, hf CLI and curl.
- Browser
- Download file 2.81 kB
-
https://huggingface.co/spaces/openfree/graphite2/resolve/main/node-graph/gcore/src/logic.rs
- Command line
-
hf download hf://spaces/openfree/graphite2/node-graph/gcore/src/logic.rs
-
curl -L -o logic.rs https://huggingface.co/spaces/openfree/graphite2/resolve/main/node-graph/gcore/src/logic.rs
2.81 kB
| use crate::ArtboardGroupTable; | |
| use crate::Color; | |
| use crate::GraphicElement; | |
| use crate::GraphicGroupTable; | |
| use crate::gradient::GradientStops; | |
| use crate::graphene_core::registry::types::TextArea; | |
| use crate::raster_types::{CPU, GPU, RasterDataTable}; | |
| use crate::vector::VectorDataTable; | |
| use crate::{Context, Ctx}; | |
| use glam::{DAffine2, DVec2}; | |
| fn to_string<T: std::fmt::Debug>(_: impl Ctx, value: T) -> String { | |
| format!("{:?}", value) | |
| } | |
| fn string_concatenate(_: impl Ctx, first: String, second: TextArea) -> String { | |
| first.clone() + &second | |
| } | |
| fn string_replace(_: impl Ctx, string: String, from: TextArea, to: TextArea) -> String { | |
| string.replace(&from, &to) | |
| } | |
| fn string_slice(_: impl Ctx, string: String, start: f64, end: f64) -> String { | |
| let start = if start < 0. { string.len() - start.abs() as usize } else { start as usize }; | |
| let end = if end <= 0. { string.len() - end.abs() as usize } else { end as usize }; | |
| let n = end.saturating_sub(start); | |
| string.char_indices().skip(start).take(n).map(|(_, c)| c).collect() | |
| } | |
| fn string_length(_: impl Ctx, string: String) -> usize { | |
| string.len() | |
| } | |
| async fn switch<T, C: Send + 'n + Clone>( | |
| ctx: C, | |
| condition: bool, | |
| if_true: impl Node<C, Output = T>, | |
| if_false: impl Node<C, Output = T>, | |
| ) -> T { | |
| if condition { | |
| // We can't remove these calls because we only want to evaluate the branch that we actually need | |
| if_true.eval(ctx).await | |
| } else { | |
| if_false.eval(ctx).await | |
| } | |
| } | |