Skip to content

Commit 3ffb078

Browse files
authored
Fix compiler warnings on windows (#250)
Signed-off-by: Chris Kulla <[email protected]>
1 parent a2446e3 commit 3ffb078

23 files changed

+333
-323
lines changed

src/Imath/ImathMatrix.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3574,22 +3574,22 @@ template <class S>
35743574
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline Matrix44<T>&
35753575
Matrix44<T>::setValue (const Matrix44<S>& v) IMATH_NOEXCEPT
35763576
{
3577-
x[0][0] = v.x[0][0];
3578-
x[0][1] = v.x[0][1];
3579-
x[0][2] = v.x[0][2];
3580-
x[0][3] = v.x[0][3];
3581-
x[1][0] = v.x[1][0];
3582-
x[1][1] = v.x[1][1];
3583-
x[1][2] = v.x[1][2];
3584-
x[1][3] = v.x[1][3];
3585-
x[2][0] = v.x[2][0];
3586-
x[2][1] = v.x[2][1];
3587-
x[2][2] = v.x[2][2];
3588-
x[2][3] = v.x[2][3];
3589-
x[3][0] = v.x[3][0];
3590-
x[3][1] = v.x[3][1];
3591-
x[3][2] = v.x[3][2];
3592-
x[3][3] = v.x[3][3];
3577+
x[0][0] = T(v.x[0][0]);
3578+
x[0][1] = T(v.x[0][1]);
3579+
x[0][2] = T(v.x[0][2]);
3580+
x[0][3] = T(v.x[0][3]);
3581+
x[1][0] = T(v.x[1][0]);
3582+
x[1][1] = T(v.x[1][1]);
3583+
x[1][2] = T(v.x[1][2]);
3584+
x[1][3] = T(v.x[1][3]);
3585+
x[2][0] = T(v.x[2][0]);
3586+
x[2][1] = T(v.x[2][1]);
3587+
x[2][2] = T(v.x[2][2]);
3588+
x[2][3] = T(v.x[2][3]);
3589+
x[3][0] = T(v.x[3][0]);
3590+
x[3][1] = T(v.x[3][1]);
3591+
x[3][2] = T(v.x[3][2]);
3592+
x[3][3] = T(v.x[3][3]);
35933593
return *this;
35943594
}
35953595

src/Imath/ImathMatrixAlgo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ addOffset (
10941094
Matrix44<T> O;
10951095

10961096
Vec3<T> _rOffset (rOffset);
1097-
_rOffset *= M_PI / 180.0;
1097+
_rOffset *= T(M_PI / 180.0);
10981098
O.rotate (_rOffset);
10991099

11001100
O[3][0] = tOffset[0];

src/ImathTest/half_perf_test.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#endif
99

1010
#include <ImathConfig.h>
11+
#include <ImathRandom.h>
1112
#include <half.h>
1213

1314
#include <limits.h>
@@ -378,28 +379,17 @@ main (int argc, char* argv[])
378379

379380
if (halfs && floats)
380381
{
381-
srand (numentries);
382+
Rand48 r(numentries);
382383
for (int i = 0; i < numentries; ++i)
383384
{
384-
halfs[i] = (uint16_t) (rand ());
385+
halfs[i] = (uint16_t) r.nexti();
385386
floats[i] = imath_half_to_float (halfs[i]);
386387
}
387388
perf_test_half_to_float (floats, halfs, numentries);
388389

389390
// test float -> half with real-world values
390-
#ifdef _WIN32
391-
unsigned int rv;
392-
for (int i = 0; i < numentries; ++i)
393-
{
394-
rand_s (&rv);
395-
floats[i] =
396-
65504.0 *
397-
(((double) rand () / (double) UINT_MAX) * 2.0 - 1.0);
398-
}
399-
#else
400391
for (int i = 0; i < numentries; ++i)
401-
floats[i] = 65504.0 * (drand48 () * 2.0 - 1.0);
402-
#endif
392+
floats[i] = float(r.nextf(-65504, 65504));
403393
perf_test_float_to_half (halfs, floats, numentries);
404394
}
405395

src/ImathTest/testBox.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ addItem (const std::vector<int>& value, std::vector<T>& perms)
3939
T p;
4040
for (unsigned int i = 0; i < value.size (); i++)
4141
{
42-
p[i] = value[i];
42+
p[i] = static_cast<typename T::BaseType>(value[i]);
4343
}
4444
perms.push_back (p);
4545
}
@@ -94,7 +94,7 @@ testConstructors (const char* type)
9494
{
9595
T p;
9696
for (unsigned int i = 0; i < T::dimensions (); i++)
97-
p[i] = i;
97+
p[i] = static_cast<typename T::BaseType>(i);
9898

9999
IMATH_INTERNAL_NAMESPACE::Box<T> b (p);
100100
assert (b.min == p && b.max == p);
@@ -108,8 +108,8 @@ testConstructors (const char* type)
108108
T p1;
109109
for (unsigned int i = 0; i < T::dimensions (); i++)
110110
{
111-
p0[i] = i;
112-
p1[i] = 10 * T::dimensions () - i - 1;
111+
p0[i] = static_cast<typename T::BaseType>(i);
112+
p1[i] = static_cast<typename T::BaseType>(10 * T::dimensions () - i - 1);
113113
}
114114

115115
IMATH_INTERNAL_NAMESPACE::Box<T> b (p0, p1);
@@ -625,7 +625,7 @@ testSize (const char* type)
625625
T p;
626626
for (unsigned int i = 0; i < T::dimensions (); i++)
627627
{
628-
p[i] = i;
628+
p[i] = static_cast<typename T::BaseType>(i);
629629
}
630630
IMATH_INTERNAL_NAMESPACE::Box<T> b1 (-p, p);
631631
assert (b1.size () == p * T (2));
@@ -684,8 +684,10 @@ testCenter (const char* type)
684684
T p1;
685685
for (unsigned int i = 0; i < T::dimensions (); i++)
686686
{
687-
p0[i] = -typename T::BaseType (1 << (i + 1));
688-
p1[i] = typename T::BaseType (1 << (T::dimensions () - i));
687+
int lo = 1 << (i + 1);
688+
int hi = 1 << (T::dimensions () - i);
689+
p0[i] = -static_cast<typename T::BaseType>(lo);
690+
p1[i] = static_cast<typename T::BaseType>(hi);
689691
}
690692
IMATH_INTERNAL_NAMESPACE::Box<T> b1 (p0, p1);
691693
assert (b1.center () == (p1 + p0) / 2);
@@ -737,8 +739,10 @@ testIsEmpty (const char* type)
737739
T p1;
738740
for (unsigned int i = 0; i < T::dimensions (); i++)
739741
{
740-
p0[i] = -typename T::BaseType (1 << (i + 1));
741-
p1[i] = typename T::BaseType (1 << (T::dimensions () - i));
742+
int lo = 1 << (i + 1);
743+
int hi = 1 << (T::dimensions () - i);
744+
p0[i] = -static_cast<typename T::BaseType>(lo);
745+
p1[i] = static_cast<typename T::BaseType>(hi);
742746
}
743747
IMATH_INTERNAL_NAMESPACE::Box<T> b1 (p0, p1);
744748
assert (!b1.isEmpty ());
@@ -791,8 +795,10 @@ testIsInfinite (const char* type)
791795
T p1;
792796
for (unsigned int i = 0; i < T::dimensions (); i++)
793797
{
794-
p0[i] = -typename T::BaseType (1 << (i + 1));
795-
p1[i] = typename T::BaseType (1 << (T::dimensions () - i));
798+
int lo = 1 << (i + 1);
799+
int hi = 1 << (T::dimensions () - i);
800+
p0[i] = -static_cast<typename T::BaseType>(lo);
801+
p1[i] = static_cast<typename T::BaseType>(hi);
796802
}
797803
IMATH_INTERNAL_NAMESPACE::Box<T> b1 (p0, p1);
798804
assert (!b1.isInfinite ());
@@ -853,8 +859,10 @@ testHasVolume (const char* type)
853859
T p1;
854860
for (unsigned int i = 0; i < T::dimensions (); i++)
855861
{
856-
p0[i] = -typename T::BaseType (1 << (i + 1));
857-
p1[i] = typename T::BaseType (1 << (T::dimensions () - i));
862+
int lo = 1 << (i + 1);
863+
int hi = 1 << (T::dimensions () - i);
864+
p0[i] = -static_cast<typename T::BaseType>(lo);
865+
p1[i] = static_cast<typename T::BaseType>(hi);
858866
}
859867
IMATH_INTERNAL_NAMESPACE::Box<T> b1 (p0, p1);
860868
assert (b1.hasVolume ());

src/ImathTest/testBoxAlgo.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ testEntryAndExitPoints (const Box3f& box)
5151
for (int i = 0; i < 100000; ++i)
5252
{
5353
V3f p1 (
54-
random.nextf (box.max.x, box.min.x),
55-
random.nextf (box.max.y, box.min.y),
56-
random.nextf (box.max.z, box.min.z));
54+
float(random.nextf (box.max.x, box.min.x)),
55+
float(random.nextf (box.max.y, box.min.y)),
56+
float(random.nextf (box.max.z, box.min.z)));
5757

5858
V3f p2 (p1 + hollowSphereRand<V3f> (random));
5959

@@ -99,8 +99,8 @@ testEntryAndExitPoints (const Box3f& box)
9999
// box, and it passes the box at a minimum distance of r1.
100100
//
101101

102-
const float r1 = 0.00001;
103-
const float r2 = 1.0;
102+
const float r1 = 0.00001f;
103+
const float r2 = 1.0f;
104104

105105
V3f p1 = box.min + r2 * hollowSphereRand<V3f> (random);
106106
V3f p2;
@@ -142,19 +142,19 @@ testEntryAndExitPoints (const Box3f& box)
142142
do
143143
{
144144
p1 = V3f (
145-
random.nextf (bigBox.min.x, bigBox.max.x),
146-
random.nextf (bigBox.min.y, bigBox.max.y),
147-
random.nextf (bigBox.min.z, bigBox.max.z));
145+
float(random.nextf (bigBox.min.x, bigBox.max.x)),
146+
float(random.nextf (bigBox.min.y, bigBox.max.y)),
147+
float(random.nextf (bigBox.min.z, bigBox.max.z)));
148148
} while (box.intersects (p1));
149149

150150
V3f p2;
151151

152152
do
153153
{
154154
p2 = V3f (
155-
random.nextf (box.min.x, box.max.x),
156-
random.nextf (box.min.y, box.max.y),
157-
random.nextf (box.min.z, box.max.z));
155+
float(random.nextf (box.min.x, box.max.x)),
156+
float(random.nextf (box.min.y, box.max.y)),
157+
float(random.nextf (box.min.z, box.max.z)));
158158
} while (approximatelyEqual (p1, p2, e));
159159

