9 #ifndef UTIL_MATH_VECTOR2_H__ 10 #define UTIL_MATH_VECTOR2_H__ 13 #include <type_traits> 15 #include "base/integral_types.h" 28 template <
typename VType>
36 typedef typename std::conditional<std::is_integral<VType>::value,
37 double, VType>::type FloatType;
41 typedef VType BaseType;
45 Vector2(
const VType x,
const VType y);
53 template <
typename VType2>
56 static int Size() {
return 2; }
58 void Set(
const VType x,
const VType y);
59 const Self& operator=(
const Self &vb);
61 Self& operator+=(
const Self &vb);
63 Self& operator-=(
const Self &vb);
65 Self& operator*=(
const VType k);
67 Self& operator/=(
const VType k);
69 Self MulComponents(
const Self &vb)
const;
71 Self DivComponents(
const Self &vb)
const;
73 Self operator+(
const Self &vb)
const;
75 Self operator-(
const Self &vb)
const;
77 Self operator-()
const;
80 VType DotProd(
const Self &vb)
const;
82 Self operator*(
const VType k)
const;
84 Self operator/(
const VType k)
const;
87 VType CrossProd(
const Self &vb)
const;
89 VType& operator[](
const int b);
91 VType operator[](
const int b)
const;
93 void x(
const VType &v);
95 void y(
const VType &v);
101 const VType* Data()
const;
104 VType Norm2(
void)
const;
108 FloatType Norm(
void)
const;
110 FloatType Angle(
const Self &v)
const;
113 Self Normalize()
const;
117 bool operator==(
const Self &vb)
const;
118 bool operator!=(
const Self &vb)
const;
121 bool aequal(
const Self &vb, FloatType margin)
const;
125 bool operator<(
const Self &vb)
const;
126 bool operator>(
const Self &vb)
const;
127 bool operator<=(
const Self &vb)
const;
128 bool operator>=(
const Self &vb)
const;
165 template <
typename ScalarType,
typename VType>
168 template <
typename ScalarType,
typename VType>
171 template <
typename VType2>
174 template <
typename VType2>
177 template <
typename VType2>
178 std::ostream &operator <<(std::ostream &out,
187 #endif // UTIL_MATH_VECTOR2_H__