Browse Source

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.
Vladimír Vondruš 13 years ago
parent
commit
36ac4de5c4
  1. 2
      src/Color.h
  2. 8
      src/Math/Test/UnitTest.cpp
  3. 11
      src/Math/Unit.h
  4. 8
      src/Primitives/Capsule.cpp
  5. 2
      src/Primitives/Cylinder.cpp
  6. 2
      src/Primitives/UVSphere.cpp

2
src/Color.h

@ -46,7 +46,7 @@ template<class T> inline typename std::enable_if<std::is_floating_point<T>::valu
std::tie(hue, saturation, value) = hsv;
/* Remove repeats */
hue -= int(T(hue)/T(360))*Math::Deg<T>(360);
hue -= Math::Deg<T>(int(T(hue)/T(360))*T(360));
if(hue < Math::Deg<T>(0)) hue += Math::Deg<T>(360);
int h = int(T(hue)/T(60)) % 6;

8
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);

11
src/Math/Unit.h

@ -54,7 +54,11 @@ template<template<class> class Derived, class T> class Unit {
template<class U> inline constexpr explicit Unit(Unit<Derived, U> 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<Derived, T> other) const {
@ -113,6 +117,9 @@ template<template<class> class Derived, class T> class Unit {
return Unit<Derived, T>(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<Derived, T>& operator*=(T number) {
value *= number;
@ -139,17 +146,21 @@ template<template<class> class Derived, class T> class Unit {
inline constexpr T operator/(Unit<Derived, T> 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<template<class> class Derived, class T> inline constexpr Unit<Derived, T> operator*(typename std::common_type<T>::type number, const Unit<Derived, T>& value) {
return value*number;
}
#endif
}}

8
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)});

2
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);

2
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);

Loading…
Cancel
Save