160160
Line3f ray (p1, p2);
@@ -423,9 +423,9 @@ testRayBoxIntersection (const Box3f& box)
423423
for (int i = 0; i < 100000; ++i)
424424
{
425425
V3f p1 (
426-
random.nextf (box.max.x, box.min.x),
427-
random.nextf (box.max.y, box.min.y),
428-
random.nextf (box.max.z, box.min.z));
426+
float(random.nextf (box.max.x, box.min.x)),
427+
float(random.nextf (box.max.y, box.min.y)),
428+
float(random.nextf (box.max.z, box.min.z)));
429429

430430
V3f p2 (p1 + hollowSphereRand<V3f> (random));
431431

@@ -471,8 +471,8 @@ testRayBoxIntersection (const Box3f& box)
471471
// box, and it passes the box at a minimum distance of r1.
472472
//
473473

474-
const float r1 = 0.00001;
475-
const float r2 = 1.0;
474+
const float r1 = 0.00001f;
475+
const float r2 = 1.0f;
476476

477477
V3f p1 = box.min + r2 * hollowSphereRand<V3f> (random);
478478
V3f p2;
@@ -504,9 +504,9 @@ testRayBoxIntersection (const Box3f& box)
504504
for (int i = 0; i < 1000; ++i)
505505
{
506506
V3f p1 (
507-
random.nextf (box.min.x, box.max.x),
508-
random.nextf (box.min.y, box.max.y),
509-
random.nextf (box.min.z, box.max.z));
507+
float(random.nextf (box.min.x, box.max.x)),
508+
float(random.nextf (box.min.y, box.max.y)),
509+
float(random.nextf (box.min.z, box.max.z)));
510510

