mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 02:48:12 +08:00
Replace the 'Vec2 to Point' node with automatic conversion machinery (#4236)
* Replace the 'Vec2 to Point' node with an 'As Vector' node and automatic conversion * Accept a Vec2 as content for the Wrap Graphic node * Rename the type-assertion nodes from 'To' to 'As' * Fix the Transform node reversing a Vec2 input's direction * Fix text migration bug
This commit is contained in:
@@ -549,6 +549,7 @@ pub async fn wrap_graphic<T: Into<Graphic> + 'n>(
|
||||
List<Color>,
|
||||
List<GradientStops>,
|
||||
DAffine2,
|
||||
DVec2,
|
||||
)]
|
||||
content: T,
|
||||
) -> List<Graphic> {
|
||||
|
||||
@@ -421,22 +421,22 @@ fn random(
|
||||
|
||||
// TODO: Test that these are no longer needed in all circumstances, then remove them and add a migration to convert these into Passthrough nodes. Note: these act more as type annotations than as identity functions.
|
||||
/// Convert a number to an integer of the type u32, which may be the required type for certain node inputs.
|
||||
#[node_macro::node(name("To u32"), category("Debug"))]
|
||||
fn to_u32(_: impl Ctx, value: u32) -> u32 {
|
||||
#[node_macro::node(name("As u32"), category("Debug"))]
|
||||
fn as_u32(_: impl Ctx, value: u32) -> u32 {
|
||||
value
|
||||
}
|
||||
|
||||
// TODO: Test that these are no longer needed in all circumstances, then remove them and add a migration to convert these into Passthrough nodes. Note: these act more as type annotations than as identity functions.
|
||||
/// Convert a number to an integer of the type u64, which may be the required type for certain node inputs.
|
||||
#[node_macro::node(name("To u64"), category("Debug"))]
|
||||
fn to_u64(_: impl Ctx, value: u64) -> u64 {
|
||||
#[node_macro::node(name("As u64"), category("Debug"))]
|
||||
fn as_u64(_: impl Ctx, value: u64) -> u64 {
|
||||
value
|
||||
}
|
||||
|
||||
// TODO: Test that these are no longer needed in all circumstances, then remove them and add a migration to convert these into Passthrough nodes. Note: these act more as type annotations than as identity functions.
|
||||
/// Convert an integer to a decimal number of the type f64, which may be the required type for certain node inputs.
|
||||
#[node_macro::node(name("To f64"), category("Debug"))]
|
||||
fn to_f64(_: impl Ctx, value: f64) -> f64 {
|
||||
#[node_macro::node(name("As f64"), category("Debug"))]
|
||||
fn as_f64(_: impl Ctx, value: f64) -> f64 {
|
||||
value
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ fn string_value(_: impl Ctx, _primary: (), string: TextArea) -> String {
|
||||
|
||||
/// Type-asserts a value to be a string.
|
||||
#[node_macro::node(category("Debug"))]
|
||||
fn to_string(_: impl Ctx, value: String) -> String {
|
||||
fn as_string(_: impl Ctx, value: String) -> String {
|
||||
value
|
||||
}
|
||||
|
||||
|
||||
@@ -1074,16 +1074,10 @@ async fn dimensions(_: impl Ctx, content: List<Vector>) -> DVec2 {
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
// TODO: Replace this node with an automatic type conversion implementation of the `Convert` trait
|
||||
/// 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.
|
||||
#[node_macro::node(category("Vector"), name("Vec2 to Point"), path(core_types::vector))]
|
||||
async fn vec2_to_point(_: impl Ctx, vec2: DVec2) -> List<Vector> {
|
||||
let mut point_domain = PointDomain::new();
|
||||
point_domain.push(PointId::generate(), vec2);
|
||||
|
||||
List::new_from_item(Item::new_from_element(Vector { point_domain, ..Default::default() }))
|
||||
/// Type-asserts a value to be vector data.
|
||||
#[node_macro::node(category("Vector"), name("As Vector"), path(core_types::vector))]
|
||||
fn as_vector(_: impl Ctx, value: List<Vector>) -> List<Vector> {
|
||||
value
|
||||
}
|
||||
|
||||
/// Creates a polyline from a series of vector points, replacing any existing segments and regions that may already exist.
|
||||
|
||||
Reference in New Issue
Block a user