·
14 commits
to master
since this release
Add sizes, numeric ranges, bounding boxes, and utility functions.
Change Log
- Add the
Size,Range, andBoundingBoxclasses - Add the
round(),almost_equal(),clamp(),lerp(),inverse_lerp(),wrap(), andrandom_in_range()utility functions - Perform refactoring:
- Add
schema()andfrom_options()toVector2DandMatrix3x3 - Validate dimensions passed to the
Matrix3x3constructor
- Add
Features
- Utility functions:
round(value, [precision])— round a number to the specified number of decimal placesalmost_equal(left_operand, right_operand, [epsilon])— compare two numbers approximatelyclamp(value, minimum, maximum)— clamp a number to a rangelerp(minimum, maximum, progress)— interpolate between two numbersinverse_lerp(minimum, maximum, value)— compute interpolation progress for a valuewrap(value, minimum, maximum)— wrap a number into a rangerandom_in_range(minimum, maximum)— generate a random number in a range
- Classes:
Vector2D:- Serialization:
schema()— return the JSON Schema for the classfrom_options(options)— construct a vector from a table__data()— return a table with the instance fields__tostring()— return a string representation of the instance
- Constants:
ZERO— (0, 0)BASIS_X— (1, 0)BASIS_Y— (0, 1)
- Operations:
equals(other)— check exact equalityalmost_equals(other, [epsilon])— check approximate equality within a given epsilonlength_squared()— compute the squared lengthlength()— compute the lengthnormalized()— return the normalized vectoradd(other)— add another vectorsub(other)— subtract another vectormul(value)— multiply by a scalar, matrix, or perform component-wise multiplication with another vectorneg()— unary minusdot(other)— compute the dot productdiv(value)— divide by a scalar or perform component-wise division by another vector
- Operators (via metamethods):
==— check exact equality (__eq())#vector— compute the length (__len()); supported only since Lua 5.2+— add two vectors (__add())-— subtract two vectors (__sub())*— multiply by a scalar (vector * scalarorscalar * vector), matrix (vector * matrixormatrix * vector), or perform component-wise multiplication (vector * vector) (__mul())-vector— unary minus (__unm())/— divide by a scalar (vector / scalar) or perform component-wise division (vector / vector) (__div())
- Serialization:
Matrix3x3:- Serialization:
schema()— return the JSON Schema for the classfrom_options(options)— construct a matrix from a table__data()— return a table with the instance fields__tostring()— return a string representation of the instance
- Constants:
ZERO— zero matrixIDENTITY— identity matrix
- Factories:
translate(delta_x, delta_y)— translationrotate(angle)— rotationscale(scale_x, scale_y)— scalingshear(shear_x, shear_y)— shear
- Operations:
equals(other)— check exact equalityalmost_equals(other, [epsilon])— check approximate equality within a given epsilonadd(other)— add another matrixsub(other)— subtract another matrixmul(value)— multiply by a scalar, vector, or another matrixdiv(value)— divide by a scalar
- Operators (via metamethods):
==— check exact equality (__eq())+— add two matrices (__add())-— subtract two matrices (__sub())*— multiply by a scalar (matrix * scalarorscalar * matrix), vector (matrix * vectororvector * matrix), or another matrix (matrix * matrix) (__mul())/— divide by a scalar (matrix / scalar) (__div())
- Serialization:
- Models:
Size— aVector2Dsubclass withwidthandheightaliases forxandy:- Serialization:
schema()— return the JSON Schema for the classfrom_options(options)— construct a size from a table__data()— return a table with the instance fields__tostring()— return a string representation of the instance
- Operations:
equals(other)— check exact equalityalmost_equals(other, [epsilon])— check approximate equality within a given epsilonlength_squared()— compute the squared lengthlength()— compute the lengthnormalized()— return the normalized sizeadd(other)— add another vectorsub(other)— subtract another vectormul(value)— multiply by a scalar, matrix, or perform component-wise multiplication with another vectorneg()— unary minusdot(other)— compute the dot productdiv(value)— divide by a scalar or perform component-wise division by another vector
- Operators (via metamethods):
==— check exact equality (__eq())#size— compute the length (__len()); supported only since Lua 5.2+— add two vectors (__add())-— subtract two vectors (__sub())*— multiply by a scalar, matrix, or another vector (__mul())-size— unary minus (__unm())/— divide by a scalar or another vector (__div())
- Serialization:
Range— a closed numeric range:- Serialization:
schema()— return the JSON Schema for the classfrom_options(options)— construct a range from a table__data()— return a table with the instance fields__tostring()— return a string representation of the instance
- Factories:
union(...)— return the smallest range containing all input rangesintersection(...)— return the common range ornilif it is empty
- Operations:
equals(other)— check exact equalityalmost_equals(other, [epsilon])— check approximate equality within a given epsilonis_valid()— check that the minimum is not greater than the maximumis_degenerate()— check whether the range has zero lengthis_almost_degenerate([epsilon])— check whether the range has almost zero lengthlength()— compute the range lengthcenter()— compute the centeroverlaps(other)— check whether the intersection has positive lengthcontains(value)— check whether the range contains a number or another rangeclamp(value)— clamp a number to the rangelerp(progress)— interpolate between the endpointsinverse_lerp(value)— compute interpolation progress for a valuewrap(value)— wrap a number into the rangerandom()— generate a random number in the rangetranslate(delta)— translate the rangeexpand(delta)— expand the range symmetricallyscale(factor)— scale the range around its center
- Operators (via metamethods):
==— check exact equality (__eq())#range— compute the range length (__len()); supported only since Lua 5.2
- Serialization:
BoundingBox— an axis-aligned bounding box with closed boundaries:- Serialization:
schema()— return the JSON Schema for the classfrom_options(options)— construct a bounding box from a table__data()— return a table with the instance fields__tostring()— return a string representation of the instance
- Factories:
from_position_and_size(position, size)— construct a box from its position and sizefrom_ranges(x_range, y_range)— construct a box from its horizontal and vertical rangesunion(...)— return the smallest box containing all input boxesintersection(...)— return the common box ornilif it is empty
- Operations:
equals(other)— check exact equalityalmost_equals(other, [epsilon])— check approximate equality within a given epsilonis_valid()— check that the minimum is not greater than the maximum on either axisis_degenerate([axis])— check whether either or a selected axis has zero lengthis_almost_degenerate([epsilon], [axis])— check whether either or a selected axis has almost zero lengthis_point()— check whether both axes have zero lengthis_almost_point([epsilon])— check whether both axes have almost zero lengthposition()— return the top-left positionsize()— return the box sizex_range()— return the horizontal rangey_range()— return the vertical rangecenter()— compute the centertop_left()— return the top-left cornertop_right()— return the top-right cornerbottom_left()— return the bottom-left cornerbottom_right()— return the bottom-right corneroverlaps(other)— check whether the intersection has positive areacontains(value)— check whether the box contains a vector or another boxclamp(value)— clamp a vector to the boxlerp(progress)— interpolate between the corners per axisinverse_lerp(value)— compute interpolation progress per axiswrap(value)— wrap a vector into the box per axisrandom()— generate a random point in the boxtranslate(delta_x, delta_y)— translate the boxexpand(delta_x, delta_y)— expand the box symmetricallyscale(scale_x, scale_y)— scale the box around its center
- Operators (via metamethods):
==— check exact equality (__eq())
- Serialization: