Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rect,RectFにrotate90(int32)系を追加 (#1094) #1178

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Siv3D/include/Siv3D/Rect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,19 @@ namespace s3d
[[nodiscard]]
Quad rotatedAt(Vec2 _pos, double angle) const noexcept;

/// @brief _posを中心とし、時計回りに 90°* n 回転した長方形を返します。
/// @param _pos 回転の中心座標
/// @param n 時計回りに 90° 回転させる回数(負の場合は反時計回り)
/// @return _posを中心とし、時計回りに 90°* n 回転した長方形
[[nodiscard]]
constexpr Rect rotated90At(const position_type& _pos, int32 n = 1) const noexcept;

/// @brief _posを中心とし、自身を時計回りに 90°* n 回転します。
/// @param _pos 回転の中心座標
/// @param n 時計回りに 90° 回転させる回数(負の場合は反時計回り)
/// @return *this
constexpr Rect& rotate90At(const position_type& _pos, int32 n = 1) noexcept;

[[nodiscard]]
constexpr Quad shearedX(double vx) 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 @@ -698,6 +698,30 @@ namespace s3d
[[nodiscard]]
Quad rotatedAt(Vec2 _pos, double angle) const noexcept;

/// @brief 時計回りに 90°* n 回転した長方形を返します。
/// @param n 時計回りに 90° 回転させる回数(負の場合は反時計回り)
/// @return 時計回りに 90°* n 回転した長方形
[[nodiscard]]
constexpr RectF rotated90(int32 n = 1) const noexcept;

/// @brief 自身を時計回りに 90°* n 回転します。
/// @param n 時計回りに 90° 回転させる回数(負の場合は反時計回り)
/// @return *this
constexpr RectF& rotate90(int32 n = 1) noexcept;

/// @brief _posを中心とし、時計回りに 90°* n 回転した長方形を返します。
/// @param _pos 回転の中心座標
/// @param n 時計回りに 90° 回転させる回数(負の場合は反時計回り)
/// @return _posを中心とし、時計回りに 90°* n 回転した長方形
[[nodiscard]]
constexpr RectF rotated90At(const Vec2& _pos, int32 n = 1) const noexcept;

/// @brief _posを中心とし、自身を時計回りに 90°* n 回転します。
/// @param _pos 回転の中心座標
/// @param n 時計回りに 90° 回転させる回数(負の場合は反時計回り)
/// @return *this
constexpr RectF& rotate90At(const Vec2& _pos, int32 n = 1) noexcept;

[[nodiscard]]
constexpr Quad shearedX(double vx) const noexcept;

Expand Down
23 changes: 23 additions & 0 deletions Siv3D/include/Siv3D/detail/Rect.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,29 @@ namespace s3d
return (static_cast<Type>(size.x) / size.y);
}

inline constexpr Rect Rect::rotated90At(const position_type& _pos, const int32 n) const noexcept
{
switch (n % 4) // 時計回りに何回 90° 回転するか
{
case 1:
case -3:
return { bl().rotate90At(_pos,1),size.yx() }; // 1 回または -3 回
case 2:
case -2:
return { br().rotate90At(_pos,2),size }; // 2 回または -2 回
case 3:
case -1:
return { tr().rotate90At(_pos,3),size.yx() }; // 3 回または -1 回
default:
return *this; // 0 回
}
}

inline constexpr Rect& Rect::rotate90At(const position_type& _pos, const int32 n) noexcept
{
return (*this = rotated90At(_pos, n));
}

inline constexpr Quad Rect::shearedX(const double vx) const noexcept
{
return{ {(pos.x + vx), pos.y}, {(pos.x + size.x + vx), pos.y}, {(pos.x + size.x - vx), (pos.y + size.y)}, {(pos.x - vx), (pos.y + size.y)} };
Expand Down
40 changes: 40 additions & 0 deletions Siv3D/include/Siv3D/detail/RectF.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,46 @@ namespace s3d
return (size.x / size.y);
}

inline constexpr RectF RectF::rotated90(const int32 n) const noexcept
{
switch (n % 2) // 90°* (奇数) 回転か
Reputeless marked this conversation as resolved.
Show resolved Hide resolved
{
case 1:
case -1:
return { bl().rotate90At(center(),1),size.yx() }; // 奇数
default:
return *this; // 偶数
}
}

inline constexpr RectF& RectF::rotate90(const int32 n) noexcept
{
return (*this = rotated90(n));
}

inline constexpr RectF RectF::rotated90At(const Vec2& _pos, const int32 n) const noexcept
{
switch (n % 4) // 時計回りに何回 90° 回転するか
{
case 1:
case -3:
return { bl().rotate90At(_pos,1),size.yx() }; // 1 回または -3 回
case 2:
case -2:
return { br().rotate90At(_pos,2),size }; // 2 回または -2 回
case 3:
case -1:
return { tr().rotate90At(_pos,3),size.yx() }; // 3 回または -1 回
default:
return *this; // 0 回
}
}

inline constexpr RectF& RectF::rotate90At(const Vec2& _pos, const int32 n) noexcept
{
return (*this = rotated90At(_pos, n));
}

inline constexpr Quad RectF::shearedX(const double vx) const noexcept
{
return{ {(pos.x + vx), pos.y}, {(pos.x + size.x + vx), pos.y}, {(pos.x + size.x - vx), (pos.y + size.y)}, {(pos.x - vx), (pos.y + size.y)} };
Expand Down