Closed LetsMelon closed 1 year ago
There is this: https://github.com/rhaiscript/rhai-sci
Perhaps it is better to expand rhai-sci
?
I think these functions would better fit in the BasicMathPackage
because of the simplicity of the functions and the comprehensive area of application.
e.g.:
pixel mapping from a float value with the range 0.0 - 1.0
to an 0.0 - 255.0
range -> map(1.0, 0.0, 1.0, 0.0, 255.0)
[1]
[1] maybe a better implementation of map
can cast between float and integer so that you can do this: map(1.0, 0.0, 1.0, 0, 255)
) an store the result in rust as u8
It probably won't be Basic
... if we put it in the standard library, we probably would need to create something like MoreMathPackage
etc.
Actually I see many of your proposed functions already in rhai-sci
so perhaps it is not a good idea to duplicate.
And the remaining ones are really not very standard and have specific uses in specific cases.
Yeah duplicates with rhai-sci
would be a terrible solution in every point.
But I think it's also not a great solution to add another crate to a project to have a function like min(x, y)
and max(x, y)
.
And where is the line if a function should go into a package distributed with rhai
(and enabled by default) or with a seperate crate (like rhai-sci
)?
But nevertheless a official and tested distribution of the missing (or more, or less, ...) in rhai-sci
would be better than none.
But nevertheless a official and tested distribution of the missing (or more, or less, ...) in
rhai-sci
would be better than none.
And then maybe it would also be a great idea to mention rhai-sci
in the docs page for Numeric Functions.
There are more things to consider. For example, the max
function takes two numbers.
Normally, in the standard library, numbers can interoperate, and there are INT
, FLOAT
, Decimal
.
So we're looking at nine combinations and so nine versions of the function. Seven if excluding float+decimal.
This falls into the gray area where we need to ponder whethrr to add max and min. Because they can easily be replaced by an if
expression.
Alright, come to think of it, I agree that max
and min
probably should belong to the standard library, considering that operators like >
and <
are defined for numbers.
I'll add them. Like all the other operators, floating-point can also inter-operate with integers for max
and min
.
It would be nice if the
BasicMathPackage
implements more basic functions, like some functions processing implements by default.from processings docs:
abs()
Calculates the absolute value (magnitude) of a numberceil()
Calculates the closest int value that is greater than or equal to the value of the parameterconstrain()
Constrains a value to not exceed a maximum and minimum valueexp()
Returns Euler's number e (2.71828...) raised to the power of the value parameterfloor()
Calculates the closest int value that is less than or equal to the value of the parameterlerp()
Calculates a number between two numbers at a specific incrementlog()
Calculates the natural logarithm (the base-e logarithm) of a numbermap()
Re-maps a number from one range to anothermax()
Determines the largest value in a sequence of numbersmin()
Determines the smallest value in a sequence of numbersnorm()
Normalizes a number from another range into a value between 0 and 1pow()
Facilitates exponential expressionsround()
Calculates the integer closest to the value parametersq()
Squares a number (multiplies a number by itself)sqrt()
Calculates the square root of a numberother functions from the docs: (but I'm not quit sure if they would be really necessary and maybe they should go into a separate package for vectors)
dist()
Calculates the distance between two pointsmag()
Calculates the magnitude (or length) of a vector(Sorry if I missed a already implemented function from the packages and I'm in love with this crate, so easy to use)