Advertisement
Guest User

Untitled

a guest
Jul 1st, 2022
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. class Entity {
  2. public:
  3.     int x, y;
  4.     bool alive;
  5.     // Distance squared
  6.     inline int distance2 (const Entity &e) {
  7.         return (x - e.x)*(x - e.x) + (y - e.y)*(y - e.y);
  8.     }
  9.     // Distance square rooted
  10.     inline float distance (Entity *e) {
  11.         return sqrt(distance2(*e));
  12.     }
  13.  
  14.     inline float distance (int value) {
  15.         return sqrt(value);
  16.     }
  17.  
  18.     // Distance squared from given point
  19.     inline int distance2 (int _x, int _y) {
  20.         return (x - _x)*(x - _x) + (y - _y)*(y - _y);
  21.     }
  22.  
  23.     // Distance square from given point
  24.     inline float distance (int _x, int _y) {
  25.         return sqrt(distance2(_x,_y));
  26.     }
  27. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement