Skip to content

Commit

Permalink
[共通] Image::inBounds #1229
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Jun 29, 2024
1 parent 78a09e2 commit 9ee8f8b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Siv3D/include/Siv3D/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ namespace s3d
[[nodiscard]]
const Color& operator [](Point pos) const;

[[nodiscard]]
bool inBounds(int64 y, int64 x) const noexcept;

[[nodiscard]]
bool inBounds(Point pos) const noexcept;

/// @brief 画像データの先頭のポインタを返します。
/// @return 画像データの先頭のポインタ
[[nodiscard]]
Expand Down
12 changes: 12 additions & 0 deletions Siv3D/include/Siv3D/detail/Image.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ namespace s3d
return *(m_data.data() + (static_cast<size_t>(m_width) * pos.y + pos.x));
}

inline bool Image::inBounds(const int64 y, const int64 x) const noexcept
{
return (0 <= y) && (y < static_cast<int64>(m_height))
&& (0 <= x) && (x < static_cast<int64>(m_width));
}

inline bool Image::inBounds(const Point pos) const noexcept
{
return (0 <= pos.y) && (pos.y < static_cast<int64>(m_height))
&& (0 <= pos.x) && (pos.x < static_cast<int64>(m_width));
}

inline Color* Image::data()
{
return m_data.data();
Expand Down

0 comments on commit 9ee8f8b

Please sign in to comment.