Skip to content

Commit b734917

Browse files
authored
Substitute defines DEG_TO_RAD / RAD_TO_DEG with ofDegToRad / ofRadToDeg (#7413)
#changelog #math #internals
1 parent 2290da4 commit b734917

25 files changed

+134
-123
lines changed

addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ void ofxAssimpModelLoader::calculateDimensions(){
215215

216216
// optional normalized scaling
217217
normalizedScale = scene_max.x-scene_min.x;
218-
normalizedScale = MAX(scene_max.y - scene_min.y,normalizedScale);
219-
normalizedScale = MAX(scene_max.z - scene_min.z,normalizedScale);
218+
normalizedScale = std::max(double(scene_max.y - scene_min.y), normalizedScale);
219+
normalizedScale = std::max(double(scene_max.z - scene_min.z), normalizedScale);
220220
if (abs(normalizedScale) < std::numeric_limits<float>::epsilon()){
221221
ofLogWarning("ofxAssimpModelLoader") << "Error calculating normalized scale of scene" << std::endl;
222222
normalizedScale = 1.0;
@@ -823,25 +823,25 @@ void ofxAssimpModelLoader::getBoundingBoxForNode(const ofxAssimpMeshHelper & mes
823823
auto vertex = mesh.mesh->mVertices[i];
824824
auto tmp = mesh.matrix * glm::vec4(vertex.x,vertex.y,vertex.z,1.0f);
825825

826-
min->x = MIN(min->x,tmp.x);
827-
min->y = MIN(min->y,tmp.y);
828-
min->z = MIN(min->z,tmp.z);
826+
min->x = std::min(min->x,tmp.x);
827+
min->y = std::min(min->y,tmp.y);
828+
min->z = std::min(min->z,tmp.z);
829829

830-
max->x = MAX(max->x,tmp.x);
831-
max->y = MAX(max->y,tmp.y);
832-
max->z = MAX(max->z,tmp.z);
830+
max->x = std::max(max->x,tmp.x);
831+
max->y = std::max(max->y,tmp.y);
832+
max->z = std::max(max->z,tmp.z);
833833
}
834834
} else {
835835
for (auto & animPos: mesh.animatedPos){
836836
auto tmp = mesh.matrix * glm::vec4(animPos.x,animPos.y,animPos.z,1.0f);
837837

838-
min->x = MIN(min->x,tmp.x);
839-
min->y = MIN(min->y,tmp.y);
840-
min->z = MIN(min->z,tmp.z);
838+
min->x = std::min(min->x,tmp.x);
839+
min->y = std::min(min->y,tmp.y);
840+
min->z = std::min(min->z,tmp.z);
841841

842-
max->x = MAX(max->x,tmp.x);
843-
max->y = MAX(max->y,tmp.y);
844-
max->z = MAX(max->z,tmp.z);
842+
max->x = std::max(max->x,tmp.x);
843+
max->y = std::max(max->y,tmp.y);
844+
max->z = std::max(max->z,tmp.z);
845845
}
846846
}
847847
}

libs/openFrameworks/3d/ofCamera.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void ofCamera::setupPerspective(bool _vFlip, float fov, float nearDist, float fa
6060
ofRectangle orientedViewport = getRenderer()->getNativeViewport();
6161
float eyeX = orientedViewport.width / 2;
6262
float eyeY = orientedViewport.height / 2;
63-
float halfFov = PI * fov / 360;
63+
float halfFov = glm::pi<float>() * fov / 360.0f;
6464
float theTan = tanf(halfFov);
6565
float dist = eyeY / theTan;
6666

@@ -98,7 +98,7 @@ void ofCamera::setupOffAxisViewPortal(const glm::vec3 & topLeft, const glm::vec3
9898
setLensOffset(lensOffset);
9999
setAspectRatio( glm::length(bottomEdge) / glm::length(leftEdge) );
100100
auto distanceAlongOpticalAxis = fabs(glm::dot(bottomLeftToCam, cameraLookVector));
101-
setFov(2.0f * RAD_TO_DEG * atan( (glm::length(leftEdge) / 2.0f) / distanceAlongOpticalAxis));
101+
setFov(2.0f * glm::degrees( atan( (glm::length(leftEdge) / 2.0f) / distanceAlongOpticalAxis) ) );
102102
}
103103

104104

@@ -129,7 +129,7 @@ bool ofCamera::getOrtho() const {
129129

130130
//----------------------------------------
131131
float ofCamera::getImagePlaneDistance(const ofRectangle & viewport) const {
132-
return viewport.height / (2.0f * tanf(PI * fov / 360.0f));
132+
return viewport.height / (2.0f * tanf(glm::pi<float>() * fov / 360.0f));
133133
}
134134

135135
//----------------------------------------

libs/openFrameworks/3d/ofMesh.inl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,14 +1154,14 @@ void ofMesh_<V,N,C,T>::load(const of::filesystem::path& path){
11541154

11551155
if((state==Header || state==FaceDef) && lineStr.find("element vertex")==0){
11561156
state = VertexDef;
1157-
orderVertices = MAX(orderIndices, 0)+1;
1157+
orderVertices = std::max(orderIndices, 0)+1;
11581158
data.getVertices().resize(ofTo<size_t>(lineStr.substr(15)));
11591159
continue;
11601160
}
11611161

11621162
if((state==Header || state==VertexDef) && lineStr.find("element face")==0){
11631163
state = FaceDef;
1164-
orderIndices = MAX(orderVertices, 0)+1;
1164+
orderIndices = std::max(orderVertices, 0)+1;
11651165
data.getIndices().resize(ofTo<size_t>(lineStr.substr(13))*3);
11661166
continue;
11671167
}
@@ -1840,7 +1840,7 @@ void ofMesh_<V,N,C,T>::smoothNormals( float angle ) {
18401840

18411841
V vert;
18421842
N normal;
1843-
float angleCos = cos(angle * DEG_TO_RAD );
1843+
float angleCos = cos(ofDegToRad(angle));
18441844
float numNormals=0;
18451845

18461846
for(ofIndexType j = 0; j < triangles.size(); j++) {
@@ -2006,8 +2006,8 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::sphere( float radius, int res, ofPrimitiveMod
20062006
ofMesh_<V,N,C,T> mesh;
20072007

20082008
float doubleRes = res*2.f;
2009-
float polarInc = PI/(res); // ringAngle
2010-
float azimInc = TWO_PI/(doubleRes); // segAngle //
2009+
float polarInc = glm::pi<float>()/(res); // ringAngle
2010+
float azimInc = glm::two_pi<float>()/(doubleRes); // segAngle //
20112011

20122012
if(mode != OF_PRIMITIVE_TRIANGLE_STRIP && mode != OF_PRIMITIVE_TRIANGLES) {
20132013
mode = OF_PRIMITIVE_TRIANGLE_STRIP;
@@ -2019,8 +2019,8 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::sphere( float radius, int res, ofPrimitiveMod
20192019

20202020
for(float i = 0; i < res+1; i++) {
20212021

2022-
float tr = sin( PI-i * polarInc );
2023-
float ny = cos( PI-i * polarInc );
2022+
float tr = sin( glm::pi<float>()-i * polarInc );
2023+
float ny = cos( glm::pi<float>()-i * polarInc );
20242024

20252025
tcoord.y = 1.f - (i / res);
20262026

@@ -2228,8 +2228,8 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::icosphere(float radius, std::size_t iteration
22282228
float r0 = sqrtf(vec.x*vec.x+vec.z*vec.z);
22292229
float alpha;
22302230
alpha = atan2f(vec.z,vec.x);
2231-
u = alpha/TWO_PI+.5f;
2232-
v = atan2f(vec.y, r0)/PI + .5f;
2231+
u = alpha/glm::two_pi<float>()+.5f;
2232+
v = atan2f(vec.y, r0)/glm::pi<float>() + .5f;
22332233
// reverse the u coord, so the default is texture mapped left to
22342234
// right on the outside of a sphere
22352235
// reverse the v coord, so that texture origin is at top left
@@ -2338,7 +2338,7 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::cylinder( float radius, float height, int rad
23382338
if( capSegs < 2 ) bCapped = false;
23392339
if(!bCapped) capSegs=1;
23402340

2341-
float angleIncRadius = -1 * (TWO_PI/((float)radiusSegments-1.f));
2341+
float angleIncRadius = -1 * (glm::two_pi<float>()/((float)radiusSegments-1.f));
23422342
float heightInc = height/((float)heightSegments-1.f);
23432343
float halfH = height*.5f;
23442344

@@ -2533,7 +2533,7 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::cone( float radius, float height, int radiusS
25332533
}
25342534

25352535

2536-
float angleIncRadius = -1.f * ((TWO_PI/((float)radiusSegments-1.f)));
2536+
float angleIncRadius = -1.f * ((glm::two_pi<float>()/((float)radiusSegments-1.f)));
25372537
float heightInc = height/((float)heightSegments-1);
25382538
float halfH = height*.5f;
25392539

libs/openFrameworks/gl/ofCubeMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ bool ofCubeMap::load( ofCubeMapSettings aSettings ) {
375375
_createCubeMap(srcTex);
376376
if( isHdr() ) {
377377

378-
int srcCubeFSize = MAX(256, data->settings.preFilterRes);
378+
int srcCubeFSize = std::max(256, data->settings.preFilterRes);
379379
GLuint cubeFid = _createFloatCubeMap(srcTex, srcCubeFSize );
380380

381381
// figure out the number of mip maps //

libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ void ofGLProgrammableRenderer::setupScreenPerspective(float width, float height,
602602

603603
float eyeX = viewW / 2;
604604
float eyeY = viewH / 2;
605-
float halfFov = PI * fov / 360;
605+
float halfFov = glm::pi<float>() * fov / 360.0f;
606606
float theTan = tanf(halfFov);
607607
float dist = eyeY / theTan;
608608
float aspect = (float) viewW / viewH;

libs/openFrameworks/gl/ofGLRenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ void ofGLRenderer::setupScreenPerspective(float width, float height, float fov,
770770

771771
float eyeX = viewW / 2;
772772
float eyeY = viewH / 2;
773-
float halfFov = PI * fov / 360;
773+
float halfFov = glm::pi<float>() * fov / 360.0f;
774774
float theTan = tanf(halfFov);
775775
float dist = eyeY / theTan;
776776
float aspect = (float) viewW / viewH;

libs/openFrameworks/gl/ofLight.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include "ofGLBaseTypes.h"
1414
#include "ofGLUtils.h"
1515
#include "ofConstants.h"
16-
#include <map>
1716
#include <glm/gtc/quaternion.hpp>
17+
#include <map>
1818

1919
using std::weak_ptr;
2020
using std::vector;
@@ -208,7 +208,7 @@ bool ofLight::getIsSpotlight() const{
208208

209209
//----------------------------------------
210210
void ofLight::setSpotlightCutOff( float spotCutOff ) {
211-
data->spotCutOff = CLAMP(spotCutOff, 0, 90);
211+
data->spotCutOff = ofClamp(spotCutOff, 0, 90);
212212
if ( auto r = data->rendererP.lock() ){
213213
r->setLightSpotlightCutOff( data->glIndex, spotCutOff );
214214
}
@@ -224,7 +224,7 @@ float ofLight::getSpotlightCutOff() const{
224224

225225
//----------------------------------------
226226
void ofLight::setSpotConcentration( float exponent ) {
227-
data->exponent = CLAMP(exponent, 0, 128);
227+
data->exponent = ofClamp(exponent, 0, 128);
228228
if ( auto r = data->rendererP.lock() ){
229229
r->setLightSpotConcentration( data->glIndex, exponent );
230230
}
@@ -348,8 +348,8 @@ void ofLight::customDraw(const ofBaseRenderer * renderer) const{
348348
renderer->drawSphere( 0,0,0, 10);
349349
ofDrawAxis(20);
350350
} else if (getIsSpotlight()) {
351-
float coneHeight = (sin(data->spotCutOff*DEG_TO_RAD) * 30.f) + 1;
352-
float coneRadius = (cos(data->spotCutOff*DEG_TO_RAD) * 30.f) + 8;
351+
float coneHeight = (sin(ofDegToRad(data->spotCutOff)) * 30.f) + 1;
352+
float coneRadius = (cos(ofDegToRad(data->spotCutOff)) * 30.f) + 8;
353353
const_cast<ofBaseRenderer*>(renderer)->rotateDeg(-90,1,0,0);
354354
renderer->drawCone(0, -(coneHeight*.5), 0, coneHeight, coneRadius);
355355
} else if (getIsAreaLight()) {

libs/openFrameworks/graphics/of3dGraphics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ void of3dGraphics::drawRotationAxes(float radius, float stripWidth, int circleRe
508508
axisZMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
509509

510510
for (int j = 0; j<=circleRes; j++) {
511-
float x = cos(TWO_PI * j/circleRes);
512-
float y = sin(TWO_PI * j/circleRes);
511+
float x = cos(glm::two_pi<float>() * j/circleRes);
512+
float y = sin(glm::two_pi<float>() * j/circleRes);
513513
axisXMesh.addColor(ofFloatColor(ofFloatColor::red));
514514
axisXMesh.addVertex({-stripWidth, x*radius, y*radius});
515515
axisXMesh.addColor(ofFloatColor(ofFloatColor::red));

libs/openFrameworks/graphics/ofCairoRenderer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,11 @@ void ofCairoRenderer::draw(const ofPath::Command & command) const{
476476
mut_this->translate(0,-command.to.y*ellipse_ratio);
477477
mut_this->scale(1,ellipse_ratio);
478478
mut_this->translate(0,command.to.y/ellipse_ratio);
479-
cairo_arc(cr,command.to.x,command.to.y,command.radiusX,command.angleBegin*DEG_TO_RAD,command.angleEnd*DEG_TO_RAD);
479+
cairo_arc(cr,command.to.x, command.to.y, command.radiusX, ofDegToRad(command.angleBegin), ofDegToRad(command.angleEnd));
480480
//cairo_set_matrix(cr,&stored_matrix);
481481
mut_this->popMatrix();
482482
}else{
483-
cairo_arc(cr,command.to.x,command.to.y,command.radiusX,command.angleBegin*DEG_TO_RAD,command.angleEnd*DEG_TO_RAD);
483+
cairo_arc(cr,command.to.x, command.to.y, command.radiusX, ofDegToRad(command.angleBegin), ofDegToRad(command.angleEnd));
484484
}
485485
break;
486486

@@ -493,11 +493,11 @@ void ofCairoRenderer::draw(const ofPath::Command & command) const{
493493
mut_this->translate(0,-command.to.y*ellipse_ratio);
494494
mut_this->scale(1,ellipse_ratio);
495495
mut_this->translate(0,command.to.y/ellipse_ratio);
496-
cairo_arc_negative(cr,command.to.x,command.to.y,command.radiusX,command.angleBegin*DEG_TO_RAD,command.angleEnd*DEG_TO_RAD);
496+
cairo_arc_negative(cr,command.to.x, command.to.y, command.radiusX, ofDegToRad(command.angleBegin), ofDegToRad(command.angleEnd));
497497
//cairo_set_matrix(cr,&stored_matrix);
498498
mut_this->popMatrix();
499499
}else{
500-
cairo_arc_negative(cr,command.to.x,command.to.y,command.radiusX,command.angleBegin*DEG_TO_RAD,command.angleEnd*DEG_TO_RAD);
500+
cairo_arc_negative(cr,command.to.x, command.to.y, command.radiusX, ofDegToRad(command.angleBegin), ofDegToRad(command.angleEnd));
501501
}
502502
break;
503503

@@ -956,7 +956,7 @@ void ofCairoRenderer::setupScreenPerspective(float width, float height, float fo
956956

957957
float eyeX = viewW / 2;
958958
float eyeY = viewH / 2;
959-
float halfFov = PI * fov / 360;
959+
float halfFov = glm::pi<float>() * fov / 360.0f;
960960
float theTan = tanf(halfFov);
961961
float dist = eyeY / theTan;
962962
float aspect = (float) viewW / viewH;
@@ -1306,7 +1306,7 @@ void ofCairoRenderer::drawTriangle(float x1, float y1, float z1, float x2, float
13061306
//----------------------------------------------------------
13071307
void ofCairoRenderer::drawCircle(float x, float y, float z, float radius) const{
13081308
cairo_new_path(cr);
1309-
cairo_arc(cr, x,y,radius,0,2*PI);
1309+
cairo_arc(cr, x, y, radius, 0, glm::two_pi<float>());
13101310

13111311
cairo_close_path(cr);
13121312

@@ -1336,7 +1336,7 @@ void ofCairoRenderer::drawEllipse(float x, float y, float z, float width, float
13361336
mutThis->translate(0,-y*ellipse_ratio);
13371337
mutThis->scale(1,ellipse_ratio);
13381338
mutThis->translate(0,y/ellipse_ratio);
1339-
cairo_arc(cr,x,y,width*0.5,0,2*PI);
1339+
cairo_arc(cr, x, y, width*0.5, 0, glm::two_pi<float>());
13401340
mutThis->popMatrix();
13411341

13421342
cairo_close_path(cr);

libs/openFrameworks/graphics/ofGraphics.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,12 @@ void ofBackgroundGradient(const ofColor& start, const ofColor& end, ofGradientMo
397397
glm::vec2 center(w / 2, h / 2);
398398
gradientMesh.addVertex(glm::vec3(center, 0.f));
399399
gradientMesh.addColor(start);
400-
int n = 32; // circular gradient resolution
401-
float angleBisector = TWO_PI / (n * 2);
400+
float n = 32; // circular gradient resolution
401+
float angleBisector = glm::two_pi<float>() / (n * 2.0);
402402
float smallRadius = ofDist(0, 0, w / 2, h / 2);
403403
float bigRadius = smallRadius / cos(angleBisector);
404404
for(int i = 0; i <= n; i++) {
405-
float theta = i * TWO_PI / n;
405+
float theta = i * glm::two_pi<float>() / n;
406406
gradientMesh.addVertex(glm::vec3(center + glm::vec2(sin(theta), cos(theta)) * bigRadius, 0));
407407
gradientMesh.addColor(end);
408408
}
@@ -1213,7 +1213,7 @@ void ofDrawBitmapStringHighlight(string text, int x, int y, const ofColor& backg
12131213
currentLineLength++;
12141214
}
12151215
}
1216-
maxLineLength = MAX(maxLineLength, currentLineLength);
1216+
maxLineLength = std::max(maxLineLength, currentLineLength);
12171217
}
12181218

12191219
int padding = 4;

0 commit comments

Comments
 (0)