Blender  V3.3
btReducedVector.cpp
Go to the documentation of this file.
1 //
2 // btReducedVector.cpp
3 // LinearMath
4 //
5 // Created by Xuchen Han on 4/4/20.
6 //
7 #include <stdio.h>
8 #include "btReducedVector.h"
9 #include <cmath>
10 
11 // returns the projection of this onto other
13 {
15  btScalar other_length2 = other.length2();
16  if (other_length2 < SIMD_EPSILON)
17  {
18  return ret;
19  }
20  return other*(this->dot(other))/other_length2;
21 }
22 
24 {
25  if (this->length2() < SIMD_EPSILON)
26  {
27  m_indices.clear();
28  m_vecs.clear();
29  return;
30  }
31  *this /= std::sqrt(this->length2());
32 }
33 
35 {
36  int sz = 5;
38  id1.push_back(1);
39  id1.push_back(3);
41  v1.push_back(btVector3(1,0,1));
42  v1.push_back(btVector3(3,1,5));
44  id2.push_back(2);
45  id2.push_back(3);
46  id2.push_back(5);
48  v2.push_back(btVector3(2,3,1));
49  v2.push_back(btVector3(3,4,9));
50  v2.push_back(btVector3(0,4,0));
52  id3.push_back(1);
53  id3.push_back(2);
54  id3.push_back(3);
55  id3.push_back(5);
57  v3.push_back(btVector3(1,0,1));
58  v3.push_back(btVector3(2,3,1));
59  v3.push_back(btVector3(6,5,14));
60  v3.push_back(btVector3(0,4,0));
61  btReducedVector rv1(sz, id1, v1);
62  btReducedVector rv2(sz, id2, v2);
63  btReducedVector ans(sz, id3, v3);
64  bool ret = ((ans == rv1+rv2) && (ans == rv2+rv1));
65  if (!ret)
66  printf("btReducedVector testAdd failed\n");
67  return ret;
68 }
69 
71 {
72  int sz = 5;
74  id1.push_back(1);
75  id1.push_back(3);
77  v1.push_back(btVector3(1,0,1));
78  v1.push_back(btVector3(3,1,5));
80  id2.push_back(2);
81  id2.push_back(3);
82  id2.push_back(5);
84  v2.push_back(btVector3(2,3,1));
85  v2.push_back(btVector3(3,4,9));
86  v2.push_back(btVector3(0,4,0));
88  id3.push_back(1);
89  id3.push_back(2);
90  id3.push_back(3);
91  id3.push_back(5);
93  v3.push_back(btVector3(-1,-0,-1));
94  v3.push_back(btVector3(2,3,1));
95  v3.push_back(btVector3(0,3,4));
96  v3.push_back(btVector3(0,4,0));
97  btReducedVector rv1(sz, id1, v1);
98  btReducedVector rv2(sz, id2, v2);
99  btReducedVector ans(sz, id3, v3);
100  bool ret = (ans == rv2-rv1);
101  if (!ret)
102  printf("btReducedVector testMinus failed\n");
103  return ret;
104 }
105 
107 {
108  int sz = 5;
110  id1.push_back(1);
111  id1.push_back(3);
113  v1.push_back(btVector3(1,0,1));
114  v1.push_back(btVector3(3,1,5));
116  id2.push_back(2);
117  id2.push_back(3);
118  id2.push_back(5);
120  v2.push_back(btVector3(2,3,1));
121  v2.push_back(btVector3(3,4,9));
122  v2.push_back(btVector3(0,4,0));
123  btReducedVector rv1(sz, id1, v1);
124  btReducedVector rv2(sz, id2, v2);
125  btScalar ans = 58;
126  bool ret = (ans == rv2.dot(rv1) && ans == rv1.dot(rv2));
127  ans = 14+16+9+16+81;
128  ret &= (ans==rv2.dot(rv2));
129 
130  if (!ret)
131  printf("btReducedVector testDot failed\n");
132  return ret;
133 }
134 
136 {
137  int sz = 5;
139  id1.push_back(1);
140  id1.push_back(3);
142  v1.push_back(btVector3(1,0,1));
143  v1.push_back(btVector3(3,1,5));
144  btScalar s = 2;
145  btReducedVector rv1(sz, id1, v1);
147  id2.push_back(1);
148  id2.push_back(3);
150  v2.push_back(btVector3(2,0,2));
151  v2.push_back(btVector3(6,2,10));
152  btReducedVector ans(sz, id2, v2);
153  bool ret = (ans == rv1*s);
154  if (!ret)
155  printf("btReducedVector testMultiply failed\n");
156  return ret;
157 }
158 
160 {
161  bool ans = testAdd() && testMinus() && testDot() && testMultiply();
162  if (ans)
163  {
164  printf("All tests passed\n");
165  }
166  else
167  {
168  printf("Tests failed\n");
169  }
170 }
sqrt(x)+1/max(0
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
ATTR_WARN_UNUSED_RESULT const BMVert * v2
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define SIMD_EPSILON
Definition: btScalar.h:543
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
SIMD_FORCE_INLINE void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0),...
SIMD_FORCE_INLINE void push_back(const T &_Val)
bool testAdd() const
bool testDot() const
bool testMinus() const
btScalar length2() const
btAlignedObjectArray< int > m_indices
btReducedVector proj(const btReducedVector &other) const
btAlignedObjectArray< btVector3 > m_vecs
btScalar dot(const btReducedVector &other) const
bool testMultiply() const
return ret