also changes case/naming to agreed conventions in the utility components

This commit is contained in:
tosh 2013-03-29 11:54:09 +01:00
parent 2d997a9a8d
commit 1eb904ca59
7 changed files with 69 additions and 70 deletions

View file

@ -349,7 +349,7 @@ namespace starfield {
float slice = _objTiling.getSliceAngle();
unsigned stride = _objTiling.getAzimuthalTiles();
float azimuth = (i % stride) * slice;
float altitude = (i / stride) * slice - Radians::half_pi();
float altitude = (i / stride) * slice - Radians::halfPi();
float gx = sin(azimuth);
float gz = -cos(azimuth);
float exz = cos(altitude);

View file

@ -27,7 +27,7 @@ namespace starfield {
Tiling(unsigned k) :
_valK(k),
_valRcpSlice(k / Radians::twice_pi()) {
_valRcpSlice(k / Radians::twicePi()) {
_valBits = ceil(log2(getTileCount()));
}
@ -60,7 +60,7 @@ namespace starfield {
unsigned discreteAltitude(float a) const {
return min(getAltitudinalTiles() - 1,
discreteAngle(a + Radians::half_pi()) );
discreteAngle(a + Radians::halfPi()) );
}
};

View file

@ -13,23 +13,23 @@
struct Degrees
{
static float pi() { return 180.0f; }
static float twice_pi() { return 360.0f; }
static float half_pi() { return 90.0f; }
static float pi() { return 180.0f; }
static float twicePi() { return 360.0f; }
static float halfPi() { return 90.0f; }
};
struct Radians
{
static float pi() { return 3.141592653589793f; }
static float twice_pi() { return 6.283185307179586f; }
static float half_pi() { return 1.5707963267948966; }
static float pi() { return 3.141592653589793f; }
static float twicePi() { return 6.283185307179586f; }
static float halfPi() { return 1.5707963267948966; }
};
struct Rotations
{
static float pi() { return 0.5f; }
static float twice_pi() { return 1.0f; }
static float half_pi() { return 0.25f; }
static float pi() { return 0.5f; }
static float twicePi() { return 1.0f; }
static float halfPi() { return 0.25f; }
};
/**
@ -38,7 +38,7 @@ struct Rotations
template< class UnitFrom, class UnitTo >
float angleConvert(float a)
{
return a * (UnitTo::half_pi() / UnitFrom::half_pi());
return a * (UnitTo::halfPi() / UnitFrom::halfPi());
}
@ -48,7 +48,7 @@ float angleConvert(float a)
template< class Unit >
float angleSignedNormal(float a)
{
float result = remainder(a, Unit::twice_pi());
float result = remainder(a, Unit::twicePi());
if (result == Unit::pi())
result = -Unit::pi();
return result;
@ -75,12 +75,12 @@ template< class Unit >
void angleHorizontalPolar(float& azimuth, float& altitude)
{
altitude = angleSignedNormal<Unit>(altitude);
if (altitude > Unit::half_pi())
if (altitude > Unit::halfPi())
{
altitude = Unit::pi() - altitude;
azimuth += Unit::pi();
}
else if (altitude < -Unit::half_pi())
else if (altitude < -Unit::halfPi())
{
altitude = -Unit::pi() - altitude;
azimuth += Unit::pi();

View file

@ -36,7 +36,7 @@ struct floodFill_impl : Strategy
void go(Cursor position)
{
Cursor higher, lower, h,l, i;
bool higher_found, lower_found, hf, lf;
bool higherFound, lowerFound, hf, lf;
do
{
if (! select(position))
@ -44,18 +44,18 @@ struct floodFill_impl : Strategy
process(position);
higher = position; higher_found = false;
up(higher); yTest(higher, higher_found);
lower = position; lower_found = false;
down(lower); yTest(lower, lower_found);
higher = position; higherFound = false;
up(higher); yTest(higher, higherFound);
lower = position; lowerFound = false;
down(lower); yTest(lower, lowerFound);
i = position, h = higher, l = lower;
hf = higher_found, lf = lower_found;
hf = higherFound, lf = lowerFound;
do { right(i), right(h), right(l); yTest(h,hf); yTest(l,lf); }
while (selectAndProcess(i));
i = position, h = higher, l = lower;
hf = higher_found, lf = lower_found;
hf = higherFound, lf = lowerFound;
do { left(i); left(h); left(l); yTest(h,hf); yTest(l,lf); }
while (selectAndProcess(i));
}

View file

@ -41,20 +41,20 @@ class Radix2IntegerScanner;
template< typename UInt >
class Radix2IntegerScanner< UInt, false >
{
UInt msb;
UInt valMsb;
public:
Radix2IntegerScanner()
: msb(~UInt(0) &~ (~UInt(0) >> 1)) { }
: valMsb(~UInt(0) &~ (~UInt(0) >> 1)) { }
explicit Radix2IntegerScanner(int bits)
: msb(UInt(1u) << (bits - 1))
: valMsb(UInt(1u) << (bits - 1))
{ }
typedef UInt state_type;
state_type initial_state() const { return msb; }
state_type initial_state() const { return valMsb; }
bool advance(state_type& s) const { return (s >>= 1) != 0u; }
bool bit(UInt const& v, state_type const& s) const { return !!(v & s); }
@ -63,25 +63,24 @@ class Radix2IntegerScanner< UInt, false >
template< typename Int >
class Radix2IntegerScanner< Int, true >
{
typename type_traits::make_unsigned<Int>::type msb;
typename type_traits::make_unsigned<Int>::type valMsb;
public:
Radix2IntegerScanner()
: msb(~state_type(0u) &~ (~state_type(0u) >> 1))
: valMsb(~state_type(0u) &~ (~state_type(0u) >> 1))
{ }
explicit Radix2IntegerScanner(int bits)
: msb(state_type(1u) << (bits - 1))
: valMsb(state_type(1u) << (bits - 1))
{ }
typedef typename type_traits::make_unsigned<Int>::type state_type;
state_type initial_state() const { return msb; }
state_type initial_state() const { return valMsb; }
bool advance(state_type& s) const { return (s >>= 1) != 0u; }
bool bit(Int const& v, state_type const& s) const
{ return !!((v-msb) & s); }
bool bit(Int const& v, state_type const& s) const { return !!((v-valMsb) & s); }
};
#endif /* defined(__hifi__Radix2IntegerScanner__) */

View file

@ -20,15 +20,15 @@ char const* const UrlReader::error_aborted = "UrlReader: Processing err
char const* const UrlReader::error_buffer_overflow = "UrlReader: Buffer overflow.";
char const* const UrlReader::error_leftover_input = "UrlReader: Incomplete processing.";
#define hnd_curl static_cast<CURL*>(ptr_impl)
#define hnd_curl static_cast<CURL*>(_ptrImpl)
UrlReader::UrlReader()
: ptr_impl(0l), arr_xtra(0l), str_error(0l)
: _ptrImpl(0l), _arrXtra(0l), _strError(0l)
{
arr_xtra = new(std::nothrow) char[max_read_ahead];
if (! arr_xtra) { str_error = error_init_failed; return; }
ptr_impl = curl_easy_init();
if (! ptr_impl) { str_error = error_init_failed; return; }
_arrXtra = new(std::nothrow) char[max_read_ahead];
if (! _arrXtra) { _strError = error_init_failed; return; }
_ptrImpl = curl_easy_init();
if (! _ptrImpl) { _strError = error_init_failed; return; }
curl_easy_setopt(hnd_curl, CURLOPT_NOSIGNAL, 1l);
curl_easy_setopt(hnd_curl, CURLOPT_FAILONERROR, 1l);
curl_easy_setopt(hnd_curl, CURLOPT_FILETIME, 1l);
@ -36,7 +36,7 @@ UrlReader::UrlReader()
UrlReader::~UrlReader()
{
delete arr_xtra;
delete _arrXtra;
if (! hnd_curl) return;
curl_easy_cleanup(hnd_curl);
}
@ -51,11 +51,11 @@ bool UrlReader::perform(char const* url, transfer_callback* cb)
if (rc == CURLE_OK)
{
while (val_xtra_size_size > 0 && str_error == success)
while (_valXtraSize > 0 && _strError == success)
cb(0l, 0, 0, this);
}
else if (str_error == success)
str_error = curl_easy_strerror(rc);
else if (_strError == success)
_strError = curl_easy_strerror(rc);
return rc == CURLE_OK;
}

View file

@ -19,11 +19,11 @@
*/
class UrlReader
{
void* ptr_impl;
char* arr_xtra;
char const* str_error;
void* ptr_stream;
size_t val_xtra_size_size;
void* _ptrImpl;
char* _arrXtra;
char const* _strError;
void* _ptrStream;
size_t _valXtraSize;
public:
@ -151,21 +151,21 @@ class UrlReader
template< class ContentStream >
bool UrlReader::readUrl(char const* url, ContentStream& s)
{
if (! ptr_impl) return false;
str_error = success;
ptr_stream = & s;
val_xtra_size_size = ~size_t(0);
if (! _ptrImpl) return false;
_strError = success;
_ptrStream = & s;
_valXtraSize = ~size_t(0);
this->perform(url, & callback_template<ContentStream>);
s.end(str_error == success);
return str_error == success;
s.end(_strError == success);
return _strError == success;
}
inline char const* UrlReader::getError() const { return this->str_error; }
inline char const* UrlReader::getError() const { return this->_strError; }
inline void UrlReader::setError(char const* static_c_string)
{
if (this->str_error == success)
this->str_error = static_c_string;
if (this->_strError == success)
this->_strError = static_c_string;
}
template< class Stream >
@ -175,12 +175,12 @@ size_t UrlReader::callback_template(
size *= nmemb;
UrlReader* me = static_cast<UrlReader*>(thiz);
Stream* stream = static_cast<Stream*>(me->ptr_stream);
Stream* stream = static_cast<Stream*>(me->_ptrStream);
// first call?
if (me->val_xtra_size_size == ~size_t(0))
if (me->_valXtraSize == ~size_t(0))
{
me->val_xtra_size_size = 0u;
me->_valXtraSize = 0u;
// extract meta information and call 'begin'
char const* url, * type;
int64_t length, stardate;
@ -196,15 +196,15 @@ size_t UrlReader::callback_template(
size_t bytes = size - input_offset;
// data in extra buffer?
if (me->val_xtra_size_size > 0)
if (me->_valXtraSize > 0)
{
// fill extra buffer with beginning of input
size_t fill = max_read_ahead - me->val_xtra_size_size;
size_t fill = max_read_ahead - me->_valXtraSize;
if (bytes < fill) fill = bytes;
memcpy(me->arr_xtra + me->val_xtra_size_size, buffer, fill);
memcpy(me->_arrXtra + me->_valXtraSize, buffer, fill);
// use extra buffer for next transfer
buffer = me->arr_xtra;
bytes = me->val_xtra_size_size + fill;
buffer = me->_arrXtra;
bytes = me->_valXtraSize + fill;
input_offset += fill;
}
@ -223,9 +223,9 @@ size_t UrlReader::callback_template(
size_t unprocessed = bytes - processed;
// can switch to input buffer, now?
if (buffer == me->arr_xtra && unprocessed <= input_offset)
if (buffer == me->_arrXtra && unprocessed <= input_offset)
{
me->val_xtra_size_size = 0u;
me->_valXtraSize = 0u;
input_offset -= unprocessed;
}
else // no? unprocessed data -> extra buffer
@ -235,10 +235,10 @@ size_t UrlReader::callback_template(
me->setError(error_buffer_overflow);
return 0;
}
me->val_xtra_size_size = unprocessed;
memmove(me->arr_xtra, buffer + processed, unprocessed);
me->_valXtraSize = unprocessed;
memmove(me->_arrXtra, buffer + processed, unprocessed);
if (input_offset == size || buffer != me->arr_xtra)
if (input_offset == size || buffer != me->_arrXtra)
{
return size;
}