8#ifndef DESIGNLAB_MATH_VECTOR2_H_
9#define DESIGNLAB_MATH_VECTOR2_H_
33 constexpr Vector2(
float x_pos,
float y_pos) :
x(x_pos),
y(y_pos) {}
43 return{
x + other.
x,
y + other.
y };
48 return{
x - other.
x,
y - other.
y };
66 return !(*
this == other);
88 return x * other.x +
y * other.y;
98 return x * other.y -
y * other.x;
107 return (other - *
this).GetLength();
141 [[nodiscard]] std::string
ToString()
const;
160 return { s * v.
x, s * v.
y };
164std::basic_ostream<Char>&
operator <<(std::basic_ostream<Char>& os,
const Vector2& v)
172 std::basic_istream<Char>& is,
Vector2& v)
175 return is >> unused >> v.
x >> unused >> v.
y >> unused;
std::string FloatingPointNumToString(const T num, const int digit=kDigit, const int width=kWidth)
小数を文字列に変換する関数. C++ では C のフォーマットのように %3.3f とかで小数を文字列に変換できないため自作する.
constexpr bool IsEqual(const T num1, const T num2) noexcept
C++において,小数同士の計算は誤差が出てしまう. 誤差込みで値が等しいか調べる.
constexpr Quaternion operator*(float s, const Quaternion &q)
std::basic_istream< Char > & operator>>(std::basic_istream< Char > &is, EulerXYZ &r)
入力ストリーム
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &os, const EulerXYZ &r)
出力ストリーム.Csv形式で出力する.カンマ区切り.単位は [rad].
float GetDistanceFrom(const Vector2 &other) const noexcept
このベクトルと other の距離を返す.
std::string ToString() const
このベクトルを文字列にして返す. (x, y) の形式,小数点以下3桁まで.
constexpr Vector2 & operator=(const Vector2 &other)=default
constexpr bool IsZero() const noexcept
このベクトルが0ならば true.
constexpr Vector2 operator-() const
Vector2 & operator*=(float s)
constexpr Vector2 operator*(float s) const
constexpr Vector2 operator+() const
constexpr Vector2(Vector2 &&other) noexcept=default
constexpr float Dot(const Vector2 &other) const noexcept
自分・引数 の内積の結果を返す.
Vector2 GetNormalized() const
このベクトルを正規化したベクトルを返す.
constexpr bool operator==(const Vector2 &other) const
Vector2 & operator+=(const Vector2 &other)
constexpr float GetSquaredLength() const noexcept
このベクトルの長さの2乗を返す.
constexpr Vector2 operator/(float s) const
static constexpr Vector2 GetZeroVec() noexcept
零ベクトルを返す. 静的な関数なので Vector2::GetZeroVec() と呼ぶことができる.
constexpr float Cross(const Vector2 &other) const noexcept
自分×引数 の外積の結果を返す.
constexpr Vector2(float x_pos, float y_pos)
std::string ToCsvString() const
このベクトルをCSV形式の文字列にして返す. x, y, z の形式,小数点以下3桁まで.
float GetLength() const
このベクトルの長さを返す.
Vector2 & operator/=(float s)
void Normalize() noexcept
このベクトルを正規化する. 絶対値が0のベクトルの場合,そのまま0ベクトルになる.
constexpr Vector2(const Vector2 &other)=default
constexpr bool operator!=(const Vector2 &other) const
Vector2 & operator-=(const Vector2 &other)