From 3ed03edfec82740ebecda53a6100470fbe6570ee Mon Sep 17 00:00:00 2001 From: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Date: Mon, 5 May 2025 10:04:33 +1000 Subject: [PATCH] [display] Fix Rect::inside (#8679) --- esphome/components/display/rect.cpp | 13 ++++--------- esphome/components/display/rect.h | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/esphome/components/display/rect.cpp b/esphome/components/display/rect.cpp index 49bb7d025f..2c41127860 100644 --- a/esphome/components/display/rect.cpp +++ b/esphome/components/display/rect.cpp @@ -69,21 +69,16 @@ bool Rect::inside(int16_t test_x, int16_t test_y, bool absolute) const { // NOL return true; } if (absolute) { - return ((test_x >= this->x) && (test_x <= this->x2()) && (test_y >= this->y) && (test_y <= this->y2())); - } else { - return ((test_x >= 0) && (test_x <= this->w) && (test_y >= 0) && (test_y <= this->h)); + return test_x >= this->x && test_x < this->x2() && test_y >= this->y && test_y < this->y2(); } + return test_x >= 0 && test_x < this->w && test_y >= 0 && test_y < this->h; } -bool Rect::inside(Rect rect, bool absolute) const { +bool Rect::inside(Rect rect) const { if (!this->is_set() || !rect.is_set()) { return true; } - if (absolute) { - return ((rect.x <= this->x2()) && (rect.x2() >= this->x) && (rect.y <= this->y2()) && (rect.y2() >= this->y)); - } else { - return ((rect.x <= this->w) && (rect.w >= 0) && (rect.y <= this->h) && (rect.h >= 0)); - } + return this->x2() >= rect.x && this->x <= rect.x2() && this->y2() >= rect.y && this->y <= rect.y2(); } void Rect::info(const std::string &prefix) { diff --git a/esphome/components/display/rect.h b/esphome/components/display/rect.h index f55c2fe201..5f11d94681 100644 --- a/esphome/components/display/rect.h +++ b/esphome/components/display/rect.h @@ -26,7 +26,7 @@ class Rect { void extend(Rect rect); void shrink(Rect rect); - bool inside(Rect rect, bool absolute = true) const; + bool inside(Rect rect) const; bool inside(int16_t test_x, int16_t test_y, bool absolute = true) const; bool equal(Rect rect) const; void info(const std::string &prefix = "rect info:");