fork download
  1. #include <iostream>
  2. using namespace std;
  3. // simple Point structure
  4. template <typename T, typename U, typename V>
  5. struct Point{
  6. T x;
  7. U y;
  8. V z; // optional
  9.  
  10. /*
  11.   Point(){
  12.   x = T();
  13.   y = U();
  14.   z = V();
  15.   }*/
  16.  
  17. Point(T _x, U _y) {
  18. x = _x;
  19. y = _y;
  20. }
  21.  
  22. Point(T _x, U _y, V _z){
  23. x = _x;
  24. y = _y;
  25. z = _z;
  26. }
  27.  
  28. inline bool equals(Point & p){
  29. return(p.x == x && p.y == y);
  30. }
  31.  
  32. };
  33. // Rectangular Bounds for tree
  34. // T,U should hold double or float only
  35. template <typename T, typename U, typename V>
  36. struct RectBounds {
  37. // x, y center point
  38. T x;
  39. U y;
  40. // dimension width w and height h
  41. T w, h;
  42.  
  43. //constructors
  44.  
  45. // (_x, _y): center of rectangle bound. (_w, _h): width and height
  46. RectBounds(T _x, U _y, T _w, T _h){
  47. x = _x;
  48. y = _y;
  49. w = _w;
  50. h = _h;
  51. }
  52.  
  53. // returns true if point p is in Rect bounds, false otherwise
  54. inline bool contains(Point<T, U, V> & p) {
  55. float _w = w/2.0f;
  56. float _h = h/2.0f;
  57. return p.x >= x - _w && p.x < x + _w && p.y >= y - _h && p.y < y + _h;
  58. }
  59.  
  60. // returns true if rectangle o intersects this, false otherwise
  61. inline bool intersects( RectBounds & o){
  62. float _w = w/2.0f;
  63. float _h = h/2.0f;
  64. return !(o.y + o.h/2.0f <= y - _h || o.y - o.h/2.0f >= y + _h || o.x + o.w/2.0f <= x - _w || o.x - o.w/2.0f >= x + _w);
  65. }
  66. };
  67.  
  68. int main() {
  69. // your code goes here
  70. return 0;
  71. }
Success #stdin #stdout 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty