2 次元整数座標のデータ型
ソースコード
主な機能
2 次元整数座標を扱うデータ型を提供する。
構造体テンプレート VecI2
テンプレート引数
template<class Int = long long, class Int2 = long long>
struct VecI2;
通常使用する整数型 Int
と、乗算結果のための大きい整数型 Int2
を設定できる。
コンストラクタ
VecI2(); // (1)
VecI2(std::pair<Int, Int> _p) // (2)
VecI2(Int _x, Int _y); // (3)
- (1) : (0,0) で初期化する。
- (2) : 座標を (x,y) のペアで与えて初期化する。
- (3) : 座標を与えて初期化する。
基本的な演算子
VecI2& operator+=(VecI2 r);
VecI2& operator-=(VecI2 r);
VecI2& operator*=(Int r);
VecI2 operator+(VecI2 r) const;
VecI2 operator-(VecI2 r) const;
VecI2 operator*(Int r) const;
VecI2 operator-() const;
加減算と定数倍。
内積
Int2 operator*(VecI2 r) const; // (1)
Int2 norm() const; // (2)
- (1)
this
とr
の内積を計算する。 - (2) x2+y2 の値を計算して返す。
行列式
Int2 operator^(VecI2 r);
this
を (x1,y1) 、 r
を (x2,y2) とするとき、 x1y2−x2y1 の値を計算して返す。
辞書順比較
static bool compareYX(VecI2 a, VecI2 b); // (1)
static bool compareXY(VecI2 a, VecI2 b); // (2)
bool operator<(VecI2 r) const; // (3)
- (1) (y,x) の辞書順で比較する。
- (2) (x,y) の辞書順で比較する。
- (3) (x,y) の辞書順で比較する。