No, those are not the same. (although I applaud you for trying it yourself.) :scruff:
If @x = 5, x1 = 10, x2 = 15, then
@x > x1 => false
@x < x2 => true
You defined the problem as 2 arbitrary rectangles, existing in any position on a plane.
Both scripts provided will tell you if the 2 rectangles intersect. (or touch)
But by the sounds of your 2nd post, the rectangles will never intersect, only touch (or not touch).
Let's make a couple more assumptions...
You are using pixel movement
The rectangles can be any size
You are using 8 directional movement.
Seph's algorithm compares every point (integer / pixel) on rect1 to the boundaries of rect2. If any point falls within those boundaries, the rectangles intersect.
My algorithm determines if rect2 is either Above, Below, Left, or Right of rect1, then they do not intersect. I think this algorithm lends itself to determining direction a bit easier.
Since this is "Script Support" where we learn to script, I'll just give you the algorithm, and see if you can code it...
8 directional movement is indicated by the numbers on the number pad...
7 8 9
4 5 6
1 2 3
So, if rect2 is above, the direction is '8', below is '2', Left is '4', Right is '6'
Both Above & Left would be '7'.....
If we initialize 'direction' to 5 (in the middle) then we can work out from there...
@direction = 5 #initialize direction
# set the direction of approach before they touch
If <the bottom of rect2> is less than <the top of rect1>
@direction = 8 #above
end
If <the top of rect2> is greater than <the bottom of rect1>
@direction = 2 #below
end
If <the left side of rect2> is greater than <the right side of rect1>
@direction += 1 #1 right of either above, center, or bottom
end
If <the right side of rect2> is less than <the left side of rect1>
@direction -= 1 # 1 left of either above, center, or bottom
end
# If the direction == 5, return true. Otherwise return false
return @direction == 5
If you check direction after a 'true' response, it should be set to the proper approach direction.
Be Well