# GeometricMath

## GeometricMath

A Class of static methods used for various geometry calculations and basic collision detection. Also contains some Array helper methods; splice and mergeArrays.

## Constructor

### Methods

#### (static) arcCurvePoint(t, p0x, p0y, p1x, p1y, p2x, p2y) → {MoverPoint}

Returns the MoverPoint on the arc curve that is defined by the x/y pairs given. The MoverPoint returned is in relation to t (0 to .9) on the curve. This method creates and returns a new MoverPoint, to avoid that instead use updateArcCurvePath with a premade MoverPoint.

Parameters:
Name Type Description
`t` Number

translation on the path from which to get the one point; 0 to .9.

`p0x` Number

x position of first point in curve path

`p0y` Number

y position of first point in curve path

`p1x` Number

x position of middle point in curve path

`p1y` Number

y position of middle point in curve path

`p2x` Number

x position of last point in curve path

`p2y` Number

y position of last point in curve path

Returns:
Type
MoverPoint

#### (static) getArcCurvePath(p0, p1, p2, amountOfPathPoints) → {Array}

Returns an Array of MoverPoints that make up the arc defined by the points given. p0 is the first leftmost point of the arc, p1 is the middle of the arc, and p2 is the end of the arc.

Parameters:
Name Type Description
`p0` MoverPoint

the first MoverPoint of the arc path

`p1` MoverPoint

the middle MoverPoint of the arc path

`p2` MoverPoint

the last MoverPoint of the arc path

`amountOfPathPoints` Number

the number of points along the path to return.

Returns:
Type
Array

#### (static) getHermiteCurvePath() → {Array}

Returns an Array of MoverPoints that make up the hermite (wave) path as defined by the points given.

Returns:
Type
Array

#### (static) getMoverPointsOnCircle(circleCenter, circleRadius, numberOfPoints) → {Array}

Returns an Array of MoverPoints that make up a circle as defined by circleCenter, and circleRadius

Parameters:
Name Type Description
`circleCenter` MoverPoint

the center point of the circle

`circleRadius` Number

`numberOfPoints` Number

the amount of points to get

Returns:
Type
Array

#### (static) getRawArcCurvePath(p0x, p0y, p1x, p1y, p2x, p2y, amountOfPathPoints, prePath) → {Array|Number}

Returns an Array of x and y pairs that make up the locations of each point along the path defined by the x/y pairs given. This is the most efficient method to use to obtain a arc curve path, then loop through the array by 2 to use each x y location.

Parameters:
Name Type Description
`p0x` Number

the x position of the first point.

`p0y` Number

the y position of the first point.

`p1x` Number

the x position of the middle point.

`p1y` Number

the y position of the middle point.

`p2x` Number

the x position of the last point.

`p2y` Number

the y position of the last point.

`amountOfPathPoints` Number

the amount of points to calculate.

`prePath` Array

a predefined Array to hold the path.

Returns:
Type
Array | Number

#### (static) getRawHermiteCurvePath() → {Array|Number}

Returns or updates an Array of x/y pairs that make up the hermite (wave) path as defined by the x/y pairs given.

Returns:
Type
Array | Number

#### (static) getRawPointsOnCircle(circleCenterX, circleCenterY, circleRadius, numberOfPoints) → {Array}

Returns an Array of the x/y pairs that define each point along the circle defined by circleCenterX/Y circleRaidus and numberOfPoints.

Parameters:
Name Type Description
`circleCenterX` Number

the x position of the circles center

`circleCenterY` Number

the y position of the circles center

`circleRadius` Number

`numberOfPoints` Number

the amount of points to get

Returns:
Type
Array

#### (static) hermiteCurvePoint(t, p0x, p0y, t0x, t0y, p1x, p1y, t1x, t1y) → {MoverPoint}

Returns the point on the hermite (wave) curve as defined by t and the x/y pairs given. Creates and returns a new MoverPoint.

Parameters:
Name Type Description
`t` Number
`p0x` Number

the x position of the first point.

`p0y` Number

the y position of the first point.

`t0x` Number

the x position of the middle point.

`t0y` Number

the y position of the middle point.

`p1x` Number

the x position of the last point.

`p1y` Number

the y position of the last point.

`t1x` Number

the x position of the middle point.

`t1y` Number

the y position of the middle point.

Returns:
Type
MoverPoint

#### (static) isPowerOfTwo(x) → {Boolean}

Returns true if the number given is a power of 2.

Parameters:
Name Type Description
`x` Number

The Number to check.

Returns:
Type
Boolean

#### (static) lineIntersectionPoint(a, b, c, d) → {MoverPoint}

Returns the point at which the lines interset or null.

Parameters:
Name Type Description
`a`

beginning point of line one

`b`

ending point of line one

`c`

beginning point of line two

`d`

ending point of line two

Returns:
Type
MoverPoint

#### (static) lineIntersectionTest(a, b, c, d) → {Boolean}

Returns true if the two lines intersect.

Parameters:
Name Type Description
`a`

beginning point of line one

`b`

ending point of line one

`c`

beginning point of line two

`d`

ending point of line two

Returns:
Type
Boolean

#### (static) mergeArrays(a1, a2) → {Array}

Merges two or more Arrays into a1 and returns a1.

Parameters:
Name Type Description
`a1` Array

The Array that should get the other Arrays values added to it at the end

`a2` Array

The first Array whos values will get added to the end of a1, any other Arrays passed will keep getting added to the end.

Returns:

One Array containing the values of all the Arrays given.

Type
Array

#### (static) rectanglesIntersect(r1, r2) → {Boolean}

Returns true if the two given Rectangles intersect.

Parameters:
Name Type Description
`r1` Rectangle
`r2` Rectangle
Returns:
Type
Boolean

#### (static) rectanglesOverlapAmount(r1, r2) → {Number}

Returns the amount of overlap between two Rectangles, if any.

Parameters:
Name Type Description
`r1` Rectangle
`r2` Rectangle
Returns:
Type
Number

#### (static) splice(arr, index)

Splices the given Array at the given index, without returning anything.

Parameters:
Name Type Description
`arr` Array

The Array to splice

`index` Number

The index at which to splice the Array.

#### (static) testForPointInArea(p, left, right, top, bottom) → {Boolean}

Returns true if the given point is inside the area defined by left top right and bottom cords.

Parameters:
Name Type Description
`p` MoverPoint

the point to check if its in the given area.

`left` Number

the left (x) position of the area

`right` Number

the right (x+width) position of the area

`top` Number

the top (y) position of the area

`bottom` Number

the bottom (y+height) position of the area

Returns:
Type
Boolean

#### (static) testForPointInCircle(circlePosition, circleRadius, pointToTest) → {Boolean}

Returns true if the given point is inside the circle defined by circlePosition and circleRadius

Parameters:
Name Type Description
`circlePosition` MoverPoint

the position of the circle (its center)

`circleRadius` Number

`pointToTest` MoverPoint

the point to test and see if its inside the circles area.

Returns:
Type
Boolean

#### (static) updateArcCurvePath(path, p0, p1, p2)

Updates the Array path given with the MoverPoints that make up the arc defined by the points given. A path should first be made using the GeometricMath.getArcCurvePath method.

Parameters:
Name Type Description
`path` Array

an Array of MoverPoints to update

`p0` MoverPoint

the first point in the arc curve path

`p1` MoverPoint

the middle point in the arc curve path

`p2` MoverPoint

the last point in the arc curve path

#### (static) updateArcCurvePoint(point, t, p0x, p0y, p1x, p1y, p2x, p2y)

Updates the given MoverPoint on the arc curve defined by the x/y pairs given. The update is based on t, which is a 0 to .9 value, the amount of points the path has being 1. The path is defined by p0x...p2y.

Same as the arcCurvePoint method except that you pass in a pre made MoverPoint that gets updated.

Parameters:
Name Type Description
`point` MoverPoint

The MoverPoint to store the point on the path.

`t` Number

translation on the path from which to get the one point; 0 to .9.

`p0x` Number

x position of first point in curve path

`p0y` Number

y position of first point in curve path

`p1x` Number

x position of middle point in curve path

`p1y` Number

y position of middle point in curve path

`p2x` Number

x position of last point in curve path

`p2y` Number

y position of last point in curve path