Page 2 of 2

### Re: Another Lua Vector library

Posted: Tue Jul 30, 2019 10:55 pm

### Re: Another Lua Vector library

Posted: Tue Jul 30, 2019 11:42 pm
damv wrote:
Tue Jul 30, 2019 10:55 pm
Here is the improved version: https://github.com/DeybisMelendez/lua-v ... tag/v0.7.0
github wrote:

Code: Select all

``````vecMt.__index = vecMt
local mt = { -- Metatable of vector
__call = function(_, x, y)
...
``````
I think you want:

Code: Select all

``````vecMt.__index = vecMt
vecMt.__call = function(_, x, y)
...
``````
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.

### Re: Another Lua Vector library

Posted: Sat Aug 03, 2019 12:21 pm
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.
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:

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 )
``````
It's a bit less elegant, but it's way faster and more memory efficient.

### Re: Another Lua Vector library

Posted: Wed Aug 07, 2019 3:50 pm
ReFreezed wrote:
Sat Aug 03, 2019 12:21 pm
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.
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:

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 )
``````
It's a bit less elegant, but it's way faster and more memory efficient.
What do you think if I change it as follows:

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

Posted: Wed Aug 07, 2019 3:59 pm
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.
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".