Rename the Coordinate data type to Vec2 (#2959)

This commit is contained in:
Keavon Chambers 2025-07-30 22:53:36 -07:00 committed by GitHub
parent 4391f88d03
commit 3cc9dd79fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 31 additions and 26 deletions

File diff suppressed because one or more lines are too long

View File

@ -851,7 +851,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
properties: None, properties: None,
}, },
DocumentNodeDefinition { DocumentNodeDefinition {
identifier: "Split Coordinate", identifier: "Split Vec2",
category: "Math: Vector", category: "Math: Vector",
node_template: NodeTemplate { node_template: NodeTemplate {
document_node: DocumentNode { document_node: DocumentNode {
@ -882,7 +882,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
..Default::default() ..Default::default()
}, },
persistent_node_metadata: DocumentNodePersistentMetadata { persistent_node_metadata: DocumentNodePersistentMetadata {
input_metadata: vec![("Coordinate", "TODO").into()], input_metadata: vec![("Vec2", "TODO").into()],
output_names: vec!["X".to_string(), "Y".to_string()], output_names: vec!["X".to_string(), "Y".to_string()],
has_primary_output: false, has_primary_output: false,
network_metadata: Some(NodeNetworkMetadata { network_metadata: Some(NodeNetworkMetadata {
@ -917,7 +917,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
}, },
}, },
description: Cow::Borrowed( description: Cow::Borrowed(
"Decomposes the X and Y components of a 2D coordinate.\n\nThe inverse of this node is \"Coordinate Value\", which can have either or both its X and Y exposed as graph inputs.", "Decomposes the X and Y components of a vec2.\n\nThe inverse of this node is \"Vec2 Value\", which can have either or both its X and Y parameters exposed as graph inputs.",
), ),
properties: None, properties: None,
}, },
@ -2042,7 +2042,7 @@ fn static_input_properties() -> InputProperties {
.and_then(|value| value.as_bool()) .and_then(|value| value.as_bool())
.unwrap_or_default(); .unwrap_or_default();
Ok(vec![node_properties::coordinate_widget( Ok(vec![node_properties::vec2_widget(
ParameterWidgetsInfo::new(node_id, index, true, context), ParameterWidgetsInfo::new(node_id, index, true, context),
&x, &x,
&y, &y,
@ -2298,7 +2298,7 @@ fn static_input_properties() -> InputProperties {
"spline_input".to_string(), "spline_input".to_string(),
Box::new(|node_id, index, context| { Box::new(|node_id, index, context| {
Ok(vec![LayoutGroup::Row { Ok(vec![LayoutGroup::Row {
widgets: node_properties::array_of_coordinates_widget(ParameterWidgetsInfo::new(node_id, index, true, context), TextInput::default().centered(true)), widgets: node_properties::array_of_vec2_widget(ParameterWidgetsInfo::new(node_id, index, true, context), TextInput::default().centered(true)),
}]) }])
}), }),
); );

View File

@ -160,7 +160,7 @@ pub(crate) fn property_from_type(
Some("Fraction") => number_widget(default_info, number_input.mode_range().min(min(0.)).max(max(1.))).into(), Some("Fraction") => number_widget(default_info, number_input.mode_range().min(min(0.)).max(max(1.))).into(),
Some("IntegerCount") => number_widget(default_info, number_input.int().min(min(1.))).into(), Some("IntegerCount") => number_widget(default_info, number_input.int().min(min(1.))).into(),
Some("SeedValue") => number_widget(default_info, number_input.int().min(min(0.))).into(), Some("SeedValue") => number_widget(default_info, number_input.int().min(min(0.))).into(),
Some("PixelSize") => coordinate_widget(default_info, "X", "Y", unit.unwrap_or(" px"), None, false), Some("PixelSize") => vec2_widget(default_info, "X", "Y", unit.unwrap_or(" px"), None, false),
Some("TextArea") => text_area_widget(default_info).into(), Some("TextArea") => text_area_widget(default_info).into(),
// For all other types, use TypeId-based matching // For all other types, use TypeId-based matching
@ -175,13 +175,13 @@ pub(crate) fn property_from_type(
Some(x) if x == TypeId::of::<u64>() => number_widget(default_info, number_input.int().min(min(0.))).into(), Some(x) if x == TypeId::of::<u64>() => number_widget(default_info, number_input.int().min(min(0.))).into(),
Some(x) if x == TypeId::of::<bool>() => bool_widget(default_info, CheckboxInput::default()).into(), Some(x) if x == TypeId::of::<bool>() => bool_widget(default_info, CheckboxInput::default()).into(),
Some(x) if x == TypeId::of::<String>() => text_widget(default_info).into(), Some(x) if x == TypeId::of::<String>() => text_widget(default_info).into(),
Some(x) if x == TypeId::of::<DVec2>() => coordinate_widget(default_info, "X", "Y", "", None, false), Some(x) if x == TypeId::of::<DVec2>() => vec2_widget(default_info, "X", "Y", "", None, false),
Some(x) if x == TypeId::of::<DAffine2>() => transform_widget(default_info, &mut extra_widgets), Some(x) if x == TypeId::of::<DAffine2>() => transform_widget(default_info, &mut extra_widgets),
// ========================== // ==========================
// PRIMITIVE COLLECTION TYPES // PRIMITIVE COLLECTION TYPES
// ========================== // ==========================
Some(x) if x == TypeId::of::<Vec<f64>>() => array_of_number_widget(default_info, TextInput::default()).into(), Some(x) if x == TypeId::of::<Vec<f64>>() => array_of_number_widget(default_info, TextInput::default()).into(),
Some(x) if x == TypeId::of::<Vec<DVec2>>() => array_of_coordinates_widget(default_info, TextInput::default()).into(), Some(x) if x == TypeId::of::<Vec<DVec2>>() => array_of_vec2_widget(default_info, TextInput::default()).into(),
// ==================== // ====================
// GRAPHICAL DATA TYPES // GRAPHICAL DATA TYPES
// ==================== // ====================
@ -626,7 +626,7 @@ pub fn transform_widget(parameter_widgets_info: ParameterWidgetsInfo, extra_widg
} }
} }
pub fn coordinate_widget(parameter_widgets_info: ParameterWidgetsInfo, x: &str, y: &str, unit: &str, min: Option<f64>, is_integer: bool) -> LayoutGroup { pub fn vec2_widget(parameter_widgets_info: ParameterWidgetsInfo, x: &str, y: &str, unit: &str, min: Option<f64>, is_integer: bool) -> LayoutGroup {
let ParameterWidgetsInfo { document_node, node_id, index, .. } = parameter_widgets_info; let ParameterWidgetsInfo { document_node, node_id, index, .. } = parameter_widgets_info;
let mut widgets = start_widgets(parameter_widgets_info); let mut widgets = start_widgets(parameter_widgets_info);
@ -723,7 +723,7 @@ pub fn array_of_number_widget(parameter_widgets_info: ParameterWidgetsInfo, text
widgets widgets
} }
pub fn array_of_coordinates_widget(parameter_widgets_info: ParameterWidgetsInfo, text_props: TextInput) -> Vec<WidgetHolder> { pub fn array_of_vec2_widget(parameter_widgets_info: ParameterWidgetsInfo, text_props: TextInput) -> Vec<WidgetHolder> {
let ParameterWidgetsInfo { document_node, node_id, index, .. } = parameter_widgets_info; let ParameterWidgetsInfo { document_node, node_id, index, .. } = parameter_widgets_info;
let mut widgets = start_widgets(parameter_widgets_info); let mut widgets = start_widgets(parameter_widgets_info);
@ -1249,7 +1249,7 @@ pub(crate) fn grid_properties(node_id: NodeId, context: &mut NodePropertiesConte
if let Some(&TaggedValue::GridType(grid_type)) = grid_type_input.as_non_exposed_value() { if let Some(&TaggedValue::GridType(grid_type)) = grid_type_input.as_non_exposed_value() {
match grid_type { match grid_type {
GridType::Rectangular => { GridType::Rectangular => {
let spacing = coordinate_widget(ParameterWidgetsInfo::new(node_id, SpacingInput::<f64>::INDEX, true, context), "W", "H", " px", Some(0.), false); let spacing = vec2_widget(ParameterWidgetsInfo::new(node_id, SpacingInput::<f64>::INDEX, true, context), "W", "H", " px", Some(0.), false);
widgets.push(spacing); widgets.push(spacing);
} }
GridType::Isometric => { GridType::Isometric => {
@ -1259,7 +1259,7 @@ pub(crate) fn grid_properties(node_id: NodeId, context: &mut NodePropertiesConte
NumberInput::default().label("H").min(0.).unit(" px"), NumberInput::default().label("H").min(0.).unit(" px"),
), ),
}; };
let angles = coordinate_widget(ParameterWidgetsInfo::new(node_id, AnglesInput::INDEX, true, context), "", "", "°", None, false); let angles = vec2_widget(ParameterWidgetsInfo::new(node_id, AnglesInput::INDEX, true, context), "", "", "°", None, false);
widgets.extend([spacing, angles]); widgets.extend([spacing, angles]);
} }
} }

View File

@ -186,13 +186,18 @@ const NODE_REPLACEMENTS: &[NodeReplacement<'static>] = &[
aliases: &["graphene_core::ops::PercentageValueNode"], aliases: &["graphene_core::ops::PercentageValueNode"],
}, },
NodeReplacement { NodeReplacement {
node: graphene_std::math_nodes::coordinate_value::IDENTIFIER, node: graphene_std::math_nodes::vec_2_value::IDENTIFIER,
aliases: &[ aliases: &[
"graphene_core::ops::CoordinateValueNode",
"graphene_core::ops::ConstructVector2", "graphene_core::ops::ConstructVector2",
"graphene_core::ops::Vector2ValueNode", "graphene_core::ops::Vector2ValueNode",
"graphene_core::ops::CoordinateValueNode",
"graphene_math_nodes::CoordinateValueNode",
], ],
}, },
NodeReplacement {
node: graphene_std::vector::vec_2_to_point::IDENTIFIER,
aliases: &["graphene_core::vector::PositionToPointNode"],
},
NodeReplacement { NodeReplacement {
node: graphene_std::math_nodes::color_value::IDENTIFIER, node: graphene_std::math_nodes::color_value::IDENTIFIER,
aliases: &["graphene_core::ops::ColorValueNode"], aliases: &["graphene_core::ops::ColorValueNode"],

View File

@ -2,9 +2,9 @@ use crate::Ctx;
use dyn_any::DynAny; use dyn_any::DynAny;
use glam::{DVec2, IVec2, UVec2}; use glam::{DVec2, IVec2, UVec2};
/// Obtains the X or Y component of a coordinate point. /// Obtains the X or Y component of a vec2.
/// ///
/// The inverse of this node is "Coordinate Value", which can have either or both its X and Y exposed as graph inputs. /// The inverse of this node is "Vec2 Value", which can have either or both its X and Y parameters exposed as graph inputs.
#[node_macro::node(name("Extract XY"), category("Math: Vector"))] #[node_macro::node(name("Extract XY"), category("Math: Vector"))]
fn extract_xy<T: Into<DVec2>>(_: impl Ctx, #[implementations(DVec2, IVec2, UVec2)] vector: T, axis: XY) -> f64 { fn extract_xy<T: Into<DVec2>>(_: impl Ctx, #[implementations(DVec2, IVec2, UVec2)] vector: T, axis: XY) -> f64 {
match axis { match axis {
@ -13,7 +13,7 @@ fn extract_xy<T: Into<DVec2>>(_: impl Ctx, #[implementations(DVec2, IVec2, UVec2
} }
} }
/// The X or Y component of a coordinate. /// The X or Y component of a vec2.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, DynAny, node_macro::ChoiceType, specta::Type, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, DynAny, node_macro::ChoiceType, specta::Type, serde::Serialize, serde::Deserialize)]
#[widget(Dropdown)] #[widget(Dropdown)]
pub enum XY { pub enum XY {

View File

@ -931,13 +931,13 @@ async fn dimensions(_: impl Ctx, vector_data: VectorDataTable) -> DVec2 {
.unwrap_or_default() .unwrap_or_default()
} }
/// Converts a coordinate value into a vector anchor point. /// Converts a vec2 value into a vector path composed of a single anchor point.
/// ///
/// This is useful in conjunction with nodes that repeat it, followed by the "Points to Polyline" node to string together a path of the points. /// This is useful in conjunction with nodes that repeat it, followed by the "Points to Polyline" node to string together a path of the points.
#[node_macro::node(category("Vector"), name("Coordinate to Point"), path(graphene_core::vector))] #[node_macro::node(category("Vector"), name("Vec2 to Point"), path(graphene_core::vector))]
async fn position_to_point(_: impl Ctx, coordinate: DVec2) -> VectorDataTable { async fn vec2_to_point(_: impl Ctx, vec2: DVec2) -> VectorDataTable {
let mut point_domain = PointDomain::new(); let mut point_domain = PointDomain::new();
point_domain.push(PointId::generate(), coordinate); point_domain.push(PointId::generate(), vec2);
VectorDataTable::new_instance(Instance { VectorDataTable::new_instance(Instance {
instance: VectorData { point_domain, ..Default::default() }, instance: VectorData { point_domain, ..Default::default() },

View File

@ -286,7 +286,7 @@ fn cosine_inverse<U: num_traits::float::Float>(
/// The inverse tangent trigonometric function (atan or atan2, depending on input type) calculates: /// The inverse tangent trigonometric function (atan or atan2, depending on input type) calculates:
/// atan: the angle whose tangent is the specified scalar number. /// atan: the angle whose tangent is the specified scalar number.
/// atan2: the angle of a ray from the origin to the specified coordinate. /// atan2: the angle of a ray from the origin to the specified vec2.
/// ///
/// The resulting angle is always in the range [0°, 180°] or, in radians, [-π/2, π/2]. /// The resulting angle is always in the range [0°, 180°] or, in radians, [-π/2, π/2].
#[node_macro::node(category("Math: Trig"))] #[node_macro::node(category("Math: Trig"))]
@ -651,9 +651,9 @@ fn percentage_value(_: impl Ctx, _primary: (), percentage: Percentage) -> f64 {
percentage percentage
} }
/// Constructs a two-dimensional vector value which may be set to any XY coordinate. /// Constructs a two-dimensional vector value which may be set to any XY pair.
#[node_macro::node(category("Value"))] #[node_macro::node(category("Value"), name("Vec2 Value"))]
fn coordinate_value(_: impl Ctx, _primary: (), x: f64, y: f64) -> DVec2 { fn vec2_value(_: impl Ctx, _primary: (), x: f64, y: f64) -> DVec2 {
DVec2::new(x, y) DVec2::new(x, y)
} }