Format library

This commit is contained in:
Bertold Van den Bergh 2019-08-14 18:52:24 +02:00
parent 591a75df2f
commit 79da7aae0a
2 changed files with 179 additions and 159 deletions

View file

@ -95,7 +95,8 @@ static int32_t ZDFloatToFixedPoint(float input, float scale, unsigned int precis
return (int32_t)(inputScaled * (float)(1 << (precision - 1)));
}
static float ZDFixedPointToFloat(int32_t input, float scale, unsigned int precision){
static float ZDFixedPointToFloat(int32_t input, float scale, unsigned int precision)
{
const float value = (float)input / (float)(1 << (precision - 1));
return value * scale;
}
@ -143,7 +144,8 @@ static unsigned int ZDDecodeVariableLengthUnsigned(const ZoneDetect *library, ui
return i;
}
static unsigned int ZDDecodeVariableLengthUnsignedReverse(const ZoneDetect *library, uint32_t *index, uint64_t *result){
static unsigned int ZDDecodeVariableLengthUnsignedReverse(const ZoneDetect *library, uint32_t *index, uint64_t *result)
{
uint32_t i = *index;
if(*index >= (uint32_t)library->length) {
@ -187,7 +189,8 @@ static unsigned int ZDDecodeVariableLengthUnsignedReverse(const ZoneDetect *libr
return ZDDecodeVariableLengthUnsigned(library, &i2, result);
}
static int64_t ZDDecodeUnsignedToSigned(uint64_t value){
static int64_t ZDDecodeUnsignedToSigned(uint64_t value)
{
return (value & 1) ? -(int64_t)(value / 2) : (int64_t)(value / 2);
}
@ -326,7 +329,8 @@ static int ZDPointInBox(int32_t xl, int32_t x, int32_t xr, int32_t yl, int32_t y
return 0;
}
static void ZDDecodePoint(uint64_t point, int32_t* lat, int32_t* lon){
static void ZDDecodePoint(uint64_t point, int32_t* lat, int32_t* lon)
{
uint64_t latu = 0;
uint64_t lonu = 0;
@ -361,7 +365,8 @@ struct Reader{
int32_t firstLat, firstLon;
};
static void ZDReaderInit(struct Reader *reader, const ZoneDetect *library, uint32_t polygonIndex){
static void ZDReaderInit(struct Reader *reader, const ZoneDetect *library, uint32_t polygonIndex)
{
memset(reader, 0, sizeof(*reader));
reader->library = library;
@ -370,7 +375,8 @@ static void ZDReaderInit(struct Reader *reader, const ZoneDetect *library, uint3
reader->first = 1;
}
static int ZDReaderGetPoint(struct Reader *reader, int32_t *pointLat, int32_t *pointLon){
static int ZDReaderGetPoint(struct Reader *reader, int32_t *pointLat, int32_t *pointLon)
{
int32_t diffLat = 0, diffLon = 0;
readNewPoint:
@ -486,7 +492,8 @@ readNewPoint:
return 1;
}
static int ZDFindPolygon(const ZoneDetect *library, uint32_t wantedId, uint32_t* metadataIndexPtr, uint32_t* polygonIndexPtr){
static int ZDFindPolygon(const ZoneDetect *library, uint32_t wantedId, uint32_t* metadataIndexPtr, uint32_t* polygonIndexPtr)
{
uint32_t polygonId = 0;
uint32_t bboxIndex = library->bboxOffset;
@ -524,7 +531,8 @@ static int ZDFindPolygon(const ZoneDetect *library, uint32_t wantedId, uint32_t*
return 0;
}
static int32_t* ZDPolygonToListInternal(const ZoneDetect *library, uint32_t polygonIndex, size_t* length){
static int32_t* ZDPolygonToListInternal(const ZoneDetect *library, uint32_t polygonIndex, size_t* length)
{
struct Reader reader;
ZDReaderInit(&reader, library, polygonIndex);
@ -574,7 +582,8 @@ fail:
return NULL;
}
float* ZDPolygonToList(const ZoneDetect *library, uint32_t polygonId, size_t* lengthPtr){
float* ZDPolygonToList(const ZoneDetect *library, uint32_t polygonId, size_t* lengthPtr)
{
uint32_t polygonIndex;
int32_t* data = NULL;
float* flData = NULL;
@ -1051,19 +1060,30 @@ const char *ZDLookupResultToString(ZDLookupResult result)
const char *ZDGetErrorString(int errZD)
{
switch ((enum ZDInternalError)errZD) {
default: assert(0);
case ZD_OK : return "";
case ZD_E_DB_OPEN : return ZD_E_COULD_NOT("open database file");
case ZD_E_DB_SEEK : return ZD_E_COULD_NOT("retrieve database file size");
case ZD_E_DB_MMAP : return ZD_E_COULD_NOT("map database file to system memory");
default:
assert(0);
case ZD_OK :
return "";
case ZD_E_DB_OPEN :
return ZD_E_COULD_NOT("open database file");
case ZD_E_DB_SEEK :
return ZD_E_COULD_NOT("retrieve database file size");
case ZD_E_DB_MMAP :
return ZD_E_COULD_NOT("map database file to system memory");
#if defined(_MSC_VER) || defined(__MINGW32__)
case ZD_E_DB_MMAP_MSVIEW : return ZD_E_COULD_NOT("open database file view");
case ZD_E_DB_MAP_EXCEPTION: return "I/O exception occurred while accessing database file view";
case ZD_E_DB_MUNMAP_MSVIEW: return ZD_E_COULD_NOT("close database file view");
case ZD_E_DB_MMAP_MSVIEW :
return ZD_E_COULD_NOT("open database file view");
case ZD_E_DB_MAP_EXCEPTION:
return "I/O exception occurred while accessing database file view";
case ZD_E_DB_MUNMAP_MSVIEW:
return ZD_E_COULD_NOT("close database file view");
#endif
case ZD_E_DB_MUNMAP : return ZD_E_COULD_NOT("unmap database");
case ZD_E_DB_CLOSE : return ZD_E_COULD_NOT("close database file");
case ZD_E_PARSE_HEADER : return ZD_E_COULD_NOT("parse database header");
case ZD_E_DB_MUNMAP :
return ZD_E_COULD_NOT("unmap database");
case ZD_E_DB_CLOSE :
return ZD_E_COULD_NOT("close database file");
case ZD_E_PARSE_HEADER :
return ZD_E_COULD_NOT("parse database header");
}
}