From f2b438d5c5b29cb4e31a02d4f715a9f9ddb87c93 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 29 Jan 2023 23:37:34 -0500 Subject: [PATCH] const-correctness in location/rectangle --- src/location.cpp | 16 ++++++++-------- src/location.hpp | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/location.cpp b/src/location.cpp index af45518ac..b5debd392 100644 --- a/src/location.cpp +++ b/src/location.cpp @@ -54,7 +54,7 @@ bool loc_compare::operator()(location a, location b) const { return false; } -bool location::in(rectangle r){ +bool location::in(rectangle r) const { if(y >= r.top && y <= r.bottom && x >= r.left && x <= r.right) return true; return false; @@ -88,13 +88,13 @@ rectangle::rectangle(int t, int l, int b, int r) : top(t), left(l), right(r), bo rectangle::rectangle(const sf::Texture& texture) : top(0), left(0), right(texture.getSize().x), bottom(texture.getSize().y) {} rectangle::rectangle(const sf::RenderTarget& texture) : top(0), left(0), right(texture.getSize().x), bottom(texture.getSize().y) {} -bool rectangle::contains(location p){ +bool rectangle::contains(location p) const { if(p.y >= top && p.y <= bottom && p.x >= left && p.x <= right) return true; return false; } -bool rectangle::contains(int x, int y) { +bool rectangle::contains(int x, int y) const { return contains(location(x,y)); } @@ -166,23 +166,23 @@ const rectangle_size_delegate rectangle::height() const { return rectangle_size_delegate(*const_cast(this), &rectangle::top, &rectangle::bottom); } -location rectangle::centre() { +location rectangle::centre() const { return location((left + right) / 2, (top + bottom) / 2); } -location rectangle::topLeft() { +location rectangle::topLeft() const { return location(left, top); } -location rectangle::topRight() { +location rectangle::topRight() const { return location(right, top); } -location rectangle::bottomLeft() { +location rectangle::bottomLeft() const { return location(left, bottom); } -location rectangle::bottomRight() { +location rectangle::bottomRight() const { return location(right, bottom); } diff --git a/src/location.hpp b/src/location.hpp index 629369fb5..a5721a92f 100644 --- a/src/location.hpp +++ b/src/location.hpp @@ -34,7 +34,7 @@ struct location { location(int x, int y); template location(sf::Vector2 other) : location(other.x, other.y) {} - bool in(rectangle r); + bool in(rectangle r) const; template operator typename sf::template Vector2() { return sf::Vector2(x,y); @@ -81,13 +81,13 @@ struct rectangle { rectangle_size_delegate height(); const rectangle_size_delegate width() const; const rectangle_size_delegate height() const; - location centre(); - location topLeft(); - location topRight(); - location bottomLeft(); - location bottomRight(); - bool contains(location p); - bool contains(int x, int y); + location centre() const; + location topLeft() const; + location topRight() const; + location bottomLeft() const; + location bottomRight() const; + bool contains(location p) const; + bool contains(int x, int y) const; void offset(int h, int v); void offset(location diff); void move_to(int x, int y);