Another Lua Vector library
Re: Another Lua Vector library
Here is the improved version: https://github.com/DeybisMelendez/lua-v ... tag/v0.7.0
Re: Another Lua Vector library
damv wrote: ↑Tue Jul 30, 2019 10:55 pm Here is the improved version: https://github.com/DeybisMelendez/lua-v ... tag/v0.7.0
I think you want:github wrote:Code: Select all
vecMt.__index = vecMt local mt = { -- Metatable of vector __call = function(_, x, y) ...
Code: Select all
vecMt.__index = vecMt
vecMt.__call = function(_, x, y)
...
Personally I'm more of the "no tabs ever" school but I know that's not too popular with Lua.
Re: Another Lua Vector library
I just want to add that the absolutely most performant code does not use tables at all. The fastest vector library would simply treat 2D vectors as two numbers:Nelvin wrote: ↑Tue Jul 30, 2019 9:09 pm If you really care about performance (maybe just in special areas of some innerloops where you need the best possible performance) you could easily localize the methods in question, shortcutting all the overhead described above and directly call them with your tables.
Code: Select all
local vec1x, vec1y = 4, 2
local vec2x, vec2y = 2, 4
vec1x, vec1y = vectorRotate( vec1x,vec1y, math.pi/3 )
local dotResult = vectorDot( vec1x,vec1y, vec2x,vec2y )
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
Re: Another Lua Vector library
What do you think if I change it as follows:ReFreezed wrote: ↑Sat Aug 03, 2019 12:21 pmI just want to add that the absolutely most performant code does not use tables at all. The fastest vector library would simply treat 2D vectors as two numbers:Nelvin wrote: ↑Tue Jul 30, 2019 9:09 pm If you really care about performance (maybe just in special areas of some innerloops where you need the best possible performance) you could easily localize the methods in question, shortcutting all the overhead described above and directly call them with your tables.
It's a bit less elegant, but it's way faster and more memory efficient.Code: Select all
local vec1x, vec1y = 4, 2 local vec2x, vec2y = 2, 4 vec1x, vec1y = vectorRotate( vec1x,vec1y, math.pi/3 ) local dotResult = vectorDot( vec1x,vec1y, vec2x,vec2y )
Code: Select all
vector = require "vector"
--variables
vec1 = vector(5, 5)
vec2 = vector(3, 6)
-- The vector class contains the methods...
local distance = vector.distanceTo(vec1, vec2) --get the distance between 2 vectors...
vec1 = vector.rotated(vec1, math.pi)
-- The vector instance contains the metatable methods
print(tostring(vec1 + vec2))
Re: Another Lua Vector library
As for the spaces and tabs, I have that problem with Atom, I think I do not have it well configured, I will have to see how to fix it, although Travis gives me the "build: passing".pgimeno wrote: ↑Tue Jul 30, 2019 11:42 pm
Also, you seem to have mixed tabs and spaces. If you look at https://github.com/DeybisMelendez/lua-v ... vector.lua you'll see the difference between lines 67 and before, and 68 and after, because GitHub uses a tab size of 8.
Personally I'm more of the "no tabs ever" school but I know that's not too popular with Lua.
Who is online
Users browsing this forum: Google [Bot] and 3 guests