Re: Two NSRects adjacent/touching?
Re: Two NSRects adjacent/touching?
- Subject: Re: Two NSRects adjacent/touching?
- From: Wagner Truppel <email@hidden>
- Date: Wed, 27 Jun 2007 13:48:15 +0200
Compute the union of the two rectangles. If
a) the width of the union equals the sum of the widths of the two
individual rectangles AND the height of the union is less than or
equal to the sum of the heights of the individual rectangles
OR
b) the height of the union equals the sum of the heights of the two
individual rectangles AND the width of the union is less than or
equal to the sum of the widths of the individual rectangles
then the two rectangles are sharing an edge and are, therefore,
touching.
Drawing a picture will help to see why.
Wagner
Hi all,
Summary:
Is there a simple way to determine if two NSRects are
touching/adjacent to each other?
Background:
I'm working on an instructional tile game, and need a
way to determine if tiles are touching.
Currently, I have a tile class, each of which knows
its own NSRect, whether it's been clicked, etc. At the
time of a new game, all of the tiles are created and
stored in an NSMutableArray.
When the game's being played, and the user clicks
somewhere in the view, I iterate through the tile
array to see which one the user clicked, using a
simple NSPointInRect() call.
This is where I'm running into trouble: only some
tiles are clickable at any given moment. Part of what
determines clickability is whether the tile has any
sides that aren't touching another tile.
So, I was hoping to find a way to determine this
programatically by feeding the clicked tile's rect
into a function which could then quickly compare that
rect against those of the other tiles.
Is there an easy way to determine whether two NSRects
are touching/adjacent to each other?
Thanks!
B
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden