summary refs log tree commit diff stats
path: root/src/rectangle.h
blob: 7815b567e664a5f3a86f374167b999d570fe682f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef RECTANGLE_H_23049366
#define RECTANGLE_H_23049366

#include "vector.h"

template <typename T>
class rect {
public:

  using vector_type = vec2<T>;

  constexpr rect(
    vector_type pos,
    vector_type size) :
      pos(pos),
      size(size)
  {
  }

  const vector_type pos;
  const vector_type size;

  bool contains(vector_type point) const
  {
    return (
      point.x() >= pos.x() &&
      point.x() < pos.x() + size.w() &&
      point.y() >= pos.y() &&
      point.y() < pos.y() + size.h());
  }

};

using rect4s = rect<size_t>;

#endif /* end of include guard: RECTANGLE_H_23049366 */