XOR and IsClockWise

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
whitebear
Citizen
Posts: 86
Joined: Sun Mar 15, 2009 1:50 am

XOR and IsClockWise

Post by whitebear »

I needed a IsClockWise Function so I converted this code to Lua.
Only problem I had was that LÖVE does not have XOR so I made one.

Usage:
GetIsClockWise(x1,y1,x2,y2,x3,y3)
If points are given in clockwise order it returns true, else it returns false.


XOR(a,b)
if a is true and b is true returns false
if a is false and b is false returns false
if a is false and b is true returns true
if a is true and b is false returns true

example syntrax:

Code: Select all

if XOR(a > b, b < c) then
--my bla code if b neither biggest or smallest
else
--my bla code if b is biggest or smallest
end
I know the example sucked.
Attachments
lib_cw.lua
(482 Bytes) Downloaded 128 times
User avatar
ljdp
Party member
Posts: 209
Joined: Sat Jan 03, 2009 1:04 pm
Contact:

Re: XOR and IsClockWise

Post by ljdp »

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

Re: XOR and IsClockWise

Post by Robin »

I think the XOR thing could be done with a one-liner. Something like "bool(a) ~= bool(b)".
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: XOR and IsClockWise

Post by bartbes »

Robin wrote:I think the XOR thing could be done with a one-liner. Something like "bool(a) ~= bool(b)".
POWNED?

Well, at least a ~= b is a lot shorter..
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: XOR and IsClockWise

Post by Robin »

bartbes wrote:Well, at least a ~= b is a lot shorter..
Your version wins. It seems we have no bool() in Lua :cry:.
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: XOR and IsClockWise

Post by bartbes »

I've thought of a fix for that:

Code: Select all

function xor(a, b)
    return not a ~= not b
end
Not will convert it into boolean for you.
User avatar
whitebear
Citizen
Posts: 86
Joined: Sun Mar 15, 2009 1:50 am

Re: XOR and IsClockWise

Post by whitebear »

Its not same but what ever.. I just posted it if it would help.
Post Reply

Who is online

Users browsing this forum: No registered users and 228 guests