Skip to content

Commit e9d562f

Browse files
authored
ofMesh - newfaces push_back to insert a list (#7772)
#changelog #gl
1 parent bda1575 commit e9d562f

6 files changed

Lines changed: 53 additions & 49 deletions

File tree

libs/openFrameworks/3d/ofMesh.inl

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,9 +2137,9 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::icosphere(float radius, std::size_t iteration
21372137
ofMesh_<V,N,C,T> sphere;
21382138

21392139
/// Step 1 : Generate icosahedron
2140-
const float sqrt5 = sqrt(5.0f);
2140+
const float sqrt5 = std::sqrt(5.0f);
21412141
const float phi = (1.0f + sqrt5) * 0.5f;
2142-
const float invnorm = 1/sqrt(phi*phi+1);
2142+
const float invnorm = 1/std::sqrt(phi*phi+1);
21432143

21442144

21452145
// FIXME: addvertices XAXA
@@ -2156,7 +2156,7 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::icosphere(float radius, std::size_t iteration
21562156
sphere.addVertex(invnorm * V(-1, -phi,0));//10
21572157
sphere.addVertex(invnorm * V( 1, -phi,0));//11
21582158

2159-
ofIndexType firstFaces[] = {
2159+
ofIndexType firstFaces[] = {
21602160
0,1,2,
21612161
0,3,1,
21622162
0,4,5,
@@ -2198,29 +2198,33 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::icosphere(float radius, std::size_t iteration
21982198
auto i1 = faces[i*3];
21992199
auto i2 = faces[i*3+1];
22002200
auto i3 = faces[i*3+2];
2201-
auto i12 = vertices.size();
2202-
auto i23 = i12+1;
2203-
auto i13 = i12+2;
2201+
auto i12 = static_cast<ofIndexType>(vertices.size());
2202+
auto i23 = static_cast<ofIndexType>(i12 + 1);
2203+
auto i13 = static_cast<ofIndexType>(i12 + 2);
22042204
auto v1 = vertices[i1];
22052205
auto v2 = vertices[i2];
22062206
auto v3 = vertices[i3];
22072207
//make 1 vertice at the center of each edge and project it onto the sphere
2208-
vertices.push_back(glm::normalize(toGlm(v1+v2)));
2209-
vertices.push_back(glm::normalize(toGlm(v2+v3)));
2210-
vertices.push_back(glm::normalize(toGlm(v1+v3)));
2208+
vertices.insert(vertices.end(), {
2209+
glm::normalize(toGlm(v1+v2)),
2210+
glm::normalize(toGlm(v2+v3)),
2211+
glm::normalize(toGlm(v1+v3)),
2212+
});
22112213
//now recreate indices
2212-
newFaces.push_back(i1);
2213-
newFaces.push_back(i12);
2214-
newFaces.push_back(i13);
2215-
newFaces.push_back(i2);
2216-
newFaces.push_back(i23);
2217-
newFaces.push_back(i12);
2218-
newFaces.push_back(i3);
2219-
newFaces.push_back(i13);
2220-
newFaces.push_back(i23);
2221-
newFaces.push_back(i12);
2222-
newFaces.push_back(i23);
2223-
newFaces.push_back(i13);
2214+
newFaces.insert(newFaces.end(), {
2215+
i1,
2216+
i12,
2217+
i13,
2218+
i2,
2219+
i23,
2220+
i12,
2221+
i3,
2222+
i13,
2223+
i23,
2224+
i12,
2225+
i23,
2226+
i13
2227+
});
22242228
}
22252229
faces.swap(newFaces);
22262230
}

libs/openFrameworks/math/ofMath.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ float ofMap(float value, float inputMin, float inputMax, float outputMin, float
8686

8787
//--------------------------------------------------
8888
float ofDist(float x1, float y1, float x2, float y2) {
89-
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
89+
return std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
9090
}
9191

9292
//--------------------------------------------------
9393
float ofDist(float x1, float y1, float z1, float x2, float y2, float z2) {
94-
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
94+
return std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
9595
}
9696

9797
//--------------------------------------------------

libs/openFrameworks/math/ofMatrix4x4.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ ofQuaternion ofMatrix4x4::getRotate() const
220220
QZ = tq[3];
221221
}
222222

223-
s = sqrt(0.25/tq[j]);
223+
s = std::sqrt(0.25f/tq[j]);
224224
QW *= s;
225225
QX *= s;
226226
QY *= s;
@@ -239,10 +239,10 @@ ofQuaternion ofMatrix4x4::getRotate() const
239239
ofQuaternion q;
240240

241241
// From http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
242-
QW = 0.5 * sqrt( osg::maximum( 0.0, 1.0 + _mat[0][0] + _mat[1][1] + _mat[2][2] ) );
243-
QX = 0.5 * sqrt( osg::maximum( 0.0, 1.0 + _mat[0][0] - _mat[1][1] - _mat[2][2] ) );
244-
QY = 0.5 * sqrt( osg::maximum( 0.0, 1.0 - _mat[0][0] + _mat[1][1] - _mat[2][2] ) );
245-
QZ = 0.5 * sqrt( osg::maximum( 0.0, 1.0 - _mat[0][0] - _mat[1][1] + _mat[2][2] ) );
242+
QW = 0.5 * std::sqrt( osg::maximum( 0.0, 1.0 + _mat[0][0] + _mat[1][1] + _mat[2][2] ) );
243+
QX = 0.5 * std::sqrt( osg::maximum( 0.0, 1.0 + _mat[0][0] - _mat[1][1] - _mat[2][2] ) );
244+
QY = 0.5 * std::sqrt( osg::maximum( 0.0, 1.0 - _mat[0][0] + _mat[1][1] - _mat[2][2] ) );
245+
QZ = 0.5 * std::sqrt( osg::maximum( 0.0, 1.0 - _mat[0][0] - _mat[1][1] + _mat[2][2] ) );
246246

247247
#if 0
248248
// Robert Osfield, June 7th 2007, arggg this new implementation produces many many errors, so have to revert to sign(..) orignal below.
@@ -516,7 +516,7 @@ void ofMatrix4x4::makeOrthoNormalOf(const ofMatrix4x4& rhs)
516516

517517
if(!equivalent((double)x_colMag, 1.0) && !equivalent((double)x_colMag, 0.0))
518518
{
519-
x_colMag = sqrt(x_colMag);
519+
x_colMag = std::sqrt(x_colMag);
520520
_mat[0][0] = rhs._mat[0][0] / x_colMag;
521521
_mat[1][0] = rhs._mat[1][0] / x_colMag;
522522
_mat[2][0] = rhs._mat[2][0] / x_colMag;
@@ -530,7 +530,7 @@ void ofMatrix4x4::makeOrthoNormalOf(const ofMatrix4x4& rhs)
530530

531531
if(!equivalent((double)y_colMag, 1.0) && !equivalent((double)y_colMag, 0.0))
532532
{
533-
y_colMag = sqrt(y_colMag);
533+
y_colMag = std::sqrt(y_colMag);
534534
_mat[0][1] = rhs._mat[0][1] / y_colMag;
535535
_mat[1][1] = rhs._mat[1][1] / y_colMag;
536536
_mat[2][1] = rhs._mat[2][1] / y_colMag;
@@ -544,7 +544,7 @@ void ofMatrix4x4::makeOrthoNormalOf(const ofMatrix4x4& rhs)
544544

545545
if(!equivalent((double)z_colMag, 1.0) && !equivalent((double)z_colMag, 0.0))
546546
{
547-
z_colMag = sqrt(z_colMag);
547+
z_colMag = std::sqrt(z_colMag);
548548
_mat[0][2] = rhs._mat[0][2] / z_colMag;
549549
_mat[1][2] = rhs._mat[1][2] / z_colMag;
550550
_mat[2][2] = rhs._mat[2][2] / z_colMag;
@@ -1056,10 +1056,10 @@ void adjoint_transpose(_HMatrix M, _HMatrix MadjT)
10561056
/** Setup u for Household reflection to zero all v components but first **/
10571057
void make_reflector(double *v, double *u)
10581058
{
1059-
double s = sqrt(vdot(v, v));
1059+
double s = std::sqrt(vdot(v, v));
10601060
u[0] = v[0]; u[1] = v[1];
10611061
u[2] = v[2] + ((v[2]<0.0) ? -s : s);
1062-
s = sqrt(2.0/vdot(u, u));
1062+
s = std::sqrt(2.0/vdot(u, u));
10631063
u[0] = u[0]*s; u[1] = u[1]*s; u[2] = u[2]*s;
10641064
}
10651065

@@ -1116,10 +1116,10 @@ void do_rank2(_HMatrix M, _HMatrix MadjT, _HMatrix Q)
11161116
make_reflector(v2, v2); reflect_rows(M, v2);
11171117
w = M[0][0]; x = M[0][1]; y = M[1][0]; z = M[1][1];
11181118
if (w*z>x*y) {
1119-
c = z+w; s = y-x; d = sqrt(c*c+s*s); c = c/d; s = s/d;
1119+
c = z+w; s = y-x; d = std::sqrt(c*c+s*s); c = c/d; s = s/d;
11201120
Q[0][0] = Q[1][1] = c; Q[0][1] = -(Q[1][0] = s);
11211121
} else {
1122-
c = z-w; s = y+x; d = sqrt(c*c+s*s); c = c/d; s = s/d;
1122+
c = z-w; s = y+x; d = std::sqrt(c*c+s*s); c = c/d; s = s/d;
11231123
Q[0][0] = -(Q[1][1] = c); Q[0][1] = Q[1][0] = s;
11241124
}
11251125
Q[0][2] = Q[2][0] = Q[1][2] = Q[2][1] = 0.0; Q[2][2] = 1.0;
@@ -1155,7 +1155,7 @@ ofQuaternion quatFromMatrix(_HMatrix mat)
11551155
tr = mat[X][X] + mat[Y][Y]+ mat[Z][Z];
11561156
if (tr >= 0.0)
11571157
{
1158-
s = sqrt(tr + mat[W][W]);
1158+
s = std::sqrt(tr + mat[W][W]);
11591159
qu.w() = s*0.5;
11601160
s = 0.5 / s;
11611161
qu.x() = (mat[Z][Y] - mat[Y][Z]) * s;
@@ -1219,7 +1219,7 @@ double polarDecomp( _HMatrix M, _HMatrix Q, _HMatrix S)
12191219
MadjT_one = norm_one(MadjTk);
12201220
MadjT_inf = norm_inf(MadjTk);
12211221

1222-
gamma = sqrt(sqrt((MadjT_one*MadjT_inf)/(M_one*M_inf))/std::abs(det));
1222+
gamma = std::sqrt(std::sqrt((MadjT_one*MadjT_inf)/(M_one*M_inf))/std::abs(det));
12231223
g1 = gamma*0.5;
12241224
g2 = 0.5/(gamma*det);
12251225
matrixCopy(Ek,=,Mk,3);
@@ -1392,7 +1392,7 @@ ofQuaternion snuggle(ofQuaternion q, HVect *k)
13921392
}
13931393

13941394
qp = Qt_Mul(q, p);
1395-
t = sqrt(mag[win]+0.5);
1395+
t = std::sqrt(mag[win]+0.5);
13961396
p = Qt_Mul(p, Qt_(0.0,0.0,-qp.z()/t,qp.w()/t));
13971397
p = Qt_Mul(qtoz, Qt_Conj(p));
13981398
}

libs/openFrameworks/math/ofQuaternion.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void ofQuaternion::makeRotate( const ofVec3f& from, const ofVec3f& to ) {
9393
float fromLen;
9494
// normalize only when necessary, epsilon test
9595
if ((fromLen2 < 1.0 - 1e-7) || (fromLen2 > 1.0 + 1e-7)) {
96-
fromLen = sqrt(fromLen2);
96+
fromLen = std::sqrt(fromLen2);
9797
sourceVector /= fromLen;
9898
} else fromLen = 1.0;
9999

@@ -104,7 +104,7 @@ void ofQuaternion::makeRotate( const ofVec3f& from, const ofVec3f& to ) {
104104
// re-use fromLen for case of mapping 2 vectors of the same length
105105
if ((toLen2 > fromLen2 - 1e-7) && (toLen2 < fromLen2 + 1e-7)) {
106106
toLen = fromLen;
107-
} else toLen = sqrt(toLen2);
107+
} else toLen = std::sqrt(toLen2);
108108
targetVector /= toLen;
109109
}
110110

@@ -121,19 +121,19 @@ void ofQuaternion::makeRotate( const ofVec3f& from, const ofVec3f& to ) {
121121
// Then use it as quaternion axis with pi angle
122122
// Trick is to realize one value at least is >0.6 for a normalized vector.
123123
if (std::abs(sourceVector.x) < 0.6) {
124-
const double norm = sqrt(1.0 - sourceVector.x * sourceVector.x);
124+
const double norm = std::sqrt(1.0 - sourceVector.x * sourceVector.x);
125125
_v.x = 0.0;
126126
_v.y = sourceVector.z / norm;
127127
_v.z = -sourceVector.y / norm;
128128
_v.w = 0.0;
129129
} else if (std::abs(sourceVector.y) < 0.6) {
130-
const double norm = sqrt(1.0 - sourceVector.y * sourceVector.y);
130+
const double norm = std::sqrt(1.0 - sourceVector.y * sourceVector.y);
131131
_v.x = -sourceVector.z / norm;
132132
_v.y = 0.0;
133133
_v.z = sourceVector.x / norm;
134134
_v.w = 0.0;
135135
} else {
136-
const double norm = sqrt(1.0 - sourceVector.z * sourceVector.z);
136+
const double norm = std::sqrt(1.0 - sourceVector.z * sourceVector.z);
137137
_v.x = sourceVector.y / norm;
138138
_v.y = -sourceVector.x / norm;
139139
_v.z = 0.0;
@@ -144,7 +144,7 @@ void ofQuaternion::makeRotate( const ofVec3f& from, const ofVec3f& to ) {
144144
else {
145145
// Find the shortest angle quaternion that transforms normalized vectors
146146
// into one other. Formula is still valid when vectors are colinear
147-
const double s = sqrt(0.5 * dotProdPlus1);
147+
const double s = std::sqrt(0.5 * dotProdPlus1);
148148
const ofVec3f tmp = sourceVector.getCrossed(targetVector) / (2.0 * s);
149149
_v.x = tmp.x;
150150
_v.y = tmp.y;
@@ -217,7 +217,7 @@ void ofQuaternion::getRotate( float& angle, ofVec3f& vec ) const {
217217
// Won't give very meaningful results if the Quat is not associated
218218
// with a rotation!
219219
void ofQuaternion::getRotate( float& angle, float& x, float& y, float& z ) const {
220-
float sinhalfangle = sqrt( _v.x * _v.x + _v.y * _v.y + _v.z * _v.z );
220+
float sinhalfangle = std::sqrt( _v.x * _v.x + _v.y * _v.y + _v.z * _v.z );
221221

222222
angle = 2.0 * std::atan2( sinhalfangle, _v.w );
223223
if (sinhalfangle) {

libs/openFrameworks/math/ofQuaternion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ const ofQuaternion ofQuaternion::operator -() const {
456456

457457
//----------------------------------------
458458
float ofQuaternion::length() const {
459-
return sqrt(_v.x*_v.x + _v.y*_v.y + _v.z*_v.z + _v.w*_v.w);
459+
return std::sqrt(_v.x*_v.x + _v.y*_v.y + _v.z*_v.z + _v.w*_v.w);
460460
}
461461

462462

@@ -493,7 +493,7 @@ ofVec3f ofQuaternion::operator*(const ofVec3f& v) const {
493493

494494
void ofQuaternion::normalize(){
495495
float len = _v.w*_v.w + _v.x*_v.x + _v.y*_v.y + _v.z*_v.z;
496-
float factor = 1.0f / sqrt(len);
496+
float factor = 1.0f / std::sqrt(len);
497497
_v.x *= factor;
498498
_v.y *= factor;
499499
_v.z *= factor;

libs/openFrameworks/sound/ofSoundBuffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ float ofSoundBuffer::getRMSAmplitude() const {
540540
for(size_t i = 0; i < buffer.size(); i++){
541541
acc += buffer[i] * buffer[i];
542542
}
543-
return sqrt(acc / (double)buffer.size());
543+
return std::sqrt(acc / (double)buffer.size());
544544
}
545545

546546
float ofSoundBuffer::getRMSAmplitudeChannel(std::size_t channel) const {
@@ -553,7 +553,7 @@ float ofSoundBuffer::getRMSAmplitudeChannel(std::size_t channel) const {
553553
float sample = getSample(i, channel);
554554
acc += sample * sample;
555555
}
556-
return sqrt(acc / (double)getNumFrames());
556+
return std::sqrt(acc / (double)getNumFrames());
557557
}
558558

559559
void ofSoundBuffer::normalize(float level){

0 commit comments

Comments
 (0)