Skip to content

Commit 9c3679c

Browse files
author
Sascha Brandt
committed
removed warnings
1 parent adc87fa commit 9c3679c

12 files changed

+70
-68
lines changed

Box.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ class _Box {
4141
* @name Main
4242
*/
4343
//@{
44-
_Box() : min(-0.0, -0.0, -0.0), max(0.0, 0.0, 0.0) {
44+
_Box() : min(static_cast<value_t>(-0.0), static_cast<value_t>(-0.0), static_cast<value_t>(-0.0)), max(static_cast<value_t>(0.0), static_cast<value_t>(0.0), static_cast<value_t>(0.0)) {
4545
}
4646
_Box(value_t minx, value_t maxx, value_t miny, value_t maxy, value_t minz, value_t maxz)
4747
: min(minx, miny, minz), max(maxx, maxy, maxz) {
4848
}
4949
_Box(const vec3_t & center, value_t size)
50-
: min(center.getX() - size * 0.5, center.getY() - size * 0.5, center.getZ() - size * 0.5),
51-
max(center.getX() + size * 0.5, center.getY() + size * 0.5, center.getZ() + size * 0.5) {
50+
: min(center.getX() - static_cast<value_t>(size * 0.5), center.getY() - static_cast<value_t>(size * 0.5), center.getZ() - static_cast<value_t>(size * 0.5)),
51+
max(center.getX() + static_cast<value_t>(size * 0.5), center.getY() + static_cast<value_t>(size * 0.5), center.getZ() + static_cast<value_t>(size * 0.5)) {
5252
}
5353
_Box(const vec3_t & center, value_t dimX, value_t dimY, value_t dimZ)
54-
: min(center.getX() - dimX * 0.5, center.getY() - dimY * 0.5, center.getZ() - dimZ * 0.5),
55-
max(center.getX() + dimX * 0.5, center.getY() + dimY * 0.5, center.getZ() + dimZ * 0.5) {
54+
: min(center.getX() - static_cast<value_t>(dimX * 0.5), center.getY() - static_cast<value_t>(dimY * 0.5), center.getZ() - static_cast<value_t>(dimZ * 0.5)),
55+
max(center.getX() + static_cast<value_t>(dimX * 0.5), center.getY() + static_cast<value_t>(dimY * 0.5), center.getZ() + static_cast<value_t>(dimZ * 0.5)) {
5656
}
5757
_Box(const vec3_t & cornerA, const vec3_t & cornerB)
5858
: min(vec3_t::pairwiseMin(cornerA, cornerB)), max(vec3_t::pairwiseMax(cornerA, cornerB)) {
@@ -161,10 +161,10 @@ class _Box {
161161
}
162162

163163
vec3_t getCenter() const {
164-
return (min + max) * 0.5;
164+
return (min + max) * static_cast<value_t>(0.5);
165165
}
166166
value_t getBoundingSphereRadius() const {
167-
return getDiameter() * 0.5;
167+
return getDiameter() * static_cast<value_t>(0.5);
168168
}
169169
//@}
170170

@@ -309,7 +309,7 @@ inline value_t _Box<value_t>::getDiameterSquared() const {
309309

310310
template <typename value_t>
311311
inline value_t _Box<value_t>::getSurfaceArea() const {
312-
return 2.0 * getExtentX() * getExtentY() + 2.0 * getExtentY() * getExtentZ() + 2.0 * getExtentX() * getExtentZ();
312+
return static_cast<value_t>(2.0) * getExtentX() * getExtentY() + static_cast<value_t>(2.0) * getExtentY() * getExtentZ() + static_cast<value_t>(2.0) * getExtentX() * getExtentZ();
313313
}
314314

315315
template <typename value_t>
@@ -412,8 +412,8 @@ inline _Vec3<value_t> _Box<value_t>::getClosestPoint(const vec3_t & p) const {
412412
// ---- Modification
413413
template <typename value_t>
414414
inline void _Box<value_t>::invalidate() {
415-
min.setX(1.0);
416-
max.setX(0.0);
415+
min.setX(static_cast<value_t>(1.0));
416+
max.setX(static_cast<value_t>(0.0));
417417
}
418418

419419
template <typename value_t>
@@ -521,9 +521,9 @@ inline void _Box<value_t>::resizeAbs(value_t sizeX, value_t sizeY, value_t sizeZ
521521

522522
template <typename value_t>
523523
inline void _Box<value_t>::resizeRel(value_t relSizeX, value_t relSizeY, value_t relSizeZ) {
524-
const value_t halfChangeLengthX = (relSizeX - 1.0) * getExtentX() * 0.5;
525-
const value_t halfChangeLengthY = (relSizeY - 1.0) * getExtentY() * 0.5;
526-
const value_t halfChangeLengthZ = (relSizeZ - 1.0) * getExtentZ() * 0.5;
524+
const value_t halfChangeLengthX = (relSizeX - static_cast<value_t>(1.0)) * getExtentX() * static_cast<value_t>(0.5);
525+
const value_t halfChangeLengthY = (relSizeY - static_cast<value_t>(1.0)) * getExtentY() * static_cast<value_t>(0.5);
526+
const value_t halfChangeLengthZ = (relSizeZ - static_cast<value_t>(1.0)) * getExtentZ() * static_cast<value_t>(0.5);
527527

528528
const vec3_t resizeVec(halfChangeLengthX, halfChangeLengthY, halfChangeLengthZ);
529529

@@ -540,24 +540,24 @@ inline void _Box<value_t>::setExtent(value_t ex) {
540540

541541
template <typename value_t>
542542
inline void _Box<value_t>::setExtentX(value_t ex) {
543-
const value_t center = (min.getX() + max.getX()) * 0.5;
544-
const value_t halfEx = ex * 0.5;
543+
const value_t center = (min.getX() + max.getX()) * static_cast<value_t>(0.5);
544+
const value_t halfEx = ex * static_cast<value_t>(0.5);
545545
min.setX(center - halfEx);
546546
max.setX(center + halfEx);
547547
}
548548

549549
template <typename value_t>
550550
inline void _Box<value_t>::setExtentY(value_t ey) {
551-
const value_t center = (min.getY() + max.getY()) * 0.5;
552-
const value_t halfEx = ey * 0.5;
551+
const value_t center = (min.getY() + max.getY()) * static_cast<value_t>(0.5);
552+
const value_t halfEx = ey * static_cast<value_t>(0.5);
553553
min.setY(center - halfEx);
554554
max.setY(center + halfEx);
555555
}
556556

557557
template <typename value_t>
558558
inline void _Box<value_t>::setExtentZ(value_t ez) {
559-
const value_t center = (min.getZ() + max.getZ()) * 0.5;
560-
const value_t halfEx = ez * 0.5;
559+
const value_t center = (min.getZ() + max.getZ()) * static_cast<value_t>(0.5);
560+
const value_t halfEx = ez * static_cast<value_t>(0.5);
561561
min.setZ(center - halfEx);
562562
max.setZ(center + halfEx);
563563
}

Convert.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct Convert {
7676
static signed_t toSigned(float_t f) {
7777
const float_t fC = std::min(std::max(static_cast<float_t>(-1), f), static_cast<float_t>(1));
7878
// max() is equal to 2^(b-1) - 1 for signed types with b bits
79-
return fC * std::numeric_limits<signed_t>::max();
79+
return static_cast<signed_t>(fC * std::numeric_limits<signed_t>::max());
8080
}
8181

8282
/**
@@ -98,20 +98,20 @@ struct Convert {
9898
static unsigned_t toUnsigned(float_t f) {
9999
const float_t fC = std::min(std::max(static_cast<float_t>(0), f), static_cast<float_t>(1));
100100
// max() is equal to 2^b - 1 for unsigned types with b bits
101-
return fC * std::numeric_limits<unsigned_t>::max();
101+
return static_cast<unsigned_t>(fC * std::numeric_limits<unsigned_t>::max());
102102
}
103103

104104
template <typename _T>
105105
static _T degToRad(_T f) {
106106
static_assert(std::is_floating_point<_T>::value, "template argument not a floating point type");
107-
const _T DEG_TO_RAD = 0.017453292519943295769236907684886;
107+
const _T DEG_TO_RAD = static_cast<_T>(0.017453292519943295769236907684886);
108108
return f * DEG_TO_RAD;
109109
}
110110

111111
template <typename _T>
112112
static _T radToDeg(_T f) {
113113
static_assert(std::is_floating_point<_T>::value, "template argument not a floating point type");
114-
const _T RAD_TO_DEG = 57.295779513082320876798154814105170;
114+
const _T RAD_TO_DEG = static_cast<_T>(57.295779513082320876798154814105170);
115115
return f * RAD_TO_DEG;
116116
}
117117

@@ -137,7 +137,7 @@ struct Convert {
137137
v.si ^= sign;
138138
sign >>= 16; // logical shift
139139
s.si = 0x52000000; // (1 << 23) / minN
140-
s.si = s.f * v.f; // correct subnormals
140+
s.si = static_cast<int32_t>(s.f * v.f); // correct subnormals
141141
v.si ^= (s.si ^ v.si) & -(minN > v.si);
142142
v.si ^= (infN ^ v.si) & -((infN > v.si) & (v.si > maxN));
143143
v.si ^= (nanN ^ v.si) & -((nanN > v.si) & (v.si > infN));

Interpolation.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ val_t clamp(val_t lower, val_t value, val_t upper) {
4040
template <class vec_t, class val_t>
4141
vec_t linear(vec_t p0, vec_t p1, val_t t) {
4242
const val_t v = clamp(static_cast<val_t>(0), t, static_cast<val_t>(1));
43-
const val_t oneMinusV = 1.0 - v;
43+
const val_t oneMinusV = static_cast<val_t>(1.0) - v;
4444
return p0 * oneMinusV + p1 * v;
4545
}
4646

@@ -56,8 +56,8 @@ vec_t linear(vec_t p0, vec_t p1, val_t t) {
5656
template <class vec_t, class val_t>
5757
vec_t quadraticBezier(vec_t p0, vec_t p1, vec_t p2, val_t t) {
5858
const val_t v = clamp(static_cast<val_t>(0), t, static_cast<val_t>(1));
59-
const val_t oneMinusV = 1.0 - v;
60-
return p0 * oneMinusV * oneMinusV + p1 * 2.0 * oneMinusV * v + p2 * v * v;
59+
const val_t oneMinusV = static_cast<val_t>(1.0) - v;
60+
return p0 * oneMinusV * oneMinusV + p1 * static_cast<val_t>(2.0) * oneMinusV * v + p2 * v * v;
6161
}
6262

6363
/**
@@ -74,11 +74,10 @@ vec_t quadraticBezier(vec_t p0, vec_t p1, vec_t p2, val_t t) {
7474
template <class vec_t, class val_t>
7575
vec_t cubicBezier(vec_t p0, vec_t p1, vec_t p2, vec_t p3, val_t t) {
7676
const val_t v = clamp(static_cast<val_t>(0), t, static_cast<val_t>(1));
77-
const val_t oneMinusV = 1.0 - v;
77+
const val_t oneMinusV = static_cast<val_t>(1.0) - v;
7878
const val_t vSquared = v * v;
7979
const val_t oneMinusVSquared = oneMinusV * oneMinusV;
80-
return p0 * oneMinusVSquared * oneMinusV + p1 * 3.0 * oneMinusVSquared * v + p2 * 3.0 * oneMinusV * vSquared
81-
+ p3 * vSquared * v;
80+
return p0 * oneMinusVSquared * oneMinusV + p1 * static_cast<val_t>(3.0) * oneMinusVSquared * v + p2 * static_cast<val_t>(3.0) * oneMinusV * vSquared + p3 * vSquared * v;
8281
}
8382
}
8483
}

LineTriangleIntersection.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ bool getLineTriangleIntersection(const line_t & line, const Triangle<_Vec3<value
5757
if (det > -epsilon && det < epsilon) {
5858
return false;
5959
}
60-
const auto invDet = 1.0 / det;
60+
const auto invDet = static_cast<value_t>(1.0) / det;
6161

6262
// Calculate distance from vertex A to line origin
6363
const auto tVec = ori - triangle.getVertexA();
6464

6565
// Calculate u parameter and test bounds
6666
const auto u = tVec.dot(pVec) * invDet;
67-
if (u < 0.0 || u > 1.0) {
67+
if (u < static_cast<value_t>(0.0) || u > static_cast<value_t>(1.0)) {
6868
return false;
6969
}
7070

@@ -73,7 +73,7 @@ bool getLineTriangleIntersection(const line_t & line, const Triangle<_Vec3<value
7373

7474
// Calculate v parameter and test bounds
7575
const auto v = dir.dot(qVec) * invDet;
76-
if (v < 0.0 || u + v > 1.0) {
76+
if (v < static_cast<value_t>(0.0) || u + v > static_cast<value_t>(1.0)) {
7777
return false;
7878
}
7979

Matrix4x4.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class _Matrix4x4 {
280280
const value_t d = angle.rad();
281281
const value_t s = std::sin(d);
282282
const value_t c = std::cos(d);
283-
const value_t lengthInv = 1.0 / sqrt(x * x + y * y + z * z);
283+
const value_t lengthInv = static_cast<value_t>(1.0 / std::sqrt(x * x + y * y + z * z));
284284
x *= lengthInv, y *= lengthInv, z *= lengthInv;
285285

286286
const value_t xy = x * y, yz = y * z, xz = x * z, xs = x * s, ys = y * s, zs = z * s;
@@ -593,7 +593,7 @@ class _Matrix4x4 {
593593
const value_t l3 = ez.lengthSquared();
594594

595595
const value_t squaredLengthEpsilon = std::numeric_limits<value_t>::epsilon();
596-
const value_t epsilon = 1.0e-3;
596+
const value_t epsilon = static_cast<value_t>(1.0e-3);
597597

598598
return l1 >= squaredLengthEpsilon && l2 >= squaredLengthEpsilon && l3 >= squaredLengthEpsilon
599599
&& std::abs((l1 / l2) - 1) <= epsilon && std::abs((l2 / l3) - 1) <= epsilon;
@@ -622,7 +622,7 @@ class _Matrix4x4 {
622622
const vec3_t dirNorm = dir / lengthDir;
623623

624624
// Check if the resulting coordinate system is right-handed.
625-
if (!rightNorm.cross(upNorm).equals(dirNorm, 1.0e-3)) {
625+
if (!rightNorm.cross(upNorm).equals(dirNorm, static_cast<value_t>(1.0e-3))) {
626626
// Negative scaling.
627627
return srt_t(pos, -dirNorm, -upNorm, -lengthDir);
628628
}

PointOctree.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ class PointOctree {
170170
return found ? cell : nullptr;
171171
}
172172

173-
void getClosestPoints(const Vec3f & pos, size_t count, std::deque<Point_t> & out) const;
173+
void getClosestPoints(const Vec3f & pos, uint64_t count, std::deque<Point_t> & out) const;
174174

175-
std::deque<Point_t> getSortedClosestPoints(const Vec3f & pos, size_t count) const;
175+
std::deque<Point_t> getSortedClosestPoints(const Vec3f & pos, uint64_t count) const;
176176
};
177177

178178
template <typename Point_t>
@@ -381,7 +381,7 @@ inline bool PointOctree<Point_t>::sphereBoxIntersection(const Sphere_f & sphere,
381381
}
382382

383383
template <typename Point_t>
384-
inline void PointOctree<Point_t>::getClosestPoints(const Vec3f & pos, size_t count, std::deque<Point_t> & out) const {
384+
inline void PointOctree<Point_t>::getClosestPoints(const Vec3f & pos, uint64_t count, std::deque<Point_t> & out) const {
385385
const PointOctree * leaf = findLeafCell(pos);
386386
if (leaf == nullptr) {
387387
return;
@@ -391,17 +391,17 @@ inline void PointOctree<Point_t>::getClosestPoints(const Vec3f & pos, size_t cou
391391
return;
392392
}
393393
const float maxRadius = box.getDiameter();
394-
for (float radius = leaf->box.getDiameter() * 0.25; radius <= maxRadius; radius *= 2.0) {
394+
for (float radius = leaf->box.getDiameter() * 0.25f; radius <= maxRadius; radius *= 2.0f) {
395395
out.clear();
396396
collectPointsWithinSphere(Sphere_f(pos, radius), out);
397397
if (out.size() >= count)
398398
break;
399399
}
400400
if (out.size() > count) {
401-
std::vector<std::pair<float, size_t>> sortedPoints;
401+
std::vector<std::pair<float, uint64_t>> sortedPoints;
402402

403403
// store (distance,pointIndex) in sortedPoints
404-
size_t i = 0;
404+
uint64_t i = 0;
405405
for (auto & point : out) {
406406
sortedPoints.emplace_back(pos.distanceSquared(point.getPosition()), i++);
407407
}
@@ -420,14 +420,14 @@ inline void PointOctree<Point_t>::getClosestPoints(const Vec3f & pos, size_t cou
420420
}
421421

422422
template <typename Point_t>
423-
inline std::deque<Point_t> PointOctree<Point_t>::getSortedClosestPoints(const Vec3f & pos, size_t count) const {
423+
inline std::deque<Point_t> PointOctree<Point_t>::getSortedClosestPoints(const Vec3f & pos, uint64_t count) const {
424424
std::deque<Point_t> closestPoints;
425425
getClosestPoints(pos, count, closestPoints);
426426

427-
std::vector<std::pair<float, size_t>> sortingData;
427+
std::vector<std::pair<float, uint64_t>> sortingData;
428428

429429
// store (distance,pointIndex) in sortingData
430-
size_t i = 0;
430+
uint64_t i = 0;
431431
for (auto & point : closestPoints)
432432
sortingData.emplace_back(pos.distanceSquared(point.getPosition()), i++);
433433

Quaternion.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,15 @@ class _Quaternion {
245245
value_t zz = q.z() * q.z();
246246

247247
matrix3x3_t mat;
248-
mat.set(0, 0, 1.0 - 2.0 * (yy + zz));
249-
mat.set(0, 1, 2.0 * (xy - wz));
250-
mat.set(0, 2, 2.0 * (xz + wy));
251-
mat.set(1, 0, 2.0 * (xy + wz));
252-
mat.set(1, 1, 1.0 - 2.0 * (xx + zz));
253-
mat.set(1, 2, 2.0 * (yz - wx));
254-
mat.set(2, 0, 2.0 * (xz - wy));
255-
mat.set(2, 1, 2.0 * (yz + wx));
256-
mat.set(2, 2, 1.0 - 2.0 * (xx + yy));
248+
mat.set(0, 0, static_cast<value_t>(1) - static_cast<value_t>(2) * (yy + zz));
249+
mat.set(0, 1, static_cast<value_t>(2) * (xy - wz));
250+
mat.set(0, 2, static_cast<value_t>(2) * (xz + wy));
251+
mat.set(1, 0, static_cast<value_t>(2) * (xy + wz));
252+
mat.set(1, 1, static_cast<value_t>(1) - static_cast<value_t>(2) * (xx + zz));
253+
mat.set(1, 2, static_cast<value_t>(2) * (yz - wx));
254+
mat.set(2, 0, static_cast<value_t>(2) * (xz - wy));
255+
mat.set(2, 1, static_cast<value_t>(2) * (yz + wx));
256+
mat.set(2, 2, static_cast<value_t>(1) - static_cast<value_t>(2) * (xx + yy));
257257

258258
return mat;
259259
}
@@ -269,11 +269,11 @@ class _Quaternion {
269269
value_t sqz = values[2] * values[2];
270270
value_t unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
271271
value_t test = values[0] * values[1] + values[2] * values[3];
272-
if (test > 0.499 * unit) { // singularity at north pole
273-
return vec3_t(2 * std::atan2(values[0], values[3]), M_PI / 2, 0);
272+
if (test > static_cast<value_t>(0.499 * unit)) { // singularity at north pole
273+
return vec3_t(static_cast<value_t>(2 * std::atan2(values[0], values[3])), static_cast<value_t>(M_PI / 2), 0);
274274
}
275275
if (test < -0.499 * unit) { // singularity at south pole
276-
return vec3_t(-2 * std::atan2(values[0], values[3]), -M_PI / 2, 0);
276+
return vec3_t(static_cast<value_t>(-2 * std::atan2(values[0], values[3])), static_cast<value_t>(-M_PI / 2), 0);
277277
}
278278
return vec3_t(std::atan2(2 * values[1] * values[3] - 2 * values[0] * values[2], sqx - sqy - sqz + sqw),
279279
std::asin(2 * test / unit),
@@ -348,7 +348,7 @@ class _Quaternion {
348348
const value_t rad = angle.rad();
349349
// Used to normalize the rotation vector.
350350
const value_t invLength = 1.0f / std::sqrt(_x * _x + _y * _y + _z * _z);
351-
const value_t sinHalfAngle = std::sin(0.5 * rad);
351+
const value_t sinHalfAngle = static_cast<value_t>(std::sin(0.5 * rad));
352352
values[0] = sinHalfAngle * invLength * _x;
353353
values[1] = sinHalfAngle * invLength * _y;
354354
values[2] = sinHalfAngle * invLength * _z;

Triangle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class Triangle {
145145
*/
146146
value_t calcArea() const {
147147
// Triangle area is half of the area of a parallelogram.
148-
return 0.5 * getEdgeBA().cross(getEdgeBC()).length();
148+
return 0.5f * getEdgeBA().cross(getEdgeBC()).length();
149149
}
150150

151151
/**

Vec2.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ class _Vec2 {
308308

309309
typedef _Vec2<float> Vec2;
310310
typedef _Vec2<float> Vec2f;
311-
typedef _Vec2<int> Vec2i;
311+
typedef _Vec2<int32_t> Vec2i;
312+
typedef _Vec2<uint32_t> Vec2ui;
312313
typedef _Vec2<double> Vec2d;
313314
}
314315

Vec3.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ class _Vec3 {
516516
typedef _Vec3<float> Vec3;
517517
typedef _Vec3<float> Vec3f;
518518
typedef _Vec3<double> Vec3d;
519-
typedef _Vec3<int> Vec3i;
519+
typedef _Vec3<int32_t> Vec3i;
520+
typedef _Vec3<uint32_t> Vec3ui;
520521
}
521522

522523
#endif /* GEOMETRY_VEC3_H */

Vec4.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ class _Vec4 {
458458
typedef _Vec4<float> Vec4;
459459
typedef _Vec4<float> Vec4f;
460460
typedef _Vec4<double> Vec4d;
461-
typedef _Vec4<int> Vec4i;
461+
typedef _Vec4<int32_t> Vec4i;
462+
typedef _Vec4<uint32_t> Vec4ui;
462463
}
463464

464465
#endif /* GEOMETRY_VEC4_H */

0 commit comments

Comments
 (0)