VM2D 1.14
Vortex methods for 2D flows simulation
Loading...
Searching...
No Matches
numvector.h
Go to the documentation of this file.
1/*--------------------------------*- VM2D -*-----------------*---------------*\
2| ## ## ## ## #### ##### | | Version 1.14 |
3| ## ## ### ### ## ## ## ## | VM2D: Vortex Method | 2026/03/06 |
4| ## ## ## # ## ## ## ## | for 2D Flow Simulation *----------------*
5| #### ## ## ## ## ## | Open Source Code |
6| ## ## ## ###### ##### | https://www.github.com/vortexmethods/VM2D |
7| |
8| Copyright (C) 2017-2026 I. Marchevsky, K. Sokol, E. Ryatina, A. Kolganova |
9*-----------------------------------------------------------------------------*
10| File name: numvector.h |
11| Info: Source code of VM2D |
12| |
13| This file is part of VM2D. |
14| VM2D is free software: you can redistribute it and/or modify it |
15| under the terms of the GNU General Public License as published by |
16| the Free Software Foundation, either version 3 of the License, or |
17| (at your option) any later version. |
18| |
19| VM2D is distributed in the hope that it will be useful, but WITHOUT |
20| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
21| FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
22| for more details. |
23| |
24| You should have received a copy of the GNU General Public License |
25| along with VM2D. If not, see <http://www.gnu.org/licenses/>. |
26\*---------------------------------------------------------------------------*/
27
28
40#ifndef NUMVECTOR_H_
41#define NUMVECTOR_H_
42
43/*
44#define STRINGIZE_HELPER(x) #x
45#define STRINGIZE(x) STRINGIZE_HELPER(x)
46#define WARNING(desc) message(__FILE__ "(" STRINGIZE(__LINE__) ") : warning: " #desc)
47*/
48
49/*
50#if defined(__GNUC__) || defined(__clang__)
51#define DEPRECATED __attribute__((deprecated))
52#elif defined(_MSC_VER)
53#define DEPRECATED __declspec(deprecated)
54#else
55#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
56#define DEPRECATED
57#endif
58*/
59
60#if defined(__CUDACC__)
61 #define HD __host__ __device__
62#else
63 #define HD
64#endif
65
66#define DEPRECATED
67
68#include <array>
69#include <cmath>
70#include <cstring>
71#include <initializer_list>
72#include <ostream>
73#include <set>
74#include <vector>
75
76namespace VMlib
77{
78
79 class Point2D;
80 class Point;
81
96 template<typename T, size_t n>
97 //class numvector : public std::array<T, n>
99 {
100 protected:
101 T data[n];
102
103 public:
104 HD T& operator[](size_t i)
105 {
106 return this->data[i];
107 }
108
109 HD const T& operator[](size_t i) const
110 {
111 return this->data[i];
112 }
113
114 HD size_t size() const
115 {
116 return n;
117 }
118
125 template <typename P>
126 HD auto operator& (const numvector<P, n>& y) const -> typename std::remove_const<decltype(this->data[0] * y[0])>::type
127 {
128 typename std::remove_const<decltype(this->data[0] * y[0])>::type res = 0;
129 for (size_t j = 0; j < n; ++j)
130 res += this->data[j] * y[j];
131 return res;
132 }//operator&(...)
133
134
142 template <typename P>
143 HD auto operator^(const numvector<P, 3>& y) const -> numvector<typename std::remove_const<decltype(this->data[1] * y[2])>::type, 3>
144 {
145 numvector<typename std::remove_const<decltype(this->data[1] * y[2])>::type, 3> vec;
146 vec[0] = this->data[1] * y[2] - this->data[2] * y[1];
147 vec[1] = this->data[2] * y[0] - this->data[0] * y[2];
148 vec[2] = this->data[0] * y[1] - this->data[1] * y[0];
149 return vec;
150 }//operator^(...)
151
152
160 template <typename P>
161 HD auto operator^ (const numvector<P, 2>& y) const -> typename std::remove_const<decltype(this->data[0] * y[1])>::type
162 {
163 return (this->data[0] * y[1] - this->data[1] * y[0]);
164 }//operator^(...)
165
166
174 template <typename P>
176 {
177 for (size_t i = 0; i < n; ++i)
178 this->data[i] *= c;
179 return *this;
180 }//operator*=(...)
181
182
190 template <typename P>
192 {
193 for (size_t i = 0; i < n; ++i)
194 this->data[i] /= c;
195 return *this;
196 }//operator/=(...)
197
198
206 template <typename P>
208 {
209 for (size_t i = 0; i < n; ++i)
210 this->data[i] += y[i];
211 return *this;
212 }//operator+=(...)
213
214
222 template <typename P>
224 {
225 for (size_t i = 0; i < n; ++i)
226 this->data[i] -= y[i];
227 return *this;
228 }//operator-=(...)
229
230
237 template <typename P>
238 HD auto operator+(const numvector<P, n>& y) const -> numvector<typename std::remove_const<decltype(this->data[0] + y[0])>::type, n>
239 {
240 numvector<typename std::remove_const<decltype(this->data[0] + y[0])>::type, n> res;
241 for (size_t i = 0; i < n; ++i)
242 res[i] = this->data[i] + y[i];
243 return res;
244 }//operator+(...)
245
246
253 template <typename P>
254 HD auto operator-(const numvector<P, n>& y) const -> numvector<typename std::remove_const<decltype(this->data[0] - y[0])>::type, n>
255 {
256 numvector<typename std::remove_const<decltype(this->data[0] - y[0])>::type, n> res;
257 for (size_t i = 0; i < n; ++i)
258 res[i] = this->data[i] - y[i];
259 return res;
260 }//operator-(...)
261
262
269 template <typename P>
270 HD auto operator*(const P c) const -> numvector<typename std::remove_const<decltype(this->data[0] * c)>::type, n>
271 {
272 numvector<typename std::remove_const<decltype(this->data[0] * c)>::type, n> res;
273 for (size_t i = 0; i < n; ++i)
274 res[i] = c * this->data[i];
275 return res;
276 }//operator*(...)
277
278
285 {
286 numvector<T, n> res;
287 for (size_t i = 0; i < n; ++i)
288 res[i] = -this->data[i];
289 return res;
290 }//operator-()
291
292
299 {
300 return *this;
301 }//operator+()
302
303
310 template <typename P>
311 HD bool operator==(const numvector<P, n>& y) const
312 {
313 for (size_t i = 0; i < n; ++i)
314 if (this->data[i] != y[i])
315 return false;
316 return true;
317 }//operator==(...)
318
319
326 template <typename P>
327 HD bool operator!=(const numvector<P, n>& y) const
328 {
329 return !(*this == y);
330 }//operator!=(...)
331
332
333
334
340 HD auto norm1() const -> typename std::remove_const<typename std::remove_reference<decltype(this->data[0])>::type>::type
341 {
342 typename std::remove_const<typename std::remove_reference<decltype(this->data[0])>::type>::type res = 0;
343 for (size_t i = 0; i < n; ++i)
344 res += abs(this->data[i]);
345 return res;
346 }//norm1()
347
348
354 HD auto norminf() const -> typename std::remove_const<typename std::remove_reference<decltype(this->data[0])>::type>::type
355 {
356 typename std::remove_const<typename std::remove_reference<decltype(this->data[0])>::type>::type res = 0;
357 for (size_t i = 0; i < n; ++i)
358 {
359 if (abs(this->data[i]) > res)
360 res = abs(this->data[i]);
361 }
362 return res;
363 }//norminf()
364
365
373 template <typename P = double>
374 HD P length() const
375 {
376 P res = *this & *this;
377 return sqrt(res);
378 }//length()
379
380
386 HD auto length2() const -> typename std::remove_const<typename std::remove_reference<decltype(this->data[0])>::type>::type
387 {
388 return (*this & *this);
389 }//length2()
390
391
401 template <typename P = double>
402 HD auto unit(P newlen = 1) const -> numvector<typename std::remove_const<decltype(this->data[0] * newlen)>::type, n>
403 {
404 auto ilen = static_cast<decltype(this->data[0] * newlen)>(newlen / std::max(this->length(), 1e-16));
405 return (*this * ilen);
406 }//unit(...)
407
408
409
418 template <typename P = double>
419 HD void normalize(P newlen = 1.0)
420 {
421 auto ilen = static_cast<decltype(this->data[0] * newlen)>(newlen / std::max(this->length(), 1e-16));
422 *this *= ilen;
423 }//normalize(...)
424
425
426
432 template <typename P>
433 HD size_t member(const P& s) const
434 {
435 for (size_t i = 0; i < n; ++i)
436 if (this->data[i] == s)
437 return i;
438
439 return static_cast<size_t>(-1);
440 }//member(...)
441
442
443
448 template <typename P>
449 operator std::set<P>() const
450 {
451 std::set<P> newset;
452 for (size_t i = 0; i < n; ++i)
453 newset.insert(this->data[i]);
454 return newset;
455 }//toSet()
456
457
462 template <typename P>
463 operator std::vector<P>() const
464 {
465 std::vector<P> vec;
466 vec.reserve(n);
467 for (size_t i = 0; i < n; ++i)
468 vec.push_back(this->data[i]);
469 return vec;
470 }
471
472
482 {
483 if (k > n)
484 throw;
485
486 if (k == n)
487 return *this;
488
489 numvector<T, n> res;
490
491 //for (size_t i = 0; i < n; ++i)
492 // res[i] = r[(i + k) % n];
493
494 for (size_t i = 0; i < n - k; ++i)
495 res[i] = this->data[i + k];
496 for (size_t i = n - k; i < n; ++i)
497 res[i] = this->data[i + k - n];
498 return res;
499 }//rotateLeft(...)
500
501
502
511 {
512 numvector<T, 2> res;
513 res[0] = -this->data[1];
514 res[1] = this->data[0];
515 return res;
516 }//kcross()
517
518
526 template <typename P = T>
528 {
529 for (size_t i = 0; i < n; ++i)
530 this->data[i] = val;
531 return *this;
532 }
533
534
542 template <typename P = T>
544 {
545 numvector<T, n> res;
546 res = ((*this & v) / (v & v))* v;
547
548 return res;
549 }
550
551
557 template<typename P>
558 HD auto dist2To(const numvector<P, n>& y) const -> typename std::remove_const<decltype(this->data[0] - y[0])>::type
559 {
560 return (*this - y).length2();
561 }//dist2To(...)
562
563
570 template<typename R = double, typename P>
572 {
573 R res = (*this - y) & (*this - y);
574 return sqrt(res);
575 }//distTo(...)
576
577
579 numvector() = default;
580
581
586 template <typename P>
587 explicit numvector(const P c)
588 {
589 for (size_t i = 0; i < n; ++i)
590 this->data[i] = c;
591 }//numvector(...)
592
593
594
601 {
602 //for (size_t i = 0; i < n; ++i)
603 // r[i] = vec[i];
604 memcpy(this->data, vec.data, n * sizeof(T));
605 }//numvector(...)
606
607
613 template <typename P>
615 {
616 for (size_t i = 0; i < n; ++i)
617 this->data[i] = vec[i];
618 }//numvector(...)
619
620
627 {
628 //for (size_t i = 0; i < n; ++i)
629 // r[i] = vec[i];
630 memcpy(this->data, vec.data, n * sizeof(T));
631 return *this;
632 }//numvector(...)
633
634
640 template <typename P>
642 {
643 for (size_t i = 0; i < n; ++i)
644 this->data[i] = vec[i];
645 }//numvector(...)
646
647
655 template <typename P>
656 numvector(const std::vector<P>& vec)
657 {
658 if (vec.size() != n)
659 throw;
660 for (size_t i = 0; i < n; ++i)
661 this->data[i] = vec[i];
662 }//numvector(...)
663
664
665#if !defined(__CUDACC__)
672 numvector(const std::initializer_list<T>& z)
673 {
674 if (z.size() != n)
675 throw;
676 for (size_t i = 0; i < n; ++i)
677 this->data[i] = *(z.begin() + i);
678 }//numvector(...)
679
680
681
688 template <typename P>
689 numvector(const std::initializer_list<P>& z)
690 {
691 if (z.size() != n)
692 throw;
693 for (size_t i = 0; i < n; ++i)
694 this->data[i] = *(z.begin() + i);
695 }//numvector(...)
696#endif
697
698
708 template <typename P, size_t p>
709 explicit numvector(const numvector<P, p>& vec, T add = 0)
710 {
711 size_t minPN = (p < n) ? p : n;
712 for (size_t i = 0; i < minPN; ++i)
713 this->data[i] = vec[i];
714 for (size_t i = minPN; i < n; ++i)
715 this->data[i] = add;
716 }//numvector(...)
717
718
719// ////////////////////////////////////////////////////////////////////////////
720// //// Далее deprecate-функции для ПОЛНОЙ СОВМЕСТИМОСТИ со старой версией ////
721// //// -------------------- ////
722// ////////////////////////////////////////////////////////////////////////////
723//
724// /// \brief Оператор присваивания всем компонентам вектора одного и того же числа
725// DEPRECATED numvector<T, n>& operator=(double c)
726// {
727// toZero(c);
728// return *this;
729// }//operator(...)
730
731
732// /// \brief Построение множества std::set на основе вектора
733// ///
734// /// \return множество типа std::set, состоящее из тех же элементов, что исходный вектор
735// DEPRECATED std::set<T> toSet() const
736// {
737// //(deprecate: use implicit type conversion)
738//
739// std::set<T> newset;
740// for (size_t i = 0; i < n; ++i)
741// newset.insert(this->data[i]);
742// return newset;
743// }//toSet()
744
745
746// /// \brief Построение вектора std::vector на основе вектора
747// ///
748// /// \return вектор типа std::vector, состоящий из тех же элементов, что исходный вектор
749// DEPRECATED std::vector<T> toVector() const
750// {
751// //(deprecate: use implicit type conversion)
752//
753// std::vector<T> vec;
754// vec.reserve(n);
755// for (size_t i = 0; i < n; ++i)
756// vec.push_back(this->data[i]);
757// return vec;
758// }
759
760 }; //class numvector
761
762// /// \todo Исследовать целесообразность наличия нешаблонного умножения
763// inline numvector<double, 3> operator*(double c, const numvector<double, 3>& x)
764// {
765// numvector<double, 3> res(x);
766// for (size_t i = 0; i < 3; ++i)
767// res[i] *= c;
768// return res;
769// }//operator*(...)
770
778 template<typename T, size_t n>
780 {
781 numvector<T, n> res(x);
782 for (size_t i = 0; i < n; ++i)
783 res[i] *= c;
784 return res;
785 }//operator*(...)
786
787
796 template<typename T, typename P, size_t n>
797 HD auto operator*(const P c, const numvector<T, n>& x) -> numvector<typename std::remove_const<decltype(x[0] * c)>::type, n>
798 {
799 numvector<typename std::remove_const<decltype(x[0] * c)>::type, n> res;
800 for (size_t i = 0; i < n; ++i)
801 res[i] = x[i] * c;
802 return res;
803 }//operator*(...)
804
805
806#if !defined(__CUDACC__)
818 template<typename T, typename P, typename R>
820 {
821 z = { x[1] * y[2] - x[2] * y[1], x[2] * y[0] - x[0] * y[2], x[0] * y[1] - x[1] * y[0] };
822 }//cross(...)
823#endif
824
825
834 template<typename T, typename P, size_t n>
835 HD auto dist2(const numvector<T, n>& x, const numvector<P, n>& y) -> typename std::remove_const<decltype(x[0] - y[0])>::type
836 {
837 numvector<typename std::remove_const<decltype(x[0] - y[0])>::type, n> p = x - y;
838 return p.length2();
839 }//dist2(...)
840
841
850 template<typename R = double, typename T, typename P, size_t n>
852 {
853 numvector<R, n> p = x - y;
854 return sqrt(p&p);
855 }//dist(...)
856
857
867 template<typename T, size_t n>
868 std::ostream& operator<< (std::ostream& str, const numvector<T, n>& x)
869 {
870 str << "{ ";
871 for (size_t j = 0; j < n - 1; ++j)
872 str << x[j] << ", ";
873 str << x[n - 1];
874 str << " }";
875 return str;
876 }//operator<<(...)
877
878
882
883
894 template<typename T, typename P, typename R, typename S, size_t n>
895 inline std::pair<numvector<T, n>, numvector<P, n>>& operator+=(std::pair<numvector<T, n>, numvector<P, n>>& a, const std::pair<numvector<R, n>, numvector<S, n>>& b)
896 {
897 a.first += b.first;
898 a.second += b.second;
899 return a;
900 }//operator+=(...)
901
902
913 template<typename T, typename P, typename R, typename S, size_t n>
914 inline auto operator+(const std::pair<numvector<T, n>, numvector<P, n>>& a, const std::pair<numvector<R, n>, numvector<S, n>>& b) -> \
915 std::pair<numvector<typename std::remove_const<decltype(a.first[0] + b.first[0])>::type, n>, numvector<typename std::remove_const<decltype(a.second[0] + b.second[0])>::type, n >>
916 {
917 std::pair<numvector<typename std::remove_const<decltype(a.first[0] + b.first[0])>::type, n>, numvector<typename std::remove_const<decltype(a.second[0] + b.second[0])>::type, n >> res;
918 res.first = a.first + b.first;
919 res.second = a.second + b.second;
920 return res;
921 }//operator+(...)
922
923
933 template<typename T, typename P, typename R, size_t n>
934 inline std::pair<numvector<T, n>, numvector<P, n>>& operator*=(std::pair<numvector<T, n>, numvector<P, n>>& a, R c)
935 {
936 a.first *= c;
937 a.second *= c;
938 return a;
939 }//operator*=(...)
940
941
951 template<typename T, typename P, typename R, size_t n>
952 inline auto operator*(R c, const std::pair<numvector<T, n>, numvector<P, n>>& a) -> \
953 std::pair<numvector<typename std::remove_const<decltype(c * a.first[0])>::type, n>, numvector<typename std::remove_const<decltype(c * a.second[0])>::type, n >>
954 {
955 std::pair<numvector<typename std::remove_const<decltype(c * a.first[0])>::type, n>, numvector<typename std::remove_const<decltype(c * a.second[0])>::type, n >> res;
956 res.first = c * a.first;
957 res.second = c * a.second;
958 return res;
959 }//operator*(...)
960
961
971 template<typename T, typename P, typename R, size_t n>
972 inline auto operator*(const std::pair<numvector<T, n>, numvector<P, n>>& a, R c) -> \
973 std::pair<numvector<typename std::remove_const<decltype(a.first[0] * c)>::type, n>, numvector<typename std::remove_const<decltype(a.second[0] * c)>::type, n >>
974 {
975 return c * a;
976 }//operator*(...)
977
978
989 template<typename T, typename P, size_t n>
990 std::ostream& operator<< (std::ostream& str, const std::pair<numvector<T, n>, numvector<P, n>>& x)
991 {
992 str << "{ " << x.first << ", " << x.second << " }";
993 return str;
994 }//operator<<
995
996
998 // Далее deprecate-функции для ПОЛНОЙ СОВМЕСТИМОСТИ со старой версией //
999 // -------------------- //
1001
1002// /// \brief Умножение квадратной матрицы на вектор (без приведения типов)
1003// ///
1004// /// \tparam T тип данных компонент матрицы и вектора
1005// /// \tparam n размерность матрицы и вектора
1006// /// \param[in] A константная ссылка на матрицу
1007// /// \param[in] x константная ссылка на вектор
1008// /// \return вектор результат умножения матрицы на вектор
1009// template<typename T, size_t n>
1010// DEPRECATED inline numvector<T, n> dot(const numvector<numvector<T, n>, n>& A, const numvector<T, n>& x)
1011// {
1012// //deprecate: use nummatrix.operator& instead of dot(numvector<numvector<>>, numvector<>)
1013//
1014// numvector<T, n> res;
1015// for (size_t i = 0; i < n; ++i)
1016// res[i] = A[i] & x;
1017// return res;
1018// }//dot(...)
1019
1020
1021// /// \brief Умножение вектора на квадратную матрицу (без приведения типов)
1022// ///
1023// /// \tparam T тип данных компонент матрицы и вектора
1024// /// \tparam n размерность матрицы и вектора
1025// /// \param[in] A константная ссылка на матрицу
1026// /// \param[in] x константная ссылка на вектор
1027// /// \return вектор результат умножения матрицы на вектор
1028// template<typename T, size_t n>
1029// DEPRECATED inline numvector<T, n> dot(const numvector<T, n>& x, const numvector<numvector<T, n>, n>& A)
1030// {
1031// //deprecate: use operator&(numvector<>, nummatrix<>) instead of dot(numvector<>, numvector<numvector<>>)
1032//
1033// numvector<T, n> res;
1034// for (size_t i = 0; i < n; ++i)
1035// {
1036// res[i] = 0.0;
1037// for (size_t j = 0; j < n; ++j)
1038// res[i] += x[j] * A[j][i];
1039// }
1040// return res;
1041// }//dot(...)
1042
1043
1044// /// \brief Умножение квадратной матрицы на вектор
1045// ///
1046// /// \tparam T тип данных вектора и матрицы
1047// /// \tparam n длина вектора и размерность матрицы
1048// /// \param[in] A константная ссылка на матрицу
1049// /// \param[in] x константная ссылка на вектор
1050// /// \return вектор --- результат умножения матрицы на вектор
1051// template<typename T, size_t n>
1052// DEPRECATED inline numvector<T, n> matDotVec(const numvector<numvector<T, n>, n>& A, const numvector<T, n>& x)
1053// {
1054// //deprecate: use nummatrix.operator& instead of matDotVec(numvector<numvector<>>, numvector<>)
1055//
1056// numvector<T, n> res;
1057// for (size_t i = 0; i < n; ++i)
1058// res[i] = A[i] * x;
1059// return res;
1060// }//dot(...)
1061
1062
1063// /// \brief Умножение вектора на вектор той же размерности внешним образом
1064// ///
1065// /// \tparam T тип данных компонент векторов
1066// /// \tparam n размерность векторов
1067// /// \param[in] x константная ссылка на первый вектор
1068// /// \param[in] y константная ссылка на второй вектор
1069// /// \return матрицу ранга 1, являющюуся внешним (кронекеровым) произведением двух векторов
1070// template<typename T, size_t n>
1071// DEPRECATED inline numvector<numvector<T, n>, n> KronProd(const numvector<T, n>& x, const numvector<T, n>& y)
1072// {
1073// //deprecate: use nummatrix.operator|(numvector<>, numvector<>) instead of KronProd(numvector<>, numvector<>)
1074// numvector<numvector<T, n>, n> res;
1075// for (size_t i = 0; i < n; ++i)
1076// for (size_t j = 0; j < n; ++j)
1077// res[i][j] = x[i] * y[j];
1078// return res;
1079// }//KronProd(...)
1080
1081
1082// /// \brief Транспонирование квадратной матрицы
1083// ///
1084// /// \tparam T тип данных компонент матрицы
1085// /// \tparam n размерность матрицы
1086// /// \return транспонированную матрицу
1087// template<typename T, size_t n>
1088// DEPRECATED inline numvector<numvector<T, n>, n> Transpose(const numvector<numvector<T, n>, n>& A)
1089// {
1090// //deprecate: use member class nummatrix.transpose() instead of Transpose(numvector<numvector>)
1091//
1092// numvector<numvector<T, n>, n> res;
1093// for (size_t i = 0; i < n; ++i)
1094// for (size_t j = 0; j < n; ++j)
1095// res[i][j] = A[j][i];
1096// return res;
1097// }
1098
1099
1110 template<typename T, typename P, size_t n>
1112 {
1113 //deprecate: use numvector.operator^ instead of cross3(numvector<>,numvector<>)
1114
1115 return (x[0] * y[1] - x[1] * y[0]);
1116 }//cross3(...)
1117
1118
1119// /// \brief Скалярное умножение двух векторов
1120// ///
1121// /// \param[in] x константная ссылка на первый множитель
1122// /// \param[in] y константная ссылка на второй множитель
1123// /// \return результат скалярного умножения
1124// DEPRECATED inline double operator*(const Point2D& x, const Point2D& y)
1125// {
1126// //deprecate: use numvector.operator& instead of operator*
1127//
1128// const numvector<double, 2> xx = *(reinterpret_cast<const numvector<double, 2>*>(&x));
1129// const numvector<double, 2> yy = *(reinterpret_cast<const numvector<double, 2>*>(&y));
1130// return (xx & yy);
1131// }//operator*(...)
1132
1133
1134// /// \brief Скалярное умножение двух векторов
1135// ///
1136// /// \param[in] x константная ссылка на первый множитель
1137// /// \param[in] y константная ссылка на второй множитель
1138// /// \return результат скалярного умножения
1139// DEPRECATED inline double operator*(const numvector<double, 2>& x, const Point2D& y)
1140// {
1141// //deprecate: use numvector.operator& instead of operator*
1142//
1143// const numvector<double, 2> yy = *(reinterpret_cast<const numvector<double, 2>*>(&y));
1144// return (x & yy);
1145// }//operator*(...)
1146
1147
1148// /// \brief Скалярное умножение двух векторов
1149// ///
1150// /// \param[in] x константная ссылка на первый множитель
1151// /// \param[in] y константная ссылка на второй множитель
1152// /// \return результат скалярного умножения
1153// DEPRECATED inline double operator*(const Point2D& x, const numvector<double, 2>& y)
1154// {
1155// //deprecate: use numvector.operator& instead of operator*
1156//
1157// const numvector<double, 2> xx = *(reinterpret_cast<const numvector<double, 2>*>(&x));
1158// return (xx & y);
1159// }//operator*(...)
1160
1161
1162// /// \brief Скалярное умножение двух векторов
1163// ///
1164// /// \param[in] x константная ссылка на первый множитель
1165// /// \param[in] y константная ссылка на второй множитель
1166// /// \return результат скалярного умножения
1167// DEPRECATED inline double operator*(const Point& x, const Point& y)
1168// {
1169// //deprecate: use numvector.operator& instead of operator*
1170//
1171// const numvector<double, 2> xx = *(reinterpret_cast<const numvector<double, 2>*>(&x));
1172// const numvector<double, 2> yy = *(reinterpret_cast<const numvector<double, 2>*>(&y));
1173// return (xx & yy);
1174// }//operator*(...)
1175
1176
1177// /// \brief Скалярное умножение двух векторов
1178// ///
1179// /// \param[in] x константная ссылка на первый множитель
1180// /// \param[in] y константная ссылка на второй множитель
1181// /// \return результат скалярного умножения
1182// DEPRECATED inline double operator*(const numvector<double, 2>& x, const Point& y)
1183// {
1184// //deprecate: use numvector.operator& instead of operator*
1185//
1186// const numvector<double, 2> yy = *(reinterpret_cast<const numvector<double, 2>*>(&y));
1187// return (x & yy);
1188// }//operator*(...)
1189
1190
1191// /// \brief Скалярное умножение двух векторов
1192// ///
1193// /// \param[in] x константная ссылка на первый множитель
1194// /// \param[in] y константная ссылка на второй множитель
1195// /// \return результат скалярного умножения
1196// DEPRECATED inline double operator*(const Point& x, const numvector<double, 2>& y)
1197// {
1198// //deprecate: use numvector.operator& instead of operator*
1199//
1200// const numvector<double, 2> xx = *(reinterpret_cast<const numvector<double, 2>*>(&x));
1201// return (xx & y);
1202// }//operator*(...)
1203
1204
1205
1206
1207// /// \brief Скалярное умножение двух векторов
1208// ///
1209// /// \param[in] x константная ссылка на первый множитель
1210// /// \param[in] y константная ссылка на второй множитель
1211// /// \return результат скалярного умножения
1212// DEPRECATED inline double operator*(const numvector<double, 2>& x, const numvector<double, 2>& y)
1213// {
1214// //deprecate: use numvector.operator& instead of operator*
1215//
1216// return (x & y);
1217// }//operator*(...)
1218
1219
1220// /// \brief Скалярное умножение двух векторов
1221// ///
1222// /// \param[in] x константная ссылка на первый множитель
1223// /// \param[in] y константная ссылка на второй множитель
1224// /// \return результат скалярного умножения
1225// DEPRECATED inline double operator*(const numvector<double, 3>& x, const numvector<double, 3>& y)
1226// {
1227// //deprecate: use numvector.operator& instead of operator*
1228//
1229// return (x & y);
1230// }//operator*(...)
1231
1232}//namespace VMlib
1233
1234using VMlib::numvector;
1235using VMlib::dist2;
1236
1237#endif
Шаблонный класс, определяющий вектор фиксированной длины Фактически представляет собой массив,...
Definition numvector.h:99
const numvector< T, n > & operator+() const
Оператор "+" унарного плюса
Definition numvector.h:298
numvector< T, n > rotateLeft(size_t k) const
"Вращение" вектора на несколько позиций влево
Definition numvector.h:481
R distTo(const numvector< P, n > &y)
Вычисление расстояния между двумя точками
Definition numvector.h:571
auto operator*(const P c) const -> numvector< typename std::remove_const< decltype(this->data[0] *c)>::type, n >
Оператор "*" умножения вектора на число (вектор слева, число справа)
Definition numvector.h:270
const T & operator[](size_t i) const
Definition numvector.h:109
numvector< T, n > & operator-=(const numvector< P, n > &y)
Оператор "-=" вычитания другого вектора
Definition numvector.h:223
T & operator[](size_t i)
Definition numvector.h:104
numvector(const numvector< P, n > &vec)
Шаблонный конструктор копирования
Definition numvector.h:614
numvector(const P c)
Конструктор, инициализирующий весь вектор одной и той же константой
Definition numvector.h:587
numvector(const numvector< T, n > &vec)
Нешаблонный конструктор копирования
Definition numvector.h:600
numvector< T, n > proj(const numvector< P, n > &v)
Проекция вектора на вектор v.
Definition numvector.h:543
auto dist2To(const numvector< P, n > &y) const -> typename std::remove_const< decltype(this->data[0] - y[0])>::type
Вычисление квадрата расстояния до другой точки
Definition numvector.h:558
numvector(const std::vector< P > &vec)
Конструктор инициализации с помощью std::vector.
Definition numvector.h:656
numvector< T, 2 > kcross() const
Геометрический поворот двумерного вектора на 90 градусов
Definition numvector.h:510
numvector(const std::initializer_list< P > &z)
Шаблонный конструктор инициализации списком
Definition numvector.h:689
auto length2() const -> typename std::remove_const< typename std::remove_reference< decltype(this->data[0])>::type >::type
Вычисление квадрата нормы (длины) вектора
Definition numvector.h:386
auto operator&(const numvector< P, n > &y) const -> typename std::remove_const< decltype(this->data[0] *y[0])>::type
Оператор "&" скалярного умножения
Definition numvector.h:126
numvector< T, n > & operator+=(const numvector< P, n > &y)
Оператор "+=" прибавления другого вектора
Definition numvector.h:207
numvector< T, n > & toZero(P val=0)
Установка всех компонент вектора в константу (по умолчанию — нуль)
Definition numvector.h:527
numvector(const std::initializer_list< T > &z)
Нешаблонный конструктор инициализации списком
Definition numvector.h:672
numvector< T, n > operator-() const
Оператор "-" унарного минуса
Definition numvector.h:284
size_t member(const P &s) const
Проверка вхождения элемента в вектор
Definition numvector.h:433
size_t size() const
Definition numvector.h:114
auto operator+(const numvector< P, n > &y) const -> numvector< typename std::remove_const< decltype(this->data[0]+y[0])>::type, n >
Оператор "+" сложения двух векторов
Definition numvector.h:238
auto unit(P newlen=1) const -> numvector< typename std::remove_const< decltype(this->data[0] *newlen)>::type, n >
Вычисление орта вектора или вектора заданной длины, коллинеарного данному
Definition numvector.h:402
P length() const
Вычисление 2-нормы (длины) вектора
Definition numvector.h:374
numvector< T, n > & operator/=(P c)
Оператор "/=" деления вектора на действительное число
Definition numvector.h:191
auto norminf() const -> typename std::remove_const< typename std::remove_reference< decltype(this->data[0])>::type >::type
Вычисление inf-нормы вектора
Definition numvector.h:354
numvector(const numvector< P, p > &vec, T add=0)
Явный конструктор инициализации вектором другой размерности
Definition numvector.h:709
auto norm1() const -> typename std::remove_const< typename std::remove_reference< decltype(this->data[0])>::type >::type
Вычисление 1-нормы вектора
Definition numvector.h:340
numvector< T, n > & operator=(const numvector< T, n > &vec)
Нешаблонный оператор копирования
Definition numvector.h:626
numvector< T, n > operator=(const numvector< P, n > &vec)
Шаблонный оператор копирования
Definition numvector.h:641
numvector()=default
Пустой конструктор
auto operator^(const numvector< P, 3 > &y) const -> numvector< typename std::remove_const< decltype(this->data[1] *y[2])>::type, 3 >
Оператор "^" векторного произведения
Definition numvector.h:143
void normalize(P newlen=1.0)
Нормирование вектора на заданную длину
Definition numvector.h:419
auto operator-(const numvector< P, n > &y) const -> numvector< typename std::remove_const< decltype(this->data[0] - y[0])>::type, n >
Оператор "-" вычитания двух векторов
Definition numvector.h:254
bool operator==(const numvector< P, n > &y) const
Оператор "==" логического равенства
Definition numvector.h:311
bool operator!=(const numvector< P, n > &y) const
Перегрузка оператора "!=" логического неравенства
Definition numvector.h:327
numvector< T, n > & operator*=(P c)
Оператор "*=" домножения вектора на действительное число
Definition numvector.h:175
numvector< T, n > operator*(double c, const numvector< T, n > &x)
Оператор "*" умножения вектора на число (число слева, вектор справа)
Definition numvector.h:779
std::pair< numvector< T, n >, numvector< P, n > > & operator*=(std::pair< numvector< T, n >, numvector< P, n > > &a, R c)
Оператор домножения "*=" пары векторов на число (пара слева, число справа)
Definition numvector.h:934
void cross(const numvector< T, 3 > &x, const numvector< P, 3 > &y, numvector< R, 3 > &z)
Быстрое вычисление векторного произведения
Definition numvector.h:819
R dist(const numvector< T, n > &x, const numvector< P, n > &y)
Вычисление расстояния между двумя точками
Definition numvector.h:851
auto operator+(const std::pair< numvector< T, n >, numvector< P, n > > &a, const std::pair< numvector< R, n >, numvector< S, n > > &b) -> std::pair< numvector< typename std::remove_const< decltype(a.first[0]+b.first[0])>::type, n >, numvector< typename std::remove_const< decltype(a.second[0]+b.second[0])>::type, n > >
Оператор сложения "+" для пар векторов
Definition numvector.h:914
std::pair< numvector< T, n >, numvector< P, n > > & operator+=(std::pair< numvector< T, n >, numvector< P, n > > &a, const std::pair< numvector< R, n >, numvector< S, n > > &b)
Оператор прибавления "+=" для пар векторов
Definition numvector.h:895
double cross3(const numvector< T, n > &x, const numvector< P, n > &y)
Вычисление третьей компоненты векторного произведения
Definition numvector.h:1111
auto dist2(const numvector< T, n > &x, const numvector< P, n > &y) -> typename std::remove_const< decltype(x[0] - y[0])>::type
Вычисление квадрата расстояния между двумя точками
Definition numvector.h:835
std::ostream & operator<<(std::ostream &_stream, const std::vector< T > &_vec)
Переопределение оператора "<<" для вывода в поток вектора std::vector.
Definition defs.h:292
#define DEPRECATED
Definition numvector.h:66
#define HD
Definition numvector.h:63