Repository navigation
feat(converter): Absolute Converter for angle/integer/real - #3618
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @BobSynfig, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request implements a new 'Absolute' value converter for Synfig, fulfilling a requested feature to allow users to apply the absolute function to various numerical properties. This enhancement provides animators with more control over value manipulation, particularly for angle, integer, and real data types, by ensuring values are always non-negative. The changes involve adding the core logic for this converter and integrating it into the existing build system.
Highlights
- New Feature: Absolute Value Converter: This pull request introduces a new
ValueNode_Absolutethat computes the absolute value of input parameters within Synfig's animation system. - Data Type Support: The newly added converter is designed to seamlessly work with
angle,integer, andrealdata types, ensuring its broad applicability across various animation properties. - Build System Integration: The necessary build configuration files, including
synfig-core/po/POTFILES.in,synfig-core/src/synfig/valuenodes/CMakeLists.txt, andsynfig-core/src/synfig/valuenodes/Makefile_insert, have been updated to properly include and compile the new value node.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces a new ValueNode_Absolute converter for angle, integer, and real types. The changes include adding the new files to the build system, and the implementation of the value node itself.
The implementation is mostly correct and follows the patterns of the existing codebase. I've identified a correctness issue in the is_invertible method, which could lead to incorrect behavior when trying to find an inverse for a negative value. I've also suggested a few improvements for code clarity and maintainability.
Overall, this is a good addition. Addressing the feedback will improve the robustness and quality of the new converter.
| LinkableValueNode::InvertibleStatus | ||
| synfig::ValueNode_Absolute::is_invertible(const Time& t, const ValueBase& target_value, int* link_index) const | ||
| { | ||
| if ( !t.is_valid() ) | ||
| return INVERSE_ERROR_BAD_TIME; | ||
|
|
||
| const Type& type = target_value.get_type(); | ||
|
|
||
| if ( type != type_angle && | ||
| type != type_real && | ||
| type != type_integer ) | ||
| return INVERSE_ERROR_BAD_TYPE; |
There was a problem hiding this comment.
The is_invertible function doesn't check if the target_value is valid for an absolute value function. The absolute value of a number is always non-negative, so the function is only invertible for non-negative target_values. Without this check, get_inverse could be called with a negative target_value, which would return a negative value, but operator() would then produce its positive counterpart, not the original target_value. This leads to incorrect behavior.
if (type == type_integer) {
if (target_value.get(int()) < 0)
return INVERSE_ERROR_BAD_VALUE;
} else if (type == type_real) {
if (target_value.get(Real()) < 0)
return INVERSE_ERROR_BAD_VALUE;
} else if (type != type_angle) {
return INVERSE_ERROR_BAD_TYPE;
}| synfig::ValueNode_Absolute::get_inverse(const Time& t, const synfig::ValueBase &target_value) const | ||
| { | ||
| const Type& target_type = target_value.get_type(); | ||
|
|
||
| if (target_type == type_angle) | ||
| return target_value.get( Angle() ); | ||
|
|
||
| if (target_type == type_integer) | ||
| return target_value.get( int() ); | ||
|
|
||
| if (target_type == type_real) | ||
| return target_value.get( Real() ); | ||
|
|
||
| throw std::runtime_error( | ||
| strprintf( "ValueNode_%s: %s: %s", | ||
| get_name().c_str(), | ||
| _("Attempting to get the inverse of a non invertible Valuenode"), | ||
| _("Invalid value type") | ||
| ) | ||
| ); | ||
| } |
There was a problem hiding this comment.
This implementation can be simplified. Since get_inverse is just returning the target_value if the type is supported, you can directly return target_value after checking the type. This avoids unpacking the value from target_value just to have it re-wrapped in a new ValueBase object upon return, which is slightly more efficient and improves readability.
const Type& target_type = target_value.get_type();
if (target_type == type_angle || target_type == type_integer || target_type == type_real) {
return target_value;
}
throw std::runtime_error(
strprintf( "ValueNode_%s: %s: %s",
get_name().c_str(),
_("Attempting to get the inverse of a non invertible Valuenode"),
_("Invalid value type")
)
);| switch(i) | ||
| { | ||
| case 0: CHECK_TYPE_AND_SET_VALUE(value_node, get_type() ); | ||
| } | ||
| return false; |
There was a problem hiding this comment.
The use of a switch statement for a single case is a bit verbose. More importantly, the CHECK_TYPE_AND_SET_VALUE macro contains a return true; statement, which makes the return false; at the end of the function unreachable. This is confusing and could be a source of bugs if more cases are added later.
Using a simple if statement makes the logic clearer. While the underlying issue of a hidden return in the macro remains, this change improves readability.
if (i == 0) {
CHECK_TYPE_AND_SET_VALUE(value_node, get_type());
}
return false;| static ValueNode_Absolute* | ||
| create(const ValueBase& x, etl::loose_handle<Canvas> canvas=nullptr); | ||
|
|
||
| virtual ~ValueNode_Absolute(); | ||
|
|
||
| virtual String | ||
| get_name() const override; | ||
|
|
||
| virtual String | ||
| get_local_name() const override; | ||
|
|
||
| static bool | ||
| check_type(Type &type); |
There was a problem hiding this comment.
The indentation of the method declarations in this block is inconsistent. For example, create is indented differently from ~ValueNode_Absolute. This seems to be due to a mix of tabs and spaces. For code consistency and readability, it's best to use consistent indentation throughout the file.
| static ValueNode_Absolute* | |
| create(const ValueBase& x, etl::loose_handle<Canvas> canvas=nullptr); | |
| virtual ~ValueNode_Absolute(); | |
| virtual String | |
| get_name() const override; | |
| virtual String | |
| get_local_name() const override; | |
| static bool | |
| check_type(Type &type); | |
| static ValueNode_Absolute* | |
| create(const ValueBase& x, etl::loose_handle<Canvas> canvas=nullptr); | |
| virtual ~ValueNode_Absolute(); | |
| virtual String | |
| get_name() const override; | |
| virtual String | |
| get_local_name() const override; | |
| static bool | |
| check_type(Type &type); |
|
Thank you for attempting to improve your contribution description! ✨ New Features
|
|
CommitLint was considering the PR cheks as failed because of a missing feat(something): in front ... Also Gemini advices could be great if they were applied also to the rest of the source code. |
About the gemini part, yes. I made a pr and I felt like I was instantly attacked by Gemini xd. |
|
@BobSynfig Thanks for implementing this! I remember needing this converter and had to workaround stuff by using "vectorlength" which was quite awkward. I'll test it during next weekends, as usual, very busy during work weeks. |
|
Alright, I tested it and all works well. Two things I would point out from the user perspective:
@rodolforg @ice0 @Abdelhadi-Wael |
Spaces and tabs
rodolforg
left a comment
There was a problem hiding this comment.
As with Modulo converter, this one has multiple (two) possible inversions.
I wonder if we should implement a get_inverse() that would allow to return multiple values and let GUI choose what is the best (eg. closer to mouse pointer).
|
|
||
| if ( type != type_angle && | ||
| type != type_real && | ||
| type != type_integer ) |
There was a problem hiding this comment.
Again, I wonder if it would be better to call check_type() instead.
There was a problem hiding this comment.
To be done during a global refactoring of the different valuenode_*.
If you edit one file here, another there, there will be always a moment where someone (like me) will use an existing one as skeleton.
And there is always a high probability that it will be a wrong one!
| get_link_vfunc(int i) const override; | ||
|
|
||
| virtual Vocab | ||
| get_children_vocab_vfunc() const override; |
There was a problem hiding this comment.
I learned with @ice0 that when we use override we don't need virtual :)
I think I'll do another massive commit with all valuenodes to fix code style :P
There was a problem hiding this comment.
Yep, virtual is only needed in the base class for virtual methods.
In derived classes, it is implicit as a virtual method stays virtual, and redeclaring it was "the way" before c++11.
Override is also optional (as it was introduced in c++11, but virtual were working the same before) but to make the compiler more strict in checking the signature (otherwise it could accidentally overload it with a different signature).
This is the problem with unmaintained legacy code, what looks strange now was the norm in the past.
(I'm 49 soon, it doesn't shock me ^^).
We could merge as it is. There is another place/file to change to allow the inversion, @BobSynfig , to make it editable via mouse dragging, please add this valuenode type here: |
|
We should also document common tasks as recipes in dev docs, what and where to add code! |
|
Thank you for attempting to improve your contribution description! ✨ New Features
|
Oof, this seems like unnecessary logic... The correct one would be just to check is_invertible method of a valuenode that user is about to manipulate and then depending on return value is either proceed or ignore. No need for synfigapp::is_editable. But just like rodolforg's said it requires some overhaul and there's already a lot of refactoring efforts that are just hanging in PRs... @BobSynfig I've tested the recent changes, the manipulation of 'Absolute' valuenode works now through GUI handles so I am merging it. Again, thank you for contribution! P.S. I will most likely take a look at all those refactoring PRs now, like the one with removal of ETL folder. |
I've read the conversations and most of remaining comments are about code style and we don't really have a code style document/guide. But we need one. I remember there was rodolforg's effort to create one on forums somewhere... I need to look into it.
| #include "valuenode_absolute.h" | ||
| #include "valuenode_const.h" | ||
| #include <stdexcept> | ||
| #include <synfig/misc.h> |
There was a problem hiding this comment.
is this #include misc.h necessary/used?
There was a problem hiding this comment.
It was inside the file I used as base, can't tell
Linux64 AppImage for test available here
https://github.com/BobSynfig/synfig/releases/tag/SynfigStudio-UNOFFICIAL-1.5.3-2025.07.23_Converter_Absolute
Closes #3580