Skip to content

Commit

Permalink
Pointクラスに剰余演算子「%」と「%=」を追加 (#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozone010 authored Aug 17, 2023
1 parent 5694668 commit 499aae9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Siv3D/include/Siv3D/Point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ namespace s3d
[[nodiscard]]
constexpr Point operator /(Point p) const noexcept;

[[nodiscard]]
constexpr Point operator %(int32 s) const noexcept;

[[nodiscard]]
constexpr Point operator %(Point p) const noexcept;

template <class Type>
[[nodiscard]]
constexpr Vector2D<Type> operator /(Vector2D<Type> v) const noexcept;
Expand All @@ -151,6 +157,8 @@ namespace s3d

constexpr Point& operator /=(int32 s) noexcept;

constexpr Point& operator %=(int32 s) noexcept;

[[nodiscard]]
friend constexpr bool operator ==(Point lhs, Point rhs) noexcept
{
Expand Down
17 changes: 17 additions & 0 deletions Siv3D/include/Siv3D/detail/Point.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ namespace s3d
return{ x / p.x, y / p.y };
}

inline constexpr Point Point::operator %(const int32 s) const noexcept
{
return{ x % s, y % s };
}

inline constexpr Point Point::operator %(const Point p) const noexcept
{
return{ x % p.x, y % p.y };
}

template <class Type>
inline constexpr Vector2D<Type> Point::operator /(const Vector2D<Type> v) const noexcept
{
Expand Down Expand Up @@ -209,6 +219,13 @@ namespace s3d
return *this;
}

inline constexpr Point& Point::operator %=(const int32 s) noexcept
{
assert(s != 0);
x %= s; y %= s;
return *this;
}

inline constexpr bool Point::isZero() const noexcept
{
return ((x == 0) && (y == 0));
Expand Down

0 comments on commit 499aae9

Please sign in to comment.