Skip to content

Commit

Permalink
[共通] T::withElem(e) #1143
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Nov 18, 2023
1 parent e4d6a33 commit dc10e6d
Show file tree
Hide file tree
Showing 30 changed files with 431 additions and 9 deletions.
12 changes: 12 additions & 0 deletions Siv3D/include/Siv3D/Circular.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ namespace s3d
[[nodiscard]]
position_type operator -(position_type v) const noexcept;

/// @brief r 成分のみを変更した自身のコピーを返します。
/// @param _r r 成分
/// @return r 成分を変更したコピー
[[nodiscard]]
constexpr CircularBase withR(value_type _r) const noexcept;

/// @brief theta 成分のみを変更した自身のコピーを返します。
/// @param _theta theta 成分
/// @return theta 成分を変更したコピー
[[nodiscard]]
constexpr CircularBase withTheta(value_type _theta) const noexcept;

[[nodiscard]]
constexpr CircularBase rotated(value_type angle) const noexcept;

Expand Down
25 changes: 25 additions & 0 deletions Siv3D/include/Siv3D/Color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ namespace s3d
# endif
}

/// @brief r 成分のみを変更した自身のコピーを返します。
/// @param _r r 成分
/// @return r 成分を変更したコピー
[[nodiscard]]
constexpr Color withR(uint32 _r) const noexcept;

/// @brief g 成分のみを変更した自身のコピーを返します。
/// @param _g g 成分
/// @return g 成分を変更したコピー
[[nodiscard]]
constexpr Color withG(uint32 _g) const noexcept;

/// @brief b 成分のみを変更した自身のコピーを返します。
/// @param _b b 成分
/// @return b 成分を変更したコピー
[[nodiscard]]
constexpr Color withB(uint32 _b) const noexcept;

/// @brief a 成分のみを変更した自身のコピーを返します。
/// @param _a a 成分
/// @return a 成分を変更したコピー
[[nodiscard]]
constexpr Color withA(uint32 _a) const noexcept;

constexpr Color& setR(uint32 _r) noexcept;

constexpr Color& setG(uint32 _g) noexcept;
Expand All @@ -127,6 +151,7 @@ namespace s3d

constexpr Color& set(Color color) noexcept;

[[deprecated("use withA()")]]
constexpr Color withAlpha(uint32 _a) const noexcept;

[[nodiscard]]
Expand Down
25 changes: 25 additions & 0 deletions Siv3D/include/Siv3D/ColorF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@ namespace s3d
|| (lhs.a != rhs.a);
}

/// @brief r 成分のみを変更した自身のコピーを返します。
/// @param _r r 成分
/// @return r 成分を変更したコピー
[[nodiscard]]
constexpr ColorF withR(double _r) const noexcept;

/// @brief g 成分のみを変更した自身のコピーを返します。
/// @param _g g 成分
/// @return g 成分を変更したコピー
[[nodiscard]]
constexpr ColorF withG(double _g) const noexcept;

/// @brief b 成分のみを変更した自身のコピーを返します。
/// @param _b b 成分
/// @return b 成分を変更したコピー
[[nodiscard]]
constexpr ColorF withB(double _b) const noexcept;

/// @brief a 成分のみを変更した自身のコピーを返します。
/// @param _a a 成分
/// @return a 成分を変更したコピー
[[nodiscard]]
constexpr ColorF withA(double _a) const noexcept;

constexpr ColorF& setR(double _r) noexcept;

constexpr ColorF& setG(double _g) noexcept;
Expand All @@ -145,6 +169,7 @@ namespace s3d

constexpr ColorF& set(const ColorF& ColorF) noexcept;

[[deprecated("use withA()")]]
constexpr ColorF withAlpha(double _a) const noexcept;

[[nodiscard]]
Expand Down
25 changes: 25 additions & 0 deletions Siv3D/include/Siv3D/HSV.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@ namespace s3d
|| (lhs.a != rhs.a);
}

/// @brief h 成分のみを変更した自身のコピーを返します。
/// @param _h h 成分
/// @return h 成分を変更したコピー
[[nodiscard]]
constexpr HSV withH(double _h) const noexcept;

/// @brief s 成分のみを変更した自身のコピーを返します。
/// @param _s s 成分
/// @return s 成分を変更したコピー
[[nodiscard]]
constexpr HSV withS(double _s) const noexcept;

/// @brief v 成分のみを変更した自身のコピーを返します。
/// @param _v v 成分
/// @return v 成分を変更したコピー
[[nodiscard]]
constexpr HSV withV(double _v) const noexcept;

/// @brief a 成分のみを変更した自身のコピーを返します。
/// @param _a a 成分
/// @return a 成分を変更したコピー
[[nodiscard]]
constexpr HSV withA(double _a) const noexcept;

