QTrk
std_incl.h
Go to the documentation of this file.
1 #pragma once
2 
3 #define _CRT_SECURE_NO_WARNINGS
4 #include <crtdbg.h>
5 #include "memdbg.h"
6 #include <cstdint>
7 #include <string>
8 #include <deque>
9 #include <vector>
10 #include <algorithm>
11 #include <cstdio>
12 #include <stdexcept>
13 #include <cassert>
14 #include <cmath>
15 #include <cstdlib>
16 #include <cstddef>
17 #include <complex>
18 
19 #include "random_distr.h"
20 
21 #pragma pack(push, 4)
22 
23 template<typename T>
24 struct vector2 {
25  vector2() {x=y=0.0; }
26  template<typename Tx, typename Ty>
27  vector2(Tx X,Ty Y) { x=(T)X;y=(T)Y; }
28  T x,y;
29 
30  static vector2 random(vector2 center, T R)
31  {
32  T ang = rand_uniform<T>() * 2 * 3.141593;
33  T r = rand_uniform<T>() * R;
34 
35  return vector2(center.x + r*(T)cos(ang), center.y + r*(T)sin(ang));
36  }
37 };
38 
41 
42 template<typename T>
43 struct vector3 {
44  vector3() { x=y=z=0.0f; }
45  template<typename Tx, typename Ty, typename Tz>
46  vector3(Tx X,Ty Y,Tz Z) { x=(T)X; y=(T)Y; z=(T)Z; }
47  template<typename Tc>
48  vector3(const vector3<Tc>& o) : x(o.x),y(o.y),z(o.z) {}
49  T x,y,z;
50 
51  vector3 operator*(const vector3& o) const {
52  return vector3(x*o.x,y*o.y,z*o.z);
53  }
54  vector3 operator*(T a) const {
55  return vector3(x*a,y*a,z*a);
56  }
57  friend vector3 operator*(T a, const vector3& b) {
58  return b*a;
59  }
60  vector3 operator+(const vector3& o) const {
61  return vector3(x+o.x,y+o.y,z+o.z);
62  }
63  vector3& operator+=(const vector3& o) {
64  x+=o.x; y+=o.y; z+=o.z; return *this;
65  }
66  vector3& operator-=(const vector3& o) {
67  x-=o.x; y-=o.y; z-=o.z; return *this;
68  }
69  vector3 operator-(const vector3& o) const {
70  return vector3(x-o.x,y-o.y,z-o.z);
71  }
72  vector3 operator-(float a) const {
73  return vector3(x-a,y-a,z-a);
74  }
75  vector3 operator+(float a) const {
76  return vector3(x+a,y+a,z+a);
77  }
78  vector3 operator-() const {
79  return vector3(-x,-y,-z);
80  }
81  vector3& operator*=(const vector3& o) {
82  x*=o.x; y*=o.y; z*=o.z;
83  return *this;
84  }
86  x*=a; y*=a; z*=a;
87  return *this;
88  }
90  x/=a; y/=a; z/=a;
91  return *this;
92  }
94  return vector3(x/a,y/a,z/a);
95  }
96  T length() {
97  return sqrtf(x*x+y*y+z*z);
98  }
99  template<typename T>
100  friend vector3 operator/(T a, vector3<T> b) {
101  return vector3<T>(a/b.x,a/b.y,a/b.z);
102  }
103 
105  {
106  return vector2<T>(x,y);
107  }
108 
109 };
110 
111 template<typename T>
112 inline vector3<T> sqrt(const vector3<T>& a) { return vector3<T>(sqrt(a.x),sqrt(a.y),sqrt(a.z)); }
113 
116 
117 #pragma pack(pop)
118 
119 
120 #define _CRT_SECURE_NO_WARNINGS
121 
122 #ifdef _MSC_VER
123 #pragma warning(disable: 4244) // conversion from 'int' to 'float', possible loss of data
124 #endif
125 
126 
127 typedef unsigned int uint;
128 typedef unsigned short ushort;
129 typedef unsigned long ulong;
130 typedef unsigned char uchar;
131 
132 /*
133  * Portable definition for SNPRINTF, VSNPRINTF, STRCASECMP and STRNCASECMP
134  */
135 #ifdef _MSC_VER
136  #if _MSC_VER > 1310
137  #define SNPRINTF _snprintf_s
138  #define VSNPRINTF _vsnprintf_s
139  #else
140  #define SNPRINTF _snprintf
141  #define VSNPRINTF _vsnprintf
142  #endif
143  #define STRCASECMP _stricmp
144  #define STRNCASECMP _strnicmp
145  #define ALLOCA(size) _alloca(size) // allocates memory on stack
146 #else
147  #define STRCASECMP strcasecmp
148  #define STRNCASECMP strncasecmp
149  #define SNPRINTF snprintf
150  #define VSNPRINTF vsnprintf
151  #define ALLOCA(size) alloca(size)
152 #endif
153 #define ALLOCA_ARRAY(T, N) ((T*)ALLOCA(sizeof(T) * (N)))
154 
155 #include "dllmacros.h"
vector3 & operator-=(const vector3 &o)
Definition: std_incl.h:66
vector3 operator*(T a) const
Definition: std_incl.h:54
vector3 operator-() const
Definition: std_incl.h:78
vector3 & operator/=(T a)
Definition: std_incl.h:89
vector2()
Definition: std_incl.h:25
static vector2 random(vector2 center, T R)
Definition: std_incl.h:30
unsigned int uint
Definition: std_incl.h:127
vector3(Tx X, Ty Y, Tz Z)
Definition: std_incl.h:46
vector3 operator-(const vector3 &o) const
Definition: std_incl.h:69
vector3(const vector3< Tc > &o)
Definition: std_incl.h:48
unsigned short ushort
Definition: std_incl.h:128
vector2< float > vector2f
Definition: std_incl.h:39
vector2< T > xy()
Definition: std_incl.h:104
vector3< T > sqrt(const vector3< T > &a)
Definition: std_incl.h:112
vector3< double > vector3d
Definition: std_incl.h:115
friend vector3 operator/(T a, vector3< T > b)
Definition: std_incl.h:100
vector3 operator+(float a) const
Definition: std_incl.h:75
T length()
Definition: std_incl.h:96
vector2(Tx X, Ty Y)
Definition: std_incl.h:27
vector3 & operator+=(const vector3 &o)
Definition: std_incl.h:63
friend vector3 operator*(T a, const vector3 &b)
Definition: std_incl.h:57
vector3< float > vector3f
Definition: std_incl.h:114
vector3 & operator*=(const vector3 &o)
Definition: std_incl.h:81
vector3 operator*(const vector3 &o) const
Definition: std_incl.h:51
vector3 operator-(float a) const
Definition: std_incl.h:72
vector2< double > vector2d
Definition: std_incl.h:40
vector3()
Definition: std_incl.h:44
vector3 operator+(const vector3 &o) const
Definition: std_incl.h:60
vector3 & operator*=(T a)
Definition: std_incl.h:85
unsigned char uchar
Definition: std_incl.h:130
vector3 operator/(T a)
Definition: std_incl.h:93
unsigned long ulong
Definition: std_incl.h:129