Penetrator (Geometry lib)

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Penetrator (Geometry lib)

Post by Ranguna259 »

I couldn't find any geometry library for LÖVE and geometry is something that is usually needed for Game Engines. In AdobeScript we have this, Java, C# and lots of other programing languages and since there is no Geom for our lövely engine then I've decided to create one. And it's called Penetrator ;)

This library is currently based on the Adobe's one but I'm also taking ideas from other languages (like the mentioned above).

I'd like to make this lib open for everyone to add stuff to it, so if you have any ideas related to geometry that can help lovers out then by all means share it here and I'll add it (if it's usefull :P )

Functions in the build:
  • function newRect(x,y,width,height)
  • function moveRect(Rect,x,y)
  • function resizeRect(Rect,width,height)
  • function reshapeRect(Rect,x,y,width,height)
  • function getArea(Rect)
  • function getInter(Rect1,Rect2)
  • function isInter(Rect1,Rect2,Tolerance)
  • function isIn(Rect,x,y)
  • function getUnion(Rect1,Rect2)
  • function equalsRect(Rect1,Rect2)
  • function emptyRect(Rect)
  • function isEmpty(Rect)
  • function tostringRect(Rect1,'Name')
What you can do with the current build:
  • Creating a rectangle with just one line of code
  • Moving, resizing and reshaping rectangles
  • Getting the area (px^2) of a rectangle
  • Getting the Intersetion Area of two rectangles
  • Checking if two rectangles are intersecting
  • Getting the Union data of two rectangles
  • Emptying a rectangle and check if rectangles are empty
  • Converting a rectangle data into a printable string
What I'm currently working on:
  • Functio to check if a point is within a rectangle
  • Check if a rectangle is the same as another rectangle
  • "Growing" a rectangle
  • Checking if a rectangle is.. a rectangle and not an empty table
  • Changing the location of a rectangle
  • Making a rectangle "empty"
  • Resizing a rectangle
  • Recreating rectangle.java to löve --Dropped because of legal issues
  • Union of two rectangles (or more)

Change log:
v2.4:
  • Added resizeRect()
  • Added moveRect()
  • Added equalsRect()
  • Added isEmpty()
  • Added emptyRect()
v2.3:
  • Added getArea()
  • Added tostringRect()
v2.2:
  • Added tolerance to isInter()
v2.1:
  • Optimized isInter()
v2:
  • Added getUnion
  • Optimized getInter(), thanks to jonyzz
v1:
  • Added newRect
  • Added isInter
  • Added getInter
Check out Penetrator's GitHub for more info and Demos

(Licence stuff: You can use this file however you want: use it, edit it, include it in a commercial game (free or paid) and distribute it to your friends, you can do all that and it's free of charge)
Attachments
Penetrator.lua
v2.4
(3.76 KiB) Downloaded 158 times
Penetrator.love
Demo (outdated)
(1.83 KiB) Downloaded 188 times
Last edited by Ranguna259 on Tue Aug 27, 2013 4:30 pm, edited 10 times in total.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Penetrator (Geometry lib)

Post by Ranguna259 »

I can't upload attachments ? :shock:

It says:
Sorry, the board attachment quota has been reached.
Last edited by Ranguna259 on Mon Aug 26, 2013 2:53 am, edited 1 time in total.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Penetrator (Geometry lib)

Post by raidho36 »

Well just read into what it says: you've reached attachments limit. What's unclear with that?

Go to your user control panel and delete some useless attachments. Or, better yet, ask admin for extra room for attachments. You could also upload files to the wiki all you want (which makes attachment limit utterly useless) and post links to the forum.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Penetrator (Geometry lib)

Post by Ranguna259 »

Ah thanks :megagrin:
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
Daniel Eakins
Citizen
Posts: 99
Joined: Thu Jul 18, 2013 9:14 pm
Location: France

Re: Penetrator (Geometry lib)

Post by Daniel Eakins »

raidho36 wrote:Well just read into what it says: you've reached attachments limit. What's unclear with that?

Go to your user control panel and delete some useless attachments. Or, better yet, ask admin for extra room for attachments. You could also upload files to the wiki all you want (which makes attachment limit utterly useless) and post links to the forum.
I have zero attachment and I get that same message when I tried to attach a file once.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Penetrator (Geometry lib)

Post by Ranguna259 »

You sure ? I just went to the Attachmnet manager, removed some attachments and I can upload again
Last edited by Ranguna259 on Sat Aug 24, 2013 9:07 pm, edited 1 time in total.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Penetrator (Geometry lib)

Post by Robin »

Daniel Eakins wrote:I have zero attachment and I get that same message when I tried to attach a file once.
That's probably because that file was too large.
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Penetrator (Geometry lib)

Post by Jasoco »

I didn't even know this forum had an attachment quota, or a way to remove attachments.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Penetrator (Geometry lib)

Post by vrld »

Sorry, but your code is not very good and much too long. Here is a shorter version:

Code: Select all

function isInter(a, b)
	local ax2,ay2,bx2,by2 = a.x + a.width, a.y + a.height, b.x + b.width, b.y + b.height
	return a.x < bx2 and ax2 > b.x and a.y < by2 and ay2 > b.y
end

function getInter(a, b)
	if not isInter(a, b) then return end

	if a.x > b.x then a,b = b,a end
	local x = b.x
	local w = a.x + a.width - b.x

	if a.y > b.y then a,b = b,a end
	local y = b.y
	local h = a.y + a.height - b.y

	return newRect(x,y,w,h)
end
The isInter function is in fact the same as the BoundingBox.lua in the wiki. I am sure it's possible to make getInter more efficient, but I hope you get the idea.

Regarding coding style for modules: It's generally a good idea to not create any global variables (and functions) inside modules, but return a table with the functions instead. The function names could also be better: It is not immediately clear what isInter() and getInter() are supposed to do. You can look at the libraries of other users to get a feeling for this stuff.

Also,
Ranguna259 wrote:I couldn't find any geometry library for LÖVE and geometry is something that is usually needed for Game Engines.
Maybe you looked for the wrong stuff. If you search for collision detection, you will almost certainly find at least HardonCollider, bump.lua, and maybe also fizzx.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Penetrator (Geometry lib)

Post by Ranguna259 »

Jasoco wrote:I didn't even know this forum had an attachment quota, or a way to remove attachments.
Yeah neither did I, but it's kinda comprehensible, after all space costs money but the limit is kind of.. small
vrld wrote:Sorry, but your code is not very good and much too long. Here is a shorter version:

Code: Select all

function isInter(a, b)
	local ax2,ay2,bx2,by2 = a.x + a.width, a.y + a.height, b.x + b.width, b.y + b.height
	return a.x < bx2 and ax2 > b.x and a.y < by2 and ay2 > b.y
end

function getInter(a, b)
	if not isInter(a, b) then return end

	if a.x > b.x then a,b = b,a end
	local x = b.x
	local w = a.x + a.width - b.x

	if a.y > b.y then a,b = b,a end
	local y = b.y
	local h = a.y + a.height - b.y

	return newRect(x,y,w,h)
end
The isInter function is in fact the same as the BoundingBox.lua in the wiki. I am sure it's possible to make getInter more efficient, but I hope you get the idea.

Regarding coding style for modules: It's generally a good idea to not create any global variables (and functions) inside modules, but return a table with the functions instead. The function names could also be better: It is not immediately clear what isInter() and getInter() are supposed to do. You can look at the libraries of other users to get a feeling for this stuff.

Also,
Ranguna259 wrote:I couldn't find any geometry library for LÖVE and geometry is something that is usually needed for Game Engines.
Maybe you looked for the wrong stuff. If you search for collision detection, you will almost certainly find at least HardonCollider, bump.lua, and maybe also fizzx.
Your code doesn't work when obj2 has bigger or smaller width or height, that's why the code is big, this is not a collision detection lib, it's just a geometry lib.. Wait don't tell me that the libs you said do what this does do they ? :ultrashocked:
Last edited by Ranguna259 on Sun Aug 25, 2013 1:41 pm, edited 1 time in total.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests