Bitfighter
021
The Bitfighter Lua Documentation - Robots, Levelgens, and Plugins
|
Library of various geometric transforms.
Member Functions | |
centroid(geom) | |
Find the centroid (center) of geom | |
coordsToPoints(coordList) | |
Convert a table of coordinates into a table of points. [details] | |
flip(geom, horizontal) | |
Flip geom along the x- or y-axis in regards to the origin. [details] | |
rotate(geom, angle) | |
Rotate geom about its centroid. [details] | |
scale(geom, sx, sy) | |
Scale geom by sx, sy, in reference to the x- and y-axes. [details] | |
transform(geom, tx, ty, sx, sy, angle) | |
Transform geom by scaling, rotating, and translating. [details] | |
translate(geom, tx, ty) | |
Translate (offset) geom by tx, ty. [details] | |
Static Member Functions | |
clipPolygons(op, subject, clip, mergeAfterTriangulating=false) | |
Perform a clipping operation on sets of polygons. [details] | |
clipPolygonsAsTree(op, subject, clip) | |
Perform a clipping operation on sets of polygons, keeping holes. [details] | |
offsetPolygons(offset, polygons) | |
Offset polygons by the given offset. [details] | |
polyganize(triangles) | |
Merge triangles into convex polygons. [details] | |
segmentsIntersect(a1, a2, b1, b2) | |
Finds intersection of the linesegments (a1, a2) and (b1, b2) [details] | |
triangulate(polygons) | |
Break up polygons into triangles. [details] | |
Library of various geometric transforms.
The Geom class provides a collection of useful geometric operations. Since point objects are immutable, all the Geom functions return either a new point or a new table of new points. All follow the same usage pattern.
In all cases below, geom refers to either a single point or a table of points.
Find the centroid (center) of geom
geom | The geometry to find the centroid of |
geom
|
static |
Perform a clipping operation on sets of polygons.
This function uses Bitfighter's polygon manipulation utilities to perform boolean operations on sets of polygons. While these utilities are generally robust, there are a few caveats and some inputs may cause failure.
In particular, Bitfighter's engine does not support "holes" in polygons. Because of this, if the result of the requested operation would have holes, the entire solution is triangulated to remove them. The triangles may then be optionally merged into convex polygons. This way, the client code (or level designer) can select and manually join the result into the desired shape, rather than making Bitfighter guess (probably incorrectly) how it should look. When no holes are created in the output, this function produces the least number of polygons which represent it.
op | ClipType The polygon boolean operation to execute. |
subject | A table of polygons or a single polygon to use as the subject. |
clip | A table of polygons or a single polygon to use as the clip. |
mergeAfterTriangulating | Merge triangles into convex polygons when forced to triangulate the result. |
nil
on failure.
|
static |
Perform a clipping operation on sets of polygons, keeping holes.
This function uses Bitfighter's polygon manipulation utilities to perform boolean operations on sets of polygons, keeping holes, and returning the result as a tree of polygons and holes. This is useful when performing repeated operations on the results of a clipping operation, or when you need to know which polygon is contained in which hole or vice versa.
op | ClipType The polygon boolean operation to execute. |
subject | A table of polygons or a single polygon to use as the subject. |
clip | A table of polygons or a single polygon to use as the clip. |
Arg types: coordList: table | returns nothing |
Convert a table of coordinates into a table of points.
Parse a list of coordinates and generate points for every pair. An even number of coordinates should be provided. If an odd number is supplied, 0 will be used for the missing coordinate.
Example: pts = Geom.coordsToPoints({ 0,0, 100,0, 100,100, 0,100 })
coordList | - The list of coordinates to be used for creating points |
Arg types: geom: Geom, horizontal: bool | returns geom |
Flip geom along the x- or y-axis in regards to the origin.
geom | - The geometry to modify. Geom can either be a point or a table of points. |
horizontal | - Pass true to flip along the x-axis, false to flip along the y-axis. |
|
static |
Offset polygons by the given offset.
This offsets polygons using a 'miter' join type.
If the input offset generates polygons that overlap, the output can have fewer total polygons than the input.
If the input polygon has 'isthmus' pieces, then the output cat have more polygons than the input.
offset | Amount to offset the polygons. |
polygons | A table of polygons. |
nil
on failure.
|
static |
Merge triangles into convex polygons.
Merges triangles into convex polygons using the Recast library. This function is meant for use as a best-effort to clean up triangles output by geometric operations.
triangles | Either a single triangle or a table of triangles. |
Arg types: geom: Geom, angle: int | returns nothing |
Rotate geom about its centroid.
geom | - The geometry to modify. Geom can either be a point or a table of points. |
angle | - The angle (clockwise, in degrees) to rotate geom. |
Arg types: geom: Geom, sx: int, sy: int | returns nothing |
Scale geom by sx, sy, in reference to the x- and y-axes.
If sy is omitted, geom will be scaled evenly horizontally and vertically without distortion.
geom | - The geometry to modify. Geom can either be a point or a table of points. |
sx | - The amount to scale each point in geom horizontally. |
sy | - (Optional) The amount to scale each point in geom vertically. Defaults to sx. |
Finds intersection of the linesegments (a1, a2) and (b1, b2)
Determines if and "when" the line segments a and b intersect. The boolean return value is true
if the segments intersect. The number return value is a "time" t
along the line a corresponding to where they intersect. If the segments intersect, the first return value will true
and the second return value will be in the range [0, 1]. If they do not intersect, the first return value will be false, and the second value should be discarded.
To find the actual point of intersection, just use
Arg types: geom: Geom, tx: int, ty: int, sx: int, sy: int, angle: int | returns nothing |
Transform geom by scaling, rotating, and translating.
Apply a full transformation to the points in geom, doing a combination of the above in a single operation. Scales, rotates, then translates. Performing these operations together is more effient than applying them individually.
Note that sy can be omitted for uniform scaling horizontally and vertically.
geom | - The geometry to modify. Geom can either be a point or a table of points. |
tx | - The amount to add to the x-coord of each point in geom. |
ty | - The amount to add to the y-coord of each point in geom. |
sx | - The amount to scale each point in geom horizontally. |
sy | - (Optional) The amount to scale each point in geom vertically. Defaults to sx. |
angle | - The angle (clockwise, in degrees) to rotate geom. |
Arg types: geom: Geom, tx: int, ty: int | returns nothing |
Translate (offset) geom by tx, ty.
geom | - The geometry to modify. Geom can either be a point or a table of points. |
tx | - The amount to add to the x-coord of each point in geom. |
ty | - The amount to add to the y-coord of each point in geom. |
|
static |
Break up polygons into triangles.
Performs a Constrained Delauney Triangulation on the input. This function is meant to be used for breaking complex polygons into pieces which can then be manipulated either in the editor or through more processing.
polygons | Either a single polygon or a table of polygons. |