File: Rect.h

package info (click to toggle)
pymol 2.5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 42,288 kB
  • sloc: cpp: 476,472; python: 76,538; ansic: 29,510; javascript: 6,792; sh: 47; makefile: 24
file content (37 lines) | stat: -rw-r--r-- 621 bytes parent folder | download | duplicates (2)
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
37
#pragma once

namespace pymol
{

template<typename T>
struct Rect
{
  T x1{};
  T x2{};
  T y1{};
  T y2{};

  Rect() = default;
  Rect(T x1_, T x2_, T y1_, T y2_)
    : x1(x1_)
    , x2(x2_)
    , y1(y1_)
    , y2(y2_)
    {}

  /**
   * Determines if point is inside rect
   * @param x 2D point x coord
   * @param y 2D point y coord
   * @param proper disallows point to be on edge of rect
   */
  bool contains (T x, T y, bool proper = true) const noexcept {
    if (proper) {
      return x > x1 && x < x2 && y > y1 && y < y2;
    }
    return x >= x1 && x <= x2 && y >= y1 && y <= y2;
  }
};

} // namespace pymol