511511
V3f p2 (p1 + hollowSphereRand<V3f> (random));
512512

@@ -531,19 +531,19 @@ testRayBoxIntersection (const Box3f& box)
531531
do
532532
{
533533
p1 = V3f (
534-
random.nextf (bigBox.min.x, bigBox.max.x),
535-
random.nextf (bigBox.min.y, bigBox.max.y),
536-
random.nextf (bigBox.min.z, bigBox.max.z));
534+
float(random.nextf (bigBox.min.x, bigBox.max.x)),
535+
float(random.nextf (bigBox.min.y, bigBox.max.y)),
536+
float(random.nextf (bigBox.min.z, bigBox.max.z)));
537537
} while (box.intersects (p1));
538538

539539
V3f p2;
540540

541541
do
542542
{
543543
p2 = V3f (
544-
random.nextf (box.min.x, box.max.x),
545-
random.nextf (box.min.y, box.max.y),
546-
random.nextf (box.min.z, box.max.z));
544+
float(random.nextf (box.min.x, box.max.x)),
545+
float(random.nextf (box.min.y, box.max.y)),
546+
float(random.nextf (box.min.z, box.max.z)));
547547
} while (approximatelyEqual (p1, p2, e));
548548

549549
Line3f ray (p1, p2);

src/ImathTest/testColor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ testColor ()
3838
assert (in3 == out3);
3939

