Skip to content

Commit

Permalink
make vectors work with map positions
Browse files Browse the repository at this point in the history
  • Loading branch information
przemo1232 committed Aug 23, 2024
1 parent 1a55c65 commit 3592eb8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/vector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
---@operator unm(): Pyvector
py.vector = {
__add = function(self, v)
return py.vector.new(self.x + v.x, self.y + v.y, self.z + v.z)
return py.vector.new(self.x + v.x, self.y + v.y, self.z + (v.z or 0))
end,

__sub = function(self, v)
return py.vector.new(self.x - v.x, self.y - v.y, self.z - v.z)
return py.vector.new(self.x - v.x, self.y - v.y, self.z - (v.z or 0))
end,

__mul = function(self, v)
if type(self) == 'number' then self = py.vector.new(self,self,self) end
if type(v) == 'number' then v = py.vector.new(v,v,v) end
return py.vector.new(self.x * v.x, self.y * v.y, self.z * v.z)
return py.vector.new(self.x * v.x, self.y * v.y, self.z * (v.z or 0))
end,

__div = function(self, v)
if type(self) == 'number' then self = py.vector.new(self,self,self) end
if type(v) == 'number' then v = py.vector.new(v,v,v) end
return py.vector.new(self.x / v.x, self.y / v.y, self.z / v.z)
return py.vector.new(self.x / v.x, self.y / v.y, self.z / (v.z or 0))
end,

__unm = function(self)
Expand Down Expand Up @@ -59,16 +59,16 @@ py.vector = {
---@param v Pyvector
---@return Pyvector
dot = function(self, v)
return self.x * v.x + self.y * v.y + self.z * v.z
return self.x * v.x + self.y * v.y + self.z * (v.z or 0)
end,

---@param v Pyvector
---@return Pyvector
cross = function(self, v)
local out = {}
local a, b, c = self.x, self.y, self.z
out.x = b * v.z - c * v.y
out.y = c * v.x - a * v.z
out.x = b * (v.z or 0) - c * v.y
out.y = c * v.x - a * (v.z or 0)
out.z = a * v.y - b * v.x
return py.vector.new(out)
end,
Expand Down

0 comments on commit 3592eb8

Please sign in to comment.