Files
Graphite/node-graph/nodes/raster/src/adjust.rs
Keavon Chambers 2f24459344 Rework Gradient into a newtype of List<Color> with optional position and midpoint attributes (#4397)
* Rework Gradient into a newtype of List<Color> with optional position and midpoint attributes

* Fix Vello stopless-gradient fallback coverage, empty legacy gradient tables, the node docs gradient swatch, NaN position elision, and wired setter input overwrites
2026-08-03 04:05:02 -07:00

31 lines
671 B
Rust

use no_std_types::color::Color;
pub trait Adjust<P> {
fn adjust(&mut self, map_fn: impl Fn(&P) -> P);
}
impl Adjust<Color> for Color {
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
*self = map_fn(self);
}
}
#[cfg(feature = "std")]
mod adjust_std {
use super::*;
use raster_types::{CPU, Raster};
use vector_types::Gradient;
impl Adjust<Color> for Raster<CPU> {
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
for color in self.data_mut().data.iter_mut() {
*color = map_fn(color);
}
}
}
impl Adjust<Color> for Gradient {
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
*self = self.map_colors(map_fn);
}
}
}