constexpr HSV& setH(double _h) noexcept;

constexpr HSV& setS(double _s) noexcept;
Expand All @@ -119,6 +143,7 @@ namespace s3d

constexpr HSV& set(const HSV& hsva) noexcept;

[[deprecated("use withA()")]]
constexpr HSV withAlpha(double _a) const noexcept;

[[nodiscard]]
Expand Down
25 changes: 25 additions & 0 deletions Siv3D/include/Siv3D/OffsetCircular.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ namespace s3d

constexpr OffsetCircularBase& operator -=(position_type v) noexcept;

/// @brief 中心座標のみを変更した自身のコピーを返します。
/// @param x 中心の X 座標
/// @param y 中心の Y 座標
/// @return 中心座標を変更したコピー
[[nodiscard]]
constexpr OffsetCircularBase withCenter(value_type x, value_type y) const noexcept;

/// @brief 中心座標のみを変更した自身のコピーを返します。
/// @param _center 中心座標
/// @return 中心座標を変更したコピー
[[nodiscard]]
constexpr OffsetCircularBase withCenter(position_type _center) const noexcept;

/// @brief r 成分のみを変更した自身のコピーを返します。
/// @param _r r 成分
/// @return r 成分を変更したコピー
[[nodiscard]]
constexpr OffsetCircularBase withR(value_type _r) const noexcept;

/// @brief theta 成分のみを変更した自身のコピーを返します。
/// @param _theta theta 成分
/// @return theta 成分を変更したコピー
[[nodiscard]]
constexpr OffsetCircularBase withTheta(value_type _theta) const noexcept;

[[nodiscard]]
constexpr OffsetCircularBase movedBy(value_type x, value_type y) const noexcept;

Expand Down
18 changes: 15 additions & 3 deletions Siv3D/include/Siv3D/Point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,24 @@ namespace s3d

constexpr void clear() noexcept;

constexpr Point& set(int32 _x, int32 _y) noexcept;
/// @brief x 成分のみを変更した自身のコピーを返します。
/// @param _x x 成分
/// @return x 成分を変更したコピー
[[nodiscard]]
constexpr Point withX(value_type _x) const noexcept;

/// @brief y 成分のみを変更した自身のコピーを返します。
/// @param _y y 成分
/// @return y 成分を変更したコピー
[[nodiscard]]
constexpr Point withY(value_type _y) const noexcept;

constexpr Point& set(value_type _x, value_type _y) noexcept;

constexpr Point& set(Point p) noexcept;

[[nodiscard]]
constexpr Point movedBy(int32 _x, int32 _y) const noexcept;
constexpr Point movedBy(value_type _x, value_type _y) const noexcept;

[[nodiscard]]
constexpr Point movedBy(Point p) const noexcept;
Expand All @@ -198,7 +210,7 @@ namespace s3d
[[nodiscard]]
constexpr Vector2D<Type> movedBy(Vector2D<Type> v) const noexcept;

constexpr Point& moveBy(int32 _x, int32 _y) noexcept;
constexpr Point& moveBy(value_type _x, value_type _y) noexcept;

constexpr Point& moveBy(Point p) noexcept;

Expand Down
12 changes: 12 additions & 0 deletions Siv3D/include/Siv3D/Vector2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ namespace s3d
/// @brief 各成分を 0 にセットします。
constexpr void clear() noexcept;

/// @brief x 成分のみを変更した自身のコピーを返します。
/// @param _x x 成分
/// @return x 成分を変更したコピー
[[nodiscard]]
constexpr Vector2D withX(value_type _x) const noexcept;

/// @brief y 成分のみを変更した自身のコピーを返します。
/// @param _y y 成分
/// @return y 成分を変更したコピー
[[nodiscard]]
constexpr Vector2D withY(value_type _y) const noexcept;

/// @brief 各成分を変更します。
/// @param _x 新しい X 成分
/// @param _y 新しい Y 成分
Expand Down
18 changes: 18 additions & 0 deletions Siv3D/include/Siv3D/Vector3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ namespace s3d
/// @brief 各成分を 0 にセットします。
constexpr void clear() noexcept;

/// @brief x 成分のみを変更した自身のコピーを返します。
/// @param _x x 成分
/// @return x 成分を変更したコピー
[[nodiscard]]
constexpr Vector3D withX(value_type _x) const noexcept;

/// @brief y 成分のみを変更した自身のコピーを返します。
/// @param _y y 成分
/// @return y 成分を変更したコピー
[[nodiscard]]
constexpr Vector3D withY(value_type _y) const noexcept;

