Change number inputs to be f32 instead of f64 for most nodes (#1543)

This commit is contained in:
Dennis Kobert 2024-01-05 14:13:26 +01:00 committed by GitHub
parent d268afb7fb
commit 6bfb2bf344
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 18 deletions

View file

@ -1936,7 +1936,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
implementation: NodeImplementation::proto("graphene_core::ops::DivideNode<_>"),
inputs: vec![
DocumentInputType::value("Primary", TaggedValue::F32(0.), true),
DocumentInputType::value("Divisor", TaggedValue::F32(0.), false),
DocumentInputType::value("Divisor", TaggedValue::F32(1.), false),
],
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
properties: node_properties::divide_properties,
@ -1948,7 +1948,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
implementation: NodeImplementation::proto("graphene_core::ops::MultiplyNode<_>"),
inputs: vec![
DocumentInputType::value("Primary", TaggedValue::F32(0.), true),
DocumentInputType::value("Multiplicand", TaggedValue::F32(0.), false),
DocumentInputType::value("Multiplicand", TaggedValue::F32(1.), false),
],
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
properties: node_properties::multiply_properties,
@ -1960,7 +1960,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
implementation: NodeImplementation::proto("graphene_core::ops::ExponentNode<_>"),
inputs: vec![
DocumentInputType::value("Primary", TaggedValue::F32(0.), true),
DocumentInputType::value("Power", TaggedValue::F32(0.), false),
DocumentInputType::value("Power", TaggedValue::F32(2.), false),
],
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
properties: node_properties::exponent_properties,
@ -2506,7 +2506,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentInputType::none(),
DocumentInputType::value("Text", TaggedValue::String("Lorem ipsum".to_string()), false),
DocumentInputType::value("Font", TaggedValue::Font(Font::new(DEFAULT_FONT_FAMILY.into(), DEFAULT_FONT_STYLE.into())), false),
DocumentInputType::value("Size", TaggedValue::F64(24.), false),
DocumentInputType::value("Size", TaggedValue::F32(24.), false),
],
outputs: vec![DocumentOutputType::new("Vector", FrontendGraphDataType::Subpath)],
properties: node_properties::node_section_font,
@ -2659,9 +2659,9 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
implementation: NodeImplementation::proto("graphene_core::vector::ResamplePoints<_, _, _, _>"),
inputs: vec![
DocumentInputType::value("Vector Data", TaggedValue::VectorData(graphene_core::vector::VectorData::empty()), true),
DocumentInputType::value("Spacing", TaggedValue::F64(100.), false),
DocumentInputType::value("Start Offset", TaggedValue::F64(0.), false),
DocumentInputType::value("Stop Offset", TaggedValue::F64(0.), false),
DocumentInputType::value("Spacing", TaggedValue::F32(100.), false),
DocumentInputType::value("Start Offset", TaggedValue::F32(0.), false),
DocumentInputType::value("Stop Offset", TaggedValue::F32(0.), false),
DocumentInputType::value("Adaptive Spacing", TaggedValue::Bool(false), false),
],
outputs: vec![DocumentOutputType::new("Vector", FrontendGraphDataType::Subpath)],
@ -2814,7 +2814,7 @@ pub static IMAGINATE_NODE: Lazy<DocumentNodeDefinition> = Lazy::new(|| DocumentN
default: NodeInput::Network(concrete!(WasmEditorApi)),
},
DocumentInputType::value("Controller", TaggedValue::ImaginateController(Default::default()), false),
DocumentInputType::value("Seed", TaggedValue::F64(0.), false), // Remember to keep index used in `ImaginateRandom` updated with this entry's index
DocumentInputType::value("Seed", TaggedValue::U64(0), false), // Remember to keep index used in `ImaginateRandom` updated with this entry's index
DocumentInputType::value("Resolution", TaggedValue::OptionalDVec2(None), false),
DocumentInputType::value("Samples", TaggedValue::U32(30), false),
DocumentInputType::value("Sampling Method", TaggedValue::ImaginateSamplingMethod(ImaginateSamplingMethod::EulerA), false),
@ -3007,7 +3007,7 @@ pub fn new_text_network(text: String, font: Font, size: f64) -> NodeNetwork {
NodeInput::Network(concrete!(WasmEditorApi)),
NodeInput::value(TaggedValue::String(text), false),
NodeInput::value(TaggedValue::Font(font), false),
NodeInput::value(TaggedValue::F64(size), false),
NodeInput::value(TaggedValue::F32(size as f32), false),
],
DocumentNodeMetadata::position((0, 4)),
));

