Skip to content

Commit

Permalink
improve: Add directional overloads for Rect::stretched and RectF::str…
Browse files Browse the repository at this point in the history
…etched (#1279)
  • Loading branch information
leaf2326 authored Dec 13, 2024
1 parent 53a103e commit b8882b9
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Siv3D/include/Siv3D/Rect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,30 @@ namespace s3d
[[nodiscard]]
constexpr Rect stretched(value_type top, value_type right, value_type bottom, value_type left) const noexcept;

/// @brief 上方向に拡大縮小した長方形を返します。
/// @param top 上方向の拡大縮小量
/// @return 上方向に拡大縮小した長方形
[[nodiscard]]
constexpr Rect stretched(Arg::top_<value_type> top) const noexcept;

/// @brief 右方向に拡大縮小した長方形を返します。
/// @param right 右方向の拡大縮小量
/// @return 右方向に拡大縮小した長方形
[[nodiscard]]
constexpr Rect stretched(Arg::right_<value_type> right) const noexcept;

/// @brief 下方向に拡大縮小した長方形を返します。
/// @param bottom 下方向の拡大縮小量
/// @return 下方向に拡大縮小した長方形
[[nodiscard]]
constexpr Rect stretched(Arg::bottom_<value_type> bottom) const noexcept;

/// @brief 左方向に拡大縮小した長方形を返します。
/// @param left 左方向の拡大縮小量
/// @return 左方向に拡大縮小した長方形
[[nodiscard]]
constexpr Rect stretched(Arg::left_<value_type> left) const noexcept;

[[nodiscard]]
constexpr RectF scaled(double s) const noexcept;

Expand Down
24 changes: 24 additions & 0 deletions Siv3D/include/Siv3D/RectF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,30 @@ namespace s3d
[[nodiscard]]
constexpr RectF stretched(value_type top, value_type right, value_type bottom, value_type left) const noexcept;

/// @brief 上方向に拡大縮小した長方形を返します。
/// @param top 上方向の拡大縮小量
/// @return 上方向に拡大縮小した長方形
[[nodiscard]]
constexpr RectF stretched(Arg::top_<value_type> top) const noexcept;

/// @brief 右方向に拡大縮小した長方形を返します。
/// @param right 右方向の拡大縮小量
/// @return 右方向に拡大縮小した長方形
[[nodiscard]]
constexpr RectF stretched(Arg::right_<value_type> right) const noexcept;

/// @brief 下方向に拡大縮小した長方形を返します。
/// @param bottom 下方向の拡大縮小量
/// @return 下方向に拡大縮小した長方形
[[nodiscard]]
constexpr RectF stretched(Arg::bottom_<value_type> bottom) const noexcept;

/// @brief 左方向に拡大縮小した長方形を返します。
/// @param left 左方向の拡大縮小量
/// @return 左方向に拡大縮小した長方形
[[nodiscard]]
constexpr RectF stretched(Arg::left_<value_type> left) const noexcept;

[[nodiscard]]
constexpr RectF scaled(double s) const noexcept;

Expand Down
20 changes: 20 additions & 0 deletions Siv3D/include/Siv3D/detail/Rect.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,26 @@ namespace s3d
return{ (pos.x - left), (pos.y - top), (size.x + left + right), (size.y + top + bottom) };
}

inline constexpr Rect Rect::stretched(Arg::top_<value_type> top) const noexcept
{
return stretched(top.value(), 0, 0, 0);
}

inline constexpr Rect Rect::stretched(Arg::right_<value_type> right) const noexcept
{
return stretched(0, right.value(), 0, 0);
}

inline constexpr Rect Rect::stretched(Arg::bottom_<value_type> bottom) const noexcept
{
return stretched(0, 0, bottom.value(), 0);
}

inline constexpr Rect Rect::stretched(Arg::left_<value_type> left) const noexcept
{
return stretched(0, 0, 0, left.value());
}

inline constexpr RectF Rect::scaled(const double s) const noexcept
{
return{ Arg::center((pos.x + size.x * 0.5), (pos.y + size.y * 0.5)), (size.x * s), (size.y * s) };
Expand Down
20 changes: 20 additions & 0 deletions Siv3D/include/Siv3D/detail/RectF.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,26 @@ namespace s3d
return{ (pos.x - left), (pos.y - top), (size.x + left + right), (size.y + top + bottom) };
}

inline constexpr RectF RectF::stretched(Arg::top_<value_type> top) const noexcept
{
return stretched(top.value(), 0, 0, 0);
}

inline constexpr RectF RectF::stretched(Arg::right_<value_type> right) const noexcept
{
return stretched(0, right.value(), 0, 0);
}

inline constexpr RectF RectF::stretched(Arg::bottom_<value_type> bottom) const noexcept
{
return stretched(0, 0, bottom.value(), 0);
}

inline constexpr RectF RectF::stretched(Arg::left_<value_type> left) const noexcept
{
return stretched(0, 0, 0, left.value());
}

inline constexpr RectF RectF::scaled(const double s) const noexcept
{
return{ Arg::center((pos.x + size.x * 0.5), (pos.y + size.y * 0.5)), (size.x * s), (size.y * s) };
Expand Down

0 comments on commit b8882b9

Please sign in to comment.