Jump to content

TPointF vector functions are broken


Recommended Posts

There's a very obvious bug in TPointF.Displace (but not TPoint.Displace).  Have a look; you should spot it in no time flat.

 

Also, once that's worked out, there's also something wrong with AngleTo.  And that's partially my own fault; I'm the one who provided the original implementation, and I missed something somewhere.  I'm not clear on exactly what the problem is, but there are certain angles where point.displace(1, point.AngleTo(point2)) does not result in a move closer to point 2.  I'm going to have to look at it further, but if there's anyone here with better trig skills than me, I'd welcome any help.

Link to post
Share on other sites

Fixed for TPointF.Displace.

 

The error for AngleTo seems to be similar (and X instead of an Y when computing dy).

 

However the following implementation would be preferable anyway:

function TPointF.AngleTo(const aPoint: TPointF): Float; 
begin 
   Result := ArcTan2( aPoint.Y - Y, aPoint.X - X ); 
end;

Link to post
Share on other sites

Wow, it is the same problem. Somehow I missed that.  That's kind of embarrassing... :P

 

Thanks for the atan2 solution.  I didn't know about atan2 when I wrote that.  That makes it a lot simpler, and it appears to be correct now.

 

BTW I had a heck of a time debugging this, because every time I would change the code, it would get changed back when I built since I'm apparently working on a copy of the RTL, and the "master copy" is hidden somewhere completely different that Smart never tells you about so I had to go search for it.  Is there any way we could get that replaced with some more user-friendly behavior?  Thanks.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...