VNMediaClientNET
Rectangle.h
1 
12 #include "Point.h"
13 
14 #pragma once
15 #ifndef H_Rectangle
16 #define H_Rectangle
17 
18 class Rectangle2 {
19 public:
20  Rectangle2(void) {}
21  Rectangle2(int x, int y, int width, int height)
22  {
23  this->x = x;
24  this->y = y;
25  this->width = width;
26  this->height = height;
27  }
28  Rectangle2( int width, int height )
29  : x(0), y(0), width( width ), height( height )
30  { }
31  //~Rectangle2(void);
32  bool contains(const Point2& p)
33  {
34  return this->contains(p.x, p.y);
35  }
36  bool contains(int x, int y)
37  {
38  return this->inside(x, y);
39  }
40 
52  bool inside(int X, int Y) {
53  int w = this->width;
54  int h = this->height;
55  if ((w | h) < 0) {
56  // At least one of the dimensions is negative...
57  return false;
58  }
59  // Note: if either dimension is zero, tests below must return false...
60  int x = this->x;
61  int y = this->y;
62  if (X < x || Y < y) {
63  return false;
64  }
65  w += x;
66  h += y;
67  // overflow || intersect
68  return ((w < x || w > X) &&
69  (h < y || h > Y));
70  }
71 
72  void setBounds(Rectangle2 r) {
73  setBounds(r.x, r.y, r.width, r.height);
74  }
75 
76  void setBounds(int x, int y, int width, int height) {
77  reshape(x, y, width, height);
78  }
79 
80  void reshape(int x, int y, int width, int height) {
81  this->x = x;
82  this->y = y;
83  this->width = width;
84  this->height = height;
85  }
86 public:
87  int x;
88  int y;
89  int width;
90  int height;
91 };
92 
93 #endif
Rectangle2
Definition: Rectangle.h:18
Point2
Definition: Point.h:16
Rectangle2::inside
bool inside(int X, int Y)
Definition: Rectangle.h:52