Skip to content

Commit c764e55

Browse files
committed
Clean up (not compiling because of DVec2 clamping)
1 parent 51e12e0 commit c764e55

File tree

3 files changed

+52
-61
lines changed

3 files changed

+52
-61
lines changed

node-graph/gcore/src/vector/generator_nodes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ impl GridSpacing for DVec2 {
150150
}
151151

152152
#[node_macro::node(category("Vector: Shape"), properties("grid_properties"))]
153-
fn grid<T: GridSpacing>(
153+
fn grid<T: GridSpacing + std::cmp::PartialOrd + FromPrimitive>(
154154
_: impl Ctx,
155155
_primary: (),
156156
grid_type: GridType,
157-
#[min(0.)]
157+
#[hard_min(0.)]
158158
#[default(10)]
159159
#[implementations(f64, DVec2)]
160160
spacing: T,

node-graph/gcore/src/vector/vector_nodes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,8 @@ async fn generate_handles(
879879
// _: impl Ctx,
880880
// source: VectorDataTable,
881881
// #[default(1.)]
882-
// #[min(1.)]
883-
// #[max(8.)]
882+
// #[hard_min(1.)]
883+
// #[soft_max(8.)]
884884
// subdivisions: f64,
885885
// ) -> VectorDataTable {
886886
// let source_transform = source.transform();

node-graph/node-macro/src/validation.rs

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,67 +21,58 @@ pub fn validate_node_fn(parsed: &ParsedNodeFn) -> syn::Result<()> {
2121

2222
fn validate_min_max(parsed: &ParsedNodeFn) {
2323
for field in &parsed.fields {
24-
match field {
25-
ParsedField::Regular {
26-
number_hard_max,
27-
number_hard_min,
28-
number_soft_max,
29-
number_soft_min,
30-
pat_ident,
31-
..
32-
} => {
33-
match (number_soft_min, number_hard_min) {
34-
(Some(soft_min), Some(hard_min)) => {
35-
let soft_min_value: f64 = soft_min.base10_parse().unwrap_or_default();
36-
let hard_min_value: f64 = hard_min.base10_parse().unwrap_or_default();
37-
if soft_min_value == hard_min_value {
38-
emit_error!(
39-
pat_ident.span(),
40-
"Unnecessary #[soft_min] attribute on `{}` as #[hard_min] equals to it.",
41-
pat_ident.ident;
42-
help = "You can safely remove the #[soft_min] attribute from this field.";
43-
note = "The #[hard_min] also limits the range to same without #[soft_min]",
44-
);
45-
} else if soft_min_value < hard_min_value {
46-
emit_error!(
47-
pat_ident.span(),
48-
"The #[soft_min] attribute exists on `{}` and is lower than #[hard_min].",
49-
pat_ident.ident;
50-
help = "You probably meant to reverse the two macros";
51-
note = "Allowing the possible range in slider to be more than #[hard_min] doesn't make sense",
52-
);
53-
}
54-
}
55-
_ => (),
24+
if let ParsedField::Regular {
25+
number_hard_max,
26+
number_hard_min,
27+
number_soft_max,
28+
number_soft_min,
29+
pat_ident,
30+
..
31+
} = field
32+
{
33+
if let (Some(soft_min), Some(hard_min)) = (number_soft_min, number_hard_min) {
34+
let soft_min_value: f64 = soft_min.base10_parse().unwrap_or_default();
35+
let hard_min_value: f64 = hard_min.base10_parse().unwrap_or_default();
36+
if soft_min_value == hard_min_value {
37+
emit_error!(
38+
pat_ident.span(),
39+
"Unnecessary #[soft_min] attribute on `{}`, as #[hard_min] has the same value.",
40+
pat_ident.ident;
41+
help = "You can safely remove the #[soft_min] attribute from this field.";
42+
note = "#[soft_min] is redundant when it equals #[hard_min].",
43+
);
44+
} else if soft_min_value < hard_min_value {
45+
emit_error!(
46+
pat_ident.span(),
47+
"The #[soft_min] attribute on `{}` is incorrectly greater than #[hard_min].",
48+
pat_ident.ident;
49+
help = "You probably meant to reverse the two attribute values.";
50+
note = "Allowing the possible slider range to preceed #[hard_min] doesn't make sense.",
51+
);
5652
}
53+
}
5754

58-
match (number_soft_max, number_hard_max) {
59-
(Some(soft_max), Some(hard_max)) => {
60-
let soft_max_value: f64 = soft_max.base10_parse().unwrap_or_default();
61-
let hard_max_value: f64 = hard_max.base10_parse().unwrap_or_default();
62-
if soft_max_value == hard_max_value {
63-
emit_error!(
64-
pat_ident.span(),
65-
"Unnecessary #[soft_max] attribute on `{}` as #[hard_max] equals to it.",
66-
pat_ident.ident;
67-
help = "You can safely remove the #[soft_max] attribute from this field.";
68-
note = "The #[hard_max] also limits the range to same without #[soft_max]",
69-
);
70-
} else if soft_max_value < hard_max_value {
71-
emit_error!(
72-
pat_ident.span(),
73-
"The #[soft_max] attribute exists on `{}` and is greater than #[hard_max].",
74-
pat_ident.ident;
75-
help = "You probably meant to reverse the two macros";
76-
note = "Allowing the possible range in slider to be more than #[hard_max] doesn't make sense",
77-
);
78-
}
79-
}
80-
_ => (),
55+
if let (Some(soft_max), Some(hard_max)) = (number_soft_max, number_hard_max) {
56+
let soft_max_value: f64 = soft_max.base10_parse().unwrap_or_default();
57+
let hard_max_value: f64 = hard_max.base10_parse().unwrap_or_default();
58+
if soft_max_value == hard_max_value {
59+
emit_error!(
60+
pat_ident.span(),
61+
"Unnecessary #[soft_max] attribute on `{}`, as #[hard_max] has the same value.",
62+
pat_ident.ident;
63+
help = "You can safely remove the #[soft_max] attribute from this field.";
64+
note = "#[soft_max] is redundant when it equals #[hard_max].",
65+
);
66+
} else if soft_max_value < hard_max_value {
67+
emit_error!(
68+
pat_ident.span(),
69+
"The #[soft_max] attribute on `{}` is incorrectly greater than #[hard_max].",
70+
pat_ident.ident;
71+
help = "You probably meant to reverse the two attribute values.";
72+
note = "Allowing the possible slider range to exceed #[hard_max] doesn't make sense.",
73+
);
8174
}
8275
}
83-
84-
_ => (),
8576
}
8677
}
8778
}

0 commit comments

Comments
 (0)