Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
meganindya committed Jun 17, 2020
1 parent d176c4e commit 5ca0f51
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion js/utils/mathutils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
/**
* @file This contains the encapsulation related to math operations.
* @author Walter Bender
*
* @copyright 2014-2020 Walter Bender
* @copyright 2020 Anindya Kundu
*
* @license
* This program is free software; you can redistribute it and/or modify it under the terms of
* the The GNU Affero General Public License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* You should have received a copy of the GNU Affero General Public License along with this
* library; if not, write to the Free Software Foundation, 51 Franklin Street, Suite 500 Boston,
* MA 02110-1335 USA.
*/

/**
* Utility class for managing math operations.
*
* @class
* @classdesc This is the prototype that encapsulates the ten math operations: random, one-of,
* modulus, square root, add, subtract, multiply, divide, eucleidean distance, and exponent.
* The methods verify the input/s and return the operations' results or throws an exception if
* the arguments are invalid, which is then handled by their callers, i.e. `arg` methods in
* NumberBlocks.js
*/
class MathUtility {
/**
* Returns a random integer in a range.
*
* @static
* @param a - preferably the minimum
* @param b - preferably the maximum
* @returns {Number}
Expand Down Expand Up @@ -39,6 +67,7 @@ class MathUtility {
/**
* Randomly returns either a or b.
*
* @static
* @param a
* @param b
* @returns {*}
Expand All @@ -50,6 +79,7 @@ class MathUtility {
/**
* Returns a modulo b.
*
* @static
* @param a
* @param b
* @returns {Number}
Expand All @@ -66,6 +96,7 @@ class MathUtility {
/**
* Square-roots a number.
*
* @static
* @param a
* @returns {Number}
* @throws {String} No square root error, NAN error
Expand All @@ -85,6 +116,7 @@ class MathUtility {
/**
* Adds a and b.
*
* @static
* @param a
* @param b
* @returns {Number|String}
Expand All @@ -103,6 +135,7 @@ class MathUtility {
/**
* Subtracts b from a.
*
* @static
* @param a
* @param b
* @returns {Number}
Expand All @@ -119,6 +152,7 @@ class MathUtility {
/**
* Multiplies a by b.
*
* @static
* @param a
* @param b
* @returns {Number}
Expand All @@ -135,6 +169,7 @@ class MathUtility {
/**
* Divides a by b.
*
* @static
* @param a
* @param b
* @returns {Number}
Expand All @@ -155,6 +190,7 @@ class MathUtility {
/**
* Calculates euclidean distance between (cursor x, cursor y) and (mouse 'x' and mouse 'y').
*
* @static
* @param a
* @param b
* @param c
Expand Down Expand Up @@ -182,6 +218,7 @@ class MathUtility {
/**
* Returns a to the power of b.
*
* @static
* @param a
* @param b
* @returns {Number}
Expand All @@ -194,4 +231,4 @@ class MathUtility {
throw "NanError";
}
}
}
}

0 comments on commit 5ca0f51

Please sign in to comment.