ESPHome  2024.4.1
rect.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "esphome/core/helpers.h"
4 
5 namespace esphome {
6 namespace display {
7 
8 static const int16_t VALUE_NO_SET = 32766;
9 
10 class Rect {
11  public:
12  int16_t x;
13  int16_t y;
14  int16_t w;
15  int16_t h;
16 
17  Rect() : x(VALUE_NO_SET), y(VALUE_NO_SET), w(VALUE_NO_SET), h(VALUE_NO_SET) {} // NOLINT
18  inline Rect(int16_t x, int16_t y, int16_t w, int16_t h) ALWAYS_INLINE : x(x), y(y), w(w), h(h) {}
19  inline int16_t x2() const { return this->x + this->w; };
20  inline int16_t y2() const { return this->y + this->h; };
21 
22  inline bool is_set() const ALWAYS_INLINE { return (this->h != VALUE_NO_SET) && (this->w != VALUE_NO_SET); }
23 
24  void expand(int16_t horizontal, int16_t vertical);
25 
26  void extend(Rect rect);
27  void shrink(Rect rect);
28 
29  bool inside(Rect rect, bool absolute = true) const;
30  bool inside(int16_t test_x, int16_t test_y, bool absolute = true) const;
31  bool equal(Rect rect) const;
32  void info(const std::string &prefix = "rect info:");
33 };
34 
35 } // namespace display
36 } // namespace esphome
bool inside(Rect rect, bool absolute=true) const
Definition: rect.cpp:78
int16_t x
X coordinate of corner.
Definition: rect.h:12
int16_t h
Height of region.
Definition: rect.h:15
bool is_set() const ALWAYS_INLINE
Y coordinate of corner.
Definition: rect.h:22
int16_t y
Y coordinate of corner.
Definition: rect.h:13
void extend(Rect rect)
Definition: rect.cpp:19
bool equal(Rect rect) const
Definition: rect.cpp:63
Rect(int16_t x, int16_t y, int16_t w, int16_t h) ALWAYS_INLINE
Definition: rect.h:18
void info(const std::string &prefix="rect info:")
Definition: rect.cpp:89
int16_t x2() const
Definition: rect.h:19
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void expand(int16_t horizontal, int16_t vertical)
Definition: rect.cpp:10
void shrink(Rect rect)
Definition: rect.cpp:42
int16_t y2() const
X coordinate of corner.
Definition: rect.h:20
int16_t w
Width of region.
Definition: rect.h:14