You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This pull request introduces new implementations for 2D, 3D, and 4D vector classes in Lua using the ffi library. These classes provide various mathematical operations, utility methods, and compatibility with LuaSTG Evo. Below is a summary of the most important changes:
2D Vector (Vector2)
Added a Vector2 class with fields x and y, operator overloads for arithmetic operations (+, -, *, /), unary negation, equality, and string representation.
Implemented utility methods such as length, angle, dot, normalize, and normalized for vector operations.
Introduced LuaSTG Evo compatibility methods and exposed Vector2 creation via lstg.Vector2.
3D Vector (Vector3)
Added a Vector3 class with fields x, y, and z, along with operator overloads for arithmetic operations, unary negation, equality, and string representation.
Implemented utility methods such as length, dot, normalize, and normalized for 3D vector operations.
4D Vector (Vector4)
Added a Vector4 class with fields x, y, z, and w, along with operator overloads for arithmetic operations, unary negation, equality, and string representation.
Implemented utility methods such as length, dot, normalize, and normalized for 4D vector operations.
These changes enhance the mathematical foundation of the project by introducing efficient, reusable vector classes with extensive functionality.
Introduced a Triangle class supporting operations like area, centroid, circumradius, inradius, and geometric transformations (rotation, scaling). (game/packages/thlib-scripts-v2/foundation/shape/Triangle.lua)
Added methods for point containment checks and string representation for debugging. (game/packages/thlib-scripts-v2/foundation/shape/Triangle.lua)
These additions establish a solid mathematical foundation for further development in game physics, geometry, and spatial computations.
Introduced a Line class for 2D geometric operations, including creation from points, length calculation, midpoint, angle, translation, rotation, intersection detection, and point projection. (game/packages/thlib-scripts-v2/foundation/shape/Line.lua)
Revisions to existing files within the foundation/math and foundation/shape directories, such as:
Vector2.lua
Vector3.lua
Vector4.lua
Segment.lua
Triangle.lua
New Files Added:
New shape-related modules have been introduced:
Circle.lua
Line.lua
Ray.lua
Structural Renaming:
Structs like Vector2, Vector3, and Vector4 have been renamed for consistency, e.g., to foundation_math_Vector2, foundation_math_Vector3, and foundation_math_Vector4.
Enhanced Features & Methods:
Zero Vector Methods: Added zero() methods for initializing zero vectors in Vector2, Vector3, and Vector4.
Clone Method: Introduced clone() methods for creating copies of vectors and shapes.
Intersection Checks: New methods for intersection handling among shapes (e.g., lines, circles, triangles).
Scaling and Movement: Added scaling and moving functionality for shapes like segments, triangles, and circles.
Code Refactoring:
Reorganized and standardized method names and variable references for clarity and consistency.
Updated all references to use new struct names and standardized methods.
New Functionalities for Shapes:
Added robust intersection checks for shapes like Segment, Triangle, Circle, and Ray.
Enhanced mathematical operations for geometry handling (e.g., centroids, projections, normals).
Added methods to check for intersections between various shapes (Circle, Line, Ray, Segment, Triangle) to identify if they intersect with other geometric shapes.
These methods include both detailed intersection logic (returning points) and simplified checks (returning boolean).
Enhanced Shape Capabilities:
Implemented utility methods for operations like calculating the closest point, projecting points, distance calculations, and containment checks for shapes.
Key Updates:
Circle: Methods added for checking intersections and calculating the closest point or distance to other shapes.
Line: Added methods for simplified intersection logic and operations like projecting points and checking containment.
Ray: Introduced similar intersection and utility methods as Line, alongside distance and projection calculations.
Segment: Enhanced intersection checks and utility functions for containment and distance.
Triangle: Expanded functionality with methods for intersections, closest points, projections, and distance calculations.
New intersection methods were added to the Circle, Line, Ray, Segment, and Triangle classes to handle interactions with Rectangle objects.
Both detailed intersection logic (returning intersection points) and simplified checks (returning boolean values) were implemented.
Vector Comparison Improvements:
Updated the equality (__eq) methods in Vector2, Vector3, and Vector4 classes to use a tolerance threshold (1e-10) for floating-point comparison, improving numerical stability.
Enhanced Geometric Classes:
Line: Added methods to create lines using radians (createFromPointAndRad) and improved initialization by normalizing direction vectors.
Ray: Added similar methods as Line for initialization using radians.
Segment: Renamed angle-based creation methods (createFromPointAndAngle to createFromAngle) and added support for intersection checks with rectangles.
Triangle: Added methods for rectangle interactions and refactored existing intersection logic.
Because it's a pain in the ass to re-record and modify gifs, please run your own tests to get the latest performance.
Current fix: If the detection point is inside the graph, the projection point is now calculated to be confined to the graph boundary instead of coinciding with the closest point.
Introduced a comprehensive implementation of Bézier curves, including methods for creating, manipulating, and performing geometric computations (e.g., splitting, rotations, and intersections).
Ellipse.lua:
Implemented functionality for handling ellipses, supporting operations like scaling, rotations, and intersection checks.
Modules in ShapeIntersector/:
Added specialized intersection logic for various geometric shapes (e.g., Bézier curves, circles, ellipses).
Enhancements and Refactorings:
Improved modularity by splitting logic into separate files (e.g., ShapeIntersector components).
Added clone methods across multiple shape classes for deep copying instances.
Enhanced __index and __newindex metamethods in shape classes to better handle data encapsulation and property access.
Fixes and Optimizations:
Rectified issues in geometric operations, ensuring accurate computations.
Refactored redundant calculations into reusable methods for maintainability.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces new implementations for 2D, 3D, and 4D vector classes in Lua using the
ffi
library. These classes provide various mathematical operations, utility methods, and compatibility with LuaSTG Evo. Below is a summary of the most important changes:2D Vector (
Vector2
)Vector2
class with fieldsx
andy
, operator overloads for arithmetic operations (+
,-
,*
,/
), unary negation, equality, and string representation.length
,angle
,dot
,normalize
, andnormalized
for vector operations.Vector2
creation vialstg.Vector2
.3D Vector (
Vector3
)Vector3
class with fieldsx
,y
, andz
, along with operator overloads for arithmetic operations, unary negation, equality, and string representation.length
,dot
,normalize
, andnormalized
for 3D vector operations.4D Vector (
Vector4
)Vector4
class with fieldsx
,y
,z
, andw
, along with operator overloads for arithmetic operations, unary negation, equality, and string representation.length
,dot
,normalize
, andnormalized
for 4D vector operations.These changes enhance the mathematical foundation of the project by introducing efficient, reusable vector classes with extensive functionality.