fork download
  1. struct Point
  2. {
  3. public:
  4. int x;
  5. int y;
  6.  
  7. public:
  8. Point() : x(0), y(0) { }
  9. Point(int x, int y) : x(x), y(y) { }
  10. Point(const Point &point); //Copy constructor
  11. ~Point() { }
  12.  
  13. //A bunch of helper functions for assorted uses.
  14. //Some of it depends on another class (Rect), so I commented it all out.
  15. /*
  16.   //Keeps the point within 'rect'.
  17.   void KeepWithin(const Rect &rect);
  18.   //Keeps the point outside of 'rect'.
  19.   void KeepWithout(const Rect &rect);
  20.   //Snaps the point to the nearest edge of 'rect', regardless of
  21.   //whether the point is inside or outside the rectangle.
  22.   void SnapToEdge(const Rect &rect);
  23.  
  24.   //Returns 'true' if 'value.x' is greater than 'min.x' and less than 'max.x', and the same for the 'y' member.
  25.   static bool IsWithin(const Point &min, const Point &value, const Point &max);
  26.   static bool IsWithin(const Point &value, const Point &max);
  27.   //Keeps 'value.x' between 'min.x' and 'max.x', with 'loops.x' being the number of times it had to loop around.
  28.   //Does the same with the 'y' member. Negative loops return a negative number.
  29.   static Point LoopInRange(const Point &min, const Point &value, const Point &max, Point &loops);
  30.   static Point LoopInRange(const Point &value, const Point &max, Point &loops);
  31.   */
  32.  
  33. bool operator==(const Point &other) const;
  34. bool operator!=(const Point &other) const;
  35.  
  36. Point &operator=(const Point &other); //Assignment operator
  37.  
  38. Point &operator+=(const Point &other);
  39. Point &operator-=(const Point &other);
  40. Point &operator*=(const Point &other);
  41. Point &operator/=(const Point &other);
  42. Point &operator%=(const Point &other);
  43.  
  44. Point operator+(const Point &other) const;
  45. Point operator-(const Point &other) const;
  46. Point operator*(const Point &other) const;
  47. Point operator/(const Point &other) const;
  48. Point operator%(const Point &other) const;
  49.  
  50. //Additive-inverse operator.
  51. Point operator-() const;
  52.  
  53. //Some conversions you don't need:
  54. /*
  55.   //Packs the Point into a Uint32, with 16 bits for x, and 16 for y. Since both x and y can be negative,
  56.   //this leaves just 15 bits for the numeral component, meaning (-32768 to 32768) in both x and y.
  57.   uint32_t ToUint32() const;
  58.   void FromUint32(uint32_t data);
  59.  
  60.   //Format: "(x, y)"
  61.   std::string ToString() const;
  62.   void FromString(const std::string &str);
  63.  
  64.   SFML_ONLY
  65.   (
  66.   sf::Vector2f ToSfmlVector2f() const;
  67.   void FromSfmlVector2f(sf::Vector2f vector);
  68.   )
  69.  
  70.   QT_ONLY
  71.   (
  72.   QPoint ToQPoint() const;
  73.   void FromQPoint(QPoint point);
  74.   )
  75.   */
  76. };
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty