comp-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub luzhiled1333/comp-library

:heavy_check_mark: ベクトル (整数幾何)
(src/geometry/Z2/class/vector.hpp)

コンストラクタ

(1) Z2::Vector()
(2) Z2::Vector(Z x, Z y)
  1. Z2::Vector のデフォルトコンストラクタ。$(0, 0)$ が格納される。
  2. 整数型 Z に対するコンストラクタ。$(x, y)$ が格納される。

座標

(1) Z x() const
(2) Z y() const
  1. ベクトルの x 成分を返す。
  2. ベクトルの y 成分を返す。

各種演算

Z2::Vector<Z> u, v に対し以下が動作する。

+v
-v

u += v
u -= v

u + v
u - v

u == v
u != v

エイリアス

その他、std::vector< Vector<Z> > のエイリアスとして Vectors<Z> が定義されている。

Required by

Verified with

Code

#pragma once

#include <vector>

namespace luz::Z2 {

  template < typename Z >
  class Vector {

    Z x_, y_;

   public:
    Vector(): x_(0), y_(0) {}
    Vector(Z x, Z y): x_(x), y_(y) {}

    Z x() const {
      return x_;
    }

    Z y() const {
      return y_;
    }

    bool operator==(const Vector &v) const {
      return x_ == v.x_ and y_ == v.y_;
    }

    bool operator!=(const Vector &v) const {
      return x_ != v.x_ or y_ != v.y_;
    }

    Vector &operator+=(const Vector &v) {
      x_ += v.x_;
      y_ += v.y_;
      return *this;
    }
    Vector &operator-=(const Vector &v) {
      x_ -= v.x_;
      y_ -= v.y_;
      return *this;
    }

    Vector operator+(const Vector &v) const {
      return Vector(*this) += v;
    }
    Vector operator-(const Vector &v) const {
      return Vector(*this) -= v;
    }

    Vector operator+() const {
      return *this;
    }
    Vector operator-() const {
      return Vector() - *this;
    }
  };

  template < typename Z >
  using Vectors = std::vector< Vector< Z > >;

} // namespace luz::Z2
#line 2 "src/geometry/Z2/class/vector.hpp"

#include <vector>

namespace luz::Z2 {

  template < typename Z >
  class Vector {

    Z x_, y_;

   public:
    Vector(): x_(0), y_(0) {}
    Vector(Z x, Z y): x_(x), y_(y) {}

    Z x() const {
      return x_;
    }

    Z y() const {
      return y_;
    }

    bool operator==(const Vector &v) const {
      return x_ == v.x_ and y_ == v.y_;
    }

    bool operator!=(const Vector &v) const {
      return x_ != v.x_ or y_ != v.y_;
    }

    Vector &operator+=(const Vector &v) {
      x_ += v.x_;
      y_ += v.y_;
      return *this;
    }
    Vector &operator-=(const Vector &v) {
      x_ -= v.x_;
      y_ -= v.y_;
      return *this;
    }

    Vector operator+(const Vector &v) const {
      return Vector(*this) += v;
    }
    Vector operator-(const Vector &v) const {
      return Vector(*this) -= v;
    }

    Vector operator+() const {
      return *this;
    }
    Vector operator-() const {
      return Vector() - *this;
    }
  };

  template < typename Z >
  using Vectors = std::vector< Vector< Z > >;

} // namespace luz::Z2
Back to top page