Just to follow up on the question that I posted yesterday (see below), I
have found the problem.
The distance method in the DrawUtils class was overflowing and returning
an erroneous result. For the most part, the overflow occurred where
each of the terms are squared. The cast to float does not apply until
after the overflow, so that does nothing to mitigate the problem. The
original code is below:
public final static float distance(int x1, int y1, int x2, int y2) {
int xdiff = x2 - x1;
int ydiff = y2 - y1;
return (float) Math.sqrt((float) (xdiff * xdiff + ydiff *
ydiff));
}
Although complete overkill to use double, changing the variable type of
the *diff variables to long does not completely solve the problem. If
both of the difference calculations overflow the integer, it is then
possible to overflow the long when the two differences are added. Since
Math.sqrt takes a double anyway, I didn't see much harm in replacing
this integer multiplication with a double multiplication.
The patched code follows:
public final static float distance(int x1, int y1, int x2, int y2) {
double xdiff = x2 - x1;
double ydiff = y2 - y1;
return (float) Math.sqrt(xdiff * xdiff + ydiff * ydiff);
}
Chris
-- Hi, OpenMappers, In our application, we make extensive use of OMLines with OMArrowHeads. It seems that when the ratio between the length of the arrow (i.e. distance to destination) and the zoom level hits a certain threshold, the arrow fills the entire screen. This problem is not typically noticeable since we operate with modest line lengths and reasonable zoom levels. However, once in a while, we will get a very long line and the problem appears. In tracking this down, I noticed the link between line length and zoom. At maximum zoom in, the arrow starts exploding somewhere around 4km. When the arrow head is removed from the line, the problem goes away. And finally, in the typical scenario, the arrow does not fill the screen constantly - it will continue to flicker on and off as zooming continues. Thanks in advance for your assistance! Chris ________________________________ Chris Allport Software Engineer 21795 N Shangri-La Dr, Ste C Lexington Park, MD 20653 (301) 904-5943 Fax (301) 737-8897 callport@dtiweb.net www.dtiweb.net This message may contain sensitive, proprietary and/or privileged information. Disclosure is not authorized unless provided in writing by Defense Technologies, Inc. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation.
-- [To unsubscribe to this list send an email to "majdart@bbn.com" with the following text in the BODY of the message "unsubscribe openmap-users"]
This archive was generated by hypermail 2.1.8 : Thu Mar 11 2010 - 13:12:20 EST