Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: monkey0506 on Wed 27/01/2016 19:02:48

Title: MODULE: MathsPlus v1.0 - Abs, AbsInt, Ceil, Floor, Max, MaxInt, Min, MinInt...
Post by: monkey0506 on Wed 27/01/2016 19:02:48
DOWNLOAD (https://sites.google.com/site/monkey0506/MathsPlus.scm?attredirects=0&d=1)

The MathsPlus module adds some additional Maths functions, including:

* float Maths.Abs(float)
* float Maths.Ceil(float)
* float Maths.Floor(float)
* float Maths.Max(float, float)
* float Maths.Min(float, float)
* float Maths.Round(float)
* int Maths.AbsInt(int)
* int Maths.MaxInt(int, int)
* int Maths.MinInt(int, int)

Requires AGS 3.4.0.6 or higher
Title: Re: MODULE: MathsPlus v1.0 - Abs, AbsInt, Ceil, Floor, Max, MaxInt, Min, MinInt...
Post by: Sslaxx on Fri 29/01/2016 13:46:25
Any chance of this being integrated into AGS proper?
Title: Re: MODULE: MathsPlus v1.0 - Abs, AbsInt, Ceil, Floor, Max, MaxInt, Min, MinInt...
Post by: Gurok on Thu 11/02/2016 06:57:31
I think we want to eventually have some kind of polymorphism or type coercion for AGS proper. i.e. A Maths.Abs() that would support both floats and ints. For now, I think this is a good approach.

This library might also work as a good study reference or just time-tested implementations of common methods. I am not sure what your intention was though, Monkey. Was this just to fill gaps in the existing library or to be more of a supplemental library with slightly less general use things?

Whatever the case, there's Clamp, which is common for graphics stuff:


// Clamp a number to a specified range
float Maths::Clamp(float value, float minimum, float maximum);
int Maths::ClampInt(int value, int minimum, int maximum);


If you are taking further suggestions, here are some not-so-common ones I use:


// Find the distance between two points (a^2 + b^2 = c^2)
float Maths::DistanceBetween(float x1, float y1, float x2, float y2);
int Maths::DistanceBetweenInt(int x1, int y1, int x2, int y2);

// Find whether two ranges intersect (startA <= stopB and stopA >= startB)
// I put this in a method because it's annoying to have to work from the proof each time to get the right conditions
bool Maths::Intersects(float startA, float stopA, float startB, float stopB);
bool Maths::IntersectsInt(int startA, int stopA, int startB, int stopB);

// Return true if a given probability succeeds
// This is probably the best candidate for a library, as it's a standard form
bool Maths::Chance(float p); // p = 0.5 is a coin flip
// I actually use something like this because it's easy to read as "Chance(1, 20) => chance 1 in 20" and the default is a percentage
bool Maths::Chance(int numerator, int denominator = 100);


If this is a shared library, for something like Chance, it might be better to see which one people prefer.
Title: Re: MODULE: MathsPlus v1.0 - Abs, AbsInt, Ceil, Floor, Max, MaxInt, Min, MinInt...
Post by: Crimson Wizard on Thu 11/02/2016 12:05:43
I question the decision to give "basic" names to float variants, and specific names to integer ones.
I know this may sound naive, but I think AGSers use integers more often than floats, even in calculations; therefore it might be more natural for them to have simplier function names for integer variants. Float variants could be distinguished by F prefix or postfix (MaxF, MinF, AbsF, -- or -- FMax, FMin, FAbs, etc).
Title: Re: MODULE: MathsPlus v1.0 - Abs, AbsInt, Ceil, Floor, Max, MaxInt, Min, MinInt...
Post by: monkey0506 on Fri 12/02/2016 06:06:11
Quote from: Crimson Wizard on Thu 11/02/2016 12:05:43I question the decision to give "basic" names to float variants, and specific names to integer ones.

Your rationale about the general use case might be accurate, but I picked the names I did to better mirror the existing methods, which all operate on floats.

I didn't have any particular purpose behind the module except filling in gaps for common functions that I particularly needed. These specific ones are probably general enough to warrant a built-in implementation, but I would rate it as very low priority (although, the implementations themselves are trivial, so...).
Title: Re: MODULE: MathsPlus v1.0 - Abs, AbsInt, Ceil, Floor, Max, MaxInt, Min, MinInt...
Post by: vga256 on Thu 31/08/2023 22:32:32
Apologies for the necropost - since monkey0506's link is long dead, just wanted to share an archived link to the module:
Download Here (https://web.archive.org/web/20201009211721/https://48f8441d-a-62cb3a1a-s-sites.googlegroups.com/site/monkey0506/MathsPlus.scm?attachauth=ANoY7crhf5DZ1IN1rjXf70FCEL7O-4BLfr4bmg8I-Tu8C1msJYhIrefzVLzBLlAG4EcoLsBF0SWeGGZHpQDYdE2jOnz8PZl1a6GZqiyLj9KJcLVXdQLyA7F8rb2sbMyx3oPbiWKPLWZU3aHGXaIBe5G_JiRaGmmhVdzkgIShBs16D17-_7WxvCnMqGTkrsuWBl0o40GSHNSg_sL-bme8uMHzL08QhWwIsg%3D%3D&attredirects=0)