From ae86ae29ab663f365a290034c685e221528c28f9 Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Sun, 24 Mar 2024 17:07:35 +0100 Subject: [PATCH] svg-filters: more testssss --- crates/svg-filters/src/tests.rs | 49 ++----------------- .../src/tests/component_transfer.rs | 36 ++++++++++++++ .../svg-filters/src/tests/displacement_map.rs | 32 ++++++++++++ crates/svg-filters/src/tests/flood.rs | 17 +++++++ crates/svg-filters/src/tests/turbulence.rs | 25 ++++++++++ .../svg-filters/src/types/nodes/primitives.rs | 18 +++---- 6 files changed, 124 insertions(+), 53 deletions(-) create mode 100644 crates/svg-filters/src/tests/component_transfer.rs create mode 100644 crates/svg-filters/src/tests/displacement_map.rs create mode 100644 crates/svg-filters/src/tests/flood.rs create mode 100644 crates/svg-filters/src/tests/turbulence.rs diff --git a/crates/svg-filters/src/tests.rs b/crates/svg-filters/src/tests.rs index 771ab3a..742c457 100644 --- a/crates/svg-filters/src/tests.rs +++ b/crates/svg-filters/src/tests.rs @@ -1,56 +1,17 @@ -mod color_matrix; - mod blend; +mod color_matrix; mod complex; +mod component_transfer; +mod displacement_map; +mod flood; mod gaussian_blur; mod offset; - -mod component_transfer { - use crate::{ - codegen::SvgDocument, - types::nodes::primitives::{ - component_transfer::{ComponentTransfer, TransferFn}, - FePrimitive, - }, - Node, - }; - - #[test] - fn test_comp_trans_simple() { - let mut doc = SvgDocument::new(); - - let comptrans = doc.create_filter("comp_trans"); - - comptrans.add_node(Node::simple(FePrimitive::ComponentTransfer( - ComponentTransfer { - func_r: TransferFn::Table { - table_values: vec![0., 0.1, 0.4, 0.9], - }, - func_g: TransferFn::Discrete { - table_values: vec![0.1, 0.3, 0.5, 0.7, 0.9], - }, - func_b: TransferFn::Linear { - slope: 1.0, - intercept: 0.75, - }, - func_a: TransferFn::Identity, - }, - ))); - - assert_eq!( - doc.generate_svg(), - r#""# - ); - } -} +mod turbulence; mod composite {} mod convolve_matrix {} mod diffuse_lighting {} -mod displacement_map {} -mod flood {} mod image {} mod merge {} mod morphology {} mod specular_lighting {} mod tile {} -mod turbulence {} diff --git a/crates/svg-filters/src/tests/component_transfer.rs b/crates/svg-filters/src/tests/component_transfer.rs new file mode 100644 index 0000000..8f24c6f --- /dev/null +++ b/crates/svg-filters/src/tests/component_transfer.rs @@ -0,0 +1,36 @@ +use crate::{ + codegen::SvgDocument, + types::nodes::primitives::{ + component_transfer::{ComponentTransfer, TransferFn}, + FePrimitive, + }, + Node, +}; + +#[test] +fn test_comp_trans_simple() { + let mut doc = SvgDocument::new(); + + let comptrans = doc.create_filter("comp_trans"); + + comptrans.add_node(Node::simple(FePrimitive::ComponentTransfer( + ComponentTransfer { + func_r: TransferFn::Table { + table_values: vec![0., 0.1, 0.4, 0.9], + }, + func_g: TransferFn::Discrete { + table_values: vec![0.1, 0.3, 0.5, 0.7, 0.9], + }, + func_b: TransferFn::Linear { + slope: 1.0, + intercept: 0.75, + }, + func_a: TransferFn::Identity, + }, + ))); + + assert_eq!( + doc.generate_svg(), + r#""# + ); +} diff --git a/crates/svg-filters/src/tests/displacement_map.rs b/crates/svg-filters/src/tests/displacement_map.rs new file mode 100644 index 0000000..3b41ff1 --- /dev/null +++ b/crates/svg-filters/src/tests/displacement_map.rs @@ -0,0 +1,32 @@ +use crate::{ + codegen::SvgDocument, + types::nodes::{ + primitives::{ + displacement_map::Channel, + turbulence::{NoiseType, StitchTiles}, + }, + standard_input::StandardInput, + }, +}; + +#[test] +fn test_displacement_map_simple() { + let mut doc = SvgDocument::new(); + + let displace = doc.create_filter("displace"); + + let simple_noise = + displace.turbulence(0.01, 0.01, 1, 0, StitchTiles::Stitch, NoiseType::Turbulence); + displace.displacement_map( + StandardInput::SourceGraphic, + simple_noise, + 128., + Channel::R, + Channel::R, + ); + + assert_eq!( + doc.generate_svg(), + r#""# + ); +} diff --git a/crates/svg-filters/src/tests/flood.rs b/crates/svg-filters/src/tests/flood.rs new file mode 100644 index 0000000..27ed8bc --- /dev/null +++ b/crates/svg-filters/src/tests/flood.rs @@ -0,0 +1,17 @@ +use csscolorparser::Color; + +use crate::codegen::SvgDocument; + +#[test] +fn test_flood_simple() { + let mut doc = SvgDocument::new(); + + let turbdispl = doc.create_filter("noiseDisplace"); + + turbdispl.flood(Color::new(0.9, 0.7, 0.85, 1.), 1.); + + assert_eq!( + doc.generate_svg(), + r##""## + ); +} diff --git a/crates/svg-filters/src/tests/turbulence.rs b/crates/svg-filters/src/tests/turbulence.rs new file mode 100644 index 0000000..dd53e7d --- /dev/null +++ b/crates/svg-filters/src/tests/turbulence.rs @@ -0,0 +1,25 @@ +use crate::{ + codegen::SvgDocument, + types::nodes::primitives::turbulence::{NoiseType, StitchTiles}, +}; + +#[test] +fn test_simple_turbulence() { + let mut doc = SvgDocument::new(); + + let noise = doc.create_filter("noise"); + + noise.turbulence( + 0.01, + 0.01, + 1, + 0, + StitchTiles::Stitch, + NoiseType::FractalNoise, + ); + + assert_eq!( + doc.generate_svg(), + r#""# + ); +} diff --git a/crates/svg-filters/src/types/nodes/primitives.rs b/crates/svg-filters/src/types/nodes/primitives.rs index 171314f..4675b8e 100644 --- a/crates/svg-filters/src/types/nodes/primitives.rs +++ b/crates/svg-filters/src/types/nodes/primitives.rs @@ -88,13 +88,13 @@ impl WriteElement for FePrimitive { FePrimitive::GaussianBlur(el) => el.attrs(), FePrimitive::Offset(el) => el.attrs(), FePrimitive::Turbulence(el) => el.attrs(), - FePrimitive::ConvolveMatrix(_) => todo!(), - FePrimitive::DiffuseLighting(_) => todo!(), FePrimitive::DisplacementMap(el) => el.attrs(), FePrimitive::Flood(el) => el.attrs(), + FePrimitive::Morphology(el) => el.attrs(), + FePrimitive::ConvolveMatrix(_) => todo!(), + FePrimitive::DiffuseLighting(_) => todo!(), FePrimitive::Image(_) => todo!(), FePrimitive::Merge(_) => todo!(), - FePrimitive::Morphology(_) => todo!(), FePrimitive::SpecularLighting(_) => todo!(), FePrimitive::Tile(_) => todo!(), } @@ -109,13 +109,13 @@ impl WriteElement for FePrimitive { FePrimitive::GaussianBlur(el) => el.tag_name(), FePrimitive::Offset(el) => el.tag_name(), FePrimitive::Turbulence(el) => el.tag_name(), - FePrimitive::ConvolveMatrix(_) => todo!(), - FePrimitive::DiffuseLighting(_) => todo!(), FePrimitive::DisplacementMap(el) => el.tag_name(), FePrimitive::Flood(el) => el.tag_name(), + FePrimitive::Morphology(el) => el.tag_name(), + FePrimitive::ConvolveMatrix(_) => todo!(), + FePrimitive::DiffuseLighting(_) => todo!(), FePrimitive::Image(_) => todo!(), FePrimitive::Merge(_) => todo!(), - FePrimitive::Morphology(_) => todo!(), FePrimitive::SpecularLighting(_) => todo!(), FePrimitive::Tile(_) => todo!(), } @@ -136,13 +136,13 @@ impl WriteElement for FePrimitive { FePrimitive::Turbulence(el) => el.element_writer(writer, common, inputs, output), FePrimitive::GaussianBlur(el) => el.element_writer(writer, common, inputs, output), FePrimitive::Offset(el) => el.element_writer(writer, common, inputs, output), - FePrimitive::ConvolveMatrix(_) => todo!(), - FePrimitive::DiffuseLighting(_) => todo!(), FePrimitive::DisplacementMap(el) => el.element_writer(writer, common, inputs, output), FePrimitive::Flood(el) => el.element_writer(writer, common, inputs, output), + FePrimitive::Morphology(el) => el.element_writer(writer, common, inputs, output), + FePrimitive::ConvolveMatrix(_) => todo!(), + FePrimitive::DiffuseLighting(_) => todo!(), FePrimitive::Image(_) => todo!(), FePrimitive::Merge(_) => todo!(), - FePrimitive::Morphology(_) => todo!(), FePrimitive::SpecularLighting(_) => todo!(), FePrimitive::Tile(_) => todo!(), }