{ "name": "Path Math", "script": "PathMath.js", "version": "1.5.3", "previousversions": ["1.0", "1.1", "1.2", "1.3", "1.4.1", "1.5.1", "1.5.2"], "description": "# Path Math\r\rA library that provides some mathematical operations involving Paths.\rIt has no stand-alone functionality of its own.\r\r## API Documentation:\r\rThis script's documentation uses the following typedefs and classes:\r\r```\r/**\r * An open shape defined by a path.\r * @class Path\r */\r\r/**\r * A closed shape defined by a path.\r * @class Polygon\r */\r\r/**\r * A polygon primitive consisting of 3 vertices. Great for tessellation!\r * @class Triangle\r * @extends Polygon\r */\r\r/**\r * A circle defined by a center point and radius.\r * @class Circle\r */\r\r/**\r * A rectangle defining a path's bounding box.\r * @typedef {Object} BoundingBox\r * @property {number} left\r * @property {number} top\r * @property {number} width\r * @property {number} height\r */\r\r/**\r * JSON used to create a Path object with createObj().\r * @typedef {Object} PathData\r * This is documented by the Roll20 API wiki.\r */\r\r/**\r * Information about a path's 2D transform.\r * @typedef {Object} PathTransformInfo\r * @property {number} angle\r * The path's rotation angle in radians.\r * @property {number} cx\r * The x coordinate of the center of the path's bounding box.\r * @property {number} cy\r * The y coordinate of the center of the path's bounding box.\r * @property {number} height\r * The unscaled height of the path's bounding box.\r * @property {number} scaleX\r * The path's X-scale.\r * @property {number} scaleY\r * The path's Y-scale.\r * @property {number} width\r * The unscaled width of the path's bounding box.\r */\r\r/**\r * A line segment defined by two homogeneous 2D points.\r * @typedef {Vector[]} Segment\r */\r\r/**\r * A vector used to define a homogeneous point or a direction.\r * @typedef {number[]} Vector\r */\r```\r\rThe following functions are exposed by the ```PathMath``` object:\r\r```\r/**\r * Returns the partial path data for creating a circular path.\r * @param {number} radius\r * @param {int} [sides]\r * If specified, then a polygonal path with the specified number of\r * sides approximating the circle will be created instead of a true\r * circle.\r * @return {PathData}\r */\rfunction createCircleData(radius, sides)\r```\r\r```\r/**\r * Gets a point along some Bezier curve of arbitrary degree.\r * @param {vec3[]} points\r * The points of the Bezier curve. The points between the first and\r * last point are the control points.\r * @param {number} scalar\r * The parametric value for the point we want along the curve.\r * This value is expected to be in the range [0, 1].\r * @return {vec3}\r */\rfunction getBezierPoint(points, scalar)\r```\r\r```\r/**\r * Calculates the bounding box for a list of paths.\r * @param {(Path | Path[])} paths\r * @return {BoundingBox}\r */\rfunction getBoundingBox(paths)\r```\r\r```\r/**\r * Returns the center of the bounding box containing a path or list\r * of paths. The center is returned as a homogenous 2D point\r * (It has a third component which is always 1 which is helpful for\r * affine transformations).\r * @param {(Path|Path[])} paths\r * @return {Vector}\r */\rfunction getCenter(paths)\r```\r\r```\r/**\r * Gets the 2D transform information about a path.\r * @param {Path} path\r * @return {PathTransformInfo}\r */\rfunction getTransformInfo(path)\r```\r\r```\r/**\r * Produces a merged path string from a list of path objects.\r * @param {Path[]} paths\r * @return {String}\r */\rfunction mergePathStr(paths)\r```\r\r```\r/**\r * Reproduces the data for a polygonal path such that the scales are 1 and\r * its rotate is 0.\r * This can also normalize freehand paths, but they will be converted to\r * polygonal paths. The quatric Bezier curves used in freehand paths are\r * so short though, that it doesn't make much difference though.\r * @param {Path}\r * @return {PathData}\r */\rfunction normalizePath(path)\r```\r\r```\r/**\r * Computes the intersection between the projected lines of two homogeneous\r * 2D line segments.\r * @param {Segment} seg1\r * @param {Segment} seg2\r * @return {Array}\r * The point of intersection in homogenous 2D coordinates and its\r * parametric coefficients along seg1 and seg2,\r * or undefined if the segments are parallel.\r */\r```\r\r```\r/**\r * Computes the intersection between two homogenous 2D line segments,\r * if it exists.\r * @param {Segment} seg1\r * @param {Segment} seg2\r * @return {Array}\r * The point of intersection in homogenous 2D coordinates and its\r * parametric coefficients along seg1 and seg2,\r * or undefined if the segments don't intersect.\r */\rfunction segmentIntersection(seg1, seg2)\r```\r\r```\r/**\r * Produces the data for creating a path from a list of segments forming a\r * continuous path.\r * @param {Segment[]}\r * @return {PathData}\r */\rfunction segmentsToPath(segments)\r```\r\r```\r/**\r * Converts a path into a list of line segments.\r * This supports freehand paths, but not elliptical paths.\r * @param {(Path|Path[])} path\r * @return {Segment[]}\r */\rfunction toSegments(path)\r```\r\r```\r/**\r * Transforms a tuple for a point in a path's _path property into a point in\r * homogeneous 2D map coordinates.\r * @param {PathTuple} tuple\r * @param {PathTransformInfo} transformInfo\r * @return {Vector}\r */\rfunction tupleToPoint(tuple, transformInfo)\r```\r\r### Help\r\rIf you experience any issues while using this script,\rneed help using it, or if you have a neat suggestion for a new feature, please\rpost to the script's thread in the API forums or shoot me a PM:\rhttps://app.roll20.net/users/46544/stephen-l\r\r### Show Support\r\rIf you would like to show your appreciation and support for the work I do in writing,\rupdating, and maintaining my API scripts, consider buying one of my art packs from the Roll20 marketplace (https://marketplace.roll20.net/browse/search/?keywords=&sortby=newest&type=all&genre=all&author=Stephen%20Lindberg)\ror, simply leave a thank you note in the script's thread on the Roll20 forums.\rEither is greatly appreciated! Happy gaming!\r", "authors": "Stephen Lindberg", "roll20userid": 46544, "useroptions": [], "dependencies": ["MatrixMath", "Vector Math"], "modifies": { "paths": "read, write" }, "conflicts": [] }