Skip to content

feat(converter): Absolute Converter for angle/integer/real - #3618

Merged
Svarov-RZM merged 7 commits into
synfig:masterfrom
BobSynfig:converter_abs
Feb 1, 2026
Merged

Svarov-RZM merged 7 commits into
synfig:masterfrom
BobSynfig:converter_abs

Conversation

@BobSynfig

@BobSynfig BobSynfig commented Jul 23, 2025 •

Copy link
Copy Markdown
Collaborator

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_Absolute that 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, and real data 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, and synfig-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

  1. 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. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +163 to +174
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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;
	}

Comment on lines +141 to +161
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")
)
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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")
	    )
	);

Comment on lines +187 to +191
switch(i)
{
case 0: CHECK_TYPE_AND_SET_VALUE(value_node, get_type() );
}
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;

Comment on lines +54 to +66
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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);

@BobSynfig BobSynfig changed the title Absolute Converter for angle/integer/real feat(converter): Absolute Converter for angle/integer/real Jul 24, 2025
@github-actions

Copy link
Copy Markdown

Thank you for attempting to improve your contribution description!
Below is how your updated contribution will appear in Synfig's release notes. Review it and make further improvements until you're satisfied!

✨ New Features

@BobSynfig

Copy link
Copy Markdown
Collaborator Author

CommitLint was considering the PR cheks as failed because of a missing feat(something): in front ...
Not because the code was bad ...
Other PR suffer the same issue, like #3607 for example
Do we really need this sh!t feature?

Also Gemini advices could be great if they were applied also to the rest of the source code.
Obviously it doesn't recognize when some code is directly inspired from existing ones and the "intention" that lies behind.
Too much optimization for a specific purpose could lead to other deeper bugs in the future.

@mohamedAdhamc

Copy link
Copy Markdown
Member

CommitLint was considering the PR cheks as failed because of a missing feat(something): in front ... Not because the code was bad ... Other PR suffer the same issue, like #3607 for example Do we really need this sh!t feature?

Also Gemini advices could be great if they were applied also to the rest of the source code. Obviously it doesn't recognize when some code is directly inspired from existing ones and the "intention" that lies behind. Too much optimization for a specific purpose could lead to other deeper bugs in the future.

About the gemini part, yes. I made a pr and I felt like I was instantly attacked by Gemini xd.

@Svarov-RZM Svarov-RZM self-assigned this Jan 25, 2026
@Svarov-RZM

Copy link
Copy Markdown
Contributor

@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.

@Svarov-RZM

Copy link
Copy Markdown
Contributor

Alright, I tested it and all works well. Two things I would point out from the user perspective:

  • The 'Absolute' node is invertible but GUI doesn't see it as such. I think there must be some hook in the GUI logic for it to recognize it. I am not currently sure whether this converter should support inverse manipulation or not. If there will be a requirement for it we will add it in the future
  • Perhaps this converter should also support 'vector' type, but again, I don't have a use-case for it now. We can add it later if needed

@rodolforg @ice0 @Abdelhadi-Wael
Guys, if you don't have any issues with the code, I will squash and merge it closer to the middle of the next week

@rodolforg rodolforg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I wonder if it would be better to call check_type() instead.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ^^).

@rodolforg

rodolforg commented Jan 31, 2026 •

Copy link
Copy Markdown
Contributor
  • The 'Absolute' node is invertible but GUI doesn't see it as such. I think there must be some hook in the GUI logic for it to recognize it. I am not currently sure whether this converter should support inverse manipulation or not. If there will be a requirement for it we will add it in the future

We could merge as it is. There is another place/file to change to allow the inversion, but I think I'll remove this requirement (it exists before the implementation of get_inverse() and related methods) (forget it, too much work lol).

@BobSynfig , to make it editable via mouse dragging, please add this valuenode type here:
synfigapp::is_editable(synfig::ValueNode::Handle value_node) in synfigapp/instance.cpp.

@BobSynfig

Copy link
Copy Markdown
Collaborator Author

synfigapp/instance.cpp is one of those very ugly files with 6-7 levels of nesting and pre-c++11 crappy code.

We should also document common tasks as recipes in dev docs, what and where to add code!

@github-actions

Copy link
Copy Markdown

Thank you for attempting to improve your contribution description!
Below is how your updated contribution will appear in Synfig's release notes. Review it and make further improvements until you're satisfied!

✨ New Features

@Svarov-RZM

Copy link
Copy Markdown
Contributor

to make it editable via mouse dragging, please add this valuenode type here:
synfigapp::is_editable(synfig::ValueNode::Handle value_node) in synfigapp/instance.cpp.

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.

@Svarov-RZM
Svarov-RZM dismissed rodolforg’s stale review February 1, 2026 06:31

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.

@Svarov-RZM
Svarov-RZM merged commit 0d059a1 into synfig:master Feb 1, 2026
#include "valuenode_absolute.h"
#include "valuenode_const.h"
#include <stdexcept>
#include <synfig/misc.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this #include misc.h necessary/used?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was inside the file I used as base, can't tell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: New convert type - Absolute value

4 participants