View file

@ -1327,19 +1327,19 @@ pub fn subtract_properties(document_node: &DocumentNode, node_id: NodeId, _conte
}
pub fn divide_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
let widgets = number_widget(document_node, node_id, 1, "Divisor", NumberInput::default(), true);
let widgets = number_widget(document_node, node_id, 1, "Divisor", NumberInput::new(Some(1.)), true);
vec![LayoutGroup::Row { widgets }]
}
pub fn multiply_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
let widgets = number_widget(document_node, node_id, 1, "Multiplicand", NumberInput::default(), true);
let widgets = number_widget(document_node, node_id, 1, "Multiplicand", NumberInput::new(Some(1.)), true);
vec![LayoutGroup::Row { widgets }]
}
pub fn exponent_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
let widgets = number_widget(document_node, node_id, 1, "Power", NumberInput::default(), true);
let widgets = number_widget(document_node, node_id, 1, "Power", NumberInput::new(Some(2.)), true);
vec![LayoutGroup::Row { widgets }]
}

View file

@ -15,7 +15,7 @@ pub struct TextGeneratorNode<Text, FontName, Size> {
}
#[node_fn(TextGeneratorNode)]
fn generate_text<'a: 'input, T>(editor: EditorApi<'a, T>, text: String, font_name: Font, font_size: f64) -> crate::vector::VectorData {
fn generate_text<'a: 'input, T>(editor: EditorApi<'a, T>, text: String, font_name: Font, font_size: f32) -> crate::vector::VectorData {
let buzz_face = editor.font_cache.get(&font_name).map(|data| load_face(data));
crate::vector::VectorData::from_subpaths(to_path(&text, buzz_face, font_size, None))
crate::vector::VectorData::from_subpaths(to_path(&text, buzz_face, font_size as f64, None))
}

View file

@ -212,7 +212,11 @@ pub struct ResamplePoints<Spacing, StartOffset, StopOffset, AdaptiveSpacing> {
}
#[node_macro::node_fn(ResamplePoints)]
fn resample_points(mut vector_data: VectorData, spacing: f64, start_offset: f64, stop_offset: f64, adaptive_spacing: bool) -> VectorData {
fn resample_points(mut vector_data: VectorData, spacing: f32, start_offset: f32, stop_offset: f32, adaptive_spacing: bool) -> VectorData {
let spacing = spacing as f64;
let start_offset = start_offset as f64;
let stop_offset = stop_offset as f64;
for subpath in &mut vector_data.subpaths {
if subpath.is_empty() || spacing.is_zero() || !spacing.is_finite() {
continue;

View file

@ -20,6 +20,7 @@ pub enum TaggedValue {
None,
String(String),
U32(u32),
U64(u64),
F32(f32),
F64(f64),
Bool(bool),
@ -82,6 +83,7 @@ impl Hash for TaggedValue {
Self::None => {}
Self::String(x) => x.hash(state),
Self::U32(x) => x.hash(state),
Self::U64(x) => x.hash(state),
Self::F32(x) => x.to_bits().hash(state),
Self::F64(x) => x.to_bits().hash(state),
Self::Bool(x) => x.hash(state),
@ -159,6 +161,7 @@ impl<'a> TaggedValue {
TaggedValue::None => Box::new(()),
TaggedValue::String(x) => Box::new(x),
TaggedValue::U32(x) => Box::new(x),
TaggedValue::U64(x) => Box::new(x),
TaggedValue::F32(x) => Box::new(x),
TaggedValue::F64(x) => Box::new(x),
TaggedValue::Bool(x) => Box::new(x),
@ -219,6 +222,7 @@ impl<'a> TaggedValue {
TaggedValue::None => "()".to_string(),
TaggedValue::String(x) => format!("\"{x}\""),
TaggedValue::U32(x) => x.to_string() + "_u32",
TaggedValue::U64(x) => x.to_string() + "_u64",
TaggedValue::F32(x) => x.to_string() + "_f32",
TaggedValue::F64(x) => x.to_string() + "_f64",
TaggedValue::Bool(x) => x.to_string(),
@ -233,6 +237,7 @@ impl<'a> TaggedValue {
TaggedValue::None => concrete!(()),
TaggedValue::String(_) => concrete!(String),
TaggedValue::U32(_) => concrete!(u32),
TaggedValue::U64(_) => concrete!(u64),
TaggedValue::F32(_) => concrete!(f32),
TaggedValue::F64(_) => concrete!(f64),
TaggedValue::Bool(_) => concrete!(bool),
@ -296,6 +301,7 @@ impl<'a> TaggedValue {
x if x == TypeId::of::<()>() => Ok(TaggedValue::None),
x if x == TypeId::of::<String>() => Ok(TaggedValue::String(*downcast(input).unwrap())),
x if x == TypeId::of::<u32>() => Ok(TaggedValue::U32(*downcast(input).unwrap())),
x if x == TypeId::of::<u64>() => Ok(TaggedValue::U64(*downcast(input).unwrap())),
x if x == TypeId::of::<f32>() => Ok(TaggedValue::F32(*downcast(input).unwrap())),
x if x == TypeId::of::<f64>() => Ok(TaggedValue::F64(*downcast(input).unwrap())),
x if x == TypeId::of::<bool>() => Ok(TaggedValue::Bool(*downcast(input).unwrap())),

View file

@ -623,7 +623,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
vec![
fn_type!(WasmEditorApi),
fn_type!(ImaginateController),
fn_type!(f64),
fn_type!(u64),
fn_type!(Option<DVec2>),
fn_type!(u32),
fn_type!(ImaginateSamplingMethod),
@ -734,7 +734,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
register_node!(graphene_std::raster::MandelbrotNode, input: Footprint, params: []),
async_node!(graphene_core::vector::CopyToPoints<_, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData, Footprint => VectorData]),
async_node!(graphene_core::vector::CopyToPoints<_, _>, input: Footprint, output: GraphicGroup, fn_params: [Footprint => VectorData, Footprint => GraphicGroup]),
register_node!(graphene_core::vector::ResamplePoints<_, _, _, _>, input: VectorData, params: [f64, f64, f64, bool]),
register_node!(graphene_core::vector::ResamplePoints<_, _, _, _>, input: VectorData, params: [f32, f32, f32, bool]),
register_node!(graphene_core::vector::SplinesFromPointsNode, input: VectorData, params: []),
register_node!(graphene_core::vector::generator_nodes::CircleGenerator<_>, input: (), params: [f32]),
register_node!(graphene_core::vector::generator_nodes::EllipseGenerator<_, _>, input: (), params: [f32, f32]),
@ -748,7 +748,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
input: Vec<graphene_core::vector::bezier_rs::Subpath<graphene_core::uuid::ManipulatorGroupId>>,
params: [Vec<graphene_core::uuid::ManipulatorGroupId>]
),
register_node!(graphene_core::text::TextGeneratorNode<_, _, _>, input: WasmEditorApi, params: [String, graphene_core::text::Font, f64]),
register_node!(graphene_core::text::TextGeneratorNode<_, _, _>, input: WasmEditorApi, params: [String, graphene_core::text::Font, f32]),
register_node!(graphene_std::brush::VectorPointsNode, input: VectorData, params: []),
register_node!(graphene_core::ExtractImageFrame, input: WasmEditorApi, params: []),
async_node!(graphene_core::ConstructLayerNode<_, _>, input: Footprint, output: GraphicGroup, fn_params: [Footprint => graphene_core::GraphicElement, Footprint => GraphicGroup]),