24#include "AstMath/MathOperator.hpp"
41template<
typename _Scalar,
size_t N>
45#define _AST_DEF_VECTOR_METHOD(Scalar) \
46 A_DEF_POD_ITERABLE(Scalar) \
47 Scalar operator()(size_t idx) const{return data()[idx];} \
48 Scalar& operator()(size_t idx) {return data()[idx];} \
49 Scalar& x() {return data()[0];} \
50 Scalar& y() {return data()[1];} \
51 Scalar& z() {return data()[2];} \
52 Scalar x() const {return data()[0];} \
53 Scalar y() const {return data()[1];} \
54 Scalar z() const {return data()[2];} \
58template<
typename _Scalar,
size_t N>
62 typedef _Scalar Scalar;
64 _AST_DEF_VECTOR_METHOD(Scalar);
70template<
typename _Scalar>
75 typedef _Scalar Scalar;
78 static Self Zero(){
return Self{0,0,0}; }
79 static Self UnitX() {
return Self{1,0,0}; }
80 static Self UnitY() {
return Self{0,1,0}; }
81 static Self UnitZ() {
return Self{0,0,1}; }
82 _Scalar at(
size_t idx)
const{
return data()[idx]; }
83 _Scalar& at(
size_t idx) {
return data()[idx]; }
86 double norm()
const{
return _ASTMATH
norm(*
this);}
88 Self cross(
const Self& other)
const{
return _ASTMATH cross(*
this, other);}
89 double dot(
const Self& other)
const{
return _ASTMATH
dot(*
this, other);}
90 void setZero(){x_ = y_ = z_ = 0;}
91 Self& operator*=(Scalar
s){
return *
this = _ASTMATH operator*(*
this,
s);}
92 Self operator*(Scalar
s)
const{
return _ASTMATH operator*(*
this,
s);}
93 Self operator-()
const{
return Self{-x_, -y_, -z_};}
94 Self operator-(
const Self& other)
const{
return _ASTMATH operator-(*
this, other);}
95 Self operator+(
const Self& other)
const{
return _ASTMATH operator+(*
this, other);}
96 Self& operator+=(
const Self& other){
return *
this = _ASTMATH operator+(*
this, other);}
97 std::string toString()
const;
98 _AST_DEF_VECTOR_METHOD(Scalar);
104template<
typename _Scalar>
112 void resize(
size_t size);
114 A_DEF_ITERABLE(_Scalar, data_, size_)
124template<
typename _Scalar>
131template<
typename _Scalar>
134 , data_((_Scalar*)malloc(sizeof(_Scalar)* size))
140template<
typename _Scalar>
141inline VectorX<_Scalar>::~VectorX()
147template<
typename _Scalar>
148inline void VectorX<_Scalar>::resize(
size_t size)
154 data_ = (_Scalar*)malloc(
sizeof(_Scalar) * size);
159template <
typename _Scalar>
160inline void VectorX<_Scalar>::setZero()
163 memset(data_, 0,
sizeof(_Scalar) * size_);
166typedef VectorX<double> VectorXd;
174AST_DECL_TYPE_ALIAS(Vector3d)
175AST_DECL_TYPE_ALIAS(VectorXd)
VectorX()
inlines
定义 Vector.hpp:125
double norm(const double *vec, size_t N)
norm
定义 MathOperator.hpp:281
double dot(const Container1 &vec1, const Container2 &vec2)
dot
定义 MathOperator.hpp:153
auto normalized(const Vector &vec) -> typename std::enable_if<!std::is_pointer< Vector >::value, Vector >::type
normalized
定义 MathOperator.hpp:352
double normalize(double *vec, size_t N)
normalize
定义 MathOperator.hpp:306
double squaredNorm(const double *vec, size_t N)
squaredNorm
定义 MathOperator.hpp:245