Re: Best way to compare CGFloats
Re: Best way to compare CGFloats
- Subject: Re: Best way to compare CGFloats
- From: "Rimas M." <email@hidden>
- Date: Wed, 30 Jun 2010 12:46:43 +0300
Thanks everyone for answers. Now situation is more clear.
On Wed, Jun 30, 2010 at 12:14 PM, Alastair Houghton
<email@hidden> wrote:
>
> fabs is the right way to do this in most cases, *but* with co-ordinate values it may be that you are actually more interested in the distance of one point from the other---i.e. you might in fact be interested in
>
> CGFloat dx = C.x - D.x, dy = C.y - D.y;
> BOOL pointsAreEqual = (dx * dx + dy * dy) < epsilonSquared;
>
> It rather depends on what you want, and that's going to differ from one application to another.
In my case I am interested in x's and y's comparison. Not points as
themselves. But your suggestion gave me another question, which I have
never thought about before - how NSEqualPoints, ...Rects etc works? I
guess they *must* be safe to use, because NSPoint, NSRect etc relies
on floats/doubles. Or they uses the same '==' and are TRUE only if
points/rects are *really* equal?
Best Regards,
Rimas M.
_______________________________________________
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