diff --git a/Changes.txt b/Changes.txt index 8384d96..6a3480e 100644 --- a/Changes.txt +++ b/Changes.txt @@ -1,3 +1,35 @@ +0.10.0 +==== +Added: +---- + +Changed: +---- +- mlib.line.segment is now mlib.segment. +- mlib.line.getIntercept has been renamed to mlib.line.getYIntercept +- mlib.line.getYIntercept now returns the x-coordinate for vertical lines instead of false. +- mlib.line.getPerpendicularBisector is now mlib.segment.getPerpendicularBisector. +- mlib.math.getPercentOfChange now returns the percentage instead of the decimal answer. + +Fixed: +---- +- mlib.line.getIntersection now should handle vertical slopes better. +- mlib.line.getClosestPoint now uses local function checkFuzzy for checking horizontal lines. +- Fixed possible bug in mlib.line.getSegmentIntersection and vertical lines. +- mlib.segment.getIntersection now uses fuzzy checking for parallel lines. +- mlib.math.round is now much more efficient. +- Removed some useless code from mlib.polygon.isSegmentInside. + +To-Do +---- +- Determine if isCompletelyInsideFunctions should return true with tangents. +- Check argument order for logicality and consistency. +- Improve speed. +- Add error checking. +- Make sure to see if any aliases were missed. (e.g. isSegmentInside) +- Implement mlib.shapes again(?) +- Clean up and correct README (add "Home" link, etc.) + 0.9.4 ==== Added: diff --git a/README.md b/README.md index 1887c97..02fedd2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ MLib ==== -__MLib__ is a math and collisions library written in Lua. It's aim is to be __robust__ and __easy to use__. +__MLib__ is a math and collisions library written in Lua. It's aim is to be __robust__ and __easy to use__. ##Downloading You can download the latest __stable__ version of MLib by downloading the latest [release](https://github.com/davisdude/mlib/releases/). @@ -11,7 +11,7 @@ You can download the latest __working__ version of MLib by downloading the lates To use MLib, simply place [mlib.lua](mlib.lua) inside the desired folder in your project. Then use the `require 'path.to.mlib'` to use any of the functions. ##Examples -You can see some examples of the code in action [here](https://github.com/davisdude/mlib/tree/master/Examples/). +You can see some examples of the code in action [here](https://github.com/davisdude/mlib/tree/master/Examples/). All examples are done using the *awesome* engine of [LÖVE](https://love2d.org/). To run them properly, download the [.love file](https://github.com/davisdude/mlib/blob/master/Examples/Shapes.love) and install LÖVE to your computer. After that, make sure you set .love files to open with "love.exe". @@ -19,8 +19,8 @@ For more, see [here](https://love2d.org/). ##When should I use MLib? - If you need to know exactly where two objects intersect. -- If you need general mathematical equations to be done. -- If you need very precise details about point intersections. +- If you need general mathematical equations to be done. +- If you need very precise details about point intersections. ##When should I __not__ use MLib? - All of the objects in a platformer, or other game, for instance, should not be registered with MLib. Only ones that need very specific information. @@ -35,7 +35,7 @@ If that does not work, you made need to put a link to Lua inside of the folder f ``` lua tsc -f specs.lua ``` -If you encounter further errors, try to run the command line as an administrator (usually located in `C:\Windows\System32\`), then right-click on `cmd.exe` and select `Run as administrator`, then do +If you encounter further errors, try to run the command line as an administrator (usually located in `C:\Windows\System32\`), then right-click on `cmd.exe` and select `Run as administrator`, then do ``` cd C:\Path\to\telescope\ ``` @@ -48,7 +48,7 @@ And __then__ run one of the above commands. If none of those work, just take my - [mlib.line.getCircleIntersection](https://github.com/davisdude/mlib#mliblinegetcircleintersection) - [mlib.line.getClosestPoint](https://github.com/davisdude/mlib#mliblinegetclosestpoint) - [mlib.line.getDistance](https://github.com/davisdude/mlib#mliblinegetdistance) - - [mlib.line.getIntercept](https://github.com/davisdude/mlib#mliblinegetintercept) + - [mlib.line.getYIntercept](https://github.com/davisdude/mlib#mliblinegetintercept) - [mlib.line.getIntersection](https://github.com/davisdude/mlib#mliblinegetintersection) - [mlib.line.getLength](https://github.com/davisdude/mlib#mliblinegetlength) - [mlib.line.getLineIntersection](https://github.com/davisdude/mlib#mliblinegetlineintersection) @@ -58,15 +58,15 @@ And __then__ run one of the above commands. If none of those work, just take my - [mlib.line.getPolygonIntersection](https://github.com/davisdude/mlib#mliblinegetpolygonintersection) - [mlib.line.getSegmentIntersection](https://github.com/davisdude/mlib#mliblinegetsegmentintersection) - [mlib.line.getSlope](https://github.com/davisdude/mlib#mliblinegetslope) -- [mlib.line.segment](https://github.com/davisdude/mlib#mliblinesegment) - - [mlib.line.segment.checkPoint](https://github.com/davisdude/mlib#mliblinesegmentcheckpoint) - - [mlib.line.segment.getCircleIntersection](https://github.com/davisdude/mlib#mliblinesegmentgetcircleintersection) - - [mlib.line.segment.getPolygonIntersection](https://github.com/davisdude/mlib#mliblinesegmentgetpolygonintersection) - - [mlib.line.segment.getLineIntersection](https://github.com/davisdude/mlib#mliblinesegmentgetlineintersection) - - [mlib.line.segment.getIntersection](https://github.com/davisdude/mlib#mliblinesegmentgetintersection) - - [mlib.line.segment.getSegmentIntersection](https://github.com/davisdude/mlib#mliblinesegmentgetsegmentintersection) - - [mlib.line.segment.isSegmentCompletelyInsideCircle](https://github.com/davisdude/mlib#mliblinesegmentissegmentcompletelyinsidecircle) - - [mlib.line.segment.isSegmentCompletelyInsidePolygon](https://github.com/davisdude/mlib#mliblinesegmentissegmentcompletelyinsidepolygon) +- [mlib.segment](https://github.com/davisdude/mlib#mliblinesegment) + - [mlib.segment.checkPoint](https://github.com/davisdude/mlib#mliblinesegmentcheckpoint) + - [mlib.segment.getCircleIntersection](https://github.com/davisdude/mlib#mliblinesegmentgetcircleintersection) + - [mlib.segment.getPolygonIntersection](https://github.com/davisdude/mlib#mliblinesegmentgetpolygonintersection) + - [mlib.segment.getLineIntersection](https://github.com/davisdude/mlib#mliblinesegmentgetlineintersection) + - [mlib.segment.getIntersection](https://github.com/davisdude/mlib#mliblinesegmentgetintersection) + - [mlib.segment.getSegmentIntersection](https://github.com/davisdude/mlib#mliblinesegmentgetsegmentintersection) + - [mlib.segment.isSegmentCompletelyInsideCircle](https://github.com/davisdude/mlib#mliblinesegmentissegmentcompletelyinsidecircle) + - [mlib.segment.isSegmentCompletelyInsidePolygon](https://github.com/davisdude/mlib#mliblinesegmentissegmentcompletelyinsidepolygon) - [mlib.polygon](https://github.com/davisdude/mlib#mlibpolygon) - [mlib.polygon.checkPoint](https://github.com/davisdude/mlib#mlibpolygoncheckpoint) - [mlib.polygon.getCentroid](https://github.com/davisdude/mlib#mlibpolygongetcentroid) @@ -117,33 +117,33 @@ And __then__ run one of the above commands. If none of those work, just take my - [mlib.math.getSummation](https://github.com/davisdude/mlib#mlibmathgetsummation) - [mlib.math.isPrime](https://github.com/davisdude/mlib#mlibmathisprime) - [mlib.math.round](https://github.com/davisdude/mlib#mlibmathround) - + ####mlib.line -- Deals with linear aspects, such as slope and length. +- Deals with linear aspects, such as slope and length. #####mlib.line.checkPoint - Checks if a point lies on a line. -- Synopsis: +- Synopsis: - `onPoint = mlib.line.checkPoint( px, px, x1, y1, x2, y2 )` - Arguments: - `px`, `py`: Numbers. The x and y coordinates of the point being tested. - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates of the line being tested. - Returns: - - `onPoint`: Boolean. + - `onPoint`: Boolean. - `true` if the point is on the line. - - `false` if it does not. + - `false` if it does not. - Notes: - You cannot use the format `mlib.line.checkPoint( px, px, slope, intercept )` because this would lead to errors on vertical lines. #####mlib.line.getCircleIntersection -- Returns the intersections of a circle and a line. +- Returns the intersections of a circle and a line. - Synopsis: - `intersections = mlib.line.getCircleIntersection( cx, cy, radius, x1, y1, x2, y2 )` - Arguments: - `cx`, `cy`: Numbers. The x and y coordinates for the center of the circle. - - `radius`: Number. The radius of the circle. - - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates the lie on the line. -- Returns: + - `radius`: Number. The radius of the circle. + - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates the lie on the line. +- Returns: - `intersections`: Table. A table with the type and where the intersections happened. Table is formatted: - `type`, `x1`, `y1`, `x2`, `y2` - String (`'secant'`), Number, Number, Number, Number @@ -151,46 +151,45 @@ And __then__ run one of the above commands. If none of those work, just take my - String (`'tangent'`), Number, Number, Boolean (`nil`), Boolean (`nil`) - `x1` and `x2` represent where the line intersects the circle. - Boolean (`false`), Boolean (`nil`), Boolean (`nil`), Boolean (`nil`), Boolean (`nil`) - - No intersection. + - No intersection. - For more see the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L233). - + #####mlib.line.getClosestPoint -- Gives the closest point to a line. -- Synopses: +- Gives the closest point to a line. +- Synopses: - `cx, cy = mlib.line.getClosestPoint( px, py, x1, y1, x2, y2 )` - `cx, cy = mlib.line.getClosestPoint( px, py, slope, intercept )` - Arguments: - - `x`, `y`: Numbers. The x and y coordinates of the point. - - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates on the line. - - `slope`, `intercept`: - - Numbers. The slope and y-intercept of the line. + - `x`, `y`: Numbers. The x and y coordinates of the point. + - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates on the line. + - `slope`, `intercept`: + - Numbers. The slope and y-intercept of the line. - Booleans (`false`). The slope and y-intercept of a vertical line. - Returns: - - `cx`, `cy`: Numbers. The closest points that lie on the line to the point. - + - `cx`, `cy`: Numbers. The closest points that lie on the line to the point. + #####mlib.line.getDistance -- Gives the distance between two points. -- Synopsis: +- Gives the distance between two points. +- Synopsis: - `length = mlib.line.getDistance( x1, y1, x2, y2 ) -- Arguments: +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates. -- Returns: - - `length`: Number. The distance between the two points. +- Returns: + - `length`: Number. The distance between the two points. -#####mlib.line.getIntercept +#####mlib.line.getYIntercept - Gives y-intercept of the line. - Synopses: - - `intercept = mlib.line.getIntercept( x1, y1, x2, y2 )` - - `intercept = mlib.line.getIntercept( x1, y1, slope )` -- Arguments: - - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates that lie on the line. - - `slope`: + - `intercept = mlib.line.getYIntercept( x1, y1, x2, y2 )` + - `intercept = mlib.line.getYIntercept( x1, y1, slope )` +- Arguments: + - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates that lie on the line. + - `slope`: - Number. The slope of the line. - - Boolean. The slope of the line (if the line is vertical)/ - Returns: - - `intercept`: - - Number. The y-intercept of the line. - - Boolean (`false`). The y-intercept for a vertical line. + - `intercept`: + - Number. The y-intercept of the line. + - Number. The `x1` coordinate of the line if the line is vertical. #####mlib.line.getIntersection - Gives the intersection of two lines. @@ -198,13 +197,13 @@ And __then__ run one of the above commands. If none of those work, just take my - `x, y = mlib.line.getIntersection( x1, y1, x2, y2, x3, y3, x4, y4 )` - `x, y = mlib.line.getIntersection( slope1, intercept1, x3, y3, x4, y4 )` - `x, y = mlib.line.getIntersection( slope1, intercept1, slope2, intercept2 )` -- Arguments: - - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates that lie on the first line. +- Arguments: + - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates that lie on the first line. - `x3`, `y3`, `x4`, `y4`: Numbers. Two x and y coordinates that lie on the second line. - - `slope1`, `intercept1`: + - `slope1`, `intercept1`: - Numbers. The slope and y-intercept of the first line. - Booleans (`false`). The slope and y-intercept of the first line (if the first line is vertical). - - `slope2`, `intercept2`: + - `slope2`, `intercept2`: - Numbers. The slope and y-intercept of the second line. - Booleans (`false`). The slope and y-intercept of the second line (if the second line is vertical). - Returns: @@ -215,13 +214,13 @@ And __then__ run one of the above commands. If none of those work, just take my - `false`, `nil`: The lines are parallel and __not__ collinear. #####mlib.line.getLength -- Gives the distance between two points. -- Synopsis: +- Gives the distance between two points. +- Synopsis: - `length = mlib.line.getLength( x1, y1, x2, y2 ) -- Arguments: +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates. -- Returns: - - `length`: Number. The distance between the two points. +- Returns: + - `length`: Number. The distance between the two points. #####mlib.line.getLineIntersection - Gives the intersection of two lines. @@ -229,13 +228,13 @@ And __then__ run one of the above commands. If none of those work, just take my - `x, y = mlib.line.getLineIntersection( x1, y1, x2, y2, x3, y3, x4, y4 )` - `x, y = mlib.line.getLineIntersection( slope1, intercept1, x3, y3, x4, y4 )` - `x, y = mlib.line.getLineIntersection( slope1, intercept1, slope2, intercept2 )` -- Arguments: - - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates that lie on the first line. +- Arguments: + - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates that lie on the first line. - `x3`, `y3`, `x4`, `y4`: Numbers. Two x and y coordinates that lie on the second line. - - `slope1`, `intercept1`: + - `slope1`, `intercept1`: - Numbers. The slope and y-intercept of the first line. - Booleans (`false`). The slope and y-intercept of the first line (if the first line is vertical). - - `slope2`, `intercept2`: + - `slope2`, `intercept2`: - Numbers. The slope and y-intercept of the second line. - Booleans (`false`). The slope and y-intercept of the second line (if the second line is vertical). - Returns: @@ -246,112 +245,112 @@ And __then__ run one of the above commands. If none of those work, just take my - `false`, `nil`: The lines are parallel and __not__ collinear. #####mlib.line.getMidpoint -- Gives the midpoint of two points. +- Gives the midpoint of two points. - Synopsis: - `x, y = mlib.line.getMidpoint( x1, y1, x2, y2 )` -- Arguments: - - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates. -- Returns: - - `x`, `y`: Numbers. The midpoint x and y coordinates. - -#####mlib.line.getPerpendicularBisector -- Gives the perpendicular bisector of a line. -- Synopsis: - - `x, y, slope = mlib.line.getPerpendicularBisector( x1, y1, x2, y2 )` -- Arguments: +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates. -- Returns: - - `x`, `y`: Numbers. The midpoint of the line. - - `slope`: - - Number. The perpendicular slope of the line. - - Boolean (`false`). The perpendicular slope of the line (if the original line was horizontal). +- Returns: + - `x`, `y`: Numbers. The midpoint x and y coordinates. #####mlib.line.getPerpendicularSlope -- Gives the perpendicular slope of a line. +- Gives the perpendicular slope of a line. - Synopses: - `perpSlope = mlib.line.getPerpendicularSlope( x1, y1, x2, y2 )` - `perpSlope = mlib.line.getPerpendicularSlope( slope )` -- Arguments: +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates. - - `slope`: Number. The slope of the line. -- Returns: - - `perpSlope`: - - Number. The perpendicular slope of the line. + - `slope`: Number. The slope of the line. +- Returns: + - `perpSlope`: + - Number. The perpendicular slope of the line. - Boolean (`false`). The perpendicular slope of the line (if the original line was horizontal). #####mlib.line.getPolygonIntersection -- Returns the coordinates of where a line intersects a polygon. -- Synopses: +- Returns the coordinates of where a line intersects a polygon. +- Synopses: - `intersections = mlib.line.getPolygonIntersection( x1, y1, x2, y2, vertices )` - `intersections = mlib.line.getPolygonIntersection( x1, y1, x2, y2, ... ) -- Arguments: +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: +- Returns: - `intersections`: Table. Contains the intersections. - Notes: - With collinear lines, they are actually broken up. i.e. `{ 0, 4, 0, 0 }` would become `{ 0, 4 }, { 0, 0 }`. #####mlib.line.getSegmentIntersection -- Gives the intersection of a line segment and a line. -- Synopses: +- Gives the intersection of a line segment and a line. +- Synopses: - `x1, y1, x2, y2 = mlib.line.getSegmentIntersection( x1, y1, x2, y2, x3, y3, x4, y4 )` - `x1, y1, x2, y2 = mlib.line.getSegmentIntersection( x1, y1, x2, y2, slope, intercept )` -- Arguments: +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates that lie on the line segment. - `x3`, `y3`, `x4`, `y4`: Numbers. Two x and y coordinates that lie on the line. - - `slope`, `intercept`: + - `slope`, `intercept`: - Numbers. The slope and y-intercept of the the line. - Booleans (`false`). The slope and y-intercept of the line (if the line is vertical). - Returns: - - `x1`, `y1`, `x2`, `y2`: - - Number, Number, Number, Number. + - `x1`, `y1`, `x2`, `y2`: + - Number, Number, Number, Number. - The points of the line segment if the line and segment are collinear. - - Number, Number, Boolean (`nil`), Boolean (`nil`). + - Number, Number, Boolean (`nil`), Boolean (`nil`). - The coordinate of intersection if the line and segment intersect and are not collinear. - - Boolean (`false`), Boolean (`nil`), Boolean (`nil`), - - Boolean (`nil`). If the line and segment don't intersect. + - Boolean (`false`), Boolean (`nil`), Boolean (`nil`), + - Boolean (`nil`). If the line and segment don't intersect. #####mlib.line.getSlope -- Gives the slope of a line. -- Synopsis: +- Gives the slope of a line. +- Synopsis: - `slope = mlib.line.getSlope( x1, y1, x2, y2 ) -- Arguments: +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates. -- Returns: +- Returns: - `slope`: - - Number. The slope of the line. + - Number. The slope of the line. - Boolean (`false`). The slope of the line (if the line is vertical). -####mlib.line.segment -- Deals with line segments. +####mlib.segment +- Deals with line segments. -#####mlib.line.segment.checkPoint -- Checks if a point lies on a line segment. +#####mlib.segment.checkPoint +- Checks if a point lies on a line segment. - Synopsis: - - `onSegment = mlib.line.segment.checkPoint( px, py, x1 y1, x2, y2 )` -- Arguments: + - `onSegment = mlib.segment.checkPoint( px, py, x1 y1, x2, y2 )` +- Arguments: - `px`, `py`: Numbers. The x and y coordinates of the point being checked. - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates. - Returns: - `onSegment`: Boolean. - `true` if the point lies on the line segment. - - `false` if the point does not lie on the line segment. + - `false` if the point does not lie on the line segment. -#####mlib.line.segment.getCircleIntersection -- Returns the intersections of a circle and a line segment. +#####mlib.line.getPerpendicularBisector +- Gives the perpendicular bisector of a line. - Synopsis: - - `intersections = mlib.line.segment.getCircleIntersection( cx, cy, radius, x1, y1, x2, y2 )` + - `x, y, slope = mlib.line.getPerpendicularBisector( x1, y1, x2, y2 )` +- Arguments: + - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates. +- Returns: + - `x`, `y`: Numbers. The midpoint of the line. + - `slope`: + - Number. The perpendicular slope of the line. + - Boolean (`false`). The perpendicular slope of the line (if the original line was horizontal). + +#####mlib.segment.getCircleIntersection +- Returns the intersections of a circle and a line segment. +- Synopsis: + - `intersections = mlib.segment.getCircleIntersection( cx, cy, radius, x1, y1, x2, y2 )` - Arguments: - `cx`, `cy`: Numbers. The x and y coordinates for the center of the circle. - - `radius`: Number. The radius of the circle. - - `x1`, `y1`, `x2`, `y2`: Numbers. The two x and y coordinates of the line segment. -- Returns: + - `radius`: Number. The radius of the circle. + - `x1`, `y1`, `x2`, `y2`: Numbers. The two x and y coordinates of the line segment. +- Returns: - `intersections`: Table. A table with the type and where the intersections happened. Table is formatted: - `type`, `x1`, `y1`, `x2`, `y2` - String (`'chord'`), Number, Number, Number, Number - - The numbers are the x and y coordinates where the line segment is on both edges of the circle. + - The numbers are the x and y coordinates where the line segment is on both edges of the circle. - String (`'enclosed'`), Number, Number, Number, Number - The numbers are the x and y coordinates of the line segment if it is fully inside of the circle. - String (`'secant'`), Number, Number, Number, Number @@ -359,144 +358,144 @@ And __then__ run one of the above commands. If none of those work, just take my - String (`'tangent'`), Number, Number, Boolean (`nil`), Boolean (`nil`) - `x1` and `x2` represent where the line segment intersects the circle. - Boolean (`false`), Boolean (`nil`), Boolean (`nil`), Boolean (`nil`), Boolean (`nil`) - - No intersection. + - No intersection. - For more see the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L324). -#####mlib.line.segment.getPolygonIntersection -- Returns the coordinates of where a line segmeing intersects a polygon. -- Synopses: - - `intersections = mlib.line.segment.getPolygonIntersection( x1, y1, x2, y2, vertices )` - - `intersections = mlib.line.segment.getPolygonIntersection( x1, y1, x2, y2, ... ) -- Arguments: +#####mlib.segment.getPolygonIntersection +- Returns the coordinates of where a line segmeing intersects a polygon. +- Synopses: + - `intersections = mlib.segment.getPolygonIntersection( x1, y1, x2, y2, vertices )` + - `intersections = mlib.segment.getPolygonIntersection( x1, y1, x2, y2, ... ) +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: +- Returns: - `intersections`: Table. Contains the intersections. - Notes: - - With collinear line segments, they are __not__ broken up. See the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L346) for more. - -#####mlib.line.segment.getLineIntersection -- Gives the intersection of a line segment and a line. -- Synopses: - - `x1, y1, x2, y2 = mlib.line.segment.getLineIntersection( x1, y1, x2, y2, x3, y3, x4, y4 )` - - `x1, y1, x2, y2 = mlib.line.segment.getLineIntersection( x1, y1, x2, y2, slope, intercept )` -- Arguments: + - With collinear line segments, they are __not__ broken up. See the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L346) for more. + +#####mlib.segment.getLineIntersection +- Gives the intersection of a line segment and a line. +- Synopses: + - `x1, y1, x2, y2 = mlib.segment.getLineIntersection( x1, y1, x2, y2, x3, y3, x4, y4 )` + - `x1, y1, x2, y2 = mlib.segment.getLineIntersection( x1, y1, x2, y2, slope, intercept )` +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates that lie on the line segment. - `x3`, `y3`, `x4`, `y4`: Numbers. Two x and y coordinates that lie on the line. - - `slope`, `intercept`: + - `slope`, `intercept`: - Numbers. The slope and y-intercept of the the line. - Booleans (`false`). The slope and y-intercept of the line (if the line is vertical). - Returns: - - `x1`, `y1`, `x2`, `y2`: - - Number, Number, Number, Number. + - `x1`, `y1`, `x2`, `y2`: + - Number, Number, Number, Number. - The points of the line segment if the line and segment are collinear. - - Number, Number, Boolean (`nil`), Boolean (`nil`). + - Number, Number, Boolean (`nil`), Boolean (`nil`). - The coordinate of intersection if the line and segment intersect and are not collinear. - - Boolean (`false`), Boolean (`nil`), Boolean (`nil`), - - Boolean (`nil`). If the line and segment don't intersect. - -#####mlib.line.segment.getIntersection -- Checks if two line segments intersect. -- Synopsis: - - `cx1, cy1, cx2, cy2 = mlib.line.segment.getIntersection( x1, y1, x2, y2, x3, y3 x4, y4 )` -- Arguments: + - Boolean (`false`), Boolean (`nil`), Boolean (`nil`), + - Boolean (`nil`). If the line and segment don't intersect. + +#####mlib.segment.getIntersection +- Checks if two line segments intersect. +- Synopsis: + - `cx1, cy1, cx2, cy2 = mlib.segment.getIntersection( x1, y1, x2, y2, x3, y3 x4, y4 )` +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates of the first line segment. - `x3`, `y3`, `x4`, `y4`: Numbers. Two x and y coordinates of the second line segment. -- Returns: - - `cx1`, `cy1`, `cx2`, `cy2`: - - Number, Number, Number, Number. +- Returns: + - `cx1`, `cy1`, `cx2`, `cy2`: + - Number, Number, Number, Number. - The points of the resulting intersection if the line segments are collinear. - - Number, Number, Boolean (`nil`), Boolean (`nil`). - - The point of the resulting intersection if the line segments are not collinear. + - Number, Number, Boolean (`nil`), Boolean (`nil`). + - The point of the resulting intersection if the line segments are not collinear. - Boolean (`false`), Boolean (`nil`), Boolean (`nil`) , Boolean (`nil`). - - If the line segments don't intersect. + - If the line segments don't intersect. -#####mlib.line.segment.getSegmentIntersection -- Checks if two line segments intersect. -- Synopsis: - - `cx1, cy1, cx2, cy2 = mlib.line.segment.getIntersection( x1, y1, x2, y2, x3, y3 x4, y4 )` -- Arguments: +#####mlib.segment.getSegmentIntersection +- Checks if two line segments intersect. +- Synopsis: + - `cx1, cy1, cx2, cy2 = mlib.segment.getIntersection( x1, y1, x2, y2, x3, y3 x4, y4 )` +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates of the first line segment. - `x3`, `y3`, `x4`, `y4`: Numbers. Two x and y coordinates of the second line segment. -- Returns: - - `cx1`, `cy1`, `cx2`, `cy2`: - - Number, Number, Number, Number. +- Returns: + - `cx1`, `cy1`, `cx2`, `cy2`: + - Number, Number, Number, Number. - The points of the resulting intersection if the line segments are collinear. - - Number, Number, Boolean (`nil`), Boolean (`nil`). - - The point of the resulting intersection if the line segments are not collinear. + - Number, Number, Boolean (`nil`), Boolean (`nil`). + - The point of the resulting intersection if the line segments are not collinear. - Boolean (`false`), Boolean (`nil`), Boolean (`nil`) , Boolean (`nil`). - - If the line segments don't intersect. + - If the line segments don't intersect. -#####mlib.line.segment.isSegmentCompletelyInsideCircle +#####mlib.segment.isSegmentCompletelyInsideCircle - Checks if a polygon is completely inside of a circle. - Synopsis: - - `completelyInside = mlib.line.segment.isSegmentCompletelyInsideCircle( circleX, circleY, circleRadius, x1, y1, x2, y2 )` -- Arguments: - - `circleX`, `circleY`: Numbers. The x and y coordinates of the circle. + - `completelyInside = mlib.segment.isSegmentCompletelyInsideCircle( circleX, circleY, circleRadius, x1, y1, x2, y2 )` +- Arguments: + - `circleX`, `circleY`: Numbers. The x and y coordinates of the circle. - `circleRadius`: Number. The radius of the circle. - `x1`, `y1`: Numbers. The x and y coordinates of one end of the segment. - `x2`, `y2`: Numbers. The x and y coordinates of the other end of the segment. -- Returns: - - `completelyInside`: Boolean. +- Returns: + - `completelyInside`: Boolean. - `true` if the segment is inside of the circle. - `false` if the segment is not __completely__ inside of the circle. -#####mlib.line.segment.isSegmentCompletelyInsidePolygon -- Checks if a line segment is completely inside a polygon. +#####mlib.segment.isSegmentCompletelyInsidePolygon +- Checks if a line segment is completely inside a polygon. - Synopses: - - `inPolygon = mlib.line.segment.isSegmentCompletelyInsidePolygon( x1, y1, x2, y2, vertices )` - - `inPolygon = mlib.line.segment.isSegmentCompletelyInsidePolygon( x1, y1, x2, y2, ... )` -- Arguments: - - `x1`, `y1`, `x2`, `y2`: Numbers. The x and y coordinates of the line segment. + - `inPolygon = mlib.segment.isSegmentCompletelyInsidePolygon( x1, y1, x2, y2, vertices )` + - `inPolygon = mlib.segment.isSegmentCompletelyInsidePolygon( x1, y1, x2, y2, ... )` +- Arguments: + - `x1`, `y1`, `x2`, `y2`: Numbers. The x and y coordinates of the line segment. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: - - `inPolygon`: Boolean. - - `true` if the line segment is __completely__ inside the polygon. - - `false` if the line segment is not inside the polygon. +- Returns: + - `inPolygon`: Boolean. + - `true` if the line segment is __completely__ inside the polygon. + - `false` if the line segment is not inside the polygon. ####mlib.polygon -- Handles aspects involving polygons. +- Handles aspects involving polygons. #####mlib.polygon.checkPoint - Checks if a point is inside of a polygon. -- Synopses: +- Synopses: - `inPolygon = mlib.polygon.checkPoint( px, py, vertices )` - `inPolygon = mlib.polygon.checkPoint( px, py, ... )` -- Arguments: +- Arguments: - `px`, `py`: Numbers. The x and y coordinate of the point being checked. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: +- Returns: - `inPolygon`: Boolean. - - `true` if the point is inside the polygon. - - `false` if the point is not inside the polygon. + - `true` if the point is inside the polygon. + - `false` if the point is not inside the polygon. #####mlib.polygon.getCentroid -- Returns the centroid of the polygon. -- Synopses: +- Returns the centroid of the polygon. +- Synopses: - `cx, cy = mlib.polygon.getCentroid( vertices )` - `cx, cy = mlib.polygon.getCentroid( ... )` -- Arguments: +- Arguments: - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: - - `cx`, `cy`: Numbers. The x and y coordinates of the centroid. +- Returns: + - `cx`, `cy`: Numbers. The x and y coordinates of the centroid. #####mlib.polygon.getCircleIntersection -- Returns the coordinates of where a circle intersects a polygon. -- Synopses: +- Returns the coordinates of where a circle intersects a polygon. +- Synopses: - `intersections = mlib.polygon.getCircleIntersection( cx, cy, radius, vertices )` - `intersections = mlib.polygon.getCircleIntersection( cx, cy, radius, ... ) -- Arguments: +- Arguments: - `cx`, `cy`: Number. The coordinates of the center of the circle. - - `radius`: Number. The radius of the circle. + - `radius`: Number. The radius of the circle. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: - - `intersections`: Table. Contains the intersections and type. -- Example: +- Returns: + - `intersections`: Table. Contains the intersections and type. +- Example: ```lua local tab = _.polygon.getCircleIntersection( 5, 5, 1, 4, 4, 6, 4, 6, 6, 4, 6 ) for i = 1, #tab do @@ -510,180 +509,180 @@ end - For more see [mlib.circle.getSegmentIntersection](https://github.com/davisdude/mlib#mlibcirclegetsegmentintersection) or the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L557) #####mlib.polygon.getLineIntersection -- Returns the coordinates of where a line intersects a polygon. -- Synopses: +- Returns the coordinates of where a line intersects a polygon. +- Synopses: - `intersections = mlib.polygon.getLineIntersection( x1, y1, x2, y2, vertices )` - `intersections = mlib.polygon.getLineIntersection( x1, y1, x2, y2, ... ) -- Arguments: +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: +- Returns: - `intersections`: Table. Contains the intersections. - Notes: - With collinear lines, they are actually broken up. i.e. `{ 0, 4, 0, 0 }` would become `{ 0, 4 }, { 0, 0 }`. #####mlib.polygon.getPolygonArea -- Gives the area of a polygon. -- Synopses: +- Gives the area of a polygon. +- Synopses: - `area = mlib.polygon.getArea( vertices )` - `area = mlib.polygon.getArea( ... ) -- Arguments: +- Arguments: - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: - - `area`: Number. The area of the polygon. +- Returns: + - `area`: Number. The area of the polygon. #####mlib.polygon.getPolygonIntersection - Gives the intersection of two polygons. - Synopsis: - `intersections = mlib.polygon.getPolygonIntersections( polygon1, polygon2 )` -- Arguments: +- Arguments: - `polygon1`: Table. The vertices of the first polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `polygon2`: Table. The vertices of the second polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - Returns: - - `intersections`: Table. A table of the points of intersection. + - `intersections`: Table. A table of the points of intersection. #####mlib.polygon.getSegmentIntersection -- Returns the coordinates of where a line segmeing intersects a polygon. -- Synopses: +- Returns the coordinates of where a line segmeing intersects a polygon. +- Synopses: - `intersections = mlib.polygon.getSegmentIntersection( x1, y1, x2, y2, vertices )` - `intersections = mlib.polygon.getSegmentIntersection( x1, y1, x2, y2, ... ) -- Arguments: +- Arguments: - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: +- Returns: - `intersections`: Table. Contains the intersections. - Notes: - - With collinear line segments, they are __not__ broken up. See the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L507) for more. + - With collinear line segments, they are __not__ broken up. See the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L507) for more. #####mlib.polygon.getSignedPolygonArea -- Gets the signed area of the polygon. If the points are ordered counter-clockwise the area is positive. If the points are ordered clockwise the number is negative. +- Gets the signed area of the polygon. If the points are ordered counter-clockwise the area is positive. If the points are ordered clockwise the number is negative. - Synopses: - `area = mlib.polygon.getLineIntersection( vertices )` - `area = mlib.polygon.getLineIntersection( ... ) -- Arguments: +- Arguments: - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: - - `area`: Number. The __signed__ area of the polygon. If the points are ordered counter-clockwise the area is positive. If the points are ordered clockwise the number is negative. +- Returns: + - `area`: Number. The __signed__ area of the polygon. If the points are ordered counter-clockwise the area is positive. If the points are ordered clockwise the number is negative. #####mlib.polygon.getTriangleHeight - Gives the height of a triangle. -- Synopses: +- Synopses: - `height = mlib.polygon.getTriangleHeigh( base, x1, y1, x2, y2, x3, y3 )` - `height = mlib.polygon.getTriangleHeight( base, area )` -- Arguments: +- Arguments: - `base`: Number. The length of the base of the triangle. - `x1`, `y1`, `x2`, `y2`, `x3`, `y3`: Numbers. The x and y coordinates of the triangle. - `area`: Number. The regular area of the triangle. __Not__ the signed area. -- Returns: - - `height`: Number. The height of the triangle. +- Returns: + - `height`: Number. The height of the triangle. #####mlib.polygon.isCircleInside -- Checks if a circle is inside the polygon. +- Checks if a circle is inside the polygon. - Synopses: - `inPolygon = mlib.polygon.isCircleInside( cx, cy, radius, vertices )` - `inPolygon = mlib.polygon.isCircleInside( cx, cy, radius, ... )` -- Arguments: +- Arguments: - `cx`, `cy`: Numbers. The x and y coordinates for the center of the circle. - `radius`: Number. The radius of the circle. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: +- Returns: - `inPolygon`: Boolean. - - `true` if the circle is inside the polygon. - - `false` if the circle is not inside the polygon. + - `true` if the circle is inside the polygon. + - `false` if the circle is not inside the polygon. - Notes: - - Only returns true if the center of the circle is inside the circle. + - Only returns true if the center of the circle is inside the circle. #####mlib.polygon.isCircleCompletelyInside -- Checks if a circle is completely inside the polygon. +- Checks if a circle is completely inside the polygon. - Synopses: - `inPolygon = mlib.polygon.isCircleCompletelyInside( cx, cy, radius, vertices )` - `inPolygon = mlib.polygon.isCircleCompletelyInside( cx, cy, radius, ... )` -- Arguments: +- Arguments: - `cx`, `cy`: Numbers. The x and y coordinates for the center of the circle. - `radius`: Number. The radius of the circle. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: +- Returns: - `inPolygon`: Boolean. - - `true` if the circle is __completely__ inside the polygon. - - `false` if the circle is not inside the polygon. + - `true` if the circle is __completely__ inside the polygon. + - `false` if the circle is not inside the polygon. #####mlib.polygon.isCircleCompletelyOver - Checks if a polygon is completely inside of a circle. - Synopsis: - `completelyInside = mlib.polygon.isCircleCompletelyOver( circleX, circleY, circleRadius, vertices )` - `completelyInside = mlib.polygon.isCircleCompletelyOver( circleX, circleY, circleRadius, ... )` -- Arguments: - - `circleX`, `circleY`: Numbers. The x and y coordinates of the circle. +- Arguments: + - `circleX`, `circleY`: Numbers. The x and y coordinates of the circle. - `circleRadius`: Number. The radius of the circle. - - `vertices`: Table. A table containing all of the vertices of the polygon. + - `vertices`: Table. A table containing all of the vertices of the polygon. - `...`: Numbers. All of the points of the polygon. -- Returns: - - `completelyInside`: Boolean. +- Returns: + - `completelyInside`: Boolean. - `true` if the polygon is inside of the circle. - `false` if the polygon is not __completely__ inside of the circle. #####mlib.polygon.isPolygonInside -- Checks if a polygon is inside a polygon. -- Synopsis: +- Checks if a polygon is inside a polygon. +- Synopsis: - `inPolygon = mlib.polygon.isPolygonInside( polygon1, polygon2 )` -- Arguments: +- Arguments: - `polygon1`: Table. The vertices of the first polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `polygon2`: Table. The vertices of the second polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` -- Returns: - - `inPolygon`: Boolean. +- Returns: + - `inPolygon`: Boolean. - `true` if the `polygon2` is inside of `polygon1`. - `false` if `polygon2` is not inside of `polygon2`. -- Notes: +- Notes: - Returns true as long as any of the line segments of `polygon2` are inside of the `polygon1`. #####mlib.polygon.isPolygonCompletelyInside -- Checks if a polygon is completely inside a polygon. -- Synopsis: +- Checks if a polygon is completely inside a polygon. +- Synopsis: - `inPolygon = mlib.polygon.isPolygonCompletelyInside( polygon1, polygon2 )` -- Arguments: +- Arguments: - `polygon1`: Table. The vertices of the first polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `polygon2`: Table. The vertices of the second polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` -- Returns: - - `inPolygon`: Boolean. +- Returns: + - `inPolygon`: Boolean. - `true` if the `polygon2` is __completely__ inside of `polygon1`. - `false` if `polygon2` is not inside of `polygon2`. #####mlib.polygon.isSegmentInside -- Checks if a line segment is inside a polygon. +- Checks if a line segment is inside a polygon. - Synopses: - `inPolygon = mlib.polygon.isSegmentInside( x1, y1, x2, y2, vertices )` - `inPolygon = mlib.polygon.isSegmentInside( x1, y1, x2, y2, ... )` -- Arguments: - - `x1`, `y1`, `x2`, `y2`: Numbers. The x and y coordinates of the line segment. +- Arguments: + - `x1`, `y1`, `x2`, `y2`: Numbers. The x and y coordinates of the line segment. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: - - `inPolygon`: Boolean. - - `true` if the line segment is inside the polygon. - - `false` if the line segment is not inside the polygon. -- Note: - - Only one of the points has to be in the polygon to be considered 'inside' of the polygon. - - This is really just a faster version of [mlib.polygon.getPolygonIntersection](https://github.com/davisdude/mlib#mlibpolygongetpolygonintersection) that does not give the points of intersection. +- Returns: + - `inPolygon`: Boolean. + - `true` if the line segment is inside the polygon. + - `false` if the line segment is not inside the polygon. +- Note: + - Only one of the points has to be in the polygon to be considered 'inside' of the polygon. + - This is really just a faster version of [mlib.polygon.getPolygonIntersection](https://github.com/davisdude/mlib#mlibpolygongetpolygonintersection) that does not give the points of intersection. #####mlib.polygon.isSegmentCompletelyInside -- Checks if a line segment is completely inside a polygon. +- Checks if a line segment is completely inside a polygon. - Synopses: - `inPolygon = mlib.polygon.isSegmentCompletelyInside( x1, y1, x2, y2, vertices )` - `inPolygon = mlib.polygon.isSegmentCompletelyInside( x1, y1, x2, y2, ... )` -- Arguments: - - `x1`, `y1`, `x2`, `y2`: Numbers. The x and y coordinates of the line segment. +- Arguments: + - `x1`, `y1`, `x2`, `y2`: Numbers. The x and y coordinates of the line segment. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: - - `inPolygon`: Boolean. - - `true` if the line segment is __completely__ inside the polygon. - - `false` if the line segment is not inside the polygon. +- Returns: + - `inPolygon`: Boolean. + - `true` if the line segment is __completely__ inside the polygon. + - `false` if the line segment is not inside the polygon. ####mlib.circle - Handles aspects involving circles. @@ -692,54 +691,54 @@ end - Checks if a point is on the inside or on the edge the circle. - Synopsis: - `inCircle = mlib.circle.checkPoint( px, px, cx, cy, radius )` -- Arguments: - - `px`, `py`: Numbers. The x and y coordinates of the point being tested. +- Arguments: + - `px`, `py`: Numbers. The x and y coordinates of the point being tested. - `cx`, `cy`: Numbers. The x and y coordinates of the center of the circle. - `radius`: Number. The radius of the circle. -- Returns: +- Returns: - `inCircle`: Boolean. - - `true` if the point is inside or on the circle. - - `false` if the point is outside of the circle. + - `true` if the point is inside or on the circle. + - `false` if the point is outside of the circle. #####mlib.circle.getArea -- Gives the area of a circle. +- Gives the area of a circle. - Synopsis: - `area = mlib.circle.getArea( radius )` -- Arguments: +- Arguments: - `radius`: Number. The radius of the circle. -- Returns: - - `area`: Number. The area of the circle. +- Returns: + - `area`: Number. The area of the circle. #####mlib.circle.getCircleIntersection -- Gives the intersections of two circles. +- Gives the intersections of two circles. - Synopsis: - `intersections = mlib.circle.getCircleIntersection( c1x, c1y, radius1, c2x, c2y, radius2 ) -- Arguments: - - `c1x`, `c1y`: Numbers. The x and y coordinate of the first circle. +- Arguments: + - `c1x`, `c1y`: Numbers. The x and y coordinate of the first circle. - `radius1`: Number. The radius of the first circle. - - `c2x`, `c2y`: Numbers. The x and y coordinate of the second circle. + - `c2x`, `c2y`: Numbers. The x and y coordinate of the second circle. - `radius2`: Number. The radius of the second circle. -- Returns: - - `intersections`: Table. A table that contains the type and where the circle collides. See the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L697) for more. +- Returns: + - `intersections`: Table. A table that contains the type and where the circle collides. See the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L697) for more. #####mlib.circle.getCircumference - Returns the circumference of a circle. - Synopsis: - `circumference = mlib.circle.getCircumference( radius )` -- Arguments: +- Arguments: - `radius`: Number. The radius of the circle. - Returns: - - `circumference`: Number. The circumference of a circle. + - `circumference`: Number. The circumference of a circle. #####mlib.circle.getLineIntersection -- Returns the intersections of a circle and a line. +- Returns the intersections of a circle and a line. - Synopsis: - `intersections = mlib.circle.getLineIntersections( cx, cy, radius, x1, y1, x2, y2 )` - Arguments: - `cx`, `cy`: Numbers. The x and y coordinates for the center of the circle. - - `radius`: Number. The radius of the circle. - - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates the lie on the line. -- Returns: + - `radius`: Number. The radius of the circle. + - `x1`, `y1`, `x2`, `y2`: Numbers. Two x and y coordinates the lie on the line. +- Returns: - `intersections`: Table. A table with the type and where the intersections happened. Table is formatted: - `type`, `x1`, `y1`, `x2`, `y2` - String (`'secant'`), Number, Number, Number, Number @@ -747,22 +746,22 @@ end - String (`'tangent'`), Number, Number, Boolean (`nil`), Boolean (`nil`) - `x1` and `x2` represent where the line intersects the circle. - Boolean (`false`), Boolean (`nil`), Boolean (`nil`), Boolean (`nil`), Boolean (`nil`) - - No intersection. + - No intersection. - For more see the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L659). #####mlib.circle.getPolygonIntersection -- Returns the coordinates of where a circle intersects a polygon. -- Synopses: +- Returns the coordinates of where a circle intersects a polygon. +- Synopses: - `intersections = mlib.circle.getPolygonIntersection( cx, cy, radius, vertices )` - `intersections = mlib.circle.getPolygonIntersection( cx, cy, radius, ... ) -- Arguments: +- Arguments: - `cx`, `cy`: Number. The coordinates of the center of the circle. - - `radius`: Number. The radius of the circle. + - `radius`: Number. The radius of the circle. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: - - `intersections`: Table. Contains the intersections and type. -- Example: +- Returns: + - `intersections`: Table. Contains the intersections and type. +- Example: ```lua local tab = _.circle.getPolygonIntersection( 5, 5, 1, 4, 4, 6, 4, 6, 6, 4, 6 ) for i = 1, #tab do @@ -776,18 +775,18 @@ end - For more see [mlib.circle.getSegmentIntersection](https://github.com/davisdude/mlib#mlibcirclegetsegmentintersection) or the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L753) #####mlib.circle.getSegmentIntersection -- Returns the intersections of a circle and a line segment. +- Returns the intersections of a circle and a line segment. - Synopsis: - `intersections = mlib.circle.getSegmentIntersections( cx, cy, radius, x1, y1, x2, y2 )` - Arguments: - `cx`, `cy`: Numbers. The x and y coordinates for the center of the circle. - - `radius`: Number. The radius of the circle. - - `x1`, `y1`, `x2`, `y2`: Numbers. The two x and y coordinates of the line segment. -- Returns: + - `radius`: Number. The radius of the circle. + - `x1`, `y1`, `x2`, `y2`: Numbers. The two x and y coordinates of the line segment. +- Returns: - `intersections`: Table. A table with the type and where the intersections happened. Table is formatted: - `type`, `x1`, `y1`, `x2`, `y2` - String (`'chord'`), Number, Number, Number, Number - - The numbers are the x and y coordinates where the line segment is on both edges of the circle. + - The numbers are the x and y coordinates where the line segment is on both edges of the circle. - String (`'enclosed'`), Number, Number, Number, Number - The numbers are the x and y coordinates of the line segment if it is fully inside of the circle. - String (`'secant'`), Number, Number, Number, Number @@ -795,68 +794,68 @@ end - String (`'tangent'`), Number, Number, Boolean (`nil`), Boolean (`nil`) - `x1` and `x2` represent where the line segment intersects the circle. - Boolean (`false`), Boolean (`nil`), Boolean (`nil`), Boolean (`nil`), Boolean (`nil`) - - No intersection. + - No intersection. - For more see the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L675). #####mlib.circle.isCircleCompletelyInside - Checks if one circle is completely inside of another circle. - Synopsis: - `completelyInside = mlib.circle.isCircleCompletelyInside( c1x, c1y, c1radius, c2x, c2y, c2radius )` -- Arguments: - - `c1x`, `c1y`: Numbers. The x and y coordinates of the first circle. +- Arguments: + - `c1x`, `c1y`: Numbers. The x and y coordinates of the first circle. - `c1radius`: Number. The radius of the first circle. - - `c2x`, `c2y`: Numbers. The x and y coordinates of the second circle. + - `c2x`, `c2y`: Numbers. The x and y coordinates of the second circle. - `c2radius`: Number. The radius of the second circle. -- Returns: - - `completelyInside`: Boolean. +- Returns: + - `completelyInside`: Boolean. - `true` if circle1 is inside of circle2. - `false` if circle1 is not __completely__ inside of circle2. #####mlib.circle.isCircleCompletelyInsidePolygon -- Checks if a circle is completely inside the polygon. +- Checks if a circle is completely inside the polygon. - Synopses: - `inPolygon = mlib.polygon.isCircleCompletelyInside( cx, cy, radius, vertices )` - `inPolygon = mlib.polygon.isCircleCompletelyInside( cx, cy, radius, ... )` -- Arguments: +- Arguments: - `cx`, `cy`: Numbers. The x and y coordinates for the center of the circle. - `radius`: Number. The radius of the circle. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: +- Returns: - `inPolygon`: Boolean. - - `true` if the circle is __completely__ inside the polygon. - - `false` if the circle is not inside the polygon. + - `true` if the circle is __completely__ inside the polygon. + - `false` if the circle is not inside the polygon. #####mlib.circle.isCircleInsidePolygon -- Checks if a circle is inside a polygon. +- Checks if a circle is inside a polygon. - Synopses: - `inPolygon = mlib.circle.isCircleInsidePolygon( cx, cy, radius, vertices )` - `inPolygon = mlib.circle.isCircleInsidePolygon( cx, cy, radius, ... )` -- Arguments: +- Arguments: - `cx`, `cy`: Numbers. The x and y coordinates for the center of the circle. - `radius`: Number. The radius of the circle. - `vertices`: Table. The vertices of the polygon in the format `{ x1, y1, x2, y2, x3, y3, ... }` - `...`: Numbers. The x and y coordinates of the polygon. (Same as using `unpack( vertices )`) -- Returns: +- Returns: - `inPolygon`: Boolean. - - `true` if the circle is inside the polygon. - - `false` if the circle is not inside the polygon. + - `true` if the circle is inside the polygon. + - `false` if the circle is not inside the polygon. - Notes: - - Only returns true if the center of the circle is inside the circle. + - Only returns true if the center of the circle is inside the circle. #####mlib.circle.isPointOnCircle - Checks if a point is __exactly__ on the edge of the circle. - Synopsis: - `onCircle = mlib.circle.checkPoint( px, px, cx, cy, radius )` -- Arguments: - - `px`, `py`: Numbers. The x and y coordinates of the point being tested. +- Arguments: + - `px`, `py`: Numbers. The x and y coordinates of the point being tested. - `cx`, `cy`: Numbers. The x and y coordinates of the center of the circle. - `radius`: Number. The radius of the circle. -- Returns: +- Returns: - `onCircle`: Boolean. - - `true` if the point is on the circle. - - `false` if the point is on the inside or outside of the circle. -- Notes: + - `true` if the point is on the circle. + - `false` if the point is on the inside or outside of the circle. +- Notes: - Will return false if the point is inside __or__ outside of the circle. #####mlib.circle.isPolygonCompletelyInside @@ -864,13 +863,13 @@ end - Synopsis: - `completelyInside = mlib.circle.isPolygonCompletelyInside( circleX, circleY, circleRadius, vertices )` - `completelyInside = mlib.circle.isPolygonCompletelyInside( circleX, circleY, circleRadius, ... )` -- Arguments: - - `circleX`, `circleY`: Numbers. The x and y coordinates of the circle. +- Arguments: + - `circleX`, `circleY`: Numbers. The x and y coordinates of the circle. - `circleRadius`: Number. The radius of the circle. - - `vertices`: Table. A table containing all of the vertices of the polygon. + - `vertices`: Table. A table containing all of the vertices of the polygon. - `...`: Numbers. All of the points of the polygon. -- Returns: - - `completelyInside`: Boolean. +- Returns: + - `completelyInside`: Boolean. - `true` if the polygon is inside of the circle. - `false` if the polygon is not __completely__ inside of the circle. @@ -878,13 +877,13 @@ end - Checks if a polygon is completely inside of a circle. - Synopsis: - `completelyInside = mlib.circle.isSegmentCompletelyInside( circleX, circleY, circleRadius, x1, y1, x2, y2 )` -- Arguments: - - `circleX`, `circleY`: Numbers. The x and y coordinates of the circle. +- Arguments: + - `circleX`, `circleY`: Numbers. The x and y coordinates of the circle. - `circleRadius`: Number. The radius of the circle. - `x1`, `y1`: Numbers. The x and y coordinates of one end of the segment. - `x2`, `y2`: Numbers. The x and y coordinates of the other end of the segment. -- Returns: - - `completelyInside`: Boolean. +- Returns: + - `completelyInside`: Boolean. - `true` if the segment is inside of the circle. - `false` if the segment is not __completely__ inside of the circle. @@ -896,12 +895,12 @@ end - Synopses: - `modes, occurrences, median, mean = mlib.statistics.getCentralTendency( data )` - `modes, occurrences, median, mean = mlib.statistics.getCentralTendency( ... )` -- Arguments: +- Arguments: - `data`: Table. A table containing the values of data. - `...`: Numbers. All of the numbers in the data set. - Returns: - `modes, occurrences`: Table, Number. The modes of the data and the number of times it occurs. See [mlib.statistics.getMode](https://github.com/davisdude/mlib#mlibstatisticsgetmode). - - `median`: Number. The median of the data set. + - `median`: Number. The median of the data set. - `mean`: Number. The mean of the data set. #####mlib.statistics.getDispersion @@ -909,7 +908,7 @@ end - Synopses: - `variationRatio, range, standardDeviation = mlib.statistics.getDispersion( data )` - `variationRatio, range, standardDeviation = mlib.statistics.getDispersion( ... )` -- Arguments: +- Arguments: - `data`: Table. A table containing the values of data. - `...`: Numbers. All of the numbers in the data set. - Returns: @@ -922,63 +921,63 @@ end - Synopses: - `mean = mlib.statistics.getMean( data )` - `mean = mlib.statistics.getMean( ... )` -- Arguments: +- Arguments: - `data`: Table. A table containing the values of data. - `...`: Numbers. All of the numbers in the data set. - Returns: - - `mean`: Number. The arithmetic mean of the data set. + - `mean`: Number. The arithmetic mean of the data set. #####mlib.statistics.getMedian -- Gets the median of the data set. +- Gets the median of the data set. - Synopses: - `median = mlib.statistics.getMedian( data )` - `median = mlib.statistics.getMedian( ... )` -- Arguments: +- Arguments: - `data`: Table. A table containing the values of data. - `...`: Numbers. All of the numbers in the data set. -- Returns: - - `median`: Number. The median of the data. +- Returns: + - `median`: Number. The median of the data. #####mlib.statistics.getMode -- Gets the mode of the data set. +- Gets the mode of the data set. - Synopses: - `mode, occurrences = mlib.statistics.getMode( data )` - `mode, occurrences = mlib.statistics.getMode( ... )` -- Arguments: +- Arguments: - `data`: Table. A table containing the values of data. - `...`: Numbers. All of the numbers in the data set. -- Returns: +- Returns: - `mode`: Table. The mode(s) of the data. - `occurrences`: Number. The number of time the mode(s) occur. #####mlib.statistics.getRange -- Gets the range of the data set. +- Gets the range of the data set. - Synopses: - `range = mlib.statistics.getRange( data )` - `range = mlib.statistics.getRange( ... )` -- Arguments: +- Arguments: - `data`: Table. A table containing the values of data. - `...`: Numbers. All of the numbers in the data set. -- Returns: - - `range`: Number. The range of the data. +- Returns: + - `range`: Number. The range of the data. #####mlib.statistics.getStandardDeviation - Gets the standard deviation of the data. - Synopses: - `standardDeviation = mlib.statistics.getStandardDeviation( data )` - `standardDeviation = mlib.statistics.getStandardDeviation( ... )` -- Arguments: +- Arguments: - `data`: Table. A table containing the values of data. - `...`: Numbers. All of the numbers in the data set. - Returns: - - `standardDeviation`: Number. The standard deviation of the data set. + - `standardDeviation`: Number. The standard deviation of the data set. #####mlib.statistics.getVariance - Gets the variation of the data. - Synopses: - `variance = mlib.statistics.getVariance( data )` - `variance = mlib.statistics.getVariance( ... )` -- Arguments: +- Arguments: - `data`: Table. A table containing the values of data. - `...`: Numbers. All of the numbers in the data set. - Returns: @@ -989,63 +988,63 @@ end - Synopses: - `variationRatio = mlib.statistics.getVariationRatio( data )` - `variationRatio = mlib.statistics.getVariationRatio( ... )` -- Arguments: +- Arguments: - `data`: Table. A table containing the values of data. - `...`: Numbers. All of the numbers in the data set. - Returns: - - `variationRatio`: Number. The variation ratio of the data set. + - `variationRatio`: Number. The variation ratio of the data set. ####mlib.math -- Miscellaneous functions that have no home. +- Miscellaneous functions that have no home. #####mlib.math.getAngle -- Gets the angle between three points. -- Synopsis: +- Gets the angle between three points. +- Synopsis: - `angle = mlib.math.getAngle( x1, y1, x2, y2, x3, y3 )` -- Arguments: - - `x1`, `y1`: Numbers. The x and y coordinates of the first point. - - `x2`, `y2`: Numbers. The x and y coordinates of the vertex of the two points. - - `x3`, `y3`: Numbers. The x and y coordinates of the second point. +- Arguments: + - `x1`, `y1`: Numbers. The x and y coordinates of the first point. + - `x2`, `y2`: Numbers. The x and y coordinates of the vertex of the two points. + - `x3`, `y3`: Numbers. The x and y coordinates of the second point. #####mlib.math.getPercentage -- Gets the percentage of a number. -- Synopsis: +- Gets the percentage of a number. +- Synopsis: - `percentage = mlib.math.getPercentage( percent, number )` -- Arguments: +- Arguments: - `percent`: Number. The decimal value of the percent (i.e. 100% is 1, 50% is .5). - - `number`: Number. The number to get the percentage of. -- Returns: + - `number`: Number. The number to get the percentage of. +- Returns: - `percentage`: Number. The `percent`age or `number`. #####mlib.math.getPercentOfChange -- Gets the percent of change from one to another. -- Synopsis: +- Gets the percent of change from one to another. +- Synopsis: - `change = mlib.math.getPercentOfChange( old, new )` -- Arguments: - - `old`: Number. The original number. - - `new`: Number. The new number. -- Returns: - - `change`: Number. The percent of change from `old` to `new`. +- Arguments: + - `old`: Number. The original number. + - `new`: Number. The new number. +- Returns: + - `change`: Number. The percent of change from `old` to `new`. #####mlib.math.getQuadraticRoots - Gets the quadratic roots of the the equation. - Synopsis: - `root1, root2 = mlib.math.getQuadraticRoots( a, b, c )` -- Arguments: +- Arguments: - `a`, `b`, `c`: Numbers. The a, b, and c values of the equation `a * x ^ 2 + b * x ^ 2 + c`. -- Returns: +- Returns: - `root1`, `root2`: Numbers. The roots of the equation (where `a * x ^ 2 + b * x ^ 2 + c = 0`). #####mlib.math.getRoot - Gets the `n`th root of a number. -- Synopsis: +- Synopsis: - `x = mlib.math.getRoot( number, root )` -- Arguments: +- Arguments: - `number`: Number. The number to get the root of. - - `root`: Number. The root. -- Returns: + - `root`: Number. The root. +- Returns: - `x`: The `root`th root of `number`. -- Example: +- Example: ```lua local a = mlib.math.getRoot( 4, 2 ) -- Same as saying 'math.pow( 4, .5 )' or 'math.sqrt( 4 )' in this case. local b = mlib.math.getRoot( 27, 3 ) @@ -1055,40 +1054,40 @@ print( a, b ) --> 2, 3 - For more, see the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L859). #####mlib.math.getSummation -- Gets the summation of numbers. -- Synopsis: +- Gets the summation of numbers. +- Synopsis: - `summation = mlib.math.getSummation( start, stop, func )` -- Arguments: +- Arguments: - `start`: Number. The number at which to start the summation. - `stop`: Number. The number at which to stop the summation. - `func`: Function. The method to add the numbers. - - Arguments: + - Arguments: - `i`: Number. Index. - - `previous`: Table. The previous values used. -- Returns: + - `previous`: Table. The previous values used. +- Returns: - `Summation`: Number. The summation of the numbers. - - For more, see the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L896). + - For more, see the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L896). #####mlib.math.isPrime -- Checks if a number is prime. -- Synopsis: +- Checks if a number is prime. +- Synopsis: - `isPrime = mlib.math.isPrime( x )` -- Arguments: - - `x`: Number. The number to check if it's prime. -- Returns: - - `isPrime`: Boolean. - - `true` if the number is prime. - - `false` if the number is not prime. +- Arguments: + - `x`: Number. The number to check if it's prime. +- Returns: + - `isPrime`: Boolean. + - `true` if the number is prime. + - `false` if the number is not prime. #####mlib.math.round -- Rounds a number to the given decimal place. -- Synopsis: +- Rounds a number to the given decimal place. +- Synopsis: - `rounded = mlib.math.round( number, [place] ) -- Arguments: - - `number`: Number. The number to round. - - `place (1)`: Number. The decimal place to round to. Defaults to 1. -- Returns: - - The rounded number. +- Arguments: + - `number`: Number. The number to round. + - `place (1)`: Number. The decimal place to round to. Defaults to 1. +- Returns: + - The rounded number. - For more, see the [specs](https://github.com/davisdude/mlib/blob/master/spec.lua#L880). ##License