Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add concat function (WIP) #338

Closed
wants to merge 5 commits into from
Closed

Add concat function (WIP) #338

wants to merge 5 commits into from

Conversation

Reptorian1125
Copy link

@Reptorian1125 Reptorian1125 commented Feb 26, 2022

It doesn't seem discoverable by g'mic cli. I'm also not expecting mp_concat to work due to very little experience with C++. This is more of a starting point.

It doesn't work, but in theory, it should be able to be used on G'MIC. I'm missing something here.
It doesn't work on vector. That's something that needs to be addressed.
I would like to figure out how to retrieve characters from mp_arg(i_end). I want the function to be able to differentiate whether the last argument contains a . at the beginning if that is possible. If not, then this can be pushed.
@Reptorian1125
Copy link
Author

Reptorian1125 commented Feb 27, 2022

Here's the output so far:

c:\gmic-devel\gmic\src>gmic echo {concat(-50,20,30,.09)}
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ -502030.09000000003
[gmic]-0./ End G'MIC interpreter.

c:\gmic-devel\gmic\src>gmic echo {concat(5,20,30,.09)}
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ 52030.089999999997
[gmic]-0./ End G'MIC interpreter.

c:\gmic-devel\gmic\src>gmic echo {concat(5,20,30,8)}
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ 520308
[gmic]-0./ End G'MIC interpreter.

For first one, since the last argument doesn't have a 0 at the beginning, a unnecessary 0 is added. But, I believe users can address that with ease.

@dtschump
Copy link
Collaborator

Won't consider this for merging, because:

  • This functions seems rather useless by itself. Maybe you need it for a certain filter, but for general use, concatenate numbers is not a common operation, particularly when it is already possible to concatenate strings.
  • Moreover, this won't work for large numbers. Numbers are stored in double, and there is no way this concat() function can work with any number of arguments.

@Reptorian1125
Copy link
Author

Reptorian1125 commented Feb 27, 2022

This functions seems rather useless by itself. Maybe you need it for a certain filter, but for general use, concatenate numbers is not a common operation, particularly when it is already possible to concatenate strings.

It's not common, yes, I agree. However, this is easier to work with when using math evaluation within G'MIC, which is exactly why I have created it in the first place. It also enables access to this function within filters that supports custom expression, which is another reason why I did this. This doesn't involve strings. One can do something like this in G'MIC with some time though with the setback of having to copy and paste this function.

Moreover, this won't work for large numbers. Numbers are stored in double, and there is no way this concat() function can work with any number of arguments.

Yes, large numbers won't work with it, I agree with that. It does work for any number of arguments from 1-n where the concatenated number is less than DBL_MAX.

That being said, at the end of the day, I respect your decision.

@dtschump
Copy link
Collaborator

Also, there is a way to do this directly with macros :

foo :
  eval "
    nbd(x) = x>0?1+int(log10(x)):1;
    concat(a,b) = (a*10^nbd(b) + b);
    concat(a,b,c) = (concat(a,b)*10^nbd(c) + c);
    concat(a,b,c,d) = (concat(a,b,c)*10^nbd(d) + d);
    concat(a,b,c,d,e) = (concat(a,b,c,d)*10^nbd(e) + e);

    print(concat(100,50,25,12,7));
  "

@Reptorian1125
Copy link
Author

I did not realize that functions with same name can have different numbers of arguments at all. Thanks.

@Reptorian1125
Copy link
Author

Reptorian1125 commented Feb 27, 2022

I may have prematurely closed this.

After trying to make own macro generator within G'MIC. I realized that my concat() function in this pull request actually factors into conditions such as whether the first argument is a positive or a negative, and whether every arguments except the last one contains a decimal. It doesn't look very feasible to do this in G'MIC language. My solution solves most of the shortcomings with the G'MIC macro.

Maybe, I'll have another crack, but I find it very difficult to work without resorting to math-based approach. Maybe it's not worth reopening.

Reptorian1125 added a commit to GreycLab/gmic-community that referenced this pull request Feb 28, 2022
This is an attempt at generator for macro lines found here - GreycLab/CImg#338
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.

2 participants