Add an Autoscale option to the Brush tool - #4485
Open
timon-schelling wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
2 issues found across 1 file
Confidence score: 3/5
- In
editor/src/messages/tool/tool_messages/brush_tool.rs, toggling Autoscale can reinterpret an unchanged brush diameter in the wrong unit, causing the brush size to change unexpectedly; convertoptions.diameterusing the current viewport zoom when switching modes. - In
editor/src/messages/tool/tool_messages/brush_tool.rs, non-representable zoom values can make round-tripped diameters fail exact equality, creating a new brush group instead of matching the existing stroke; use a scale-aware floating-point comparison.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="editor/src/messages/tool/tool_messages/brush_tool.rs">
<violation number="1" location="editor/src/messages/tool/tool_messages/brush_tool.rs:221">
P2: When the user toggles Autoscale with a brush layer selected, this branch reinterprets the unchanged diameter in the wrong unit. Convert `options.diameter` by the current viewport zoom when changing modes so the existing document-space diameter remains unchanged.</violation>
<violation number="2" location="editor/src/messages/tool/tool_messages/brush_tool.rs:387">
P2: When autoscale selection sync round-trips a diameter through a non-representable zoom, exact equality rejects the matching stroke and creates a new brush group. 比较 the diameters with a scale-aware floating-point tolerance.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| let value = |index: usize| node.inputs.get(index).and_then(|input| input.as_value()); | ||
| matches!(value(STROKES_COLOR_INPUT), Some(TaggedValue::Color(color)) if *color == options.active_color()) | ||
| && matches!(value(STROKES_DIAMETER_INPUT), Some(TaggedValue::F64(diameter)) if *diameter == options.diameter) | ||
| && matches!(value(STROKES_DIAMETER_INPUT), Some(TaggedValue::F64(diameter)) if *diameter == options.stroke_diameter(document)) |
Contributor
There was a problem hiding this comment.
P2: When autoscale selection sync round-trips a diameter through a non-representable zoom, exact equality rejects the matching stroke and creates a new brush group. 比较 the diameters with a scale-aware floating-point tolerance.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At editor/src/messages/tool/tool_messages/brush_tool.rs, line 387:
<comment>When autoscale selection sync round-trips a diameter through a non-representable zoom, exact equality rejects the matching stroke and creates a new brush group. 比较 the diameters with a scale-aware floating-point tolerance.</comment>
<file context>
@@ -355,7 +384,7 @@ impl BrushToolData {
let value = |index: usize| node.inputs.get(index).and_then(|input| input.as_value());
matches!(value(STROKES_COLOR_INPUT), Some(TaggedValue::Color(color)) if *color == options.active_color())
- && matches!(value(STROKES_DIAMETER_INPUT), Some(TaggedValue::F64(diameter)) if *diameter == options.diameter)
+ && matches!(value(STROKES_DIAMETER_INPUT), Some(TaggedValue::F64(diameter)) if *diameter == options.stroke_diameter(document))
&& matches!(value(STROKES_HARDNESS_INPUT), Some(TaggedValue::F64(hardness)) if *hardness == options.hardness)
&& matches!(value(STROKES_FLOW_INPUT), Some(TaggedValue::F64(flow)) if *flow == options.flow)
</file context>
Suggested change
| && matches!(value(STROKES_DIAMETER_INPUT), Some(TaggedValue::F64(diameter)) if *diameter == options.stroke_diameter(document)) | |
| && matches!(value(STROKES_DIAMETER_INPUT), Some(TaggedValue::F64(diameter)) if (*diameter - options.stroke_diameter(document)).abs() <= f64::EPSILON * diameter.abs().max(options.stroke_diameter(document).abs()).max(1.)) |
| responses.add(ToolMessage::SelectWorkingColor { color, primary: true }); | ||
| } | ||
| } | ||
| BrushToolMessageOptionsUpdate::Autoscale(autoscale) => self.options.autoscale = autoscale, |
Contributor
There was a problem hiding this comment.
P2: When the user toggles Autoscale with a brush layer selected, this branch reinterprets the unchanged diameter in the wrong unit. Convert options.diameter by the current viewport zoom when changing modes so the existing document-space diameter remains unchanged.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At editor/src/messages/tool/tool_messages/brush_tool.rs, line 221:
<comment>When the user toggles Autoscale with a brush layer selected, this branch reinterprets the unchanged diameter in the wrong unit. Convert `options.diameter` by the current viewport zoom when changing modes so the existing document-space diameter remains unchanged.</comment>
<file context>
@@ -190,6 +218,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for Brus
responses.add(ToolMessage::SelectWorkingColor { color, primary: true });
}
}
+ BrushToolMessageOptionsUpdate::Autoscale(autoscale) => self.options.autoscale = autoscale,
BrushToolMessageOptionsUpdate::WorkingColorsChanged => {
self.options.color.fill_choice = Some(solid(context.global_tool_data.primary_color));
</file context>
Suggested change
| BrushToolMessageOptionsUpdate::Autoscale(autoscale) => self.options.autoscale = autoscale, | |
| BrushToolMessageOptionsUpdate::Autoscale(autoscale) => { | |
| if self.options.autoscale != autoscale { | |
| let zoom = viewport_zoom(context.document); | |
| self.options.diameter = if autoscale { self.options.diameter * zoom } else { self.options.diameter / zoom }; | |
| } | |
| self.options.autoscale = autoscale; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
注册 for free
to join this conversation on GitHub.
Already have an account?
登录 to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.