00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef HAVE_CONFIG_H
00023 # include <config.h>
00024 #endif
00025
00026 #include "dir.h"
00027
00028
00029
00030
00031
00032
00033
00034 Direction Get_direction
00035 (
00036 int deltay,
00037 int deltax
00038 )
00039 {
00040 if (deltax == 0)
00041 return deltay > 0 ? north : south;
00042 int dydx = (1024*deltay)/deltax;
00043 if (dydx >= 0)
00044 if (deltax >= 0)
00045 return dydx <= 424 ? east : dydx <= 2472 ? northeast
00046 : north;
00047 else
00048 return dydx <= 424 ? west : dydx <= 2472 ? southwest
00049 : south;
00050 else
00051 if (deltax >= 0)
00052 return dydx >= -424 ? east : dydx >= -2472 ? southeast
00053 : south;
00054 else
00055 return dydx >= -424 ? west : dydx >= -2472 ? northwest
00056 : north;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 Direction Get_direction4
00066 (
00067 int deltay,
00068 int deltax
00069 )
00070 {
00071 if (deltax >= 0)
00072 return (deltay > deltax ? north : deltay < -deltax ? south
00073 : east);
00074 else
00075 return (deltay > -deltax ? north : deltay < deltax ? south
00076 : west);
00077 }
00078
00079
00080
00081
00082
00083
00084
00085 int Get_direction16
00086 (
00087 int deltay,
00088 int deltax
00089 )
00090 {
00091 if (deltax == 0)
00092 return deltay > 0 ? 0 : 8;
00093 int dydx = (1024*deltay)/deltax;
00094 int adydx = dydx < 0 ? -dydx : dydx;
00095 int angle = 0;
00096 if (adydx < 1533)
00097 {
00098 if (adydx < 204)
00099 angle = 4;
00100 else if (adydx < 684)
00101 angle = 3;
00102 else
00103 angle = 2;
00104 }
00105 else
00106 {
00107 if (adydx < 5148)
00108 angle = 1;
00109 else
00110 angle = 0;
00111 }
00112
00113 if (deltay < 0)
00114 if (deltax > 0)
00115 angle = 8 - angle;
00116 else
00117 angle += 8;
00118 else if (deltax < 0)
00119 angle = 16 - angle;
00120 return angle % 16;
00121 }