OSDN Git Service

[Refactor] #37353 distance() を geometry.c/h へ移動。
authordeskull <deskull@users.sourceforge.jp>
Thu, 18 Apr 2019 04:59:43 +0000 (13:59 +0900)
committerdeskull <deskull@users.sourceforge.jp>
Thu, 18 Apr 2019 04:59:43 +0000 (13:59 +0900)
src/externs.h
src/geometry.c
src/geometry.h
src/grid.c

index 3cea29d..0ebb5c5 100644 (file)
@@ -415,7 +415,6 @@ extern void dump_yourself(FILE *fff);
 
 
 /* grids.c */
-extern POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
 extern bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
 extern void update_local_illumination(POSITION y, POSITION x);
 extern bool player_can_see_bold(POSITION y, POSITION x);
index 8307ba5..9688a9b 100644 (file)
@@ -1,6 +1,46 @@
 #include "angband.h"
 #include "floor.h"
 
+
+/*!
+ * @brief 2点間の距離をニュートン・ラプソン法で算出する / Distance between two points via Newton-Raphson technique
+ * @param y1 1点目のy座標
+ * @param x1 1点目のx座標
+ * @param y2 2点目のy座標
+ * @param x2 2点目のx座標
+ * @return 2点間の距離
+ */
+POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
+{
+       POSITION dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
+       POSITION dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
+
+       /* Squared distance */
+       POSITION target = (dy * dy) + (dx * dx);
+
+       /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
+       POSITION d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
+
+       POSITION err;
+
+       /* Simple case */
+       if (!dy || !dx) return d;
+
+       while (1)
+       {
+               /* Approximate error */
+               err = (target - d * d) / (2 * d);
+
+               /* No error - we are done */
+               if (!err) break;
+
+               /* Adjust distance */
+               d += err;
+       }
+
+       return d;
+}
+
 /*!
  * @brief プレイヤーから指定の座標がどの方角にあるかを返す /
  * Convert an adjacent location to a direction.
index 742a84a..747b160 100644 (file)
@@ -23,6 +23,7 @@ extern DIRECTION coords_to_dir(POSITION y, POSITION x);
 #define PROJECT_LOS         0x8000 /*!< 遠隔攻撃特性: /  */
 extern sint project_path(u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg);
 
+extern POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
 extern bool projectable(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
 extern void scatter(POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode);
 extern void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2);
index c19e347..2b25e3a 100644 (file)
@@ -793,47 +793,6 @@ void place_bound_perm_wall(grid_type *g_ptr)
        place_solid_perm_grid(g_ptr);
 }
 
-
-/*!
- * @brief 2点間の距離をニュートン・ラプソン法で算出する / Distance between two points via Newton-Raphson technique
- * @param y1 1点目のy座標
- * @param x1 1点目のx座標
- * @param y2 2点目のy座標
- * @param x2 2点目のx座標
- * @return 2点間の距離
- */
-POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
-{
-       POSITION dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
-       POSITION dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
-
-       /* Squared distance */
-       POSITION target = (dy * dy) + (dx * dx);
-
-       /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
-       POSITION d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
-
-       POSITION err;
-
-       /* Simple case */
-       if (!dy || !dx) return d;
-
-       while (1)
-       {
-               /* Approximate error */
-               err = (target - d * d) / (2 * d);
-
-               /* No error - we are done */
-               if (!err) break;
-
-               /* Adjust distance */
-               d += err;
-       }
-
-       return d;
-}
-
-
 /*!
  * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
  * @param g_ptr マス構造体の参照ポインタ