Package Exports
- @danehansen/math
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@danehansen/math) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
#math#
The math library contains a collection of mathematical equations either written or collected to make shit easier and awesomer.
##Public Methods##
- average(...args):Number
[static] Accepts either an unlimited quantity of numbers or an array of numbers and returns the total. - ceil(num:Number, increment:Number = 1):Number
[static] Rounds a number up to the nearest increment. - circleIntersection(centerA:Point, radiusA:Number, centerB:Point, radiusB:Number):Number
[static] Returns an array of the two points at which 2 circles intersect, if they intersect. - cover(content:Element, frame:Element)
[static] Takes content element and fills the entirety of the frame element to scale. This would be likened to filling an element with a background image where with the css propertybackground-size:cover
but where that is not possible, Such as filling an element with a video element. It is assumed that the content will haveposition:absolute
and the frame will have at least some sort of positioning applied, and probably alsooverflow:hidden
. To scale the content, the original dimentions of the item before manipulation are recorded and then referred to each time it is resized. For example, if you are filling the entire background of a page with a bleeding video, the body would haveposition:relative
andoverflow:hidden
applied, and the video would haveposition:absolute
as well aswidth:1280px
andheight:720px
. - ease(current:Number, dest:Number, speed:Number = 0.05):Number
[static] Eases a number towards the destination by a factor of speed. Great for making a display object follow a mouse cursor or some other moving target. - easeProp(targ:Object, key:String, dest:Number, speed:Number = 0.05)
[static] Brings the object’s provided property (targ[key]) towards the destination by a factor of speed. Great for making a display object follow a mouse cursor or some other moving target. - euclid(a:int, b:int):int
[static] Returns the greatest common divisor of two integers. - floor(num:Number, increment:Number = 1):Number
[static] Rounds a number down to the nearest increment. - intLength(num:uint):uint
[static] Returns the number of decimals in an integer. - luhn(num:uint):Boolean
[static] Returns whether or not an integer meets the Luhn validation. - modulo(num:Number, limit:Number):Number
[static] Similar to the modulo (%) operator, but rather than mirroring at 0, it continues past 0. For example, -1%4=-1, but modulo(-1, 4)=3. Great for when you decrement a value below 0 and need the functionality to wrap, like an image gallery. - primes(limit:Number):Array
[static] Returns an array of all prime numbers between 0 and limit. - random(limitA:Number, limitB:Number = 0, round:Boolean = false, choke:int = 1):Number
[static] Returns a random number between limit1 and limit2. Optionally, it will be rounded. The choke... tough one to explain. It is a representation of how to make the random number favor towards the middle of the two limits. There is a difference between Math.random()*2, and Math.random()+Math.random(), and this argument builds upon that. If you covered a square with 100 points all with random x and y positions, leaving the natural factor would result in scattered points like until a section of a starry night. With natural bumped up to 2 or higher, it would look more like a shotgun blast. - randomChoice(array:* = [-1,1], choke:int = 1):*
[static] Returns a random value from the provided array or list. The default is [-1,1] for instances when you need to randomly determine if something should be left or right, up or down. - relativePercentage(start:Number, end:Number, current:Number):Number
[static] Returns the position of current in reference to a scale between start and end. Example: relativePercentage(2,4,3) returns 0.5. - round(num:Number, increment:Number):Number
[static] Returns a number rounded by the increment, rather than by 1. - shuffle(array:Number, duplicate:Boolean = false):Array
[static] Shuffles the provided array or list. If duplicate is set to true, the original list is left alone and the shuffled list is returned on a new array. Note: when shuffling a NodeList, always set duplicate to true as a NodeList does not shuffle well. - sortAscending(a:Number, b:Number):Number
[static] Returns the difference between the a and b, meant to pass into the Array.sort method as an alternate to the default alphabetical. - sortDescending(a:Number, b:Number):Number
[static] Returns the reversed difference between a and b, meant to pass into the Array.sort method as an alternate to the default alphabetical. - splitUint(num:int):Array
[static] Returns an array representing each digit of an integer. - toDegrees(radians:Number, offset:Boolean = false):Number
[static] Converts an angle in radians to degrees. By default, just returns an angle of the same amount measured in degrees, but when set to true will also account for offsetting by 1/4 turn. - toRadians(degrees:Number, offset:Boolean = false):Number
[static] Converts an angle in degrees to radians. By default, just returns an angle of the same amount measured in radians, but when set to true will also account for offsetting by 1/4 turn. - total(array:*):Number
[static] Calculates the total in an array or list of values. Truthy values will also be totaled as 1s and falsey values as 0s.