Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
5d8e690
添加 ffi 版本的 Vector2/Vector3/Vector4
BAKAOLC Apr 28, 2025
5c26343
重命名类型标识名
BAKAOLC Apr 28, 2025
d123dc3
添加部分常用类型结构
BAKAOLC Apr 28, 2025
9a40e95
为布尔数组、双精度数组和整型数组添加偏移量支持,更新创建函数和索引方法以处理偏移量
BAKAOLC Apr 29, 2025
16ae5df
add rotation methods to Vector2
BAKAOLC Apr 29, 2025
4271d13
refactor Vector2 rotation methods to use radians and improve document…
BAKAOLC Apr 29, 2025
6ba4458
add cross product method to Vector2
BAKAOLC Apr 29, 2025
27cbf2b
add Triangle class with geometric operations and methods
BAKAOLC Apr 29, 2025
ab034da
add methods to create Vector2 from radians and angles
BAKAOLC Apr 29, 2025
f81de14
add move and moved methods to Triangle for translation operations
BAKAOLC Apr 29, 2025
f7fd944
add Line class for geometric operations
BAKAOLC Apr 29, 2025
868ed00
rename Line class to Segment and update methods accordingly
BAKAOLC Apr 29, 2025
a6ec037
refactor: update struct names to include foundation prefix for consis…
BAKAOLC Apr 29, 2025
4163969
feat: add intersection methods for Segment and Triangle classes
BAKAOLC Apr 29, 2025
4294d26
feat: add Circle, Line, Ray classes and intersection methods for geom…
BAKAOLC Apr 29, 2025
a60abcf
feat: update intersection methods to return multiple points for geome…
BAKAOLC Apr 29, 2025
08c097d
feat: add intersection methods for Circle, Line, Ray, Segment, and Tr…
BAKAOLC Apr 29, 2025
7427682
feat: add intersection methods for Rectangle in Circle, Line, Ray, Se…
BAKAOLC Apr 29, 2025
4e026cc
feat: add Rectangle class with geometric operations and intersection …
BAKAOLC Apr 29, 2025
885444b
feat: 添加获取三角形顶点和边的功能,优化相交检测方法
BAKAOLC Apr 29, 2025
7ccbc4a
feat: add conversion methods for Vector2, Vector3, and Vector4, and e…
BAKAOLC Apr 29, 2025
83295d5
feat: add Sector class with intersection methods for Circle, Line, Ra…
BAKAOLC Apr 29, 2025
5e44fde
refactor: remove unused local variables from Line, Ray, and Segment m…
BAKAOLC Apr 29, 2025
7f8fed5
fix comment
BAKAOLC Apr 29, 2025
7003c4a
refactor: simplify intersection checks by utilizing ShapeIntersector …
BAKAOLC Apr 29, 2025
b31c635
feat: add angle and rotation methods for Line, Ray, Rectangle, and Se…
BAKAOLC Apr 29, 2025
731b0ee
refactor: reorganize Triangle intersection methods in ShapeIntersector
BAKAOLC Apr 29, 2025
13f0071
refactor: update sector direction calculations to use angle method
BAKAOLC Apr 29, 2025
d2a031c
refactor: consolidate sector direction and range properties in Sector…
BAKAOLC Apr 30, 2025
dae0a1c
refactor: optimize point containment checks in Sector and ShapeInters…
BAKAOLC Apr 30, 2025
892523d
refactor: update equality checks and distance comparisons to use incl…
BAKAOLC Apr 30, 2025
a12e824
refactor: add methods to calculate closest points on Line and Ray
BAKAOLC Apr 30, 2025
2c53ce4
refactor: rename nearestPoint method to closestPoint in Ray class
BAKAOLC Apr 30, 2025
18ce64e
refactor: simplify direction calculations and streamline closestPoint…
BAKAOLC Apr 30, 2025
d8882e8
refactor: simplify point containment and closest point calculations i…
BAKAOLC Apr 30, 2025
a2791e2
refactor: add perimeter calculation methods for Circle, Rectangle, Se…
BAKAOLC Apr 30, 2025
c5ffcec
feat: implement Polygon class with geometric operations and intersect…
BAKAOLC Apr 30, 2025
42d68a1
refactor: change size type from size_t to int in Polygon struct
BAKAOLC Apr 30, 2025
4265b4a
feat: add containsPoint method to Polygon class for point containment…
BAKAOLC Apr 30, 2025
f8af2e4
feat: add createFromTable methods for Vector2, Vector3, and Vector4 c…
BAKAOLC Apr 30, 2025
0d508c9
feat: add garbage collection for Polygon creation to manage memory
BAKAOLC Apr 30, 2025
656ca90
refactor: remove debug print statement from garbage collection in Pol…
BAKAOLC Apr 30, 2025
4168029
feat: implement custom __index and __newindex methods for Polygon class
BAKAOLC May 1, 2025
05434b0
feat: enhance convexity check in Polygon class for improved validity …
BAKAOLC May 1, 2025
71187be
feat: add rotation and incenter calculations for Circle and Rectangle…
BAKAOLC May 1, 2025
20a5044
feat: add laboratory for geometry
BAKAOLC May 1, 2025
21132b2
feat: add rendering for projected points in object visualization
BAKAOLC May 1, 2025
b9e14e8
feat: update closestPoint method in Circle class to return input poin…
BAKAOLC May 1, 2025
815decf
feat: add boundary parameter to closestPoint methods in geometric shapes
BAKAOLC May 1, 2025
a2be53f
feat: add centroid and getCenter methods for Circle, Polygon, Rectang…
BAKAOLC May 1, 2025
4d2d4d9
feat: add getCenter and getBoundingBoxSize methods for Circle, Line, …
BAKAOLC May 1, 2025
e52bd60
add MIT LICENSE about this
BAKAOLC May 1, 2025
ad0a104
feat: implement __index and __newindex metamethods for Circle, Line, …
BAKAOLC May 1, 2025
a0e9cb1
feat: add rendering toggle options for various geometric features in …
BAKAOLC May 1, 2025
76b65d4
fix: handle NaN values in player position calculation
BAKAOLC May 1, 2025
a2d7d08
fix: rename data reference for points in Polygon class
BAKAOLC May 1, 2025
55fdcba
feat: add clone method for geometric shape classes
BAKAOLC May 1, 2025
03ac1c4
重新整理代码结构
BAKAOLC May 1, 2025
cd0ccbc
feat: add Ellipse and BezierCurve classes with intersection methods
BAKAOLC May 1, 2025
ef13702
feat: render BezierCurve control points in the main drawing function
BAKAOLC May 1, 2025
4548651
refactor: simplify point transformation logic in Ellipse class
BAKAOLC May 1, 2025
18cd0ef
feat: add segment parameter to containsPoint method for BezierCurve
BAKAOLC May 1, 2025
ffbc84d
feat: add methods for equal arc length points and segments in BezierC…
BAKAOLC May 2, 2025
eb7d039
Merge pull request #1 from BAKAOLC/ffi_struct
BAKAOLC May 2, 2025
db468f0
fix: address parameter type mismatch warnings in ellipse intersection…
BAKAOLC May 2, 2025
049a6c5
feat: add matrix and transformation classes for 2D and 3D operations
BAKAOLC May 2, 2025
cb8fc60
feat: add AABB bounding box methods for geometric shapes
BAKAOLC May 10, 2025
b2c52ac
feat: enhance geometric shapes with rotation and scaling methods supp…
BAKAOLC May 10, 2025
dec237c
feat: 添加线段取点方法
BAKAOLC May 18, 2025
864a842
modify to git modules
BAKAOLC May 20, 2025
95da691
update
BAKAOLC May 20, 2025
d795063
update module
BAKAOLC May 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "game/packages/community-creations"]
path = game/packages/community-creations
url = https://github.com/Legacy-LuaSTG-Engine/Community-Creations
[submodule "game/packages/lua-ffi-math"]
path = game/packages/lua-ffi-math
url = https://github.com/BAKAOLC/Lua-FFI-Math.git
7 changes: 6 additions & 1 deletion game/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"type": "directory",
"path": "packages/thlib-scripts-v2/"
},
{
"name": "lua-ffi-math",
"type": "directory",
"path": "packages/lua-ffi-math/"
},
{
"name": "community-creations",
"type": "directory",
Expand All @@ -69,7 +74,7 @@
"window": {
"title": "LuaSTG aex+",
"cursor_visible": true,
"allow_window_corner": true
"allow_window_corner": false
},
"graphics_system": {
"preferred_device_name": "",
Expand Down
1 change: 1 addition & 0 deletions game/packages/lua-ffi-math
Submodule lua-ffi-math added at adaa76
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
local ffi = require("ffi")

local type = type
local error = error
local tostring = tostring
local setmetatable = setmetatable
local table = table
local math = math

---@class foundation.struct.array.BooleanArray
---@field size number 数组大小
---@field offset number 偏移量
---@field data userdata FFI布尔数组
local BooleanArray = {}

---创建一个新的布尔数组
---@param size number 数组大小(必须为正整数)
---@param offset number 偏移量(默认为1)
---@return foundation.struct.array.BooleanArray 新创建的布尔数组
---@overload fun(size:number):foundation.struct.array.BooleanArray
function BooleanArray.create(size, offset)
if type(size) ~= "number" or size <= 0 then
error("Invalid size: " .. tostring(size))
end
if type(offset) == "nil" then
offset = 1
end
if type(offset) ~= "number" or offset ~= math.floor(offset) then
error("Invalid offset: " .. tostring(offset))
end
local self = setmetatable({
size = size,
offset = offset,
data = ffi.new("bool[?]", size)
}, BooleanArray)
return self
end

---索引元方法,获取数组元素
---@param self foundation.struct.array.BooleanArray
---@param key number|string 索引或方法名
---@return boolean|function 数组元素值或方法
function BooleanArray.__index(self, key)
if type(key) == "number" then
local c_key = key - self.offset
if c_key < 0 or c_key >= self.size then
error("Index out of bounds: " .. key)
end
return self.data[c_key]
end
return BooleanArray[key]
end

---赋值元方法,设置数组元素
---@param self foundation.struct.array.BooleanArray
---@param key number 数组索引
---@param value boolean 布尔值
function BooleanArray.__newindex(self, key, value)
if type(key) ~= "number" then
error("Invalid index type: " .. type(key))
end
local c_key = key - self.offset
if c_key < 0 or c_key >= self.size then
error("Index out of bounds: " .. key)
end
if type(value) ~= "boolean" then
error("Invalid value type: " .. type(value))
end
self.data[c_key] = value
end

---加法元方法 (逻辑OR操作)
---@param a foundation.struct.array.BooleanArray 左操作数
---@param b foundation.struct.array.BooleanArray 右操作数
---@return foundation.struct.array.BooleanArray 结果数组
function BooleanArray.__add(a, b)
if a.size ~= b.size then
error("Cannot add arrays of different sizes")
end
local result = BooleanArray.create(a.size)
for i = 0, a.size - 1 do
result.data[i] = a.data[i] or b.data[i]
end
return result
end

---减法元方法 (a且非b)
---@param a foundation.struct.array.BooleanArray 左操作数
---@param b foundation.struct.array.BooleanArray 右操作数
---@return foundation.struct.array.BooleanArray 结果数组
function BooleanArray.__sub(a, b)
if a.size ~= b.size then
error("Cannot subtract arrays of different sizes")
end
local result = BooleanArray.create(a.size)
for i = 0, a.size - 1 do
result.data[i] = a.data[i] and not b.data[i]
end
return result
end

---乘法元方法 (逻辑AND操作)
---@param a foundation.struct.array.BooleanArray 左操作数
---@param b foundation.struct.array.BooleanArray 右操作数
---@return foundation.struct.array.BooleanArray 结果数组
function BooleanArray.__mul(a, b)
if a.size ~= b.size then
error("Cannot multiply arrays of different sizes")
end
local result = BooleanArray.create(a.size)
for i = 0, a.size - 1 do
result.data[i] = a.data[i] and b.data[i]
end
return result
end

---除法元方法 (逻辑相等操作)
---@param a foundation.struct.array.BooleanArray 左操作数
---@param b foundation.struct.array.BooleanArray 右操作数
---@return foundation.struct.array.BooleanArray 结果数组
function BooleanArray.__div(a, b)
if a.size ~= b.size then
error("Cannot divide arrays of different sizes")
end
local result = BooleanArray.create(a.size)
for i = 0, a.size - 1 do
result.data[i] = a.data[i] == b.data[i]
end
return result
end

---一元减法元方法 (逻辑NOT操作)
---@param self foundation.struct.array.BooleanArray
---@return foundation.struct.array.BooleanArray 取反后的数组
function BooleanArray.__unm(self)
local result = BooleanArray.create(self.size)
for i = 0, self.size - 1 do
result.data[i] = not self.data[i]
end
return result
end

---连接元方法
---@param a foundation.struct.array.BooleanArray 左操作数
---@param b foundation.struct.array.BooleanArray 右操作数
---@return foundation.struct.array.BooleanArray 连接后的数组
function BooleanArray.__concat(a, b)
local result = BooleanArray.create(a.size + b.size)
for i = 0, a.size - 1 do
result.data[i] = a.data[i]
end
for i = 0, b.size - 1 do
result.data[a.size + i] = b.data[i]
end
return result
end

---相等比较元方法
---@param a foundation.struct.array.BooleanArray 左操作数
---@param b foundation.struct.array.BooleanArray 右操作数
---@return boolean 数组是否相等
function BooleanArray.__eq(a, b)
if a.size ~= b.size then
return false
end
for i = 0, a.size - 1 do
if a.data[i] ~= b.data[i] then
return false
end
end
return true
end

---获取数组长度的元方法
---@param self foundation.struct.array.BooleanArray
---@return number 数组长度
function BooleanArray.__len(self)
return self.size
end
BooleanArray.length = BooleanArray.__len

---转为字符串的元方法
---@param self foundation.struct.array.BooleanArray
---@return string 数组的字符串表示
function BooleanArray.__tostring(self)
local result = {}
for i = 0, self.size - 1 do
result[i + 1] = tostring(self.data[i])
end
return "BooleanArray: [" .. table.concat(result, ", ") .. "]"
end

---获取数组索引的偏移量
---@return number 数组偏移量
function BooleanArray:getOffset()
return self.offset
end

---设置数组的偏移量
---@param offset number 新的偏移量
function BooleanArray:setOffset(offset)
if type(offset) ~= "number" then
error("Invalid offset type: " .. type(offset))
end
if offset ~= math.floor(offset) then
error("Offset must be an integer")
end
self.offset = offset
end

---用指定的值填充整个数组
---@param value boolean 填充值
function BooleanArray:fill(value)
for i = 0, self.size - 1 do
self.data[i] = value
end
end

---获取数组的迭代器
---@return function,foundation.struct.array.BooleanArray,number 迭代器函数、数组对象和初始索引
function BooleanArray:ipairs()
return function(t, i)
i = i + 1
if i < t.size then
return i, t.data[i]
end
end, self, -1
end

---克隆数组
---@return foundation.struct.array.BooleanArray 数组副本
function BooleanArray:clone()
local clone = BooleanArray.create(self.size)
for i = 0, self.size - 1 do
clone.data[i] = self.data[i]
end
return clone
end

return BooleanArray
Loading