New useful features in math parser, planned in 2.9.8

The “Gradient Bar” filter seems to work here.
How can I get the error ?

Remove the " around $sub.

It works, with my current version 2.9.8_pre#210520

Ah, I think that’s why.

Here’s my version:

  gmic: GREYC's Magic for Image Computing: command-line interface
        Version 2.9.8 (pre-release #210512)

Downloaded from here - Index of /files/prerelease

5/19/2021 is the date of the last version that is available without compiling.

Ok, I’ll try to build a new package for Windows tonight then.

1 Like

@David_Tschumperle - It works, thank you very much. Only problem is on the PDN side of thing, not much I can about. I will just wait till there’s official update to remove the unnecessary " s on my code.

New changes also planed in the math parser, for 2.9.8 :

  • New functions deg2rad() and rad2deg() converts angles specified in degrees to radians (and vice versa).
  • New postfix operator ° (UTF8-symbol for degrees) can be added to convert an angle in degrees to radians, as in the expression cos(45°) (eq. to cos(deg2rad(45)) or cos(45*pi/180) ).
  • Functions rot() and ellipse() now consider that their angle arguments are specified in radians instead of degrees (just like the other trigonometric functions in the math parser).

All this avoids to add a bunch of new functions as cosd(), sind(), ... (as done in R, Matlab, etc.)
This may requires some changes in your scripts anyway (even if I tried to make the change myself).

1 Like

Could you allow something like 45d or 45deg? It may be unconventional but the key combination for ° isn’t easy to remember. It is ALT+0176 on Windows.

Ahhh, Windows and UTF-8… UTF-8 seems to be a too much advanced technology for Windows. :nauseated_face:

I’ll try to find something else then, maybe 45*, that is the closest I can think of.

Is it completely different on your keyboards? I have it with <shift>^ . I think * has a completely different connotation!

Yes, I admit I’m not that happy about this possible alternative.

Imagine a formula e.g. sin(($alpha/3)°+pi/4) with * !

Yes, definitely ugly :slight_smile: Thanks Karsten.

Personally, I’m ok with the symbol addition. It is just a copy and paste into your gmic file, and you can always find it. I think deg2rad() and rad2deg() is more than enough with regards with degree indicator.

Also, is the ~ taken? Maybe ‘o’ as degree indicator?

What I think right now is that the postfix operator should keep the ° symbol. After all, that is the official degree symbol :slight_smile: Anything else will look weird.

Windows users that cannot use it can still use deg2rad() indeed (or *pi/180).
That’s more solutions than we actually need in fact!

A quick coding and testing here leads me to this.

rep_hex2img_test:
if narg($1)&&narg($2)
 hex2img $1
 hex2img $2
 hex_col_a={crop(#-2)}
 hex_col_b={crop(#-1)}
 rm[-2,-1]
fi

c=4
1,500,1,3,"begin(
 a=["$hex_col_a"];
 print(a);
 c=$c;
 print(c);
);
1;
"

For multiple numbers to work within a, one would have to use “” wrappers. Would it be possible to allow the math parser to read multi-number variable defined in the gmic interpreter?

Also, brings me a idea. is hex2vec a thing?

EDIT:

Got the hex2vec thing to work.

rep_hex2vec:

1,1,1,3,"begin(
  from_char(a)=a>=48&&a<=57?a-48:a-87;
  
  hex2vec(a)=(
   v=('$1');
   const vs=size(v);
   const m=int(vs/2);
   nv=vectorm(0);
   repeat(m,p,
    nv[p]=from_char(v[2*p])*16+from_char(v[2*p+1]);
   );
   nv;
  );
  
  hex_a=hex2vec($1);
 );
 hex_a[c];"

No, that’s not possible, because the $-operator in the math parser is intended to be a constant value. Vector-valued items or variables cannot be defined to be constant.
I’ve thought a long time about allowing const vectors to be defined in the math parser, but would introduce some disadvantages that do not compensate for the few advantages it provides.

Late to the party commenting here, but on the whole, a “like”. For tutorial writing purposes, I anticipate using deg2rad() and rad2deg() a good deal more than ° because the two formers clearly spell out their intent, and newcomers are already battling with understanding a script author’s intent. Neither requires special keyboard gyrations to get - for some platforms - a ‘special character’. In truth, I had to teach myself to love °. I get its convenience: I may write degrees everywhere and post-fixed ° makes them everywhere radians. That, and ensuring that every angular-related function now takes radians, is a consistency i enjoy. Nice to see this.

PS - thanks for the patches for my scripts. Much appreciated!

1 Like

Yep, I will be using the two macros (mackerels :yum:). About the degree symbol, I am curious how you input it on your system? I haven’t used Linux, etc., in a while…

Personally, I have this symbol directly on my keyboard (AZERTY / France), on the key with the right parenthesis.

Otherwise, it seems that with the Compose key, you can do COMPOSE + o + o.