/// @brief z 成分のみを変更した自身のコピーを返します。
/// @param _z z 成分
/// @return z 成分を変更したコピー
[[nodiscard]]
constexpr Vector3D withZ(value_type _z) const noexcept;

/// @brief 各成分を変更します。
/// @param _x 新しい X 成分
/// @param _y 新しい Y 成分
Expand Down
24 changes: 24 additions & 0 deletions Siv3D/include/Siv3D/Vector4D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,30 @@ namespace s3d

constexpr void clear() noexcept;

/// @brief x 成分のみを変更した自身のコピーを返します。
/// @param _x x 成分
/// @return x 成分を変更したコピー
[[nodiscard]]
constexpr Vector4D withX(value_type _x) const noexcept;

/// @brief y 成分のみを変更した自身のコピーを返します。
/// @param _y y 成分
/// @return y 成分を変更したコピー
[[nodiscard]]
constexpr Vector4D withY(value_type _y) const noexcept;

/// @brief z 成分のみを変更した自身のコピーを返します。
/// @param _z z 成分
/// @return z 成分を変更したコピー
[[nodiscard]]
constexpr Vector4D withZ(value_type _z) const noexcept;

/// @brief w 成分のみを変更した自身のコピーを返します。
/// @param _w w 成分
/// @return w 成分を変更したコピー
[[nodiscard]]
constexpr Vector4D withW(value_type _w) const noexcept;

constexpr Vector4D& set(const Vector2D<value_type>& xy, const Vector2D<value_type>& zw) noexcept;

constexpr Vector4D& set(const Vector2D<value_type>& xy, value_type _z, value_type _w) noexcept;
Expand Down
12 changes: 12 additions & 0 deletions Siv3D/include/Siv3D/detail/Circular.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ namespace s3d
return (toPosition() - v);
}

template <class Float, int32 Oclock>
inline constexpr CircularBase<Float, Oclock> CircularBase<Float, Oclock>::withR(const value_type _r) const noexcept
{
return{ _r, theta };
}

template <class Float, int32 Oclock>
inline constexpr CircularBase<Float, Oclock> CircularBase<Float, Oclock>::withTheta(const value_type _theta) const noexcept
{
return{ r, _theta };
}

template <class Float, int32 Oclock>
inline constexpr CircularBase<Float, Oclock> CircularBase<Float, Oclock>::rotated(const value_type angle) const noexcept
{
Expand Down
20 changes: 20 additions & 0 deletions Siv3D/include/Siv3D/detail/Color.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ namespace s3d
a };
}

inline constexpr Color Color::withR(const uint32 _r) const noexcept
{
return{ static_cast<uint8>(_r), g, b, a };
}

inline constexpr Color Color::withG(const uint32 _g) const noexcept
{
return{ r, static_cast<uint8>(_g), b, a };
}

inline constexpr Color Color::withB(const uint32 _b) const noexcept
{
return{ r, g, static_cast<uint8>(_b), a };
}

inline constexpr Color Color::withA(const uint32 _a) const noexcept
{
return{ r, g, b, static_cast<uint8>(_a) };
}

inline constexpr Color& Color::setR(const uint32 _r) noexcept
{
r = static_cast<uint8>(_r);
Expand Down
20 changes: 20 additions & 0 deletions Siv3D/include/Siv3D/detail/ColorF.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ namespace s3d
return *this;
}

inline constexpr ColorF ColorF::withR(const double _r) const noexcept
{
return{ _r, g, b, a };
}

inline constexpr ColorF ColorF::withG(const double _g) const noexcept
{
return{ r, _g, b, a };
}

inline constexpr ColorF ColorF::withB(const double _b) const noexcept
{
return{ r, g, _b, a };
}

inline constexpr ColorF ColorF::withA(const double _a) const noexcept
{
return{ r, g, b, _a };
}

inline constexpr ColorF& ColorF::setR(const double _r) noexcept
{
r = _r;
Expand Down
20 changes: 20 additions & 0 deletions Siv3D/include/Siv3D/detail/HSV.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ namespace s3d
return{ h - hsv.h, Clamp(s - hsv.s, 0.0, 1.0), Clamp(v - hsv.v, 0.0, 1.0), a };
}

inline constexpr HSV HSV::withH(const double _h) const noexcept
{
return{ _h, s, v, a };
}

inline constexpr HSV HSV::withS(const double _s) const noexcept
{
return{ h, _s, v, a };
}

inline constexpr HSV HSV::withV(const double _v) const noexcept
{
return{ h, s, _v, a };
}

inline constexpr HSV HSV::withA(const double _a) const noexcept
{
return{ h, s, v, _a };
}

inline constexpr HSV& HSV::setH(const double _h) noexcept
{
h = _h;
Expand Down
Loading

0 comments on commit dc10e6d

Please sign in to comment.