fork download
  1. //I place this code in the public domain - Jamin Grey
  2. struct Point
  3. {
  4. public:
  5. int x;
  6. int y;
  7.  
  8. public:
  9. Point() : x(0), y(0) { }
  10. Point(int x, int y) : x(x), y(y) { }
  11. Point(const Point &point); //Copy constructor
  12. ~Point() = default;
  13.  
  14. /*
  15.   //Keeps the point within 'rect'.
  16.   void KeepWithin(const Rect &rect);
  17.  
  18.   //Keeps the point outside of 'rect'.
  19.   void KeepWithout(const Rect &rect);
  20.  
  21.   //Snaps the point to the nearest edge of 'rect', regardless of
  22.   //whether the point is inside or outside the rectangle.
  23.   void SnapToEdge(const Rect &rect);
  24.   */
  25.  
  26. //Returns the absolute distance between this point and 'other'.
  27. unsigned DistanceFrom(const Point &other);
  28. //Returns true if we are within 'distance' of 'other'. This is faster than 'DistanceFrom', because it saves a sqrt().
  29. bool WithinDistanceOf(const Point &other, unsigned distance) const;
  30.  
  31. bool operator==(const Point &other) const;
  32. bool operator!=(const Point &other) const;
  33.  
  34. Point &operator=(const Point &other); //Assignment operator
  35.  
  36. Point &operator+=(const Point &other);
  37. Point &operator-=(const Point &other);
  38. Point &operator*=(const Point &other);
  39. Point &operator/=(const Point &other);
  40. Point &operator%=(const Point &other);
  41.  
  42. Point operator+(const Point &other) const;
  43. Point operator-(const Point &other) const;
  44. Point operator*(const Point &other) const;
  45. Point operator/(const Point &other) const;
  46. Point operator%(const Point &other) const;
  47.  
  48. //Additive-inverse operator.
  49. Point operator-() const;
  50. };
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty