From 36ac4de5c4ae2af654c3490f5b25c20e086258b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Mar 2013 22:18:15 +0100 Subject: [PATCH] GCC 4.4 compatibility: no explicit conv op on Unit and related issues. Using Deg/Rad on GCC 4.4 will be bigger PITA than I thought. --- src/Color.h | 2 +- src/Math/Test/UnitTest.cpp | 8 ++++++++ src/Math/Unit.h | 11 +++++++++++ src/Primitives/Capsule.cpp | 8 ++++---- src/Primitives/Cylinder.cpp | 2 +- src/Primitives/UVSphere.cpp | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Color.h b/src/Color.h index 74b634d84..5900c8b04 100644 --- a/src/Color.h +++ b/src/Color.h @@ -46,7 +46,7 @@ template inline typename std::enable_if::valu std::tie(hue, saturation, value) = hsv; /* Remove repeats */ - hue -= int(T(hue)/T(360))*Math::Deg(360); + hue -= Math::Deg(int(T(hue)/T(360))*T(360)); if(hue < Math::Deg(0)) hue += Math::Deg(360); int h = int(T(hue)/T(60)) % 6; diff --git a/src/Math/Test/UnitTest.cpp b/src/Math/Test/UnitTest.cpp index d1d687a9a..9b05833e5 100644 --- a/src/Math/Test/UnitTest.cpp +++ b/src/Math/Test/UnitTest.cpp @@ -131,9 +131,17 @@ void UnitTest::multiplyDivide() { constexpr Sec b(-4.5f); constexpr Sec c(5.0f); + /* The operation returns underlying type on GCC 4.4 because of non-explicit + conversion operators and conflicts with builtin operators */ + #ifndef CORRADE_GCC44_COMPATIBILITY constexpr Sec d = a*-1.5f; constexpr Sec e = -1.5f*a; constexpr Sec f = b/-1.5f; + #else + constexpr Sec d(a*-1.5f); + constexpr Sec e(-1.5f*a); + constexpr Sec f(b/-1.5f); + #endif CORRADE_COMPARE(d, b); CORRADE_COMPARE(e, b); CORRADE_COMPARE(f, a); diff --git a/src/Math/Unit.h b/src/Math/Unit.h index 7a586ec6e..0be16e18e 100644 --- a/src/Math/Unit.h +++ b/src/Math/Unit.h @@ -54,7 +54,11 @@ template class Derived, class T> class Unit { template inline constexpr explicit Unit(Unit value): value(value.value) {} /** @brief Explicit conversion to underlying type */ + #ifndef CORRADE_GCC44_COMPATIBILITY inline constexpr explicit operator T() const { return value; } + #else + inline constexpr operator T() const { return value; } + #endif /** @brief Equality comparison */ inline constexpr bool operator==(Unit other) const { @@ -113,6 +117,9 @@ template class Derived, class T> class Unit { return Unit(value - other.value); } + /* These are conflicting with builtin operators because of non-explicit + conversion to T */ + #ifndef CORRADE_GCC44_COMPATIBILITY /** @brief Multiply with number and assign */ inline Unit& operator*=(T number) { value *= number; @@ -139,17 +146,21 @@ template class Derived, class T> class Unit { inline constexpr T operator/(Unit other) const { return value/other.value; } + #endif private: T value; }; +/* This is conflicting with builtin operator because of non-explicit conversion to T */ +#ifndef CORRADE_GCC44_COMPATIBILITY /** @relates Unit @brief Multiply number with value */ template class Derived, class T> inline constexpr Unit operator*(typename std::common_type::type number, const Unit& value) { return value*number; } +#endif }} diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index e35ecb34f..51eed80ea 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -40,7 +40,7 @@ Capsule::Capsule(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, Unsigne capVertex(-height/2, -1.0f, 0.0f); /* Rings of bottom hemisphere */ - hemisphereVertexRings(hemisphereRings-1, -length/2, -Rad(Constants::pi())/2+hemisphereRingAngleIncrement, hemisphereRingAngleIncrement, hemisphereTextureCoordsVIncrement, hemisphereTextureCoordsVIncrement); + hemisphereVertexRings(hemisphereRings-1, -length/2, -Rad(Constants::pi()/2)+hemisphereRingAngleIncrement, hemisphereRingAngleIncrement, hemisphereTextureCoordsVIncrement, hemisphereTextureCoordsVIncrement); /* Rings of cylinder */ cylinderVertexRings(cylinderRings+1, -length/2, length/cylinderRings, 1.0f/height, length/(cylinderRings*height)); @@ -71,12 +71,12 @@ void Capsule::hemisphereVertexRings(UnsignedInt count, Float centerY, Rad startR Rad segmentAngleIncrement(2*Constants::pi()/segments); Float x, y, z; for(UnsignedInt i = 0; i != count; ++i) { - Rad ringAngle = startRingAngle + i*ringAngleIncrement; + Rad ringAngle = startRingAngle + Rad(i*ringAngleIncrement); x = z = Math::cos(ringAngle); y = Math::sin(ringAngle); for(UnsignedInt j = 0; j != segments; ++j) { - Rad segmentAngle = j*segmentAngleIncrement; + Rad segmentAngle(j*segmentAngleIncrement); positions(0)->push_back({x*Math::sin(segmentAngle), centerY+y, z*Math::cos(segmentAngle)}); normals(0)->push_back({x*Math::sin(segmentAngle), y, z*Math::cos(segmentAngle)}); @@ -97,7 +97,7 @@ void Capsule::cylinderVertexRings(UnsignedInt count, Float startY, Float yIncrem Rad segmentAngleIncrement(2*Constants::pi()/segments); for(UnsignedInt i = 0; i != count; ++i) { for(UnsignedInt j = 0; j != segments; ++j) { - Rad segmentAngle = j*segmentAngleIncrement; + Rad segmentAngle(j*segmentAngleIncrement); positions(0)->push_back({Math::sin(segmentAngle), startY, Math::cos(segmentAngle)}); normals(0)->push_back({Math::sin(segmentAngle), 0.0f, Math::cos(segmentAngle)}); diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index 691e5402b..3d6ff6e58 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -60,7 +60,7 @@ void Cylinder::capVertexRing(Float y, Float textureCoordsV, const Vector3& norma Rad segmentAngleIncrement(2*Constants::pi()/segments); for(UnsignedInt i = 0; i != segments; ++i) { - Rad segmentAngle = i*segmentAngleIncrement; + Rad segmentAngle(i*segmentAngleIncrement); positions(0)->push_back({Math::sin(segmentAngle), y, Math::cos(segmentAngle)}); normals(0)->push_back(normal); diff --git a/src/Primitives/UVSphere.cpp b/src/Primitives/UVSphere.cpp index b6cde4ca3..f2591633c 100644 --- a/src/Primitives/UVSphere.cpp +++ b/src/Primitives/UVSphere.cpp @@ -38,7 +38,7 @@ UVSphere::UVSphere(UnsignedInt rings, UnsignedInt segments, TextureCoords textur capVertex(-1.0f, -1.0f, 0.0f); /* Vertex rings */ - hemisphereVertexRings(rings-1, 0.0f, -Rad(Constants::pi())/2+ringAngleIncrement, ringAngleIncrement, textureCoordsVIncrement, textureCoordsVIncrement); + hemisphereVertexRings(rings-1, 0.0f, -Rad(Constants::pi()/2)+ringAngleIncrement, ringAngleIncrement, textureCoordsVIncrement, textureCoordsVIncrement); /* Top cap vertex */ capVertex(1.0f, 1.0f, 1.0f);