ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Gui.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 #include <algorithm>
11 
12 namespace cloudViewer {
13 namespace visualization {
14 namespace gui {
15 
16 Point::Point() : x(0), y(0) {}
17 
18 Point::Point(int x_, int y_) : x(x_), y(y_) {}
19 
20 // ----------------------------------------------------------------------------
21 Size::Size() : width(0), height(0) {}
22 
23 Size::Size(int w, int h) : width(w), height(h) {}
24 
25 // ----------------------------------------------------------------------------
26 Rect::Rect() : x(0), y(0), width(0), height(0) {}
27 
28 Rect::Rect(int x_, int y_, int w_, int h_)
29  : x(x_), y(y_), width(w_), height(h_) {}
30 
31 int Rect::GetTop() const { return this->y; }
32 
33 int Rect::GetBottom() const { return this->y + this->height; }
34 
35 int Rect::GetLeft() const { return this->x; }
36 
37 int Rect::GetRight() const { return this->x + this->width; }
38 
39 bool Rect::Contains(int x, int y) const {
40  return (x >= this->x && x <= GetRight() && y >= this->y &&
41  y <= GetBottom());
42 }
43 
44 bool Rect::Contains(const Point& pt) const { return Contains(pt.x, pt.y); }
45 
46 Rect Rect::UnionedWith(const Rect& r) const {
47  auto newX = std::min(this->x, r.x);
48  auto newY = std::min(this->y, r.y);
49  auto w = std::max(GetRight() - newX, r.GetRight() - newX);
50  auto h = std::max(GetBottom() - newY, r.GetBottom() - newY);
51  return Rect(newX, newY, w, h);
52 }
53 
54 bool Rect::operator==(const Rect& other) const {
55  return (this->x == other.x && this->y == other.y &&
56  this->width == other.width && this->height == other.height);
57 }
58 
59 bool Rect::operator!=(const Rect& other) const { return !operator==(other); }
60 
61 } // namespace gui
62 } // namespace visualization
63 } // namespace cloudViewer
int width
int height
int min(int a, int b)
Definition: cutil_math.h:53
int max(int a, int b)
Definition: cutil_math.h:48
Generic file read and write utility for python interface.
Rect UnionedWith(const Rect &r) const
Definition: Gui.cpp:46
bool operator!=(const Rect &other) const
Definition: Gui.cpp:59
bool Contains(int x, int y) const
Definition: Gui.cpp:39
bool operator==(const Rect &other) const
Definition: Gui.cpp:54