4040
IMATH_INTERNAL_NAMESPACE::C4c testConstructor1;
41-
IMATH_INTERNAL_NAMESPACE::C4c testConstructor1i (0.f);
41+
IMATH_INTERNAL_NAMESPACE::C4c testConstructor1i (0);
4242
IMATH_INTERNAL_NAMESPACE::C4c testConstructor2 (testConstructor1i);
4343

4444
testConstructor1 =

src/ImathTest/testExtractEuler.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace
2424
float
2525
rad (float deg)
2626
{
27-
return deg * (M_PI / 180);
27+
return deg * float(M_PI / 180);
2828
}
2929

3030
M44f
@@ -103,9 +103,9 @@ testRandomAngles (
103103
//
104104

105105
Eulerf e (
106-
rad (r.nextf (-180, 180)),
107-
rad (r.nextf (-180, 180)),
108-
rad (r.nextf (-180, 180)),
106+
rad (float(r.nextf (-180, 180))),
107+
rad (float(r.nextf (-180, 180))),
108+
rad (float(r.nextf (-180, 180))),
109109
Eulerf::XYZ);
110110

111111
M44f M (e.toMatrix44 ());
@@ -116,7 +116,7 @@ testRandomAngles (
116116

117117
for (int j = 0; j < 3; ++j)
118118
for (int k = 0; k < 3; ++k)
119-
M[j][k] += r.nextf (-1e-7, 1e-7);
119+
M[j][k] += float(r.nextf (-1e-7, 1e-7));
120120

121121
//
122122
// Extract Euler angles from M, convert the Euler angles
@@ -176,19 +176,19 @@ test (
176176
for (int i = 0; i < 360; i += 90)
177177
for (int j = 0; j < 360; j += 90)
178178
for (int k = 0; k < 360; k += 90)
179-
testAngles (V3f (i, j, k), matrixEulerMatrix, order);
179+
testAngles (V3f (float(i), float(j), float(k)), matrixEulerMatrix, order);
180180
}
181181

182182
void
183183
testRandomAngles33 ()
184184
{
185185
Rand48 r (0);
186186

187-
float eps = 8.0 * std::numeric_limits<float>::epsilon ();
187+
float eps = 8.0f * std::numeric_limits<float>::epsilon ();
188188

189189
for (int i = 0; i < 100000; ++i)
190190
{
191-
float angle = rad (r.nextf (-180, 180));
191+
float angle = rad (float(r.nextf (-180, 180)));
192192

193193
M33f M;
194194
M.setRotation (angle);

0 commit comments

Comments
 (0)