diff options
author | Karl Berry <karl@freefriends.org> | 2019-04-04 20:55:44 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2019-04-04 20:55:44 +0000 |
commit | acab24042d34dd439e1d074820d1da2fa1d591cd (patch) | |
tree | 32881f869e20a69711c5fe86134aa48143d9b1e8 /Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/force/QuadTree.lua | |
parent | 93f5c4643a3d0a596d220ff14756ce68d99afe33 (diff) |
pgf (4apr19)
git-svn-id: svn://tug.org/texlive/trunk@50758 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/force/QuadTree.lua')
-rw-r--r-- | Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/force/QuadTree.lua | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/force/QuadTree.lua b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/force/QuadTree.lua index 4e511746bb2..3e1620dc21f 100644 --- a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/force/QuadTree.lua +++ b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/force/QuadTree.lua @@ -14,12 +14,12 @@ --- An implementation of a quad trees. -- -- The class QuadTree provides methods form handling quadtrees. --- +-- local QuadTree = { - -- Subclases + -- Subclasses Particle = {}, - Cell = {} + Cell = {} } QuadTree.__index = QuadTree @@ -45,7 +45,7 @@ end ---- Inserts a particle +--- Inserts a particle -- -- @param param A particle of type QuadTree.Particle -- @@ -76,7 +76,7 @@ end ---- Partical subclass +--- Particle subclass QuadTree.Particle.__index = QuadTree.Particle @@ -176,7 +176,7 @@ function QuadTree.Cell:insert(particle) if #self.subcells == 0 then self:createSubcells() end - + -- move particles to the new subcells for _,existing in ipairs(self.particles) do local cell = self:findSubcell(existing) @@ -210,7 +210,7 @@ function QuadTree.Cell:updateMass() for _,particle in ipairs(self.particles) do self.mass = self.mass + particle.mass for _,subparticle in ipairs(particle.subparticles) do - self.mass = self.mass + subparticle.mass + self.mass = self.mass + subparticle.mass end end else @@ -226,27 +226,27 @@ end function QuadTree.Cell:updateCenterOfMass() -- reset center of mass, assuming the cell is empty self.center_of_mass = nil - + if #self.subcells == 0 then -- the center of mass is the average position of the particles -- weighted by their masses self.center_of_mass = Vector.new (2) for _,p in ipairs(self.particles) do for _,sp in ipairs(p.subparticles) do - self.center_of_mass = self.center_of_mass:plus(sp.pos:timesScalar(sp.mass)) + self.center_of_mass = self.center_of_mass:plus(sp.pos:timesScalar(sp.mass)) end self.center_of_mass = self.center_of_mass:plus(p.pos:timesScalar(p.mass)) end self.center_of_mass = self.center_of_mass:dividedByScalar(self.mass) else - -- the center of mass is the average of the weighted centers of mass + -- the center of mass is the average of the weighted centers of mass -- of the subcells self.center_of_mass = Vector.new(2) for _,sc in ipairs(self.subcells) do if sc.center_of_mass then - self.center_of_mass = self.center_of_mass:plus(sc.center_of_mass:timesScalar(sc.mass)) + self.center_of_mass = self.center_of_mass:plus(sc.center_of_mass:timesScalar(sc.mass)) else - assert(sc.mass == 0) + assert(sc.mass == 0) end end self.center_of_mass = self.center_of_mass:dividedByScalar(self.mass) @@ -268,7 +268,7 @@ end function QuadTree.Cell:__tostring() return '((' .. self.x .. ', ' .. self.y .. ') ' - .. 'to (' .. self.x + self.width .. ', ' .. self.y + self.height .. '))' + .. 'to (' .. self.x + self.width .. ', ' .. self.y + self.height .. '))' .. (self.particle and ' => ' .. self.particle.name or '') .. (self.center_of_mass and ' mass ' .. self.mass .. ' at ' .. tostring(self.center_of_mass) or '') end @@ -277,4 +277,4 @@ end -- done -return QuadTree
\ No newline at end of file +return QuadTree |