Skip to content

Commit 05fe3b0

Browse files
committedApr 3, 2018
Fix last clang-tidy reported problems for performance-type-promotion-in-math-fn
Based on https://travis-ci.org/minetest/minetest/jobs/361810382 output Also fix 2 missing copyright notices
1 parent 4827f75 commit 05fe3b0

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed
 

‎src/client/hud.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2020
*/
2121

2222
#include "client/hud.h"
23+
#include <cmath>
2324
#include "settings.h"
2425
#include "util/numeric.h"
2526
#include "log.h"
@@ -50,7 +51,7 @@ Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
5051
this->inventory = inventory;
5152

5253
m_hud_scaling = g_settings->getFloat("hud_scaling");
53-
m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE *
54+
m_hotbar_imagesize = std::floor(HOTBAR_IMAGE_SIZE *
5455
RenderingEngine::getDisplayDensity() + 0.5f);
5556
m_hotbar_imagesize *= m_hud_scaling;
5657
m_padding = m_hotbar_imagesize / 12;
@@ -336,7 +337,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
336337
case HUD_ELEM_WAYPOINT: {
337338
v3f p_pos = player->getPosition() / BS;
338339
v3f w_pos = e->world_pos * BS;
339-
float distance = floor(10 * p_pos.getDistanceFrom(e->world_pos)) / 10;
340+
float distance = std::floor(10 * p_pos.getDistanceFrom(e->world_pos)) /
341+
10.0f;
340342
scene::ICameraSceneNode* camera =
341343
RenderingEngine::get_scene_manager()->getActiveCamera();
342344
w_pos -= intToFloat(camera_offset, BS);
@@ -735,12 +737,12 @@ void drawItemStack(video::IVideoDriver *driver,
735737
// wear = 0.5: yellow
736738
// wear = 1.0: red
737739
video::SColor color(255,255,255,255);
738-
int wear_i = MYMIN(floor(wear * 600), 511);
740+
int wear_i = MYMIN(std::floor(wear * 600), 511);
739741
wear_i = MYMIN(wear_i + 10, 511);
740-
if(wear_i <= 255)
742+
if (wear_i <= 255)
741743
color.set(255, wear_i, 255, 0);
742744
else
743-
color.set(255, 255, 511-wear_i, 0);
745+
color.set(255, 255, 511 - wear_i, 0);
744746

745747
core::rect<s32> progressrect2 = progressrect;
746748
progressrect2.LowerRightCorner.X = progressmid;

‎src/hud.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1-
#include "hud.h"
1+
/*
2+
Minetest
3+
Copyright (C) 2010-2018 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
214
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
#include "hud.h"
21+
#include <cmath>
322

423
const struct EnumString es_HudElementType[] =
524
{

‎src/script/lua_api/l_camera.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
1-
#include "script/common/c_converter.h"
1+
/*
2+
Minetest
3+
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
220
#include "l_camera.h"
21+
#include <cmath>
22+
#include "script/common/c_converter.h"
323
#include "l_internal.h"
424
#include "content_cao.h"
525
#include "camera.h"
@@ -98,7 +118,8 @@ int LuaCamera::l_get_look_dir(lua_State *L)
98118

99119
float pitch = -1.0 * player->getPitch() * core::DEGTORAD;
100120
float yaw = (player->getYaw() + 90.) * core::DEGTORAD;
101-
v3f v(cos(pitch) * cos(yaw), sin(pitch), cos(pitch) * sin(yaw));
121+
v3f v(std::cos(pitch) * std::cos(yaw), std::sin(pitch),
122+
std::cos(pitch) * std::sin(yaw));
102123

103124
push_v3f(L, v);
104125
return 1;

‎src/util/numeric.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
157157
// HOTFIX: use sligthly increased angle (+10%) to fix too agressive
158158
// culling. Somebody have to find out whats wrong with the math here.
159159
// Previous value: camera_fov / 2
160-
if(cosangle < cos(camera_fov * 0.55))
160+
if (cosangle < std::cos(camera_fov * 0.55f))
161161
return false;
162162

163163
return true;
@@ -172,6 +172,6 @@ s16 adjustDist(s16 dist, float zoom_fov)
172172
return dist;
173173

174174
// new_dist = dist * ((1 - cos(FOV / 2)) / (1-cos(zoomFOV /2))) ^ (1/3)
175-
return round(dist * cbrt((1.0f - std::cos(default_fov / 2.0f)) /
175+
return round(dist * std::cbrt((1.0f - std::cos(default_fov / 2.0f)) /
176176
(1.0f - std::cos(zoom_fov / 2.0f))));
177177
}

0 commit comments

Comments
 (0)