[Freeciv-Dev] Re: directional system: more magic code cleanups
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Mon, Sep 17, 2001 at 01:01:51PM -0400, Jason Dorje Short wrote:
> static int straightest_direction(int src_x, int src_y, int dest_x, int
> dest_y)
> {
> int best_dir = -1, dir;
> float best = -1;
> int diff_x, diff_y;
>
> /* This code is topology-dependent */
> diff_x = dest_x - src_x;
> if (diff_x < -map.xsize / 2) diff_x += map.xsize;
> if (diff_x > map.xsize / 2) diff_x -= map.xsize;
> diff_y = dest_y - src_y;
>
> for (dir=0; dir<8; dir++) {
> float product = diff_x * DIR_DX[dir] + diff_y * DIR_DY[dir];
> product /= sqrt(DIR_DX[dir] * DIR_DX[dir] + DIR_DY[dir] *
> DIR_DY[dir]);
>
> if (product > best) {
> best = product;
> best_dir = dir;
> }
> }
>
> assert(best >= 0 && best_dir >= 0);
> return best_dir;
> }
I have attached a version which doesn't use float and sqrt. Please
review.
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
Living on earth may be expensive, but it includes an annual free trip
around the sun.
diff
Description: Text document
- [Freeciv-Dev] Re: directional system: more magic code cleanups, (continued)
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Gregory Berkolaiko, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Gregory Berkolaiko, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Gregory Berkolaiko, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Jason Dorje Short, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Jason Dorje Short, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups,
Raimar Falke <=
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Jason Dorje Short, 2001/09/18
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Ross W. Wetmore, 2001/09/18
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Ross W. Wetmore, 2001/09/18
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/19
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/20
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Ross W. Wetmore, 2001/09/20
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/21
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Ross W. Wetmore, 2001/09/21
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/23
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Ross W. Wetmore, 2001/09/24
|
|