Math & Collisions library
Re: mlib: Math Library
I have no idea why I didn't do that earlier...
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: mlib: Math Library
Not too bright here but doesn't
get you to the same place as
Just wondering.
Best
Edit: If you want to retain the original order of the table you could add:
as the first line of my function
Code: Select all
function median(tab)
table.sort(tab)
if #tab%2 == 0 then
return (tab[math.floor(#tab/2)]+tab[math.floor(#tab/2+1)])/2
else
return tab[#tab/2+.5]
end
end
Code: Select all
function mlib.get_median( ... )
name = { ... }
for i = 1, #name do
if #name > 2 then
least = math.min( unpack( name ) )
largest = math.max( unpack( name ) )
for ii = 1, #name do
if name[ii] == least then
table.remove( name, ii )
break
end
end
for ii = 1, #name do
if name[ii] == largest then
table.remove( name, ii )
break
end
end
elseif #name == 2 then
median = mlib.get_mean( name[1], name[2] )
return median
elseif #name == 1 then
median = name[1]
return median
end
end
end
Best
Edit: If you want to retain the original order of the table you could add:
Code: Select all
local tab = {unpack(tab)}
Re: mlib: Math Library
Updated GitHub! Functions are now localized, refined, and get_mode returns how many times the number repeats as well.
You can also use straight tables now instead of having to do you can do
You can also use straight tables now instead of having to do
Code: Select all
mlib.get_mode( unpack( tab ) )
Code: Select all
mlib.get_mode( tab )
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: mlib: Math Library
Might want to avoid unnecessary variable creation by replacing:davisdude wrote:Updated GitHub! Functions are now localized( tab )[/code]
Code: Select all
function mlib.get_midpoint( x1, y1, x2, y2 )
local name = { ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 }
return name
end
Code: Select all
function mlib.get_midpoint( x1, y1, x2, y2 )
return { ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 }
end
Best
Re: mlib: Math Library
I read somewhere that it was faster if you assigned variables then called them as opposed to just calling them. I don't know if it's true or not, or if it even really impacts it that much, but...
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- Hexenhammer
- Party member
- Posts: 175
- Joined: Sun Feb 17, 2013 8:19 am
Re: mlib: Math Library
Assigning the table to a variable is completely pointless here and only makes your code more verbose. If it has any effect on performance at all it will make things slower.davisdude wrote:I read somewhere that it was faster if you assigned variables then called them as opposed to just calling them. I don't know if it's true or not, or if it even really impacts it that much, but...
Re: mlib: Math Library
I guess that does make more sense, but I just thought it would make the code neater anyway...Hexenhammer wrote:davisdude wrote:I read somewhere that it was faster if you assigned variables then called them as opposed to just calling them. I don't know if it's true or not, or if it even really impacts it that much, but...
Assigning the table to a variable is completely pointless here and only makes your code more verbose. If it has any effect on performance at all it will make things slower.
Fixed!
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: mlib: Math Library
Sorry for double posting!
Updated! Added getPolygonArea and removed get_convex_area and get_triangle_area since they are repetitive. Check out the GitHub for the update!
By the way, just in case any of you are curious, I used the Shoelace Formula.
Updated! Added getPolygonArea and removed get_convex_area and get_triangle_area since they are repetitive. Check out the GitHub for the update!
By the way, just in case any of you are curious, I used the Shoelace Formula.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: mlib: Math Library
Sorry for triple posting! (Please don't get mad! )
v. 1.4.1 is now released! You can now get the centroid of a non-intersecting polygon! mlib is also a localized variable now!
I also have a simple little demo if you want to check it out! I may expand upon it/make more if you guys like it! Just an idea...
v. 1.4.1 is now released! You can now get the centroid of a non-intersecting polygon! mlib is also a localized variable now!
I also have a simple little demo if you want to check it out! I may expand upon it/make more if you guys like it! Just an idea...
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: mlib: Math Library
The shame! 4 consecutive posts...
Somebody stop the madness!
Anyway, 1.5.0 is out and I'm working on more functions at the moment.
As always, please make sure to vote and comment if you want any particular function/don't like how the arguments work/have any issue.
Enjoy!
(I'm working on a better demo right now, so ignore that bit for now...)
Somebody stop the madness!
Anyway, 1.5.0 is out and I'm working on more functions at the moment.
As always, please make sure to vote and comment if you want any particular function/don't like how the arguments work/have any issue.
Enjoy!
(I'm working on a better demo right now, so ignore that bit for now...)
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Who is online
Users browsing this forum: Ahrefs [Bot] and 2 guests