Skip to content

Commit 37b6178

Browse files
authored
Some math functions now prefixed with std:: (#7918)
#changelog #core
1 parent 8f2db49 commit 37b6178

103 files changed

Lines changed: 607 additions & 616 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

addons/ofxAccelerometer/src/ofxAccelerometer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ class ofxAccelerometerHandler {
140140
if(!orientDirty) return;
141141
orientDirty = false;
142142

143-
orientation.x = atan2(accelOrientation.y, -accelOrientation.z) * RAD_TO_DEG;
144-
orientation.y = atan2(accelOrientation.x, -accelOrientation.z) * RAD_TO_DEG;
143+
orientation.x = glm::degrees( atan2(accelOrientation.y, -accelOrientation.z) );
144+
orientation.y = glm::degrees( atan2(accelOrientation.x, -accelOrientation.z) );
145145
orientation.z = 0;
146146
}
147147

addons/ofxAssimpModelLoader/src/ofxAssimpAnimation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void ofxAssimpAnimation::update() {
5656
position = 1.0;
5757
stop();
5858
} else if(position > 1.0 && loopType == OF_LOOP_NORMAL) {
59-
position = fmod(position, 1.0f);
59+
position = std::fmod(position, 1.0f);
6060
} else if(position > 1.0 && loopType == OF_LOOP_PALINDROME) {
6161
speedFactor *= -1;
6262
} else if(position < 0.0 && loopType == OF_LOOP_PALINDROME) {

addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void ofxAssimpModelLoader::calculateDimensions(){
219219
normalizedScale = scene_max.x-scene_min.x;
220220
normalizedScale = std::max(double(scene_max.y - scene_min.y), normalizedScale);
221221
normalizedScale = std::max(double(scene_max.z - scene_min.z), normalizedScale);
222-
if (fabs(normalizedScale) < std::numeric_limits<float>::epsilon()){
222+
if (std::abs(normalizedScale) < std::numeric_limits<float>::epsilon()){
223223
ofLogWarning("ofxAssimpModelLoader") << "Error calculating normalized scale of scene" << std::endl;
224224
normalizedScale = 1.0;
225225
} else {

addons/ofxGui/src/ofxColorPicker.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ PolCord getPolarCoordinate(const glm::vec2 & p, float radius){
2323

2424
float px = p.x - radius; // point x from center.
2525
float py = p.y - radius; // point x from center.
26-
float pl = sqrt(px * px + py * py); // point length from center.
27-
float pa = atan2(px, py); // point angle around center.
26+
float pl = std::sqrt(px * px + py * py); // point length from center.
27+
float pa = std::atan2(px, py); // point angle around center.
2828

29-
pa *= RAD_TO_DEG;
29+
pa = glm::degrees(pa);
3030
pa -= 90;
3131
pl /= radius;
3232

@@ -39,8 +39,8 @@ PolCord getPolarCoordinate(const glm::vec2 & p, float radius){
3939

4040
glm::vec2 getPoint(float a, float r){
4141
glm::vec2 p;
42-
p.x = r * cos(-a * DEG_TO_RAD);
43-
p.y = r * sin(-a * DEG_TO_RAD);
42+
p.x = r * std::cos(glm::radians(-a));
43+
p.y = r * std::sin(glm::radians(-a));
4444

4545
return p;
4646
}
@@ -248,9 +248,9 @@ ofMesh ofxColorPicker_<ColorType>::getColorWheel() {
248248

249249
int j = i % COLOR_WHEEL_RES;
250250
float p = j / (float)COLOR_WHEEL_RES;
251-
float a = p * TWO_PI;
251+
float a = p * glm::two_pi<float>();
252252

253-
ofFloatColor c0 = getCircularColor<float>(a * RAD_TO_DEG, 1.0, colorScale);
253+
ofFloatColor c0 = getCircularColor<float>(glm::degrees(a), 1.0, colorScale);
254254
meshColorWheel.addColor(ofFloatColor::white);
255255
meshColorWheel.addColor(c0);
256256
meshColorWheel.addColor(c0);

addons/ofxKinect/src/ofxKinect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ void ofxKinect::update() {
384384
if( videoPixels.getHeight() == videoPixelsIntra.getHeight() ){
385385
std::swap(videoPixels,videoPixelsIntra);
386386
}else{
387-
int minimumSize = MIN(videoPixels.size(), videoPixelsIntra.size());
387+
int minimumSize = std::min(videoPixels.size(), videoPixelsIntra.size());
388388
memcpy(videoPixels.getData(), videoPixelsIntra.getData(), minimumSize);
389389
}
390390
bNeedsUpdateVideo = false;

addons/ofxOpenCv/src/ofxCvImage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ void ofxCvImage::transform( float angle, float centerX, float centerY,
620620
return;
621621
}
622622

623-
float sina = sin(angle * DEG_TO_RAD);
624-
float cosa = cos(angle * DEG_TO_RAD);
623+
float sina = std::sin(glm::radians(angle));
624+
float cosa = std::cos(glm::radians(angle));
625625
CvMat* transmat = cvCreateMat( 2,3, CV_32F );
626626
cvmSet( transmat, 0,0, scaleX*cosa );
627627
cvmSet( transmat, 0,1, scaleY*sina );

addons/ofxSvg/src/ofxSvg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void ofxSvg::fixSvgString(std::string & xmlstring) {
9898
for (ofXml & element : strokeWidthElements) {
9999
//cout << element.toString() << endl;
100100
float strokewidth = element.getAttribute("stroke-width").getFloatValue();
101-
strokewidth = MAX(1, round(strokewidth));
101+
strokewidth = std::fmax(1.0, std::round(strokewidth));
102102
element.getAttribute("stroke-width").set(strokewidth);
103103
}
104104
}

addons/ofxiOS/src/core/ofxiOSGLKViewController.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ - (float)rotationForOrientation:(UIInterfaceOrientation)interfaceOrientation {
195195
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
196196
return 0; // 0 degrees.
197197
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
198-
return M_PI * 0.5; // 90 degrees.
198+
return glm::half_pi<float>(); // 90 degrees.
199199
} else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
200-
return M_PI; // 180 degrees.
200+
return glm::pi<float>(); // 180 degrees.
201201
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
202-
return M_PI * 1.5; // 270 degrees.
202+
return glm::pi<float>() + glm::half_pi<float>(); // 270 degrees.
203203
} else {
204204
return 0;
205205
}

addons/ofxiOS/src/core/ofxiOSViewController.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ - (float)rotationForOrientation:(UIInterfaceOrientation)interfaceOrientation {
127127
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
128128
return 0; // 0 degrees.
129129
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
130-
return M_PI * 0.5; // 90 degrees.
130+
return glm::half_pi<float>(); // 90 degrees.
131131
} else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
132-
return M_PI; // 180 degrees.
132+
return glm::pi<float>(); // 180 degrees.
133133
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
134-
return M_PI * 1.5; // 270 degrees.
134+
return glm::pi<float>() + glm::half_pi<float>(); // 270 degrees.
135135
} else {
136136
return 0;
137137
}

addons/ofxiOS/src/utils/ofxiOSImagePicker.mm

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ - (instancetype) initWithPicker:(canLoadPixels *) _picker
198198
*/
199199
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
200200
if(orientation == UIInterfaceOrientationLandscapeLeft) {
201-
_imagePicker.view.transform = CGAffineTransformMakeRotation(-PI*0.5);
201+
_imagePicker.view.transform = CGAffineTransformMakeRotation(-glm::half_pi<float>());
202202
} else if(orientation == UIInterfaceOrientationLandscapeRight) {
203-
_imagePicker.view.transform = CGAffineTransformMakeRotation(PI*0.5);
203+
_imagePicker.view.transform = CGAffineTransformMakeRotation(glm::half_pi<float>());
204204
} else if(orientation == UIInterfaceOrientationPortraitUpsideDown) {
205-
_imagePicker.view.transform = CGAffineTransformMakeRotation(PI);
205+
_imagePicker.view.transform = CGAffineTransformMakeRotation(glm::pi<float>());
206206
}
207207
}
208208

@@ -330,11 +330,11 @@ - (BOOL) showCameraOverlayWithCustomView:(UIView *)overlayView {
330330
overlay.center = CGPointMake(screenSize.width * 0.5, screenSize.height * 0.5);
331331
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
332332
if(orientation == UIInterfaceOrientationLandscapeLeft) {
333-
overlay.transform = CGAffineTransformMakeRotation(-PI * 0.5);
333+
overlay.transform = CGAffineTransformMakeRotation(-glm::half_pi<float>());
334334
} else if(orientation == UIInterfaceOrientationLandscapeRight) {
335-
overlay.transform = CGAffineTransformMakeRotation(PI * 0.5);
335+
overlay.transform = CGAffineTransformMakeRotation(glm::half_pi<float>());
336336
} else if(orientation == UIInterfaceOrientationPortraitUpsideDown) {
337-
overlay.transform = CGAffineTransformMakeRotation(PI);
337+
overlay.transform = CGAffineTransformMakeRotation(glm::pi<float>());
338338
}
339339
}
340340

@@ -458,7 +458,7 @@ - (UIImage *)scaleAndRotateImage:(UIImage *)image {
458458
break;
459459
case UIImageOrientationDown:
460460
transform = CGAffineTransformMakeTranslation(imageSize.width, imageSize.height);
461-
transform = CGAffineTransformRotate(transform, M_PI);
461+
transform = CGAffineTransformRotate(transform, glm::pi<float>());
462462
break;
463463
case UIImageOrientationDownMirrored:
464464
transform = CGAffineTransformMakeTranslation(0.0, imageSize.height);
@@ -470,28 +470,28 @@ - (UIImage *)scaleAndRotateImage:(UIImage *)image {
470470
bounds.size.width = boundHeight;
471471
transform = CGAffineTransformMakeTranslation(imageSize.height, imageSize.width);
472472
transform = CGAffineTransformScale(transform, -1.0, 1.0);
473-
transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);
473+
transform = CGAffineTransformRotate(transform, glm::pi<float>() + glm::half_pi<float>());
474474
break;
475475
case UIImageOrientationLeft:
476476
boundHeight = bounds.size.height;
477477
bounds.size.height = bounds.size.width;
478478
bounds.size.width = boundHeight;
479479
transform = CGAffineTransformMakeTranslation(0.0, imageSize.width);
480-
transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);
480+
transform = CGAffineTransformRotate(transform, glm::pi<float>() + glm::half_pi<float>());
481481
break;
482482
case UIImageOrientationRightMirrored:
483483
boundHeight = bounds.size.height;
484484
bounds.size.height = bounds.size.width;
485485
bounds.size.width = boundHeight;
486486
transform = CGAffineTransformMakeScale(-1.0, 1.0);
487-
transform = CGAffineTransformRotate(transform, M_PI / 2.0);
487+
transform = CGAffineTransformRotate(transform, glm::half_pi<float>());
488488
break;
489489
case UIImageOrientationRight:
490490
boundHeight = bounds.size.height;
491491
bounds.size.height = bounds.size.width;
492492
bounds.size.width = boundHeight;
493493
transform = CGAffineTransformMakeTranslation(imageSize.height, 0.0);
494-
transform = CGAffineTransformRotate(transform, M_PI / 2.0);
494+
transform = CGAffineTransformRotate(transform, glm::half_pi<float>());
495495
break;
496496
default:
497497
[NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"];

0 commit comments

Comments
 (0)