From e4969e60cbcceab5d51c79f4ffbdcca4b23a5471 Mon Sep 17 00:00:00 2001 From: Samuel Surtees Date: Wed, 16 Nov 2022 15:00:07 +1000 Subject: [PATCH] Added .clang-format files to the repo --- .clang-format | 33 + 3rdParty/.clang-format | 2 + Include/udAsyncJob.h | 26 +- Include/udCallback.h | 74 +- Include/udChunkedArray.h | 44 +- Include/udCompression.h | 4 +- Include/udCrypto.h | 13 +- Include/udDebug.h | 188 +-- Include/udFile.h | 10 +- Include/udFileHandler.h | 10 +- Include/udGeoZone.h | 135 +- Include/udImage.h | 18 +- Include/udJSON.h | 58 +- Include/udJSON_Inl.h | 86 +- Include/udMath.h | 1077 ++++++++++----- Include/udMath_Inl.h | 828 +++++++----- Include/udNew.h | 10 +- Include/udPlatform.h | 388 +++--- Include/udPlatformUtil.h | 118 +- Include/udResult.h | 83 +- Include/udSafeDeque.h | 2 +- Include/udSocket.h | 2 +- Include/udStringUtil.h | 57 +- Include/udThread.h | 25 +- Include/udUUID.h | 19 +- Include/udWorkerPool.h | 2 +- Source/udAsyncJob.cpp | 14 +- Source/udCompression.cpp | 227 ++-- Source/udCrc.cpp | 94 +- Source/udCrypto.cpp | 271 ++-- Source/udDebug.cpp | 23 +- Source/udFile.cpp | 80 +- Source/udFileHandler_Data.cpp | 8 +- Source/udFileHandler_EmscriptenHTTP.cpp | 12 +- Source/udFileHandler_FILE.cpp | 62 +- Source/udFileHandler_HTTP.cpp | 46 +- Source/udFileHandler_Raw.cpp | 28 +- Source/udGeoZone.cpp | 1592 +++++++++++------------ Source/udImage.cpp | 14 +- Source/udIntersectionTest.cpp | 200 ++- Source/udJSON.cpp | 525 ++++---- Source/udPlatform.cpp | 66 +- Source/udPlatformUtil.cpp | 227 ++-- Source/udResult.cpp | 19 +- Source/udSocket.cpp | 78 +- Source/udStringUtil.cpp | 349 ++--- Source/udThread.cpp | 177 +-- Source/udUUID.cpp | 26 +- Source/udWorkerPool.cpp | 6 +- udTest/src/main.cpp | 22 +- udTest/src/udBlankTests.cpp | 2 +- udTest/src/udCallbackTests.cpp | 26 +- udTest/src/udChunkedArrayTests.cpp | 37 +- udTest/src/udCompressionTests.cpp | 47 +- udTest/src/udCryptoTests.cpp | 115 +- udTest/src/udDebugTests.cpp | 7 +- udTest/src/udFileTests.cpp | 60 +- udTest/src/udFilenameTests.cpp | 8 +- udTest/src/udGeoZoneTests.cpp | 315 +++-- udTest/src/udImageTests.cpp | 4 +- udTest/src/udJSONTests.cpp | 24 +- udTest/src/udMathTests.cpp | 138 +- udTest/src/udMemoryTests.cpp | 4 +- udTest/src/udResultTests.cpp | 7 +- udTest/src/udSafeDequeTests.cpp | 2 +- udTest/src/udSocketTests.cpp | 16 +- udTest/src/udStrTests.cpp | 35 +- udTest/src/udThreadTests.cpp | 46 +- udTest/src/udUUIDTests.cpp | 2 +- udTest/src/udWorkerPoolTests.cpp | 12 +- 70 files changed, 4765 insertions(+), 3620 deletions(-) create mode 100644 .clang-format create mode 100644 3rdParty/.clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..266f93c5 --- /dev/null +++ b/.clang-format @@ -0,0 +1,33 @@ +UseTab: Never +IndentWidth: 2 +Language: Cpp +DerivePointerAlignment: false +PointerAlignment: Right +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: true + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +IndentCaseLabels: true +AttributeMacros: [UD_PRINTF_FORMAT_FUNC(1)] +ColumnLimit: 0 +IndentPPDirectives: AfterHash +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AlignConsecutiveMacros: true +Cpp11BracedListStyle: false diff --git a/3rdParty/.clang-format b/3rdParty/.clang-format new file mode 100644 index 00000000..a43d914e --- /dev/null +++ b/3rdParty/.clang-format @@ -0,0 +1,2 @@ +DisableFormat: true +SortIncludes: false \ No newline at end of file diff --git a/Include/udAsyncJob.h b/Include/udAsyncJob.h index 98f9bfde..f0dfe601 100644 --- a/Include/udAsyncJob.h +++ b/Include/udAsyncJob.h @@ -9,9 +9,9 @@ // with the caller able to either poll or wait for completion at a later time // +#include "udPlatformUtil.h" #include "udResult.h" #include "udThread.h" -#include "udPlatformUtil.h" // A simple interface to allow function calls to be easily made optionally background calls with one additional parameter @@ -20,8 +20,8 @@ struct udAsyncJob; // A helper for pausing ASync jobs, ensure all fields are zero to be initialised into non-paused state struct udAsyncPause { - udSemaphore *volatile pSema; // Created locked by initiator of pause, released and destroyed by handler of pause when incremented to release pause - udResult errorCausingPause; // If an error condition (eg disk full) initiated a pause, the error code is here + udSemaphore *volatile pSema; // Created locked by initiator of pause, released and destroyed by handler of pause when incremented to release pause + udResult errorCausingPause; // If an error condition (eg disk full) initiated a pause, the error code is here enum Context { EC_None, @@ -69,14 +69,16 @@ const char *udAsyncPause_GetErrorContextString(udAsyncPause::Context errorContex // Some helper macros for boiler-plate code generation, each macro corresponds to number of parameters before pAsyncJob // For these macros to work, udAsyncJob *pAsyncJob must be the LAST PARAMETER of the function -#define UDASYNC_CALL(funcCall) if (pAsyncJob) { \ - udThreadStart udajStartFunc = [=](void *) -> unsigned int \ - { \ - udAsyncJob_SetResult(pAsyncJob, funcCall); \ - return 0; \ - }; \ - udAsyncJob_SetPending(pAsyncJob); \ - return udThread_Create(nullptr, udajStartFunc, nullptr, udTCF_None, __FUNC_NAME__); \ -} +#define UDASYNC_CALL(funcCall) \ + if (pAsyncJob) \ + { \ + udThreadStart udajStartFunc = [=](void *) -> unsigned int \ + { \ + udAsyncJob_SetResult(pAsyncJob, funcCall); \ + return 0; \ + }; \ + udAsyncJob_SetPending(pAsyncJob); \ + return udThread_Create(nullptr, udajStartFunc, nullptr, udTCF_None, __FUNC_NAME__); \ + } #endif // UDASYNCJOB_H diff --git a/Include/udCallback.h b/Include/udCallback.h index ee3e8bf0..e45b506c 100644 --- a/Include/udCallback.h +++ b/Include/udCallback.h @@ -9,23 +9,23 @@ // #include "udNew.h" -#include #include +#include -template +template struct udAbstractCallback; -template +template struct udAbstractCallback { virtual Result call(Args... args) const = 0; virtual ~udAbstractCallback() = default; }; -template +template struct udConcreteCallback; -template +template struct udConcreteCallback : udAbstractCallback { T callback; @@ -33,22 +33,37 @@ struct udConcreteCallback : udAbstractCallback +template struct udCallback; -template +template struct udCallback { uint8_t buffer[256]; udAbstractCallback *pPtr; - udCallback() noexcept : buffer(), pPtr(nullptr) { } - udCallback(std::nullptr_t) noexcept : buffer(), pPtr(nullptr) { } + udCallback() noexcept : buffer(), pPtr(nullptr) {} + udCallback(std::nullptr_t) noexcept : buffer(), pPtr(nullptr) {} - udCallback(const udCallback &other) { memcpy(buffer, other.buffer, sizeof(buffer)); if (other.pPtr) pPtr = (decltype(pPtr))buffer; else pPtr = nullptr; }; - udCallback(udCallback &&other) noexcept { memmove(buffer, other.buffer, sizeof(buffer)); if (other.pPtr) pPtr = (decltype(pPtr))buffer; else pPtr = nullptr; other.pPtr = nullptr; } + udCallback(const udCallback &other) + { + memcpy(buffer, other.buffer, sizeof(buffer)); + if (other.pPtr) + pPtr = (decltype(pPtr))buffer; + else + pPtr = nullptr; + }; + udCallback(udCallback &&other) noexcept + { + memmove(buffer, other.buffer, sizeof(buffer)); + if (other.pPtr) + pPtr = (decltype(pPtr))buffer; + else + pPtr = nullptr; + other.pPtr = nullptr; + } - template + template udCallback(T callback) { UDCOMPILEASSERT(sizeof(T) <= sizeof(buffer), "Provided function is larger than buffer!"); @@ -56,12 +71,37 @@ struct udCallback pPtr = new (buffer) udCallbackT(std::move(callback)); } - ~udCallback() { if (pPtr) pPtr->~udAbstractCallback(); } + ~udCallback() + { + if (pPtr) + pPtr->~udAbstractCallback(); + } - udCallback &operator=(const udCallback &other) { memcpy(buffer, other.buffer, sizeof(buffer)); if (other.pPtr) pPtr = (decltype(pPtr))buffer; else pPtr = nullptr; return *this; } - udCallback &operator=(udCallback &&other) noexcept { memmove(buffer, other.buffer, sizeof(buffer)); if (other.pPtr) pPtr = (decltype(pPtr))buffer; else pPtr = nullptr; other.pPtr = nullptr; return *this; } - udCallback &operator=(std::nullptr_t) noexcept { pPtr = nullptr; return *this; } - template + udCallback &operator=(const udCallback &other) + { + memcpy(buffer, other.buffer, sizeof(buffer)); + if (other.pPtr) + pPtr = (decltype(pPtr))buffer; + else + pPtr = nullptr; + return *this; + } + udCallback &operator=(udCallback &&other) noexcept + { + memmove(buffer, other.buffer, sizeof(buffer)); + if (other.pPtr) + pPtr = (decltype(pPtr))buffer; + else + pPtr = nullptr; + other.pPtr = nullptr; + return *this; + } + udCallback &operator=(std::nullptr_t) noexcept + { + pPtr = nullptr; + return *this; + } + template udCallback &operator=(T callback) { UDCOMPILEASSERT(sizeof(T) <= sizeof(buffer), "Provided function is larger than buffer!"); diff --git a/Include/udChunkedArray.h b/Include/udChunkedArray.h index a58609c7..23bcbb52 100644 --- a/Include/udChunkedArray.h +++ b/Include/udChunkedArray.h @@ -21,8 +21,8 @@ struct udChunkedArrayIterator using iterator_category = std::random_access_iterator_tag; using difference_type = ptrdiff_t; using value_type = T; - using pointer = T*; - using reference = T&; + using pointer = T *; + using reference = T &; udChunkedArrayIterator(T **ppChunks, size_t inset, size_t chunkElementCount, size_t chunkElementCountShift, size_t chunkElementCountMask, size_t startInd); @@ -53,7 +53,6 @@ struct udChunkedArrayIterator bool operator==(const udChunkedArrayIterator &rhs) const; }; - template struct udChunkedArray { @@ -68,20 +67,20 @@ struct udChunkedArray size_t FindIndex(const T &element, size_t compareLen = sizeof(T)) const; // Linear search for matching element (first compareLen bytes compared) void SetElement(size_t index, const T &data); - udResult PushBack(const T &v); // Push a copy of v to the back of the array, can fail if memory allocation fails - udResult PushBack(T **ppElement, bool zeroMemory = true); // Get pointer to new element at back of the array, can fail if memory allocation fails when growing array - T *PushBack(); // Get pointer to new zeroed element at back of the array, or NULL on failure + udResult PushBack(const T &v); // Push a copy of v to the back of the array, can fail if memory allocation fails + udResult PushBack(T **ppElement, bool zeroMemory = true); // Get pointer to new element at back of the array, can fail if memory allocation fails when growing array + T *PushBack(); // Get pointer to new zeroed element at back of the array, or NULL on failure - udResult PushFront(const T &v); // Push a copy of v to the front of the array, can fail if memory allocation fails - udResult PushFront(T **ppElement, bool zeroMemory = true); // Get pointer to new element at front of the array, can fail if memory allocation fails when growing array - T *PushFront(); // Get pointer to new zeroed element at front of the array, or NULL on failure + udResult PushFront(const T &v); // Push a copy of v to the front of the array, can fail if memory allocation fails + udResult PushFront(T **ppElement, bool zeroMemory = true); // Get pointer to new element at front of the array, can fail if memory allocation fails when growing array + T *PushFront(); // Get pointer to new zeroed element at front of the array, or NULL on failure - udResult Insert(size_t index, const T *pData = nullptr); // Insert the element at index, pushing and moving all elements after to make space. + udResult Insert(size_t index, const T *pData = nullptr); // Insert the element at index, pushing and moving all elements after to make space. - bool PopBack(T *pData = nullptr); // Returns false if no element to pop - bool PopFront(T *pData = nullptr); // Returns false if no element to pop - void RemoveAt(size_t index); // Remove the element at index, moving all elements after to fill the gap. - void RemoveSwapLast(size_t index); // Remove the element at index, swapping with the last element to ensure array is contiguous + bool PopBack(T *pData = nullptr); // Returns false if no element to pop + bool PopFront(T *pData = nullptr); // Returns false if no element to pop + void RemoveAt(size_t index); // Remove the element at index, moving all elements after to fill the gap. + void RemoveSwapLast(size_t index); // Remove the element at index, swapping with the last element to ensure array is contiguous udResult ToArray(T *pArray, size_t arrayLength, size_t startIndex = 0, size_t count = 0) const; // Copy elements to an array supplied by caller udResult ToArray(T **ppArray, size_t startIndex = 0, size_t count = 0) const; // Copy elements to an array allocated and returned to caller @@ -101,7 +100,10 @@ struct udChunkedArray iterator begin(); iterator end(); - enum { ptrArrayInc = 32 }; + enum + { + ptrArrayInc = 32 + }; T **ppChunks; size_t ptrArraySize; @@ -148,7 +150,7 @@ inline udChunkedArrayIterator &udChunkedArrayIterator::operator+=(const di //index within the chunk adjusting for block size difference_type newInd = (rawInd < 0 ? (difference_type)chunkElementCount : 0) + rawInd % (difference_type)chunkElementCount; // change in chunk index - difference_type chunkChange = (rawInd < 0 ? -1 : 0) + rawInd / (difference_type)chunkElementCount; + difference_type chunkChange = (rawInd < 0 ? -1 : 0) + rawInd / (difference_type)chunkElementCount; ppCurrChunk += chunkChange; currChunkElementIndex = newInd; @@ -205,7 +207,7 @@ bool udChunkedArrayIterator::operator!=(const udChunkedArrayIterator &rhs) return !(*this == rhs); } -template +template typename udChunkedArrayIterator::reference udChunkedArrayIterator::operator[](const size_t &a) const { return *(*this + a); @@ -474,7 +476,7 @@ inline udResult udChunkedArray::PushBack(T **ppElement, bool zeroMemory) *ppElement = ppChunks[chunkIndex] + (newIndex & chunkElementCountMask); if (zeroMemory) - memset((void*)*ppElement, 0, sizeof(T)); + memset((void *)*ppElement, 0, sizeof(T)); ++length; return udR_Success; @@ -563,7 +565,7 @@ inline udResult udChunkedArray::PushFront(T **ppElement, bool zeroMemory) *ppElement = ppChunks[0] + inset; if (zeroMemory) - memset((void*)*ppElement, 0, sizeof(T)); + memset((void *)*ppElement, 0, sizeof(T)); return udR_Success; } @@ -783,7 +785,7 @@ inline udResult udChunkedArray::Insert(size_t index, const T *pData) if (result != udR_Success) return result; - for (size_t dst = length - 1; dst > index; ) + for (size_t dst = length - 1; dst > index;) { size_t src = dst - 1; size_t srcBackRunLen = GetElementRunLength(src, true); @@ -837,7 +839,7 @@ inline typename udChunkedArray::iterator udChunkedArray::end() return udChunkedArrayIterator(this->ppChunks, this->inset, this->chunkElementCount, this->chunkElementCountShift, this->chunkElementCountMask, this->length); } -template +template udChunkedArrayIterator::udChunkedArrayIterator(T **ppChunks, size_t inset, size_t chunkElementCount, size_t chunkElementCountShift, size_t chunkElementCountMask, size_t startInd) { this->ppCurrChunk = &ppChunks[(inset + startInd) >> chunkElementCountShift]; diff --git a/Include/udCompression.h b/Include/udCompression.h index 60bdcbb9..7e4d9b07 100644 --- a/Include/udCompression.h +++ b/Include/udCompression.h @@ -12,8 +12,8 @@ enum udCompressionType { - udCT_None, // No compression (performs a udMemDup) - udCT_RawDeflate, // Raw deflate compression + udCT_None, // No compression (performs a udMemDup) + udCT_RawDeflate, // Raw deflate compression udCT_ZlibDeflate, // Deflate compression with zlib header and footer udCT_GzipDeflate, // Deflate compression with gzip header and footer diff --git a/Include/udCrypto.h b/Include/udCrypto.h index 8171d01b..ab9fbacd 100644 --- a/Include/udCrypto.h +++ b/Include/udCrypto.h @@ -47,14 +47,14 @@ enum udCryptoCipherKeyLength enum udCryptoPaddingMode { udCPM_None, - udCPM_PKCS7, // PKCS5 is identical but was only defined for 8-byte block ciphers + udCPM_PKCS7, // PKCS5 is identical but was only defined for 8-byte block ciphers }; enum udCryptoChainMode { - udCCM_None, // Sentinal meaning no chaining mode has been set yet - udCCM_CBC, // Sequential access, requires IV unique to each call to encrypt - udCCM_CTR, // Random access, requires a nonce unique to file + udCCM_None, // Sentinal meaning no chaining mode has been set yet + udCCM_CBC, // Sequential access, requires IV unique to each call to encrypt + udCCM_CTR, // Random access, requires a nonce unique to file }; struct udCryptoCipherContext; @@ -79,7 +79,6 @@ udResult udCryptoCipher_Destroy(udCryptoCipherContext **ppCtx); // Internal self-test udResult udCryptoCipher_SelfTest(udCryptoCiphers cipher); - // **** Hash algorithms **** enum udCryptoHashes @@ -101,7 +100,6 @@ enum udCryptoHashLength udCHL_MaxHashLength = udCHL_SHA512Length }; - struct udCryptoHashContext; // Initialise a hash @@ -125,7 +123,6 @@ udResult udCryptoHash_HMAC(udCryptoHashes hash, const char *pKeyBase64, const vo // Internal self-test udResult udCryptoHash_SelfTest(udCryptoHashes hash); - // **** Key derivation/exchange functions, generated keys are encoded into a string **** struct udCryptoDHMContext; @@ -180,7 +177,7 @@ enum udCryptoSigType enum udCryptoSigPadScheme { - udCSPS_Deterministic // A deterministic signature that doesn't require entropy. For RSA PKCS #1.5 + udCSPS_Deterministic // A deterministic signature that doesn't require entropy. For RSA PKCS #1.5 }; // Generate a random key-pair diff --git a/Include/udDebug.h b/Include/udDebug.h index bda23a9e..10877662 100644 --- a/Include/udDebug.h +++ b/Include/udDebug.h @@ -12,7 +12,8 @@ #include "udResult.h" // Outputs a string to debug console -UD_PRINTF_FORMAT_FUNC(1) void udDebugPrintf(const char *format, ...); +UD_PRINTF_FORMAT_FUNC(1) +void udDebugPrintf(const char *format, ...); // Optional, set this pointer to redirect debug printfs extern void (*gpudDebugPrintfOutputCallback)(const char *pString); @@ -22,7 +23,8 @@ class udTrace public: udTrace(const char *, int traceLevel); ~udTrace(); - UD_PRINTF_FORMAT_FUNC(1) static void Message(const char *pFormat, ...); // Print a message at the indentation level of the current trace + UD_PRINTF_FORMAT_FUNC(1) + static void Message(const char *pFormat, ...); // Print a message at the indentation level of the current trace static void ShowCallstack(); const char *functionName; @@ -37,131 +39,161 @@ class udTrace }; template -inline void udTrace_Variable(const char *pName, const T *value, int line) { udTrace::Message("%s = %p (line#=%d)", pName, value, line); } -inline void udTrace_Variable(const char *pName, udResult value, int line) { udTrace::Message("%s = udR_%s (line#=%d)", pName, udResultAsString(value), line); } -inline void udTrace_Variable(const char *pName, const char *value, int line) { udTrace::Message("%s = '%s' (line#=%d)", pName, value, line); } -inline void udTrace_Variable(const char *pName, int value, int line) { udTrace::Message("%s = %d/0x%x (int, line#=%d)", pName, value, value, line); } -inline void udTrace_Variable(const char *pName, int64_t value, int line) { udTrace::Message("%s = %" PRId64 "/0x%" PRIx64 " (int64, line#=%d)", pName, value, value, line); } -inline void udTrace_Variable(const char *pName, unsigned value, int line) { udTrace::Message("%s = %u/0x%x (int, line#=%d)", pName, value, value, line); } -inline void udTrace_Variable(const char *pName, uint64_t value, int line) { udTrace::Message("%s = %" PRIu64 "/0x%" PRIx64 " (int64, line#=%d)", pName, value, value, line); } -inline void udTrace_Variable(const char *pName, float value, int line) { udTrace::Message("%s = %f (float, line#=%d)", pName, value, line); } -inline void udTrace_Variable(const char *pName, double value, int line) { udTrace::Message("%s = %lf (double line#=%d)", pName, value, line); } -inline void udTrace_Variable(const char *pName, bool value, int line) { udTrace::Message("%s = %s (line#=%d)", pName, value ? "true" : "false", line); } +inline void udTrace_Variable(const char *pName, const T *value, int line) { udTrace::Message("%s = %p (line#=%d)", pName, value, line); } +inline void udTrace_Variable(const char *pName, udResult value, int line) { udTrace::Message("%s = udR_%s (line#=%d)", pName, udResultAsString(value), line); } +inline void udTrace_Variable(const char *pName, const char *value, int line) { udTrace::Message("%s = '%s' (line#=%d)", pName, value, line); } +inline void udTrace_Variable(const char *pName, int value, int line) { udTrace::Message("%s = %d/0x%x (int, line#=%d)", pName, value, value, line); } +inline void udTrace_Variable(const char *pName, int64_t value, int line) { udTrace::Message("%s = %" PRId64 "/0x%" PRIx64 " (int64, line#=%d)", pName, value, value, line); } +inline void udTrace_Variable(const char *pName, unsigned value, int line) { udTrace::Message("%s = %u/0x%x (int, line#=%d)", pName, value, value, line); } +inline void udTrace_Variable(const char *pName, uint64_t value, int line) { udTrace::Message("%s = %" PRIu64 "/0x%" PRIx64 " (int64, line#=%d)", pName, value, value, line); } +inline void udTrace_Variable(const char *pName, float value, int line) { udTrace::Message("%s = %f (float, line#=%d)", pName, value, line); } +inline void udTrace_Variable(const char *pName, double value, int line) { udTrace::Message("%s = %lf (double line#=%d)", pName, value, line); } +inline void udTrace_Variable(const char *pName, bool value, int line) { udTrace::Message("%s = %s (line#=%d)", pName, value ? "true" : "false", line); } void udTrace_Memory(const char *pName, const void *pMem, int length, int line = 0); - #if UD_DEBUG -# define UDTRACE_ON 0 // Set to 1 to enable, set to 2 for printf on entry/exit of every function -# define UDASSERT_ON 1 -# define UDRELASSERT_ON 1 +# define UDTRACE_ON 0 // Set to 1 to enable, set to 2 for printf on entry/exit of every function +# define UDASSERT_ON 1 +# define UDRELASSERT_ON 1 #elif UD_RELEASE -#if !defined(UDTRACE_ON) -# define UDTRACE_ON 0 -# endif -# define UDASSERT_ON 0 -# define UDRELASSERT_ON 1 +# if !defined(UDTRACE_ON) +# define UDTRACE_ON 0 +# endif +# define UDASSERT_ON 0 +# define UDRELASSERT_ON 1 #endif #if defined(__GNUC__) -# if UD_DEBUG -# include -# if !defined(__debugbreak) -# define __debugbreak() raise(SIGTRAP) -# endif // !defined(__debugbreak) -# if !defined(DebugBreak) -# define DebugBreak() raise(SIGTRAP) -# endif // !defined(DebugBreak) -# else -# if !defined(__debugbreak) -# define __debugbreak() {} -# endif // !defined(__debugbreak) -# if !defined(DebugBreak) -# define DebugBreak() {} -# endif // !defined(DebugBreak) -# endif +# if UD_DEBUG +# include +# if !defined(__debugbreak) +# define __debugbreak() raise(SIGTRAP) +# endif // !defined(__debugbreak) +# if !defined(DebugBreak) +# define DebugBreak() raise(SIGTRAP) +# endif // !defined(DebugBreak) +# else +# if !defined(__debugbreak) +# define __debugbreak() \ + {} +# endif // !defined(__debugbreak) +# if !defined(DebugBreak) +# define DebugBreak() \ + {} +# endif // !defined(DebugBreak) +# endif #endif - #if UDTRACE_ON -# define UDTRACE() udTrace __udtrace##__LINE__(__FUNCTION__, UDTRACE_ON) -# define UDTRACE_LINE() udTrace::Message("Line %d\n", __LINE__) -# define UDTRACE_SCOPE(id) udTrace __udtrace##__LINE__(id, UDTRACE_ON) -# define UDTRACE_MESSAGE(format,...) udTrace::Message(format,__VA_ARGS__) -# define UDTRACE_VARIABLE(var) udTrace_Variable(#var, var, __LINE__) -# define UDTRACE_MEMORY(var,length) udTrace_Memory(#var, var, length, __LINE__) +# define UDTRACE() udTrace __udtrace##__LINE__(__FUNCTION__, UDTRACE_ON) +# define UDTRACE_LINE() udTrace::Message("Line %d\n", __LINE__) +# define UDTRACE_SCOPE(id) udTrace __udtrace##__LINE__(id, UDTRACE_ON) +# define UDTRACE_MESSAGE(format, ...) udTrace::Message(format, __VA_ARGS__) +# define UDTRACE_VARIABLE(var) udTrace_Variable(# var, var, __LINE__) +# define UDTRACE_MEMORY(var, length) udTrace_Memory(# var, var, length, __LINE__) #else -# define UDTRACE() -# define UDTRACE_LINE() -# define UDTRACE_SCOPE(id) -# define UDTRACE_MESSAGE(format,...) -# define UDTRACE_VARIABLE(var) -# define UDTRACE_MEMORY(var,length) +# define UDTRACE() +# define UDTRACE_LINE() +# define UDTRACE_SCOPE(id) +# define UDTRACE_MESSAGE(format, ...) +# define UDTRACE_VARIABLE(var) +# define UDTRACE_MEMORY(var, length) #endif // UDTRACE_ON // TODO: Make assertion system handle pop-up window where possible #if UDASSERT_ON -# define UDASSERT(condition, ...) do { bool testCondition = !!(condition); if (!testCondition) { udDebugPrintf(__VA_ARGS__); DebugBreak(); udDebugPrintf("\n"); } } while (0) -# define IF_UDASSERT(x) x +# define UDASSERT(condition, ...) \ + do \ + { \ + bool testCondition = !!(condition); \ + if (!testCondition) \ + { \ + udDebugPrintf(__VA_ARGS__); \ + DebugBreak(); \ + udDebugPrintf("\n"); \ + } \ + } while (0) +# define IF_UDASSERT(x) x #else -# define UDASSERT(condition, ...) do { } while (0) // TODO: Make platform-specific __assume(condition) -# define IF_UDASSERT(x) +# define UDASSERT(condition, ...) \ + do \ + { \ + } while (0) // TODO: Make platform-specific __assume(condition) +# define IF_UDASSERT(x) #endif // UDASSERT_ON #if UDRELASSERT_ON -# define UDRELASSERT(condition, ...) do { bool testCondition = !!(condition); if (!testCondition) { udDebugPrintf(__VA_ARGS__); DebugBreak(); udDebugPrintf("\n"); } } while(0) -# define IF_UDRELASSERT(x) x +# define UDRELASSERT(condition, ...) \ + do \ + { \ + bool testCondition = !!(condition); \ + if (!testCondition) \ + { \ + udDebugPrintf(__VA_ARGS__); \ + DebugBreak(); \ + udDebugPrintf("\n"); \ + } \ + } while (0) +# define IF_UDRELASSERT(x) x #else -# define UDRELASSERT(condition, ...) do { } while (0) // TODO: Make platform-specific __assume(condition) -# define IF_UDRELASSERT(x) +# define UDRELASSERT(condition, ...) \ + do \ + { \ + } while (0) // TODO: Make platform-specific __assume(condition) +# define IF_UDRELASSERT(x) #endif //UDRELASSERT_ON #if UDCPP11 -# define UDCOMPILEASSERT(a_condition, a_error) static_assert(a_condition, a_error) +# define UDCOMPILEASSERT(a_condition, a_error) static_assert(a_condition, a_error) #else -# if UDPLATFORM_WINDOWS -# define UDCOMPILEASSERT(a_condition, a_error) typedef char UDCOMPILEASSERT##__LINE__[(a_condition)?1:-1] -# else -# define UDCOMPILEASSERT(a_condition, a_error) typedef char UDCOMPILEASSERT##__LINE__[(a_condition)?1:-1] __attribute__ ((unused)) -# endif +# if UDPLATFORM_WINDOWS +# define UDCOMPILEASSERT(a_condition, a_error) typedef char UDCOMPILEASSERT##__LINE__[(a_condition) ? 1 : -1] +# else +# define UDCOMPILEASSERT(a_condition, a_error) typedef char UDCOMPILEASSERT##__LINE__[(a_condition) ? 1 : -1] __attribute__((unused)) +# endif #endif #define UDUNREACHABLE() UDASSERT(false, "Unreachable!") #if UD_DEBUG -# define OUTPUT_ERROR_STRINGS (1) +# define OUTPUT_ERROR_STRINGS (1) #else -# define OUTPUT_ERROR_STRINGS (0) +# define OUTPUT_ERROR_STRINGS (0) #endif #define UD_BREAK_ON_ERROR_STRING (0) #if OUTPUT_ERROR_STRINGS -# if UD_BREAK_ON_ERROR_STRING -# define __breakOnErrorString() __debugbreak() -# else -# define __breakOnErrorString() -# endif -# define PRINT_ERROR_STRING(...) do {udDebugPrintf("%s : ", __FUNCTION__); udDebugPrintf(__VA_ARGS__); __breakOnErrorString(); } while (false) +# if UD_BREAK_ON_ERROR_STRING +# define __breakOnErrorString() __debugbreak() +# else +# define __breakOnErrorString() +# endif +# define PRINT_ERROR_STRING(...) \ + do \ + { \ + udDebugPrintf("%s : ", __FUNCTION__); \ + udDebugPrintf(__VA_ARGS__); \ + __breakOnErrorString(); \ + } while (false) #else -# define PRINT_ERROR_STRING(...) +# define PRINT_ERROR_STRING(...) #endif #if defined(__GNUC__) && (__GNUC__ >= 4) -#define UDCHECKRESULT __attribute__ ((warn_unused_result)) +# define UDCHECKRESULT __attribute__((warn_unused_result)) #elif defined(_MSC_VER) && (_MSC_VER >= 1700) -#define UDCHECKRESULT _Check_return_ +# define UDCHECKRESULT _Check_return_ #else -#define UDCHECKRESULT +# define UDCHECKRESULT #endif // Dump a report to debug console of all lines that allocated memory, with allocation count and total, sorted by total // Returns true if a report was generated bool udDebugMemoryReport(const char *pHeader, size_t minimumUsageForReport = 0, size_t *pActualUsage = nullptr); - - #endif // UDDEBUG_H diff --git a/Include/udFile.h b/Include/udFile.h index 0699db59..1ad6cee8 100644 --- a/Include/udFile.h +++ b/Include/udFile.h @@ -12,18 +12,18 @@ // The prefix raw://compression=ZlibDeflate,size=123@base64 can be used for compressed in-memory files contained in the filename (see udCompressionTypeAsString) // +#include "udCompression.h" #include "udPlatform.h" #include "udResult.h" -#include "udCompression.h" struct udFile; enum udFileOpenFlags { - udFOF_Read = 1, + udFOF_Read = 1, udFOF_Write = 2, udFOF_Create = 4, udFOF_Multithread = 8, - udFOF_FastOpen = 16 // No checks performed, file length not supported. Currently functional for FILE (deferred open) and HTTP (stateless) + udFOF_FastOpen = 16 // No checks performed, file length not supported. Currently functional for FILE (deferred open) and HTTP (stateless) }; // Inline of operator to allow flags to be combined and retain type-safety inline udFileOpenFlags operator|(udFileOpenFlags a, udFileOpenFlags b) { return (udFileOpenFlags)(int(a) | int(b)); } @@ -52,8 +52,8 @@ struct udFilePerformance // Load an entire file, appending a nul terminator. Calls Open/Read/Close internally. udResult udFile_Load(const char *pFilename, void **ppMemory, int64_t *pFileLengthInBytes = nullptr); -template -inline udResult udFile_Load(const char *pFilename, T **ppMemory, int64_t *pFileLengthInBytes = nullptr) { return udFile_Load(pFilename, (void**)ppMemory, pFileLengthInBytes); } +template +inline udResult udFile_Load(const char *pFilename, T **ppMemory, int64_t *pFileLengthInBytes = nullptr) { return udFile_Load(pFilename, (void **)ppMemory, pFileLengthInBytes); } // Save an entire file, Calls Open/Write/Close internally. udResult udFile_Save(const char *pFilename, const void *pBuffer, size_t length); diff --git a/Include/udFileHandler.h b/Include/udFileHandler.h index 9984d3da..421b0349 100644 --- a/Include/udFileHandler.h +++ b/Include/udFileHandler.h @@ -9,8 +9,8 @@ // internally to provide file i/o to direct file system, http and other future protocols // -#include "udPlatform.h" #include "udFile.h" +#include "udPlatform.h" #include "udThread.h" // Some function prototypes required if implementing a custom file handler @@ -43,8 +43,8 @@ typedef udResult udFile_CloseHandlerFunc(udFile **ppFile); // The base file structure, file handlers are expected to zero this structure and extend the to include custom data to manage state. struct udFile { - const char *pFilenameCopy; // If assigned by a handler, set filenameCopyRequiresFree, or handler is responsible for free - udFileOpenFlags flagsCopy; // Set by udFile, not handlers. A copy of the flags used to open the file + const char *pFilenameCopy; // If assigned by a handler, set filenameCopyRequiresFree, or handler is responsible for free + udFileOpenFlags flagsCopy; // Set by udFile, not handlers. A copy of the flags used to open the file udFile_SetSubFilenameFunc *fpSetSubFilename; // Optional, for handlers of archive files such as zip etc udFile_LoadHandlerFunc *fpLoad; // Optional, for handlers that can optimize the Open/Read/Close approach of udFile_Load, such as HTTP udFile_SeekReadHandlerFunc *fpRead; @@ -53,7 +53,7 @@ struct udFile udFile_ReleaseHandlerFunc *fpRelease; udFile_CloseHandlerFunc *fpClose; struct udCryptoCipherContext *pCipherCtx; - int64_t nonce, counterOffset; // For CTR mode, the nonce and an offset added to calculated counter, used mainly by split files or to add perceived security + int64_t nonce, counterOffset; // For CTR mode, the nonce and an offset added to calculated counter, used mainly by split files or to add perceived security int64_t seekBase; int64_t filePos; int64_t fileLength; @@ -61,7 +61,7 @@ struct udFile uint32_t requestsInFlight; uint64_t totalBytes; float mbPerSec; - bool filenameCopyRequiresFree; // Set if the filename copy was allocated, will be freed prior to calling handler close function + bool filenameCopyRequiresFree; // Set if the filename copy was allocated, will be freed prior to calling handler close function }; // Register a file handler diff --git a/Include/udGeoZone.h b/Include/udGeoZone.h index 7f40cd71..773031f1 100644 --- a/Include/udGeoZone.h +++ b/Include/udGeoZone.h @@ -32,73 +32,72 @@ enum udGeoZoneEllipsoid udGZE_IAG1975, udGZE_Everest1830, udGZE_GRS67, - udGZE_ANS, //EPSG:7003 - udGZE_INS, //EPSG:7021 + udGZE_ANS, //EPSG:7003 + udGZE_INS, //EPSG:7021 udGZE_Count }; enum udGeoZoneGeodeticDatum { - udGZGD_WGS84, //EPSG:4326 - udGZGD_ED50, //EPSG:4230 - udGZGD_ETRS89, //EPSG:4258,4936 - udGZGD_TM75, //EPSG:4300 - udGZGD_NAD27, //EPSG:4267 - udGZGD_NAD27CGQ77, //EPSG:4609 - udGZGD_NAD83, //EPSG:4269 - udGZGD_NAD83_1996, //EPSG:6307 - udGZGD_NAD83_CSRS, //EPSG:2955 - udGZGD_NAD83_NSRS2007,//EPSG:3465 - udGZGD_NAD83_2011, //EPSG:6318 - udGZGD_NTF, //EPSG:4275 - udGZGD_OSGB36, //EPSG:4277 - udGZGD_Potsdam, //EPSG:4746 - udGZGD_Tokyo, //EPSG:7414 - udGZGD_WGS72, //EPSG:4322 - udGZGD_JGD2000, //EPSG:4612 - udGZGD_JGD2011, //EPSG:6668 - udGZGD_GDA94, //EPSG:4283 - udGZGD_GDA2020, //EPSG:7844 - udGZGD_RGF93, //EPSG:4171 - udGZGD_NAD83_HARN, //EPSG:4152 - udGZGD_CGCS2000, //EPSG:4490 - udGZGD_HK1980, //EPSG:4611 - udGZGD_SVY21, //EPSG:4757 - udGZGD_MGI, //EPSG:6312 - udGZGD_NZGD2000, //EPSG:2193 - udGZGD_AMERSFOORT, //EPSG:28992 - udGZGD_TRI1903, //EPSG:30200 - udGZGD_VANUA1915, //EPSG:3139 - udGZGD_DEALUL1970, //EPSG:31700 - udGZGD_SINGGRID, //EPSG:19920 - udGZGD_MARS_MERC, //EPSG:49974,49975 - udGZGD_MARS_PCPF, //EPSG:8705 - udGZGD_MOON_MERC, //EPSG:30174,30175 - udGZGD_MOON_PCPF, //EPSG:30100,30100 - udGZGD_DBREF, //EPSG:5681 - udGZGD_DHDN, //EPSG:4314 - udGZGD_SJTSK03, //EPSG:8353 - udGZGD_PULK1942, //EPSG:4284 - udGZGD_PULK194258, //EPSG:4179 - udGZGD_PULK194283, //EPSG:4178 - udGZGD_PULK1995, //EPSG:20004 - udGZGD_WGS_72BE, //EPSG:32401 - udGZGD_BEIJING1954,//EPSG:21413 - udGZGD_NEWBEIJING, //EPSG:4555 - udGZGD_XIAN1980, //EPSG:4610 - udGZGD_TIMB1948, //EPSG:28973 - udGZGD_NZGD49, //EPSG:4272 - udGZGD_SWEREF99, //EPSG:4619 - udGZGD_SAD69, //EPSG:4291 - udGZGD_GR96, //EPSG:4747 - udGZGD_DGN95, //EPSG:4755 - udGZGD_UCS2000, //EPSG:5561 - udGZGD_H94, //EPSG:4148 - udGZGD_ID74, //EPSG:4238 - udGZGD_NGO1948, //EPSG:4273 - udGZGD_RGF93v2b, //EPSG:9782 - + udGZGD_WGS84, //EPSG:4326 + udGZGD_ED50, //EPSG:4230 + udGZGD_ETRS89, //EPSG:4258,4936 + udGZGD_TM75, //EPSG:4300 + udGZGD_NAD27, //EPSG:4267 + udGZGD_NAD27CGQ77, //EPSG:4609 + udGZGD_NAD83, //EPSG:4269 + udGZGD_NAD83_1996, //EPSG:6307 + udGZGD_NAD83_CSRS, //EPSG:2955 + udGZGD_NAD83_NSRS2007, //EPSG:3465 + udGZGD_NAD83_2011, //EPSG:6318 + udGZGD_NTF, //EPSG:4275 + udGZGD_OSGB36, //EPSG:4277 + udGZGD_Potsdam, //EPSG:4746 + udGZGD_Tokyo, //EPSG:7414 + udGZGD_WGS72, //EPSG:4322 + udGZGD_JGD2000, //EPSG:4612 + udGZGD_JGD2011, //EPSG:6668 + udGZGD_GDA94, //EPSG:4283 + udGZGD_GDA2020, //EPSG:7844 + udGZGD_RGF93, //EPSG:4171 + udGZGD_NAD83_HARN, //EPSG:4152 + udGZGD_CGCS2000, //EPSG:4490 + udGZGD_HK1980, //EPSG:4611 + udGZGD_SVY21, //EPSG:4757 + udGZGD_MGI, //EPSG:6312 + udGZGD_NZGD2000, //EPSG:2193 + udGZGD_AMERSFOORT, //EPSG:28992 + udGZGD_TRI1903, //EPSG:30200 + udGZGD_VANUA1915, //EPSG:3139 + udGZGD_DEALUL1970, //EPSG:31700 + udGZGD_SINGGRID, //EPSG:19920 + udGZGD_MARS_MERC, //EPSG:49974,49975 + udGZGD_MARS_PCPF, //EPSG:8705 + udGZGD_MOON_MERC, //EPSG:30174,30175 + udGZGD_MOON_PCPF, //EPSG:30100,30100 + udGZGD_DBREF, //EPSG:5681 + udGZGD_DHDN, //EPSG:4314 + udGZGD_SJTSK03, //EPSG:8353 + udGZGD_PULK1942, //EPSG:4284 + udGZGD_PULK194258, //EPSG:4179 + udGZGD_PULK194283, //EPSG:4178 + udGZGD_PULK1995, //EPSG:20004 + udGZGD_WGS_72BE, //EPSG:32401 + udGZGD_BEIJING1954, //EPSG:21413 + udGZGD_NEWBEIJING, //EPSG:4555 + udGZGD_XIAN1980, //EPSG:4610 + udGZGD_TIMB1948, //EPSG:28973 + udGZGD_NZGD49, //EPSG:4272 + udGZGD_SWEREF99, //EPSG:4619 + udGZGD_SAD69, //EPSG:4291 + udGZGD_GR96, //EPSG:4747 + udGZGD_DGN95, //EPSG:4755 + udGZGD_UCS2000, //EPSG:5561 + udGZGD_H94, //EPSG:4148 + udGZGD_ID74, //EPSG:4238 + udGZGD_NGO1948, //EPSG:4273 + udGZGD_RGF93v2b, //EPSG:9782 udGZGD_Count }; @@ -142,9 +141,9 @@ struct udGeoZone udDouble2 latLongBoundMin; udDouble2 latLongBoundMax; double meridian; - double parallel; // Parallel of origin for Transverse Mercator - double latProjCentre; // Latitude of Projection Centre for Krovak Projection - double coLatConeAxis; // Co Latitude of the cone axis for Krovak Projection + double parallel; // Parallel of origin for Transverse Mercator + double latProjCentre; // Latitude of Projection Centre for Krovak Projection + double coLatConeAxis; // Co Latitude of the cone axis for Krovak Projection double flattening; double semiMajorAxis; double semiMinorAxis; @@ -160,12 +159,12 @@ struct udGeoZone double secondParallel; double falseNorthing; double falseEasting; - double unitMetreScale; // 1.0 for metres, 0.3048006096012192 for feet + double unitMetreScale; // 1.0 for metres, 0.3048006096012192 for feet int32_t zone; int32_t srid; char datumShortName[16]; char datumName[64]; - char zoneName[64]; // Only 33 characters required for longest known name "Japan Plane Rectangular CS XVIII" + char zoneName[64]; // Only 33 characters required for longest known name "Japan Plane Rectangular CS XVIII" char displayName[128]; // This is the human readable name; often just datumShortName & zoneName concatenated bool knownDatum; @@ -184,8 +183,8 @@ struct udGeoZoneGeodeticDatumDescriptor const char *pDatumName; udGeoZoneEllipsoid ellipsoid; double paramsHelmert7[7]; //TO-WGS84 as { Tx, Ty, Tz, Rx, Ry, Rz, DS } - int32_t epsg; // epsg code for the datum - int32_t authority; // authority for this datum + int32_t epsg; // epsg code for the datum + int32_t authority; // authority for this datum bool exportAxisInfo; bool exportToWGS84; }; diff --git a/Include/udImage.h b/Include/udImage.h index 839eddcb..320c1e5f 100644 --- a/Include/udImage.h +++ b/Include/udImage.h @@ -25,14 +25,14 @@ struct udImageStreamingOnDisk { enum { - Fourcc = MAKE_FOURCC('U', 'D', 'T', '0'), // Fourcc also a version number + Fourcc = MAKE_FOURCC('U', 'D', 'T', '0'), // Fourcc also a version number TileSize = 64, MaxMipLevels = 24, }; uint32_t fourcc; uint32_t width, height; uint16_t mipCount; - char name[64]; // some descriptive text (such as a filename) to help identify + char name[64]; // some descriptive text (such as a filename) to help identify uint16_t offsetToMip0; // To allow future extension }; @@ -43,10 +43,10 @@ struct udImageStreaming : public udImageStreamingOnDisk int64_t baseOffset; struct Mip { - int64_t offset; // Offset from beginning of on-disk image of first tile - uint32_t width, height; // Dimensions for this mip - uint16_t gridW, gridH; // Dimensions of cell grid - uint8_t * volatile * ppCellImage; // Pointers to each 64x64 tile + int64_t offset; // Offset from beginning of on-disk image of first tile + uint32_t width, height; // Dimensions for this mip + uint16_t gridW, gridH; // Dimensions of cell grid + uint8_t *volatile *ppCellImage; // Pointers to each 64x64 tile } mips[MaxMipLevels]; }; @@ -55,9 +55,9 @@ enum udImageSampleFlags udISF_None = 0, udISF_Filter = 1, udISF_Clamp = 2, - udISF_ABGR = 4, // By default, colors are returned in ARGB (blue least significant byte), this option returns in ABGR (red least significant byte) - udISF_TopLeft = 8, // Sample with top left point as 0,0 rather than openGL's curious bottom left 0,0 scheme - udISF_NoStream = 16, // If a cell isn't loaded, don't load it, but rather return the index data in lower 24 bits, alpha is zero + udISF_ABGR = 4, // By default, colors are returned in ARGB (blue least significant byte), this option returns in ABGR (red least significant byte) + udISF_TopLeft = 8, // Sample with top left point as 0,0 rather than openGL's curious bottom left 0,0 scheme + udISF_NoStream = 16, // If a cell isn't loaded, don't load it, but rather return the index data in lower 24 bits, alpha is zero }; inline udImageSampleFlags operator|(udImageSampleFlags a, udImageSampleFlags b) { return (udImageSampleFlags)(int(a) | int(b)); } diff --git a/Include/udJSON.h b/Include/udJSON.h index 0311bfce..6216b718 100644 --- a/Include/udJSON.h +++ b/Include/udJSON.h @@ -8,19 +8,19 @@ // Module for loading and saving JSON (JavaScript Object Notation), with additional limited support for XML // -#include "udPlatform.h" #include "udChunkedArray.h" #include "udMath.h" +#include "udPlatform.h" #if !defined(UDVALUE_DEPRECATED) -#define udValue udJSON -#define udValueExportOption udJSONExportOption -#define udVEO_JSON udJEO_JSON -#define udVEO_XML udJEO_XML -#define udVEO_StripWhiteSpace 0 -#define udValueKVPair udJSONKVPair -#define udValueArray udJSONArray -#define udValueObject udJSONObject +# define udValue udJSON +# define udValueExportOption udJSONExportOption +# define udVEO_JSON udJEO_JSON +# define udVEO_XML udJEO_XML +# define udVEO_StripWhiteSpace 0 +# define udValueKVPair udJSONKVPair +# define udValueArray udJSONArray +# define udValueObject udJSONObject #endif /* @@ -82,7 +82,12 @@ * v.Destroy(); // To destroy object before waiting to go out of scope */ -enum udJSONExportOption { udJEO_JSON = 0, udJEO_XML = 1, udJEO_FormatWhiteSpace = 2 }; +enum udJSONExportOption +{ + udJEO_JSON = 0, + udJEO_XML = 1, + udJEO_FormatWhiteSpace = 2 +}; static inline udJSONExportOption operator|(udJSONExportOption a, udJSONExportOption b) { return (udJSONExportOption)(int(a) | int(b)); } class udJSON; @@ -95,13 +100,13 @@ class udJSON public: enum Type { - T_Void = 0, // Guaranteed to be zero, thus a non-zero type indicates value exists + T_Void = 0, // Guaranteed to be zero, thus a non-zero type indicates value exists T_Bool, T_Int64, T_Double, T_String, - T_Array, // A udChunkedArray of values - T_Object, // An list of key/value pairs (equiv of JSON object, or XML element attributes) + T_Array, // A udChunkedArray of values + T_Object, // An list of key/value pairs (equiv of JSON object, or XML element attributes) T_Count }; @@ -111,7 +116,7 @@ class udJSON inline udJSON(int64_t v); inline udJSON(double v); inline void Clear(); - void Destroy(); // Free any memory associated, expects object to be constructed + void Destroy(); // Free any memory associated, expects object to be constructed inline ~udJSON(); // Set the value @@ -122,7 +127,7 @@ class udJSON // Set to a more complex type requiring memory allocation udResult SetString(const char *pStr, size_t charCount = 0); // non-zero charCount specifies maximum characters copied - udResult SetArray(); // A dynamic array of JSON elements, whose types can change per element + udResult SetArray(); // A dynamic array of JSON elements, whose types can change per element udResult SetObject(); // Some convenience helpers to create an array of doubles @@ -141,10 +146,10 @@ class udJSON inline bool IsArray() const; inline bool IsObject() const; inline bool HasMemory() const; - inline size_t ArrayLength() const; // Get the length of the array (always 1 for an object) - inline size_t MemberCount() const; // Get the number of members for an object (zero for all other types) - inline const char *GetMemberName(size_t index) const; // Get the name of a member (null if out of range or not an object) - inline const udJSON *GetMember(size_t index) const; // Get the member value (null if out of range or not an object) + inline size_t ArrayLength() const; // Get the length of the array (always 1 for an object) + inline size_t MemberCount() const; // Get the number of members for an object (zero for all other types) + inline const char *GetMemberName(size_t index) const; // Get the name of a member (null if out of range or not an object) + inline const udJSON *GetMember(size_t index) const; // Get the member value (null if out of range or not an object) const udJSON *FindMember(const char *pMemberName, size_t *pIndex = nullptr) const; // Get a member of an object bool IsEqualTo(const udJSON &other) const; @@ -179,14 +184,18 @@ class udJSON // Get a pointer to a key's value, this pointer is valid as long as the key remains, ppValue may be null if just testing existence // Allowed operators are . and [] to dereference (eg "instances[%d].%s", (int)instanceIndex, (char*)pInstanceKeyName) - UD_PRINTF_FORMAT_FUNC(3) udResult Get(udJSON **ppValue, const char *pKeyExpression, ...); - UD_PRINTF_FORMAT_FUNC(2) const udJSON &Get(const char *pKeyExpression, ...) const; + UD_PRINTF_FORMAT_FUNC(3) + udResult Get(udJSON **ppValue, const char *pKeyExpression, ...); + UD_PRINTF_FORMAT_FUNC(2) + const udJSON &Get(const char *pKeyExpression, ...) const; // Set a new key/value pair to the store, overwriting a existing key, using = operator in the expression // Allowed operators are . and [] to dereference and for version without pValue, = to assign value (eg "obj.value = %d", 5) // Set with null for pValue or nothing following the = will remove the key - UD_PRINTF_FORMAT_FUNC(3) udResult Set(udJSON *pValue, const char *pKeyExpression, ...); - UD_PRINTF_FORMAT_FUNC(2) udResult Set(const char *pKeyExpression, ...); + UD_PRINTF_FORMAT_FUNC(3) + udResult Set(udJSON *pValue, const char *pKeyExpression, ...); + UD_PRINTF_FORMAT_FUNC(2) + udResult Set(const char *pKeyExpression, ...); // Parse a string an assign the type/value, supporting string, integer and float/double, JSON or XML udResult Parse(const char *pString, int *pCharCount = nullptr, int *pLineNumber = nullptr); @@ -202,7 +211,7 @@ class udJSON udResult CalculateHMAC(const char **ppHMACBase64, const char *pKeyBase64 = nullptr) const; protected: - typedef udChunkedArray LineList; + typedef udChunkedArray LineList; udResult ParseJSON(const char *pJSON, int *pCharCount, int *pLineNumber); udResult ParseXML(const char *pJSON, int *pCharCount, int *pLineNumber); @@ -223,7 +232,6 @@ class udJSON Type type; }; - struct udJSONKVPair { const char *pKey; diff --git a/Include/udJSON_Inl.h b/Include/udJSON_Inl.h index c0b027f8..66dc2ac7 100644 --- a/Include/udJSON_Inl.h +++ b/Include/udJSON_Inl.h @@ -1,35 +1,77 @@ #ifndef UDJSON_INL_H #define UDJSON_INL_H -inline udJSON::udJSON() { Clear(); } -inline udJSON::udJSON(int64_t v) { type = T_Int64; u.i64Val = v; dPrec = 0; } -inline udJSON::udJSON(double v) { type = T_Double; u.dVal = v; dPrec = 0; } -inline void udJSON::Clear() { type = T_Void; u.i64Val = 0; dPrec = 0; } // Clear the value without freeing -inline udJSON::~udJSON() { Destroy(); } +inline udJSON::udJSON() { Clear(); } +inline udJSON::udJSON(int64_t v) +{ + type = T_Int64; + u.i64Val = v; + dPrec = 0; +} +inline udJSON::udJSON(double v) +{ + type = T_Double; + u.dVal = v; + dPrec = 0; +} +inline void udJSON::Clear() +{ + type = T_Void; + u.i64Val = 0; + dPrec = 0; +} // Clear the value without freeing +inline udJSON::~udJSON() { Destroy(); } // Set the value -inline void udJSON::SetVoid() { Destroy(); } -inline void udJSON::Set(bool v) { Destroy(); type = T_Bool; u.bVal = v; } -inline void udJSON::Set(int64_t v) { Destroy(); type = T_Int64; u.i64Val = v; } -inline void udJSON::Set(double v) { Destroy(); type = T_Double; u.dVal = v; } +inline void udJSON::SetVoid() { Destroy(); } +inline void udJSON::Set(bool v) +{ + Destroy(); + type = T_Bool; + u.bVal = v; +} +inline void udJSON::Set(int64_t v) +{ + Destroy(); + type = T_Int64; + u.i64Val = v; +} +inline void udJSON::Set(double v) +{ + Destroy(); + type = T_Double; + u.dVal = v; +} // Accessors inline udJSON::Type udJSON::GetType() const { return type; } -inline bool udJSON::IsVoid() const { return (type == T_Void); } -inline bool udJSON::IsBool() const { return (type == T_Bool); } -inline bool udJSON::IsNumeric() const { return (type >= T_Int64 && type <= T_Double); } -inline bool udJSON::IsIntegral() const { return (type >= T_Int64 && type <= T_Int64); } -inline bool udJSON::IsString() const { return (type == T_String); } -inline bool udJSON::IsArray() const { return (type == T_Array); } -inline bool udJSON::IsObject() const { return (type == T_Object); } -inline bool udJSON::HasMemory() const { return (type >= T_String && type < T_Count); } -inline size_t udJSON::ArrayLength() const { return (type == T_Array) ? u.pArray->length : (type == T_Object) ? 1 : 0; } -inline size_t udJSON::MemberCount() const { return (type == T_Object) ? AsObject()->length : 0; } +inline bool udJSON::IsVoid() const { return (type == T_Void); } +inline bool udJSON::IsBool() const { return (type == T_Bool); } +inline bool udJSON::IsNumeric() const { return (type >= T_Int64 && type <= T_Double); } +inline bool udJSON::IsIntegral() const { return (type >= T_Int64 && type <= T_Int64); } +inline bool udJSON::IsString() const { return (type == T_String); } +inline bool udJSON::IsArray() const { return (type == T_Array); } +inline bool udJSON::IsObject() const { return (type == T_Object); } +inline bool udJSON::HasMemory() const { return (type >= T_String && type < T_Count); } +inline size_t udJSON::ArrayLength() const { return (type == T_Array) ? u.pArray->length : (type == T_Object) ? 1 + : 0; } +inline size_t udJSON::MemberCount() const { return (type == T_Object) ? AsObject()->length : 0; } inline const char *udJSON::GetMemberName(size_t index) const { return (type == T_Object && index < AsObject()->length) ? AsObject()->GetElement(index)->pKey : nullptr; } inline const udJSON *udJSON::GetMember(size_t index) const { return (type == T_Object && index < AsObject()->length) ? &AsObject()->GetElement(index)->value : nullptr; } -inline udJSONArray *udJSON::AsArray() const { return (type == T_Array) ? u.pArray : nullptr; } -inline udJSONObject *udJSON::AsObject() const { return (type == T_Object) ? u.pObject : nullptr; } +inline udJSONArray *udJSON::AsArray() const { return (type == T_Array) ? u.pArray : nullptr; } +inline udJSONObject *udJSON::AsObject() const { return (type == T_Object) ? u.pObject : nullptr; } inline udResult udJSON::ToString(const char **ppStr, bool escapeBackslashes) const { return ToString(ppStr, 0, "", "", "", escapeBackslashes); } -inline udResult udJSON::ExtractAndVoid(const char **ppStr) { if (!ppStr) return udR_InvalidParameter; if (type == T_String) { *ppStr = u.pStr; Clear(); return udR_Success; } return udR_ObjectTypeMismatch; } +inline udResult udJSON::ExtractAndVoid(const char **ppStr) +{ + if (!ppStr) + return udR_InvalidParameter; + if (type == T_String) + { + *ppStr = u.pStr; + Clear(); + return udR_Success; + } + return udR_ObjectTypeMismatch; +} #endif // UDJSON_INL_H diff --git a/Include/udMath.h b/Include/udMath.h index b4585635..26f57a9f 100644 --- a/Include/udMath.h +++ b/Include/udMath.h @@ -14,19 +14,18 @@ #if defined(_MSC_VER) // warning C4201: nonstandard extension used : nameless struct/union -# pragma warning(disable: 4201) +# pragma warning(disable : 4201) #endif -#define UD_PI 3.1415926535897932384626433832795 -#define UD_2PI 6.283185307179586476925286766559 -#define UD_HALF_PI 1.5707963267948966192313216916398 -#define UD_ROOT_2 1.4142135623730950488016887242097 -#define UD_INV_ROOT_2 0.70710678118654752440084436210485 -#define UD_RAD2DEGVAL 57.295779513082320876798154814105 -#define UD_DEG2RADVAL 0.01745329251994329576923690768489 -#define UD_RAD2DEG(rad) ((rad)*UD_RAD2DEGVAL) -#define UD_DEG2RAD(deg) ((deg)*UD_DEG2RADVAL) - +#define UD_PI 3.1415926535897932384626433832795 +#define UD_2PI 6.283185307179586476925286766559 +#define UD_HALF_PI 1.5707963267948966192313216916398 +#define UD_ROOT_2 1.4142135623730950488016887242097 +#define UD_INV_ROOT_2 0.70710678118654752440084436210485 +#define UD_RAD2DEGVAL 57.295779513082320876798154814105 +#define UD_DEG2RADVAL 0.01745329251994329576923690768489 +#define UD_RAD2DEG(rad) ((rad)*UD_RAD2DEGVAL) +#define UD_DEG2RAD(deg) ((deg)*UD_DEG2RADVAL) #define UD_PIf float(UD_PI) #define UD_2PIf float(UD_2PI) @@ -38,21 +37,30 @@ #define UD_RAD2DEGf(rad) ((rad)*UD_RAD2DEGVALf) #define UD_DEG2RADf(deg) ((deg)*UD_DEG2RADVALf) -#define UD_EPSILON float(1.0f / 1024.0f) +#define UD_EPSILON float(1.0f / 1024.0f) #if defined(__cplusplus) // prototypes -template struct udVector2; -template struct udVector3; -template struct udVector4; -template struct udQuaternion; -template struct udMatrix4x4; +template +struct udVector2; +template +struct udVector3; +template +struct udVector4; +template +struct udQuaternion; +template +struct udMatrix4x4; -template T udRoundEven(T t); -template T udPowerOfTwoAbove(T i); -template bool udIsPowerOfTwo(T i); -template T udHighestBitValue(T i); +template +T udRoundEven(T t); +template +T udPowerOfTwoAbove(T i); +template +bool udIsPowerOfTwo(T i); +template +T udHighestBitValue(T i); // math functions float udPow(float f, float n); @@ -100,9 +108,11 @@ template T udNormaliseRotation(T rad, T absRange = UD_PI); // A define for consistency with udArrayIsFinite -#define udIsFinite(x) isfinite(x) +# define udIsFinite(x) isfinite(x) -template constexpr bool udArrayIsFinite(const T *pArr, size_t n) { +template +constexpr bool udArrayIsFinite(const T *pArr, size_t n) +{ for (size_t i = 0; i < n; ++i) { if (!udIsFinite(pArr[i])) @@ -112,150 +122,259 @@ template constexpr bool udArrayIsFinite(const T *pArr, size_t n) { } // Template helper for arrays whose length is known at compile time -template constexpr bool udArrayIsFinite(T(&arr)[N]) { return udArrayIsFinite(arr, N); } - +template +constexpr bool udArrayIsFinite(T (&arr)[N]) { return udArrayIsFinite(arr, N); } // rounding functions float udRound(float f); double udRound(double d); -template udVector2 udRound(const udVector2 &v); -template udVector3 udRound(const udVector3 &v); -template udVector4 udRound(const udVector4 &v); +template +udVector2 udRound(const udVector2 &v); +template +udVector3 udRound(const udVector3 &v); +template +udVector4 udRound(const udVector4 &v); float udFloor(float f); double udFloor(double d); -template udVector2 udFloor(const udVector2 &v); -template udVector3 udFloor(const udVector3 &v); -template udVector4 udFloor(const udVector4 &v); +template +udVector2 udFloor(const udVector2 &v); +template +udVector3 udFloor(const udVector3 &v); +template +udVector4 udFloor(const udVector4 &v); float udCeil(float f); double udCeil(double d); -template udVector2 udCeil(const udVector2 &v); -template udVector3 udCeil(const udVector3 &v); -template udVector4 udCeil(const udVector4 &v); +template +udVector2 udCeil(const udVector2 &v); +template +udVector3 udCeil(const udVector3 &v); +template +udVector4 udCeil(const udVector4 &v); // typical linear algebra functions -template T udAbs(T v); -template udVector2 udAbs(const udVector2 &v); -template udVector3 udAbs(const udVector3 &v); -template udVector4 udAbs(const udVector4 &v); -template udQuaternion udAbs(const udQuaternion &q); - -template udVector2 udMax(const udVector2 &v1, const udVector2 &v2); -template udVector3 udMax(const udVector3 &v1, const udVector3 &v2); -template udVector4 udMax(const udVector4 &v1, const udVector4 &v2); -template T udMaxElement(const udVector2 &v); -template T udMaxElement(const udVector3 &v); -template T udMaxElement(const udVector4 &v); -template udVector2 udMin(const udVector2 &v1, const udVector2 &v2); -template udVector3 udMin(const udVector3 &v1, const udVector3 &v2); -template udVector4 udMin(const udVector4 &v1, const udVector4 &v2); -template T udMinElement(const udVector2 &v); -template T udMinElement(const udVector3 &v); -template T udMinElement(const udVector4 &v); -template T udClamp(T v, T _min, T _max); -template udVector2 udClamp(const udVector2 &v, const udVector2 &_min, const udVector2 &_max); -template udVector3 udClamp(const udVector3 &v, const udVector3 &_min, const udVector3 &_max); -template udVector4 udClamp(const udVector4 &v, const udVector4 &_min, const udVector4 &_max); -template T udSaturate(const T &v); -template udVector2 udSaturate(const udVector2 &v); -template udVector3 udSaturate(const udVector3 &v); -template udVector4 udSaturate(const udVector4 &v); - -template bool udIsUnitLength(const V &v, T epsilon = UD_EPSILON); - -template T udDot(const udVector2 &v1, const udVector2 &v2); -template T udDot(const udVector3 &v1, const udVector3 &v2); -template T udDot(const udVector4 &v1, const udVector4 &v2); -template T udDot(const udQuaternion &q1, const udQuaternion &q2); - -template T udDot2(const udVector2 &v1, const udVector2 &v2); -template T udDot2(const udVector3 &v1, const udVector3 &v2); -template T udDot2(const udVector4 &v1, const udVector4 &v2); -template T udDot3(const udVector3 &v1, const udVector3 &v2); -template T udDot3(const udVector4 &v1, const udVector4 &v2); -template T udDot4(const udVector4 &v1, const udVector4 &v2); -template T udDoth(const udVector3 &v3, const udVector4 &v4); -template T udDotQ(const udQuaternion &q1, const udQuaternion &q2); - -template T udMagSq(const udVector2 &v); -template T udMagSq(const udVector3 &v); -template T udMagSq(const udVector4 &v); -template T udMagSq(const udQuaternion &q); - -template T udMagSq2(const udVector2 &v); -template T udMagSq2(const udVector3 &v); -template T udMagSq2(const udVector4 &v); -template T udMagSq3(const udVector3 &v); -template T udMagSq3(const udVector4 &v); -template T udMagSq4(const udVector4 &v); -template T udMagSqQ(const udQuaternion &q); - -template T udMag(const udVector2 &v); -template T udMag(const udVector3 &v); -template T udMag(const udVector4 &v); -template T udMag(const udQuaternion &v); - -template T udMag2(const udVector2 &v); -template T udMag2(const udVector3 &v); -template T udMag2(const udVector4 &v); -template T udMag3(const udVector3 &v); -template T udMag3(const udVector4 &v); -template T udMag4(const udVector4 &v); -template T udMagQ(const udQuaternion &v); - -template T udCross(const udVector2 &v1, const udVector2 &v2); -template udVector3 udCross(const udVector3 &v1, const udVector3 &v2); - -template T udCross2(const udVector2 &v1, const udVector2 &v2); -template T udCross2(const udVector3 &v1, const udVector3 &v2); -template T udCross2(const udVector4 &v1, const udVector4 &v2); -template udVector3 udCross3(const udVector3 &v1, const udVector3 &v2); -template udVector3 udCross3(const udVector4 &v1, const udVector4 &v2); - -template udVector2 udNormalize(const udVector2 &v); -template udVector3 udNormalize(const udVector3 &v); -template udVector4 udNormalize(const udVector4 &v); -template udQuaternion udNormalize(const udQuaternion &q); - -template udVector2 udNormalize2(const udVector2 &v); -template udVector3 udNormalize2(const udVector3 &v); -template udVector4 udNormalize2(const udVector4 &v); -template udVector3 udNormalize3(const udVector3 &v); -template udVector4 udNormalize3(const udVector4 &v); -template udVector4 udNormalize4(const udVector4 &v); -template udQuaternion udNormalizeQ(const udQuaternion &q); +template +T udAbs(T v); +template +udVector2 udAbs(const udVector2 &v); +template +udVector3 udAbs(const udVector3 &v); +template +udVector4 udAbs(const udVector4 &v); +template +udQuaternion udAbs(const udQuaternion &q); + +template +udVector2 udMax(const udVector2 &v1, const udVector2 &v2); +template +udVector3 udMax(const udVector3 &v1, const udVector3 &v2); +template +udVector4 udMax(const udVector4 &v1, const udVector4 &v2); +template +T udMaxElement(const udVector2 &v); +template +T udMaxElement(const udVector3 &v); +template +T udMaxElement(const udVector4 &v); +template +udVector2 udMin(const udVector2 &v1, const udVector2 &v2); +template +udVector3 udMin(const udVector3 &v1, const udVector3 &v2); +template +udVector4 udMin(const udVector4 &v1, const udVector4 &v2); +template +T udMinElement(const udVector2 &v); +template +T udMinElement(const udVector3 &v); +template +T udMinElement(const udVector4 &v); +template +T udClamp(T v, T _min, T _max); +template +udVector2 udClamp(const udVector2 &v, const udVector2 &_min, const udVector2 &_max); +template +udVector3 udClamp(const udVector3 &v, const udVector3 &_min, const udVector3 &_max); +template +udVector4 udClamp(const udVector4 &v, const udVector4 &_min, const udVector4 &_max); +template +T udSaturate(const T &v); +template +udVector2 udSaturate(const udVector2 &v); +template +udVector3 udSaturate(const udVector3 &v); +template +udVector4 udSaturate(const udVector4 &v); + +template +bool udIsUnitLength(const V &v, T epsilon = UD_EPSILON); + +template +T udDot(const udVector2 &v1, const udVector2 &v2); +template +T udDot(const udVector3 &v1, const udVector3 &v2); +template +T udDot(const udVector4 &v1, const udVector4 &v2); +template +T udDot(const udQuaternion &q1, const udQuaternion &q2); + +template +T udDot2(const udVector2 &v1, const udVector2 &v2); +template +T udDot2(const udVector3 &v1, const udVector3 &v2); +template +T udDot2(const udVector4 &v1, const udVector4 &v2); +template +T udDot3(const udVector3 &v1, const udVector3 &v2); +template +T udDot3(const udVector4 &v1, const udVector4 &v2); +template +T udDot4(const udVector4 &v1, const udVector4 &v2); +template +T udDoth(const udVector3 &v3, const udVector4 &v4); +template +T udDotQ(const udQuaternion &q1, const udQuaternion &q2); + +template +T udMagSq(const udVector2 &v); +template +T udMagSq(const udVector3 &v); +template +T udMagSq(const udVector4 &v); +template +T udMagSq(const udQuaternion &q); + +template +T udMagSq2(const udVector2 &v); +template +T udMagSq2(const udVector3 &v); +template +T udMagSq2(const udVector4 &v); +template +T udMagSq3(const udVector3 &v); +template +T udMagSq3(const udVector4 &v); +template +T udMagSq4(const udVector4 &v); +template +T udMagSqQ(const udQuaternion &q); + +template +T udMag(const udVector2 &v); +template +T udMag(const udVector3 &v); +template +T udMag(const udVector4 &v); +template +T udMag(const udQuaternion &v); + +template +T udMag2(const udVector2 &v); +template +T udMag2(const udVector3 &v); +template +T udMag2(const udVector4 &v); +template +T udMag3(const udVector3 &v); +template +T udMag3(const udVector4 &v); +template +T udMag4(const udVector4 &v); +template +T udMagQ(const udQuaternion &v); + +template +T udCross(const udVector2 &v1, const udVector2 &v2); +template +udVector3 udCross(const udVector3 &v1, const udVector3 &v2); + +template +T udCross2(const udVector2 &v1, const udVector2 &v2); +template +T udCross2(const udVector3 &v1, const udVector3 &v2); +template +T udCross2(const udVector4 &v1, const udVector4 &v2); +template +udVector3 udCross3(const udVector3 &v1, const udVector3 &v2); +template +udVector3 udCross3(const udVector4 &v1, const udVector4 &v2); + +template +udVector2 udNormalize(const udVector2 &v); +template +udVector3 udNormalize(const udVector3 &v); +template +udVector4 udNormalize(const udVector4 &v); +template +udQuaternion udNormalize(const udQuaternion &q); + +template +udVector2 udNormalize2(const udVector2 &v); +template +udVector3 udNormalize2(const udVector3 &v); +template +udVector4 udNormalize2(const udVector4 &v); +template +udVector3 udNormalize3(const udVector3 &v); +template +udVector4 udNormalize3(const udVector4 &v); +template +udVector4 udNormalize4(const udVector4 &v); +template +udQuaternion udNormalizeQ(const udQuaternion &q); // matrix and quat functions -template udVector2 udMul(const udMatrix4x4 &m, const udVector2 &v); -template udVector3 udMul(const udMatrix4x4 &m, const udVector3 &v); -template udVector4 udMul(const udMatrix4x4 &m, const udVector4 &v); -template udMatrix4x4 udMul(const udMatrix4x4 &m, U f); -template udMatrix4x4 udMul(const udMatrix4x4 &m1, const udMatrix4x4 &m2); -template udQuaternion udMul(const udQuaternion &q1, const udQuaternion &q2); +template +udVector2 udMul(const udMatrix4x4 &m, const udVector2 &v); +template +udVector3 udMul(const udMatrix4x4 &m, const udVector3 &v); +template +udVector4 udMul(const udMatrix4x4 &m, const udVector4 &v); +template +udMatrix4x4 udMul(const udMatrix4x4 &m, U f); +template +udMatrix4x4 udMul(const udMatrix4x4 &m1, const udMatrix4x4 &m2); +template +udQuaternion udMul(const udQuaternion &q1, const udQuaternion &q2); -template T udLerp(T a, T b, double t); -template udVector2 udLerp(const udVector2 &v1, const udVector2 &v2, double t); -template udVector3 udLerp(const udVector3 &v1, const udVector3 &v2, double t); -template udVector4 udLerp(const udVector4 &v1, const udVector4 &v2, double t); -template udQuaternion udLerp(const udQuaternion &q1, const udQuaternion &q2, double t); -template udMatrix4x4 udLerp(const udMatrix4x4 &m1, const udMatrix4x4 &m2, double t); +template +T udLerp(T a, T b, double t); +template +udVector2 udLerp(const udVector2 &v1, const udVector2 &v2, double t); +template +udVector3 udLerp(const udVector3 &v1, const udVector3 &v2, double t); +template +udVector4 udLerp(const udVector4 &v1, const udVector4 &v2, double t); +template +udQuaternion udLerp(const udQuaternion &q1, const udQuaternion &q2, double t); +template +udMatrix4x4 udLerp(const udMatrix4x4 &m1, const udMatrix4x4 &m2, double t); -template udMatrix4x4 udTranspose(const udMatrix4x4 &m); +template +udMatrix4x4 udTranspose(const udMatrix4x4 &m); -template T udDeterminant(const udMatrix4x4 &m); +template +T udDeterminant(const udMatrix4x4 &m); -template udQuaternion udInverse(const udQuaternion &q); -template udMatrix4x4 udInverse(const udMatrix4x4 &m); +template +udQuaternion udInverse(const udQuaternion &q); +template +udMatrix4x4 udInverse(const udMatrix4x4 &m); -template udQuaternion udConjugate(const udQuaternion &q); -template udQuaternion udSlerp(const udQuaternion &q1, const udQuaternion &q2, double t); +template +udQuaternion udConjugate(const udQuaternion &q); +template +udQuaternion udSlerp(const udQuaternion &q1, const udQuaternion &q2, double t); -template bool udEqualApprox(const V &a, const V &b, typename V::ElementType epsilon = UD_EPSILON); -template bool udMatrixEqualApprox(const udMatrix4x4 &a, const udMatrix4x4 &b, T epsilon = (T)(UD_EPSILON)); +template +bool udEqualApprox(const V &a, const V &b, typename V::ElementType epsilon = UD_EPSILON); +template +bool udMatrixEqualApprox(const udMatrix4x4 &a, const udMatrix4x4 &b, T epsilon = (T)(UD_EPSILON)); -template udVector3 udDirectionFromYPR(const udVector3 &ypr); -template udVector3 udDirectionToYPR(const udVector3 &direction); +template +udVector3 udDirectionFromYPR(const udVector3 &ypr); +template +udVector3 udDirectionToYPR(const udVector3 &direction); // types template @@ -263,190 +382,531 @@ struct udVector2 { T x, y; typedef T ElementType; - enum { ElementCount = 2 } ; + enum + { + ElementCount = 2 + }; - udVector2 operator -() const { udVector2 r = { -x, -y }; return r; } - bool operator ==(const udVector2 &v) const { return x == v.x && y == v.y; } - bool operator !=(const udVector2 &v) const { return !(*this == v); } + udVector2 operator-() const + { + udVector2 r = { -x, -y }; + return r; + } + bool operator==(const udVector2 &v) const { return x == v.x && y == v.y; } + bool operator!=(const udVector2 &v) const { return !(*this == v); } - udVector2 operator +(const udVector2 &v) const { udVector2 r = { x+v.x, y+v.y }; return r; } - udVector2 operator -(const udVector2 &v) const { udVector2 r = { x-v.x, y-v.y }; return r; } - udVector2 operator *(const udVector2 &v) const { udVector2 r = { x*v.x, y*v.y }; return r; } + udVector2 operator+(const udVector2 &v) const + { + udVector2 r = { x + v.x, y + v.y }; + return r; + } + udVector2 operator-(const udVector2 &v) const + { + udVector2 r = { x - v.x, y - v.y }; + return r; + } + udVector2 operator*(const udVector2 &v) const + { + udVector2 r = { x * v.x, y * v.y }; + return r; + } template - udVector2 operator *(U f) const { udVector2 r = { T(x*f), T(y*f) }; return r; } - udVector2 operator /(const udVector2 &v) const { udVector2 r = { x/v.x, y/v.y }; return r; } + udVector2 operator*(U f) const + { + udVector2 r = { T(x * f), T(y * f) }; + return r; + } + udVector2 operator/(const udVector2 &v) const + { + udVector2 r = { x / v.x, y / v.y }; + return r; + } template - udVector2 operator /(U f) const { udVector2 r = { T(x/f), T(y/f) }; return r; } - T operator [](size_t index) const { return ((T*)this)[index]; } + udVector2 operator/(U f) const + { + udVector2 r = { T(x / f), T(y / f) }; + return r; + } + T operator[](size_t index) const { return ((T *)this)[index]; } - udVector2& operator +=(const udVector2 &v) { x+=v.x; y+=v.y; return *this; } - udVector2& operator -=(const udVector2 &v) { x-=v.x; y-=v.y; return *this; } - udVector2& operator *=(const udVector2 &v) { x*=v.x; y*=v.y; return *this; } + udVector2 &operator+=(const udVector2 &v) + { + x += v.x; + y += v.y; + return *this; + } + udVector2 &operator-=(const udVector2 &v) + { + x -= v.x; + y -= v.y; + return *this; + } + udVector2 &operator*=(const udVector2 &v) + { + x *= v.x; + y *= v.y; + return *this; + } template - udVector2& operator *=(U f) { x=T(x*f); y=T(y*f); return *this; } - udVector2& operator /=(const udVector2 &v) { x/=v.x; y/=v.y; return *this; } + udVector2 &operator*=(U f) + { + x = T(x * f); + y = T(y * f); + return *this; + } + udVector2 &operator/=(const udVector2 &v) + { + x /= v.x; + y /= v.y; + return *this; + } template - udVector2& operator /=(U f) { x=T(x/f); y=T(y/f); return *this; } - T& operator [](size_t index) { return ((T*)this)[index]; } + udVector2 &operator/=(U f) + { + x = T(x / f); + y = T(y / f); + return *this; + } + T &operator[](size_t index) { return ((T *)this)[index]; } // static members - static udVector2 zero() { udVector2 r = { T(0), T(0) }; return r; } - static udVector2 one() { udVector2 r = { T(1), T(1) }; return r; } + static udVector2 zero() + { + udVector2 r = { T(0), T(0) }; + return r; + } + static udVector2 one() + { + udVector2 r = { T(1), T(1) }; + return r; + } - static udVector2 xAxis() { udVector2 r = { T(1), T(0) }; return r; } - static udVector2 yAxis() { udVector2 r = { T(0), T(1) }; return r; } + static udVector2 xAxis() + { + udVector2 r = { T(1), T(0) }; + return r; + } + static udVector2 yAxis() + { + udVector2 r = { T(0), T(1) }; + return r; + } - static udVector2 create(T _f) { udVector2 r = { _f, _f }; return r; } - static udVector2 create(T _x, T _y) { udVector2 r = { _x, _y }; return r; } + static udVector2 create(T _f) + { + udVector2 r = { _f, _f }; + return r; + } + static udVector2 create(T _x, T _y) + { + udVector2 r = { _x, _y }; + return r; + } template - static udVector2 create(const udVector2 &_v) { udVector2 r = { T(_v.x), T(_v.y) }; return r; } + static udVector2 create(const udVector2 &_v) + { + udVector2 r = { T(_v.x), T(_v.y) }; + return r; + } }; template -udVector2 operator *(T f, const udVector2 &v) { return v * f; } +udVector2 operator*(T f, const udVector2 &v) { return v * f; } template struct udVector3 { T x, y, z; typedef T ElementType; - enum { ElementCount = 3 }; + enum + { + ElementCount = 3 + }; - udVector2& toVector2() { return *(udVector2*)this; } - const udVector2& toVector2() const { return *(udVector2*)this; } + udVector2 &toVector2() { return *(udVector2 *)this; } + const udVector2 &toVector2() const { return *(udVector2 *)this; } - udVector3 operator -() const { udVector3 r = { -x, -y, -z }; return r; } - bool operator ==(const udVector3 &v) const { return x == v.x && y == v.y && z == v.z; } - bool operator !=(const udVector3 &v) const { return !(*this == v); } + udVector3 operator-() const + { + udVector3 r = { -x, -y, -z }; + return r; + } + bool operator==(const udVector3 &v) const { return x == v.x && y == v.y && z == v.z; } + bool operator!=(const udVector3 &v) const { return !(*this == v); } - udVector3 operator +(const udVector3 &v) const { udVector3 r = { x+v.x, y+v.y, z+v.z }; return r; } - udVector3 operator -(const udVector3 &v) const { udVector3 r = { x-v.x, y-v.y, z-v.z }; return r; } - udVector3 operator *(const udVector3 &v) const { udVector3 r = { x*v.x, y*v.y, z*v.z }; return r; } + udVector3 operator+(const udVector3 &v) const + { + udVector3 r = { x + v.x, y + v.y, z + v.z }; + return r; + } + udVector3 operator-(const udVector3 &v) const + { + udVector3 r = { x - v.x, y - v.y, z - v.z }; + return r; + } + udVector3 operator*(const udVector3 &v) const + { + udVector3 r = { x * v.x, y * v.y, z * v.z }; + return r; + } template - udVector3 operator *(U f) const { udVector3 r = { T(x*f), T(y*f), T(z*f) }; return r; } - udVector3 operator /(const udVector3 &v) const { udVector3 r = { x/v.x, y/v.y, z/v.z }; return r; } + udVector3 operator*(U f) const + { + udVector3 r = { T(x * f), T(y * f), T(z * f) }; + return r; + } + udVector3 operator/(const udVector3 &v) const + { + udVector3 r = { x / v.x, y / v.y, z / v.z }; + return r; + } template - udVector3 operator /(U f) const { udVector3 r = { T(x/f), T(y/f), T(z/f) }; return r; } - T operator [](size_t index) const { return ((T*)this)[index]; } + udVector3 operator/(U f) const + { + udVector3 r = { T(x / f), T(y / f), T(z / f) }; + return r; + } + T operator[](size_t index) const { return ((T *)this)[index]; } - udVector3& operator +=(const udVector3 &v) { x+=v.x; y+=v.y; z+=v.z; return *this; } - udVector3& operator -=(const udVector3 &v) { x-=v.x; y-=v.y; z-=v.z; return *this; } - udVector3& operator *=(const udVector3 &v) { x*=v.x; y*=v.y; z*=v.z; return *this; } + udVector3 &operator+=(const udVector3 &v) + { + x += v.x; + y += v.y; + z += v.z; + return *this; + } + udVector3 &operator-=(const udVector3 &v) + { + x -= v.x; + y -= v.y; + z -= v.z; + return *this; + } + udVector3 &operator*=(const udVector3 &v) + { + x *= v.x; + y *= v.y; + z *= v.z; + return *this; + } template - udVector3& operator *=(U f) { x=T(x*f); y=T(y*f); z=T(z*f); return *this; } - udVector3& operator /=(const udVector3 &v) { x/=v.x; y/=v.y; z/=v.z; return *this; } + udVector3 &operator*=(U f) + { + x = T(x * f); + y = T(y * f); + z = T(z * f); + return *this; + } + udVector3 &operator/=(const udVector3 &v) + { + x /= v.x; + y /= v.y; + z /= v.z; + return *this; + } template - udVector3& operator /=(U f) { x=T(x/f); y=T(y/f); z=T(z/f); return *this; } - T& operator [](size_t index) { return ((T*)this)[index]; } + udVector3 &operator/=(U f) + { + x = T(x / f); + y = T(y / f); + z = T(z / f); + return *this; + } + T &operator[](size_t index) { return ((T *)this)[index]; } // static members - static udVector3 zero() { udVector3 r = { T(0), T(0), T(0) }; return r; } - static udVector3 one() { udVector3 r = { T(1), T(1), T(1) }; return r; } + static udVector3 zero() + { + udVector3 r = { T(0), T(0), T(0) }; + return r; + } + static udVector3 one() + { + udVector3 r = { T(1), T(1), T(1) }; + return r; + } - static udVector3 create(T _f) { udVector3 r = { _f, _f, _f }; return r; } - static udVector3 create(T _x, T _y, T _z) { udVector3 r = { _x, _y, _z }; return r; } - static udVector3 create(const udVector2 _v, T _z) { udVector3 r = { _v.x, _v.y, _z }; return r; } + static udVector3 create(T _f) + { + udVector3 r = { _f, _f, _f }; + return r; + } + static udVector3 create(T _x, T _y, T _z) + { + udVector3 r = { _x, _y, _z }; + return r; + } + static udVector3 create(const udVector2 _v, T _z) + { + udVector3 r = { _v.x, _v.y, _z }; + return r; + } template - static udVector3 create(const udVector3 &_v) { udVector3 r = { T(_v.x), T(_v.y), T(_v.z) }; return r; } + static udVector3 create(const udVector3 &_v) + { + udVector3 r = { T(_v.x), T(_v.y), T(_v.z) }; + return r; + } }; template -udVector3 operator *(T f, const udVector3 &v) { return v * f; } +udVector3 operator*(T f, const udVector3 &v) { return v * f; } template struct udVector4 { T x, y, z, w; typedef T ElementType; - enum { ElementCount = 4 }; + enum + { + ElementCount = 4 + }; - udVector3& toVector3() { return *(udVector3*)this; } - const udVector3& toVector3() const { return *(udVector3*)this; } - udVector2& toVector2() { return *(udVector2*)this; } - const udVector2& toVector2() const { return *(udVector2*)this; } + udVector3 &toVector3() { return *(udVector3 *)this; } + const udVector3 &toVector3() const { return *(udVector3 *)this; } + udVector2 &toVector2() { return *(udVector2 *)this; } + const udVector2 &toVector2() const { return *(udVector2 *)this; } - udVector4 operator -() const { udVector4 r = { -x, -y, -z, -w }; return r; } - bool operator ==(const udVector4 &v) const { return x == v.x && y == v.y && z == v.z && w == v.w; } - bool operator !=(const udVector4 &v) const { return !(*this == v); } + udVector4 operator-() const + { + udVector4 r = { -x, -y, -z, -w }; + return r; + } + bool operator==(const udVector4 &v) const { return x == v.x && y == v.y && z == v.z && w == v.w; } + bool operator!=(const udVector4 &v) const { return !(*this == v); } - udVector4 operator +(const udVector4 &v) const { udVector4 r = { x+v.x, y+v.y, z+v.z, w+v.w }; return r; } - udVector4 operator -(const udVector4 &v) const { udVector4 r = { x-v.x, y-v.y, z-v.z, w-v.w }; return r; } - udVector4 operator *(const udVector4 &v) const { udVector4 r = { x*v.x, y*v.y, z*v.z, w*v.w }; return r; } + udVector4 operator+(const udVector4 &v) const + { + udVector4 r = { x + v.x, y + v.y, z + v.z, w + v.w }; + return r; + } + udVector4 operator-(const udVector4 &v) const + { + udVector4 r = { x - v.x, y - v.y, z - v.z, w - v.w }; + return r; + } + udVector4 operator*(const udVector4 &v) const + { + udVector4 r = { x * v.x, y * v.y, z * v.z, w * v.w }; + return r; + } template - udVector4 operator *(U f) const { udVector4 r = { T(x*f), T(y*f), T(z*f), T(w*f) }; return r; } - udVector4 operator /(const udVector4 &v) const { udVector4 r = { x/v.x, y/v.y, z/v.z, w/v.w }; return r; } + udVector4 operator*(U f) const + { + udVector4 r = { T(x * f), T(y * f), T(z * f), T(w * f) }; + return r; + } + udVector4 operator/(const udVector4 &v) const + { + udVector4 r = { x / v.x, y / v.y, z / v.z, w / v.w }; + return r; + } template - udVector4 operator /(U f) const { udVector4 r = { T(x/f), T(y/f), T(z/f), T(w/f) }; return r; } - T operator [](size_t index) const { return ((T*)this)[index]; } + udVector4 operator/(U f) const + { + udVector4 r = { T(x / f), T(y / f), T(z / f), T(w / f) }; + return r; + } + T operator[](size_t index) const { return ((T *)this)[index]; } - udVector4& operator +=(const udVector4 &v) { x+=v.x; y+=v.y; z+=v.z; w+=v.w; return *this; } - udVector4& operator -=(const udVector4 &v) { x-=v.x; y-=v.y; z-=v.z; w-=v.w; return *this; } - udVector4& operator *=(const udVector4 &v) { x*=v.x; y*=v.y; z*=v.z; w*=v.w; return *this; } + udVector4 &operator+=(const udVector4 &v) + { + x += v.x; + y += v.y; + z += v.z; + w += v.w; + return *this; + } + udVector4 &operator-=(const udVector4 &v) + { + x -= v.x; + y -= v.y; + z -= v.z; + w -= v.w; + return *this; + } + udVector4 &operator*=(const udVector4 &v) + { + x *= v.x; + y *= v.y; + z *= v.z; + w *= v.w; + return *this; + } template - udVector4& operator *=(U f) { x=T(x*f); y=T(y*f); z=T(z*f); w=T(w*f); return *this; } - udVector4& operator /=(const udVector4 &v) { x/=v.x; y/=v.y; z/=v.z; w/=v.w; return *this; } + udVector4 &operator*=(U f) + { + x = T(x * f); + y = T(y * f); + z = T(z * f); + w = T(w * f); + return *this; + } + udVector4 &operator/=(const udVector4 &v) + { + x /= v.x; + y /= v.y; + z /= v.z; + w /= v.w; + return *this; + } template - udVector4& operator /=(U f) { x=T(x/f); y=T(y/f); z=T(z/f); w=T(w/f); return *this; } - T& operator [](size_t index) { return ((T*)this)[index]; } + udVector4 &operator/=(U f) + { + x = T(x / f); + y = T(y / f); + z = T(z / f); + w = T(w / f); + return *this; + } + T &operator[](size_t index) { return ((T *)this)[index]; } // static members - static udVector4 zero() { udVector4 r = { T(0), T(0), T(0), T(0) }; return r; } - static udVector4 one() { udVector4 r = { T(1), T(1), T(1), T(1) }; return r; } - static udVector4 identity() { udVector4 r = { T(0), T(0), T(0), T(1) }; return r; } - - static udVector4 create(T _f) { udVector4 r = { _f, _f, _f, _f }; return r; } - static udVector4 create(T _x, T _y, T _z, T _w) { udVector4 r = { _x, _y, _z, _w }; return r; } - static udVector4 create(const udVector3 &_v, T _w) { udVector4 r = { _v.x, _v.y, _v.z, _w }; return r; } - static udVector4 create(const udVector2 &_v, T _z, T _w) { udVector4 r = { _v.x, _v.y, _z, _w }; return r; } + static udVector4 zero() + { + udVector4 r = { T(0), T(0), T(0), T(0) }; + return r; + } + static udVector4 one() + { + udVector4 r = { T(1), T(1), T(1), T(1) }; + return r; + } + static udVector4 identity() + { + udVector4 r = { T(0), T(0), T(0), T(1) }; + return r; + } + + static udVector4 create(T _f) + { + udVector4 r = { _f, _f, _f, _f }; + return r; + } + static udVector4 create(T _x, T _y, T _z, T _w) + { + udVector4 r = { _x, _y, _z, _w }; + return r; + } + static udVector4 create(const udVector3 &_v, T _w) + { + udVector4 r = { _v.x, _v.y, _v.z, _w }; + return r; + } + static udVector4 create(const udVector2 &_v, T _z, T _w) + { + udVector4 r = { _v.x, _v.y, _z, _w }; + return r; + } template - static udVector4 create(const udVector4 &_v) { udVector4 r = { T(_v.x), T(_v.y), T(_v.z), T(_v.w) }; return r; } + static udVector4 create(const udVector4 &_v) + { + udVector4 r = { T(_v.x), T(_v.y), T(_v.z), T(_v.w) }; + return r; + } }; template -udVector4 operator *(U f, const udVector4 &v) { return v * f; } +udVector4 operator*(U f, const udVector4 &v) { return v * f; } template struct udQuaternion { T x, y, z, w; typedef T ElementType; - enum { ElementCount = 4 }; + enum + { + ElementCount = 4 + }; - const udVector4& toVector4() const { return *(udVector4*)this; } + const udVector4 &toVector4() const { return *(udVector4 *)this; } - udQuaternion operator -() const { udQuaternion r = { -x, -y, -z, -w }; return r; } - udQuaternion operator +(const udQuaternion &q) const { udQuaternion r = { x + q.x, y + q.y, z + q.z, w + q.w }; return r; } - udQuaternion operator -(const udQuaternion &q) const { udQuaternion r = { x - q.x, y - q.y, z - q.z, w - q.w }; return r; } - udQuaternion operator *(const udQuaternion &q) const { return udMul(*this, q); } + udQuaternion operator-() const + { + udQuaternion r = { -x, -y, -z, -w }; + return r; + } + udQuaternion operator+(const udQuaternion &q) const + { + udQuaternion r = { x + q.x, y + q.y, z + q.z, w + q.w }; + return r; + } + udQuaternion operator-(const udQuaternion &q) const + { + udQuaternion r = { x - q.x, y - q.y, z - q.z, w - q.w }; + return r; + } + udQuaternion operator*(const udQuaternion &q) const { return udMul(*this, q); } template - udQuaternion operator *(U f) const { udQuaternion r = { T(x*f), T(y*f), T(z*f), T(w*f) }; return r; } - T operator [](size_t index) const { return ((T*)this)[index]; } + udQuaternion operator*(U f) const + { + udQuaternion r = { T(x * f), T(y * f), T(z * f), T(w * f) }; + return r; + } + T operator[](size_t index) const { return ((T *)this)[index]; } - udQuaternion& operator *=(const udQuaternion &q) { *this = udMul(*this, q); return *this; } + udQuaternion &operator*=(const udQuaternion &q) + { + *this = udMul(*this, q); + return *this; + } template - udQuaternion& operator *=(U f) { x=T(x*f); y=T(y*f); z=T(z*f); w=T(w*f); return *this; } - udQuaternion& operator +=(const udQuaternion &q) { x += q.x; y += q.y; z += q.z; w += q.w; return *this; } - udQuaternion& operator -=(const udQuaternion &q) { x -= q.x; y -= q.y; z -= q.z; w -= q.w; return *this; } + udQuaternion &operator*=(U f) + { + x = T(x * f); + y = T(y * f); + z = T(z * f); + w = T(w * f); + return *this; + } + udQuaternion &operator+=(const udQuaternion &q) + { + x += q.x; + y += q.y; + z += q.z; + w += q.w; + return *this; + } + udQuaternion &operator-=(const udQuaternion &q) + { + x -= q.x; + y -= q.y; + z -= q.z; + w -= q.w; + return *this; + } - T& operator [](size_t index) { return ((T*)this)[index]; } + T &operator[](size_t index) { return ((T *)this)[index]; } - udQuaternion& inverse(); - udQuaternion& conjugate(); + udQuaternion &inverse(); + udQuaternion &conjugate(); udVector3 apply(const udVector3 &v) const; udVector3 eulerAngles() const; // static members - static udQuaternion zero() { udQuaternion q = { T(0), T(0), T(0), T(0) }; return q; } - static udQuaternion identity() { udQuaternion q = { T(0), T(0), T(0), T(1) }; return q; } + static udQuaternion zero() + { + udQuaternion q = { T(0), T(0), T(0), T(0) }; + return q; + } + static udQuaternion identity() + { + udQuaternion q = { T(0), T(0), T(0), T(1) }; + return q; + } static udQuaternion create(const udVector3 &axis, T rad); static udQuaternion create(const T _y, const T _p, const T _r); static udQuaternion create(const udVector3 &ypr) { return create(ypr.x, ypr.y, ypr.z); } template - static udQuaternion create(const udQuaternion &_q) { udQuaternion r = { T(_q.x), T(_q.y), T(_q.z), T(_q.w) }; return r; } + static udQuaternion create(const udQuaternion &_q) + { + udQuaternion r = { T(_q.x), T(_q.y), T(_q.z), T(_q.w) }; + return r; + } }; template -udQuaternion operator *(U f, const udQuaternion &q) { return q * f; } +udQuaternion operator*(U f, const udQuaternion &q) { return q * f; } template struct udRay @@ -455,10 +915,18 @@ struct udRay udVector3 direction; // static members - static udRay create(const udVector3 &position, const udVector3 &direction) { udRay r = { position, direction }; return r; } + static udRay create(const udVector3 &position, const udVector3 &direction) + { + udRay r = { position, direction }; + return r; + } template - static udRay create(const udRay &_v) { udRay r = { udVector3::create(_v.position), udVector3::create(_v.direction) }; return r; } + static udRay create(const udRay &_v) + { + udRay r = { udVector3::create(_v.position), udVector3::create(_v.direction) }; + return r; + } static udRay rotationAround(const udRay &ray, const udVector3 ¢er, const udVector3 &axis, const T &angle); }; @@ -472,15 +940,26 @@ struct udPlane bool intersects(const udRay &ray, udVector3 *pIntersectionPoint, T *pIntersectionDistance) const; // static members - static udPlane create(const udVector3 &position, const udVector3 &normal) { udPlane r = { position, normal }; return r; } + static udPlane create(const udVector3 &position, const udVector3 &normal) + { + udPlane r = { position, normal }; + return r; + } template - static udPlane create(const udPlane &_v) { udPlane r = { udVector3::create(_v.point), udVector3::create(_v.normal) }; return r; } + static udPlane create(const udPlane &_v) + { + udPlane r = { udVector3::create(_v.point), udVector3::create(_v.normal) }; + return r; + } }; template struct udMatrix4x4 { - enum { ElementCount = 16 }; + enum + { + ElementCount = 16 + }; union { T a[16]; @@ -495,30 +974,47 @@ struct udMatrix4x4 struct { T // remember, we store columns (axis) sequentially! (so appears transposed here) - _00, _10, _20, _30, - _01, _11, _21, _31, - _02, _12, _22, _32, - _03, _13, _23, _33; + _00, + _10, _20, _30, + _01, _11, _21, _31, + _02, _12, _22, _32, + _03, _13, _23, _33; } m; }; - udMatrix4x4 operator *(const udMatrix4x4 &m2) const { return udMul(*this, m2); } + udMatrix4x4 operator*(const udMatrix4x4 &m2) const { return udMul(*this, m2); } template - udMatrix4x4 operator *(U f) const { return udMul(*this, f); } - udMatrix4x4 operator +(const udMatrix4x4 &m2) const { return udAdd(*this, m2); } - udMatrix4x4 operator -(const udMatrix4x4 &m2) const { return udSub(*this, m2); } - udVector4 operator *(const udVector4 &v) const { return udMul(*this, v); } + udMatrix4x4 operator*(U f) const { return udMul(*this, f); } + udMatrix4x4 operator+(const udMatrix4x4 &m2) const { return udAdd(*this, m2); } + udMatrix4x4 operator-(const udMatrix4x4 &m2) const { return udSub(*this, m2); } + udVector4 operator*(const udVector4 &v) const { return udMul(*this, v); } - udMatrix4x4& operator +=(const udMatrix4x4 &m2) { *this = udAdd(*this, m2); return *this; } - udMatrix4x4& operator -=(const udMatrix4x4 &m2) { *this = udSub(*this, m2); return *this; } - udMatrix4x4& operator *=(const udMatrix4x4 &m2) { *this = udMul(*this, m2); return *this; } - udMatrix4x4& operator *=(T f) { *this = udMul(*this, f); return *this; } + udMatrix4x4 &operator+=(const udMatrix4x4 &m2) + { + *this = udAdd(*this, m2); + return *this; + } + udMatrix4x4 &operator-=(const udMatrix4x4 &m2) + { + *this = udSub(*this, m2); + return *this; + } + udMatrix4x4 &operator*=(const udMatrix4x4 &m2) + { + *this = udMul(*this, m2); + return *this; + } + udMatrix4x4 &operator*=(T f) + { + *this = udMul(*this, f); + return *this; + } - bool operator ==(const udMatrix4x4& rh) const { return memcmp(this, &rh, sizeof(*this)) == 0; } + bool operator==(const udMatrix4x4 &rh) const { return memcmp(this, &rh, sizeof(*this)) == 0; } - udMatrix4x4& transpose(); + udMatrix4x4 &transpose(); T determinant(); - udMatrix4x4& inverse(); + udMatrix4x4 &inverse(); udVector3 extractYPR() const; udQuaternion extractQuaternion() const; @@ -550,8 +1046,8 @@ struct udMatrix4x4 static udMatrix4x4 scaleNonUniform(T x, T y, T z, const udVector3 &t = udVector3::zero()); static udMatrix4x4 scaleNonUniform(const udVector3 &s, const udVector3 &t = udVector3::zero()) { return scaleNonUniform(s.x, s.y, s.z, t); } - static udMatrix4x4 perspectiveZO(T fovY, T aspectRatio, T znear, T zfar); // Clip-Z is [0, 1]. Compatiable with DirectX coordinate system. Previously `perspective()`. - static udMatrix4x4 perspectiveNO(T fovY, T aspectRatio, T znear, T zfar); // Clip-Z is [-1, 1]. Comptaible with OpenGL coordinate system. + static udMatrix4x4 perspectiveZO(T fovY, T aspectRatio, T znear, T zfar); // Clip-Z is [0, 1]. Compatiable with DirectX coordinate system. Previously `perspective()`. + static udMatrix4x4 perspectiveNO(T fovY, T aspectRatio, T znear, T zfar); // Clip-Z is [-1, 1]. Comptaible with OpenGL coordinate system. static udMatrix4x4 orthoZO(T left, T right, T bottom, T top, T znear = T(0), T zfar = T(1)); // Clip-Z is [0, 1]. Compatiable with DirectX coordinate system. static udMatrix4x4 orthoNO(T left, T right, T bottom, T top, T znear = T(0), T zfar = T(1)); // Clip-Z is [-1, 1]. Comptaible with OpenGL coordinate system. Previously `ortho()`. static udMatrix4x4 orthoForScreen(T width, T height, T znear = T(0), T zfar = T(1)); @@ -562,19 +1058,18 @@ struct udMatrix4x4 static udMatrix4x4 lookAt(const udVector3 &from, const udVector3 &at, const udVector3 &up = udVector3::create(T(0), T(0), T(1))); }; template -udMatrix4x4 operator *(U f, const udMatrix4x4 &m) { return m*f; } - +udMatrix4x4 operator*(U f, const udMatrix4x4 &m) { return m * f; } // typedef's for typed vectors/matices -typedef udVector2 udShort2; -typedef udVector3 udShort3; -typedef udVector4 udShort4; -typedef udVector2 udInt2; -typedef udVector3 udInt3; -typedef udVector4 udInt4; -typedef udVector2 udLong2; -typedef udVector3 udLong3; -typedef udVector4 udLong4; +typedef udVector2 udShort2; +typedef udVector3 udShort3; +typedef udVector4 udShort4; +typedef udVector2 udInt2; +typedef udVector3 udInt3; +typedef udVector4 udInt4; +typedef udVector2 udLong2; +typedef udVector3 udLong3; +typedef udVector4 udLong4; typedef udVector2 udUShort2; typedef udVector3 udUShort3; typedef udVector4 udUShort4; @@ -584,24 +1079,24 @@ typedef udVector4 udUInt4; typedef udVector2 udULong2; typedef udVector3 udULong3; typedef udVector4 udULong4; -typedef udVector4 udFloat4; -typedef udVector3 udFloat3; -typedef udVector2 udFloat2; +typedef udVector4 udFloat4; +typedef udVector3 udFloat3; +typedef udVector2 udFloat2; typedef udVector4 udDouble4; typedef udVector3 udDouble3; typedef udVector2 udDouble2; -typedef udMatrix4x4 udFloat4x4; +typedef udMatrix4x4 udFloat4x4; typedef udMatrix4x4 udDouble4x4; //typedef udMatrix3x4 udFloat3x4; //typedef udMatrix3x4 udDouble3x4; //typedef udMatrix3x3 udFloat3x3; //typedef udMatrix3x3 udDouble3x3; -typedef udQuaternion udFloatQuat; -typedef udQuaternion udDoubleQuat; +typedef udQuaternion udFloatQuat; +typedef udQuaternion udDoubleQuat; -#include "udMath_Inl.h" +# include "udMath_Inl.h" #endif // __cplusplus diff --git a/Include/udMath_Inl.h b/Include/udMath_Inl.h index 98a8a18e..b39551b9 100644 --- a/Include/udMath_Inl.h +++ b/Include/udMath_Inl.h @@ -5,19 +5,24 @@ T udHighestBitValue(T i) while (i) { result = (i & (~i + 1)); // grab lowest bit - i &= ~result; // clear lowest bit + i &= ~result; // clear lowest bit } return result; } -template bool udIsPowerOfTwo(T i) { +template +bool udIsPowerOfTwo(T i) +{ return !(i & (i - 1)); } -template T udPowerOfTwoAbove(T v) { +template +T udPowerOfTwoAbove(T v) +{ return udIsPowerOfTwo(v) ? v : udHighestBitValue(v) << 1; } -template T udRoundEven(T t) +template +T udRoundEven(T t) { int integer = (int)t; T integerPart = (integer < 0 ? udCeil(t) : udFloor(t)); @@ -45,15 +50,24 @@ UDFORCE_INLINE float udLog(float f, float base) { return udLogN(f) / udLogN(base UDFORCE_INLINE double udLog(double f, double base) { return udLogN(f) / udLogN(base); } #if defined(_MSC_VER) && _MSC_VER >= 1800 -UDFORCE_INLINE float udLog2(float f) { return log2f(f); } +UDFORCE_INLINE float udLog2(float f) +{ + return log2f(f); +} UDFORCE_INLINE double udLog2(double d) { return log2(d); } #else -UDFORCE_INLINE float udLog2(float f) { return udLog(f, 2.f); } +UDFORCE_INLINE float udLog2(float f) +{ + return udLog(f, 2.f); +} UDFORCE_INLINE double udLog2(double d) { return udLog(d, 2.0); } #endif -UDFORCE_INLINE float udRSqrt(float f) { return 1.f/sqrtf(f); } -UDFORCE_INLINE double udRSqrt(double d) { return 1.0/sqrt(d); } +UDFORCE_INLINE float udRSqrt(float f) +{ + return 1.f / sqrtf(f); +} +UDFORCE_INLINE double udRSqrt(double d) { return 1.0 / sqrt(d); } UDFORCE_INLINE float udSqrt(float f) { return sqrtf(f); } UDFORCE_INLINE double udSqrt(double d) { return sqrt(d); } UDFORCE_INLINE float udSin(float f) { return sinf(f); } @@ -85,123 +99,305 @@ UDFORCE_INLINE double udATanh(double d) { return atanh(d); } UDFORCE_INLINE float udRound(float f) { return f >= 0.0f ? floorf(f + 0.5f) : ceilf(f - 0.5f); } UDFORCE_INLINE double udRound(double d) { return d >= 0.0 ? floor(d + 0.5) : ceil(d - 0.5); } -template udVector2 udRound(const udVector2 &v) { return v.create(udRound(v.x), udRound(v.y)); } -template udVector3 udRound(const udVector3 &v) { return v.create(udRound(v.x), udRound(v.y), udRound(v.z)); } -template udVector4 udRound(const udVector4 &v) { return v.create(udRound(v.x), udRound(v.y), udRound(v.z), udRound(v.w)); } +template +udVector2 udRound(const udVector2 &v) { return v.create(udRound(v.x), udRound(v.y)); } +template +udVector3 udRound(const udVector3 &v) { return v.create(udRound(v.x), udRound(v.y), udRound(v.z)); } +template +udVector4 udRound(const udVector4 &v) { return v.create(udRound(v.x), udRound(v.y), udRound(v.z), udRound(v.w)); } UDFORCE_INLINE float udFloor(float f) { return floorf(f); } UDFORCE_INLINE double udFloor(double d) { return floor(d); } -template udVector2 udFloor(const udVector2 &v) { return v.create(udFloor(v.x), udFloor(v.y)); } -template udVector3 udFloor(const udVector3 &v) { return v.create(udFloor(v.x), udFloor(v.y), udFloor(v.z)); } -template udVector4 udFloor(const udVector4 &v) { return v.create(udFloor(v.x), udFloor(v.y), udFloor(v.z), udFloor(v.w)); } +template +udVector2 udFloor(const udVector2 &v) { return v.create(udFloor(v.x), udFloor(v.y)); } +template +udVector3 udFloor(const udVector3 &v) { return v.create(udFloor(v.x), udFloor(v.y), udFloor(v.z)); } +template +udVector4 udFloor(const udVector4 &v) { return v.create(udFloor(v.x), udFloor(v.y), udFloor(v.z), udFloor(v.w)); } UDFORCE_INLINE float udCeil(float f) { return ceilf(f); } UDFORCE_INLINE double udCeil(double d) { return ceil(d); } -template udVector2 udCeil(const udVector2 &v) { return v.create(udCeil(v.x), udCeil(v.y)); } -template udVector3 udCeil(const udVector3 &v) { return v.create(udCeil(v.x), udCeil(v.y), udCeil(v.z)); } -template udVector4 udCeil(const udVector4 &v) { return v.create(udCeil(v.x), udCeil(v.y), udCeil(v.z), udCeil(v.w)); } +template +udVector2 udCeil(const udVector2 &v) { return v.create(udCeil(v.x), udCeil(v.y)); } +template +udVector3 udCeil(const udVector3 &v) { return v.create(udCeil(v.x), udCeil(v.y), udCeil(v.z)); } +template +udVector4 udCeil(const udVector4 &v) { return v.create(udCeil(v.x), udCeil(v.y), udCeil(v.z), udCeil(v.w)); } UDFORCE_INLINE float udMod(float f, float den) { return fmodf(f, den); } UDFORCE_INLINE double udMod(double d, double den) { return fmod(d, den); } -template udVector2 udMod(const udVector2 &v) { return v.create(udMod(v.x), udMod(v.y)); } -template udVector3 udMod(const udVector3 &v) { return v.create(udMod(v.x), udMod(v.y), udMod(v.z)); } -template udVector4 udMod(const udVector4 &v) { return v.create(udMod(v.x), udMod(v.y), udMod(v.z), udMod(v.w)); } - -template T udAbs(T v) { return v < T(0) ? -v : v; } -template udVector2 udAbs(const udVector2 &v) { udVector2 r = { v.x udVector3 udAbs(const udVector3 &v) { udVector3 r = { v.x udVector4 udAbs(const udVector4 &v) { udVector4 r = { v.x udQuaternion udAbs(const udQuaternion &q) { udQuaternion r = { q.x udVector2 udMin(const udVector2 &v1, const udVector2 &v2) { udVector2 r = { v1.x udVector3 udMin(const udVector3 &v1, const udVector3 &v2) { udVector3 r = { v1.x udVector4 udMin(const udVector4 &v1, const udVector4 &v2) { udVector4 r = { v1.x T udMinElement(const udVector2 &v) { return udMin(v.x, v.y); } -template T udMinElement(const udVector3 &v) { return udMin(udMin(v.x, v.y), v.z); } -template T udMinElement(const udVector4 &v) { return udMin(udMin(v.x, v.y), udMin(v.z, v.w)); } -template udVector2 udMax(const udVector2 &v1, const udVector2 &v2) { udVector2 r = { v1.x>v2.x?v1.x:v2.x, v1.y>v2.y?v1.y:v2.y }; return r; } -template udVector3 udMax(const udVector3 &v1, const udVector3 &v2) { udVector3 r = { v1.x>v2.x?v1.x:v2.x, v1.y>v2.y?v1.y:v2.y, v1.z>v2.z?v1.z:v2.z }; return r; } -template udVector4 udMax(const udVector4 &v1, const udVector4 &v2) { udVector4 r = { v1.x>v2.x?v1.x:v2.x, v1.y>v2.y?v1.y:v2.y, v1.z>v2.z?v1.z:v2.z, v1.w>v2.w?v1.w:v2.w }; return r; } -template T udMaxElement(const udVector2 &v) { return udMax(v.x, v.y); } -template T udMaxElement(const udVector3 &v) { return udMax(udMax(v.x, v.y), v.z); } -template T udMaxElement(const udVector4 &v) { return udMax(udMax(v.x, v.y), udMax(v.z, v.w)); } -template T udClamp(T v, T _min, T _max) { return v<_min?_min:(v>_max?_max:v); } -template udVector2 udClamp(const udVector2 &v, const udVector2 &_min, const udVector2 &_max) { udVector2 r = { v.x<_min.x?_min.x:(v.x>_max.x?_max.x:v.x), v.y<_min.y?_min.y:(v.y>_max.y?_max.y:v.y) }; return r; } -template udVector3 udClamp(const udVector3 &v, const udVector3 &_min, const udVector3 &_max) { udVector3 r = { v.x<_min.x?_min.x:(v.x>_max.x?_max.x:v.x), v.y<_min.y?_min.y:(v.y>_max.y?_max.y:v.y), v.z<_min.z?_min.z:(v.z>_max.z?_max.z:v.z) }; return r; } -template udVector4 udClamp(const udVector4 &v, const udVector4 &_min, const udVector4 &_max) { udVector4 r = { v.x<_min.x?_min.x:(v.x>_max.x?_max.x:v.x), v.y<_min.y?_min.y:(v.y>_max.y?_max.y:v.y), v.z<_min.z?_min.z:(v.z>_max.z?_max.z:v.z), v.w<_min.w?_min.w:(v.w>_max.w?_max.w:v.w) }; return r; } - -template T udSaturate(const T &v) { return udClamp(v, (T)0, (T)1); } -template udVector2 udSaturate(const udVector2 &v) { return udClamp(v, udVector2::zero(), udVector2::one()); } -template udVector3 udSaturate(const udVector3 &v) { return udClamp(v, udVector3::zero(), udVector3::one()); } -template udVector4 udSaturate(const udVector4 &v) { return udClamp(v, udVector4::zero(), udVector4::one()); } - -template bool udIsUnitLength(const V &v, T epsilon) { return udAbs(typename V::ElementType(1) - udMag(v)) < typename V::ElementType(epsilon); } - -template UDFORCE_INLINE T udDot(const udVector2 &v1, const udVector2 &v2) { return udDot2(v1, v2); } -template UDFORCE_INLINE T udDot(const udVector3 &v1, const udVector3 &v2) { return udDot3(v1, v2); } -template UDFORCE_INLINE T udDot(const udVector4 &v1, const udVector4 &v2) { return udDot4(v1, v2); } -template UDFORCE_INLINE T udDot(const udQuaternion &q1, const udQuaternion &q2) { return udDotQ(q1, q2); } - -template T udDot2(const udVector2 &v1, const udVector2 &v2) { return v1.x*v2.x + v1.y*v2.y; } -template T udDot2(const udVector3 &v1, const udVector3 &v2) { return v1.x*v2.x + v1.y*v2.y; } -template T udDot2(const udVector4 &v1, const udVector4 &v2) { return v1.x*v2.x + v1.y*v2.y; } -template T udDot3(const udVector3 &v1, const udVector3 &v2) { return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z; } -template T udDot3(const udVector4 &v1, const udVector4 &v2) { return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z; } -template T udDot4(const udVector4 &v1, const udVector4 &v2) { return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z + v1.w*v2.w; } -template T udDoth(const udVector3 &v3, const udVector4 &v4) { return v3.x*v4.x + v3.y*v4.y + v3.z*v4.z + v4.w; } -template T udDotQ(const udQuaternion &q1, const udQuaternion &q2) { return q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w; } - - -template T UDFORCE_INLINE udMagSq(const udVector2 &v) { return udMagSq2(v); } -template T UDFORCE_INLINE udMagSq(const udVector3 &v) { return udMagSq3(v); } -template T UDFORCE_INLINE udMagSq(const udVector4 &v) { return udMagSq4(v); } -template T UDFORCE_INLINE udMagSq(const udQuaternion &q) { return udMagSqQ(q); } - -template T udMagSq2(const udVector2 &v) { return v.x*v.x + v.y*v.y; } -template T udMagSq2(const udVector3 &v) { return v.x*v.x + v.y*v.y; } -template T udMagSq2(const udVector4 &v) { return v.x*v.x + v.y*v.y; } -template T udMagSq3(const udVector3 &v) { return v.x*v.x + v.y*v.y + v.z*v.z; } -template T udMagSq3(const udVector4 &v) { return v.x*v.x + v.y*v.y + v.z*v.z; } -template T udMagSq4(const udVector4 &v) { return v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w; } -template T udMagSqQ(const udQuaternion &q) { return q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w; } - - -template T UDFORCE_INLINE udMag(const udVector2 &v) { return udMag2(v); } -template T UDFORCE_INLINE udMag(const udVector3 &v) { return udMag3(v); } -template T UDFORCE_INLINE udMag(const udVector4 &v) { return udMag4(v); } -template T UDFORCE_INLINE udMag(const udQuaternion &v) { return udMagQ(v); } - -template T udMag2(const udVector2 &v) { return udSqrt(v.x*v.x + v.y*v.y); } -template T udMag2(const udVector3 &v) { return udSqrt(v.x*v.x + v.y*v.y); } -template T udMag2(const udVector4 &v) { return udSqrt(v.x*v.x + v.y*v.y); } -template T udMag3(const udVector3 &v) { return udSqrt(v.x*v.x + v.y*v.y + v.z*v.z); } -template T udMag3(const udVector4 &v) { return udSqrt(v.x*v.x + v.y*v.y + v.z*v.z); } -template T udMag4(const udVector4 &v) { return udSqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); } -template T udMagQ(const udQuaternion &q) { return udSqrt(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w); } - -template UDFORCE_INLINE T udCross(const udVector2 &v1, const udVector2 &v2) { return udCross2(v1, v2); } -template UDFORCE_INLINE udVector3 udCross(const udVector3 &v1, const udVector3 &v2) { return udCross3(v1, v2); } - -template T udCross2(const udVector2 &v1, const udVector2 &v2) { return v1.x*v2.y - v1.y*v2.x; } -template T udCross2(const udVector3 &v1, const udVector3 &v2) { return v1.x*v2.y - v1.y*v2.x; } -template T udCross2(const udVector4 &v1, const udVector4 &v2) { return v1.x*v2.y - v1.y*v2.x; } - -template udVector3 udCross3(const udVector3 &v1, const udVector3 &v2) { udVector3 r = { v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x }; return r; } -template udVector3 udCross3(const udVector4 &v1, const udVector4 &v2) { udVector3 r = { v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x }; return r; } - - -template UDFORCE_INLINE udVector2 udNormalize(const udVector2 &v) { return udNormalize2(v); } -template UDFORCE_INLINE udVector3 udNormalize(const udVector3 &v) { return udNormalize3(v); } -template UDFORCE_INLINE udVector4 udNormalize(const udVector4 &v) { return udNormalize4(v); } -template UDFORCE_INLINE udQuaternion udNormalize(const udQuaternion &q) { return udNormalizeQ(q); } - -template udVector2 udNormalize2(const udVector2 &v) { T s = udRSqrt(v.x*v.x + v.y*v.y); udVector2 r = { v.x*s, v.y*s }; return r; } -template udVector3 udNormalize2(const udVector3 &v) { T s = udRSqrt(v.x*v.x + v.y*v.y); udVector3 r = { v.x*s, v.y*s, v.z }; return r; } -template udVector4 udNormalize2(const udVector4 &v) { T s = udRSqrt(v.x*v.x + v.y*v.y); udVector4 r = { v.x*s, v.y*s, v.z, v.w }; return r; } -template udVector3 udNormalize3(const udVector3 &v) { T s = udRSqrt(v.x*v.x + v.y*v.y + v.z*v.z); udVector3 r = { v.x*s, v.y*s, v.z*s }; return r; } -template udVector4 udNormalize3(const udVector4 &v) { T s = udRSqrt(v.x*v.x + v.y*v.y + v.z*v.z); udVector4 r = { v.x*s, v.y*s, v.z*s, v.w }; return r; } -template udVector4 udNormalize4(const udVector4 &v) { T s = udRSqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); udVector4 r = { v.x*s, v.y*s, v.z*s, v.w*s }; return r; } -template udQuaternion udNormalizeQ(const udQuaternion &v) { T s = udRSqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w); udQuaternion r = { v.x*s, v.y*s, v.z*s, v.w*s }; return r; } +template +udVector2 udMod(const udVector2 &v) { return v.create(udMod(v.x), udMod(v.y)); } +template +udVector3 udMod(const udVector3 &v) { return v.create(udMod(v.x), udMod(v.y), udMod(v.z)); } +template +udVector4 udMod(const udVector4 &v) { return v.create(udMod(v.x), udMod(v.y), udMod(v.z), udMod(v.w)); } + +template +T udAbs(T v) { return v < T(0) ? -v : v; } +template +udVector2 udAbs(const udVector2 &v) +{ + udVector2 r = { v.x < T(0) ? -v.x : v.x, v.y < T(0) ? -v.y : v.y }; + return r; +} +template +udVector3 udAbs(const udVector3 &v) +{ + udVector3 r = { v.x < T(0) ? -v.x : v.x, v.y < T(0) ? -v.y : v.y, v.z < T(0) ? -v.z : v.z }; + return r; +} +template +udVector4 udAbs(const udVector4 &v) +{ + udVector4 r = { v.x < T(0) ? -v.x : v.x, v.y < T(0) ? -v.y : v.y, v.z < T(0) ? -v.z : v.z, v.w < T(0) ? -v.w : v.w }; + return r; +} +template +udQuaternion udAbs(const udQuaternion &q) +{ + udQuaternion r = { q.x < T(0) ? -q.x : q.x, q.y < T(0) ? -q.y : q.y, q.z < T(0) ? -q.z : q.z, q.w < T(0) ? -q.w : q.w }; + return r; +} + +template +udVector2 udMin(const udVector2 &v1, const udVector2 &v2) +{ + udVector2 r = { v1.x < v2.x ? v1.x : v2.x, v1.y < v2.y ? v1.y : v2.y }; + return r; +} +template +udVector3 udMin(const udVector3 &v1, const udVector3 &v2) +{ + udVector3 r = { v1.x < v2.x ? v1.x : v2.x, v1.y < v2.y ? v1.y : v2.y, v1.z < v2.z ? v1.z : v2.z }; + return r; +} +template +udVector4 udMin(const udVector4 &v1, const udVector4 &v2) +{ + udVector4 r = { v1.x < v2.x ? v1.x : v2.x, v1.y < v2.y ? v1.y : v2.y, v1.z < v2.z ? v1.z : v2.z, v1.w < v2.w ? v1.w : v2.w }; + return r; +} +template +T udMinElement(const udVector2 &v) { return udMin(v.x, v.y); } +template +T udMinElement(const udVector3 &v) { return udMin(udMin(v.x, v.y), v.z); } +template +T udMinElement(const udVector4 &v) { return udMin(udMin(v.x, v.y), udMin(v.z, v.w)); } +template +udVector2 udMax(const udVector2 &v1, const udVector2 &v2) +{ + udVector2 r = { v1.x > v2.x ? v1.x : v2.x, v1.y > v2.y ? v1.y : v2.y }; + return r; +} +template +udVector3 udMax(const udVector3 &v1, const udVector3 &v2) +{ + udVector3 r = { v1.x > v2.x ? v1.x : v2.x, v1.y > v2.y ? v1.y : v2.y, v1.z > v2.z ? v1.z : v2.z }; + return r; +} +template +udVector4 udMax(const udVector4 &v1, const udVector4 &v2) +{ + udVector4 r = { v1.x > v2.x ? v1.x : v2.x, v1.y > v2.y ? v1.y : v2.y, v1.z > v2.z ? v1.z : v2.z, v1.w > v2.w ? v1.w : v2.w }; + return r; +} +template +T udMaxElement(const udVector2 &v) { return udMax(v.x, v.y); } +template +T udMaxElement(const udVector3 &v) { return udMax(udMax(v.x, v.y), v.z); } +template +T udMaxElement(const udVector4 &v) { return udMax(udMax(v.x, v.y), udMax(v.z, v.w)); } +template +T udClamp(T v, T _min, T _max) { return v < _min ? _min : (v > _max ? _max : v); } +template +udVector2 udClamp(const udVector2 &v, const udVector2 &_min, const udVector2 &_max) +{ + udVector2 r = { v.x < _min.x ? _min.x : (v.x > _max.x ? _max.x : v.x), v.y < _min.y ? _min.y : (v.y > _max.y ? _max.y : v.y) }; + return r; +} +template +udVector3 udClamp(const udVector3 &v, const udVector3 &_min, const udVector3 &_max) +{ + udVector3 r = { v.x < _min.x ? _min.x : (v.x > _max.x ? _max.x : v.x), v.y < _min.y ? _min.y : (v.y > _max.y ? _max.y : v.y), v.z < _min.z ? _min.z : (v.z > _max.z ? _max.z : v.z) }; + return r; +} +template +udVector4 udClamp(const udVector4 &v, const udVector4 &_min, const udVector4 &_max) +{ + udVector4 r = { v.x < _min.x ? _min.x : (v.x > _max.x ? _max.x : v.x), v.y < _min.y ? _min.y : (v.y > _max.y ? _max.y : v.y), v.z < _min.z ? _min.z : (v.z > _max.z ? _max.z : v.z), v.w < _min.w ? _min.w : (v.w > _max.w ? _max.w : v.w) }; + return r; +} + +template +T udSaturate(const T &v) { return udClamp(v, (T)0, (T)1); } +template +udVector2 udSaturate(const udVector2 &v) { return udClamp(v, udVector2::zero(), udVector2::one()); } +template +udVector3 udSaturate(const udVector3 &v) { return udClamp(v, udVector3::zero(), udVector3::one()); } +template +udVector4 udSaturate(const udVector4 &v) { return udClamp(v, udVector4::zero(), udVector4::one()); } + +template +bool udIsUnitLength(const V &v, T epsilon) { return udAbs(typename V::ElementType(1) - udMag(v)) < typename V::ElementType(epsilon); } + +template +UDFORCE_INLINE T udDot(const udVector2 &v1, const udVector2 &v2) { return udDot2(v1, v2); } +template +UDFORCE_INLINE T udDot(const udVector3 &v1, const udVector3 &v2) { return udDot3(v1, v2); } +template +UDFORCE_INLINE T udDot(const udVector4 &v1, const udVector4 &v2) { return udDot4(v1, v2); } +template +UDFORCE_INLINE T udDot(const udQuaternion &q1, const udQuaternion &q2) { return udDotQ(q1, q2); } + +template +T udDot2(const udVector2 &v1, const udVector2 &v2) { return v1.x * v2.x + v1.y * v2.y; } +template +T udDot2(const udVector3 &v1, const udVector3 &v2) { return v1.x * v2.x + v1.y * v2.y; } +template +T udDot2(const udVector4 &v1, const udVector4 &v2) { return v1.x * v2.x + v1.y * v2.y; } +template +T udDot3(const udVector3 &v1, const udVector3 &v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } +template +T udDot3(const udVector4 &v1, const udVector4 &v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } +template +T udDot4(const udVector4 &v1, const udVector4 &v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w; } +template +T udDoth(const udVector3 &v3, const udVector4 &v4) { return v3.x * v4.x + v3.y * v4.y + v3.z * v4.z + v4.w; } +template +T udDotQ(const udQuaternion &q1, const udQuaternion &q2) { return q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w; } + +template +T UDFORCE_INLINE udMagSq(const udVector2 &v) { return udMagSq2(v); } +template +T UDFORCE_INLINE udMagSq(const udVector3 &v) { return udMagSq3(v); } +template +T UDFORCE_INLINE udMagSq(const udVector4 &v) { return udMagSq4(v); } +template +T UDFORCE_INLINE udMagSq(const udQuaternion &q) { return udMagSqQ(q); } + +template +T udMagSq2(const udVector2 &v) { return v.x * v.x + v.y * v.y; } +template +T udMagSq2(const udVector3 &v) { return v.x * v.x + v.y * v.y; } +template +T udMagSq2(const udVector4 &v) { return v.x * v.x + v.y * v.y; } +template +T udMagSq3(const udVector3 &v) { return v.x * v.x + v.y * v.y + v.z * v.z; } +template +T udMagSq3(const udVector4 &v) { return v.x * v.x + v.y * v.y + v.z * v.z; } +template +T udMagSq4(const udVector4 &v) { return v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w; } +template +T udMagSqQ(const udQuaternion &q) { return q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w; } + +template +T UDFORCE_INLINE udMag(const udVector2 &v) { return udMag2(v); } +template +T UDFORCE_INLINE udMag(const udVector3 &v) { return udMag3(v); } +template +T UDFORCE_INLINE udMag(const udVector4 &v) { return udMag4(v); } +template +T UDFORCE_INLINE udMag(const udQuaternion &v) { return udMagQ(v); } + +template +T udMag2(const udVector2 &v) { return udSqrt(v.x * v.x + v.y * v.y); } +template +T udMag2(const udVector3 &v) { return udSqrt(v.x * v.x + v.y * v.y); } +template +T udMag2(const udVector4 &v) { return udSqrt(v.x * v.x + v.y * v.y); } +template +T udMag3(const udVector3 &v) { return udSqrt(v.x * v.x + v.y * v.y + v.z * v.z); } +template +T udMag3(const udVector4 &v) { return udSqrt(v.x * v.x + v.y * v.y + v.z * v.z); } +template +T udMag4(const udVector4 &v) { return udSqrt(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w); } +template +T udMagQ(const udQuaternion &q) { return udSqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w); } + +template +UDFORCE_INLINE T udCross(const udVector2 &v1, const udVector2 &v2) { return udCross2(v1, v2); } +template +UDFORCE_INLINE udVector3 udCross(const udVector3 &v1, const udVector3 &v2) { return udCross3(v1, v2); } + +template +T udCross2(const udVector2 &v1, const udVector2 &v2) { return v1.x * v2.y - v1.y * v2.x; } +template +T udCross2(const udVector3 &v1, const udVector3 &v2) { return v1.x * v2.y - v1.y * v2.x; } +template +T udCross2(const udVector4 &v1, const udVector4 &v2) { return v1.x * v2.y - v1.y * v2.x; } + +template +udVector3 udCross3(const udVector3 &v1, const udVector3 &v2) +{ + udVector3 r = { v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x }; + return r; +} +template +udVector3 udCross3(const udVector4 &v1, const udVector4 &v2) +{ + udVector3 r = { v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x }; + return r; +} + +template +UDFORCE_INLINE udVector2 udNormalize(const udVector2 &v) { return udNormalize2(v); } +template +UDFORCE_INLINE udVector3 udNormalize(const udVector3 &v) { return udNormalize3(v); } +template +UDFORCE_INLINE udVector4 udNormalize(const udVector4 &v) { return udNormalize4(v); } +template +UDFORCE_INLINE udQuaternion udNormalize(const udQuaternion &q) { return udNormalizeQ(q); } + +template +udVector2 udNormalize2(const udVector2 &v) +{ + T s = udRSqrt(v.x * v.x + v.y * v.y); + udVector2 r = { v.x * s, v.y * s }; + return r; +} +template +udVector3 udNormalize2(const udVector3 &v) +{ + T s = udRSqrt(v.x * v.x + v.y * v.y); + udVector3 r = { v.x * s, v.y * s, v.z }; + return r; +} +template +udVector4 udNormalize2(const udVector4 &v) +{ + T s = udRSqrt(v.x * v.x + v.y * v.y); + udVector4 r = { v.x * s, v.y * s, v.z, v.w }; + return r; +} +template +udVector3 udNormalize3(const udVector3 &v) +{ + T s = udRSqrt(v.x * v.x + v.y * v.y + v.z * v.z); + udVector3 r = { v.x * s, v.y * s, v.z * s }; + return r; +} +template +udVector4 udNormalize3(const udVector4 &v) +{ + T s = udRSqrt(v.x * v.x + v.y * v.y + v.z * v.z); + udVector4 r = { v.x * s, v.y * s, v.z * s, v.w }; + return r; +} +template +udVector4 udNormalize4(const udVector4 &v) +{ + T s = udRSqrt(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w); + udVector4 r = { v.x * s, v.y * s, v.z * s, v.w * s }; + return r; +} +template +udQuaternion udNormalizeQ(const udQuaternion &v) +{ + T s = udRSqrt(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w); + udQuaternion r = { v.x * s, v.y * s, v.z * s, v.w * s }; + return r; +} template inline bool udEqualApprox(const V &a, const V &b, typename V::ElementType epsilon) @@ -271,59 +467,59 @@ udVector3 udDirectionToYPR(const udVector3 &direction) template udMatrix4x4 udMul(const udMatrix4x4 &m, U f) { - udMatrix4x4 r = {{{ T(m.a[0] * f), T(m.a[1] * f), T(m.a[2] * f), T(m.a[3] * f), - T(m.a[4] * f), T(m.a[5] * f), T(m.a[6] * f), T(m.a[7] * f), - T(m.a[8] * f), T(m.a[9] * f), T(m.a[10] * f),T(m.a[11] * f), - T(m.a[12] * f),T(m.a[13] * f),T(m.a[14] * f),T(m.a[15] * f) }}}; + udMatrix4x4 r = { { { T(m.a[0] * f), T(m.a[1] * f), T(m.a[2] * f), T(m.a[3] * f), + T(m.a[4] * f), T(m.a[5] * f), T(m.a[6] * f), T(m.a[7] * f), + T(m.a[8] * f), T(m.a[9] * f), T(m.a[10] * f), T(m.a[11] * f), + T(m.a[12] * f), T(m.a[13] * f), T(m.a[14] * f), T(m.a[15] * f) } } }; return r; } template udVector2 udMul(const udMatrix4x4 &m, const udVector2 &v) { udVector2 r; - r.x = m.m._00*v.x + m.m._01*v.y + m.m._03; - r.y = m.m._10*v.x + m.m._11*v.y + m.m._13; + r.x = m.m._00 * v.x + m.m._01 * v.y + m.m._03; + r.y = m.m._10 * v.x + m.m._11 * v.y + m.m._13; return r; } template udVector3 udMul(const udMatrix4x4 &m, const udVector3 &v) { udVector3 r; - r.x = m.m._00*v.x + m.m._01*v.y + m.m._02*v.z + m.m._03; - r.y = m.m._10*v.x + m.m._11*v.y + m.m._12*v.z + m.m._13; - r.z = m.m._20*v.x + m.m._21*v.y + m.m._22*v.z + m.m._23; + r.x = m.m._00 * v.x + m.m._01 * v.y + m.m._02 * v.z + m.m._03; + r.y = m.m._10 * v.x + m.m._11 * v.y + m.m._12 * v.z + m.m._13; + r.z = m.m._20 * v.x + m.m._21 * v.y + m.m._22 * v.z + m.m._23; return r; } template udVector4 udMul(const udMatrix4x4 &m, const udVector4 &v) { udVector4 r; - r.x = m.m._00*v.x + m.m._01*v.y + m.m._02*v.z + m.m._03*v.w; - r.y = m.m._10*v.x + m.m._11*v.y + m.m._12*v.z + m.m._13*v.w; - r.z = m.m._20*v.x + m.m._21*v.y + m.m._22*v.z + m.m._23*v.w; - r.w = m.m._30*v.x + m.m._31*v.y + m.m._32*v.z + m.m._33*v.w; + r.x = m.m._00 * v.x + m.m._01 * v.y + m.m._02 * v.z + m.m._03 * v.w; + r.y = m.m._10 * v.x + m.m._11 * v.y + m.m._12 * v.z + m.m._13 * v.w; + r.z = m.m._20 * v.x + m.m._21 * v.y + m.m._22 * v.z + m.m._23 * v.w; + r.w = m.m._30 * v.x + m.m._31 * v.y + m.m._32 * v.z + m.m._33 * v.w; return r; } template udMatrix4x4 udMul(const udMatrix4x4 &m1, const udMatrix4x4 &m2) { udMatrix4x4 r; - r.m._00 = m1.m._00*m2.m._00 + m1.m._01*m2.m._10 + m1.m._02*m2.m._20 + m1.m._03*m2.m._30; - r.m._01 = m1.m._00*m2.m._01 + m1.m._01*m2.m._11 + m1.m._02*m2.m._21 + m1.m._03*m2.m._31; - r.m._02 = m1.m._00*m2.m._02 + m1.m._01*m2.m._12 + m1.m._02*m2.m._22 + m1.m._03*m2.m._32; - r.m._03 = m1.m._00*m2.m._03 + m1.m._01*m2.m._13 + m1.m._02*m2.m._23 + m1.m._03*m2.m._33; - r.m._10 = m1.m._10*m2.m._00 + m1.m._11*m2.m._10 + m1.m._12*m2.m._20 + m1.m._13*m2.m._30; - r.m._11 = m1.m._10*m2.m._01 + m1.m._11*m2.m._11 + m1.m._12*m2.m._21 + m1.m._13*m2.m._31; - r.m._12 = m1.m._10*m2.m._02 + m1.m._11*m2.m._12 + m1.m._12*m2.m._22 + m1.m._13*m2.m._32; - r.m._13 = m1.m._10*m2.m._03 + m1.m._11*m2.m._13 + m1.m._12*m2.m._23 + m1.m._13*m2.m._33; - r.m._20 = m1.m._20*m2.m._00 + m1.m._21*m2.m._10 + m1.m._22*m2.m._20 + m1.m._23*m2.m._30; - r.m._21 = m1.m._20*m2.m._01 + m1.m._21*m2.m._11 + m1.m._22*m2.m._21 + m1.m._23*m2.m._31; - r.m._22 = m1.m._20*m2.m._02 + m1.m._21*m2.m._12 + m1.m._22*m2.m._22 + m1.m._23*m2.m._32; - r.m._23 = m1.m._20*m2.m._03 + m1.m._21*m2.m._13 + m1.m._22*m2.m._23 + m1.m._23*m2.m._33; - r.m._30 = m1.m._30*m2.m._00 + m1.m._31*m2.m._10 + m1.m._32*m2.m._20 + m1.m._33*m2.m._30; - r.m._31 = m1.m._30*m2.m._01 + m1.m._31*m2.m._11 + m1.m._32*m2.m._21 + m1.m._33*m2.m._31; - r.m._32 = m1.m._30*m2.m._02 + m1.m._31*m2.m._12 + m1.m._32*m2.m._22 + m1.m._33*m2.m._32; - r.m._33 = m1.m._30*m2.m._03 + m1.m._31*m2.m._13 + m1.m._32*m2.m._23 + m1.m._33*m2.m._33; + r.m._00 = m1.m._00 * m2.m._00 + m1.m._01 * m2.m._10 + m1.m._02 * m2.m._20 + m1.m._03 * m2.m._30; + r.m._01 = m1.m._00 * m2.m._01 + m1.m._01 * m2.m._11 + m1.m._02 * m2.m._21 + m1.m._03 * m2.m._31; + r.m._02 = m1.m._00 * m2.m._02 + m1.m._01 * m2.m._12 + m1.m._02 * m2.m._22 + m1.m._03 * m2.m._32; + r.m._03 = m1.m._00 * m2.m._03 + m1.m._01 * m2.m._13 + m1.m._02 * m2.m._23 + m1.m._03 * m2.m._33; + r.m._10 = m1.m._10 * m2.m._00 + m1.m._11 * m2.m._10 + m1.m._12 * m2.m._20 + m1.m._13 * m2.m._30; + r.m._11 = m1.m._10 * m2.m._01 + m1.m._11 * m2.m._11 + m1.m._12 * m2.m._21 + m1.m._13 * m2.m._31; + r.m._12 = m1.m._10 * m2.m._02 + m1.m._11 * m2.m._12 + m1.m._12 * m2.m._22 + m1.m._13 * m2.m._32; + r.m._13 = m1.m._10 * m2.m._03 + m1.m._11 * m2.m._13 + m1.m._12 * m2.m._23 + m1.m._13 * m2.m._33; + r.m._20 = m1.m._20 * m2.m._00 + m1.m._21 * m2.m._10 + m1.m._22 * m2.m._20 + m1.m._23 * m2.m._30; + r.m._21 = m1.m._20 * m2.m._01 + m1.m._21 * m2.m._11 + m1.m._22 * m2.m._21 + m1.m._23 * m2.m._31; + r.m._22 = m1.m._20 * m2.m._02 + m1.m._21 * m2.m._12 + m1.m._22 * m2.m._22 + m1.m._23 * m2.m._32; + r.m._23 = m1.m._20 * m2.m._03 + m1.m._21 * m2.m._13 + m1.m._22 * m2.m._23 + m1.m._23 * m2.m._33; + r.m._30 = m1.m._30 * m2.m._00 + m1.m._31 * m2.m._10 + m1.m._32 * m2.m._20 + m1.m._33 * m2.m._30; + r.m._31 = m1.m._30 * m2.m._01 + m1.m._31 * m2.m._11 + m1.m._32 * m2.m._21 + m1.m._33 * m2.m._31; + r.m._32 = m1.m._30 * m2.m._02 + m1.m._31 * m2.m._12 + m1.m._32 * m2.m._22 + m1.m._33 * m2.m._32; + r.m._33 = m1.m._30 * m2.m._03 + m1.m._31 * m2.m._13 + m1.m._32 * m2.m._23 + m1.m._33 * m2.m._33; return r; } @@ -331,22 +527,22 @@ template udMatrix4x4 udAdd(const udMatrix4x4 &m1, const udMatrix4x4 &m2) { udMatrix4x4 r; - r.m._00 = m1.m._00+m2.m._00; - r.m._01 = m1.m._01+m2.m._01; - r.m._02 = m1.m._02+m2.m._02; - r.m._03 = m1.m._03+m2.m._03; - r.m._10 = m1.m._10+m2.m._10; - r.m._11 = m1.m._11+m2.m._11; - r.m._12 = m1.m._12+m2.m._12; - r.m._13 = m1.m._13+m2.m._13; - r.m._20 = m1.m._20+m2.m._20; - r.m._21 = m1.m._21+m2.m._21; - r.m._22 = m1.m._22+m2.m._22; - r.m._23 = m1.m._23+m2.m._23; - r.m._30 = m1.m._30+m2.m._30; - r.m._31 = m1.m._31+m2.m._31; - r.m._32 = m1.m._32+m2.m._32; - r.m._33 = m1.m._33+m2.m._33; + r.m._00 = m1.m._00 + m2.m._00; + r.m._01 = m1.m._01 + m2.m._01; + r.m._02 = m1.m._02 + m2.m._02; + r.m._03 = m1.m._03 + m2.m._03; + r.m._10 = m1.m._10 + m2.m._10; + r.m._11 = m1.m._11 + m2.m._11; + r.m._12 = m1.m._12 + m2.m._12; + r.m._13 = m1.m._13 + m2.m._13; + r.m._20 = m1.m._20 + m2.m._20; + r.m._21 = m1.m._21 + m2.m._21; + r.m._22 = m1.m._22 + m2.m._22; + r.m._23 = m1.m._23 + m2.m._23; + r.m._30 = m1.m._30 + m2.m._30; + r.m._31 = m1.m._31 + m2.m._31; + r.m._32 = m1.m._32 + m2.m._32; + r.m._33 = m1.m._33 + m2.m._33; return r; } @@ -377,9 +573,9 @@ template udQuaternion udMul(const udQuaternion &q1, const udQuaternion &q2) { udQuaternion r; - r.x = q1.x * q2.w + q1.y * q2.z - q1.z * q2.y + q1.w * q2.x; + r.x = q1.x * q2.w + q1.y * q2.z - q1.z * q2.y + q1.w * q2.x; r.y = -q1.x * q2.z + q1.y * q2.w + q1.z * q2.x + q1.w * q2.y; - r.z = q1.x * q2.y - q1.y * q2.x + q1.z * q2.w + q1.w * q2.z; + r.z = q1.x * q2.y - q1.y * q2.x + q1.z * q2.w + q1.w * q2.z; r.w = -q1.x * q2.x - q1.y * q2.y - q1.z * q2.z + q1.w * q2.w; return r; } @@ -387,13 +583,13 @@ udQuaternion udMul(const udQuaternion &q1, const udQuaternion &q2) template T udLerp(T a, T b, double t) { - return T(a + (b-a)*t); + return T(a + (b - a) * t); } template T udBiLerp(T a, T b, T c, T d, double t1, double t2) { - return udLerp(udLerp(a, b, t1), udLerp(c, d, t1),t2); + return udLerp(udLerp(a, b, t1), udLerp(c, d, t1), t2); } template @@ -401,8 +597,8 @@ udVector2 udLerp(const udVector2 &v1, const udVector2 &v2, double t) { udVector2 r; double invT = 1.0 - t; - r.x = T(v1.x*invT + v2.x*t); - r.y = T(v1.y*invT + v2.y*t); + r.x = T(v1.x * invT + v2.x * t); + r.y = T(v1.y * invT + v2.y * t); return r; } template @@ -410,9 +606,9 @@ udVector3 udLerp(const udVector3 &v1, const udVector3 &v2, double t) { udVector3 r; double invT = 1.0 - t; - r.x = T(v1.x*invT + v2.x*t); - r.y = T(v1.y*invT + v2.y*t); - r.z = T(v1.z*invT + v2.z*t); + r.x = T(v1.x * invT + v2.x * t); + r.y = T(v1.y * invT + v2.y * t); + r.z = T(v1.z * invT + v2.z * t); return r; } template @@ -420,26 +616,26 @@ udVector4 udLerp(const udVector4 &v1, const udVector4 &v2, double t) { udVector4 r; double invT = 1.0 - t; - r.x = T(v1.x*invT + v2.x*t); - r.y = T(v1.y*invT + v2.y*t); - r.z = T(v1.z*invT + v2.z*t); - r.w = T(v1.w*invT + v2.w*t); + r.x = T(v1.x * invT + v2.x * t); + r.y = T(v1.y * invT + v2.y * t); + r.z = T(v1.z * invT + v2.z * t); + r.w = T(v1.w * invT + v2.w * t); return r; } template udMatrix4x4 udLerp(const udMatrix4x4 &m1, const udMatrix4x4 &m2, double t) { - return (1.0-t)*m1 + t*m2; + return (1.0 - t) * m1 + t * m2; } template udQuaternion udLerp(const udQuaternion &q1, const udQuaternion &q2, double t) { udQuaternion r; double invT = 1.0 - t; - r.x = T(q1.x*invT + q2.x*t); - r.y = T(q1.y*invT + q2.y*t); - r.z = T(q1.z*invT + q2.z*t); - r.w = T(q1.w*invT + q2.w*t); + r.x = T(q1.x * invT + q2.x * t); + r.y = T(q1.y * invT + q2.y * t); + r.z = T(q1.z * invT + q2.z * t); + r.w = T(q1.w * invT + q2.w * t); return r; } @@ -485,51 +681,51 @@ udQuaternion udSlerp(const udQuaternion &q1, const udQuaternion &_q2, d template udMatrix4x4 udTranspose(const udMatrix4x4 &m) { - udMatrix4x4 r = {{{ m.a[0], m.a[4], m.a[8], m.a[12], - m.a[1], m.a[5], m.a[9], m.a[13], - m.a[2], m.a[6], m.a[10], m.a[14], - m.a[3], m.a[7], m.a[11], m.a[15] }}}; + udMatrix4x4 r = { { { m.a[0], m.a[4], m.a[8], m.a[12], + m.a[1], m.a[5], m.a[9], m.a[13], + m.a[2], m.a[6], m.a[10], m.a[14], + m.a[3], m.a[7], m.a[11], m.a[15] } } }; return r; } template T udDeterminant(const udMatrix4x4 &m) { - return m.m._03*m.m._12*m.m._21*m.m._30 - m.m._02*m.m._13*m.m._21*m.m._30 - m.m._03*m.m._11*m.m._22*m.m._30 + m.m._01*m.m._13*m.m._22*m.m._30 + - m.m._02*m.m._11*m.m._23*m.m._30 - m.m._01*m.m._12*m.m._23*m.m._30 - m.m._03*m.m._12*m.m._20*m.m._31 + m.m._02*m.m._13*m.m._20*m.m._31 + - m.m._03*m.m._10*m.m._22*m.m._31 - m.m._00*m.m._13*m.m._22*m.m._31 - m.m._02*m.m._10*m.m._23*m.m._31 + m.m._00*m.m._12*m.m._23*m.m._31 + - m.m._03*m.m._11*m.m._20*m.m._32 - m.m._01*m.m._13*m.m._20*m.m._32 - m.m._03*m.m._10*m.m._21*m.m._32 + m.m._00*m.m._13*m.m._21*m.m._32 + - m.m._01*m.m._10*m.m._23*m.m._32 - m.m._00*m.m._11*m.m._23*m.m._32 - m.m._02*m.m._11*m.m._20*m.m._33 + m.m._01*m.m._12*m.m._20*m.m._33 + - m.m._02*m.m._10*m.m._21*m.m._33 - m.m._00*m.m._12*m.m._21*m.m._33 - m.m._01*m.m._10*m.m._22*m.m._33 + m.m._00*m.m._11*m.m._22*m.m._33; + return m.m._03 * m.m._12 * m.m._21 * m.m._30 - m.m._02 * m.m._13 * m.m._21 * m.m._30 - m.m._03 * m.m._11 * m.m._22 * m.m._30 + m.m._01 * m.m._13 * m.m._22 * m.m._30 + + m.m._02 * m.m._11 * m.m._23 * m.m._30 - m.m._01 * m.m._12 * m.m._23 * m.m._30 - m.m._03 * m.m._12 * m.m._20 * m.m._31 + m.m._02 * m.m._13 * m.m._20 * m.m._31 + + m.m._03 * m.m._10 * m.m._22 * m.m._31 - m.m._00 * m.m._13 * m.m._22 * m.m._31 - m.m._02 * m.m._10 * m.m._23 * m.m._31 + m.m._00 * m.m._12 * m.m._23 * m.m._31 + + m.m._03 * m.m._11 * m.m._20 * m.m._32 - m.m._01 * m.m._13 * m.m._20 * m.m._32 - m.m._03 * m.m._10 * m.m._21 * m.m._32 + m.m._00 * m.m._13 * m.m._21 * m.m._32 + + m.m._01 * m.m._10 * m.m._23 * m.m._32 - m.m._00 * m.m._11 * m.m._23 * m.m._32 - m.m._02 * m.m._11 * m.m._20 * m.m._33 + m.m._01 * m.m._12 * m.m._20 * m.m._33 + + m.m._02 * m.m._10 * m.m._21 * m.m._33 - m.m._00 * m.m._12 * m.m._21 * m.m._33 - m.m._01 * m.m._10 * m.m._22 * m.m._33 + m.m._00 * m.m._11 * m.m._22 * m.m._33; } template udMatrix4x4 udInverse(const udMatrix4x4 &m) { udMatrix4x4 r; - r.m._00 = m.m._12*m.m._23*m.m._31 - m.m._13*m.m._22*m.m._31 + m.m._13*m.m._21*m.m._32 - m.m._11*m.m._23*m.m._32 - m.m._12*m.m._21*m.m._33 + m.m._11*m.m._22*m.m._33; - r.m._01 = m.m._03*m.m._22*m.m._31 - m.m._02*m.m._23*m.m._31 - m.m._03*m.m._21*m.m._32 + m.m._01*m.m._23*m.m._32 + m.m._02*m.m._21*m.m._33 - m.m._01*m.m._22*m.m._33; - r.m._02 = m.m._02*m.m._13*m.m._31 - m.m._03*m.m._12*m.m._31 + m.m._03*m.m._11*m.m._32 - m.m._01*m.m._13*m.m._32 - m.m._02*m.m._11*m.m._33 + m.m._01*m.m._12*m.m._33; - r.m._03 = m.m._03*m.m._12*m.m._21 - m.m._02*m.m._13*m.m._21 - m.m._03*m.m._11*m.m._22 + m.m._01*m.m._13*m.m._22 + m.m._02*m.m._11*m.m._23 - m.m._01*m.m._12*m.m._23; - r.m._10 = m.m._13*m.m._22*m.m._30 - m.m._12*m.m._23*m.m._30 - m.m._13*m.m._20*m.m._32 + m.m._10*m.m._23*m.m._32 + m.m._12*m.m._20*m.m._33 - m.m._10*m.m._22*m.m._33; - r.m._11 = m.m._02*m.m._23*m.m._30 - m.m._03*m.m._22*m.m._30 + m.m._03*m.m._20*m.m._32 - m.m._00*m.m._23*m.m._32 - m.m._02*m.m._20*m.m._33 + m.m._00*m.m._22*m.m._33; - r.m._12 = m.m._03*m.m._12*m.m._30 - m.m._02*m.m._13*m.m._30 - m.m._03*m.m._10*m.m._32 + m.m._00*m.m._13*m.m._32 + m.m._02*m.m._10*m.m._33 - m.m._00*m.m._12*m.m._33; - r.m._13 = m.m._02*m.m._13*m.m._20 - m.m._03*m.m._12*m.m._20 + m.m._03*m.m._10*m.m._22 - m.m._00*m.m._13*m.m._22 - m.m._02*m.m._10*m.m._23 + m.m._00*m.m._12*m.m._23; - r.m._20 = m.m._11*m.m._23*m.m._30 - m.m._13*m.m._21*m.m._30 + m.m._13*m.m._20*m.m._31 - m.m._10*m.m._23*m.m._31 - m.m._11*m.m._20*m.m._33 + m.m._10*m.m._21*m.m._33; - r.m._21 = m.m._03*m.m._21*m.m._30 - m.m._01*m.m._23*m.m._30 - m.m._03*m.m._20*m.m._31 + m.m._00*m.m._23*m.m._31 + m.m._01*m.m._20*m.m._33 - m.m._00*m.m._21*m.m._33; - r.m._22 = m.m._01*m.m._13*m.m._30 - m.m._03*m.m._11*m.m._30 + m.m._03*m.m._10*m.m._31 - m.m._00*m.m._13*m.m._31 - m.m._01*m.m._10*m.m._33 + m.m._00*m.m._11*m.m._33; - r.m._23 = m.m._03*m.m._11*m.m._20 - m.m._01*m.m._13*m.m._20 - m.m._03*m.m._10*m.m._21 + m.m._00*m.m._13*m.m._21 + m.m._01*m.m._10*m.m._23 - m.m._00*m.m._11*m.m._23; - r.m._30 = m.m._12*m.m._21*m.m._30 - m.m._11*m.m._22*m.m._30 - m.m._12*m.m._20*m.m._31 + m.m._10*m.m._22*m.m._31 + m.m._11*m.m._20*m.m._32 - m.m._10*m.m._21*m.m._32; - r.m._31 = m.m._01*m.m._22*m.m._30 - m.m._02*m.m._21*m.m._30 + m.m._02*m.m._20*m.m._31 - m.m._00*m.m._22*m.m._31 - m.m._01*m.m._20*m.m._32 + m.m._00*m.m._21*m.m._32; - r.m._32 = m.m._02*m.m._11*m.m._30 - m.m._01*m.m._12*m.m._30 - m.m._02*m.m._10*m.m._31 + m.m._00*m.m._12*m.m._31 + m.m._01*m.m._10*m.m._32 - m.m._00*m.m._11*m.m._32; - r.m._33 = m.m._01*m.m._12*m.m._20 - m.m._02*m.m._11*m.m._20 + m.m._02*m.m._10*m.m._21 - m.m._00*m.m._12*m.m._21 - m.m._01*m.m._10*m.m._22 + m.m._00*m.m._11*m.m._22; - return r*(T(1)/udDeterminant(m)); + r.m._00 = m.m._12 * m.m._23 * m.m._31 - m.m._13 * m.m._22 * m.m._31 + m.m._13 * m.m._21 * m.m._32 - m.m._11 * m.m._23 * m.m._32 - m.m._12 * m.m._21 * m.m._33 + m.m._11 * m.m._22 * m.m._33; + r.m._01 = m.m._03 * m.m._22 * m.m._31 - m.m._02 * m.m._23 * m.m._31 - m.m._03 * m.m._21 * m.m._32 + m.m._01 * m.m._23 * m.m._32 + m.m._02 * m.m._21 * m.m._33 - m.m._01 * m.m._22 * m.m._33; + r.m._02 = m.m._02 * m.m._13 * m.m._31 - m.m._03 * m.m._12 * m.m._31 + m.m._03 * m.m._11 * m.m._32 - m.m._01 * m.m._13 * m.m._32 - m.m._02 * m.m._11 * m.m._33 + m.m._01 * m.m._12 * m.m._33; + r.m._03 = m.m._03 * m.m._12 * m.m._21 - m.m._02 * m.m._13 * m.m._21 - m.m._03 * m.m._11 * m.m._22 + m.m._01 * m.m._13 * m.m._22 + m.m._02 * m.m._11 * m.m._23 - m.m._01 * m.m._12 * m.m._23; + r.m._10 = m.m._13 * m.m._22 * m.m._30 - m.m._12 * m.m._23 * m.m._30 - m.m._13 * m.m._20 * m.m._32 + m.m._10 * m.m._23 * m.m._32 + m.m._12 * m.m._20 * m.m._33 - m.m._10 * m.m._22 * m.m._33; + r.m._11 = m.m._02 * m.m._23 * m.m._30 - m.m._03 * m.m._22 * m.m._30 + m.m._03 * m.m._20 * m.m._32 - m.m._00 * m.m._23 * m.m._32 - m.m._02 * m.m._20 * m.m._33 + m.m._00 * m.m._22 * m.m._33; + r.m._12 = m.m._03 * m.m._12 * m.m._30 - m.m._02 * m.m._13 * m.m._30 - m.m._03 * m.m._10 * m.m._32 + m.m._00 * m.m._13 * m.m._32 + m.m._02 * m.m._10 * m.m._33 - m.m._00 * m.m._12 * m.m._33; + r.m._13 = m.m._02 * m.m._13 * m.m._20 - m.m._03 * m.m._12 * m.m._20 + m.m._03 * m.m._10 * m.m._22 - m.m._00 * m.m._13 * m.m._22 - m.m._02 * m.m._10 * m.m._23 + m.m._00 * m.m._12 * m.m._23; + r.m._20 = m.m._11 * m.m._23 * m.m._30 - m.m._13 * m.m._21 * m.m._30 + m.m._13 * m.m._20 * m.m._31 - m.m._10 * m.m._23 * m.m._31 - m.m._11 * m.m._20 * m.m._33 + m.m._10 * m.m._21 * m.m._33; + r.m._21 = m.m._03 * m.m._21 * m.m._30 - m.m._01 * m.m._23 * m.m._30 - m.m._03 * m.m._20 * m.m._31 + m.m._00 * m.m._23 * m.m._31 + m.m._01 * m.m._20 * m.m._33 - m.m._00 * m.m._21 * m.m._33; + r.m._22 = m.m._01 * m.m._13 * m.m._30 - m.m._03 * m.m._11 * m.m._30 + m.m._03 * m.m._10 * m.m._31 - m.m._00 * m.m._13 * m.m._31 - m.m._01 * m.m._10 * m.m._33 + m.m._00 * m.m._11 * m.m._33; + r.m._23 = m.m._03 * m.m._11 * m.m._20 - m.m._01 * m.m._13 * m.m._20 - m.m._03 * m.m._10 * m.m._21 + m.m._00 * m.m._13 * m.m._21 + m.m._01 * m.m._10 * m.m._23 - m.m._00 * m.m._11 * m.m._23; + r.m._30 = m.m._12 * m.m._21 * m.m._30 - m.m._11 * m.m._22 * m.m._30 - m.m._12 * m.m._20 * m.m._31 + m.m._10 * m.m._22 * m.m._31 + m.m._11 * m.m._20 * m.m._32 - m.m._10 * m.m._21 * m.m._32; + r.m._31 = m.m._01 * m.m._22 * m.m._30 - m.m._02 * m.m._21 * m.m._30 + m.m._02 * m.m._20 * m.m._31 - m.m._00 * m.m._22 * m.m._31 - m.m._01 * m.m._20 * m.m._32 + m.m._00 * m.m._21 * m.m._32; + r.m._32 = m.m._02 * m.m._11 * m.m._30 - m.m._01 * m.m._12 * m.m._30 - m.m._02 * m.m._10 * m.m._31 + m.m._00 * m.m._12 * m.m._31 + m.m._01 * m.m._10 * m.m._32 - m.m._00 * m.m._11 * m.m._32; + r.m._33 = m.m._01 * m.m._12 * m.m._20 - m.m._02 * m.m._11 * m.m._20 + m.m._02 * m.m._10 * m.m._21 - m.m._00 * m.m._12 * m.m._21 - m.m._01 * m.m._10 * m.m._22 + m.m._00 * m.m._11 * m.m._22; + return r * (T(1) / udDeterminant(m)); } template udQuaternion udInverse(const udQuaternion &q) { - T s = T(1)/(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w); - udQuaternion r = { -q.x*s, -q.y*s, -q.z*s, q.w*s }; + T s = T(1) / (q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w); + udQuaternion r = { -q.x * s, -q.y * s, -q.z * s, q.w * s }; return r; } @@ -548,8 +744,8 @@ udRay udRay::rotationAround(const udRay &ray, const udVector3 ¢e udQuaternion rotation = udQuaternion::create(axis, angle); - udVector3 direction = ray.position - center; // find current direction relative to center - r.position = center + rotation.apply(direction); // define new position + udVector3 direction = ray.position - center; // find current direction relative to center + r.position = center + rotation.apply(direction); // define new position r.direction = udDirectionFromYPR((rotation * udQuaternion::create(udDirectionToYPR(ray.direction))).eulerAngles()); // rotate object to keep looking at the center return r; @@ -584,7 +780,7 @@ bool udPlane::intersects(const udRay &ray, udVector3 *pIntersectionPoin // udMatrix4x4 members template -udMatrix4x4& udMatrix4x4::transpose() +udMatrix4x4 &udMatrix4x4::transpose() { *this = udTranspose(*this); return *this; @@ -597,7 +793,7 @@ T udMatrix4x4::determinant() } template -udMatrix4x4& udMatrix4x4::inverse() +udMatrix4x4 &udMatrix4x4::inverse() { *this = udInverse(*this); return *this; @@ -623,17 +819,17 @@ udVector3 udMatrix4x4::extractYPR() const Sp = my.z; // use trig identity (cos(p))^2 + (sin(p))^2 = 1, to find cos(p) - Cp = udSqrt(1.0f - Sp*Sp); + Cp = udSqrt(1.0f - Sp * Sp); // There's an edge case when if (Cp >= 0.00001f) { // find the rest from other cells - T factor = T(1)/Cp; - Sy = -my.x*factor; - Cy = my.y*factor; - Sr = -mx.z*factor; - Cr = mz.z*factor; + T factor = T(1) / Cp; + Sy = -my.x * factor; + Cy = my.y * factor; + Sr = -mx.z * factor; + Cr = mz.z * factor; } else { @@ -707,7 +903,7 @@ udQuaternion udMatrix4x4::extractQuaternion() const return udNormalize(retVal); } -template +template void udMatrix4x4::extractTransforms(udVector3 &position, udVector3 &scale, udQuaternion &orientation) const { udMatrix4x4 mat = *this; //Copy it so we can make changes @@ -727,14 +923,14 @@ void udMatrix4x4::extractTransforms(udVector3 &position, udVector3 &sca // udQuaternion members template -udQuaternion& udQuaternion::inverse() +udQuaternion &udQuaternion::inverse() { *this = udInverse(*this); return *this; } template -udQuaternion& udQuaternion::conjugate() +udQuaternion &udQuaternion::conjugate() { *this = udConjugate(*this); return *this; @@ -745,13 +941,13 @@ udVector3 udQuaternion::apply(const udVector3 &v) const { udVector3 r; - T a = w*w - (x*x + y*y + z*z); - T b = 2.0f*w; - T c = 2.0f*(x*v.x + y*v.y + z*v.z); + T a = w * w - (x * x + y * y + z * z); + T b = 2.0f * w; + T c = 2.0f * (x * v.x + y * v.y + z * v.z); - r.x = a*v.x + b*(y*v.z - z*v.y) + c*x; - r.y = a*v.y + b*(z*v.x - x*v.z) + c*y; - r.z = a*v.z + b*(x*v.y - y*v.x) + c*z; + r.x = a * v.x + b * (y * v.z - z * v.y) + c * x; + r.y = a * v.y + b * (z * v.x - x * v.z) + c * y; + r.z = a * v.z + b * (x * v.y - y * v.x) + c * z; return r; } @@ -777,40 +973,40 @@ udVector3 udQuaternion::eulerAngles() const template udMatrix4x4 udMatrix4x4::identity() { - udMatrix4x4 r = {{{ T(1),T(0),T(0),T(0), - T(0),T(1),T(0),T(0), - T(0),T(0),T(1),T(0), - T(0),T(0),T(0),T(1) }}}; + udMatrix4x4 r = { { { T(1), T(0), T(0), T(0), + T(0), T(1), T(0), T(0), + T(0), T(0), T(1), T(0), + T(0), T(0), T(0), T(1) } } }; return r; } template udMatrix4x4 udMatrix4x4::create(const T m[16]) { - udMatrix4x4 r = {{{ m[0], m[1], m[2], m[3], - m[4], m[5], m[6], m[7], - m[8], m[9], m[10],m[11], - m[12],m[13],m[14],m[15] }}}; + udMatrix4x4 r = { { { m[0], m[1], m[2], m[3], + m[4], m[5], m[6], m[7], + m[8], m[9], m[10], m[11], + m[12], m[13], m[14], m[15] } } }; return r; } template udMatrix4x4 udMatrix4x4::create(T _00, T _10, T _20, T _30, T _01, T _11, T _21, T _31, T _02, T _12, T _22, T _32, T _03, T _13, T _23, T _33) { - udMatrix4x4 r = {{{ _00, _10, _20, _30, // NOTE: remember, this looks a bit funny because we store columns (axiis) contiguous! - _01, _11, _21, _31, - _02, _12, _22, _32, - _03, _13, _23, _33 }}}; + udMatrix4x4 r = { { { _00, _10, _20, _30, // NOTE: remember, this looks a bit funny because we store columns (axiis) contiguous! + _01, _11, _21, _31, + _02, _12, _22, _32, + _03, _13, _23, _33 } } }; return r; } template udMatrix4x4 udMatrix4x4::create(const udVector4 &xColumn, const udVector4 &yColumn, const udVector4 &zColumn, const udVector4 &wColumn) { - udMatrix4x4 r = {{{ xColumn.x, xColumn.y, xColumn.z, xColumn.w, - yColumn.x, yColumn.y, yColumn.z, yColumn.w, - zColumn.x, zColumn.y, zColumn.z, zColumn.w, - wColumn.x, wColumn.y, wColumn.z, wColumn.w }}}; + udMatrix4x4 r = { { { xColumn.x, xColumn.y, xColumn.z, xColumn.w, + yColumn.x, yColumn.y, yColumn.z, yColumn.w, + zColumn.x, zColumn.y, zColumn.z, zColumn.w, + wColumn.x, wColumn.y, wColumn.z, wColumn.w } } }; return r; } @@ -818,10 +1014,10 @@ template template udMatrix4x4 udMatrix4x4::create(const udMatrix4x4 &_m) { - udMatrix4x4 r = {{{ T(_m.m._00), T(_m.m._10), T(_m.m._20), T(_m.m._30), - T(_m.m._01), T(_m.m._11), T(_m.m._21), T(_m.m._31), - T(_m.m._02), T(_m.m._12), T(_m.m._22), T(_m.m._32), - T(_m.m._03), T(_m.m._13), T(_m.m._23), T(_m.m._33) }}}; + udMatrix4x4 r = { { { T(_m.m._00), T(_m.m._10), T(_m.m._20), T(_m.m._30), + T(_m.m._01), T(_m.m._11), T(_m.m._21), T(_m.m._31), + T(_m.m._02), T(_m.m._12), T(_m.m._22), T(_m.m._32), + T(_m.m._03), T(_m.m._13), T(_m.m._23), T(_m.m._33) } } }; return r; } @@ -830,10 +1026,10 @@ udMatrix4x4 udMatrix4x4::rotationX(T rad, const udVector3 &t) { T c = udCos(rad); T s = udSin(rad); - udMatrix4x4 r = {{{ T(1),T(0),T(0),T(0), - T(0), c , s ,T(0), - T(0), -s , c ,T(0), - t.x, t.y, t.z, T(1) }}}; + udMatrix4x4 r = { { { T(1), T(0), T(0), T(0), + T(0), c, s, T(0), + T(0), -s, c, T(0), + t.x, t.y, t.z, T(1) } } }; return r; } @@ -842,10 +1038,10 @@ udMatrix4x4 udMatrix4x4::rotationY(T rad, const udVector3 &t) { T c = udCos(rad); T s = udSin(rad); - udMatrix4x4 r = {{{ c ,T(0), -s, T(0), - T(0),T(1),T(0),T(0), - s ,T(0), c ,T(0), - t.x, t.y, t.z, T(1) }}}; + udMatrix4x4 r = { { { c, T(0), -s, T(0), + T(0), T(1), T(0), T(0), + s, T(0), c, T(0), + t.x, t.y, t.z, T(1) } } }; return r; } @@ -854,10 +1050,10 @@ udMatrix4x4 udMatrix4x4::rotationZ(T rad, const udVector3 &t) { T c = udCos(rad); T s = udSin(rad); - udMatrix4x4 r = {{{ c , s ,T(0),T(0), - -s , c ,T(0),T(0), - T(0),T(0),T(1),T(0), - t.x, t.y, t.z, T(1) }}}; + udMatrix4x4 r = { { { c, s, T(0), T(0), + -s, c, T(0), T(0), + T(0), T(0), T(1), T(0), + t.x, t.y, t.z, T(1) } } }; return r; } @@ -868,10 +1064,10 @@ udMatrix4x4 udMatrix4x4::rotationAxis(const udVector3 &axis, T rad, con T s = udSin(rad); udVector3 n = axis; udVector3 a = (T(1) - c) * axis; - udMatrix4x4 r = {{{ a.x*n.x + c, a.x*n.y + s*n.z, a.x*n.z - s*n.y, T(0), - a.y*n.x - s*n.z, a.y*n.y + c, a.y*n.z + s*n.x, T(0), - a.z*n.x + s*n.y, a.z*n.y - s*n.x, a.z*n.z + c, T(0), - t.x, t.y, t.z, T(1) }}}; + udMatrix4x4 r = { { { a.x * n.x + c, a.x * n.y + s * n.z, a.x * n.z - s * n.y, T(0), + a.y * n.x - s * n.z, a.y * n.y + c, a.y * n.z + s * n.x, T(0), + a.z * n.x + s * n.y, a.z * n.y - s * n.x, a.z * n.z + c, T(0), + t.x, t.y, t.z, T(1) } } }; return r; } @@ -880,10 +1076,10 @@ udMatrix4x4 udMatrix4x4::rotationYPR(T y, T p, T r, const udVector3 &t) { T c1 = udCos(y), c2 = udCos(p), c3 = udCos(r); T s1 = udSin(y), s2 = udSin(p), s3 = udSin(r); - udMatrix4x4 result = {{{ c1*c3-s1*s2*s3, c3*s1+c1*s2*s3, -c2*s3, T(0), - -c2*s1, c1*c2, s2, T(0), - c1*s3+c3*s1*s2, s1*s3-c1*c3*s2, c2*c3, T(0), - t.x, t.y, t.z, T(1) }}}; + udMatrix4x4 result = { { { c1 * c3 - s1 * s2 * s3, c3 * s1 + c1 * s2 * s3, -c2 * s3, T(0), + -c2 * s1, c1 * c2, s2, T(0), + c1 * s3 + c3 * s1 * s2, s1 * s3 - c1 * c3 * s2, c2 * c3, T(0), + t.x, t.y, t.z, T(1) } } }; return result; } @@ -896,12 +1092,10 @@ udMatrix4x4 udMatrix4x4::rotationQuat(const udQuaternion &q, const udVe T qy2 = q.y * q.y; T qz2 = q.z * q.z; - udMatrix4x4 r = {{{ - 1 - 2 * qy2 - 2 * qz2, 2 * q.x*q.y + 2 * q.z*q.w, 2 * q.x*q.z - 2 * q.y*q.w, T(0), - 2 * q.x*q.y - 2 * q.z*q.w, 1 - 2 * qx2 - 2 * qz2 , 2 * q.y*q.z + 2 * q.x*q.w, T(0), - 2 * q.x*q.z + 2 * q.y*q.w, 2 * q.y*q.z - 2 * q.x*q.w, 1 - 2 * qx2 - 2 * qy2, T(0), - t.x, t.y, t.z, T(1) - }}}; + udMatrix4x4 r = { { { 1 - 2 * qy2 - 2 * qz2, 2 * q.x * q.y + 2 * q.z * q.w, 2 * q.x * q.z - 2 * q.y * q.w, T(0), + 2 * q.x * q.y - 2 * q.z * q.w, 1 - 2 * qx2 - 2 * qz2, 2 * q.y * q.z + 2 * q.x * q.w, T(0), + 2 * q.x * q.z + 2 * q.y * q.w, 2 * q.y * q.z - 2 * q.x * q.w, 1 - 2 * qx2 - 2 * qy2, T(0), + t.x, t.y, t.z, T(1) } } }; return r; } @@ -909,20 +1103,20 @@ udMatrix4x4 udMatrix4x4::rotationQuat(const udQuaternion &q, const udVe template udMatrix4x4 udMatrix4x4::translation(T x, T y, T z) { - udMatrix4x4 r = {{{ T(1),T(0),T(0),T(0), - T(0),T(1),T(0),T(0), - T(0),T(0),T(1),T(0), - x, y, z, T(1) }}}; + udMatrix4x4 r = { { { T(1), T(0), T(0), T(0), + T(0), T(1), T(0), T(0), + T(0), T(0), T(1), T(0), + x, y, z, T(1) } } }; return r; } template udMatrix4x4 udMatrix4x4::scaleNonUniform(T x, T y, T z, const udVector3 &t) { - udMatrix4x4 r = {{{ x, T(0), T(0), T(0), - T(0), y, T(0), T(0), - T(0), T(0), z, T(0), - t.x, t.y, t.z, T(1) }}}; + udMatrix4x4 r = { { { x, T(0), T(0), T(0), + T(0), y, T(0), T(0), + T(0), T(0), z, T(0), + t.x, t.y, t.z, T(1) } } }; return r; } @@ -930,10 +1124,10 @@ template udMatrix4x4 udMatrix4x4::perspectiveZO(T fovY, T aspectRatio, T zNear, T zFar) { T fov = udTan(fovY / T(2)); - udMatrix4x4 r = {{{ T(1) / (aspectRatio*fov), T(0), T(0), T(0), - T(0), T(0), zFar / (zFar - zNear), T(1), - T(0), T(1)/fov, T(0), T(0), - T(0), T(0), -(zFar * zNear) / (zFar - zNear), T(0) }}}; + udMatrix4x4 r = { { { T(1) / (aspectRatio * fov), T(0), T(0), T(0), + T(0), T(0), zFar / (zFar - zNear), T(1), + T(0), T(1) / fov, T(0), T(0), + T(0), T(0), -(zFar * zNear) / (zFar - zNear), T(0) } } }; return r; } @@ -941,60 +1135,60 @@ template udMatrix4x4 udMatrix4x4::perspectiveNO(T fovY, T aspectRatio, T zNear, T zFar) { T fov = udTan(fovY / T(2)); - udMatrix4x4 r = {{{ T(1) / (aspectRatio*fov), T(0), T(0), T(0), - T(0), T(0), (zFar + zNear) / (zFar - zNear), T(1), - T(0), T(1) / fov, T(0), T(0), - T(0), T(0), -(T(2) * zFar * zNear) / (zFar - zNear), T(0) } } }; + udMatrix4x4 r = { { { T(1) / (aspectRatio * fov), T(0), T(0), T(0), + T(0), T(0), (zFar + zNear) / (zFar - zNear), T(1), + T(0), T(1) / fov, T(0), T(0), + T(0), T(0), -(T(2) * zFar * zNear) / (zFar - zNear), T(0) } } }; return r; } template udMatrix4x4 udMatrix4x4::orthoNO(T left, T right, T bottom, T top, T znear, T zfar) { - udMatrix4x4 r = {{{ T(2) / (right - left), T(0), T(0), T(0), - T(0), T(0), T(2) / (zfar - znear), T(0), - T(0), T(2) / (top - bottom), T(0), T(0), - -(right + left) / (right - left), -(top + bottom) / (top - bottom), -(zfar + znear) / (zfar - znear), T(1) }}}; + udMatrix4x4 r = { { { T(2) / (right - left), T(0), T(0), T(0), + T(0), T(0), T(2) / (zfar - znear), T(0), + T(0), T(2) / (top - bottom), T(0), T(0), + -(right + left) / (right - left), -(top + bottom) / (top - bottom), -(zfar + znear) / (zfar - znear), T(1) } } }; return r; } template udMatrix4x4 udMatrix4x4::orthoZO(T left, T right, T bottom, T top, T znear, T zfar) { - udMatrix4x4 r = {{{ T(2) / (right - left), T(0), T(0), T(0), - T(0), T(0), T(1) / (zfar - znear), T(0), - T(0), T(2) / (top - bottom), T(0), T(0), - -(right + left) / (right - left), -(top + bottom) / (top - bottom), -znear / (zfar - znear), T(1) }}}; + udMatrix4x4 r = { { { T(2) / (right - left), T(0), T(0), T(0), + T(0), T(0), T(1) / (zfar - znear), T(0), + T(0), T(2) / (top - bottom), T(0), T(0), + -(right + left) / (right - left), -(top + bottom) / (top - bottom), -znear / (zfar - znear), T(1) } } }; return r; } template udMatrix4x4 udMatrix4x4::orthoForScreen(T width, T height, T znear, T zfar) { - udMatrix4x4 r = {{{ T(2) / width, T(0), T(0), T(0), - T(0), -T(2) / height, T(0), T(0), - T(0), T(0), T(2) / (zfar - znear), T(0), - T(-1), T(1), -(zfar + znear) / (zfar - znear), T(1) }}}; + udMatrix4x4 r = { { { T(2) / width, T(0), T(0), T(0), + T(0), -T(2) / height, T(0), T(0), + T(0), T(0), T(2) / (zfar - znear), T(0), + T(-1), T(1), -(zfar + znear) / (zfar - znear), T(1) } } }; return r; } template udMatrix4x4 udMatrix4x4::frustumZO(T left, T right, T bottom, T top, T znear, T zfar) { - udMatrix4x4 r = { {{ T(2) * znear / (right - left), T(0), T(0), T(0), - (right + left) / (right - left), (top + bottom) / (top - bottom), zfar / (zfar - znear), T(1), - T(0), T(2) * znear / (top - bottom), T(0), T(0), - T(0), T(0), -(zfar * znear) / (zfar - znear), T(0) }}}; + udMatrix4x4 r = { { { T(2) * znear / (right - left), T(0), T(0), T(0), + (right + left) / (right - left), (top + bottom) / (top - bottom), zfar / (zfar - znear), T(1), + T(0), T(2) * znear / (top - bottom), T(0), T(0), + T(0), T(0), -(zfar * znear) / (zfar - znear), T(0) } } }; return r; } template udMatrix4x4 udMatrix4x4::frustumNO(T left, T right, T bottom, T top, T znear, T zfar) { - udMatrix4x4 r = { {{ T(2) * znear / (right - left), T(0), T(0), T(0), - (right + left) / (right - left), (top + bottom) / (top - bottom), (zfar + znear) / (zfar - znear), T(1), - T(0), T(2) * znear / (top - bottom), T(0), T(0), - T(0), T(0), -(T(2) * zfar * znear) / (zfar - znear), T(0) } } }; + udMatrix4x4 r = { { { T(2) * znear / (right - left), T(0), T(0), T(0), + (right + left) / (right - left), (top + bottom) / (top - bottom), (zfar + znear) / (zfar - znear), T(1), + T(0), T(2) * znear / (top - bottom), T(0), T(0), + T(0), T(0), -(T(2) * zfar * znear) / (zfar - znear), T(0) } } }; return r; } @@ -1004,10 +1198,10 @@ udMatrix4x4 udMatrix4x4::lookAt(const udVector3 &from, const udVector3< udVector3 y = udNormalize3(at - from); udVector3 x = udNormalize3(udCross3(y, up)); udVector3 z = udCross3(x, y); - udMatrix4x4 r = {{{ x.x, x.y, x.z, 0, - y.x, y.y, y.z, 0, - z.x, z.y, z.z, 0, - from.x, from.y, from.z, 1 }}}; + udMatrix4x4 r = { { { x.x, x.y, x.z, 0, + y.x, y.y, y.z, 0, + z.x, z.y, z.z, 0, + from.x, from.y, from.z, 1 } } }; return r; } @@ -1015,11 +1209,11 @@ template udQuaternion udQuaternion::create(const udVector3 &axis, T rad) { UDASSERT(udIsUnitLength(axis, T(1.0 / 4096)), "axis is not normalized, magnitude %f\n", udMag(axis)); - T a = rad*T(0.5); + T a = rad * T(0.5); T s = udSin(a); - udQuaternion r = { axis.x*s, - axis.y*s, - axis.z*s, + udQuaternion r = { axis.x * s, + axis.y * s, + axis.z * s, udCos(a) }; return r; } diff --git a/Include/udNew.h b/Include/udNew.h index f64cb0ed..ab9285eb 100644 --- a/Include/udNew.h +++ b/Include/udNew.h @@ -8,13 +8,12 @@ // Wrap up C++ new operator to us udAlloc internally // -#include #include "udPlatform.h" +#include - -#define udNew(type, ...) new (_udAlloc(sizeof(type), udAF_None, IF_MEMORY_DEBUG(__FILE__, __LINE__))) type(__VA_ARGS__) -#define udNewNoParams(type) new (_udAlloc(sizeof(type), udAF_None, IF_MEMORY_DEBUG(__FILE__, __LINE__))) type() -#define udNewFlags(type, extra, flags, ...) new (_udAlloc(sizeof(type) + extra, flags, IF_MEMORY_DEBUG(__FILE__, __LINE__))) type(__VA_ARGS__) +#define udNew(type, ...) new (_udAlloc(sizeof(type), udAF_None, IF_MEMORY_DEBUG(__FILE__, __LINE__))) type(__VA_ARGS__) +#define udNewNoParams(type) new (_udAlloc(sizeof(type), udAF_None, IF_MEMORY_DEBUG(__FILE__, __LINE__))) type() +#define udNewFlags(type, extra, flags, ...) new (_udAlloc(sizeof(type) + extra, flags, IF_MEMORY_DEBUG(__FILE__, __LINE__))) type(__VA_ARGS__) #define udNewFlagsNoParams(type, extra, flags) new (_udAlloc(sizeof(type) + extra, flags, IF_MEMORY_DEBUG(__FILE__, __LINE__))) type() template @@ -28,5 +27,4 @@ void _udDelete(T *&pMemory, const char *pFile, int line) } #define udDelete(pMemory) _udDelete(pMemory, IF_MEMORY_DEBUG(__FILE__, __LINE__)) - #endif // UDNEW_H diff --git a/Include/udPlatform.h b/Include/udPlatform.h index 671f4c53..666acfb8 100644 --- a/Include/udPlatform.h +++ b/Include/udPlatform.h @@ -14,264 +14,292 @@ #include #include -#if defined(_WIN64) || defined(__amd64__) || defined (__arm64__) || defined (__aarch64__) - //64-bit code -# define UD_64BIT (1) -# define UD_32BIT (0) -# define UD_WORD_SHIFT 6 // 6 bits for 64 bit pointer -# define UD_WORD_BITS 64 -# define UD_WORD_BYTES 8 -# define UD_WORD_MAX 0x7fffffffffffffffLL - typedef signed long long udIWord; - typedef unsigned long long udUWord; -#elif defined(_WIN32) || defined(__i386__) || defined(__arm__) || defined(__native_client__) || defined(EMSCRIPTEN) - //32-bit code -# define UD_64BIT (0) -# define UD_32BIT (1) -# define UD_WORD_SHIFT 5 // 5 bits for 32 bit pointer -# define UD_WORD_BITS 32 -# define UD_WORD_BYTES 4 -# define UD_WORD_MAX 0x7fffffffL - typedef signed long udIWord; - typedef unsigned long udUWord; +#if defined(_WIN64) || defined(__amd64__) || defined(__arm64__) || defined(__aarch64__) +//64-bit code +# define UD_64BIT (1) +# define UD_32BIT (0) +# define UD_WORD_SHIFT 6 // 6 bits for 64 bit pointer +# define UD_WORD_BITS 64 +# define UD_WORD_BYTES 8 +# define UD_WORD_MAX 0x7fffffffffffffffLL +typedef signed long long udIWord; +typedef unsigned long long udUWord; +#elif defined(_WIN32) || defined(__i386__) || defined(__arm__) || defined(__native_client__) || defined(EMSCRIPTEN) +//32-bit code +# define UD_64BIT (0) +# define UD_32BIT (1) +# define UD_WORD_SHIFT 5 // 5 bits for 32 bit pointer +# define UD_WORD_BITS 32 +# define UD_WORD_BYTES 4 +# define UD_WORD_MAX 0x7fffffffL +typedef signed long udIWord; +typedef unsigned long udUWord; #else -# error "Unknown architecture (32/64 bit)" +# error "Unknown architecture (32/64 bit)" #endif #if defined(__native_client__) -# include -# include -# define UDPLATFORM_NACL 1 -# define USE_GLES +# include +# include +# define UDPLATFORM_NACL 1 +# define USE_GLES #elif defined(EMSCRIPTEN) -# include -# include -# include -# define UDPLATFORM_EMSCRIPTEN 1 -# if not defined(__EMSCRIPTEN_PTHREADS__) -# error "PTHREADS are not being used!" -# endif +# include +# include +# include +# define UDPLATFORM_EMSCRIPTEN 1 +# if not defined(__EMSCRIPTEN_PTHREADS__) +# error "PTHREADS are not being used!" +# endif #elif defined(_MSC_VER) || defined(__MINGW32__) -# include -# define UDPLATFORM_WINDOWS 1 -# include -# if WINAPI_FAMILY == WINAPI_FAMILY_PC_APP -# define UDPLATFORM_UWP 1 -# endif +# include +# define UDPLATFORM_WINDOWS 1 +# include +# if WINAPI_FAMILY == WINAPI_FAMILY_PC_APP +# define UDPLATFORM_UWP 1 +# endif #elif defined(__ANDROID__) -# include -# include -# include -# define UDPLATFORM_ANDROID 1 +# include +# include +# include +# define UDPLATFORM_ANDROID 1 #elif defined(__linux__) // TODO: Work out best tag to detect linux here -# include -# include -# include -# define UDPLATFORM_LINUX 1 +# include +# include +# include +# define UDPLATFORM_LINUX 1 #elif defined(__APPLE__) -# include -# include -# include -# include "TargetConditionals.h" -# if TARGET_OS_IPHONE && TARGET_IPHONE_SIMULATOR -# define UDPLATFORM_IOS_SIMULATOR 1 -# elif TARGET_OS_IPHONE -# define UDPLATFORM_IOS 1 -# else -# define UDPLATFORM_OSX 1 -# endif +# include "TargetConditionals.h" +# include +# include +# include +# if TARGET_OS_IPHONE && TARGET_IPHONE_SIMULATOR +# define UDPLATFORM_IOS_SIMULATOR 1 +# elif TARGET_OS_IPHONE +# define UDPLATFORM_IOS 1 +# else +# define UDPLATFORM_OSX 1 +# endif #else -# error "Unknown platform" +# error "Unknown platform" #endif #ifndef UDPLATFORM_WINDOWS -# define UDPLATFORM_WINDOWS 0 +# define UDPLATFORM_WINDOWS 0 #endif #ifndef UDPLATFORM_UWP -# define UDPLATFORM_UWP 0 +# define UDPLATFORM_UWP 0 #endif #ifndef UDPLATFORM_ANDROID -# define UDPLATFORM_ANDROID 0 +# define UDPLATFORM_ANDROID 0 #endif #ifndef UDPLATFORM_LINUX -# define UDPLATFORM_LINUX 0 +# define UDPLATFORM_LINUX 0 #endif #ifndef UDPLATFORM_OSX -# define UDPLATFORM_OSX 0 +# define UDPLATFORM_OSX 0 #endif #ifndef UDPLATFORM_IOS_SIMULATOR -# define UDPLATFORM_IOS_SIMULATOR 0 +# define UDPLATFORM_IOS_SIMULATOR 0 #endif #ifndef UDPLATFORM_IOS -# define UDPLATFORM_IOS 0 +# define UDPLATFORM_IOS 0 #endif #ifndef UDPLATFORM_NACL -# define UDPLATFORM_NACL 0 +# define UDPLATFORM_NACL 0 #endif #ifndef UDPLATFORM_EMSCRIPTEN -# define UDPLATFORM_EMSCRIPTEN 0 +# define UDPLATFORM_EMSCRIPTEN 0 #endif #if defined(_DEBUG) -# define UD_DEBUG 1 -# define UD_RELEASE 0 +# define UD_DEBUG 1 +# define UD_RELEASE 0 #else -# define UD_DEBUG 0 -# define UD_RELEASE 1 +# define UD_DEBUG 0 +# define UD_RELEASE 1 #endif #if UDPLATFORM_WINDOWS -# define udU64L(x) x##ULL -# define udI64L(x) x##LL -# define UDFORCE_INLINE __forceinline +# define udU64L(x) x##ULL +# define udI64L(x) x##LL +# define UDFORCE_INLINE __forceinline #elif UDPLATFORM_NACL || UDPLATFORM_EMSCRIPTEN -# define udU64L(x) x##ULL -# define udI64L(x) x##LL -# define UDFORCE_INLINE inline +# define udU64L(x) x##ULL +# define udI64L(x) x##LL +# define UDFORCE_INLINE inline #else -# define udU64L(x) x##UL -# define udI64L(x) x##L -# define UDFORCE_INLINE inline +# define udU64L(x) x##UL +# define udI64L(x) x##L +# define UDFORCE_INLINE inline #endif - #if UDPLATFORM_WINDOWS -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif -#include -#include -# if UD_32BIT +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include +# include +# if UD_32BIT template -inline T *udInterlockedExchangePointer(T * volatile* dest, U *exchange) { return (T*)_InterlockedExchange((volatile long*)dest, (long)exchange); } +inline T *udInterlockedExchangePointer(T *volatile *dest, U *exchange) +{ + return (T *)_InterlockedExchange((volatile long *)dest, (long)exchange); +} template -inline T *udInterlockedCompareExchangePointer(T * volatile* dest, U *exchange, U *comparand) { return (T*)_InterlockedCompareExchange((volatile long *)dest, (long)exchange, (long)comparand); } -# else // UD_32BIT +inline T *udInterlockedCompareExchangePointer(T *volatile *dest, U *exchange, U *comparand) { return (T *)_InterlockedCompareExchange((volatile long *)dest, (long)exchange, (long)comparand); } +# else // UD_32BIT template -inline T *udInterlockedExchangePointer(T * volatile* dest, U *exchange) { return (T*)_InterlockedExchangePointer((volatile PVOID*)dest, (PVOID)exchange); } +inline T *udInterlockedExchangePointer(T *volatile *dest, U *exchange) +{ + return (T *)_InterlockedExchangePointer((volatile PVOID *)dest, (PVOID)exchange); +} template -inline T *udInterlockedCompareExchangePointer(T * volatile* dest, U *exchange, U *comparand) { return (T*)_InterlockedCompareExchangePointer((volatile PVOID*)dest, (PVOID)exchange, (PVOID)comparand); } -# endif // UD_32BIT -# define udSleep(x) Sleep(x) -# define udYield() SwitchToThread() -# define UDTHREADLOCAL __declspec(thread) +inline T *udInterlockedCompareExchangePointer(T *volatile *dest, U *exchange, U *comparand) { return (T *)_InterlockedCompareExchangePointer((volatile PVOID *)dest, (PVOID)exchange, (PVOID)comparand); } +# endif // UD_32BIT +# define udSleep(x) Sleep(x) +# define udYield() SwitchToThread() +# define UDTHREADLOCAL __declspec(thread) #elif UDPLATFORM_LINUX || UDPLATFORM_NACL || UDPLATFORM_OSX || UDPLATFORM_IOS_SIMULATOR || UDPLATFORM_IOS || UDPLATFORM_ANDROID || UDPLATFORM_EMSCRIPTEN -#include -#include -#include // Required for std::nullptr_t below -#if UDPLATFORM_LINUX && !defined(__clang__) && __GNUC__ < 5 +# include // Required for std::nullptr_t below +# include +# include +# if UDPLATFORM_LINUX && !defined(__clang__) && __GNUC__ < 5 // We're just trying to ignore pedantic warnings on CentOS7 GCC due to function pointers being used in this function below -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-pedantic" -#endif +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-pedantic" +# endif template -inline T *udInterlockedExchangePointer(T * volatile* dest, U *exchange) { return (T*)__sync_lock_test_and_set((void * volatile*)dest, (void*)exchange); } -#if UDPLATFORM_LINUX && !defined(__clang__) && __GNUC__ < 5 -# pragma GCC diagnostic pop -#endif +inline T *udInterlockedExchangePointer(T *volatile *dest, U *exchange) +{ + return (T *)__sync_lock_test_and_set((void *volatile *)dest, (void *)exchange); +} +# if UDPLATFORM_LINUX && !defined(__clang__) && __GNUC__ < 5 +# pragma GCC diagnostic pop +# endif template -inline T *udInterlockedCompareExchangePointer(T * volatile* dest, U *exchange, U *comparand) { return (T*)__sync_val_compare_and_swap((void * volatile*)dest, (void*)comparand, (void*)exchange); } -# define udSleep(x) usleep((x)*1000) -# define udYield(x) sched_yield() -# if defined(__INTELLISENSE__) -# define UDTHREADLOCAL -# else -# define UDTHREADLOCAL __thread -# endif +inline T *udInterlockedCompareExchangePointer(T *volatile *dest, U *exchange, U *comparand) +{ + return (T *)__sync_val_compare_and_swap((void *volatile *)dest, (void *)comparand, (void *)exchange); +} +# define udSleep(x) usleep((x)*1000) +# define udYield(x) sched_yield() +# if defined(__INTELLISENSE__) +# define UDTHREADLOCAL +# else +# define UDTHREADLOCAL __thread +# endif #else -#error Unknown platform +# error Unknown platform #endif // nullptr helpers -template inline T *udInterlockedExchangePointer(T * volatile* dest, std::nullptr_t) { return udInterlockedExchangePointer(dest, (T*)nullptr); } -template inline T *udInterlockedCompareExchangePointer(T * volatile* dest, std::nullptr_t, U *comparand) { return udInterlockedCompareExchangePointer(dest, (U*)nullptr, comparand); } -template inline T *udInterlockedCompareExchangePointer(T * volatile* dest, U *exchange, std::nullptr_t) { return udInterlockedCompareExchangePointer(dest, exchange, (U*)nullptr); } +template +inline T *udInterlockedExchangePointer(T *volatile *dest, std::nullptr_t) { return udInterlockedExchangePointer(dest, (T *)nullptr); } +template +inline T *udInterlockedCompareExchangePointer(T *volatile *dest, std::nullptr_t, U *comparand) { return udInterlockedCompareExchangePointer(dest, (U *)nullptr, comparand); } +template +inline T *udInterlockedCompareExchangePointer(T *volatile *dest, U *exchange, std::nullptr_t) { return udInterlockedCompareExchangePointer(dest, exchange, (U *)nullptr); } -template T udMax(T a, T b) { return (a > b) ? a : b; } -template T udMin(T a, T b) { return (a < b) ? a : b; } -template T udMax(T a, U b) { return (a > (T)b) ? a : (T)b; } -template T udMin(T a, U b) { return (a < (T)b) ? a : (T)b; } +template +T udMax(T a, T b) { return (a > b) ? a : b; } +template +T udMin(T a, T b) { return (a < b) ? a : b; } +template +T udMax(T a, U b) { return (a > (T)b) ? a : (T)b; } +template +T udMin(T a, U b) { return (a < (T)b) ? a : (T)b; } -#define UDALIGN_POWEROF2(x,b) (((x)+(b)-1) & -(b)) +#define UDALIGN_POWEROF2(x, b) (((x) + (b)-1) & -(b)) #ifdef __MEMORY_DEBUG__ -# define IF_MEMORY_DEBUG(x,y) x,y +# define IF_MEMORY_DEBUG(x, y) x, y #else -# define IF_MEMORY_DEBUG(x,y) nullptr,0 +# define IF_MEMORY_DEBUG(x, y) nullptr, 0 #endif // __MEMORY_DEBUG__ - #if __cplusplus >= 201103L || _MSC_VER >= 1700 -# define UDCPP11 1 +# define UDCPP11 1 #else -# define UDCPP11 0 +# define UDCPP11 0 #endif #if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) || _MSC_VER >= 1900 -# define UDCPP14 1 +# define UDCPP14 1 #else -# define UDCPP14 0 +# define UDCPP14 0 #endif #if __cplusplus >= 201704L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201704L) -# define UDCPP17 1 +# define UDCPP17 1 #else -# define UDCPP17 0 +# define UDCPP17 0 #endif #if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) -# define UDCPP20 1 +# define UDCPP20 1 #else -# define UDCPP20 0 +# define UDCPP20 0 #endif #if UDCPP17 -# define UD_NO_DISCARD [[nodiscard]] +# define UD_NO_DISCARD [[nodiscard]] #else -# define UD_NO_DISCARD +# define UD_NO_DISCARD #endif #if UDCPP20 -# define UD_NO_DISCARD_(reason) [[nodiscard(reason)]] +# define UD_NO_DISCARD_(reason) [[nodiscard(reason)]] #else -# define UD_NO_DISCARD_(reason) +# define UD_NO_DISCARD_(reason) #endif #if defined(__clang__) || defined(__GNUC__) -# if !UDCPP11 && !defined(nullptr) -# define nullptr NULL -# endif // !UDCPP11 && !defined(nullptr) -#endif // defined(__clang__) || defined(__GNUC__) +# if !UDCPP11 && !defined(nullptr) +# define nullptr NULL +# endif // !UDCPP11 && !defined(nullptr) +#endif // defined(__clang__) || defined(__GNUC__) #if UDCPP11 && !defined(_MSC_VER) -# include - using std::nullptr_t; +# include +using std::nullptr_t; #endif //!defined(_MSC_VER) - #if UDPLATFORM_LINUX || UDPLATFORM_NACL || UDPLATFORM_EMSCRIPTEN -#include +# include #elif UDPLATFORM_UWP -#include +# include #endif #if defined(_MSC_VER) && !defined(_M_ARM64) - UDFORCE_INLINE void udMemset32(void *pDest, uint32_t val, size_t size) { __stosd((unsigned long*)pDest, val, size); } +UDFORCE_INLINE void udMemset32(void *pDest, uint32_t val, size_t size) +{ + __stosd((unsigned long *)pDest, val, size); +} #else - UDFORCE_INLINE void udMemset32(void *pDest, uint32_t val, size_t size) { uint32_t *p = (uint32_t*)pDest; while (size--) *p++ = val; } +UDFORCE_INLINE void udMemset32(void *pDest, uint32_t val, size_t size) +{ + uint32_t *p = (uint32_t *)pDest; + while (size--) + *p++ = val; +} #endif -UDFORCE_INLINE void *udSetZero(void *pMemory, size_t size) { memset(pMemory, 0, size); return pMemory; } +UDFORCE_INLINE void *udSetZero(void *pMemory, size_t size) +{ + memset(pMemory, 0, size); + return pMemory; +} enum udAllocationFlags { @@ -291,12 +319,12 @@ void *_udAlloc(size_t size, udAllocationFlags flags, const char *pFile, int line void *_udAllocAligned(size_t size, size_t alignment, udAllocationFlags flags, const char *pFile, int line); #define udAllocAligned(size, alignment, flags) _udAllocAligned(size, alignment, flags, IF_MEMORY_DEBUG(__FILE__, __LINE__)) -#define udAllocFlags(size, flags) _udAlloc(size, flags, IF_MEMORY_DEBUG(__FILE__, __LINE__)) -#define udAllocType(type, count, flags) (type*)_udAlloc(sizeof(type) * (count), flags, IF_MEMORY_DEBUG(__FILE__, __LINE__)) +#define udAllocFlags(size, flags) _udAlloc(size, flags, IF_MEMORY_DEBUG(__FILE__, __LINE__)) +#define udAllocType(type, count, flags) (type *)_udAlloc(sizeof(type) * (count), flags, IF_MEMORY_DEBUG(__FILE__, __LINE__)) void *_udRealloc(void *pMemory, size_t size, const char *pFile, int line); -#define udRealloc(pMemory, size) _udRealloc(pMemory, size, IF_MEMORY_DEBUG(__FILE__, __LINE__)) -#define udReallocType(pMemory, type, count) (type*)_udRealloc(pMemory, sizeof(type) * (count), IF_MEMORY_DEBUG(__FILE__, __LINE__)) +#define udRealloc(pMemory, size) _udRealloc(pMemory, size, IF_MEMORY_DEBUG(__FILE__, __LINE__)) +#define udReallocType(pMemory, type, count) (type *)_udRealloc(pMemory, sizeof(type) * (count), IF_MEMORY_DEBUG(__FILE__, __LINE__)) void *_udReallocAligned(void *pMemory, size_t size, size_t alignment, const char *pFile, int line); #define udReallocAligned(pMemory, size, alignment) _udReallocAligned(pMemory, size, alignment, IF_MEMORY_DEBUG(__FILE__, __LINE__)) @@ -305,10 +333,10 @@ void _udFreeInternal(void *pMemory, const char *pFile, int line); template void _udFree(T *&pMemory, const char *pFile, int line) { - void *pActualPtr = (void*)pMemory; - if (pActualPtr && udInterlockedCompareExchangePointer((void**)&pMemory, nullptr, pActualPtr) == pActualPtr) + void *pActualPtr = (void *)pMemory; + if (pActualPtr && udInterlockedCompareExchangePointer((void **)&pMemory, nullptr, pActualPtr) == pActualPtr) { - _udFreeInternal((void*)pActualPtr, pFile, line); + _udFreeInternal((void *)pActualPtr, pFile, line); } } #define udFree(pMemory) _udFree(pMemory, IF_MEMORY_DEBUG(__FILE__, __LINE__)) @@ -318,25 +346,25 @@ void _udFree(T *&pMemory, const char *pFile, int line) template void _udFreeSecure(T *&pMemory, size_t size, const char *pFile, int line) { - void *pActualPtr = (void*)pMemory; - if (pActualPtr && udInterlockedCompareExchangePointer((void**)&pMemory, nullptr, pActualPtr) == pActualPtr) + void *pActualPtr = (void *)pMemory; + if (pActualPtr && udInterlockedCompareExchangePointer((void **)&pMemory, nullptr, pActualPtr) == pActualPtr) { // Use a simple random value just to avoid filling sensitive memory with a constant // that can be used to identify the locations in memory where sensitive data was stored int randVal = rand(); size_t i = size & ~3; if (i) - udMemset32((void*)pActualPtr, randVal, i >> 2); // Fill 32-bits at a time first for performance reasons + udMemset32((void *)pActualPtr, randVal, i >> 2); // Fill 32-bits at a time first for performance reasons // Fill the last odd bytes while (i < size) - ((uint8_t*)pActualPtr)[i++] = (uint8_t)randVal; - _udFreeInternal((void*)pActualPtr, pFile, line); + ((uint8_t *)pActualPtr)[i++] = (uint8_t)randVal; + _udFreeInternal((void *)pActualPtr, pFile, line); } } #define udFreeSecure(pMemory, size) _udFreeSecure(pMemory, size, IF_MEMORY_DEBUG(__FILE__, __LINE__)) // Wrapper for alloca with flags. Note flags is OR'd with udAF_None to avoid a cppcat warning -#define udAllocStack(type, count, flags) ((flags & udAF_Zero) ? (type*)udSetZero(alloca(sizeof(type) * (count)), sizeof(type) * (count)) : (type*)alloca(sizeof(type) * (count))) +#define udAllocStack(type, count, flags) ((flags & udAF_Zero) ? (type *)udSetZero(alloca(sizeof(type) * (count)), sizeof(type) * (count)) : (type *)alloca(sizeof(type) * (count))) #define udFreeStack(pMemory) // TODO: Remove these @@ -348,38 +376,42 @@ void _udFreeSecure(T *&pMemory, size_t size, const char *pFile, int line) #define udValidateHeap() #if UDPLATFORM_WINDOWS -# define udMemoryBarrier() MemoryBarrier() +# define udMemoryBarrier() MemoryBarrier() #else -# define udMemoryBarrier() __sync_synchronize() +# define udMemoryBarrier() __sync_synchronize() #endif #define udUnused(x) (void)x #if defined(_MSC_VER) -# define __FUNC_NAME__ __FUNCTION__ +# define __FUNC_NAME__ __FUNCTION__ #elif defined(__GNUC__) -# define __FUNC_NAME__ __PRETTY_FUNCTION__ +# define __FUNC_NAME__ __PRETTY_FUNCTION__ #else -#pragma message ("This platform hasn't setup up __FUNC_NAME__") -# define __FUNC_NAME__ "unknown" +# pragma message("This platform hasn't setup up __FUNC_NAME__") +# define __FUNC_NAME__ "unknown" #endif #if defined(__GNUC__) -# define UD_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) -# if UD_GCC_VERSION < 50000 -# pragma GCC diagnostic ignored "-Wmissing-field-initializers" -# endif +# define UD_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) +# if UD_GCC_VERSION < 50000 +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" +# endif #endif #if defined(__GNUC__) -# define UD_PRINTF_FORMAT_FUNC(fmtIndex) __attribute((format(printf, fmtIndex, fmtIndex + 1))) +# define UD_PRINTF_FORMAT_FUNC(fmtIndex) __attribute((format(printf, fmtIndex, fmtIndex + 1))) #else -# define UD_PRINTF_FORMAT_FUNC(fmtIndex) +# define UD_PRINTF_FORMAT_FUNC(fmtIndex) #endif -#define MAKE_FOURCC(a, b, c, d) ( (((uint32_t)(a)) << 0) | (((uint32_t)(b)) << 8) | (((uint32_t)(c)) << 16) | (((uint32_t)(d)) << 24) ) +#define MAKE_FOURCC(a, b, c, d) ((((uint32_t)(a)) << 0) | (((uint32_t)(b)) << 8) | (((uint32_t)(c)) << 16) | (((uint32_t)(d)) << 24)) -template constexpr size_t udLengthOf(T(&)[N]) { return N; } +template +constexpr size_t udLengthOf(T (&)[N]) +{ + return N; +} #define UDARRAYSIZE udLengthOf // Get physical memory available if possible, otherwise outputs 0 to *pTotalMemory and returns udR_Failure diff --git a/Include/udPlatformUtil.h b/Include/udPlatformUtil.h index e491a2f2..c57a76cd 100644 --- a/Include/udPlatformUtil.h +++ b/Include/udPlatformUtil.h @@ -9,14 +9,13 @@ // #include "udPlatform.h" -#include #include +#include class udJSON; #define UDNAMEASSTRING(s) #s -#define UDSTRINGIFY(s) UDNAMEASSTRING(s) - +#define UDSTRINGIFY(s) UDNAMEASSTRING(s) // ********************************************************************* // Some simple utility template functions @@ -26,12 +25,15 @@ template inline DestType udCastToTypeOf(const SourceType &source, const DestType &) { return DestType(source); } // A utility macro to isolate a bit-field style value from an integer, using an enumerate convention -#define udBitFieldGet(composite, id) (((composite) >> id##Shift) & id##Mask) // Retrieve a field from a composite +#define udBitFieldGet(composite, id) (((composite) >> id##Shift) & id##Mask) // Retrieve a field from a composite #define udBitFieldClear(composite, id) ((composite) & ~(udCastToTypeOf(id##Mask, composite) << id##Shift) // Clear a field, generally used before updating just one field of a composite #define udBitFieldSet(composite, id, value) ((composite) | ((udCastToTypeOf(value, composite) & id##Mask) << id##Shift)) // NOTE! Field should be cleared first, most common case is building a composite from zero template -T *udAddBytes(T *ptr, ptrdiff_t bytes) { return (T*)(bytes + (char*)ptr); } +T *udAddBytes(T *ptr, ptrdiff_t bytes) +{ + return (T *)(bytes + (char *)ptr); +} template inline void udAssignUnaligned(P *ptr, T value) @@ -39,7 +41,7 @@ inline void udAssignUnaligned(P *ptr, T value) #if UDPLATFORM_EMSCRIPTEN memcpy(ptr, &value, sizeof(value)); #else - *(T*)ptr = value; + *(T *)ptr = value; #endif } @@ -54,7 +56,7 @@ inline udResult udReadFromPointer(T *pDest, P *&pSrc, int *pBytesRemaining = nul return udR_CountExceeded; *pBytesRemaining -= bytesRequired; } - memcpy((void*)pDest, pSrc, bytesRequired); + memcpy((void *)pDest, pSrc, bytesRequired); pSrc = udAddBytes(pSrc, bytesRequired); return udR_Success; } @@ -69,7 +71,7 @@ inline udResult udWriteToPointer(T *pSrc, P *&pDest, int *pBytesRemaining = null return udR_CountExceeded; *pBytesRemaining -= bytesRequired; } - memcpy((void*)pDest, pSrc, bytesRequired); + memcpy((void *)pDest, pSrc, bytesRequired); pDest = udAddBytes(pDest, bytesRequired); return udR_Success; } @@ -89,11 +91,11 @@ void udUpdateCamera(float camera[16], float yawRadians, float pitchRadians, floa // ********************************************************************* // Time and timing // ********************************************************************* -uint32_t udGetTimeMs(); // Get a millisecond-resolution timer that is thread-independent - timeGetTime() on windows -uint64_t udPerfCounterStart(); // Get a starting point value for now (thread dependent) +uint32_t udGetTimeMs(); // Get a millisecond-resolution timer that is thread-independent - timeGetTime() on windows +uint64_t udPerfCounterStart(); // Get a starting point value for now (thread dependent) float udPerfCounterMilliseconds(uint64_t startValue, uint64_t end = 0); // Get elapsed time since previous start (end value is "now" by default) -float udPerfCounterSeconds(uint64_t startValue, uint64_t end = 0); // Get elapsed time since previous start (end value is "now" by default) -int udDaysUntilExpired(int maxDays, const char **ppExpireDateStr); // Return the number of days until the build expires +float udPerfCounterSeconds(uint64_t startValue, uint64_t end = 0); // Get elapsed time since previous start (end value is "now" by default) +int udDaysUntilExpired(int maxDays, const char **ppExpireDateStr); // Return the number of days until the build expires int64_t udGetEpochSecsUTCd(); double udGetEpochSecsUTCf(); @@ -116,13 +118,13 @@ class udOSString char *pUTF8; }; #else -# define udOSString(p) p +# define udOSString(p) p #endif // ********************************************************************* // Helper for growing an array as required TODO: Use configured memory allocators // ********************************************************************* -template +template bool udSizeArray(T *&ptr, size_t ¤tLength, size_t requiredLength, size_t allocationMultiples = 0) { if (requiredLength > currentLength || allocationMultiples == 0) @@ -136,7 +138,7 @@ bool udSizeArray(T *&ptr, size_t ¤tLength, size_t requiredLength, size_t a if (!resized) return false; - ptr = (T*)resized; + ptr = (T *)resized; currentLength = newLength; } return true; @@ -148,8 +150,8 @@ bool udSizeArray(T *&ptr, size_t ¤tLength, size_t requiredLength, size_t a inline uint32_t udCountBits32(uint32_t v) { - v = v - ((v >> 1) & 0x55555555); // reuse input as temporary - v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp + v = v - ((v >> 1) & 0x55555555); // reuse input as temporary + v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp return (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; // count } @@ -160,26 +162,25 @@ inline uint32_t udCountBits64(uint64_t v) inline uint32_t udCountBits8(uint8_t a_number) { - static const uint8_t bits[256] = { 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4, - 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, - 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, - 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, - 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, - 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, - 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, - 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, - 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, - 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, - 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, - 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, - 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, - 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, - 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, - 4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8 }; + static const uint8_t bits[256] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 }; return bits[a_number]; } - // ********************************************************************* // Create (or optionally update) a standard 32-bit CRC (polynomial 0xedb88320) uint32_t udCrc(const void *pBuffer, size_t length, uint32_t updateCrc = 0); @@ -187,7 +188,6 @@ uint32_t udCrc(const void *pBuffer, size_t length, uint32_t updateCrc = 0); // Create (or optionally update) a iSCSI standard 32-bit CRC (polynomial 0x1edc6f41) uint32_t udCrc32c(const void *pBuffer, size_t length, uint32_t updateCrc = 0); - // ********************************************************************* // Simple base64 decoder, output can be same memory as input // Pass nullptr for pOutput to count output bytes @@ -206,7 +206,6 @@ udResult udBase64Encode(const char **ppDestStr, const void *pBinary, size_t bina // ********************************************************************* int udGetHardwareThreadCount(); - // ********************************************************************* // A helper class for dealing with filenames // If allocated rather than created with new, call Construct method @@ -224,9 +223,16 @@ class udFilename udFilename(udFilename &&o) noexcept; udFilename &operator=(udFilename &&o) noexcept; void Construct() { SetFromFullPath(NULL); } - void Destruct() { if (pPath != path) udFree(pPath); } + void Destruct() + { + if (pPath != path) + udFree(pPath); + } - enum { MaxPath = 260 }; + enum + { + MaxPath = 260 + }; //Cast operator for convenience operator const char *() { return pPath; } @@ -238,7 +244,8 @@ class udFilename // SetFilenameNoExt - Set the filename without extension, retaining the existing folder and extension // SetExtension - Set the extension, retaining the folder and filename // - UD_PRINTF_FORMAT_FUNC(2) bool SetFromFullPath(const char *pFormat, ...); + UD_PRINTF_FORMAT_FUNC(2) + bool SetFromFullPath(const char *pFormat, ...); bool SetFolder(const char *folder); bool SetFilenameNoExt(const char *filenameOnlyComponent); bool SetFilenameWithExt(const char *filenameWithExtension); @@ -249,9 +256,9 @@ class udFilename // GetPath - Get the complete path (eg pass to fopen) // GetFilenameWithExt - Get the filename and extension, without the path // GetExt - Get just the extension (starting with the dot) - const char *GetPath() const { return pPath; } + const char *GetPath() const { return pPath; } const char *GetFilenameWithExt() const { return pPath + filenameIndex; } - const char *GetExt() const { return pPath + extensionIndex; } + const char *GetExt() const { return pPath + extensionIndex; } // // Extract methods: (take portions from within the full path to a user supplied buffer, returning size required) @@ -263,21 +270,20 @@ class udFilename // // Test methods: to determine what is present in the filename - bool HasFilename() const { return pPath[filenameIndex] != 0; } - bool HasExt() const { return pPath[extensionIndex] != 0; } + bool HasFilename() const { return pPath[filenameIndex] != 0; } + bool HasExt() const { return pPath[extensionIndex] != 0; } // Temporary function to output debug info until unit tests are done to prove reliability void Debug(); protected: void CalculateIndices(); - int filenameIndex; // Index to starting character of filename - int extensionIndex; // Index to starting character of extension - char path[MaxPath]; // Buffer for the path, set to 260 characters - char *pPath; // Pointer to actual path, may point to path + int filenameIndex; // Index to starting character of filename + int extensionIndex; // Index to starting character of extension + char path[MaxPath]; // Buffer for the path, set to 260 characters + char *pPath; // Pointer to actual path, may point to path }; - // ********************************************************************* // A helper class for dealing with filenames, allocates memory due to unknown maximum length of url // If allocated rather than created with new, call Construct method @@ -285,15 +291,19 @@ class udFilename class udURL { public: - udURL(const char *pURLText = nullptr) { Construct(); SetURL(pURLText); } + udURL(const char *pURLText = nullptr) + { + Construct(); + SetURL(pURLText); + } ~udURL() { SetURL(nullptr); } void Construct() { pURLText = nullptr; } udResult SetURL(const char *pURLText); - const char *GetScheme() { return pScheme; } - const char *GetDomain() { return pDomain; } - int GetPort() { return port; } - const char *GetPathWithQuery() { return pPath; } + const char *GetScheme() { return pScheme; } + const char *GetDomain() { return pDomain; } + int GetPort() { return port; } + const char *GetPathWithQuery() { return pPath; } protected: char *pURLText; @@ -303,7 +313,6 @@ class udURL int port; }; - // Load or Save a BMP udResult udSaveBMP(const char *pFilename, int width, int height, uint32_t *pColorData, int pitch = 0); udResult udLoadBMP(const char *pFilename, int *pWidth, int *pHeight, uint32_t **pColorData); @@ -350,5 +359,4 @@ udResult udParseWKT(udJSON *pValue, const char *pWKTString, int *pCharCount = nu // Export a previously parsed WKT back to WKT format udResult udExportWKT(const char **ppOutput, const udJSON *pValue); - #endif // UDPLATFORM_UTIL_H diff --git a/Include/udResult.h b/Include/udResult.h index e36d6637..e4c29c77 100644 --- a/Include/udResult.h +++ b/Include/udResult.h @@ -11,27 +11,90 @@ #define __STDC_FORMAT_MACROS #include -extern bool g_udBreakOnError; // Set to true normally, unset and reset around sections of code (eg tests) that aren't unexpected +extern bool g_udBreakOnError; // Set to true normally, unset and reset around sections of code (eg tests) that aren't unexpected extern const char *g_udLastErrorFilename; extern int g_udLastErrorLine; #if !defined(UD_ERROR_BREAK_ON_ERROR) -# define UD_ERROR_BREAK_ON_ERROR 0 // Set to 1 to have the debugger break on error +# define UD_ERROR_BREAK_ON_ERROR 0 // Set to 1 to have the debugger break on error #endif #if defined(_DEBUG) -# define UD_ERROR_SETLAST(f,l) g_udLastErrorFilename = f; g_udLastErrorLine = l +# define UD_ERROR_SETLAST(f, l) \ + g_udLastErrorFilename = f; \ + g_udLastErrorLine = l #else -# define UD_ERROR_SETLAST(f,l) g_udLastErrorLine = l +# define UD_ERROR_SETLAST(f, l) g_udLastErrorLine = l #endif // Some helper macros that assume an exit path label "epilogue" and a local variable "result" -#define UD_ERROR_IF(cond, code) do { if (cond) { result = code; if (result) { UD_ERROR_SETLAST(__FILE__,__LINE__); if (g_udBreakOnError && UD_ERROR_BREAK_ON_ERROR) { __debugbreak(); } } goto epilogue; } } while(0) -#define UD_ERROR_NULL(ptr, code) do { if (ptr == nullptr) { result = code; if (result) { UD_ERROR_SETLAST(__FILE__,__LINE__); if (g_udBreakOnError && UD_ERROR_BREAK_ON_ERROR) { __debugbreak(); } } goto epilogue; } } while(0) -#define UD_ERROR_SET(code) do { result = code; if (result) { UD_ERROR_SETLAST(__FILE__,__LINE__); if (g_udBreakOnError && UD_ERROR_BREAK_ON_ERROR) { __debugbreak(); } } goto epilogue; } while(0) -#define UD_ERROR_HANDLE() do { if (result) goto epilogue; } while(0) -#define UD_ERROR_CHECK(funcCall) do { result = funcCall; if (result) goto epilogue; } while(0) -#define UD_ERROR_SET_NO_BREAK(code) do { result = code; goto epilogue; } while(0) +#define UD_ERROR_IF(cond, code) \ + do \ + { \ + if (cond) \ + { \ + result = code; \ + if (result) \ + { \ + UD_ERROR_SETLAST(__FILE__, __LINE__); \ + if (g_udBreakOnError && UD_ERROR_BREAK_ON_ERROR) \ + { \ + __debugbreak(); \ + } \ + } \ + goto epilogue; \ + } \ + } while (0) +#define UD_ERROR_NULL(ptr, code) \ + do \ + { \ + if (ptr == nullptr) \ + { \ + result = code; \ + if (result) \ + { \ + UD_ERROR_SETLAST(__FILE__, __LINE__); \ + if (g_udBreakOnError && UD_ERROR_BREAK_ON_ERROR) \ + { \ + __debugbreak(); \ + } \ + } \ + goto epilogue; \ + } \ + } while (0) +#define UD_ERROR_SET(code) \ + do \ + { \ + result = code; \ + if (result) \ + { \ + UD_ERROR_SETLAST(__FILE__, __LINE__); \ + if (g_udBreakOnError && UD_ERROR_BREAK_ON_ERROR) \ + { \ + __debugbreak(); \ + } \ + } \ + goto epilogue; \ + } while (0) +#define UD_ERROR_HANDLE() \ + do \ + { \ + if (result) \ + goto epilogue; \ + } while (0) +#define UD_ERROR_CHECK(funcCall) \ + do \ + { \ + result = funcCall; \ + if (result) \ + goto epilogue; \ + } while (0) +#define UD_ERROR_SET_NO_BREAK(code) \ + do \ + { \ + result = code; \ + goto epilogue; \ + } while (0) #define UD_RESULT_VERSION 2111031245U diff --git a/Include/udSafeDeque.h b/Include/udSafeDeque.h index 2185afd9..3efc180b 100644 --- a/Include/udSafeDeque.h +++ b/Include/udSafeDeque.h @@ -8,8 +8,8 @@ // Wraps udChunkedArray to provide a thread safe strict deque interface // -#include "udResult.h" #include "udChunkedArray.h" +#include "udResult.h" #include "udThread.h" /// Thread safe double ended queue diff --git a/Include/udSocket.h b/Include/udSocket.h index 8fafd938..8ce08b69 100644 --- a/Include/udSocket.h +++ b/Include/udSocket.h @@ -21,7 +21,7 @@ enum udSocketConnectionFlags udSCF_IsServer = 1 << 0, udSCF_UseTLS = 1 << 1 }; -inline udSocketConnectionFlags operator |(udSocketConnectionFlags a, udSocketConnectionFlags b) { return (udSocketConnectionFlags)(((int)a) | ((int)b)); } +inline udSocketConnectionFlags operator|(udSocketConnectionFlags a, udSocketConnectionFlags b) { return (udSocketConnectionFlags)(((int)a) | ((int)b)); } // Initialisation udResult udSocket_InitSystem(); diff --git a/Include/udStringUtil.h b/Include/udStringUtil.h index 614e3815..fb66acaf 100644 --- a/Include/udStringUtil.h +++ b/Include/udStringUtil.h @@ -29,9 +29,12 @@ size_t udStrlen(const char *pStr); // ********************************************************************* // Helper functions for fixed size strings // ********************************************************************* -template inline size_t udStrcpy(char(&dest)[N], const char *pSrc) { return udStrcpy(dest, N, pSrc); } -template inline size_t udStrncpy(char(&dest)[N], const char *pSrc, size_t maxChars) { return udStrncpy(dest, N, pSrc, maxChars); } -template inline size_t udStrcat(char(&dest)[N], const char *pSrc) { return udStrcat(dest, N, pSrc); } +template +inline size_t udStrcpy(char (&dest)[N], const char *pSrc) { return udStrcpy(dest, N, pSrc); } +template +inline size_t udStrncpy(char (&dest)[N], const char *pSrc, size_t maxChars) { return udStrncpy(dest, N, pSrc, maxChars); } +template +inline size_t udStrcat(char (&dest)[N], const char *pSrc) { return udStrcat(dest, N, pSrc); } // ********************************************************************* // String maniplulation functions, NULL-safe @@ -39,15 +42,15 @@ template inline size_t udStrcat(char(&dest)[N], const char *pSrc) { r // udStrdup behaves much like strdup, optionally allocating additional characters and replicating NULL #ifdef __MEMORY_DEBUG__ char *_udStrdup(const char *pStr, size_t additionalChars, const char *pFile, int line); -#define UD_EXPAND(x) x -#define UDSTRDUP_1_ARGS(pStr) _udStrdup(pStr, 0, __FILE__, __LINE__) -#define UDSTRDUP_2_ARGS(pStr, additionalChars) _udStrdup(pStr, additionalChars, __FILE__, __LINE__) +# define UD_EXPAND(x) x +# define UDSTRDUP_1_ARGS(pStr) _udStrdup(pStr, 0, __FILE__, __LINE__) +# define UDSTRDUP_2_ARGS(pStr, additionalChars) _udStrdup(pStr, additionalChars, __FILE__, __LINE__) -#define GET_3RD_ARG(arg1, arg2, arg3, ...) arg3 -#define UDSTRDUP_MACRO_CHOOSER(...) \ +# define GET_3RD_ARG(arg1, arg2, arg3, ...) arg3 +# define UDSTRDUP_MACRO_CHOOSER(...) \ UD_EXPAND(GET_3RD_ARG(__VA_ARGS__, UDSTRDUP_2_ARGS, UDSTRDUP_1_ARGS, )) -#define udStrdup(...) UD_EXPAND(UDSTRDUP_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)) +# define udStrdup(...) UD_EXPAND(UDSTRDUP_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)) #else char *udStrdup(const char *pStr, size_t additionalChars = 0); #endif @@ -82,10 +85,14 @@ size_t udStrItoa(char *pStr, size_t strLen, int32_t value, int radix = 10, size_ size_t udStrItoa64(char *pStr, size_t strLen, int64_t value, int radix = 10, size_t minChars = 1); size_t udStrFtoa(char *pStr, size_t strLen, double value, int precision, size_t minChars = 1); // udStr*toa helpers for fixed size strings -template inline size_t udStrUtoa(char(&str)[N], uint64_t value, int radix = 10, size_t minChars = 1) { return udStrUtoa(str, N, value, radix, minChars); } -template inline size_t udStrItoa(char(&str)[N], int32_t value, int radix = 10, size_t minChars = 1) { return udStrItoa(str, N, value, radix, minChars); } -template inline size_t udStrItoa64(char(&str)[N], int64_t value, int radix = 10, size_t minChars = 1) { return udStrItoa64(str, N, value, radix, minChars); } -template inline size_t udStrFtoa(char(&str)[N], double value, int precision, size_t minChars = 1) { return udStrFtoa(str, N, value, precision, minChars); } +template +inline size_t udStrUtoa(char (&str)[N], uint64_t value, int radix = 10, size_t minChars = 1) { return udStrUtoa(str, N, value, radix, minChars); } +template +inline size_t udStrItoa(char (&str)[N], int32_t value, int radix = 10, size_t minChars = 1) { return udStrItoa(str, N, value, radix, minChars); } +template +inline size_t udStrItoa64(char (&str)[N], int64_t value, int radix = 10, size_t minChars = 1) { return udStrItoa64(str, N, value, radix, minChars); } +template +inline size_t udStrFtoa(char (&str)[N], double value, int precision, size_t minChars = 1) { return udStrFtoa(str, N, value, precision, minChars); } // Split a line into an array of tokens int udStrTokenSplit(char *pLine, const char *pDelimiters, char *pTokenArray[], int maxTokens); @@ -131,7 +138,8 @@ int udAddToStringTable(char *&pStringTable, uint32_t *pStringTableLength, const // ********************************************************************* // Create a temporary small string using one of a number of cycling static buffers -UD_PRINTF_FORMAT_FUNC(1) const char *udTempStr(const char *pFormat, ...); +UD_PRINTF_FORMAT_FUNC(1) +const char *udTempStr(const char *pFormat, ...); // Give back pretty version (ie with commas) of an int using one of a number of cycling static buffers const char *udTempStr_CommaInt(int64_t n); @@ -147,14 +155,25 @@ inline const char *udSecondsToString(int seconds, bool trimHours = true) { retur // Return a human readable measurement string such as 1cm for 0.01, 2mm for 0.002 etc using one of a number of cycling static buffers const char *udTempStr_HumanMeasurement(double measurement); - // Write a formatted string to the buffer -UD_PRINTF_FORMAT_FUNC(3) int udSprintf(char *pDest, size_t destlength, const char *pFormat, ...); +UD_PRINTF_FORMAT_FUNC(3) +int udSprintf(char *pDest, size_t destlength, const char *pFormat, ...); int udSprintfVA(char *pDest, size_t destlength, const char *pFormat, va_list args); // Create an allocated string to fit the output, *ppDest will be freed if non-null, and may be an argument to the string -UD_PRINTF_FORMAT_FUNC(2) udResult udSprintf(const char **ppDest, const char *pFormat, ...); +UD_PRINTF_FORMAT_FUNC(2) +udResult udSprintf(const char **ppDest, const char *pFormat, ...); // Helper functions for fixed size arrays -template UD_PRINTF_FORMAT_FUNC(2) inline int udSprintf(char(&dest)[N], const char *pFormat, ...) { va_list args; va_start(args, pFormat); int length = udSprintfVA(dest, N, pFormat, args); va_end(args); return length; } -template inline int udSprintfVA(char(&dest)[N], const char *pFormat, va_list args) { return udSprintfVA(dest, N, pFormat, args); } +template +UD_PRINTF_FORMAT_FUNC(2) +inline int udSprintf(char (&dest)[N], const char *pFormat, ...) +{ + va_list args; + va_start(args, pFormat); + int length = udSprintfVA(dest, N, pFormat, args); + va_end(args); + return length; +} +template +inline int udSprintfVA(char (&dest)[N], const char *pFormat, va_list args) { return udSprintfVA(dest, N, pFormat, args); } #endif // UDSTRINGUTIL_H diff --git a/Include/udThread.h b/Include/udThread.h index 13cefdff..9b4cf344 100644 --- a/Include/udThread.h +++ b/Include/udThread.h @@ -8,8 +8,8 @@ // Very simple thread/synchronisation API wrapping the various platform implementations // -#include "udPlatform.h" #include "udCallback.h" +#include "udPlatform.h" // Minimalist MOST BASIC cross-platform thread support struct udSemaphore; @@ -17,8 +17,18 @@ struct udConditionVariable; struct udRWLock; struct udMutex; struct udThread; -enum udThreadPriority { udTP_Lowest, udTP_Low, udTP_Normal, udTP_High, udTP_Highest }; -enum udThreadCreateFlags { udTCF_None }; // For future expansion +enum udThreadPriority +{ + udTP_Lowest, + udTP_Low, + udTP_Normal, + udTP_High, + udTP_Highest +}; +enum udThreadCreateFlags +{ + udTCF_None +}; // For future expansion #define UDTHREAD_WAIT_INFINITE -1 using udThreadStart = udCallback; @@ -50,7 +60,7 @@ int udWaitConditionVariable(udConditionVariable *pConditionVariable, udMutex *pM udRWLock *udCreateRWLock(); void udDestroyRWLock(udRWLock **ppRWLock); -int udReadLockRWLock(udRWLock *pRWLock); // Returns zero on success +int udReadLockRWLock(udRWLock *pRWLock); // Returns zero on success int udWriteLockRWLock(udRWLock *pRWLock); // Returns zero on success void udReadUnlockRWLock(udRWLock *pRWLock); void udWriteUnlockRWLock(udRWLock *pRWLock); @@ -64,8 +74,13 @@ void udReleaseMutex(udMutex *pMutex); class udScopeLock { public: - udScopeLock(udMutex *mutex) { m_mutex = mutex; udLockMutex(m_mutex); } + udScopeLock(udMutex *mutex) + { + m_mutex = mutex; + udLockMutex(m_mutex); + } ~udScopeLock() { udReleaseMutex(m_mutex); } + protected: udMutex *m_mutex; }; diff --git a/Include/udUUID.h b/Include/udUUID.h index d01a133e..0c204096 100644 --- a/Include/udUUID.h +++ b/Include/udUUID.h @@ -8,28 +8,29 @@ // UUID implementation // -#include #include "udPlatform.h" +#include struct udUUID { - enum { + enum + { udUUID_Length = 36 }; - uint8_t internal_bytes[udUUID_Length+1]; //+1 for \0 + uint8_t internal_bytes[udUUID_Length + 1]; //+1 for \0 }; void udUUID_Clear(udUUID *pUUID); udResult udUUID_SetFromString(udUUID *pUUID, const char *pStr); //pStr can be freed after this -const char* udUUID_GetAsString(const udUUID &UUID); //Do not free, you do not own this -const char* udUUID_GetAsString(const udUUID *pUUID); //Do not free, you do not own this +const char *udUUID_GetAsString(const udUUID &UUID); //Do not free, you do not own this +const char *udUUID_GetAsString(const udUUID *pUUID); //Do not free, you do not own this // These functions generate UUIDs -udResult udUUID_GenerateFromRandom(udUUID *pUUID); // Fills out pUUID as a version 4 UUID +udResult udUUID_GenerateFromRandom(udUUID *pUUID); // Fills out pUUID as a version 4 UUID udResult udUUID_GenerateFromString(udUUID *pUUID, const char *pStr); // Fills out pUUID as a version 5 UUID -udResult udUUID_GenerateFromInt(udUUID *pUUID, int64_t value); // Fills out pUUID as a version 5 UUID +udResult udUUID_GenerateFromInt(udUUID *pUUID, int64_t value); // Fills out pUUID as a version 5 UUID bool udUUID_IsValid(const udUUID &UUID); bool udUUID_IsValid(const udUUID *pUUID); @@ -37,7 +38,7 @@ bool udUUID_IsValid(const char *pUUIDStr); uint64_t udUUID_ToNonce(const udUUID *pUUID); -bool operator ==(const udUUID a, const udUUID b); -bool operator !=(const udUUID a, const udUUID b); +bool operator==(const udUUID a, const udUUID b); +bool operator!=(const udUUID a, const udUUID b); #endif //UDUUID_H diff --git a/Include/udWorkerPool.h b/Include/udWorkerPool.h index d148a45b..f81ebc35 100644 --- a/Include/udWorkerPool.h +++ b/Include/udWorkerPool.h @@ -8,8 +8,8 @@ // Handles fire and forget work by pooling and processing async // -#include "udResult.h" #include "udCallback.h" +#include "udResult.h" // Function definition for async and marshalled work using udWorkerPoolCallback = udCallback; diff --git a/Source/udAsyncJob.cpp b/Source/udAsyncJob.cpp index 227c4254..eef9c6f9 100644 --- a/Source/udAsyncJob.cpp +++ b/Source/udAsyncJob.cpp @@ -162,13 +162,17 @@ void udAsyncPause_HandlePause(udAsyncPause *pPause) // **************************************************************************** // Author: Dave Pevreal, March 2019 -const char * udAsyncPause_GetErrorContextString(udAsyncPause::Context errorContext) +const char *udAsyncPause_GetErrorContextString(udAsyncPause::Context errorContext) { switch (errorContext) { - case udAsyncPause::EC_None: return "No error context"; - case udAsyncPause::EC_WritingOutputFile: return "Writing output file, disk full?"; - case udAsyncPause::EC_WritingTemporaryFile: return "Writing temporary file, disk full?"; - default: return "(unknown error context)"; + case udAsyncPause::EC_None: + return "No error context"; + case udAsyncPause::EC_WritingOutputFile: + return "Writing output file, disk full?"; + case udAsyncPause::EC_WritingTemporaryFile: + return "Writing temporary file, disk full?"; + default: + return "(unknown error context)"; } } diff --git a/Source/udCompression.cpp b/Source/udCompression.cpp index 80bf4681..2def1f4f 100644 --- a/Source/udCompression.cpp +++ b/Source/udCompression.cpp @@ -1,8 +1,8 @@ -#include "udStringUtil.h" #include "udCompression.h" +#include "libdeflate.h" #include "udFileHandler.h" #include "udMath.h" -#include "libdeflate.h" +#include "udStringUtil.h" #include // **************************************************************************** @@ -11,11 +11,16 @@ const char *udCompressionTypeAsString(udCompressionType type) { switch (type) { - case udCT_None: return "None"; - case udCT_RawDeflate: return "RawDeflate"; - case udCT_ZlibDeflate: return "ZlibDeflate"; - case udCT_GzipDeflate: return "GzipDeflate"; - default: return nullptr; + case udCT_None: + return "None"; + case udCT_RawDeflate: + return "RawDeflate"; + case udCT_ZlibDeflate: + return "ZlibDeflate"; + case udCT_GzipDeflate: + return "GzipDeflate"; + default: + return nullptr; } } @@ -135,69 +140,69 @@ udResult udCompression_Inflate(void *pDest, size_t destSize, const void *pSource } switch (type) { - case udCT_None: - // Handle the special case of no compression - memcpy(pDest, pSource, sourceSize); - if (pInflatedSize) - *pInflatedSize = sourceSize; - break; + case udCT_None: + // Handle the special case of no compression + memcpy(pDest, pSource, sourceSize); + if (pInflatedSize) + *pInflatedSize = sourceSize; + break; - case udCT_RawDeflate: - ldComp = libdeflate_alloc_decompressor(); - UD_ERROR_NULL(ldComp, udR_MemoryAllocationFailure); + case udCT_RawDeflate: + ldComp = libdeflate_alloc_decompressor(); + UD_ERROR_NULL(ldComp, udR_MemoryAllocationFailure); - pTemp = (pDest == pSource) ? udAlloc(destSize) : pDest; - UD_ERROR_NULL(pTemp, udR_MemoryAllocationFailure); + pTemp = (pDest == pSource) ? udAlloc(destSize) : pDest; + UD_ERROR_NULL(pTemp, udR_MemoryAllocationFailure); - lresult = libdeflate_deflate_decompress(ldComp, pSource, sourceSize, pTemp, destSize, &inflatedSize); - if (lresult == LIBDEFLATE_INSUFFICIENT_SPACE) - UD_ERROR_SET_NO_BREAK(udR_BufferTooSmall); - UD_ERROR_IF(lresult != LIBDEFLATE_SUCCESS, udR_CompressionError); + lresult = libdeflate_deflate_decompress(ldComp, pSource, sourceSize, pTemp, destSize, &inflatedSize); + if (lresult == LIBDEFLATE_INSUFFICIENT_SPACE) + UD_ERROR_SET_NO_BREAK(udR_BufferTooSmall); + UD_ERROR_IF(lresult != LIBDEFLATE_SUCCESS, udR_CompressionError); - if (pInflatedSize) - *pInflatedSize = inflatedSize; - if (pTemp != pDest) - memcpy(pDest, pTemp, inflatedSize); - break; + if (pInflatedSize) + *pInflatedSize = inflatedSize; + if (pTemp != pDest) + memcpy(pDest, pTemp, inflatedSize); + break; - case udCT_ZlibDeflate: - ldComp = libdeflate_alloc_decompressor(); - UD_ERROR_NULL(ldComp, udR_MemoryAllocationFailure); + case udCT_ZlibDeflate: + ldComp = libdeflate_alloc_decompressor(); + UD_ERROR_NULL(ldComp, udR_MemoryAllocationFailure); - pTemp = (pDest == pSource) ? udAlloc(destSize) : pDest; - UD_ERROR_NULL(pTemp, udR_MemoryAllocationFailure); + pTemp = (pDest == pSource) ? udAlloc(destSize) : pDest; + UD_ERROR_NULL(pTemp, udR_MemoryAllocationFailure); - lresult = libdeflate_zlib_decompress(ldComp, pSource, sourceSize, pTemp, destSize, &inflatedSize); - if (lresult == LIBDEFLATE_INSUFFICIENT_SPACE) - UD_ERROR_SET_NO_BREAK(udR_BufferTooSmall); - UD_ERROR_IF(lresult != LIBDEFLATE_SUCCESS, udR_CompressionError); + lresult = libdeflate_zlib_decompress(ldComp, pSource, sourceSize, pTemp, destSize, &inflatedSize); + if (lresult == LIBDEFLATE_INSUFFICIENT_SPACE) + UD_ERROR_SET_NO_BREAK(udR_BufferTooSmall); + UD_ERROR_IF(lresult != LIBDEFLATE_SUCCESS, udR_CompressionError); - if (pInflatedSize) - *pInflatedSize = inflatedSize; - if (pTemp != pDest) - memcpy(pDest, pTemp, inflatedSize); - break; + if (pInflatedSize) + *pInflatedSize = inflatedSize; + if (pTemp != pDest) + memcpy(pDest, pTemp, inflatedSize); + break; - case udCT_GzipDeflate: - ldComp = libdeflate_alloc_decompressor(); - UD_ERROR_NULL(ldComp, udR_MemoryAllocationFailure); + case udCT_GzipDeflate: + ldComp = libdeflate_alloc_decompressor(); + UD_ERROR_NULL(ldComp, udR_MemoryAllocationFailure); - pTemp = (pDest == pSource) ? udAlloc(destSize) : pDest; - UD_ERROR_NULL(pTemp, udR_MemoryAllocationFailure); + pTemp = (pDest == pSource) ? udAlloc(destSize) : pDest; + UD_ERROR_NULL(pTemp, udR_MemoryAllocationFailure); - lresult = libdeflate_gzip_decompress(ldComp, pSource, sourceSize, pTemp, destSize, &inflatedSize); - if (lresult == LIBDEFLATE_INSUFFICIENT_SPACE) - UD_ERROR_SET_NO_BREAK(udR_BufferTooSmall); - UD_ERROR_IF(lresult != LIBDEFLATE_SUCCESS, udR_CompressionError); + lresult = libdeflate_gzip_decompress(ldComp, pSource, sourceSize, pTemp, destSize, &inflatedSize); + if (lresult == LIBDEFLATE_INSUFFICIENT_SPACE) + UD_ERROR_SET_NO_BREAK(udR_BufferTooSmall); + UD_ERROR_IF(lresult != LIBDEFLATE_SUCCESS, udR_CompressionError); - if (pInflatedSize) - *pInflatedSize = inflatedSize; - if (pTemp != pDest) - memcpy(pDest, pTemp, inflatedSize); - break; + if (pInflatedSize) + *pInflatedSize = inflatedSize; + if (pTemp != pDest) + memcpy(pDest, pTemp, inflatedSize); + break; - default: - UD_ERROR_SET(udR_InvalidParameter); + default: + UD_ERROR_SET(udR_InvalidParameter); } result = udR_Success; @@ -212,71 +217,71 @@ udResult udCompression_Inflate(void *pDest, size_t destSize, const void *pSource } // To prevent collisions with other apps using miniz -#define mz_adler32 udComp_adler32 -#define mz_crc32 udComp_crc32 -#define mz_free udComp_free -#define mz_version udComp_version -#define mz_deflateEnd udComp_deflateEnd -#define mz_deflateBound udComp_deflateBound -#define mz_compressBound udComp_compressBound -#define mz_inflateInit2 udComp_inflateInit2 -#define mz_inflateInit udComp_inflateInit -#define mz_inflateEnd udComp_inflateEnd -#define mz_error udComp_error -#define tinfl_decompress udCompTInf_decompress -#define tinfl_decompress_mem_to_heap udCompTInf_decompress_mem_to_heap -#define tinfl_decompress_mem_to_mem udCompTInf_decompress_mem_to_mem -#define tinfl_decompress_mem_to_callback udCompTInf_decompress_mem_to_callback -#define tdefl_compress udCompTDefl_compress -#define tdefl_compress_buffer udCompTDefl_compress_buffer -#define tdefl_init udCompTDefl_init -#define tdefl_get_prev_return_status udCompTDefl_get_prev_return_status -#define tdefl_get_adler32 udCompTDefl_get_adler32 -#define tdefl_compress_mem_to_output udCompTDefl_compress_mem_to_output -#define tdefl_compress_mem_to_heap udCompTDefl_compress_mem_to_heap -#define tdefl_compress_mem_to_mem udCompTDefl_compress_mem_to_mem -#define tdefl_create_comp_flags_from_zip_params udCompTDefl_create_comp_flags_from_zip_params +#define mz_adler32 udComp_adler32 +#define mz_crc32 udComp_crc32 +#define mz_free udComp_free +#define mz_version udComp_version +#define mz_deflateEnd udComp_deflateEnd +#define mz_deflateBound udComp_deflateBound +#define mz_compressBound udComp_compressBound +#define mz_inflateInit2 udComp_inflateInit2 +#define mz_inflateInit udComp_inflateInit +#define mz_inflateEnd udComp_inflateEnd +#define mz_error udComp_error +#define tinfl_decompress udCompTInf_decompress +#define tinfl_decompress_mem_to_heap udCompTInf_decompress_mem_to_heap +#define tinfl_decompress_mem_to_mem udCompTInf_decompress_mem_to_mem +#define tinfl_decompress_mem_to_callback udCompTInf_decompress_mem_to_callback +#define tdefl_compress udCompTDefl_compress +#define tdefl_compress_buffer udCompTDefl_compress_buffer +#define tdefl_init udCompTDefl_init +#define tdefl_get_prev_return_status udCompTDefl_get_prev_return_status +#define tdefl_get_adler32 udCompTDefl_get_adler32 +#define tdefl_compress_mem_to_output udCompTDefl_compress_mem_to_output +#define tdefl_compress_mem_to_heap udCompTDefl_compress_mem_to_heap +#define tdefl_compress_mem_to_mem udCompTDefl_compress_mem_to_mem +#define tdefl_create_comp_flags_from_zip_params udCompTDefl_create_comp_flags_from_zip_params #define tdefl_write_image_to_png_file_in_memory_ex udCompTDefl_write_image_to_png_file_in_memory_ex -#define tdefl_write_image_to_png_file_in_memory udCompTDefl_write_image_to_png_file_in_memory -#define mz_deflateInit2 udComp_deflateInit2 -#define mz_deflateReset udComp_deflateReset -#define mz_deflate udComp_deflate -#define mz_inflate udComp_inflate -#define mz_uncompress udComp_uncompress -#define mz_deflateInit udComp_deflateInit -#define mz_compress2 udComp_compress2 -#define mz_compress udComp_compress +#define tdefl_write_image_to_png_file_in_memory udCompTDefl_write_image_to_png_file_in_memory +#define mz_deflateInit2 udComp_deflateInit2 +#define mz_deflateReset udComp_deflateReset +#define mz_deflate udComp_deflate +#define mz_inflate udComp_inflate +#define mz_uncompress udComp_uncompress +#define mz_deflateInit udComp_deflateInit +#define mz_compress2 udComp_compress2 +#define mz_compress udComp_compress #define mz_zip_writer_init_from_reader udComp_zip_writer_init_from_reader -#define mz_zip_reader_end udComp_mz_zip_reader_end -#define mz_zip_reader_init_mem udComp_mz_zip_reader_init_mem -#define mz_zip_reader_locate_file udComp_mz_zip_reader_locate_file -#define mz_zip_reader_file_stat udComp_mz_zip_reader_file_stat +#define mz_zip_reader_end udComp_mz_zip_reader_end +#define mz_zip_reader_init_mem udComp_mz_zip_reader_init_mem +#define mz_zip_reader_locate_file udComp_mz_zip_reader_locate_file +#define mz_zip_reader_file_stat udComp_mz_zip_reader_file_stat #define MINIZ_NO_STDIO #define MINIZ_NO_TIME //#define MINIZ_NO_MALLOC Removed because the PNG creator requires malloc #if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable:4334) +# pragma warning(push) +# pragma warning(disable : 4334) #else -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wstrict-aliasing" -# if __GNUC__ >= 6 && !defined(__clang_major__) -# pragma GCC diagnostic ignored "-Wmisleading-indentation" -# endif +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wstrict-aliasing" +# if __GNUC__ >= 6 && !defined(__clang_major__) +# pragma GCC diagnostic ignored "-Wmisleading-indentation" +# endif #endif #include "miniz/miniz.c" #if defined(_MSC_VER) -# pragma warning(pop) +# pragma warning(pop) #else -# pragma GCC diagnostic pop +# pragma GCC diagnostic pop #endif struct udFile_Zip : public udFile { mz_zip_archive mz; - udFile * volatile pZipFile; + udFile *volatile pZipFile; uint8_t *pFileData; int index; // Index within the zip of the current file std::atomic lengthRead; @@ -364,7 +369,7 @@ static udResult udFileHandler_MiniZClose(udFile **ppFile) { AbortRead(pZip); udFile *pZipFile = pZip->pZipFile; - if (pZipFile && udInterlockedCompareExchangePointer((void**)&pZip->pZipFile, nullptr, pZipFile) == pZipFile) + if (pZipFile && udInterlockedCompareExchangePointer((void **)&pZip->pZipFile, nullptr, pZipFile) == pZipFile) udFile_Close(&pZipFile); udDestroyRWLock(&pZip->pRWLock); mz_zip_reader_end(&pZip->mz); @@ -378,7 +383,11 @@ static udResult udFileHandler_MiniZClose(udFile **ppFile) static void *udMiniZ_Alloc(void * /*pOpaque*/, size_t items, size_t size) { return udAlloc(items * size); } static void *udMiniZ_Realloc(void * /*pOpaque*/, void *address, size_t items, size_t size) { return udRealloc(address, items * size); } static void udMiniZ_Free(void * /*pOpaque*/, void *address) { udFree(address); } -static size_t udMiniZ_Read(void *pOpaque, mz_uint64 fileOffset, void *pBuf, size_t n) { udFile_Read(((udFile_Zip*)pOpaque)->pZipFile, pBuf, n, fileOffset, udFSW_SeekSet, &n); return n; } +static size_t udMiniZ_Read(void *pOpaque, mz_uint64 fileOffset, void *pBuf, size_t n) +{ + udFile_Read(((udFile_Zip *)pOpaque)->pZipFile, pBuf, n, fileOffset, udFSW_SeekSet, &n); + return n; +} // ---------------------------------------------------------------------------- // Author: Dave Pevreal, October 2018 @@ -517,12 +526,12 @@ udResult udFileHandler_MiniZOpen(udFile **ppFile, const char *pFilename, udFileO pZipName = udStrdup(pFilename + 6); // Skip zip:// // Find a colon, but importantly, AFTER a folder delimiter if one exists (to exclude drive letters / protocols such as raw://) pFolderDelim = udStrchr(pZipName, "/\\"); - pSubFilename = (char*)udStrrchr(pFolderDelim ? pFolderDelim : pZipName, ":"); + pSubFilename = (char *)udStrrchr(pFolderDelim ? pFolderDelim : pZipName, ":"); if (pSubFilename) *pSubFilename++ = 0; // Skip and null the colon // Now open the underlying zip file - UD_ERROR_CHECK(udFile_Open((udFile**)&pFile->pZipFile, pZipName, udFOF_Read, &zipLen)); + UD_ERROR_CHECK(udFile_Open((udFile **)&pFile->pZipFile, pZipName, udFOF_Read, &zipLen)); // Initialise the zip reader UD_ERROR_IF(!mz_zip_reader_init(&pFile->mz, (mz_uint64)zipLen, 0), udR_OpenFailure); @@ -573,7 +582,7 @@ udResult udFileHandler_MiniZOpen(udFile **ppFile, const char *pFilename, udFileO if (pFile) { mz_zip_reader_end(&pFile->mz); - udFileHandler_MiniZClose((udFile**)&pFile); + udFileHandler_MiniZClose((udFile **)&pFile); } udFree(pZipName); return result; diff --git a/Source/udCrc.cpp b/Source/udCrc.cpp index 534593f1..e9b158f8 100644 --- a/Source/udCrc.cpp +++ b/Source/udCrc.cpp @@ -1,50 +1,49 @@ #include "udPlatformUtil.h" -static uint32_t crc32_table[] = -{ /* CRC polynomial 0xedb88320 */ - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +static uint32_t crc32_table[] = { /* CRC polynomial 0xedb88320 */ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; uint32_t crc32s_table[256] = { @@ -93,7 +92,6 @@ uint32_t crc32s_table[256] = { 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351 }; - // **************************************************************************** // Author: Dave Pevreal, July 2018 uint32_t udCrc(const void *pBuffer, size_t length, uint32_t updateCrc) @@ -101,7 +99,7 @@ uint32_t udCrc(const void *pBuffer, size_t length, uint32_t updateCrc) updateCrc = ~updateCrc; for (size_t i = 0; i < length; ++i) { - uint8_t octet = ((const uint8_t*)pBuffer)[i]; + uint8_t octet = ((const uint8_t *)pBuffer)[i]; updateCrc = crc32_table[(updateCrc ^ octet) & 0xff] ^ (updateCrc >> 8); } return ~updateCrc; @@ -114,7 +112,7 @@ uint32_t udCrc32c(const void *pBuffer, size_t length, uint32_t updateCrc) updateCrc = ~updateCrc; for (size_t i = 0; i < length; ++i) { - uint8_t octet = ((const uint8_t*)pBuffer)[i]; + uint8_t octet = ((const uint8_t *)pBuffer)[i]; updateCrc = crc32s_table[(updateCrc ^ octet) & 0xff] ^ (updateCrc >> 8); } return ~updateCrc; diff --git a/Source/udCrypto.cpp b/Source/udCrypto.cpp index 49e3198f..bc12e02f 100644 --- a/Source/udCrypto.cpp +++ b/Source/udCrypto.cpp @@ -1,22 +1,22 @@ // Include any system headers that any files that are also included by code inside the namespace wrap -#include -#include -#include -#include #include "udCrypto.h" #include "udJSON.h" -#include "udThread.h" #include "udPlatformUtil.h" #include "udStringUtil.h" +#include "udThread.h" +#include +#include +#include +#include #if UDPLATFORM_WINDOWS -#pragma warning(disable: 4267 4244) +# pragma warning(disable : 4267 4244) #else -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include #endif #define MBEDTLS_ALLOW_PRIVATE_ACCESS @@ -24,18 +24,18 @@ #include "mbedtls/platform_util.h" #include "mbedtls/aes.h" +#include "mbedtls/md5.h" #include "mbedtls/sha1.h" #include "mbedtls/sha256.h" #include "mbedtls/sha512.h" -#include "mbedtls/md5.h" #include "mbedtls/dhm.h" #include "mbedtls/ecdh.h" -#include "mbedtls/rsa.h" +#include "mbedtls/ctr_drbg.h" #include "mbedtls/ecdsa.h" #include "mbedtls/entropy.h" -#include "mbedtls/ctr_drbg.h" +#include "mbedtls/rsa.h" #include "mbedtls/threading_alt.h" enum @@ -43,13 +43,13 @@ enum AES_BLOCK_SIZE = 16 }; -#define TYPESTRING_RSA "RSA" +#define TYPESTRING_RSA "RSA" #define TYPESTRING_ECDSA "ECDSA" #define TYPESTRING_CURVE_BP384R1 "BP384R1" const mbedtls_md_type_t udc_to_mbed_hashfunctions[] = { MBEDTLS_MD_SHA1, MBEDTLS_MD_SHA256, MBEDTLS_MD_SHA512, MBEDTLS_MD_MD5, MBEDTLS_MD_NONE }; -UDCOMPILEASSERT(UDARRAYSIZE(udc_to_mbed_hashfunctions) == udCH_Count+1, "Hash methods array not updated as well!"); +UDCOMPILEASSERT(UDARRAYSIZE(udc_to_mbed_hashfunctions) == udCH_Count + 1, "Hash methods array not updated as well!"); struct udCryptoCipherContext { @@ -145,7 +145,7 @@ static udResult FromString(mbedtls_mpi *pBigNum, const char *pBase64) static udResult FromLittleEndianBinary(mbedtls_mpi *pBigNum, uint8_t *&pBuf, size_t &bufLen, int numLen) { udResult result; - uint8_t buf[4096/8]; + uint8_t buf[4096 / 8]; UD_ERROR_IF(numLen > (int)sizeof(buf), udR_InternalError); UD_ERROR_IF(numLen < 0 || (size_t)numLen > bufLen, udR_InternalError); @@ -172,7 +172,7 @@ void udCrypto_Obscure(const char *pBase64String) { size_t len = udStrlen(pBase64String); for (size_t i = 0; i < len; ++i) - const_cast(pBase64String)[i] ^= (i & 5) + 1; // For now simple xor obscure + const_cast(pBase64String)[i] ^= (i & 5) + 1; // For now simple xor obscure } // *************************************************************************************** @@ -188,9 +188,9 @@ udResult udCrypto_Random(void *pMem, size_t len) UD_ERROR_IF(!udCryptoSharedData::initialised, udR_NotInitialized); // Seed the random number generator - UD_ERROR_IF(mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char*)__FUNCTION__, sizeof(__FUNCTION__)) != 0, udR_InternalCryptoError); + UD_ERROR_IF(mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *)__FUNCTION__, sizeof(__FUNCTION__)) != 0, udR_InternalCryptoError); // Generate some random data - UD_ERROR_IF(mbedtls_ctr_drbg_random(&ctr_drbg, (unsigned char*)pMem, len) != 0, udR_InternalCryptoError); + UD_ERROR_IF(mbedtls_ctr_drbg_random(&ctr_drbg, (unsigned char *)pMem, len) != 0, udR_InternalCryptoError); result = udR_Success; @@ -211,7 +211,7 @@ void udCrypto_ThreadingMutexInit(mbedtls_threading_mutex_t *pMutexCtx) // Author: Paul Fox, October 2018 void udCrypto_ThreadingMutexFree(mbedtls_threading_mutex_t *pMutexCtx) { - udDestroyMutex((udMutex**)&pMutexCtx->pMutex); + udDestroyMutex((udMutex **)&pMutexCtx->pMutex); } // *************************************************************************************** @@ -221,7 +221,7 @@ int udCrypto_ThreadingMutexLock(mbedtls_threading_mutex_t *pMutexCtx) if (pMutexCtx == nullptr || pMutexCtx->pMutex == nullptr) return -1; - udLockMutex((udMutex*)pMutexCtx->pMutex); + udLockMutex((udMutex *)pMutexCtx->pMutex); return 0; } @@ -232,7 +232,7 @@ int udCrypto_ThreadingMutexUnlock(mbedtls_threading_mutex_t *pMutexCtx) if (pMutexCtx == nullptr || pMutexCtx->pMutex == nullptr) return -1; - udReleaseMutex((udMutex*)pMutexCtx->pMutex); + udReleaseMutex((udMutex *)pMutexCtx->pMutex); return 0; } @@ -355,7 +355,7 @@ udResult udCryptoCipher_Encrypt(udCryptoCipherContext *pCtx, const udCryptoIV *p else paddedCliperTextLen = (plainTextLen + pCtx->blockSize) & ~(pCtx->blockSize - 1); - UD_ERROR_IF((paddedCliperTextLen & (pCtx->blockSize - 1)) != 0, udR_AlignmentRequired); + UD_ERROR_IF((paddedCliperTextLen & (pCtx->blockSize - 1)) != 0, udR_AlignmentRequired); UD_ERROR_IF(paddedCliperTextLen > cipherTextLen, udR_BufferTooSmall); // Trading efficiency for simplicity, just duplicate the source and add the padding bytes @@ -363,7 +363,7 @@ udResult udCryptoCipher_Encrypt(udCryptoCipherContext *pCtx, const udCryptoIV *p { size_t padBytes = paddedCliperTextLen - plainTextLen; pPaddedPlainText = udMemDup(pPlainText, plainTextLen, padBytes, udAF_None); - memset(udAddBytes((void*)pPaddedPlainText, plainTextLen), (int)padBytes, padBytes); + memset(udAddBytes((void *)pPaddedPlainText, plainTextLen), (int)padBytes, padBytes); } else { @@ -374,34 +374,34 @@ udResult udCryptoCipher_Encrypt(udCryptoCipherContext *pCtx, const udCryptoIV *p { case udCC_AES128: case udCC_AES256: + { + switch (pCtx->chainMode) { - switch (pCtx->chainMode) - { - case udCCM_CBC: - UD_ERROR_NULL(pIV, udR_InvalidParameter); - memcpy(pCtx->iv, pIV, sizeof(pCtx->iv)); - UD_ERROR_IF(mbedtls_aes_crypt_cbc(&pCtx->ctx, MBEDTLS_AES_ENCRYPT, paddedCliperTextLen, pCtx->iv, (const unsigned char*)pPaddedPlainText, (unsigned char*)pCipherText) != 0, udR_InternalCryptoError); - - // For CBC, the output IV is the last encrypted block - if (pOutIV) - memcpy(pOutIV, (char*)pCipherText + paddedCliperTextLen - AES_BLOCK_SIZE, AES_BLOCK_SIZE); - break; - - case udCCM_CTR: - UD_ERROR_IF(pIV == nullptr || pOutIV != nullptr, udR_InvalidParameter); // Don't allow output IV in CTR mode (yet) - memcpy(pCtx->iv, pIV, sizeof(pCtx->iv)); - { - size_t ncoff = 0; - unsigned char stream_block[16]; - UD_ERROR_IF(mbedtls_aes_crypt_ctr(&pCtx->ctx, paddedCliperTextLen, &ncoff, pCtx->iv, stream_block, (const unsigned char*)pPaddedPlainText, (unsigned char *)pCipherText) != 0, udR_InternalCryptoError); - } - break; + case udCCM_CBC: + UD_ERROR_NULL(pIV, udR_InvalidParameter); + memcpy(pCtx->iv, pIV, sizeof(pCtx->iv)); + UD_ERROR_IF(mbedtls_aes_crypt_cbc(&pCtx->ctx, MBEDTLS_AES_ENCRYPT, paddedCliperTextLen, pCtx->iv, (const unsigned char *)pPaddedPlainText, (unsigned char *)pCipherText) != 0, udR_InternalCryptoError); - default: - UD_ERROR_SET(udR_InvalidConfiguration); - } + // For CBC, the output IV is the last encrypted block + if (pOutIV) + memcpy(pOutIV, (char *)pCipherText + paddedCliperTextLen - AES_BLOCK_SIZE, AES_BLOCK_SIZE); + break; + + case udCCM_CTR: + UD_ERROR_IF(pIV == nullptr || pOutIV != nullptr, udR_InvalidParameter); // Don't allow output IV in CTR mode (yet) + memcpy(pCtx->iv, pIV, sizeof(pCtx->iv)); + { + size_t ncoff = 0; + unsigned char stream_block[16]; + UD_ERROR_IF(mbedtls_aes_crypt_ctr(&pCtx->ctx, paddedCliperTextLen, &ncoff, pCtx->iv, stream_block, (const unsigned char *)pPaddedPlainText, (unsigned char *)pCipherText) != 0, udR_InternalCryptoError); + } + break; + + default: + UD_ERROR_SET(udR_InvalidConfiguration); } - break; + } + break; default: UD_ERROR_SET(udR_InvalidConfiguration); } @@ -453,7 +453,7 @@ udResult udCryptoCipher_Decrypt(udCryptoCipherContext *pCtx, const udCryptoIV *p pCtx->ctxInit = true; } memcpy(pCtx->iv, pIV, sizeof(pCtx->iv)); - UD_ERROR_IF(mbedtls_aes_crypt_cbc(&pCtx->ctx, MBEDTLS_AES_DECRYPT, cipherTextLen, pCtx->iv, (const unsigned char*)pCipherText, (unsigned char *)pPaddedPlainText) != 0, udR_InternalCryptoError); + UD_ERROR_IF(mbedtls_aes_crypt_cbc(&pCtx->ctx, MBEDTLS_AES_DECRYPT, cipherTextLen, pCtx->iv, (const unsigned char *)pCipherText, (unsigned char *)pPaddedPlainText) != 0, udR_InternalCryptoError); if (pOutIV) memcpy(pOutIV, pCtx->iv, sizeof(pCtx->iv)); break; @@ -469,7 +469,7 @@ udResult udCryptoCipher_Decrypt(udCryptoCipherContext *pCtx, const udCryptoIV *p { size_t ncoff = 0; unsigned char stream_block[16]; - if (mbedtls_aes_crypt_ctr(&pCtx->ctx, cipherTextLen, &ncoff, pCtx->iv, stream_block, (const unsigned char*)pCipherText, (unsigned char *)pPaddedPlainText) != 0) + if (mbedtls_aes_crypt_ctr(&pCtx->ctx, cipherTextLen, &ncoff, pCtx->iv, stream_block, (const unsigned char *)pCipherText, (unsigned char *)pPaddedPlainText) != 0) { UD_ERROR_SET(udR_Failure); } @@ -481,8 +481,8 @@ udResult udCryptoCipher_Decrypt(udCryptoCipherContext *pCtx, const udCryptoIV *p } } break; - default: - UD_ERROR_SET(udR_InvalidConfiguration); + default: + UD_ERROR_SET(udR_InvalidConfiguration); } if (pCtx->padMode == udCPM_None) { @@ -490,11 +490,11 @@ udResult udCryptoCipher_Decrypt(udCryptoCipherContext *pCtx, const udCryptoIV *p } else { - uint8_t padBytes = ((uint8_t*)pPaddedPlainText)[cipherTextLen - 1]; + uint8_t padBytes = ((uint8_t *)pPaddedPlainText)[cipherTextLen - 1]; actualPlainTextLen = cipherTextLen - padBytes; // Part of PKCS#7 is the padding must be verified for (uint8_t i = 0; i < padBytes; ++i) - UD_ERROR_IF(((uint8_t*)pPaddedPlainText)[actualPlainTextLen + i] != padBytes, udR_CorruptData); + UD_ERROR_IF(((uint8_t *)pPaddedPlainText)[actualPlainTextLen + i] != padBytes, udR_CorruptData); if (pPaddedPlainText != pPlainText) memcpy(pPlainText, pPaddedPlainText, actualPlainTextLen); } @@ -530,50 +530,44 @@ udResult udCryptoCipher_SelfTest(udCryptoCiphers cipher) const char *pKey = nullptr; static const size_t keyLengths[udCC_Count] = { udCCKL_AES128KeyLength, udCCKL_AES256KeyLength }; static const char *pPlainText = "There are two great days in every person's life; the day we are born and the day we discover why"; // Multiple of 16 characters - static const udCryptoIV iv = { { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f } }; - static const uint64_t nonce = 0xf7f6f5f4f3f2f1f0ULL; // Note the nonce is little endian for udCrypto + static const udCryptoIV iv = { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f } }; + static const uint64_t nonce = 0xf7f6f5f4f3f2f1f0ULL; // Note the nonce is little endian for udCrypto static const uint64_t counter = 0xf8f9fafbfcfdfeffULL; // The counter is big endian, because standards dictate that it is - static const uint8_t cipherTextCBC[udCC_Count][96] = - { + static const uint8_t cipherTextCBC[udCC_Count][96] = { // AES128-CBC { - 0xe6,0x57,0x9a,0x39,0x2a,0x37,0xc7,0xed,0x29,0x27,0x25,0xfb,0xff,0xae,0x2d,0x58, - 0xcd,0xef,0x10,0xc2,0x56,0x95,0xe8,0x22,0xa0,0xc4,0x05,0xd8,0x2c,0x26,0x30,0x83, - 0xec,0x31,0xca,0x81,0x2a,0xe8,0xde,0x51,0x16,0xce,0xeb,0x48,0x78,0x3e,0x69,0x2c, - 0x3c,0xa2,0x00,0x7c,0x65,0x64,0x05,0x12,0x13,0xde,0xa9,0x69,0x6c,0x17,0x16,0x1e, - 0xf7,0xe6,0x62,0x50,0x96,0x87,0x4b,0x6f,0x80,0xb8,0x97,0x22,0x77,0xec,0xfd,0xa7, - 0x7a,0xaa,0x6a,0x6e,0x3b,0xbf,0xf2,0x1f,0x70,0x19,0x99,0x0b,0x1a,0x32,0xf9,0xa8 - }, + 0xe6, 0x57, 0x9a, 0x39, 0x2a, 0x37, 0xc7, 0xed, 0x29, 0x27, 0x25, 0xfb, 0xff, 0xae, 0x2d, 0x58, + 0xcd, 0xef, 0x10, 0xc2, 0x56, 0x95, 0xe8, 0x22, 0xa0, 0xc4, 0x05, 0xd8, 0x2c, 0x26, 0x30, 0x83, + 0xec, 0x31, 0xca, 0x81, 0x2a, 0xe8, 0xde, 0x51, 0x16, 0xce, 0xeb, 0x48, 0x78, 0x3e, 0x69, 0x2c, + 0x3c, 0xa2, 0x00, 0x7c, 0x65, 0x64, 0x05, 0x12, 0x13, 0xde, 0xa9, 0x69, 0x6c, 0x17, 0x16, 0x1e, + 0xf7, 0xe6, 0x62, 0x50, 0x96, 0x87, 0x4b, 0x6f, 0x80, 0xb8, 0x97, 0x22, 0x77, 0xec, 0xfd, 0xa7, + 0x7a, 0xaa, 0x6a, 0x6e, 0x3b, 0xbf, 0xf2, 0x1f, 0x70, 0x19, 0x99, 0x0b, 0x1a, 0x32, 0xf9, 0xa8 }, // AES256-CBC { - 0xb8,0x89,0xea,0xb4,0x22,0x19,0x93,0x4e,0x0c,0x4c,0xa3,0xf9,0x86,0x9a,0xe4,0x9e, - 0x82,0xf7,0x58,0x64,0xcf,0x90,0x14,0x77,0xc1,0xde,0x44,0x49,0xa4,0x4a,0xbd,0x31, - 0x63,0xd2,0x80,0x26,0x99,0x0a,0xf3,0xca,0xd9,0x92,0x5f,0x18,0x30,0x6e,0x51,0x02, - 0xc6,0x7c,0x60,0x55,0x5b,0xc4,0x25,0x1b,0xed,0xf8,0x55,0x5c,0x1f,0x8c,0x6a,0xbc, - 0x5c,0xdc,0x94,0xf7,0x83,0x2d,0x7e,0x1f,0xef,0x31,0xd4,0xb2,0xf1,0xfa,0x1e,0xf1, - 0x87,0x8d,0xf1,0xe4,0xee,0xde,0x0e,0x8b,0x6e,0xf0,0xe9,0x8a,0x32,0x02,0x0f,0xad - } + 0xb8, 0x89, 0xea, 0xb4, 0x22, 0x19, 0x93, 0x4e, 0x0c, 0x4c, 0xa3, 0xf9, 0x86, 0x9a, 0xe4, 0x9e, + 0x82, 0xf7, 0x58, 0x64, 0xcf, 0x90, 0x14, 0x77, 0xc1, 0xde, 0x44, 0x49, 0xa4, 0x4a, 0xbd, 0x31, + 0x63, 0xd2, 0x80, 0x26, 0x99, 0x0a, 0xf3, 0xca, 0xd9, 0x92, 0x5f, 0x18, 0x30, 0x6e, 0x51, 0x02, + 0xc6, 0x7c, 0x60, 0x55, 0x5b, 0xc4, 0x25, 0x1b, 0xed, 0xf8, 0x55, 0x5c, 0x1f, 0x8c, 0x6a, 0xbc, + 0x5c, 0xdc, 0x94, 0xf7, 0x83, 0x2d, 0x7e, 0x1f, 0xef, 0x31, 0xd4, 0xb2, 0xf1, 0xfa, 0x1e, 0xf1, + 0x87, 0x8d, 0xf1, 0xe4, 0xee, 0xde, 0x0e, 0x8b, 0x6e, 0xf0, 0xe9, 0x8a, 0x32, 0x02, 0x0f, 0xad } }; - static const uint8_t cipherTextCTR[udCC_Count][96] = - { + static const uint8_t cipherTextCTR[udCC_Count][96] = { // AES128-CTR { - 0x44,0x90,0x81,0x06,0x60,0xf7,0x81,0x74,0x3c,0x1f,0x63,0x77,0x6b,0x7e,0xe5,0xd5, - 0x2c,0x73,0x60,0x99,0x4a,0xbe,0xa8,0xc5,0xa2,0xe4,0xb5,0xc7,0x61,0x43,0x6d,0x86, - 0x6e,0x07,0xa0,0x98,0xfa,0xa9,0x51,0x09,0xf7,0x21,0x78,0x35,0xb6,0x6b,0x7c,0x02, - 0xac,0x70,0x76,0x82,0xdc,0x39,0x1a,0x49,0x72,0xfb,0x0c,0x40,0x76,0x2d,0xac,0xeb, - 0xf9,0x27,0x99,0x9a,0x9c,0x9f,0x51,0xa2,0x3e,0x94,0x53,0xb5,0xf9,0x8d,0xa4,0x87, - 0x0d,0x5d,0x8b,0x67,0xe4,0x81,0xc4,0xed,0x53,0xa1,0x5c,0x92,0x0a,0x46,0xce,0x1d - }, + 0x44, 0x90, 0x81, 0x06, 0x60, 0xf7, 0x81, 0x74, 0x3c, 0x1f, 0x63, 0x77, 0x6b, 0x7e, 0xe5, 0xd5, + 0x2c, 0x73, 0x60, 0x99, 0x4a, 0xbe, 0xa8, 0xc5, 0xa2, 0xe4, 0xb5, 0xc7, 0x61, 0x43, 0x6d, 0x86, + 0x6e, 0x07, 0xa0, 0x98, 0xfa, 0xa9, 0x51, 0x09, 0xf7, 0x21, 0x78, 0x35, 0xb6, 0x6b, 0x7c, 0x02, + 0xac, 0x70, 0x76, 0x82, 0xdc, 0x39, 0x1a, 0x49, 0x72, 0xfb, 0x0c, 0x40, 0x76, 0x2d, 0xac, 0xeb, + 0xf9, 0x27, 0x99, 0x9a, 0x9c, 0x9f, 0x51, 0xa2, 0x3e, 0x94, 0x53, 0xb5, 0xf9, 0x8d, 0xa4, 0x87, + 0x0d, 0x5d, 0x8b, 0x67, 0xe4, 0x81, 0xc4, 0xed, 0x53, 0xa1, 0x5c, 0x92, 0x0a, 0x46, 0xce, 0x1d }, // AES256-CTR { - 0x29,0xd6,0xac,0x22,0x6c,0x2d,0xba,0x7f,0x6a,0xd3,0x94,0x45,0x7a,0x24,0xe9,0x17, - 0x0d,0x4a,0x3d,0xf9,0x5f,0xd9,0xe0,0xd3,0x3a,0x36,0x77,0xb8,0xe2,0x3d,0x84,0xf0, - 0x8a,0x89,0x7c,0x53,0x7b,0x05,0x80,0xf7,0x6f,0x0c,0xbb,0x52,0x9d,0x14,0xba,0x69, - 0xa9,0xf4,0xc2,0xd4,0x72,0x96,0x4a,0x04,0x91,0x35,0x5f,0xa0,0xd6,0x6a,0xcd,0x5c, - 0xf9,0x82,0xb7,0xa4,0x6b,0x02,0xc1,0xbf,0x52,0xb9,0x68,0xe1,0x3f,0xae,0x81,0xac, - 0x36,0x2e,0xc0,0x0e,0x62,0x04,0xe4,0x0e,0x3b,0x1a,0x5f,0x06,0x7b,0x28,0xa4,0x99 - } + 0x29, 0xd6, 0xac, 0x22, 0x6c, 0x2d, 0xba, 0x7f, 0x6a, 0xd3, 0x94, 0x45, 0x7a, 0x24, 0xe9, 0x17, + 0x0d, 0x4a, 0x3d, 0xf9, 0x5f, 0xd9, 0xe0, 0xd3, 0x3a, 0x36, 0x77, 0xb8, 0xe2, 0x3d, 0x84, 0xf0, + 0x8a, 0x89, 0x7c, 0x53, 0x7b, 0x05, 0x80, 0xf7, 0x6f, 0x0c, 0xbb, 0x52, 0x9d, 0x14, 0xba, 0x69, + 0xa9, 0xf4, 0xc2, 0xd4, 0x72, 0x96, 0x4a, 0x04, 0x91, 0x35, 0x5f, 0xa0, 0xd6, 0x6a, 0xcd, 0x5c, + 0xf9, 0x82, 0xb7, 0xa4, 0x6b, 0x02, 0xc1, 0xbf, 0x52, 0xb9, 0x68, 0xe1, 0x3f, 0xae, 0x81, 0xac, + 0x36, 0x2e, 0xc0, 0x0e, 0x62, 0x04, 0xe4, 0x0e, 0x3b, 0x1a, 0x5f, 0x06, 0x7b, 0x28, 0xa4, 0x99 } }; udCryptoIV ctrIV; uint8_t cipherText[128]; @@ -684,16 +678,16 @@ udResult udCryptoHash_Digest(udCryptoHashContext *pCtx, const void *pBytes, size switch (pCtx->hashMethod) { case udCH_SHA1: - mbedtls_sha1_update(&pCtx->sha1, (const uint8_t*)pBytes, length); + mbedtls_sha1_update(&pCtx->sha1, (const uint8_t *)pBytes, length); break; case udCH_SHA256: - mbedtls_sha256_update(&pCtx->sha256, (const uint8_t*)pBytes, length); + mbedtls_sha256_update(&pCtx->sha256, (const uint8_t *)pBytes, length); break; case udCH_SHA512: - mbedtls_sha512_update(&pCtx->sha512, (const uint8_t*)pBytes, length); + mbedtls_sha512_update(&pCtx->sha512, (const uint8_t *)pBytes, length); break; case udCH_MD5: - mbedtls_md5_update(&pCtx->md5, (const uint8_t*)pBytes, length); + mbedtls_md5_update(&pCtx->md5, (const uint8_t *)pBytes, length); break; default: return udR_InvalidParameter; @@ -786,7 +780,10 @@ udResult udCryptoHash_HMAC(udCryptoHashes hash, const char *pKeyBase64, const vo uint8_t *pLongKeyData = nullptr; const char *pLongKeyHashBase64 = nullptr; const char *pIpadHashBase64 = nullptr; - enum { blockSize = 64 }; + enum + { + blockSize = 64 + }; uint8_t key[blockSize]; uint8_t opad[blockSize]; uint8_t ipad[blockSize]; @@ -832,19 +829,17 @@ udResult udCryptoHash_SelfTest(udCryptoHashes hash) static const char *pHmacKeyBase64 = "SmVmZQ=="; // "Jefe" static const char testText[] = { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" }; - static const char *hashResults[] = - { - "hJg+RBw70m66rkqh+VEp5eVGcPE=", // udCH_SHA1 - "JI1qYdIGOLjlwCaTDD5gOaM85Flk/yFn9uzt1BnbBsE=", // udCH_SHA256 + static const char *hashResults[] = { + "hJg+RBw70m66rkqh+VEp5eVGcPE=", // udCH_SHA1 + "JI1qYdIGOLjlwCaTDD5gOaM85Flk/yFn9uzt1BnbBsE=", // udCH_SHA256 "IEqPxt2oLwoM7XvrjgikFlfBbvRosiioJ5vjMacDwzWW/RXBOxsH+aodO+pXeJygMa2Fx6cd1wNU7GMSOMo0RQ==", // udCH_SHA512 - "ghXvB5aiC8qq4RbTh2xmSg==" // udCH_MD5 + "ghXvB5aiC8qq4RbTh2xmSg==" // udCH_MD5 }; - static const char *hmacResults[] = - { - "gNSITHDFNAbgpwcaLiE1yXkDv0k=", // udCH_SHA1 - "3jREzWMffTaJrx7MExnld3wD5ZrpsNXd3QrAWJZkunc=", // udCH_SHA256 + static const char *hmacResults[] = { + "gNSITHDFNAbgpwcaLiE1yXkDv0k=", // udCH_SHA1 + "3jREzWMffTaJrx7MExnld3wD5ZrpsNXd3QrAWJZkunc=", // udCH_SHA256 "GPopoTHOqaFlvz6rC15hyA7z+VfH6v4ok3R2G0ORm5dyctUPGkvxD6Aakbta9JodqZHFKtc4NBIDFvEW+NMkFg==", // udCH_SHA512 - "5NqJxWSrcHlNi4YwIo5+Qg==" // udCH_MD5 + "5NqJxWSrcHlNi4YwIo5+Qg==" // udCH_MD5 }; const char *pResultBase64 = nullptr; @@ -871,11 +866,10 @@ udResult udCrypto_TestHMAC(udCryptoHashes hash) const char *pKeyBase64 = "a2V5"; const char *pMessage = "The quick brown fox jumps over the lazy dog"; const char *pHMACBase64 = nullptr; - static const char *pHMACResults[udCH_Count] = - { - "3nybhbi3iqa8ino29wqQcBydtNk=", // udCH_SHA1 + static const char *pHMACResults[udCH_Count] = { + "3nybhbi3iqa8ino29wqQcBydtNk=", // udCH_SHA1 "97yD9DBThCSxMpjmqm+xQ+9NWaFJRhdZl0edvC0aPNg=", // udCH_SHA256 - nullptr // TODO: Include SHA512 + nullptr // TODO: Include SHA512 }; UD_ERROR_IF(hash < udCH_SHA1 || hash > udCH_SHA256, udR_InvalidParameter); // TODO: Include SHA512 @@ -903,9 +897,9 @@ udResult udCryptoKey_DeriveFromPassword(const char **ppKey, size_t keyLen, const UD_ERROR_IF(!pPassword || !ppKey, udR_InvalidParameter); - // Hash the pass phrase + // Hash the pass phrase UD_ERROR_CHECK(udCryptoHash_Create(&pCtx, udCH_SHA1)); - UD_ERROR_CHECK(udCryptoHash_Digest(pCtx, "ud1971", 6)); // This is a special "salt" for our KDF to make it unique to UD + UD_ERROR_CHECK(udCryptoHash_Digest(pCtx, "ud1971", 6)); // This is a special "salt" for our KDF to make it unique to UD UD_ERROR_CHECK(udCryptoHash_Digest(pCtx, pPassword, strlen(pPassword))); // This is a special "salt" for our KDF to make it unique to UD UD_ERROR_CHECK(udCryptoHash_Finalise(pCtx, &pHashBase64)); UD_ERROR_CHECK(udCryptoHash_Destroy(&pCtx)); @@ -1010,14 +1004,14 @@ udResult udCryptoDHMContext::Init(size_t keyLength) mbedtls_ctr_drbg_init(&ctr_drbg); mbedtls_entropy_init(&entropy); - #define MBEDTLS_DHM_RFC5114_MODP_2048_P "AD107E1E9123A9D0D660FAA79559C51FA20D64E5683B9FD1B54B1597B61D0A75E6FA141DF95A56DBAF9A3C407BA1DF15EB3D688A309C180E1DE6B85A1274A0A66D3F8152AD6AC2129037C9EDEFDA4DF8D91E8FEF55B7394B7AD5B7D0B6C12207C9F98D11ED34DBF6C6BA0B2C8BBC27BE6A00E0A0B9C49708B3BF8A317091883681286130BC8985DB1602E714415D9330278273C7DE31EFDC7310F7121FD5A07415987D9ADC0A486DCDF93ACC44328387315D75E198C641A480CD86A1B9E587E8BE60E69CC928B2B9C52172E413042E9B23F10B0E16E79763C9B53DCF4BA80A29E3FB73C16B8E75B97EF363E2FFA31F71CF9DE5384E71B81C0AC4DFFE0C10E64F" - #define MBEDTLS_DHM_RFC5114_MODP_2048_G "AC4032EF4F2D9AE39DF30B5C8FFDAC506CDEBE7B89998CAF74866A08CFE4FFE3A6824A4E10B9A6F0DD921F01A70C4AFAAB739D7700C29F52C57DB17C620A8652BE5E9001A8D66AD7C17669101999024AF4D027275AC1348BB8A762D0521BC98AE247150422EA1ED409939D54DA7460CDB5F6C6B250717CBEF180EB34118E98D119529A45D6F834566E3025E316A330EFBB77A86F0C1AB15B051AE3D428C8F8ACB70A8137150B8EEB10E183EDD19963DDD9E263E4770589EF6AA21E7F5F2FF381B539CCE3409D13CD566AFBB48D6C019181E1BCFE94B30269EDFE72FE9B6AA4BD7B5A0F1C71CFFF4C19C418E1F6EC017981BC087F2A7065B384B890D3191F2BFA" +#define MBEDTLS_DHM_RFC5114_MODP_2048_P "AD107E1E9123A9D0D660FAA79559C51FA20D64E5683B9FD1B54B1597B61D0A75E6FA141DF95A56DBAF9A3C407BA1DF15EB3D688A309C180E1DE6B85A1274A0A66D3F8152AD6AC2129037C9EDEFDA4DF8D91E8FEF55B7394B7AD5B7D0B6C12207C9F98D11ED34DBF6C6BA0B2C8BBC27BE6A00E0A0B9C49708B3BF8A317091883681286130BC8985DB1602E714415D9330278273C7DE31EFDC7310F7121FD5A07415987D9ADC0A486DCDF93ACC44328387315D75E198C641A480CD86A1B9E587E8BE60E69CC928B2B9C52172E413042E9B23F10B0E16E79763C9B53DCF4BA80A29E3FB73C16B8E75B97EF363E2FFA31F71CF9DE5384E71B81C0AC4DFFE0C10E64F" +#define MBEDTLS_DHM_RFC5114_MODP_2048_G "AC4032EF4F2D9AE39DF30B5C8FFDAC506CDEBE7B89998CAF74866A08CFE4FFE3A6824A4E10B9A6F0DD921F01A70C4AFAAB739D7700C29F52C57DB17C620A8652BE5E9001A8D66AD7C17669101999024AF4D027275AC1348BB8A762D0521BC98AE247150422EA1ED409939D54DA7460CDB5F6C6B250717CBEF180EB34118E98D119529A45D6F834566E3025E316A330EFBB77A86F0C1AB15B051AE3D428C8F8ACB70A8137150B8EEB10E183EDD19963DDD9E263E4770589EF6AA21E7F5F2FF381B539CCE3409D13CD566AFBB48D6C019181E1BCFE94B30269EDFE72FE9B6AA4BD7B5A0F1C71CFFF4C19C418E1F6EC017981BC087F2A7065B384B890D3191F2BFA" mbedtls_dhm_init(&dhm); mbedtls_mpi_read_string(&dhm.P, 16, MBEDTLS_DHM_RFC5114_MODP_2048_P); mbedtls_mpi_read_string(&dhm.G, 16, MBEDTLS_DHM_RFC5114_MODP_2048_G); - mbErr = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char*)__FUNCTION__, sizeof(__FUNCTION__)); + mbErr = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *)__FUNCTION__, sizeof(__FUNCTION__)); UD_ERROR_IF(mbErr, udR_InternalCryptoError); // Generate random parameters to suit the P and G already defined, these are output to tempBuf @@ -1151,7 +1145,6 @@ void udCryptoKey_DestroyDHM(udCryptoDHMContext **ppDHMCtx) } } - struct udCryptoECDHContext { mbedtls_ecdh_context ecdh; @@ -1159,7 +1152,6 @@ struct udCryptoECDHContext mbedtls_entropy_context entropy; }; - // *************************************************************************************** // Author: Paul Fox, October 2021 udResult udCryptoKeyECDH_CreateContextPartyA(udCryptoECDHContext **ppECDHCtx, const char **ppPublicValueA) @@ -1185,7 +1177,7 @@ udResult udCryptoKeyECDH_CreateContextPartyA(udCryptoECDHContext **ppECDHCtx, co mbedtls_ecdh_init(&pCtx->ecdh); mbedtls_ecdh_setup(&pCtx->ecdh, MBEDTLS_ECP_DP_BP384R1); - UD_ERROR_IF(mbedtls_ctr_drbg_seed(&pCtx->ctr_drbg, mbedtls_entropy_func, &pCtx->entropy, (const unsigned char*)__FUNCTION__, sizeof(__FUNCTION__)) != 0, udR_InternalCryptoError); + UD_ERROR_IF(mbedtls_ctr_drbg_seed(&pCtx->ctr_drbg, mbedtls_entropy_func, &pCtx->entropy, (const unsigned char *)__FUNCTION__, sizeof(__FUNCTION__)) != 0, udR_InternalCryptoError); // Write the public key //UD_ERROR_IF(mbedtls_ecdh_make_public(&pCtx->dhm, &len, buf, udLengthOf(buf), mbedtls_ctr_drbg_random, &pCtx->ctr_drbg) != 0, udR_InternalCryptoError); @@ -1232,12 +1224,12 @@ udResult udCryptoKeyECDH_DeriveFromPartyA(const char *pPublicValueA, const char mbedtls_ecdh_init(&pCtx->ecdh); - UD_ERROR_IF(mbedtls_ctr_drbg_seed(&pCtx->ctr_drbg, mbedtls_entropy_func, &pCtx->entropy, (const unsigned char*)__FUNCTION__, sizeof(__FUNCTION__)) != 0, udR_InternalCryptoError); + UD_ERROR_IF(mbedtls_ctr_drbg_seed(&pCtx->ctr_drbg, mbedtls_entropy_func, &pCtx->entropy, (const unsigned char *)__FUNCTION__, sizeof(__FUNCTION__)) != 0, udR_InternalCryptoError); UD_ERROR_CHECK(udBase64Decode(pPublicValueA, udStrlen(pPublicValueA), buf, udLengthOf(buf), &written)); // Read party A's public key - UD_ERROR_IF(mbedtls_ecdh_read_params(&pCtx->ecdh, &pBuf, pBuf+written) != 0, udR_InternalCryptoError); + UD_ERROR_IF(mbedtls_ecdh_read_params(&pCtx->ecdh, &pBuf, pBuf + written) != 0, udR_InternalCryptoError); memset(buf, 0x00, sizeof(buf)); // Write the public key for Party B @@ -1319,7 +1311,7 @@ udResult udCryptoSig_CreateKeyPair(udCryptoSigContext **ppSigCtx, udCryptoSigTyp pSigCtx->type = type; // Seed the DRGB and add this function name as an optional personalisation string - mbErr = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char*)__FUNCTION__, sizeof(__FUNCTION__)); + mbErr = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *)__FUNCTION__, sizeof(__FUNCTION__)); UD_ERROR_IF(mbErr, udR_InternalCryptoError); switch (type) @@ -1370,7 +1362,7 @@ udResult udCryptoSig_ExportKeyPair(udCryptoSigContext *pSigCtx, const char **ppK case udCST_RSA1024: case udCST_RSA2048: case udCST_RSA4096: - v.Set("Type = '%s'", TYPESTRING_RSA); + v.Set("Type = '%s'", TYPESTRING_RSA); v.Set("Size = %d", pSigCtx->type); UD_ERROR_CHECK(ToValue(pSigCtx->rsa.N, &v, "N")); UD_ERROR_CHECK(ToValue(pSigCtx->rsa.E, &v, "E")); @@ -1384,15 +1376,15 @@ udResult udCryptoSig_ExportKeyPair(udCryptoSigContext *pSigCtx, const char **ppK UD_ERROR_CHECK(ToValue(pSigCtx->rsa.QP, &v, "QP")); } break; - case udCST_ECPBP384: - v.Set("Type = '%s'", TYPESTRING_ECDSA); - v.Set("Curve = '%s'", TYPESTRING_CURVE_BP384R1); - UD_ERROR_CHECK(ToValue(pSigCtx->ecdsa.Q.X, &v, "X")); - UD_ERROR_CHECK(ToValue(pSigCtx->ecdsa.Q.Y, &v, "Y")); - UD_ERROR_CHECK(ToValue(pSigCtx->ecdsa.Q.Z, &v, "Z")); - if (exportPrivate) - UD_ERROR_CHECK(ToValue(pSigCtx->ecdsa.d, &v, "D")); - break; + case udCST_ECPBP384: + v.Set("Type = '%s'", TYPESTRING_ECDSA); + v.Set("Curve = '%s'", TYPESTRING_CURVE_BP384R1); + UD_ERROR_CHECK(ToValue(pSigCtx->ecdsa.Q.X, &v, "X")); + UD_ERROR_CHECK(ToValue(pSigCtx->ecdsa.Q.Y, &v, "Y")); + UD_ERROR_CHECK(ToValue(pSigCtx->ecdsa.Q.Z, &v, "Z")); + if (exportPrivate) + UD_ERROR_CHECK(ToValue(pSigCtx->ecdsa.d, &v, "D")); + break; default: UD_ERROR_SET(udR_InvalidConfiguration); } @@ -1496,8 +1488,8 @@ udResult udCryptoSig_ImportMSBlob(udCryptoSigContext **ppSigCtx, void *pBlob, si int32_t magic; int32_t bitLen; }; - MSBlob *pPriv = (MSBlob*)pBlob; - uint8_t *p = (uint8_t*)(pPriv+1); + MSBlob *pPriv = (MSBlob *)pBlob; + uint8_t *p = (uint8_t *)(pPriv + 1); udResult result; udJSON v; @@ -1515,17 +1507,17 @@ udResult udCryptoSig_ImportMSBlob(udCryptoSigContext **ppSigCtx, void *pBlob, si mbedtls_rsa_init(&pSigCtx->rsa); pSigCtx->rsa.len = pSigCtx->type / 8; // Size of the key - UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.E, p, blobLen, 4)); - UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.N, p, blobLen, pPriv->bitLen / 8)); + UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.E, p, blobLen, 4)); + UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.N, p, blobLen, pPriv->bitLen / 8)); UD_ERROR_IF(mbedtls_rsa_check_pubkey(&pSigCtx->rsa) != 0, udR_InternalCryptoError); if (pPriv->type == 7) { - UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.P, p, blobLen, pPriv->bitLen / 16)); - UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.Q, p, blobLen, pPriv->bitLen / 16)); + UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.P, p, blobLen, pPriv->bitLen / 16)); + UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.Q, p, blobLen, pPriv->bitLen / 16)); UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.DP, p, blobLen, pPriv->bitLen / 16)); UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.DQ, p, blobLen, pPriv->bitLen / 16)); UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.QP, p, blobLen, pPriv->bitLen / 16)); // Iq == inv(q % p) - UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.D, p, blobLen, pPriv->bitLen / 8)); + UD_ERROR_CHECK(FromLittleEndianBinary(&pSigCtx->rsa.D, p, blobLen, pPriv->bitLen / 8)); UD_ERROR_IF(mbedtls_rsa_check_privkey(&pSigCtx->rsa) != 0, udR_InternalCryptoError); } @@ -1543,7 +1535,7 @@ udResult udCryptoSig_ImportMSBlob(udCryptoSigContext **ppSigCtx, void *pBlob, si udResult udCryptoSig_Sign(udCryptoSigContext *pSigCtx, const char *pHashBase64, const char **ppSignatureBase64, udCryptoHashes hashMethod, udCryptoSigPadScheme pad) { udResult result = udR_Failure; - unsigned char signature[udCST_RSA4096/8]; + unsigned char signature[udCST_RSA4096 / 8]; unsigned char hash[udCHL_MaxHashLength]; size_t hashLen; size_t sigLen = sizeof(signature); @@ -1561,7 +1553,7 @@ udResult udCryptoSig_Sign(udCryptoSigContext *pSigCtx, const char *pHashBase64, mbedtls_entropy_init(&entropy); // Seed the random number generator - UD_ERROR_IF(mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char*)__FUNCTION__, sizeof(__FUNCTION__)) != 0, udR_InternalCryptoError); + UD_ERROR_IF(mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *)__FUNCTION__, sizeof(__FUNCTION__)) != 0, udR_InternalCryptoError); UD_ERROR_CHECK(udBase64Decode(pHashBase64, 0, hash, sizeof(hash), &hashLen)); @@ -1662,4 +1654,3 @@ void udCryptoSig_Destroy(udCryptoSigContext **ppSigCtx) } } } - diff --git a/Source/udDebug.cpp b/Source/udDebug.cpp index 444099a0..a9b3a5f9 100644 --- a/Source/udDebug.cpp +++ b/Source/udDebug.cpp @@ -1,9 +1,9 @@ #include "udDebug.h" -#include "udStringUtil.h" #include "udPlatformUtil.h" +#include "udStringUtil.h" -#include #include +#include void (*gpudDebugPrintfOutputCallback)(const char *pString) = nullptr; @@ -22,7 +22,7 @@ void udDebugPrintf(const char *format, ...) if (!multiThreads) { - multiThreads = (lastThread!=-1) && (lastThread != udTrace::GetThreadId()); + multiThreads = (lastThread != -1) && (lastThread != udTrace::GetThreadId()); lastThread = udTrace::GetThreadId(); } @@ -33,7 +33,7 @@ void udDebugPrintf(const char *format, ...) } va_start(args, format); - required = udSprintfVA(pBuffer + prefix, bufferLen-prefix, format, args); + required = udSprintfVA(pBuffer + prefix, bufferLen - prefix, format, args); va_end(args); if (required >= (bufferLen - prefix)) { @@ -73,7 +73,7 @@ static std::atomic nextThreadId; // *************************************************************************************** int udTrace::GetThreadId() { - if (threadId==-1) + if (threadId == -1) threadId = nextThreadId++; return threadId; @@ -82,7 +82,7 @@ int udTrace::GetThreadId() // *************************************************************************************** udTrace::udTrace(const char *a_functionName, int traceLevel) { - if (threadId==-1) + if (threadId == -1) { threadId = nextThreadId++; if (traceLevel) @@ -94,7 +94,7 @@ udTrace::udTrace(const char *a_functionName, int traceLevel) entryPrinted = false; if (traceLevel > 1) { - udDebugPrintf("%*.s Entering %s\n", depth*2, "", functionName); + udDebugPrintf("%*.s Entering %s\n", depth * 2, "", functionName); entryPrinted = true; } ++depth; @@ -106,7 +106,7 @@ udTrace::~udTrace() --depth; head = next; if (entryPrinted) - udDebugPrintf("%*.s Exiting %s\n", depth*2, "", functionName); + udDebugPrintf("%*.s Exiting %s\n", depth * 2, "", functionName); } // *************************************************************************************** @@ -132,13 +132,12 @@ void udTrace::Message(const char *pFormat, ...) pParent1 = head->next->next->next->functionName; } } - udDebugPrintf("%*.s Within %s->%s->%s->%s\n", (depth-1)*2, "", pParent2, pParent1, pParent0, head->functionName); + udDebugPrintf("%*.s Within %s->%s->%s->%s\n", (depth - 1) * 2, "", pParent2, pParent1, pParent0, head->functionName); head->entryPrinted = true; } - udDebugPrintf("%*.s %s\n", head ? head->depth*2 : 0, "", buffer); + udDebugPrintf("%*.s %s\n", head ? head->depth * 2 : 0, "", buffer); } - // *************************************************************************************** void udTrace::ShowCallstack() { @@ -162,7 +161,7 @@ void udTrace_Memory(const char *pName, const void *pMem, int length, int line) memcpy(p, pMem, n); format[n * 5] = 0; // nul terminate in the correct spot udTrace::Message(format, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]); - pMem = ((const char*)pMem)+n; + pMem = ((const char *)pMem) + n; length -= n; } } diff --git a/Source/udFile.cpp b/Source/udFile.cpp index c6f647b9..89ee31c0 100644 --- a/Source/udFile.cpp +++ b/Source/udFile.cpp @@ -4,39 +4,38 @@ // Creator: Dave Pevreal, March 2014 // +#include "udCrypto.h" #include "udFileHandler.h" #include "udPlatformUtil.h" #include "udStringUtil.h" -#include "udCrypto.h" #if UDPLATFORM_UWP -# include +# include #elif UDPLATFORM_WINDOWS -# include +# include #else -# include +# include #endif -#define MAX_HANDLERS 16 +#define MAX_HANDLERS 16 #define CONTENT_LOAD_CHUNK_SIZE 65536 // When loading an entire file of unknown size, read in chunks of this many bytes -udFile_OpenHandlerFunc udFileHandler_FILEOpen; // Default crt FILE based handler -udFile_OpenHandlerFunc udFileHandler_RawOpen; // Default raw handler -udFile_OpenHandlerFunc udFileHandler_MiniZOpen; // Default zip handler -udFile_OpenHandlerFunc udFileHandler_DataOpen; // Default data handler +udFile_OpenHandlerFunc udFileHandler_FILEOpen; // Default crt FILE based handler +udFile_OpenHandlerFunc udFileHandler_RawOpen; // Default raw handler +udFile_OpenHandlerFunc udFileHandler_MiniZOpen; // Default zip handler +udFile_OpenHandlerFunc udFileHandler_DataOpen; // Default data handler struct udFileHandler { udFile_OpenHandlerFunc *fpOpen; - char prefix[16]; // The prefix that this handler will respond to, eg 'http:', or an empty string for regular filenames + char prefix[16]; // The prefix that this handler will respond to, eg 'http:', or an empty string for regular filenames }; -static udFileHandler s_handlers[MAX_HANDLERS] = -{ - { udFileHandler_FILEOpen, "" }, // Default file handler - { udFileHandler_RawOpen, "raw://" }, // Raw handler - { udFileHandler_MiniZOpen, "zip://" }, // Zip handler - { udFileHandler_DataOpen, "data:" }, // Data handler +static udFileHandler s_handlers[MAX_HANDLERS] = { + { udFileHandler_FILEOpen, "" }, // Default file handler + { udFileHandler_RawOpen, "raw://" }, // Raw handler + { udFileHandler_MiniZOpen, "zip://" }, // Zip handler + { udFileHandler_DataOpen, "data:" }, // Data handler }; static int s_handlersCount = 4; @@ -52,7 +51,7 @@ udResult udFile_GenericLoad(udFile *pFile, void **ppMemory, int64_t *pFileLength if (length) { - pMemory = (char*)udAlloc((size_t)length + 1); // Note always allocating 1 extra byte + pMemory = (char *)udAlloc((size_t)length + 1); // Note always allocating 1 extra byte UD_ERROR_CHECK(udFile_Read(pFile, pMemory, (size_t)length, 0, udFSW_SeekCur, &actualRead)); UD_ERROR_IF(actualRead != (size_t)length, udR_ReadFailure); } @@ -67,7 +66,7 @@ udResult udFile_GenericLoad(udFile *pFile, void **ppMemory, int64_t *pFileLength length += CONTENT_LOAD_CHUNK_SIZE; void *pNewMem = udRealloc(pMemory, (size_t)length + 1); // Note always allocating 1 extra byte UD_ERROR_NULL(pNewMem, udR_MemoryAllocationFailure); - pMemory = (char*)pNewMem; + pMemory = (char *)pNewMem; attemptRead = (size_t)length + 1 - alreadyRead; // Note attempt to read 1 extra byte so EOF is detected UD_ERROR_CHECK(udFile_Read(pFile, pMemory + alreadyRead, attemptRead, 0, udFSW_SeekCur, &actualRead)); @@ -78,7 +77,7 @@ udResult udFile_GenericLoad(udFile *pFile, void **ppMemory, int64_t *pFileLength length = alreadyRead; void *pNewMem = udRealloc(pMemory, (size_t)length + 1); UD_ERROR_NULL(pNewMem, udR_MemoryAllocationFailure); - pMemory = (char*)pNewMem; + pMemory = (char *)pNewMem; } } pMemory[length] = 0; // A nul-terminator for text files @@ -122,7 +121,7 @@ udResult udFile_Save(const char *pFilename, const void *pBuffer, size_t length) udResult result; udFile *pFile = nullptr; - UD_ERROR_CHECK(udFile_Open(&pFile, pFilename, udFOF_Create|udFOF_Write)); + UD_ERROR_CHECK(udFile_Open(&pFile, pFilename, udFOF_Create | udFOF_Write)); UD_ERROR_CHECK(udFile_Write(pFile, pBuffer, (size_t)length)); UD_ERROR_CHECK(udFile_Close(&pFile)); // Close errors are important when writing @@ -187,7 +186,7 @@ void udFile_SetSeekBase(udFile *pFile, int64_t seekBase, int64_t newLength) pFile->seekBase = seekBase; if (newLength) pFile->fileLength = newLength; - pFile->filePos = seekBase; // Move the current position to the base in case a udFSW_SeekCur read is issued + pFile->filePos = seekBase; // Move the current position to the base in case a udFSW_SeekCur read is issued } } @@ -256,7 +255,6 @@ udResult udFile_GetPerformance(udFile *pFile, udFilePerformance *pPerformance) return udR_Success; } - // ---------------------------------------------------------------------------- // Author: Dave Pevreal, March 2014 static void udUpdateFilePerformance(udFile *pFile, size_t actualRead) @@ -265,10 +263,9 @@ static void udUpdateFilePerformance(udFile *pFile, size_t actualRead) pFile->msAccumulator += udGetTimeMs(); pFile->totalBytes += actualRead; if (--pFile->requestsInFlight == 0) - pFile->mbPerSec = float((pFile->totalBytes/1048576.0) / (pFile->msAccumulator / 1000.0)); + pFile->mbPerSec = float((pFile->totalBytes / 1048576.0) / (pFile->msAccumulator / 1000.0)); } - // **************************************************************************** // Author: Dave Pevreal, March 2014 udResult udFile_Read(udFile *pFile, void *pBuffer, size_t bufferLength, int64_t seekOffset, udFileSeekWhence seekWhence, size_t *pActualRead, int64_t *pFilePos, udFilePipelinedRequest *pPipelinedRequest) @@ -284,9 +281,15 @@ udResult udFile_Read(udFile *pFile, void *pBuffer, size_t bufferLength, int64_t switch (seekWhence) { - case udFSW_SeekSet: offset = seekOffset + pFile->seekBase; break; - case udFSW_SeekCur: offset = pFile->filePos + seekOffset; break; - case udFSW_SeekEnd: offset = pFile->fileLength + seekOffset + pFile->seekBase; break; + case udFSW_SeekSet: + offset = seekOffset + pFile->seekBase; + break; + case udFSW_SeekCur: + offset = pFile->filePos + seekOffset; + break; + case udFSW_SeekEnd: + offset = pFile->fileLength + seekOffset + pFile->seekBase; + break; default: UD_ERROR_SET(udR_InvalidParameter); } @@ -347,7 +350,6 @@ udResult udFile_Read(udFile *pFile, void *pBuffer, size_t bufferLength, int64_t return result; } - // **************************************************************************** // Author: Dave Pevreal, March 2014 udResult udFile_Write(udFile *pFile, const void *pBuffer, size_t bufferLength, int64_t seekOffset, udFileSeekWhence seekWhence, size_t *pActualWritten, int64_t *pFilePos) @@ -362,11 +364,17 @@ udResult udFile_Write(udFile *pFile, const void *pBuffer, size_t bufferLength, i switch (seekWhence) { - case udFSW_SeekSet: offset = seekOffset + pFile->seekBase; break; - case udFSW_SeekCur: offset = pFile->filePos + seekOffset; break; - case udFSW_SeekEnd: offset = pFile->fileLength + seekOffset; break; - default: - UD_ERROR_SET(udR_InvalidParameter); + case udFSW_SeekSet: + offset = seekOffset + pFile->seekBase; + break; + case udFSW_SeekCur: + offset = pFile->filePos + seekOffset; + break; + case udFSW_SeekEnd: + offset = pFile->fileLength + seekOffset; + break; + default: + UD_ERROR_SET(udR_InvalidParameter); } ++pFile->requestsInFlight; @@ -391,7 +399,6 @@ udResult udFile_Write(udFile *pFile, const void *pBuffer, size_t bufferLength, i return result; } - // **************************************************************************** // Author: Dave Pevreal, March 2014 udResult udFile_BlockForPipelinedRequest(udFile *pFile, udFilePipelinedRequest *pPipelinedRequest, size_t *pActualRead) @@ -428,7 +435,6 @@ udResult udFile_Release(udFile *pFile) return result; } - // **************************************************************************** // Author: Dave Pevreal, March 2014 udResult udFile_Close(udFile **ppFile) @@ -449,7 +455,6 @@ udResult udFile_Close(udFile **ppFile) return udR_Success; // Already closed, no error condition } - // **************************************************************************** // Author: Samuel Surtees, July 2018 udResult udFile_TranslatePath(const char **ppNewPath, const char *pPath) @@ -502,7 +507,6 @@ udResult udFile_TranslatePath(const char **ppNewPath, const char *pPath) return result; } - // **************************************************************************** // Author: Dave Pevreal, March 2014 udResult udFile_RegisterHandler(udFile_OpenHandlerFunc *fpHandler, const char *pPrefix) @@ -516,7 +520,6 @@ udResult udFile_RegisterHandler(udFile_OpenHandlerFunc *fpHandler, const char *p return udR_Success; } - // **************************************************************************** // Author: Dave Pevreal, March 2014 udResult udFile_DeregisterHandler(udFile_OpenHandlerFunc *fpHandler) @@ -535,4 +538,3 @@ udResult udFile_DeregisterHandler(udFile_OpenHandlerFunc *fpHandler) return udR_NotFound; } - diff --git a/Source/udFileHandler_Data.cpp b/Source/udFileHandler_Data.cpp index d9c14f71..ec70e66e 100644 --- a/Source/udFileHandler_Data.cpp +++ b/Source/udFileHandler_Data.cpp @@ -1,15 +1,15 @@ +#include "udCompression.h" #include "udFile.h" #include "udFileHandler.h" +#include "udMath.h" #include "udPlatformUtil.h" #include "udStringUtil.h" -#include "udCompression.h" -#include "udMath.h" // Data URLs support udFile handler // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs -static udFile_SeekReadHandlerFunc udFileHandler_DataSeekRead; -static udFile_CloseHandlerFunc udFileHandler_DataClose; +static udFile_SeekReadHandlerFunc udFileHandler_DataSeekRead; +static udFile_CloseHandlerFunc udFileHandler_DataClose; struct udFile_Data : public udFile { diff --git a/Source/udFileHandler_EmscriptenHTTP.cpp b/Source/udFileHandler_EmscriptenHTTP.cpp index 87488592..7a446135 100644 --- a/Source/udFileHandler_EmscriptenHTTP.cpp +++ b/Source/udFileHandler_EmscriptenHTTP.cpp @@ -9,11 +9,11 @@ // Access-Control-Allow-Headers: Content-Type, Range // Access-Control-Allow-Methods: HEAD, GET, POST, OPTIONS -#include "udPlatformUtil.h" -#include "udStringUtil.h" -#include "udFileHandler.h" -#include "udMath.h" -#include +# include "udFileHandler.h" +# include "udMath.h" +# include "udPlatformUtil.h" +# include "udStringUtil.h" +# include // ---------------------------------------------------------------------------- // Author: Samuel Surtees, November 2018 @@ -102,7 +102,7 @@ udResult udFileHandler_EmscriptenHTTPOpen(udFile **ppFile, const char * /*pFilen emscripten_fetch_close(pFetch); if (pFile) - udFileHandler_EmscriptenHTTPClose((udFile**)&pFile); + udFileHandler_EmscriptenHTTPClose((udFile **)&pFile); return result; } diff --git a/Source/udFileHandler_FILE.cpp b/Source/udFileHandler_FILE.cpp index 6217f526..f2821e11 100644 --- a/Source/udFileHandler_FILE.cpp +++ b/Source/udFileHandler_FILE.cpp @@ -6,56 +6,54 @@ #define _FILE_OFFSET_BITS 64 #if defined(_MSC_VER) -# define _CRT_SECURE_NO_WARNINGS -# define fseeko _fseeki64 -# define ftello _ftelli64 -# if !defined(_OFF_T_DEFINED) - typedef __int64 _off_t; - typedef _off_t off_t; -# define _OFF_T_DEFINED -# endif //_OFF_T_DEFINED +# define _CRT_SECURE_NO_WARNINGS +# define fseeko _fseeki64 +# define ftello _ftelli64 +# if !defined(_OFF_T_DEFINED) +typedef __int64 _off_t; +typedef _off_t off_t; +# define _OFF_T_DEFINED +# endif //_OFF_T_DEFINED #elif defined(__linux__) -# if !defined(_LARGEFILE_SOURCE ) - // This must be set for linux to expose fseeko and ftello -# define _LARGEFILE_SOURCE -#endif +# if !defined(_LARGEFILE_SOURCE) +// This must be set for linux to expose fseeko and ftello +# define _LARGEFILE_SOURCE +# endif #endif - #include "udFile.h" #include "udFileHandler.h" #include "udPlatformUtil.h" #include "udStringUtil.h" +#include #include #include -#include #if UDPLATFORM_NACL -# define fseeko fseek -# define ftello ftell +# define fseeko fseek +# define ftello ftell #endif #define FILE_DEBUG 0 // Declarations of the fall-back standard handler that uses crt FILE as a back-end -static udFile_SeekReadHandlerFunc udFileHandler_FILESeekRead; -static udFile_SeekWriteHandlerFunc udFileHandler_FILESeekWrite; -static udFile_ReleaseHandlerFunc udFileHandler_FILERelease; -static udFile_CloseHandlerFunc udFileHandler_FILEClose; +static udFile_SeekReadHandlerFunc udFileHandler_FILESeekRead; +static udFile_SeekWriteHandlerFunc udFileHandler_FILESeekWrite; +static udFile_ReleaseHandlerFunc udFileHandler_FILERelease; +static udFile_CloseHandlerFunc udFileHandler_FILEClose; std::atomic g_udFileHandler_FILEHandleCount; #if FILE_DEBUG -#pragma optimize("", off) +# pragma optimize("", off) #endif // The udFile derivative for supporting standard runtime library FILE i/o struct udFile_FILE : public udFile { FILE *pCrtFile; - udMutex *pMutex; // Used only when the udFOF_Multithread flag is used to ensure safe access from multiple threads + udMutex *pMutex; // Used only when the udFOF_Multithread flag is used to ensure safe access from multiple threads }; - // ---------------------------------------------------------------------------- static FILE *OpenWithFlags(const char *pFilename, udFileOpenFlags flags) { @@ -63,7 +61,7 @@ static FILE *OpenWithFlags(const char *pFilename, udFileOpenFlags flags) FILE *pFile = nullptr; if ((flags & udFOF_Read) && (flags & udFOF_Write) && (flags & udFOF_Create)) - pMode = "w+b"; // Read/write, any existing file destroyed + pMode = "w+b"; // Read/write, any existing file destroyed else if ((flags & udFOF_Read) && (flags & udFOF_Write)) pMode = "r+b"; // Read/write, but file must already exist else if (flags & udFOF_Read) @@ -168,14 +166,13 @@ udResult udFileHandler_FILEOpen(udFile **ppFile, const char *pFilename, udFileOp return result; } - // ---------------------------------------------------------------------------- // Author: Dave Pevreal, March 2014 // Implementation of SeekReadHandler to access the crt FILE i/o functions static udResult udFileHandler_FILESeekRead(udFile *pFile, void *pBuffer, size_t bufferLength, int64_t seekOffset, size_t *pActualRead, udFilePipelinedRequest * /*pPipelinedRequest*/) { UDTRACE(); - udFile_FILE *pFILE = static_cast(pFile); + udFile_FILE *pFILE = static_cast(pFile); udResult result; size_t actualRead; @@ -210,7 +207,6 @@ static udResult udFileHandler_FILESeekRead(udFile *pFile, void *pBuffer, size_t return result; } - // ---------------------------------------------------------------------------- // Author: Dave Pevreal, March 2014 // Implementation of SeekWriteHandler to access the crt FILE i/o functions @@ -219,7 +215,7 @@ static udResult udFileHandler_FILESeekWrite(udFile *pFile, const void *pBuffer, UDTRACE(); udResult result; size_t actualWritten; - udFile_FILE *pFILE = static_cast(pFile); + udFile_FILE *pFILE = static_cast(pFile); UD_ERROR_NULL(pFile, udR_InvalidParameter); if (pFILE->pMutex) @@ -242,14 +238,13 @@ static udResult udFileHandler_FILESeekWrite(udFile *pFile, const void *pBuffer, return result; } - // ---------------------------------------------------------------------------- // Author: Dave Pevreal, March 2016 // Implementation of Release to release the underlying file handle static udResult udFileHandler_FILERelease(udFile *pFile) { udResult result; - udFile_FILE *pFILE = static_cast(pFile); + udFile_FILE *pFILE = static_cast(pFile); // Early-exit that doesn't involve locking the mutex UD_ERROR_NULL(pFile, udR_InvalidParameter); @@ -263,7 +258,7 @@ static udResult udFileHandler_FILERelease(udFile *pFile) UD_ERROR_IF(!pFILE->pCrtFile, udR_NothingToDo); // Don't support release/reopen on files for create/writing - UD_ERROR_IF(!pFile->pFilenameCopy || (pFile->flagsCopy & (udFOF_Create|udFOF_Write)), udR_InvalidConfiguration); + UD_ERROR_IF(!pFile->pFilenameCopy || (pFile->flagsCopy & (udFOF_Create | udFOF_Write)), udR_InvalidConfiguration); #if FILE_DEBUG udDebugPrintf("Releasing handle for %s (handleCount=%d) pCrtFile=%p\n", pFile->pFilenameCopy, g_udFileHandler_FILEHandleCount, pFILE->pCrtFile); @@ -281,7 +276,6 @@ static udResult udFileHandler_FILERelease(udFile *pFile) return result; } - // ---------------------------------------------------------------------------- // Author: Dave Pevreal, March 2014 // Implementation of CloseHandler to access the crt FILE i/o functions @@ -289,7 +283,7 @@ static udResult udFileHandler_FILEClose(udFile **ppFile) { UDTRACE(); udResult result = udR_Success; - udFile_FILE *pFILE = static_cast(*ppFile); + udFile_FILE *pFILE = static_cast(*ppFile); *ppFile = nullptr; if (pFILE) @@ -308,5 +302,3 @@ static udResult udFileHandler_FILEClose(udFile **ppFile) return result; } - - diff --git a/Source/udFileHandler_HTTP.cpp b/Source/udFileHandler_HTTP.cpp index 2635b14f..dcde6394 100644 --- a/Source/udFileHandler_HTTP.cpp +++ b/Source/udFileHandler_HTTP.cpp @@ -9,15 +9,15 @@ #include "udPlatform.h" #include "udSocket.h" +#include "udFileHandler.h" #include "udPlatformUtil.h" #include "udStringUtil.h" -#include "udFileHandler.h" #if !UDPLATFORM_EMSCRIPTEN -static udFile_OpenHandlerFunc udFileHandler_HTTPOpen; -static udFile_SeekReadHandlerFunc udFileHandler_HTTPSeekRead; +static udFile_OpenHandlerFunc udFileHandler_HTTPOpen; +static udFile_SeekReadHandlerFunc udFileHandler_HTTPSeekRead; static udFile_BlockForPipelinedRequestHandlerFunc udFileHandler_HTTPBlockForPipelinedRequest; -static udFile_CloseHandlerFunc udFileHandler_HTTPClose; +static udFile_CloseHandlerFunc udFileHandler_HTTPClose; // Register the HTTP handler (optional as it requires networking libraries, WS2_32.lib on Windows platform) udResult udFile_RegisterHTTP() @@ -28,15 +28,13 @@ udResult udFile_RegisterHTTP() return result; } - static char s_HTTPHeaderString[] = "HEAD %s HTTP/1.1\r\nHost: %s\r\nConnection: Keep-Alive\r\nUser-Agent: Euclideon udSDK/2.0\r\n\r\n"; static char s_HTTPGetString[] = "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Euclideon udSDK/2.0\r\nConnection: Keep-Alive\r\nRange: bytes=%lld-%lld\r\n\r\n"; - // The udFile derivative for supporting HTTP/S struct udFile_HTTP : public udFile { - udMutex *pMutex; // Used only when the udFOF_Multithread flag is used to ensure safe access from multiple threads + udMutex *pMutex; // Used only when the udFOF_Multithread flag is used to ensure safe access from multiple threads udURL url; bool wsInitialised; char recvBuffer[1024]; @@ -44,7 +42,6 @@ struct udFile_HTTP : public udFile int sockID; // Each time a socket it created we increment this number, this way pipelined requests from a dead socket can be identified as dead }; - // ---------------------------------------------------------------------------- // Open the socket // Author: Dave Pevreal, March 2014 @@ -69,7 +66,6 @@ static udResult udFileHandler_HTTPOpenSocket(udFile_HTTP *pFile) return result; } - // ---------------------------------------------------------------------------- // Close the socket // Author: Dave Pevreal, March 2014 @@ -79,7 +75,6 @@ static void udFileHandler_HTTPCloseSocket(udFile_HTTP *pFile) ++pFile->sockID; } - // ---------------------------------------------------------------------------- // Send a request // Author: Dave Pevreal, March 2014 @@ -88,13 +83,13 @@ static udResult udFileHandler_HTTPSendRequest(udFile_HTTP *pFile, int len) udResult result; UD_ERROR_CHECK(udFileHandler_HTTPOpenSocket(pFile)); - result = udSocket_SendData(pFile->pSocket, (const uint8_t*)pFile->recvBuffer, (int64_t)len); + result = udSocket_SendData(pFile->pSocket, (const uint8_t *)pFile->recvBuffer, (int64_t)len); if (result == udR_SocketError) { // On error, first try closing and re-opening the socket before giving up udFileHandler_HTTPCloseSocket(pFile); udFileHandler_HTTPOpenSocket(pFile); - result = udSocket_SendData(pFile->pSocket, (const uint8_t*)pFile->recvBuffer, (int64_t)len); + result = udSocket_SendData(pFile->pSocket, (const uint8_t *)pFile->recvBuffer, (int64_t)len); } epilogue: @@ -103,7 +98,6 @@ static udResult udFileHandler_HTTPSendRequest(udFile_HTTP *pFile, int len) return result; } - // ---------------------------------------------------------------------------- // Receive a response for a GET packet, parsing the string header before // delivering the payload @@ -111,7 +105,7 @@ static udResult udFileHandler_HTTPSendRequest(udFile_HTTP *pFile, int len) static udResult udFileHandler_HTTPRecvGET(udFile_HTTP *pFile, void *pBuffer, size_t bufferLength, size_t *pActualRead) { udResult result; - size_t bytesReceived = 0; // Number of bytes received from this packet + size_t bytesReceived = 0; // Number of bytes received from this packet int code; size_t headerLength; // length of the response header, before any payload const char *s; @@ -124,19 +118,19 @@ static udResult udFileHandler_HTTPRecvGET(udFile_HTTP *pFile, void *pBuffer, siz udDebugPrintf("Unable to open socket\n"); UD_ERROR_HANDLE(); - result = udSocket_ReceiveData(pFile->pSocket, (uint8_t*)pFile->recvBuffer, (int64_t)sizeof(pFile->recvBuffer), &actualReceived); + result = udSocket_ReceiveData(pFile->pSocket, (uint8_t *)pFile->recvBuffer, (int64_t)sizeof(pFile->recvBuffer), &actualReceived); if (result == udR_SocketError) { // Close and re-open the socket on error udFileHandler_HTTPCloseSocket(pFile); UD_ERROR_CHECK(udFileHandler_HTTPOpenSocket(pFile)); - UD_ERROR_CHECK(udSocket_ReceiveData(pFile->pSocket, (uint8_t*)pFile->recvBuffer, (int64_t)sizeof(pFile->recvBuffer), &actualReceived)); + UD_ERROR_CHECK(udSocket_ReceiveData(pFile->pSocket, (uint8_t *)pFile->recvBuffer, (int64_t)sizeof(pFile->recvBuffer), &actualReceived)); } bytesReceived += (size_t)actualReceived; while (udStrstr(pFile->recvBuffer, bytesReceived, "\r\n\r\n", &headerLength) == nullptr && (size_t)bytesReceived < sizeof(pFile->recvBuffer)) { - UD_ERROR_CHECK(udSocket_ReceiveData(pFile->pSocket, (uint8_t*)pFile->recvBuffer + bytesReceived, (int64_t)sizeof(pFile->recvBuffer) - bytesReceived, &actualReceived)); + UD_ERROR_CHECK(udSocket_ReceiveData(pFile->pSocket, (uint8_t *)pFile->recvBuffer + bytesReceived, (int64_t)sizeof(pFile->recvBuffer) - bytesReceived, &actualReceived)); bytesReceived += (size_t)actualReceived; } @@ -150,7 +144,7 @@ static udResult udFileHandler_HTTPRecvGET(udFile_HTTP *pFile, void *pBuffer, siz } headerLength += 4; - pFile->recvBuffer[headerLength-1] = 0; // null terminate the header part + pFile->recvBuffer[headerLength - 1] = 0; // null terminate the header part //udDebugPrintf("Received:\n%s--end--\n", pFile->recvBuffer); // Check for a request from the server to close the connection after dealing with this @@ -186,7 +180,7 @@ static udResult udFileHandler_HTTPRecvGET(udFile_HTTP *pFile, void *pBuffer, siz while (bytesReceived < (size_t)contentLength) { - UD_ERROR_CHECK(udSocket_ReceiveData(pFile->pSocket, (uint8_t*)pBuffer + bytesReceived, (int64_t)bufferLength - bytesReceived, &actualReceived)); + UD_ERROR_CHECK(udSocket_ReceiveData(pFile->pSocket, (uint8_t *)pBuffer + bytesReceived, (int64_t)bufferLength - bytesReceived, &actualReceived)); bytesReceived += (size_t)actualReceived; } if (pActualRead) @@ -204,7 +198,6 @@ static udResult udFileHandler_HTTPRecvGET(udFile_HTTP *pFile, void *pBuffer, siz return result; } - // ---------------------------------------------------------------------------- // Implementation of OpenHandler via HTTP // Author: Dave Pevreal, March 2014 @@ -215,7 +208,7 @@ udResult udFileHandler_HTTPOpen(udFile **ppFile, const char *pFilename, udFileOp int actualHeaderLen; // Automatically fail if trying to write to files on http - if (flags & (udFOF_Write|udFOF_Create)) + if (flags & (udFOF_Write | udFOF_Create)) UD_ERROR_SET(udR_OpenFailure); pFile = udAllocType(udFile_HTTP, 1, udAF_Zero); @@ -235,7 +228,7 @@ udResult udFileHandler_HTTPOpen(udFile **ppFile, const char *pFilename, udFileOp UD_ERROR_CHECK(udSocket_InitSystem()); pFile->wsInitialised = true; - actualHeaderLen = snprintf(pFile->recvBuffer, sizeof(pFile->recvBuffer)-1, s_HTTPHeaderString, pFile->url.GetPathWithQuery(), pFile->url.GetDomain()); + actualHeaderLen = snprintf(pFile->recvBuffer, sizeof(pFile->recvBuffer) - 1, s_HTTPHeaderString, pFile->url.GetPathWithQuery(), pFile->url.GetDomain()); UD_ERROR_IF(actualHeaderLen < 0, udR_Failure); //udDebugPrintf("Sending:\n%s", pFile->recvBuffer); @@ -252,12 +245,11 @@ udResult udFileHandler_HTTPOpen(udFile **ppFile, const char *pFilename, udFileOp epilogue: if (pFile) - udFileHandler_HTTPClose((udFile**)&pFile); + udFileHandler_HTTPClose((udFile **)&pFile); return result; } - // ---------------------------------------------------------------------------- // Implementation of SeekReadHandler via HTTP // Author: Dave Pevreal, March 2014 @@ -270,7 +262,7 @@ static udResult udFileHandler_HTTPSeekRead(udFile *pBaseFile, void *pBuffer, siz udLockMutex(pFile->pMutex); //udDebugPrintf("\nSeekRead: %lld bytes at offset %lld\n", bufferLength, offset); - size_t actualHeaderLen = snprintf(pFile->recvBuffer, sizeof(pFile->recvBuffer)-1, s_HTTPGetString, pFile->url.GetPathWithQuery(), pFile->url.GetDomain(), seekOffset, seekOffset + bufferLength-1); + size_t actualHeaderLen = snprintf(pFile->recvBuffer, sizeof(pFile->recvBuffer) - 1, s_HTTPGetString, pFile->url.GetPathWithQuery(), pFile->url.GetDomain(), seekOffset, seekOffset + bufferLength - 1); UD_ERROR_CHECK(udFileHandler_HTTPSendRequest(pFile, (int)actualHeaderLen)); @@ -296,7 +288,6 @@ static udResult udFileHandler_HTTPSeekRead(udFile *pBaseFile, void *pBuffer, siz return result; } - // ---------------------------------------------------------------------------- // Implementation of BlockForPipelinedRequest via HTTP // Author: Dave Pevreal, March 2014 @@ -308,7 +299,7 @@ static udResult udFileHandler_HTTPBlockForPipelinedRequest(udFile *pBaseFile, ud if (pFile->pMutex) udLockMutex(pFile->pMutex); - void *pBuffer = (void*)(pPipelinedRequest->reserved[0]); + void *pBuffer = (void *)(pPipelinedRequest->reserved[0]); size_t bufferLength = (size_t)(pPipelinedRequest->reserved[1]); int sockID = (int)pPipelinedRequest->reserved[2]; if (sockID != pFile->sockID) @@ -329,7 +320,6 @@ static udResult udFileHandler_HTTPBlockForPipelinedRequest(udFile *pBaseFile, ud return result; } - // ---------------------------------------------------------------------------- // Implementation of CloseHandler via HTTP // Author: Dave Pevreal, March 2014 diff --git a/Source/udFileHandler_Raw.cpp b/Source/udFileHandler_Raw.cpp index 8a98cbcc..4c84a31a 100644 --- a/Source/udFileHandler_Raw.cpp +++ b/Source/udFileHandler_Raw.cpp @@ -1,9 +1,9 @@ +#include "udCompression.h" #include "udFile.h" #include "udFileHandler.h" +#include "udMath.h" #include "udPlatformUtil.h" #include "udStringUtil.h" -#include "udCompression.h" -#include "udMath.h" // Raw support udFile handler // To encode to base64 use this: https://www.browserling.com/tools/file-to-base64 @@ -11,14 +11,14 @@ // Alternatively udFile_GenerateRawFilename can be used which offers compression and support for writing // Declarations of the fall-back standard handler that uses crt Raw as a back-end -static udFile_SeekReadHandlerFunc udFileHandler_RawSeekRead; -static udFile_SeekWriteHandlerFunc udFileHandler_RawSeekWrite; -static udFile_CloseHandlerFunc udFileHandler_RawClose; +static udFile_SeekReadHandlerFunc udFileHandler_RawSeekRead; +static udFile_SeekWriteHandlerFunc udFileHandler_RawSeekWrite; +static udFile_CloseHandlerFunc udFileHandler_RawClose; // The udFile derivative for supporting base64 raw and compressed files struct udFile_Raw : public udFile { - const char *pOriginalFilename; // Copy of "original" filename, generally a human-readable name rather than base64 + const char *pOriginalFilename; // Copy of "original" filename, generally a human-readable name rather than base64 uint8_t *pData; int64_t fp; size_t dataLen; @@ -26,7 +26,6 @@ struct udFile_Raw : public udFile udCompressionType ct; // For writeable files the compression type specified in the original text }; - // **************************************************************************** // Author: Dave Pevreal, August 2018 udResult udFile_GenerateRawFilename(const char **ppResultFilename, const void *pBuffer, size_t bufferLen, udCompressionType ct, const char *pOriginalFilename, size_t allocationSize, uint32_t charsPerLine) @@ -243,14 +242,13 @@ udResult udFileHandler_RawOpen(udFile **ppFile, const char *pFilename, udFileOpe return result; } - // ---------------------------------------------------------------------------- // Author: Dave Pevreal, August 2018 static udResult udFileHandler_RawSeekRead(udFile *pFile, void *pBuffer, size_t bufferLength, int64_t seekOffset, size_t *pActualRead, udFilePipelinedRequest * /*pPipelinedRequest*/) { UDTRACE(); udResult result; - udFile_Raw *pRaw = static_cast(pFile); + udFile_Raw *pRaw = static_cast(pFile); size_t actualRead; UD_ERROR_IF(seekOffset < 0 || seekOffset >= (int64_t)pRaw->dataLen, udR_InvalidParameter); @@ -266,14 +264,13 @@ static udResult udFileHandler_RawSeekRead(udFile *pFile, void *pBuffer, size_t b return result; } - // ---------------------------------------------------------------------------- // Author: Dave Pevreal, August 2018 static udResult udFileHandler_RawSeekWrite(udFile *pFile, const void *pBuffer, size_t bufferLength, int64_t seekOffset, size_t *pActualWritten) { UDTRACE(); udResult result; - udFile_Raw *pRaw = static_cast(pFile); + udFile_Raw *pRaw = static_cast(pFile); UD_ERROR_IF(seekOffset < 0, udR_InvalidParameter); if ((seekOffset + bufferLength) > pRaw->dataLen) @@ -282,7 +279,7 @@ static udResult udFileHandler_RawSeekWrite(udFile *pFile, const void *pBuffer, s size_t newLen = (size_t)(seekOffset + bufferLength); void *pNewData = udRealloc(pRaw->pData, newLen); UD_ERROR_NULL(pNewData, udR_MemoryAllocationFailure); - pRaw->pData = (uint8_t*)pNewData; + pRaw->pData = (uint8_t *)pNewData; if (seekOffset > (int64_t)pRaw->dataLen) memset(pRaw->pData + pRaw->dataLen, 0, seekOffset - pRaw->dataLen); // Zero the part of the extension not written to pRaw->dataLen = newLen; @@ -298,7 +295,6 @@ static udResult udFileHandler_RawSeekWrite(udFile *pFile, const void *pBuffer, s return result; } - // ---------------------------------------------------------------------------- // Author: Dave Pevreal, March 2014 // Implementation of CloseHandler to access the crt Raw i/o functions @@ -306,14 +302,14 @@ static udResult udFileHandler_RawClose(udFile **ppFile) { UDTRACE(); udResult result; - udFile_Raw *pRaw = static_cast(*ppFile); + udFile_Raw *pRaw = static_cast(*ppFile); *ppFile = nullptr; const char *pTempRaw = nullptr; if (pRaw && pRaw->fpWrite) { UD_ERROR_CHECK(udFile_GenerateRawFilename(&pTempRaw, pRaw->pData, pRaw->dataLen, pRaw->ct, pRaw->pOriginalFilename, pRaw->allocationSize)); - udStrcpy(const_cast(pRaw->pFilenameCopy), pRaw->allocationSize, pTempRaw); + udStrcpy(const_cast(pRaw->pFilenameCopy), pRaw->allocationSize, pTempRaw); } result = udR_Success; @@ -328,5 +324,3 @@ static udResult udFileHandler_RawClose(udFile **ppFile) } return result; } - - diff --git a/Source/udGeoZone.cpp b/Source/udGeoZone.cpp index 7f7bf819..833a402c 100644 --- a/Source/udGeoZone.cpp +++ b/Source/udGeoZone.cpp @@ -1,98 +1,98 @@ #include "udGeoZone.h" +#include "udFile.h" +#include "udJSON.h" #include "udPlatformUtil.h" #include "udStringUtil.h" -#include "udJSON.h" -#include "udFile.h" #include "udThread.h" const udGeoZoneEllipsoidInfo g_udGZ_StdEllipsoids[udGZE_Count] = { // WKT Sphere name semiMajor flattening authority epsg - { "WGS 84", 6378137.000, 1.0 / 298.257223563, 7030 }, // udGZE_WGS84 - { "Airy 1830", 6377563.396, 1.0 / 299.3249646, 7001 }, // udGZE_Airy1830 - { "Airy Modified 1849", 6377340.189, 1.0 / 299.3249646, 7002 }, // udGZE_AiryModified - { "Bessel 1841", 6377397.155, 1.0 / 299.1528128, 7004 }, // udGZE_Bessel1841 - { "Bessel Modified", 6377492.018, 1.0 / 299.1528128, 7005 }, // udGZE_BesselModified - { "Clarke 1866", 6378206.400, 1.0 / 294.978698214, 7008 }, // udGZE_Clarke1866 - { "Clarke 1880 (IGN)", 6378249.200, 1.0 / 293.466021294, 7011 }, // udGZE_Clarke1880IGN - { "GRS 1980", 6378137.000, 1.0 / 298.257222101, 7019 }, // udGZE_GRS80 - { "International 1924", 6378388.000, 1.0 / 297.00, 7022 }, // udGZE_Intl1924 - { "WGS 72", 6378135.000, 1.0 / 298.26, 7043 }, // udGZE_WGS72 - { "CGCS2000", 6378137.000, 1.0 / 298.257222101, 1024 }, // udGZE_CGCS2000 - { "Clarke 1858", 6378293.64520876, 1.0 / 294.260676369, 7007 }, // udGZE_Clarke1858 + { "WGS 84", 6378137.000, 1.0 / 298.257223563, 7030 }, // udGZE_WGS84 + { "Airy 1830", 6377563.396, 1.0 / 299.3249646, 7001 }, // udGZE_Airy1830 + { "Airy Modified 1849", 6377340.189, 1.0 / 299.3249646, 7002 }, // udGZE_AiryModified + { "Bessel 1841", 6377397.155, 1.0 / 299.1528128, 7004 }, // udGZE_Bessel1841 + { "Bessel Modified", 6377492.018, 1.0 / 299.1528128, 7005 }, // udGZE_BesselModified + { "Clarke 1866", 6378206.400, 1.0 / 294.978698214, 7008 }, // udGZE_Clarke1866 + { "Clarke 1880 (IGN)", 6378249.200, 1.0 / 293.466021294, 7011 }, // udGZE_Clarke1880IGN + { "GRS 1980", 6378137.000, 1.0 / 298.257222101, 7019 }, // udGZE_GRS80 + { "International 1924", 6378388.000, 1.0 / 297.00, 7022 }, // udGZE_Intl1924 + { "WGS 72", 6378135.000, 1.0 / 298.26, 7043 }, // udGZE_WGS72 + { "CGCS2000", 6378137.000, 1.0 / 298.257222101, 1024 }, // udGZE_CGCS2000 + { "Clarke 1858", 6378293.64520876, 1.0 / 294.260676369, 7007 }, // udGZE_Clarke1858 { "Clarke 1880 (international foot)", 6378306.369, 1.0 / 293.466307656, 7055 }, // udGZE_Clarke1880FOOT - { "Krassowsky 1940", 6378245.000, 1.0 / 298.3, 7024 }, // udGZE_Krassowsky1940 - { "Everest 1830 Modified",6377304.063, 1.0 / 300.8017, 7018 }, // udGZE_Everest1930M - { "Mars_2000_IAU_IAG", 3396190.000, 1.0 / 169.894447224, 49900 },// udGZE_MARS - { "Moon_2000_IAU_IAG", 1737400.000, 0.0, 39064 },// udGZE_MOON - { "IAG 1975", 6378140.000, 1.0 / 298.257, 7049 }, // udGZE_IAG1975 - { "Everest 1830 (1967 Definition)",6377298.556, 1.0 / 300.8017, 7016 }, // udGZE_Everest1830 - { "GRS 1967", 6378160.000, 1.0 / 298.247167427, 7036 }, // udGZE_GRS67 - { "Australian National Spheroid",6378160, 1.0 / 298.25, 7003 }, //udGZE_ANS - { "Indonesian National Spheroid",6378160, 1.0 / 298.247, 7021 }, //udGZE_INS + { "Krassowsky 1940", 6378245.000, 1.0 / 298.3, 7024 }, // udGZE_Krassowsky1940 + { "Everest 1830 Modified", 6377304.063, 1.0 / 300.8017, 7018 }, // udGZE_Everest1930M + { "Mars_2000_IAU_IAG", 3396190.000, 1.0 / 169.894447224, 49900 }, // udGZE_MARS + { "Moon_2000_IAU_IAG", 1737400.000, 0.0, 39064 }, // udGZE_MOON + { "IAG 1975", 6378140.000, 1.0 / 298.257, 7049 }, // udGZE_IAG1975 + { "Everest 1830 (1967 Definition)", 6377298.556, 1.0 / 300.8017, 7016 }, // udGZE_Everest1830 + { "GRS 1967", 6378160.000, 1.0 / 298.247167427, 7036 }, // udGZE_GRS67 + { "Australian National Spheroid", 6378160, 1.0 / 298.25, 7003 }, //udGZE_ANS + { "Indonesian National Spheroid", 6378160, 1.0 / 298.247, 7021 }, //udGZE_INS }; // Data for table gathered from https://github.com/chrisveness/geodesy/blob/master/latlon-ellipsoidal.js // and cross referenced with http://epsg.io/ const udGeoZoneGeodeticDatumDescriptor g_udGZ_GeodeticDatumDescriptors[] = { // Full Name, Short name Datum name Ellipsoid index // ToWGS84 parameters epsg auth, AxisInfo, ToWGS84 - { "WGS 84", "WGS 84", "WGS_1984", udGZE_WGS84, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4326, 6326, true, false }, - { "ED50", "ED50", "European_Datum_1950", udGZE_Intl1924, { -87.0, -98.0, -121.0, 0.0, 0.0, 0.0, 0.0 }, 4230, 6320, true, true }, - { "ETRS89", "ETRS89", "European_Terrestrial_Reference_System_1989", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4258, 6258, true, true }, - { "TM75", "TM75", "Geodetic_Datum_of_1965", udGZE_AiryModified, { 482.5, -130.6, 564.6, -1.042, -0.214, -0.631, 8.15 }, 4300, 6300, true, true }, - { "NAD27", "NAD27", "North_American_Datum_1927", udGZE_Clarke1866, { -8.0, 160.0, 176.0, 0.0, 0.0, 0.0, 0.0 }, 4267, 6267, true, true }, - { "NAD27(CGQ77)", "NAD27(CGQ77)", "North_American_Datum_1927_CGQ77", udGZE_Clarke1866, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4609, 6609, true, false }, - { "NAD83", "NAD83", "North_American_Datum_1983", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4269, 6269, true, true }, - { "NAD83(CORS96)", "NAD83(CORS96)", "NAD83_National_Spatial_Reference_System_1996", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 6783, 1133, true, false }, - { "NAD83(CSRS)", "NAD83(CSRS)", "NAD83_Canadian_Spatial_Reference_System", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 2955, 4617, true, true }, - { "NAD83(NSRS2007)", "NAD83(NSRS2007)", "NAD83_National_Spatial_Reference_System_2007", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 3465, 4759, true, true }, - { "NAD83(2011)", "NAD83(2011)", "NAD83_National_Spatial_Reference_System_2011", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 6318, 1116, true, false }, - { "NTF", "NTF", "Nouvelle_Triangulation_Francaise", udGZE_Clarke1880IGN, { -168.0, -60.0, 320.0, 0.0, 0.0, 0.0, 0.0 }, 4275, 6275, true, true }, - { "OSGB 1936", "OSGB 1936", "OSGB_1936", udGZE_Airy1830, { 446.448, -125.157, 542.06, 0.1502, 0.247, 0.8421, -20.4894 }, 4277, 6277, true, true }, - { "PD / 83", "PD / 83", "Potsdam_Datum_83", udGZE_Bessel1841, { 582.0, 105.0, 414.0, -1.04, -0.35, 3.08, 8.3 }, 4746, 6746, true, true }, - { "Tokyo", "Tokyo", "Tokyo", udGZE_Bessel1841, { -146.414, 507.337, 680.507, 0.0, 0.0, 0.0, 0.0 }, 7414, 6301, true, true }, - { "WGS 72", "WGS 72", "WGS_1972", udGZE_WGS72, { 0.0, 0.0, 4.5, 0.0, 0.0, 0.554, 0.2263 }, 4322, 6322, true, true }, - { "JGD2000", "JGD2000", "Japanese_Geodetic_Datum_2000", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4612, 6612, false, true }, - { "JGD2011", "JGD2011", "Japanese_Geodetic_Datum_2011", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 6668, 1128, false, false }, - { "GDA94", "GDA94", "Geocentric_Datum_of_Australia_1994", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4283, 6283, true, true }, - { "GDA2020", "GDA2020", "Geocentric_Datum_of_Australia_2020", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 7844, 1168, true, false }, - { "RGF93", "RGF93", "Reseau_Geodesique_Francais_1993", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4171, 6171, true, true }, - { "NAD83(HARN)", "NAD83(HARN)", "NAD83_High_Accuracy_Reference_Network", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4152, 6152, true, true }, - { "China Geodetic Coordinate System 2000", "CGCS2000", "China_2000", udGZE_CGCS2000, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4490, 1043, false, false }, - { "Hong Kong 1980", "Hong Kong 1980", "Hong_Kong_1980", udGZE_Intl1924, { -162.619,-276.959,-161.764,0.067753,-2.24365,-1.15883,-1.09425 }, 4611, 6611, false, true }, - { "SVY21", "SVY21", "SVY21", udGZE_WGS84, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4757, 6757, false, false }, - { "MGI", "MGI", "Militar_Geographische_Institute", udGZE_Bessel1841, { 577.326, 90.129, 463.919, 5.137, 1.474, 5.297, 2.4232 }, 4312, 6312, false, true }, - { "NZGD2000", "NZGD2000", "New_Zealand_Geodetic_Datum_2000", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4167, 6167, false, true }, - { "Amersfoort", "Amersfoort", "Amersfoort", udGZE_Bessel1841, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4289, 6289, true, false }, - { "Trinidad 1903", "Trinidad_1903", "Trinidad_1903", udGZE_Clarke1858, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4302, 6302, true, false }, - { "Vanua Levu 1915", "Vanua_Levu_1915", "Vanua_Levu_1915", udGZE_Clarke1880FOOT,{ 51.0, 391.0, -36.0, 0.0, 0.0, 0.0, 0.0 }, 4748, 6748, false, true }, - { "Dealul Piscului 1970", "Dealul_1970", "Dealul_Piscului_1970", udGZE_Krassowsky1940,{ 28,-121,-77, 0, 0, 0, 0 }, 4317, 6317, false, true }, - { "Singapore Grid", "Singapore Grid", "Singapore Grid", udGZE_Everest1930M, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4245, 6245, false, false }, - { "Mars 2000 Mercator", "Mars 2000", "D_Mars_2000", udGZE_Mars, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 490000, 490001, false,true }, - { "Mars 2000 / ECEF", "Mars 2000", "D_Mars_2000", udGZE_Mars, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 490000, 490001, true, false }, - { "Moon 2000 Mercator", "Moon 2000", "D_Moon_2000", udGZE_Moon, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 39064, 39065, false, true }, - { "Moon 2000 / ECEF", "Moon 2000", "D_Moon_2000", udGZE_Moon, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 39064, 39065, true, false }, - { "DB_REF", "DB_REF", "Deutsche_Bahn_Reference_System", udGZE_Bessel1841, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 5681, 1081, true, false }, - { "DHDN", "DHDN", "Deutsches_Hauptdreiecksnetz", udGZE_Bessel1841, { 598.1, 73.7, 418.2, 0.202, 0.045, -2.455, 6.7 }, 4314, 6314, false, true }, - { "System of the Unified Trigonometrical Cadastral Network [JTSK03]", "JTSK03", "S-JTSK [JTSK03]", udGZE_Bessel1841, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 8353, 8351, true, false }, - { "Pulkovo 1942", "Pulkovo_1942", "Pulkovo_1942", udGZE_Krassowsky1940,{ 23.92, -141.27, -80.9, 0, 0.35, 0.82, -0.12 }, 4284, 6284, true, true }, - { "Pulkovo 1942(58)", "Pulkovo_1942_58", "Pulkovo_1942_58", udGZE_Krassowsky1940,{ 33.4, -146.6, -76.3, -0.359, -0.053, 0.844, -0.84 }, 4179, 6179, true, true }, - { "Pulkovo 1942(83)", "Pulkovo_1942_83", "Pulkovo_1942_83", udGZE_Krassowsky1940,{ 26.0, -121.0, -78.0, 0.0, 0.0, 0.0, 0 }, 4178, 6178, true, true }, - { "Pulkovo 1995", "Pulkovo_1995", "Pulkovo_1995", udGZE_Krassowsky1940,{ 24.47, -130.89, -81.56, 0, 0, 0.13, -0.22 }, 20004, 4200, true, true }, - { "WGS 72BE", "WGS_72BE", "WGS_1972_Transit_Broadcast_Ephemeris", udGZE_WGS72, { 0, 0, 1.9, 0, 0, 0.814, -0.38 }, 4324, 6324, true, true }, - { "Beijing 1954", "Beijing_1954", "Beijing_1954", udGZE_Krassowsky1940,{ 15.8, -154.4, -82.3, 0, 0, 0, 0 }, 4214, 6214, false, true }, - { "New Beijing", "New_Beijing", "New_Beijing", udGZE_Krassowsky1940,{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4555, 1045, false, false }, - { "Xian 1980", "Xian_1980", "Xian_1980", udGZE_IAG1975, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4610, 6610, false, false }, - { "Timbalai 1948 / Tso Borneo (m)", "Timbalai 1948", "Timbalai_1948", udGZE_Everest1830, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 29873, 6298, true, false }, - { "NZGD49", "NZGD49", "New_Zealand_Geodetic_Datum_1949", udGZE_Intl1924, { 59.47, -5.04, 187.44, 0.47, -0.1, 1.024, -4.5993 }, 4272, 6272, true, true }, - { "SWEREF99", "SWEREF99", "SWEREF99", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4619, 6619, true, true }, - { "SAD69", "SAD69", "South_American_Datum_1969", udGZE_GRS67, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4291, 6291, true, false }, - { "GR96", "GR96", "Greenland_1996", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4747, 6747, false, true }, - { "DGN95", "DGN95", "Datum_Geodesi_Nasional_1995", udGZE_WGS84, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4755, 6755, false, true }, - { "UCS-2000", "UCS-2000", "Ukraine_2000", udGZE_Krassowsky1940,{ 25.0, -141.0, -78.5, 0.0, 0.35, 0.736, 0 }, 5561, 1077, true, true }, - { "Hartebeesthoek94", "Hartebeesthoek94","Hartebeesthoek94", udGZE_WGS84, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4148, 6148, false, true }, - { "ID74", "ID74", "Indonesian_Datum_1974", udGZE_INS, { -24.0, -15.0, 5.0, 0.0, 0.0, 0.0, 0 }, 4238, 6238, true, true }, - { "NGO 1948", "NGO_1948", "NGO_1948", udGZE_BesselModified,{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4273, 6273, true, false }, - { "RGF93 v2b", "RGF93 v2b", "Reseau_Geodesique_Francais_1993_v2b", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 9782, 6171, true, true }, + { "WGS 84", "WGS 84", "WGS_1984", udGZE_WGS84, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4326, 6326, true, false }, + { "ED50", "ED50", "European_Datum_1950", udGZE_Intl1924, { -87.0, -98.0, -121.0, 0.0, 0.0, 0.0, 0.0 }, 4230, 6320, true, true }, + { "ETRS89", "ETRS89", "European_Terrestrial_Reference_System_1989", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4258, 6258, true, true }, + { "TM75", "TM75", "Geodetic_Datum_of_1965", udGZE_AiryModified, { 482.5, -130.6, 564.6, -1.042, -0.214, -0.631, 8.15 }, 4300, 6300, true, true }, + { "NAD27", "NAD27", "North_American_Datum_1927", udGZE_Clarke1866, { -8.0, 160.0, 176.0, 0.0, 0.0, 0.0, 0.0 }, 4267, 6267, true, true }, + { "NAD27(CGQ77)", "NAD27(CGQ77)", "North_American_Datum_1927_CGQ77", udGZE_Clarke1866, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4609, 6609, true, false }, + { "NAD83", "NAD83", "North_American_Datum_1983", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4269, 6269, true, true }, + { "NAD83(CORS96)", "NAD83(CORS96)", "NAD83_National_Spatial_Reference_System_1996", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 6783, 1133, true, false }, + { "NAD83(CSRS)", "NAD83(CSRS)", "NAD83_Canadian_Spatial_Reference_System", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 2955, 4617, true, true }, + { "NAD83(NSRS2007)", "NAD83(NSRS2007)", "NAD83_National_Spatial_Reference_System_2007", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 3465, 4759, true, true }, + { "NAD83(2011)", "NAD83(2011)", "NAD83_National_Spatial_Reference_System_2011", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 6318, 1116, true, false }, + { "NTF", "NTF", "Nouvelle_Triangulation_Francaise", udGZE_Clarke1880IGN, { -168.0, -60.0, 320.0, 0.0, 0.0, 0.0, 0.0 }, 4275, 6275, true, true }, + { "OSGB 1936", "OSGB 1936", "OSGB_1936", udGZE_Airy1830, { 446.448, -125.157, 542.06, 0.1502, 0.247, 0.8421, -20.4894 }, 4277, 6277, true, true }, + { "PD / 83", "PD / 83", "Potsdam_Datum_83", udGZE_Bessel1841, { 582.0, 105.0, 414.0, -1.04, -0.35, 3.08, 8.3 }, 4746, 6746, true, true }, + { "Tokyo", "Tokyo", "Tokyo", udGZE_Bessel1841, { -146.414, 507.337, 680.507, 0.0, 0.0, 0.0, 0.0 }, 7414, 6301, true, true }, + { "WGS 72", "WGS 72", "WGS_1972", udGZE_WGS72, { 0.0, 0.0, 4.5, 0.0, 0.0, 0.554, 0.2263 }, 4322, 6322, true, true }, + { "JGD2000", "JGD2000", "Japanese_Geodetic_Datum_2000", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4612, 6612, false, true }, + { "JGD2011", "JGD2011", "Japanese_Geodetic_Datum_2011", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 6668, 1128, false, false }, + { "GDA94", "GDA94", "Geocentric_Datum_of_Australia_1994", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4283, 6283, true, true }, + { "GDA2020", "GDA2020", "Geocentric_Datum_of_Australia_2020", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 7844, 1168, true, false }, + { "RGF93", "RGF93", "Reseau_Geodesique_Francais_1993", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4171, 6171, true, true }, + { "NAD83(HARN)", "NAD83(HARN)", "NAD83_High_Accuracy_Reference_Network", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4152, 6152, true, true }, + { "China Geodetic Coordinate System 2000", "CGCS2000", "China_2000", udGZE_CGCS2000, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4490, 1043, false, false }, + { "Hong Kong 1980", "Hong Kong 1980", "Hong_Kong_1980", udGZE_Intl1924, { -162.619, -276.959, -161.764, 0.067753, -2.24365, -1.15883, -1.09425 }, 4611, 6611, false, true }, + { "SVY21", "SVY21", "SVY21", udGZE_WGS84, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4757, 6757, false, false }, + { "MGI", "MGI", "Militar_Geographische_Institute", udGZE_Bessel1841, { 577.326, 90.129, 463.919, 5.137, 1.474, 5.297, 2.4232 }, 4312, 6312, false, true }, + { "NZGD2000", "NZGD2000", "New_Zealand_Geodetic_Datum_2000", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4167, 6167, false, true }, + { "Amersfoort", "Amersfoort", "Amersfoort", udGZE_Bessel1841, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4289, 6289, true, false }, + { "Trinidad 1903", "Trinidad_1903", "Trinidad_1903", udGZE_Clarke1858, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4302, 6302, true, false }, + { "Vanua Levu 1915", "Vanua_Levu_1915", "Vanua_Levu_1915", udGZE_Clarke1880FOOT, { 51.0, 391.0, -36.0, 0.0, 0.0, 0.0, 0.0 }, 4748, 6748, false, true }, + { "Dealul Piscului 1970", "Dealul_1970", "Dealul_Piscului_1970", udGZE_Krassowsky1940, { 28, -121, -77, 0, 0, 0, 0 }, 4317, 6317, false, true }, + { "Singapore Grid", "Singapore Grid", "Singapore Grid", udGZE_Everest1930M, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4245, 6245, false, false }, + { "Mars 2000 Mercator", "Mars 2000", "D_Mars_2000", udGZE_Mars, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 490000, 490001, false, true }, + { "Mars 2000 / ECEF", "Mars 2000", "D_Mars_2000", udGZE_Mars, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 490000, 490001, true, false }, + { "Moon 2000 Mercator", "Moon 2000", "D_Moon_2000", udGZE_Moon, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 39064, 39065, false, true }, + { "Moon 2000 / ECEF", "Moon 2000", "D_Moon_2000", udGZE_Moon, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 39064, 39065, true, false }, + { "DB_REF", "DB_REF", "Deutsche_Bahn_Reference_System", udGZE_Bessel1841, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 5681, 1081, true, false }, + { "DHDN", "DHDN", "Deutsches_Hauptdreiecksnetz", udGZE_Bessel1841, { 598.1, 73.7, 418.2, 0.202, 0.045, -2.455, 6.7 }, 4314, 6314, false, true }, + { "System of the Unified Trigonometrical Cadastral Network [JTSK03]", "JTSK03", "S-JTSK [JTSK03]", udGZE_Bessel1841, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 8353, 8351, true, false }, + { "Pulkovo 1942", "Pulkovo_1942", "Pulkovo_1942", udGZE_Krassowsky1940, { 23.92, -141.27, -80.9, 0, 0.35, 0.82, -0.12 }, 4284, 6284, true, true }, + { "Pulkovo 1942(58)", "Pulkovo_1942_58", "Pulkovo_1942_58", udGZE_Krassowsky1940, { 33.4, -146.6, -76.3, -0.359, -0.053, 0.844, -0.84 }, 4179, 6179, true, true }, + { "Pulkovo 1942(83)", "Pulkovo_1942_83", "Pulkovo_1942_83", udGZE_Krassowsky1940, { 26.0, -121.0, -78.0, 0.0, 0.0, 0.0, 0 }, 4178, 6178, true, true }, + { "Pulkovo 1995", "Pulkovo_1995", "Pulkovo_1995", udGZE_Krassowsky1940, { 24.47, -130.89, -81.56, 0, 0, 0.13, -0.22 }, 20004, 4200, true, true }, + { "WGS 72BE", "WGS_72BE", "WGS_1972_Transit_Broadcast_Ephemeris", udGZE_WGS72, { 0, 0, 1.9, 0, 0, 0.814, -0.38 }, 4324, 6324, true, true }, + { "Beijing 1954", "Beijing_1954", "Beijing_1954", udGZE_Krassowsky1940, { 15.8, -154.4, -82.3, 0, 0, 0, 0 }, 4214, 6214, false, true }, + { "New Beijing", "New_Beijing", "New_Beijing", udGZE_Krassowsky1940, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4555, 1045, false, false }, + { "Xian 1980", "Xian_1980", "Xian_1980", udGZE_IAG1975, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4610, 6610, false, false }, + { "Timbalai 1948 / Tso Borneo (m)", "Timbalai 1948", "Timbalai_1948", udGZE_Everest1830, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 29873, 6298, true, false }, + { "NZGD49", "NZGD49", "New_Zealand_Geodetic_Datum_1949", udGZE_Intl1924, { 59.47, -5.04, 187.44, 0.47, -0.1, 1.024, -4.5993 }, 4272, 6272, true, true }, + { "SWEREF99", "SWEREF99", "SWEREF99", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4619, 6619, true, true }, + { "SAD69", "SAD69", "South_American_Datum_1969", udGZE_GRS67, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4291, 6291, true, false }, + { "GR96", "GR96", "Greenland_1996", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4747, 6747, false, true }, + { "DGN95", "DGN95", "Datum_Geodesi_Nasional_1995", udGZE_WGS84, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4755, 6755, false, true }, + { "UCS-2000", "UCS-2000", "Ukraine_2000", udGZE_Krassowsky1940, { 25.0, -141.0, -78.5, 0.0, 0.35, 0.736, 0 }, 5561, 1077, true, true }, + { "Hartebeesthoek94", "Hartebeesthoek94", "Hartebeesthoek94", udGZE_WGS84, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4148, 6148, false, true }, + { "ID74", "ID74", "Indonesian_Datum_1974", udGZE_INS, { -24.0, -15.0, 5.0, 0.0, 0.0, 0.0, 0 }, 4238, 6238, true, true }, + { "NGO 1948", "NGO_1948", "NGO_1948", udGZE_BesselModified, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 4273, 6273, true, false }, + { "RGF93 v2b", "RGF93 v2b", "Reseau_Geodesique_Francais_1993_v2b", udGZE_GRS80, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 9782, 6171, true, true }, }; UDCOMPILEASSERT(udLengthOf(g_udGZ_GeodeticDatumDescriptors) == udGZGD_Count, "Update above descriptor table!"); @@ -211,7 +211,7 @@ udResult udGeoZone_LoadZonesFromJSON(const char *pJSONStr, int *pLoaded, int *pF pSRIDStr = udStrstr(item.pKey, 0, ":"); if (pSRIDStr != nullptr) - expectedSRID = udStrAtoi(pSRIDStr+1); + expectedSRID = udStrAtoi(pSRIDStr + 1); else expectedSRID = udStrAtoi(item.pKey); @@ -320,7 +320,7 @@ udDouble3 udGeoZone_GeocentricToLatLong(udDouble3 geoCentric, const udGeoZoneEll while (lat2 != lat2Temp && isfinite(lat2)) { lat2 = lat2Temp; - lat2Temp = udATan((geoCentric.z + eSq*v*udSin(lat2)) / udSqrt(geoCentric.x * geoCentric.x + geoCentric.y * geoCentric.y)); + lat2Temp = udATan((geoCentric.z + eSq * v * udSin(lat2)) / udSqrt(geoCentric.x * geoCentric.x + geoCentric.y * geoCentric.y)); } return udDouble3::create(UD_RAD2DEG(lat2), UD_RAD2DEG(lon), h); @@ -332,12 +332,12 @@ udDouble3 udGeoZone_ApplyTransform(udDouble3 geoCentric, const udGeoZoneGeodetic double rx = UD_DEG2RAD(transform.paramsHelmert7[3] / 3600.0); // x-rotation: normalise arcseconds to radians double ry = UD_DEG2RAD(transform.paramsHelmert7[4] / 3600.0); // y-rotation: normalise arcseconds to radians double rz = UD_DEG2RAD(transform.paramsHelmert7[5] / 3600.0); // z-rotation: normalise arcseconds to radians - double ds = transform.paramsHelmert7[6] / 1000000.0 + 1.0; // scale: normalise parts-per-million to (s+1) + double ds = transform.paramsHelmert7[6] / 1000000.0 + 1.0; // scale: normalise parts-per-million to (s+1) // apply transform - double x2 = transform.paramsHelmert7[0] + (ds * geoCentric.x - geoCentric.y*rz + geoCentric.z*ry); - double y2 = transform.paramsHelmert7[1] + (geoCentric.x*rz + ds * geoCentric.y - geoCentric.z*rx); - double z2 = transform.paramsHelmert7[2] + (-geoCentric.x*ry + geoCentric.y*rx + ds * geoCentric.z); + double x2 = transform.paramsHelmert7[0] + (ds * geoCentric.x - geoCentric.y * rz + geoCentric.z * ry); + double y2 = transform.paramsHelmert7[1] + (geoCentric.x * rz + ds * geoCentric.y - geoCentric.z * rx); + double z2 = transform.paramsHelmert7[2] + (-geoCentric.x * ry + geoCentric.y * rx + ds * geoCentric.z); return udDouble3::create(x2, y2, z2); } @@ -497,7 +497,7 @@ static void udGeoZone_SetSpheroid(udGeoZone *pZone) // The alpha and beta constant below can be cross-referenced with https://geographiclib.sourceforge.io/html/transversemercator.html pZone->alpha[0] = 1.0 / 2.0 * pZone->n[1] - 2.0 / 3.0 * pZone->n[2] + 5.0 / 16.0 * pZone->n[3] + 41.0 / 180.0 * pZone->n[4] - 127.0 / 288.0 * pZone->n[5] + 7891.0 / 37800.0 * pZone->n[6] + 72161.0 / 387072.0 * pZone->n[7] - 18975107.0 / 50803200.0 * pZone->n[8] + 60193001.0 / 290304000.0 * pZone->n[9]; - pZone->alpha[1] = 13.0 / 48.0 * pZone->n[2] - 3.0 / 5.0 * pZone->n[3] + 557.0 / 1440.0 *pZone->n[4] + 281.0 / 630.0 * pZone->n[5] - 1983433.0 / 1935360.0 * pZone->n[6] + 13769.0 / 28800.0 * pZone->n[7] + 148003883.0 / 174182400.0 * pZone->n[8] - 705286231.0 / 465696000.0 * pZone->n[9]; + pZone->alpha[1] = 13.0 / 48.0 * pZone->n[2] - 3.0 / 5.0 * pZone->n[3] + 557.0 / 1440.0 * pZone->n[4] + 281.0 / 630.0 * pZone->n[5] - 1983433.0 / 1935360.0 * pZone->n[6] + 13769.0 / 28800.0 * pZone->n[7] + 148003883.0 / 174182400.0 * pZone->n[8] - 705286231.0 / 465696000.0 * pZone->n[9]; pZone->alpha[2] = 61.0 / 240.0 * pZone->n[3] - 103.0 / 140.0 * pZone->n[4] + 15061.0 / 26880.0 * pZone->n[5] + 167603.0 / 181440.0 * pZone->n[6] - 67102379.0 / 29030400.0 * pZone->n[7] + 79682431.0 / 79833600.0 * pZone->n[8] + 6304945039.0 / 2128896000.0 * pZone->n[9]; pZone->alpha[3] = 49561.0 / 161280.0 * pZone->n[4] - 179.0 / 168.0 * pZone->n[5] + 6601661.0 / 7257600.0 * pZone->n[6] + 97445.0 / 49896.0 * pZone->n[7] - 40176129013.0 / 7664025600.0 * pZone->n[8] + 138471097.0 / 66528000.0 * pZone->n[9]; pZone->alpha[4] = 34729.0 / 80640.0 * pZone->n[5] - 3418889.0 / 1995840.0 * pZone->n[6] + 14644087.0 / 9123840.0 * pZone->n[7] + 2605413599.0 / 622702080.0 * pZone->n[8] - 31015475399.0 / 2583060480.0 * pZone->n[9]; @@ -516,7 +516,7 @@ static void udGeoZone_SetSpheroid(udGeoZone *pZone) pZone->beta[7] = -191773887257.0 / 3719607091200.0 * pZone->n[8] + 17822319343.0 / 336825216000.0 * pZone->n[9]; pZone->beta[8] = -11025641854267.0 / 158083301376000.0 * pZone->n[9]; - pZone->radius = pZone->semiMajorAxis / (1 + pZone->n[1]) * (1.0 + 1.0 / 4.0 * pZone->n[2] + 1.0 / 64.0 *pZone->n[4] + 1.0 / 256.0 * pZone->n[6] + 25.0 / 16384.0 * pZone->n[8]); + pZone->radius = pZone->semiMajorAxis / (1 + pZone->n[1]) * (1.0 + 1.0 / 4.0 * pZone->n[2] + 1.0 / 64.0 * pZone->n[4] + 1.0 / 256.0 * pZone->n[6] + 25.0 / 16384.0 * pZone->n[8]); if (pZone->firstParallel == 0.0 && pZone->secondParallel == 0.0 && pZone->parallel != 0) // Latitude of origin for Transverse Mercator { @@ -623,34 +623,34 @@ udResult udGeoZone_SetFromSRID(udGeoZone *pZone, int32_t sridCode) switch (sridCode) { - case 31284: - pSuffix = "M28"; - pZone->meridian = 10.33333333333333; - pZone->falseEasting = 150000; - break; - - case 31285: - pSuffix = "M31"; - pZone->meridian = 13.33333333333333; - pZone->falseEasting = 450000; - break; - - case 31286: - pSuffix = "M34"; - pZone->meridian = 16.33333333333333; - pZone->falseEasting = 750000; - break; - - case 31287: - pSuffix = "Lambert"; - pZone->meridian = 13.33333333333333; - pZone->firstParallel = 49; - pZone->secondParallel = 46; - pZone->falseEasting = 400000; - pZone->falseNorthing = 400000; - pZone->projection = udGZPT_LambertConformalConic2SP; - pZone->parallel = 47.5; - break; + case 31284: + pSuffix = "M28"; + pZone->meridian = 10.33333333333333; + pZone->falseEasting = 150000; + break; + + case 31285: + pSuffix = "M31"; + pZone->meridian = 13.33333333333333; + pZone->falseEasting = 450000; + break; + + case 31286: + pSuffix = "M34"; + pZone->meridian = 16.33333333333333; + pZone->falseEasting = 750000; + break; + + case 31287: + pSuffix = "Lambert"; + pZone->meridian = 13.33333333333333; + pZone->firstParallel = 49; + pZone->secondParallel = 46; + pZone->falseEasting = 400000; + pZone->falseNorthing = 400000; + pZone->projection = udGZPT_LambertConformalConic2SP; + pZone->parallel = 47.5; + break; } udSprintf(pZone->zoneName, "Austria %s", pSuffix); @@ -672,37 +672,36 @@ udResult udGeoZone_SetFromSRID(udGeoZone *pZone, int32_t sridCode) switch (sridCode) { - case 31254: - pSuffix = "GK West"; - break; - - case 31255: - pZone->meridian = 13.33333333333333; - pSuffix = "GK Central"; - break; - - case 31256: - pZone->meridian = 16.33333333333333; - pSuffix = "GK East"; - break; - - case 31257: - pZone->falseEasting = 150000; - pSuffix = "GK M28"; - break; - - case 31258: - pZone->falseEasting = 450000; - pZone->meridian = 13.33333333333333; - pSuffix = "GK M31"; - break; - - case 31259: - pZone->falseEasting = 750000; - pZone->meridian = 16.33333333333333; - pSuffix = "GK M34"; - break; + case 31254: + pSuffix = "GK West"; + break; + + case 31255: + pZone->meridian = 13.33333333333333; + pSuffix = "GK Central"; + break; + + case 31256: + pZone->meridian = 16.33333333333333; + pSuffix = "GK East"; + break; + + case 31257: + pZone->falseEasting = 150000; + pSuffix = "GK M28"; + break; + + case 31258: + pZone->falseEasting = 450000; + pZone->meridian = 13.33333333333333; + pSuffix = "GK M31"; + break; + case 31259: + pZone->falseEasting = 750000; + pZone->meridian = 16.33333333333333; + pSuffix = "GK M34"; + break; } udSprintf(pZone->zoneName, "Austria %s", pSuffix); @@ -815,25 +814,25 @@ udResult udGeoZone_SetFromSRID(udGeoZone *pZone, int32_t sridCode) // {6669-6687} JGD2011 / Japan Plane Rectangular CS I through XIX const udDouble2 jprcsRegions[] = { // Meridian, Latitude Of Origin - { 129.5, 33.0 }, - { 131.0, 33.0 }, - { 132.0 + 1.0 / 6.0, 36.0 }, - { 133.5, 33.0 }, - { 134.0 + 1.0 / 3.0, 36.0 }, - { 136.0, 36.0 }, - { 137.0 + 1.0 / 6.0, 36.0 }, - { 138.5, 36.0 }, - { 139.0 + 5.0 / 6.0, 36.0 }, - { 140.0 + 5.0 / 6.0, 40.0 }, - { 140.25, 44.0 }, - { 142.25, 44.0 }, - { 144.25, 44.0 }, - { 142.0, 26.0 }, - { 127.5, 26.0 }, - { 124.0, 26.0 }, - { 131.0, 26.0 }, - { 136.0, 20.0 }, - { 154.0, 26.0 } + { 129.5, 33.0 }, + { 131.0, 33.0 }, + { 132.0 + 1.0 / 6.0, 36.0 }, + { 133.5, 33.0 }, + { 134.0 + 1.0 / 3.0, 36.0 }, + { 136.0, 36.0 }, + { 137.0 + 1.0 / 6.0, 36.0 }, + { 138.5, 36.0 }, + { 139.0 + 5.0 / 6.0, 36.0 }, + { 140.0 + 5.0 / 6.0, 40.0 }, + { 140.25, 44.0 }, + { 142.25, 44.0 }, + { 144.25, 44.0 }, + { 142.0, 26.0 }, + { 127.5, 26.0 }, + { 124.0, 26.0 }, + { 131.0, 26.0 }, + { 136.0, 20.0 }, + { 154.0, 26.0 } }; const char *pRomanNumerals[] = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX" }; @@ -907,286 +906,288 @@ udResult udGeoZone_SetFromSRID(udGeoZone *pZone, int32_t sridCode) { switch (sridCode) { - case 84: // LongLat (Not EPSG - CRS:84. There is no EPSG LongLat code) - pZone->datum = udGZGD_WGS84; - pZone->projection = udGZPT_LongLat; - pZone->zone = 0; - pZone->scaleFactor = 0.0174532925199433; - pZone->unitMetreScale = 1.0; - udStrcpy(pZone->zoneName, ""); - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(-90, -180); - pZone->latLongBoundMax = udDouble2::create(90, 180); - break; - case 2154: // RGF93 / Lambert-93 - pZone->datum = udGZGD_RGF93; - pZone->projection = udGZPT_LambertConformalConic2SP; - udStrcpy(pZone->zoneName, "Lambert-93"); - pZone->meridian = 3; - pZone->parallel = 46.5; - pZone->firstParallel = 49; - pZone->secondParallel = 44; - pZone->falseNorthing = 6600000; - pZone->falseEasting = 700000; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(41.1800, -9.6200); - pZone->latLongBoundMax = udDouble2::create(51.5400, 10.3000); - break; - case 9794: // RGF93 / Lambert-93 v2b - pZone->datum = udGZGD_RGF93v2b; - pZone->projection = udGZPT_LambertConformalConic2SP; - udStrcpy(pZone->zoneName, "Lambert-93"); - pZone->meridian = 3; - pZone->parallel = 46.5; - pZone->firstParallel = 49; - pZone->secondParallel = 44; - pZone->falseNorthing = 6600000; - pZone->falseEasting = 700000; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(41.1800 , -9.6200); - pZone->latLongBoundMax = udDouble2::create(51.5400, 10.3000); - break; - case 2193: // NZGD2000 - pZone->datum = udGZGD_NZGD2000; - pZone->projection = udGZPT_TransverseMercator; - udStrcpy(pZone->zoneName, "New Zealand Transverse Mercator 2000"); - pZone->meridian = 173; - pZone->parallel = 0; - pZone->falseNorthing = 10000000; - pZone->falseEasting = 1600000; - pZone->scaleFactor = 0.9996; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(-47.4, 166.33); - pZone->latLongBoundMax = udDouble2::create(-34, 178.6); - break; - case 2230: // NAD83 / California zone 6 (ftUS) - pZone->datum = udGZGD_NAD83; - pZone->projection = udGZPT_LambertConformalConic2SP; - pZone->unitMetreScale = 0.3048006096012192; - udStrcpy(pZone->zoneName, "California zone 6 (ftUS)"); - pZone->meridian = -116.25; - pZone->parallel = 32.0 + 1.0 / 6.0; - pZone->firstParallel = 33.0 + 53.0 / 60.0; - pZone->secondParallel = 32.0 + 47.0 / 60.0; - pZone->falseNorthing = 1640416.667; - pZone->falseEasting = 6561666.667; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(23.81, -172.54); - pZone->latLongBoundMax = udDouble2::create(86.46, -47.74); - break; - case 2238: // NAD83 / Florida North (ftUS) - pZone->datum = udGZGD_NAD83; - pZone->projection = udGZPT_LambertConformalConic2SP; - pZone->unitMetreScale = 0.3048006096012192; - udStrcpy(pZone->zoneName, "Florida North (ftUS)"); - pZone->meridian = -84.5; - pZone->parallel = 29.0; - pZone->firstParallel = 30.75; - pZone->secondParallel = 29.0 + 175.0 / 300.0; - pZone->falseNorthing = 0.0; - pZone->falseEasting = 1968500.0; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(29.28, -87.64); - pZone->latLongBoundMax = udDouble2::create(31.0, -82.05); - break; - case 2248: // NAD83 / Maryland (ftUS) - pZone->datum = udGZGD_NAD83; - pZone->projection = udGZPT_LambertConformalConic2SP; - pZone->unitMetreScale = 0.3048006096012192; - udStrcpy(pZone->zoneName, "Maryland (ftUS)"); - pZone->meridian = -77.0; - pZone->parallel = 37.0 + 2.0 / 3.0; - pZone->firstParallel = 39.45; - pZone->secondParallel = 38.3; - pZone->falseNorthing = 0.0; - pZone->falseEasting = 1312333.333; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(37.88, -79.49); - pZone->latLongBoundMax = udDouble2::create(39.72, -74.98); - break; - case 2250: // NAD83 / Massachusetts Island (ftUS) - pZone->datum = udGZGD_NAD83; - pZone->projection = udGZPT_LambertConformalConic2SP; - pZone->unitMetreScale = 0.3048006096012192; - udStrcpy(pZone->zoneName, "Massachusetts Island (ftUS)"); - pZone->meridian = -70.5; - pZone->parallel = 41.0; - pZone->firstParallel = 41.0 + 145.0 / 300.0; - pZone->secondParallel = 41.0 + 85.0 / 300.0;; - pZone->falseNorthing = 0.0; - pZone->falseEasting = 1640416.667; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(41.2, -70.87); - pZone->latLongBoundMax = udDouble2::create(41.51, -69.9); - break; - case 2285: // NAD83 / Washington North (ftUS) - pZone->datum = udGZGD_NAD83; - pZone->projection = udGZPT_LambertConformalConic2SP; - pZone->unitMetreScale = 0.3048006096012192; - udStrcpy(pZone->zoneName, "Washington North (ftUS)"); - pZone->meridian = -120 - 25.0 / 30.0; - pZone->parallel = 47.0; - pZone->firstParallel = 48.0 + 22.0 / 30.0;; - pZone->secondParallel = 47.5; - pZone->falseNorthing = 0.0; - pZone->falseEasting = 1640416.667; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(47.08, -124.75); - pZone->latLongBoundMax = udDouble2::create(49.0, -117.03); - break; - case 2326: // Hong Kong 1980 Grid System - pZone->datum = udGZGD_HK1980; - pZone->projection = udGZPT_TransverseMercator; - udStrcpy(pZone->zoneName, "Hong Kong 1980 Grid System"); - pZone->meridian = 114.1785555555556; - pZone->parallel = 22.31213333333334; - pZone->falseNorthing = 819069.8; - pZone->falseEasting = 836694.05; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(22.13, 113.76); - pZone->latLongBoundMax = udDouble2::create(22.58, 114.51); - break; - case 2771: // NAD83(HARN) / California zone 6 - pZone->datum = udGZGD_NAD83_HARN; - pZone->projection = udGZPT_LambertConformalConic2SP; - udStrcpy(pZone->zoneName, "California zone 6"); - pZone->meridian = -116.25; - pZone->parallel = 32.0 + 1.0 / 6.0; - pZone->firstParallel = 33.0 + 265.0 / 300.0; - pZone->secondParallel = 32.0 + 235.0 / 300.0; - pZone->falseNorthing = 500000.0; - pZone->falseEasting = 2000000.0; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(32.51, -118.14); - pZone->latLongBoundMax = udDouble2::create(34.08, -114.43); - break; - case 3032: // WGS 84 / Australian Antartic Polar Sterographic - pZone->datum = udGZGD_WGS84;//udGZGD_AUST_ANT; - pZone->projection = udGZPT_SterographicPolar_vB; - udStrcpy(pZone->zoneName, "Australian Antarctic Polar Stereographic"); - pZone->meridian = 70.0; - pZone->parallel = -71.0; - pZone->falseEasting = 6000000.0; - pZone->falseNorthing = 6000000.0; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(45.0, -90.0); - pZone->latLongBoundMax = udDouble2::create(160.0, -60.0); - break; - case 3112: // GDA94 / Geoscience Australia Lambert - pZone->datum = udGZGD_GDA94; - pZone->projection = udGZPT_LambertConformalConic2SP; - udStrcpy(pZone->zoneName, "Geoscience Australia Lambert"); - pZone->meridian = 134; - pZone->parallel = 0; - pZone->firstParallel = -18; - pZone->secondParallel = -36; - pZone->falseNorthing = 0; - pZone->falseEasting = 0; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(-60.56, 93.41); - pZone->latLongBoundMax = udDouble2::create(-8.47, 173.35); - break; - case 3113: // GDA94 / BCSG02 - pZone->datum = udGZGD_GDA94; - pZone->projection = udGZPT_TransverseMercator; - udStrcpy(pZone->zoneName, "BCSG02"); - pZone->meridian = 153; - pZone->parallel = -28; - pZone->falseNorthing = 100000; - pZone->falseEasting = 50000; - pZone->scaleFactor = 0.99999; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(-60.56, 93.41); - pZone->latLongBoundMax = udDouble2::create(-8.47, 173.35); - break; - case 3139: // Vanua Levu 1915 / Cassini Soldner Hyperbolic Test - pZone->datum = udGZGD_VANUA1915; - pZone->projection = udGZPT_CassiniSoldnerHyperbolic; - udStrcpy(pZone->zoneName, "Vanua Levu 1915"); - pZone->meridian = 179 + 1.0 / 3.0; - pZone->parallel = -16.25; - pZone->falseNorthing = 1662888.5; - pZone->falseEasting = 1251331.8; - pZone->scaleFactor = 1.0; - pZone->unitMetreScale = 0.201168; // Link Unit - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(-179.5, -17.05); - pZone->latLongBoundMax = udDouble2::create(178.25, -16.0); - break; - case 3174: // Great Lakes Albers / ALbers Conis Equal Area Projection Test - pZone->datum = udGZGD_NAD83; - pZone->projection = udGZPT_AlbersEqualArea; - udStrcpy(pZone->zoneName, "Great Lakes Albers"); - pZone->meridian = -84.455955; - pZone->latProjCentre = 45.568977; - pZone->falseNorthing = 1662888.5; - pZone->firstParallel = 42.122774; - pZone->secondParallel = 49.01518; - pZone->falseEasting = 1000000; - pZone->falseNorthing = 1000000; - pZone->scaleFactor = 1.0; - pZone->unitMetreScale = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(40.4, -93.21); - pZone->latLongBoundMax = udDouble2::create(50.74, -74.50); - break; - case 3414: // Singapore TM - pZone->datum = udGZGD_SVY21; - pZone->projection = udGZPT_TransverseMercator; - pZone->zone = 0; - udStrcpy(pZone->zoneName, "Singapore TM"); - pZone->meridian = 103 + (5.0 / 6.0); - pZone->parallel = 1 + (11.0 / 30.0); - pZone->falseNorthing = 38744.572; - pZone->falseEasting = 28001.642; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(1.1200, 103.6200); - pZone->latLongBoundMax = udDouble2::create(1.4600, 104.1600); - break; - case 3433: // Arkansas North - pZone->datum = udGZGD_NAD83; - pZone->projection = udGZPT_LambertConformalConic2SP; - pZone->zone = 0; - pZone->parallel = 34.33333333333334; // Can't be the fraction as rounds to '4' - pZone->firstParallel = 36.2 + (1.0/30); - pZone->secondParallel = 34.9 + (1.0/30); - pZone->meridian = -92; - pZone->falseNorthing = 0.0; - pZone->falseEasting = 1312333.3333; - pZone->scaleFactor = 1.0; - pZone->unitMetreScale = 0.3048006096012192; - udStrcpy(pZone->zoneName, "Arkansas North (ftUS)"); - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(34.67,-94.62); - pZone->latLongBoundMax = udDouble2::create(36.5,-89.64); - break; - case 3857: // Web Mercator - pZone->datum = udGZGD_WGS84; - pZone->projection = udGZPT_WebMercator; - pZone->zone = 0; - udStrcpy(pZone->zoneName, "Pseudo-Mercator"); - pZone->meridian = 0; - pZone->parallel = 0; - pZone->falseNorthing = 0; - pZone->falseEasting = 0; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(-85, -180); - pZone->latLongBoundMax = udDouble2::create(95, 180); - break; - case 4087: // WGS84 / World Equidistant Cylindrical + case 84: // LongLat (Not EPSG - CRS:84. There is no EPSG LongLat code) + pZone->datum = udGZGD_WGS84; + pZone->projection = udGZPT_LongLat; + pZone->zone = 0; + pZone->scaleFactor = 0.0174532925199433; + pZone->unitMetreScale = 1.0; + udStrcpy(pZone->zoneName, ""); + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(-90, -180); + pZone->latLongBoundMax = udDouble2::create(90, 180); + break; + case 2154: // RGF93 / Lambert-93 + pZone->datum = udGZGD_RGF93; + pZone->projection = udGZPT_LambertConformalConic2SP; + udStrcpy(pZone->zoneName, "Lambert-93"); + pZone->meridian = 3; + pZone->parallel = 46.5; + pZone->firstParallel = 49; + pZone->secondParallel = 44; + pZone->falseNorthing = 6600000; + pZone->falseEasting = 700000; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(41.1800, -9.6200); + pZone->latLongBoundMax = udDouble2::create(51.5400, 10.3000); + break; + case 9794: // RGF93 / Lambert-93 v2b + pZone->datum = udGZGD_RGF93v2b; + pZone->projection = udGZPT_LambertConformalConic2SP; + udStrcpy(pZone->zoneName, "Lambert-93"); + pZone->meridian = 3; + pZone->parallel = 46.5; + pZone->firstParallel = 49; + pZone->secondParallel = 44; + pZone->falseNorthing = 6600000; + pZone->falseEasting = 700000; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(41.1800, -9.6200); + pZone->latLongBoundMax = udDouble2::create(51.5400, 10.3000); + break; + case 2193: // NZGD2000 + pZone->datum = udGZGD_NZGD2000; + pZone->projection = udGZPT_TransverseMercator; + udStrcpy(pZone->zoneName, "New Zealand Transverse Mercator 2000"); + pZone->meridian = 173; + pZone->parallel = 0; + pZone->falseNorthing = 10000000; + pZone->falseEasting = 1600000; + pZone->scaleFactor = 0.9996; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(-47.4, 166.33); + pZone->latLongBoundMax = udDouble2::create(-34, 178.6); + break; + case 2230: // NAD83 / California zone 6 (ftUS) + pZone->datum = udGZGD_NAD83; + pZone->projection = udGZPT_LambertConformalConic2SP; + pZone->unitMetreScale = 0.3048006096012192; + udStrcpy(pZone->zoneName, "California zone 6 (ftUS)"); + pZone->meridian = -116.25; + pZone->parallel = 32.0 + 1.0 / 6.0; + pZone->firstParallel = 33.0 + 53.0 / 60.0; + pZone->secondParallel = 32.0 + 47.0 / 60.0; + pZone->falseNorthing = 1640416.667; + pZone->falseEasting = 6561666.667; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(23.81, -172.54); + pZone->latLongBoundMax = udDouble2::create(86.46, -47.74); + break; + case 2238: // NAD83 / Florida North (ftUS) + pZone->datum = udGZGD_NAD83; + pZone->projection = udGZPT_LambertConformalConic2SP; + pZone->unitMetreScale = 0.3048006096012192; + udStrcpy(pZone->zoneName, "Florida North (ftUS)"); + pZone->meridian = -84.5; + pZone->parallel = 29.0; + pZone->firstParallel = 30.75; + pZone->secondParallel = 29.0 + 175.0 / 300.0; + pZone->falseNorthing = 0.0; + pZone->falseEasting = 1968500.0; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(29.28, -87.64); + pZone->latLongBoundMax = udDouble2::create(31.0, -82.05); + break; + case 2248: // NAD83 / Maryland (ftUS) + pZone->datum = udGZGD_NAD83; + pZone->projection = udGZPT_LambertConformalConic2SP; + pZone->unitMetreScale = 0.3048006096012192; + udStrcpy(pZone->zoneName, "Maryland (ftUS)"); + pZone->meridian = -77.0; + pZone->parallel = 37.0 + 2.0 / 3.0; + pZone->firstParallel = 39.45; + pZone->secondParallel = 38.3; + pZone->falseNorthing = 0.0; + pZone->falseEasting = 1312333.333; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(37.88, -79.49); + pZone->latLongBoundMax = udDouble2::create(39.72, -74.98); + break; + case 2250: // NAD83 / Massachusetts Island (ftUS) + pZone->datum = udGZGD_NAD83; + pZone->projection = udGZPT_LambertConformalConic2SP; + pZone->unitMetreScale = 0.3048006096012192; + udStrcpy(pZone->zoneName, "Massachusetts Island (ftUS)"); + pZone->meridian = -70.5; + pZone->parallel = 41.0; + pZone->firstParallel = 41.0 + 145.0 / 300.0; + pZone->secondParallel = 41.0 + 85.0 / 300.0; + ; + pZone->falseNorthing = 0.0; + pZone->falseEasting = 1640416.667; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(41.2, -70.87); + pZone->latLongBoundMax = udDouble2::create(41.51, -69.9); + break; + case 2285: // NAD83 / Washington North (ftUS) + pZone->datum = udGZGD_NAD83; + pZone->projection = udGZPT_LambertConformalConic2SP; + pZone->unitMetreScale = 0.3048006096012192; + udStrcpy(pZone->zoneName, "Washington North (ftUS)"); + pZone->meridian = -120 - 25.0 / 30.0; + pZone->parallel = 47.0; + pZone->firstParallel = 48.0 + 22.0 / 30.0; + ; + pZone->secondParallel = 47.5; + pZone->falseNorthing = 0.0; + pZone->falseEasting = 1640416.667; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(47.08, -124.75); + pZone->latLongBoundMax = udDouble2::create(49.0, -117.03); + break; + case 2326: // Hong Kong 1980 Grid System + pZone->datum = udGZGD_HK1980; + pZone->projection = udGZPT_TransverseMercator; + udStrcpy(pZone->zoneName, "Hong Kong 1980 Grid System"); + pZone->meridian = 114.1785555555556; + pZone->parallel = 22.31213333333334; + pZone->falseNorthing = 819069.8; + pZone->falseEasting = 836694.05; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(22.13, 113.76); + pZone->latLongBoundMax = udDouble2::create(22.58, 114.51); + break; + case 2771: // NAD83(HARN) / California zone 6 + pZone->datum = udGZGD_NAD83_HARN; + pZone->projection = udGZPT_LambertConformalConic2SP; + udStrcpy(pZone->zoneName, "California zone 6"); + pZone->meridian = -116.25; + pZone->parallel = 32.0 + 1.0 / 6.0; + pZone->firstParallel = 33.0 + 265.0 / 300.0; + pZone->secondParallel = 32.0 + 235.0 / 300.0; + pZone->falseNorthing = 500000.0; + pZone->falseEasting = 2000000.0; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(32.51, -118.14); + pZone->latLongBoundMax = udDouble2::create(34.08, -114.43); + break; + case 3032: // WGS 84 / Australian Antartic Polar Sterographic + pZone->datum = udGZGD_WGS84; //udGZGD_AUST_ANT; + pZone->projection = udGZPT_SterographicPolar_vB; + udStrcpy(pZone->zoneName, "Australian Antarctic Polar Stereographic"); + pZone->meridian = 70.0; + pZone->parallel = -71.0; + pZone->falseEasting = 6000000.0; + pZone->falseNorthing = 6000000.0; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(45.0, -90.0); + pZone->latLongBoundMax = udDouble2::create(160.0, -60.0); + break; + case 3112: // GDA94 / Geoscience Australia Lambert + pZone->datum = udGZGD_GDA94; + pZone->projection = udGZPT_LambertConformalConic2SP; + udStrcpy(pZone->zoneName, "Geoscience Australia Lambert"); + pZone->meridian = 134; + pZone->parallel = 0; + pZone->firstParallel = -18; + pZone->secondParallel = -36; + pZone->falseNorthing = 0; + pZone->falseEasting = 0; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(-60.56, 93.41); + pZone->latLongBoundMax = udDouble2::create(-8.47, 173.35); + break; + case 3113: // GDA94 / BCSG02 + pZone->datum = udGZGD_GDA94; + pZone->projection = udGZPT_TransverseMercator; + udStrcpy(pZone->zoneName, "BCSG02"); + pZone->meridian = 153; + pZone->parallel = -28; + pZone->falseNorthing = 100000; + pZone->falseEasting = 50000; + pZone->scaleFactor = 0.99999; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(-60.56, 93.41); + pZone->latLongBoundMax = udDouble2::create(-8.47, 173.35); + break; + case 3139: // Vanua Levu 1915 / Cassini Soldner Hyperbolic Test + pZone->datum = udGZGD_VANUA1915; + pZone->projection = udGZPT_CassiniSoldnerHyperbolic; + udStrcpy(pZone->zoneName, "Vanua Levu 1915"); + pZone->meridian = 179 + 1.0 / 3.0; + pZone->parallel = -16.25; + pZone->falseNorthing = 1662888.5; + pZone->falseEasting = 1251331.8; + pZone->scaleFactor = 1.0; + pZone->unitMetreScale = 0.201168; // Link Unit + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(-179.5, -17.05); + pZone->latLongBoundMax = udDouble2::create(178.25, -16.0); + break; + case 3174: // Great Lakes Albers / ALbers Conis Equal Area Projection Test + pZone->datum = udGZGD_NAD83; + pZone->projection = udGZPT_AlbersEqualArea; + udStrcpy(pZone->zoneName, "Great Lakes Albers"); + pZone->meridian = -84.455955; + pZone->latProjCentre = 45.568977; + pZone->falseNorthing = 1662888.5; + pZone->firstParallel = 42.122774; + pZone->secondParallel = 49.01518; + pZone->falseEasting = 1000000; + pZone->falseNorthing = 1000000; + pZone->scaleFactor = 1.0; + pZone->unitMetreScale = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(40.4, -93.21); + pZone->latLongBoundMax = udDouble2::create(50.74, -74.50); + break; + case 3414: // Singapore TM + pZone->datum = udGZGD_SVY21; + pZone->projection = udGZPT_TransverseMercator; + pZone->zone = 0; + udStrcpy(pZone->zoneName, "Singapore TM"); + pZone->meridian = 103 + (5.0 / 6.0); + pZone->parallel = 1 + (11.0 / 30.0); + pZone->falseNorthing = 38744.572; + pZone->falseEasting = 28001.642; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(1.1200, 103.6200); + pZone->latLongBoundMax = udDouble2::create(1.4600, 104.1600); + break; + case 3433: // Arkansas North + pZone->datum = udGZGD_NAD83; + pZone->projection = udGZPT_LambertConformalConic2SP; + pZone->zone = 0; + pZone->parallel = 34.33333333333334; // Can't be the fraction as rounds to '4' + pZone->firstParallel = 36.2 + (1.0 / 30); + pZone->secondParallel = 34.9 + (1.0 / 30); + pZone->meridian = -92; + pZone->falseNorthing = 0.0; + pZone->falseEasting = 1312333.3333; + pZone->scaleFactor = 1.0; + pZone->unitMetreScale = 0.3048006096012192; + udStrcpy(pZone->zoneName, "Arkansas North (ftUS)"); + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(34.67, -94.62); + pZone->latLongBoundMax = udDouble2::create(36.5, -89.64); + break; + case 3857: // Web Mercator + pZone->datum = udGZGD_WGS84; + pZone->projection = udGZPT_WebMercator; + pZone->zone = 0; + udStrcpy(pZone->zoneName, "Pseudo-Mercator"); + pZone->meridian = 0; + pZone->parallel = 0; + pZone->falseNorthing = 0; + pZone->falseEasting = 0; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(-85, -180); + pZone->latLongBoundMax = udDouble2::create(95, 180); + break; + case 4087: // WGS84 / World Equidistant Cylindrical pZone->datum = udGZGD_WGS84; pZone->projection = udGZPT_EquidistantCylindrical; pZone->zone = 0; @@ -1200,241 +1201,241 @@ udResult udGeoZone_SetFromSRID(udGeoZone *pZone, int32_t sridCode) pZone->latLongBoundMin = udDouble2::create(-85, -180); pZone->latLongBoundMax = udDouble2::create(95, 180); break; - case 4326: // LatLong - pZone->datum = udGZGD_WGS84; - pZone->projection = udGZPT_LatLong; - pZone->zone = 0; - pZone->scaleFactor = 0.0174532925199433; - pZone->unitMetreScale = 1.0; - udStrcpy(pZone->zoneName, ""); - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(-90, -180); - pZone->latLongBoundMax = udDouble2::create(90, 180); - break; - case 4328: // ECEF (Deprecated) - pZone->datum = udGZGD_WGS84; - pZone->projection = udGZPT_ECEF; - pZone->zone = 0; - pZone->scaleFactor = 1.0; - pZone->unitMetreScale = 1.0; - udStrcpy(pZone->zoneName, ""); - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(-90, -180); - pZone->latLongBoundMax = udDouble2::create(90, 180); - break; - case 4936: // ETRS89 - pZone->datum = udGZGD_ETRS89; - pZone->projection = udGZPT_ECEF; - pZone->zone = 0; - pZone->scaleFactor = 1.0; - pZone->unitMetreScale = 1.0; - udStrcpy(pZone->zoneName, ""); - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(34.5, -10.67); - pZone->latLongBoundMax = udDouble2::create(71.05, 31.55); - break; - case 4978: // ECEF - pZone->datum = udGZGD_WGS84; - pZone->projection = udGZPT_ECEF; - pZone->zone = 0; - pZone->scaleFactor = 1.0; - pZone->unitMetreScale = 1.0; - udStrcpy(pZone->zoneName, ""); - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(-90, -180); - pZone->latLongBoundMax = udDouble2::create(90, 180); - break; - case 6411: // Arkansas North - pZone->datum = udGZGD_NAD83_2011; - pZone->projection = udGZPT_LambertConformalConic2SP; - pZone->zone = 0; - pZone->parallel = 34.33333333333334; // Can't be the fraction because it rounds to '4' - pZone->firstParallel = 36.2 + (1.0 / 30.0); - pZone->secondParallel = 34.9 + (1.0 / 30.0); - pZone->meridian = -92; - pZone->falseNorthing = 0.0; - pZone->falseEasting = 1312333.3333; - pZone->scaleFactor = 1.0; - pZone->unitMetreScale = 0.3048006096012192; - udStrcpy(pZone->zoneName, "Arkansas North (ftUS)"); - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(34.67,-94.62); - pZone->latLongBoundMax = udDouble2::create(36.5,-89.64); - break; - case 7845: // GDA2020 / Geoscience Australia Lambert - pZone->datum = udGZGD_GDA2020; - pZone->projection = udGZPT_LambertConformalConic2SP; - udStrcpy(pZone->zoneName, "GA LCC"); - pZone->meridian = 134; - pZone->parallel = 0; - pZone->firstParallel = -18; - pZone->secondParallel = -36; - pZone->falseNorthing = 0; - pZone->falseEasting = 0; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(-43.7, 112.85); - pZone->latLongBoundMax = udDouble2::create(-9.86, 153.69); - break; - case 8353: // Slovakia Krovak - pZone->datum = udGZGD_SJTSK03; - pZone->projection = udGZPT_KrovakNorthOrientated; - pZone->zone = 0; - udStrcpy(pZone->zoneName, "JTSK03"); - pZone->latProjCentre = 49.5000000000003; - pZone->coLatConeAxis = 30.2881397527781; - pZone->meridian = 24.8333333333336; - pZone->parallel = 78.5; //78.5000000000003 - pZone->falseNorthing = 0; - pZone->falseEasting = 0; - pZone->scaleFactor = 0.9999; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(1.13, 103.59); - pZone->latLongBoundMax = udDouble2::create(1.47, 104.07); - break; - case 8705: // Mars PF - pZone->datum = udGZGD_MARS_PCPF; - pZone->projection = udGZPT_ECEF; - pZone->zone = 0; - pZone->scaleFactor = 1.0; - pZone->unitMetreScale = 1.0; - udGeoZone_SetSpheroid(pZone); - break; - case 19920: // Singapore Grid - pZone->datum = udGZGD_SINGGRID; - pZone->projection = udGZPT_CassiniSoldner; - pZone->zone = 0; - udStrcpy(pZone->zoneName, "Singapore Grid"); - pZone->meridian = 103.853002222; - pZone->parallel = 1.287646667; - pZone->falseNorthing = 30000; - pZone->falseEasting = 30000; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(1.13, 103.59); - pZone->latLongBoundMax = udDouble2::create(1.47, 104.07); - break; - case 27700: // OSGB 1936 / British National Grid - pZone->datum = udGZGD_OSGB36; - pZone->projection = udGZPT_TransverseMercator; - udStrcpy(pZone->zoneName, "British National Grid"); - pZone->meridian = -2; - pZone->parallel = 49.0; - pZone->falseNorthing = -100000; - pZone->falseEasting = 400000; - pZone->scaleFactor = 0.9996012717; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(-7.5600, 49.9600); - pZone->latLongBoundMax = udDouble2::create(1.7800, 60.8400); - break; - case 28992: // Amersfoort / Stereographic oblique and Equatorial Projection Test - pZone->datum = udGZGD_AMERSFOORT; - pZone->projection = udGZPT_SterographicObliqueNEquatorial; - pZone->zone = 0; - udStrcpy(pZone->zoneName, "Amersfoort"); - pZone->meridian = 5.3876388888888888; - pZone->parallel = 52.156160555555556; - pZone->falseNorthing = 463000; - pZone->falseEasting = 155000; - pZone->scaleFactor = 0.9999079; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(3.37,50.75); - pZone->latLongBoundMax = udDouble2::create(7.21, 53.47); - break; - case 29873: // Timbalai 1948 / Hotine Oblique Mercator Variant B Projection Test - pZone->datum = udGZGD_TIMB1948; - pZone->projection = udGZPT_HotineObliqueMercatorvB; - pZone->zone = 0; - udStrcpy(pZone->zoneName, "Timbalai 1948"); - pZone->meridian = 115.0; - pZone->parallel = 53.13010236111111; - pZone->coLatConeAxis = 53.31582047222222; - pZone->latProjCentre = 4.0; - pZone->falseNorthing = 442857.65; - pZone->falseEasting = 590476.87; - pZone->scaleFactor = 0.99984; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(0.85, 109.55); - pZone->latLongBoundMax = udDouble2::create(7.35, 119.26); - break; - //case 30100: - case 30101: //Moon PF - pZone->datum = udGZGD_MOON_PCPF; - pZone->projection = udGZPT_ECEF; - pZone->zone = 30101; - pZone->falseNorthing = 0; - pZone->falseEasting = 0; - pZone->meridian = 0; - pZone->scaleFactor = 1; - pZone->parallel = 0; - udGeoZone_SetSpheroid(pZone); - break; - //case 30174: - case 30175: //Moon M - pZone->datum = udGZGD_MOON_MERC; - pZone->projection = udGZPT_Mercator; - udStrcpy(pZone->zoneName, "Moon 2000 Mercator"); - pZone->zone = 30175; - pZone->falseNorthing = 0; - pZone->falseEasting = 0; - pZone->meridian = 0; - pZone->firstParallel = 0; - pZone->scaleFactor = 1.0; - udGeoZone_SetSpheroid(pZone); - break; - case 30200: // Trinidad 1903 / Cassini Soldner Projection Test - pZone->datum = udGZGD_TRI1903; - pZone->projection = udGZPT_CassiniSoldner; - pZone->zone = 0; - udStrcpy(pZone->zoneName, "Trinidad 1903"); - pZone->meridian = -61.0 - (1.0 / 3.0); - pZone->parallel = 10.441 + (2.0 / (3.0 * 1000.0)); - pZone->falseNorthing = 325000; - pZone->falseEasting = 430000; - pZone->scaleFactor = 1.0; - pZone->unitMetreScale = 0.201166195164; // Clarke's link Unit - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(-62.08, 9.82); - pZone->latLongBoundMax = udDouble2::create(-58.53, 11.68); - break; - case 31700: // Dealul Piscului 1970/ Stereo 70 - pZone->datum = udGZGD_DEALUL1970; - pZone->projection = udGZPT_SterographicObliqueNEquatorial; - pZone->zone = 0; - udStrcpy(pZone->zoneName, "Dealul Piscului 1970"); - pZone->meridian = 25.0; - pZone->parallel = 46.0; - pZone->falseNorthing = 500000; - pZone->falseEasting = 500000; - pZone->scaleFactor = 0.99975; - udGeoZone_SetSpheroid(pZone); - pZone->latLongBoundMin = udDouble2::create(43.62, 20.26); - pZone->latLongBoundMax = udDouble2::create(48.26, 31.5); - break; - //case 49974: - case 49975: //Mars M - pZone->datum = udGZGD_MARS_MERC; - pZone->projection = udGZPT_Mercator; - udStrcpy(pZone->zoneName, "Mars 2000 Mercator"); - pZone->zone = 49975; - pZone->falseNorthing = 0; - pZone->falseEasting = 0; - pZone->meridian = 0; - pZone->scaleFactor = 1.0; - pZone->firstParallel = 0; - udGeoZone_SetSpheroid(pZone); - break; - - default: - { - udScopeLock scopeLock(g_pMutex); + case 4326: // LatLong + pZone->datum = udGZGD_WGS84; + pZone->projection = udGZPT_LatLong; + pZone->zone = 0; + pZone->scaleFactor = 0.0174532925199433; + pZone->unitMetreScale = 1.0; + udStrcpy(pZone->zoneName, ""); + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(-90, -180); + pZone->latLongBoundMax = udDouble2::create(90, 180); + break; + case 4328: // ECEF (Deprecated) + pZone->datum = udGZGD_WGS84; + pZone->projection = udGZPT_ECEF; + pZone->zone = 0; + pZone->scaleFactor = 1.0; + pZone->unitMetreScale = 1.0; + udStrcpy(pZone->zoneName, ""); + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(-90, -180); + pZone->latLongBoundMax = udDouble2::create(90, 180); + break; + case 4936: // ETRS89 + pZone->datum = udGZGD_ETRS89; + pZone->projection = udGZPT_ECEF; + pZone->zone = 0; + pZone->scaleFactor = 1.0; + pZone->unitMetreScale = 1.0; + udStrcpy(pZone->zoneName, ""); + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(34.5, -10.67); + pZone->latLongBoundMax = udDouble2::create(71.05, 31.55); + break; + case 4978: // ECEF + pZone->datum = udGZGD_WGS84; + pZone->projection = udGZPT_ECEF; + pZone->zone = 0; + pZone->scaleFactor = 1.0; + pZone->unitMetreScale = 1.0; + udStrcpy(pZone->zoneName, ""); + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(-90, -180); + pZone->latLongBoundMax = udDouble2::create(90, 180); + break; + case 6411: // Arkansas North + pZone->datum = udGZGD_NAD83_2011; + pZone->projection = udGZPT_LambertConformalConic2SP; + pZone->zone = 0; + pZone->parallel = 34.33333333333334; // Can't be the fraction because it rounds to '4' + pZone->firstParallel = 36.2 + (1.0 / 30.0); + pZone->secondParallel = 34.9 + (1.0 / 30.0); + pZone->meridian = -92; + pZone->falseNorthing = 0.0; + pZone->falseEasting = 1312333.3333; + pZone->scaleFactor = 1.0; + pZone->unitMetreScale = 0.3048006096012192; + udStrcpy(pZone->zoneName, "Arkansas North (ftUS)"); + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(34.67, -94.62); + pZone->latLongBoundMax = udDouble2::create(36.5, -89.64); + break; + case 7845: // GDA2020 / Geoscience Australia Lambert + pZone->datum = udGZGD_GDA2020; + pZone->projection = udGZPT_LambertConformalConic2SP; + udStrcpy(pZone->zoneName, "GA LCC"); + pZone->meridian = 134; + pZone->parallel = 0; + pZone->firstParallel = -18; + pZone->secondParallel = -36; + pZone->falseNorthing = 0; + pZone->falseEasting = 0; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(-43.7, 112.85); + pZone->latLongBoundMax = udDouble2::create(-9.86, 153.69); + break; + case 8353: // Slovakia Krovak + pZone->datum = udGZGD_SJTSK03; + pZone->projection = udGZPT_KrovakNorthOrientated; + pZone->zone = 0; + udStrcpy(pZone->zoneName, "JTSK03"); + pZone->latProjCentre = 49.5000000000003; + pZone->coLatConeAxis = 30.2881397527781; + pZone->meridian = 24.8333333333336; + pZone->parallel = 78.5; //78.5000000000003 + pZone->falseNorthing = 0; + pZone->falseEasting = 0; + pZone->scaleFactor = 0.9999; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(1.13, 103.59); + pZone->latLongBoundMax = udDouble2::create(1.47, 104.07); + break; + case 8705: // Mars PF + pZone->datum = udGZGD_MARS_PCPF; + pZone->projection = udGZPT_ECEF; + pZone->zone = 0; + pZone->scaleFactor = 1.0; + pZone->unitMetreScale = 1.0; + udGeoZone_SetSpheroid(pZone); + break; + case 19920: // Singapore Grid + pZone->datum = udGZGD_SINGGRID; + pZone->projection = udGZPT_CassiniSoldner; + pZone->zone = 0; + udStrcpy(pZone->zoneName, "Singapore Grid"); + pZone->meridian = 103.853002222; + pZone->parallel = 1.287646667; + pZone->falseNorthing = 30000; + pZone->falseEasting = 30000; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(1.13, 103.59); + pZone->latLongBoundMax = udDouble2::create(1.47, 104.07); + break; + case 27700: // OSGB 1936 / British National Grid + pZone->datum = udGZGD_OSGB36; + pZone->projection = udGZPT_TransverseMercator; + udStrcpy(pZone->zoneName, "British National Grid"); + pZone->meridian = -2; + pZone->parallel = 49.0; + pZone->falseNorthing = -100000; + pZone->falseEasting = 400000; + pZone->scaleFactor = 0.9996012717; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(-7.5600, 49.9600); + pZone->latLongBoundMax = udDouble2::create(1.7800, 60.8400); + break; + case 28992: // Amersfoort / Stereographic oblique and Equatorial Projection Test + pZone->datum = udGZGD_AMERSFOORT; + pZone->projection = udGZPT_SterographicObliqueNEquatorial; + pZone->zone = 0; + udStrcpy(pZone->zoneName, "Amersfoort"); + pZone->meridian = 5.3876388888888888; + pZone->parallel = 52.156160555555556; + pZone->falseNorthing = 463000; + pZone->falseEasting = 155000; + pZone->scaleFactor = 0.9999079; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(3.37, 50.75); + pZone->latLongBoundMax = udDouble2::create(7.21, 53.47); + break; + case 29873: // Timbalai 1948 / Hotine Oblique Mercator Variant B Projection Test + pZone->datum = udGZGD_TIMB1948; + pZone->projection = udGZPT_HotineObliqueMercatorvB; + pZone->zone = 0; + udStrcpy(pZone->zoneName, "Timbalai 1948"); + pZone->meridian = 115.0; + pZone->parallel = 53.13010236111111; + pZone->coLatConeAxis = 53.31582047222222; + pZone->latProjCentre = 4.0; + pZone->falseNorthing = 442857.65; + pZone->falseEasting = 590476.87; + pZone->scaleFactor = 0.99984; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(0.85, 109.55); + pZone->latLongBoundMax = udDouble2::create(7.35, 119.26); + break; + //case 30100: + case 30101: //Moon PF + pZone->datum = udGZGD_MOON_PCPF; + pZone->projection = udGZPT_ECEF; + pZone->zone = 30101; + pZone->falseNorthing = 0; + pZone->falseEasting = 0; + pZone->meridian = 0; + pZone->scaleFactor = 1; + pZone->parallel = 0; + udGeoZone_SetSpheroid(pZone); + break; + //case 30174: + case 30175: //Moon M + pZone->datum = udGZGD_MOON_MERC; + pZone->projection = udGZPT_Mercator; + udStrcpy(pZone->zoneName, "Moon 2000 Mercator"); + pZone->zone = 30175; + pZone->falseNorthing = 0; + pZone->falseEasting = 0; + pZone->meridian = 0; + pZone->firstParallel = 0; + pZone->scaleFactor = 1.0; + udGeoZone_SetSpheroid(pZone); + break; + case 30200: // Trinidad 1903 / Cassini Soldner Projection Test + pZone->datum = udGZGD_TRI1903; + pZone->projection = udGZPT_CassiniSoldner; + pZone->zone = 0; + udStrcpy(pZone->zoneName, "Trinidad 1903"); + pZone->meridian = -61.0 - (1.0 / 3.0); + pZone->parallel = 10.441 + (2.0 / (3.0 * 1000.0)); + pZone->falseNorthing = 325000; + pZone->falseEasting = 430000; + pZone->scaleFactor = 1.0; + pZone->unitMetreScale = 0.201166195164; // Clarke's link Unit + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(-62.08, 9.82); + pZone->latLongBoundMax = udDouble2::create(-58.53, 11.68); + break; + case 31700: // Dealul Piscului 1970/ Stereo 70 + pZone->datum = udGZGD_DEALUL1970; + pZone->projection = udGZPT_SterographicObliqueNEquatorial; + pZone->zone = 0; + udStrcpy(pZone->zoneName, "Dealul Piscului 1970"); + pZone->meridian = 25.0; + pZone->parallel = 46.0; + pZone->falseNorthing = 500000; + pZone->falseEasting = 500000; + pZone->scaleFactor = 0.99975; + udGeoZone_SetSpheroid(pZone); + pZone->latLongBoundMin = udDouble2::create(43.62, 20.26); + pZone->latLongBoundMax = udDouble2::create(48.26, 31.5); + break; + //case 49974: + case 49975: //Mars M + pZone->datum = udGZGD_MARS_MERC; + pZone->projection = udGZPT_Mercator; + udStrcpy(pZone->zoneName, "Mars 2000 Mercator"); + pZone->zone = 49975; + pZone->falseNorthing = 0; + pZone->falseEasting = 0; + pZone->meridian = 0; + pZone->scaleFactor = 1.0; + pZone->firstParallel = 0; + udGeoZone_SetSpheroid(pZone); + break; - int index = udGeoZone_InternalIndexOf(sridCode); - if (index >= 0) - *pZone = g_InternalGeoZoneList[index]; - else - return udR_NotFound; - } + default: + { + udScopeLock scopeLock(g_pMutex); + + int index = udGeoZone_InternalIndexOf(sridCode); + if (index >= 0) + *pZone = g_InternalGeoZoneList[index]; + else + return udR_NotFound; + } } } @@ -1478,9 +1479,9 @@ static void udGeoZone_MetreScaleSpheroidMaths(udGeoZone *pZone) pZone->semiMajorAxis /= pZone->unitMetreScale; double a = pZone->semiMajorAxis; double f = pZone->flattening; - double b = a * (1 - f); // b=a*(1-f) - pZone->semiMinorAxis = b; // in feet or metres - pZone->eccentricity = udSqrt(a*a - b*b) / a; // e=sqrt(a^2-b^2)/a + double b = a * (1 - f); // b=a*(1-f) + pZone->semiMinorAxis = b; // in feet or metres + pZone->eccentricity = udSqrt(a * a - b * b) / a; // e=sqrt(a^2-b^2)/a pZone->eccentricitySq = udPow(pZone->eccentricity, 2); pZone->thirdFlattening = (a - b) / (a + b); // tf=(a-b)/(a+b) udGeoZone_SetSpheroid(pZone); @@ -1733,8 +1734,8 @@ static void udGeoZone_JSONTreeSearch(udGeoZone *pZone, udJSON *wkt, const char * else if (udStrstr(pName, 0, "Polar_Stereographic")) { pZone->projection = udGZPT_SterographicPolar_vB; - if (pZone->scaleFactor == 0) // default for Polar Stereo is 1.0 - pZone->scaleFactor = 1.0; + if (pZone->scaleFactor == 0) // default for Polar Stereo is 1.0 + pZone->scaleFactor = 1.0; } else if (udStrstr(pName, 0, "Krovak (North Orientated)")) { @@ -1849,9 +1850,9 @@ udResult udGeoZone_SetFromWKT(udGeoZone *pZone, const char *pWKT) // if unknown Datum and known spheroid -> fill datumDescriptor table with parameters read from the JSON if (!pZone->knownDatum && pZone->zoneSpheroid != udGZE_Count) { - // Full Name, Short name, Datum name, Ellipsoid index, ToWGS84 parameters, epsg, auth, AxisInfo, ToWGS84 - g_InternalDatumList.PushBack(udGeoZoneGeodeticDatumDescriptor{ pZone->datumName, pZone->datumShortName, pZone->datumName, pZone->zoneSpheroid, {pZone->paramsHelmert7[0], pZone->paramsHelmert7[1], pZone->paramsHelmert7[2], pZone->paramsHelmert7[3], pZone->paramsHelmert7[4], pZone->paramsHelmert7[5], pZone->paramsHelmert7[6]}, pZone->srid, pZone->datumSrid, pZone->axisInfo, pZone->toWGS84 }); - pZone->datum = (udGeoZoneGeodeticDatum) ((int)udGZGD_Count + g_InternalDatumList.length); + // Full Name, Short name, Datum name, Ellipsoid index, ToWGS84 parameters, epsg, auth, AxisInfo, ToWGS84 + g_InternalDatumList.PushBack(udGeoZoneGeodeticDatumDescriptor{ pZone->datumName, pZone->datumShortName, pZone->datumName, pZone->zoneSpheroid, { pZone->paramsHelmert7[0], pZone->paramsHelmert7[1], pZone->paramsHelmert7[2], pZone->paramsHelmert7[3], pZone->paramsHelmert7[4], pZone->paramsHelmert7[5], pZone->paramsHelmert7[6] }, pZone->srid, pZone->datumSrid, pZone->axisInfo, pZone->toWGS84 }); + pZone->datum = (udGeoZoneGeodeticDatum)((int)udGZGD_Count + g_InternalDatumList.length); } //reset zone params used above @@ -1900,15 +1901,16 @@ udResult udGeoZone_GetWellKnownText(const char **ppWKT, const udGeoZone &zone) // If the ellipsoid isn't WGS84, then provide parameters to get to WGS84 if (pDesc->exportToWGS84) { - int decimalPlaces = zone.datum == udGZGD_HK1980 ? 7 : zone.datum == udGZGD_MGI ? 4 : 3; + int decimalPlaces = zone.datum == udGZGD_HK1980 ? 7 : zone.datum == udGZGD_MGI ? 4 + : 3; udSprintf(&pWKTToWGS84, ",\nTOWGS84[%s,%s,%s,%s,%s,%s,%s]", - udTempStr_TrimDouble(pDesc->paramsHelmert7[0], 3), - udTempStr_TrimDouble(pDesc->paramsHelmert7[1], 3), - udTempStr_TrimDouble(pDesc->paramsHelmert7[2], 3), - udTempStr_TrimDouble(pDesc->paramsHelmert7[3], decimalPlaces), - udTempStr_TrimDouble(pDesc->paramsHelmert7[4], decimalPlaces), - udTempStr_TrimDouble(pDesc->paramsHelmert7[5], decimalPlaces), - udTempStr_TrimDouble(pDesc->paramsHelmert7[6], decimalPlaces)); + udTempStr_TrimDouble(pDesc->paramsHelmert7[0], 3), + udTempStr_TrimDouble(pDesc->paramsHelmert7[1], 3), + udTempStr_TrimDouble(pDesc->paramsHelmert7[2], 3), + udTempStr_TrimDouble(pDesc->paramsHelmert7[3], decimalPlaces), + udTempStr_TrimDouble(pDesc->paramsHelmert7[4], decimalPlaces), + udTempStr_TrimDouble(pDesc->paramsHelmert7[5], decimalPlaces), + udTempStr_TrimDouble(pDesc->paramsHelmert7[6], decimalPlaces)); } udSprintf(&pWKTSpheroid, "SPHEROID[\"%s\",%s,%s,\nAUTHORITY[\"EPSG\",\"%d\"]]", pEllipsoid->pName, udTempStr_TrimDouble(pEllipsoid->semiMajorAxis, 8), pEllipsoid->flattening == 0.0 ? "0.0" : udTempStr_TrimDouble(1.0 / pEllipsoid->flattening, 9), pEllipsoid->authorityEpsg); @@ -1941,87 +1943,87 @@ udResult udGeoZone_GetWellKnownText(const char **ppWKT, const udGeoZone &zone) { udSprintf(&pWKTProjection, "PROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",%s],\nPARAMETER[\"central_meridian\",%s]," "\nPARAMETER[\"scale_factor\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } else if (zone.projection == udGZPT_LambertConformalConic2SP) { udSprintf(&pWKTProjection, "PROJECTION[\"Lambert_Conformal_Conic_2SP\"],\nPARAMETER[\"standard_parallel_1\",%s],\nPARAMETER[\"standard_parallel_2\",%s]," "\nPARAMETER[\"latitude_of_origin\",%s],\nPARAMETER[\"central_meridian\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.firstParallel, parallelPrecision, 0, true), udTempStr_TrimDouble(zone.secondParallel, parallelPrecision), udTempStr_TrimDouble(zone.parallel, parallelPrecision, 0, true), udTempStr_TrimDouble(zone.meridian, meridianPrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.firstParallel, parallelPrecision, 0, true), udTempStr_TrimDouble(zone.secondParallel, parallelPrecision), udTempStr_TrimDouble(zone.parallel, parallelPrecision, 0, true), udTempStr_TrimDouble(zone.meridian, meridianPrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } else if (zone.projection == udGZPT_WebMercator) { udSprintf(&pWKTProjection, "PROJECTION[\"Mercator_1SP\"],\nPARAMETER[\"central_meridian\",%s],\nPARAMETER[\"scale_factor\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } else if (zone.projection == udGZPT_CassiniSoldner) { udSprintf(&pWKTProjection, "PROJECTION[\"Cassini_Soldner\"],\nPARAMETER[\"latitude_of_origin\",%s],\nPARAMETER[\"central_meridian\",%s],\nPARAMETER[\"scale_factor\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } else if (zone.projection == udGZPT_CassiniSoldnerHyperbolic) { udSprintf(&pWKTProjection, "PROJECTION[\"Hyperbolic_Cassini_Soldner\"],\nPARAMETER[\"latitude_of_origin\",%s],\nPARAMETER[\"central_meridian\",%s],\nPARAMETER[\"scale_factor\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } else if (zone.projection == udGZPT_SterographicObliqueNEquatorial) { udSprintf(&pWKTProjection, "PROJECTION[\"Oblique_Stereographic\"],\nPARAMETER[\"latitude_of_origin\",%s],\nPARAMETER[\"central_meridian\",%s],\nPARAMETER[\"scale_factor\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } else if (zone.projection == udGZPT_Mercator) { udSprintf(&pWKTProjection, "PROJECTION[\"Mercator\"],\nPARAMETER[\"False_Easting\",%s],\nPARAMETER[\"False_Northing\",%s],\nPARAMETER[\"Central_Meridian\",%s],\nPARAMETER[\"Standard_Parallel_1\",%s],\n%s", - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), - udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.firstParallel, parallelPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), + udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.firstParallel, parallelPrecision), pWKTUnit); } else if (zone.projection == udGZPT_SterographicPolar_vB) { udSprintf(&pWKTProjection, "PROJECTION[\"Polar_Stereographic\"],\nPARAMETER[\"latitude_of_origin\",%s],\nPARAMETER[\"central_meridian\",%s],\nPARAMETER[\"scale_factor\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } else if (zone.projection == udGZPT_Krovak) { udSprintf(&pWKTProjection, "PROJECTION[\"Krovak\"],\nPARAMETER[\"latitude_projection_centre\",%s],\nPARAMETER[\"latitude_of_origin\",%s],\nPARAMETER[\"colatitude_cone_axis\",%s],\nPARAMETER[\"central_meridian\",%s],\nPARAMETER[\"scale_factor\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.latProjCentre, parallelPrecision), udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.coLatConeAxis, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.latProjCentre, parallelPrecision), udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.coLatConeAxis, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } else if (zone.projection == udGZPT_KrovakNorthOrientated) { udSprintf(&pWKTProjection, "PROJECTION[\"Krovak (North Orientated)\"],\nPARAMETER[\"latitude_projection_centre\",%s],\nPARAMETER[\"latitude_of_origin\",%s],\nPARAMETER[\"colatitude_cone_axis\",%s],\nPARAMETER[\"central_meridian\",%s],\nPARAMETER[\"scale_factor\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.latProjCentre, parallelPrecision), udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.coLatConeAxis, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.latProjCentre, parallelPrecision), udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.coLatConeAxis, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } else if (zone.projection == udGZPT_HotineObliqueMercatorvA) { udSprintf(&pWKTProjection, "PROJECTION[\"Hotine_Oblique_Mercator\"],\nPARAMETER[\"latitude_of_center\",%s],\nPARAMETER[\"longitude_of_center\",%s],\nPARAMETER[\"azimuth\",%s],\nPARAMETER[\"rectified_grid_angle\",%s],\nPARAMETER[\"scale_factor\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.latProjCentre, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.coLatConeAxis, parallelPrecision), udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.latProjCentre, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.coLatConeAxis, parallelPrecision), udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } else if (zone.projection == udGZPT_HotineObliqueMercatorvB) { udSprintf(&pWKTProjection, "PROJECTION[\"Hotine_Oblique_Mercator_Azimuth_Center\"],\nPARAMETER[\"latitude_of_center\",%s],\nPARAMETER[\"longitude_of_center\",%s],\nPARAMETER[\"azimuth\",%s],\nPARAMETER[\"rectified_grid_angle\",%s],\nPARAMETER[\"scale_factor\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.latProjCentre, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.coLatConeAxis, parallelPrecision), udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.latProjCentre, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.coLatConeAxis, parallelPrecision), udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.scaleFactor, scalePrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } else if (zone.projection == udGZPT_AlbersEqualArea) { udSprintf(&pWKTProjection, "PROJECTION[\"Albers_Conic_Equal_Area\"],\nPARAMETER[\"latitude_of_center\",%s],\nPARAMETER[\"longitude_of_center\",%s],\nPARAMETER[\"standard_parallel_1\",%s],\nPARAMETER[\"standard_parallel_2\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.latProjCentre, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.firstParallel, parallelPrecision), udTempStr_TrimDouble(zone.secondParallel, parallelPrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.latProjCentre, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), udTempStr_TrimDouble(zone.firstParallel, parallelPrecision), udTempStr_TrimDouble(zone.secondParallel, parallelPrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } else if (zone.projection == udGZPT_EquidistantCylindrical) { udSprintf(&pWKTProjection, "PROJECTION[\"Equirectangular\"],\nPARAMETER[\"latitude_of_origin\",%s],\nPARAMETER[\"central_meridian\",%s],\nPARAMETER[\"false_easting\",%s],\nPARAMETER[\"false_northing\",%s],\n%s", - udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), - udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); + udTempStr_TrimDouble(zone.parallel, parallelPrecision), udTempStr_TrimDouble(zone.meridian, meridianPrecision), + udTempStr_TrimDouble(zone.falseEasting, falseOriginPrecision), udTempStr_TrimDouble(zone.falseNorthing, falseOriginPrecision), pWKTUnit); } // JGD2000, JGD2011 and CGCS2000 doesn't provide axis information @@ -2079,37 +2081,27 @@ static double udGeoZone_LCCLatConverge(double t, double td, double e) // ---------------------------------------------------------------------------- // Author: Lauren Jones, June 2018 static double udGeoZone_LCCMeridonial(double phi, double e) - { - double d = e * udSin(phi); - return udCos(phi) / udSqrt(1 - d * d); - } +{ + double d = e * udSin(phi); + return udCos(phi) / udSqrt(1 - d * d); +} // ---------------------------------------------------------------------------- // Author: Lauren Jones, June 2018 static double udGeoZone_LCCConformal(double phi, double e) - { - double d = e * udSin(phi); - return udTan(UD_PI / 4.0 - phi / 2.0) / udPow((1 - d) / (1 + d), e / 2.0); - } +{ + double d = e * udSin(phi); + return udTan(UD_PI / 4.0 - phi / 2.0) / udPow((1 - d) / (1 + d), e / 2.0); +} // ---------------------------------------------------------------------------- // Author: Jules Proust, September 2020 -static double udGeoZone_MeridianArcDistance(const double phi, const double* n) +static double udGeoZone_MeridianArcDistance(const double phi, const double *n) { // Helmert's series // Maxima: // trigreduce( defint(taylor((1-n^2)^2/(2 * n * cos(2*t) + n^2 + 1)^(3/2), n, 0,9),t,0,phi) ); - return (phi * (82575360.0 + 185794560.0 * n[2] + 290304000.0 * n[4] + 395136000.0 * n[6] + 500094000.0 * n[8]) - + udSin(2.0 * phi) * (-123863040.0 * n[1] - 232243200.0 * n[3] - 338688000.0 * n[5] - 444528000.0 * n[7] - 550103400.0 * n[9]) - + udSin(4.0 * phi) * (77414400.0 * n[2] + 135475200.0 * n[4] + 190512000.0 * n[6] + 244490400.0 * n[8]) - + udSin(6.0 * phi) * (-60211200.0 * n[3] - 101606400.0 * n[5] - 139708800.0 * n[7] - 176576400.0 * n[9]) - + udSin(8.0 * phi) * (50803200.0 * n[4] + 83825280.0 * n[6] + 113513400.0 * n[8]) - + udSin(10.0 * phi) * (-44706816.0 * n[5] - 72648576.0 * n[7] - 97297200.0 * n[9]) - + udSin(12.0 * phi) * (40360320.0 * n[6] + 64864800.0 * n[8]) - + udSin(14.0 * phi) * (-37065600.0 * n[7] - 59073300.0 * n[9]) - + udSin(16.0 * phi) * (34459425.0 * n[8]) - + udSin(18.0 * phi) * (-32332300.0 * n[9]) - ) / 82575360.0; + return (phi * (82575360.0 + 185794560.0 * n[2] + 290304000.0 * n[4] + 395136000.0 * n[6] + 500094000.0 * n[8]) + udSin(2.0 * phi) * (-123863040.0 * n[1] - 232243200.0 * n[3] - 338688000.0 * n[5] - 444528000.0 * n[7] - 550103400.0 * n[9]) + udSin(4.0 * phi) * (77414400.0 * n[2] + 135475200.0 * n[4] + 190512000.0 * n[6] + 244490400.0 * n[8]) + udSin(6.0 * phi) * (-60211200.0 * n[3] - 101606400.0 * n[5] - 139708800.0 * n[7] - 176576400.0 * n[9]) + udSin(8.0 * phi) * (50803200.0 * n[4] + 83825280.0 * n[6] + 113513400.0 * n[8]) + udSin(10.0 * phi) * (-44706816.0 * n[5] - 72648576.0 * n[7] - 97297200.0 * n[9]) + udSin(12.0 * phi) * (40360320.0 * n[6] + 64864800.0 * n[8]) + udSin(14.0 * phi) * (-37065600.0 * n[7] - 59073300.0 * n[9]) + udSin(16.0 * phi) * (34459425.0 * n[8]) + udSin(18.0 * phi) * (-32332300.0 * n[9])) / 82575360.0; } // ---------------------------------------------------------------------------- @@ -2127,11 +2119,8 @@ static double udGeoZone_LatMeridianSameNorthing(const double mu, const double e) { // Reverted Helmert's series .... Lack of precision need investigation on Maxima // http://www.mygeodesy.id.au/documents/Meridian%20Distance.pdf p.20 eq.61 - return mu - + (3.0 / 2.0 * e - 20.0 / 32.0 * udPow(e,3)) * udSin(2 * mu) - + (21.0 / 16.0 * udPow(e,2) - 55.0 / 32.0 * udPow(e,4)) * udSin(4 * mu) - + 121.0 / 96.0 * udPow(e,3) * udSin(6 * mu) - + 1097.0 / 512.0 * udPow(e,4) * udSin(8 * mu);; + return mu + (3.0 / 2.0 * e - 20.0 / 32.0 * udPow(e, 3)) * udSin(2 * mu) + (21.0 / 16.0 * udPow(e, 2) - 55.0 / 32.0 * udPow(e, 4)) * udSin(4 * mu) + 121.0 / 96.0 * udPow(e, 3) * udSin(6 * mu) + 1097.0 / 512.0 * udPow(e, 4) * udSin(8 * mu); + ; } // ---------------------------------------------------------------------------- @@ -2207,8 +2196,8 @@ udDouble3 udGeoZone_LatLongToCartesian(const udGeoZone &zone, const udDouble3 &l double t2 = udGeoZone_LCCConformal(phi2, e); double n = (udLogN(m1) - udLogN(m2)) / (udLogN(t1) - udLogN(t2)); double F = m1 / (n * udPow(t1, n)); - double p0 = zone.semiMajorAxis * F * udPow(tOrigin, n); - double p = zone.semiMajorAxis * F * udPow(t, n); + double p0 = zone.semiMajorAxis * F * udPow(tOrigin, n); + double p = zone.semiMajorAxis * F * udPow(t, n); X = p * udSin(n * omega); Y = p0 - p * udCos(n * omega); @@ -2220,7 +2209,7 @@ udDouble3 udGeoZone_LatLongToCartesian(const udGeoZone &zone, const udDouble3 &l omega = UD_DEG2RAD(omega - zone.meridian); X = zone.semiMajorAxis * omega; - Y = zone.semiMajorAxis * udLogN(udTan(UD_PI/4.0 + phi/2.0)); + Y = zone.semiMajorAxis * udLogN(udTan(UD_PI / 4.0 + phi / 2.0)); return udDouble3::create(X + zone.falseEasting, Y + zone.falseNorthing, ellipsoidHeight); } @@ -2268,8 +2257,10 @@ udDouble3 udGeoZone_LatLongToCartesian(const udGeoZone &zone, const udDouble3 &l phi = UD_DEG2RAD(phi); double phi0 = UD_DEG2RAD(zone.parallel); - double rho0 = a * (1.0 - eSq) / udPow(1.0 - eSq * udPow(udSin(phi0), 2), 3.0 / 2.0);; // radius of curvature at the meridian - double nu0 = a / udSqrt(1.0 - eSq * udPow(udSin(phi0), 2));; // radius of curvature at the Transverse + double rho0 = a * (1.0 - eSq) / udPow(1.0 - eSq * udPow(udSin(phi0), 2), 3.0 / 2.0); + ; // radius of curvature at the meridian + double nu0 = a / udSqrt(1.0 - eSq * udPow(udSin(phi0), 2)); + ; // radius of curvature at the Transverse double s1 = (1.0 + udSin(phi0)) / (1.0 - udSin(phi0)); double s2 = (1.0 - e * udSin(phi0)) / (1.0 + e * udSin(phi0)); @@ -2290,7 +2281,7 @@ udDouble3 udGeoZone_LatLongToCartesian(const udGeoZone &zone, const udDouble3 &l double lambda = n * (UD_DEG2RAD(omega) - lambda0) + lambda0; double sA = (1.0 + udSin(phi)) / (1.0 - udSin(phi)); double sB = (1.0 - e * udSin(phi)) / (1.0 + e * udSin(phi)); - double w = c * udPow(sA * udPow(sB,e),n); + double w = c * udPow(sA * udPow(sB, e), n); double chi = udASin((w - 1.0) / (w + 1.0)); double B = (1.0 + udSin(chi) * udSin(chi0) + udCos(chi) * udCos(chi0) * cos(lambda - lambda0)); @@ -2311,7 +2302,6 @@ udDouble3 udGeoZone_LatLongToCartesian(const udGeoZone &zone, const udDouble3 &l double N = zone.falseNorthing + zone.semiMajorAxis * k0 * udLogN(udTan(UD_PI / 4.0 + phi / 2.0) * udPow((1 - zone.eccentricity * udSin(phi)) / (1 + zone.eccentricity * udSin(phi)), zone.eccentricity / 2.0)); return udDouble3::create(E, N, ellipsoidHeight); - } else if (zone.projection == udGZPT_SterographicPolar_vB) { @@ -2328,7 +2318,7 @@ udDouble3 udGeoZone_LatLongToCartesian(const udGeoZone &zone, const udDouble3 &l if (isNorthPole) t = udTan(UD_PI / 4.0 - phi / 2.0) / udPow((1 + e * udSin(phi)) / (1 - e * udSin(phi)), e / 2.0); - double rho = 2.0 *zone.semiMajorAxis * k0 * t / udSqrt(udPow(1 + e, 1 + e) * udPow(1 - e, 1 - e)); + double rho = 2.0 * zone.semiMajorAxis * k0 * t / udSqrt(udPow(1 + e, 1 + e) * udPow(1 - e, 1 - e)); double dE = rho * udSin(theta); double dN = rho * udCos(theta); double E = dE + zone.falseEasting; @@ -2340,10 +2330,10 @@ udDouble3 udGeoZone_LatLongToCartesian(const udGeoZone &zone, const udDouble3 &l } else if (zone.projection == udGZPT_Krovak || zone.projection == udGZPT_KrovakNorthOrientated) { - double phiC = UD_DEG2RAD(zone.latProjCentre); // latitude of projection centre - double alphaC = UD_DEG2RAD(zone.coLatConeAxis);// rotation in plane of meridian of origin || co latitude of the cone axis - double phiP = UD_DEG2RAD(zone.parallel); // latitude of pseudo standard parallel - double kP = zone.scaleFactor; // scale factor on pseudo standard parallel + double phiC = UD_DEG2RAD(zone.latProjCentre); // latitude of projection centre + double alphaC = UD_DEG2RAD(zone.coLatConeAxis); // rotation in plane of meridian of origin || co latitude of the cone axis + double phiP = UD_DEG2RAD(zone.parallel); // latitude of pseudo standard parallel + double kP = zone.scaleFactor; // scale factor on pseudo standard parallel double lambda0 = UD_DEG2RAD(zone.meridian); phi = UD_DEG2RAD(phi); @@ -2401,7 +2391,7 @@ udDouble3 udGeoZone_LatLongToCartesian(const udGeoZone &zone, const udDouble3 &l double uC = 0.0; if (alphaC == 90) uC = A * (lambdaC - lambda0); - else + else uC = (A / B) * udATan2(udSqrt(D * D - 1), udCos(alphaC)) * sign; double t = udTan(UD_PI / 4.0 - phi / 2.0) / udPow((1 - e * udSin(phi)) / (1 + e * udSin(phi)), e / 2.0); @@ -2459,7 +2449,8 @@ udDouble3 udGeoZone_LatLongToCartesian(const udGeoZone &zone, const udDouble3 &l double rho0 = (a * udSqrt(C - n * alpha0)) / n; double theta = n * (omega - lambda0); - double E = zone.falseEasting + rho * udSin(theta);; + double E = zone.falseEasting + rho * udSin(theta); + ; double N = zone.falseNorthing + rho0 - rho * udCos(theta); return udDouble3::create(E, N, ellipsoidHeight); @@ -2469,16 +2460,9 @@ udDouble3 udGeoZone_LatLongToCartesian(const udGeoZone &zone, const udDouble3 &l double a = zone.semiMajorAxis; phi = UD_DEG2RAD(phi); - + double eSq = zone.eccentricitySq; - double M = a * ((1 - (1.0 / 4.0) * eSq - (3.0 / 64.0) * udPow(eSq, 2) - (5.0 / 256.0) * udPow(eSq,3) - (175.0 / 16384.0) * udPow(eSq,4) - (441.0 / 65536.0) * udPow(eSq, 5) - (4851.0 / 1048576.0) * udPow(eSq, 6) - (14157.0 / 4194304.0) * udPow(eSq, 7)) * phi - + (-(3.0 / 8.0) * eSq - (3.0 / 32.0) * udPow(eSq,2) - (45.0 / 1024.0) * udPow(eSq,3) - (105.0 / 4096.0) * udPow(eSq,4) - (2205.0 / 131072.0) * udPow(eSq,5) - (6237.0 / 524288.0) * udPow(eSq,6) - (297297.0 / 33554432.0) * udPow(eSq,7)) * udSin(2*phi) - + ((15.0 / 256.0) * udPow(eSq,2) + (45.0 / 1024.0) * udPow(eSq,3) + (525.0 / 16384.0) * udPow(eSq,4) + (1575.0 / 65536.0) * udPow(eSq,5) + (155925.0 / 8388608.0) * udPow(eSq,6) + (495495/33554432) * udPow(eSq,7)) * udSin(4*phi) - + (-(35.0 / 3072.0) * udPow(eSq,3) - (175.0 / 12288.0) * udPow(eSq,4) - (3675.0 / 262144.0) * udPow(eSq,5) - (13475.0 / 1048576.0) * udPow(eSq,6) - (385385.0 / 33554432.0) * udPow(eSq,7)) * udSin(6*phi) - + ((315.0 / 131072.0) * udPow(eSq,4) + (2205.0 / 524288.0) * udPow(eSq,5) + (43659.0 / 8388608.0) * udPow(eSq,6) + (189189.0 / 33554432.0) * udPow(eSq,7)) * udSin(8*phi) - + (-(693.0 / 1310720.0) * udPow(eSq,5) - (6237.0 / 5242880.0) * udPow(eSq,6) - (297297.0 / 167772160.0) * udPow(eSq,7)) * udSin(10*phi) - + ((1001.0 / 8388608.0) * udPow(eSq,6) + (11011.0 / 33554432.0) * udPow(eSq,7)) * udSin(12*phi) - + (-(6435.0 / 234881024.0) * udPow(eSq,7)) * udSin(14* phi)); + double M = a * ((1 - (1.0 / 4.0) * eSq - (3.0 / 64.0) * udPow(eSq, 2) - (5.0 / 256.0) * udPow(eSq, 3) - (175.0 / 16384.0) * udPow(eSq, 4) - (441.0 / 65536.0) * udPow(eSq, 5) - (4851.0 / 1048576.0) * udPow(eSq, 6) - (14157.0 / 4194304.0) * udPow(eSq, 7)) * phi + (-(3.0 / 8.0) * eSq - (3.0 / 32.0) * udPow(eSq, 2) - (45.0 / 1024.0) * udPow(eSq, 3) - (105.0 / 4096.0) * udPow(eSq, 4) - (2205.0 / 131072.0) * udPow(eSq, 5) - (6237.0 / 524288.0) * udPow(eSq, 6) - (297297.0 / 33554432.0) * udPow(eSq, 7)) * udSin(2 * phi) + ((15.0 / 256.0) * udPow(eSq, 2) + (45.0 / 1024.0) * udPow(eSq, 3) + (525.0 / 16384.0) * udPow(eSq, 4) + (1575.0 / 65536.0) * udPow(eSq, 5) + (155925.0 / 8388608.0) * udPow(eSq, 6) + (495495 / 33554432) * udPow(eSq, 7)) * udSin(4 * phi) + (-(35.0 / 3072.0) * udPow(eSq, 3) - (175.0 / 12288.0) * udPow(eSq, 4) - (3675.0 / 262144.0) * udPow(eSq, 5) - (13475.0 / 1048576.0) * udPow(eSq, 6) - (385385.0 / 33554432.0) * udPow(eSq, 7)) * udSin(6 * phi) + ((315.0 / 131072.0) * udPow(eSq, 4) + (2205.0 / 524288.0) * udPow(eSq, 5) + (43659.0 / 8388608.0) * udPow(eSq, 6) + (189189.0 / 33554432.0) * udPow(eSq, 7)) * udSin(8 * phi) + (-(693.0 / 1310720.0) * udPow(eSq, 5) - (6237.0 / 5242880.0) * udPow(eSq, 6) - (297297.0 / 167772160.0) * udPow(eSq, 7)) * udSin(10 * phi) + ((1001.0 / 8388608.0) * udPow(eSq, 6) + (11011.0 / 33554432.0) * udPow(eSq, 7)) * udSin(12 * phi) + (-(6435.0 / 234881024.0) * udPow(eSq, 7)) * udSin(14 * phi)); double v1 = a / udSqrt(1 - eSq * udPow(udSin(UD_DEG2RAD(zone.parallel)), 2)); @@ -2521,7 +2505,7 @@ udDouble3 udGeoZone_CartesianToLatLong(const udGeoZone &zone, const udDouble3 &p for (size_t i = 0; i < UDARRAYSIZE(zone.beta); i++) { double j = (i + 1) * 2.0; - xi0 += zone.beta[i] * udSin(j * xi) * udCosh(j * eta); + xi0 += zone.beta[i] * udSin(j * xi) * udCosh(j * eta); eta0 += zone.beta[i] * udCos(j * xi) * udSinh(j * eta); } @@ -2550,7 +2534,7 @@ udDouble3 udGeoZone_CartesianToLatLong(const udGeoZone &zone, const udDouble3 &p double t2 = udGeoZone_LCCConformal(phi2, e); double n = (udLogN(m1) - udLogN(m2)) / (udLogN(t1) - udLogN(t2)); double F = m1 / (n * udPow(t1, n)); - double p0 = zone.semiMajorAxis * F * udPow(tOrigin, n); + double p0 = zone.semiMajorAxis * F * udPow(tOrigin, n); double p = udSqrt(x * x + (p0 - y) * (p0 - y)); // This is r' in the EPSG specs- it must have the same sign as n if (n < 0) p = -p; @@ -2636,8 +2620,10 @@ udDouble3 udGeoZone_CartesianToLatLong(const udGeoZone &zone, const udDouble3 &p double a = zone.semiMajorAxis; double phi0 = UD_DEG2RAD(zone.parallel); - double rho0 = a * (1.0 - eSq) / udPow(1.0 - eSq * udPow(udSin(phi0), 2), 3.0 / 2.0);; // radius of curvature at the meridian - double nu0 = a / udSqrt(1.0 - eSq * udPow(udSin(phi0), 2));; // radius of curvature at the Transverse + double rho0 = a * (1.0 - eSq) / udPow(1.0 - eSq * udPow(udSin(phi0), 2), 3.0 / 2.0); + ; // radius of curvature at the meridian + double nu0 = a / udSqrt(1.0 - eSq * udPow(udSin(phi0), 2)); + ; // radius of curvature at the Transverse double s1 = (1.0 + udSin(phi0)) / (1.0 - udSin(phi0)); double s2 = (1.0 - e * udSin(phi0)) / (1.0 + e * udSin(phi0)); @@ -2659,7 +2645,7 @@ udDouble3 udGeoZone_CartesianToLatLong(const udGeoZone &zone, const udDouble3 &p double i = udATan2((position.x - zone.falseEasting), (h + (position.y - zone.falseNorthing))); double j = udATan2((position.x - zone.falseEasting), (g - (position.y - zone.falseNorthing))) - i; - double chi = chi0 + 2 * udATan(((position.y - zone.falseNorthing) - (position.x - zone.falseEasting)*udTan(j/2.0)) / (2.0 * R * zone.scaleFactor)); + double chi = chi0 + 2 * udATan(((position.y - zone.falseNorthing) - (position.x - zone.falseEasting) * udTan(j / 2.0)) / (2.0 * R * zone.scaleFactor)); double lambda = j + 2 * i + UD_DEG2RAD(zone.meridian); double psi = 0.5 * udLogN((1 + udSin(chi)) / (c * (1 - udSin(chi)))) / n; @@ -2668,7 +2654,7 @@ udDouble3 udGeoZone_CartesianToLatLong(const udGeoZone &zone, const udDouble3 &p double phiTmp = 2 * udATan(udExp(psi)) - UD_HALF_PI; double psiI = 0; double epsilon = udPow(10.0, -14.0); - while (fabs(phi- phiTmp) > epsilon && !isnan(phi)) + while (fabs(phi - phiTmp) > epsilon && !isnan(phi)) { phi = phiTmp; psiI = udLogN(udTan(phiTmp / 2.0 + UD_PI / 4.0) * udPow((1 - e * udSin(phiTmp)) / (1 + e * udSin(phiTmp)), (e / 2.0))); @@ -2684,12 +2670,9 @@ udDouble3 udGeoZone_CartesianToLatLong(const udGeoZone &zone, const udDouble3 &p double eSq = zone.eccentricitySq; double k0 = udCos(UD_DEG2RAD(zone.firstParallel)) / udSqrt(1 - eSq * udPow(udSin(UD_DEG2RAD(zone.firstParallel)), 2)); double B = udExp(1.0); - double t = udPow(B, (zone.falseNorthing - position.y)/(zone.semiMajorAxis * k0)); + double t = udPow(B, (zone.falseNorthing - position.y) / (zone.semiMajorAxis * k0)); double chi = UD_HALF_PI - 2.0 * udATan(t); - double phi = chi + (eSq / 2.0 + 5.0 * udPow(eSq, 2) / 24.0 + udPow(eSq, 3) / 12.0 + 13.0 * udPow(eSq, 4) / 360.0) * udSin(2.0 * chi) - + (7.0 * udPow(eSq, 2) / 48.0 + 29.0 * udPow(eSq, 3) / 240.0 + 811.0 * udPow(eSq, 4) / 11520.0) * udSin(4.0 * chi) - + (7.0 * udPow(eSq, 3) / 120.0 + 81.0 * udPow(eSq, 4) / 1120.0) * udSin(6.0 * chi) - + (4279.0 * udPow(eSq, 4) / 161280.0) * udSin(8.0 * chi); + double phi = chi + (eSq / 2.0 + 5.0 * udPow(eSq, 2) / 24.0 + udPow(eSq, 3) / 12.0 + 13.0 * udPow(eSq, 4) / 360.0) * udSin(2.0 * chi) + (7.0 * udPow(eSq, 2) / 48.0 + 29.0 * udPow(eSq, 3) / 240.0 + 811.0 * udPow(eSq, 4) / 11520.0) * udSin(4.0 * chi) + (7.0 * udPow(eSq, 3) / 120.0 + 81.0 * udPow(eSq, 4) / 1120.0) * udSin(6.0 * chi) + (4279.0 * udPow(eSq, 4) / 161280.0) * udSin(8.0 * chi); latLong.x = UD_RAD2DEG(phi); latLong.y = UD_RAD2DEG((position.x - zone.falseEasting) / (zone.semiMajorAxis * k0) + zone.meridian); @@ -2708,13 +2691,10 @@ udDouble3 udGeoZone_CartesianToLatLong(const udGeoZone &zone, const udDouble3 &p double tP = rhoP * udSqrt(udPow(1 + e, 1 + e) * udPow(1 - e, 1 - e)) / (2.0 * zone.semiMajorAxis * k0); double chi = 2.0 * udATan(tP) - UD_HALF_PI; - if (isNorthPole)// north pole + if (isNorthPole) // north pole chi = -chi; - double phi = chi + (eSq / 2.0 + 5.0 * udPow(eSq, 2) / 24.0 + udPow(eSq, 3) / 12.0 + 13.0 * udPow(eSq, 4) / 360.0) * udSin(2.0 * chi) - + (7.0 * udPow(eSq, 2) / 48.0 + 29.0 * udPow(eSq, 3) / 240.0 + 811.0 * udPow(eSq, 4) / 11520.0) * udSin(4.0 * chi) - + (7.0 * udPow(eSq, 3) / 120.0 + 81.0 * udPow(eSq, 4) / 1120.0) * udSin(6.0 * chi) - + (4279.0 * udPow(eSq, 4) / 161280.0) * udSin(8.0 * chi); + double phi = chi + (eSq / 2.0 + 5.0 * udPow(eSq, 2) / 24.0 + udPow(eSq, 3) / 12.0 + 13.0 * udPow(eSq, 4) / 360.0) * udSin(2.0 * chi) + (7.0 * udPow(eSq, 2) / 48.0 + 29.0 * udPow(eSq, 3) / 240.0 + 811.0 * udPow(eSq, 4) / 11520.0) * udSin(4.0 * chi) + (7.0 * udPow(eSq, 3) / 120.0 + 81.0 * udPow(eSq, 4) / 1120.0) * udSin(6.0 * chi) + (4279.0 * udPow(eSq, 4) / 161280.0) * udSin(8.0 * chi); latLong.x = UD_RAD2DEG(phi); if (position.x == zone.falseEasting) @@ -2739,10 +2719,10 @@ udDouble3 udGeoZone_CartesianToLatLong(const udGeoZone &zone, const udDouble3 &p westing *= -1.0; } - double phiC = UD_DEG2RAD(zone.latProjCentre); // latitude of projection centre - double alphaC = UD_DEG2RAD(zone.coLatConeAxis);// rotation in plane of meridian of origin || co latitude of the cone axis - double phiP = UD_DEG2RAD(zone.parallel); // latitude of pseudo standard parallel - double kP = zone.scaleFactor; // scale factor on pseudo standard parallel + double phiC = UD_DEG2RAD(zone.latProjCentre); // latitude of projection centre + double alphaC = UD_DEG2RAD(zone.coLatConeAxis); // rotation in plane of meridian of origin || co latitude of the cone axis + double phiP = UD_DEG2RAD(zone.parallel); // latitude of pseudo standard parallel + double kP = zone.scaleFactor; // scale factor on pseudo standard parallel double a = zone.semiMajorAxis; double eSq = zone.eccentricitySq; @@ -2823,10 +2803,7 @@ udDouble3 udGeoZone_CartesianToLatLong(const udGeoZone &zone, const udDouble3 &p double tP = udPow(H / udSqrt((1 + Up) / (1 - Up)), 1 / B); double chi = UD_HALF_PI - 2.0 * udATan(tP); - double phi = chi + (eSq / 2.0 + 5.0 * udPow(eSq, 2) / 24.0 + udPow(eSq, 3) / 12.0 + 13.0 * udPow(eSq, 4) / 360.0) * udSin(2.0 * chi) - + (7.0 * udPow(eSq, 2) / 48.0 + 29.0 * udPow(eSq, 3) / 240.0 + 811.0 * udPow(eSq, 4) / 11520.0) * udSin(4.0 * chi) - + (7.0 * udPow(eSq, 3) / 120.0 + 81.0 * udPow(eSq, 4) / 1120.0) * udSin(6.0 * chi) - + (4279.0 * udPow(eSq, 4) / 161280.0) * udSin(8.0 * chi); + double phi = chi + (eSq / 2.0 + 5.0 * udPow(eSq, 2) / 24.0 + udPow(eSq, 3) / 12.0 + 13.0 * udPow(eSq, 4) / 360.0) * udSin(2.0 * chi) + (7.0 * udPow(eSq, 2) / 48.0 + 29.0 * udPow(eSq, 3) / 240.0 + 811.0 * udPow(eSq, 4) / 11520.0) * udSin(4.0 * chi) + (7.0 * udPow(eSq, 3) / 120.0 + 81.0 * udPow(eSq, 4) / 1120.0) * udSin(6.0 * chi) + (4279.0 * udPow(eSq, 4) / 161280.0) * udSin(8.0 * chi); double lambda = lambda0 - udATan2(Sp * udCos(gamma0) - Vp * udSin(gamma0), udCos(B * uP / A)) / B; @@ -2859,18 +2836,15 @@ udDouble3 udGeoZone_CartesianToLatLong(const udGeoZone &zone, const udDouble3 &p else theta = udATan2(-(position.x - zone.falseEasting), -(rho0 - (position.y - zone.falseNorthing))); - double rhoP = udSqrt(udPow(position.x - zone.falseEasting,2) + udPow(rho0 - (position.y - zone.falseNorthing), 2)); - double alphaP = (C - (udPow(rhoP, 2) * udPow(n,2) / udPow(a,2))) / n; - double betaP = udASin(alphaP / (1 - ((1 - eSq) / (2 * e)) * udLogN ((1 - e) / (1 + e)))); + double rhoP = udSqrt(udPow(position.x - zone.falseEasting, 2) + udPow(rho0 - (position.y - zone.falseNorthing), 2)); + double alphaP = (C - (udPow(rhoP, 2) * udPow(n, 2) / udPow(a, 2))) / n; + double betaP = udASin(alphaP / (1 - ((1 - eSq) / (2 * e)) * udLogN((1 - e) / (1 + e)))); - double phi = betaP - + ((eSq / 3.0 + 31 * udPow(e, 4) / 180 + 517 * udPow(e, 6) / 5040) * udSin(2 * betaP)) - + ((23 * udPow(e, 4) / 360 + 251 * udPow(e, 6) / 3780) * udSin(4 * betaP)) - + ((761 * udPow(e, 6) / 45360) * udSin(6 * betaP)); + double phi = betaP + ((eSq / 3.0 + 31 * udPow(e, 4) / 180 + 517 * udPow(e, 6) / 5040) * udSin(2 * betaP)) + ((23 * udPow(e, 4) / 360 + 251 * udPow(e, 6) / 3780) * udSin(4 * betaP)) + ((761 * udPow(e, 6) / 45360) * udSin(6 * betaP)); double lambda = UD_DEG2RAD(zone.meridian) + (theta / n); latLong.x = UD_RAD2DEG(phi); - latLong.y = UD_RAD2DEG(-lambda);// West Axis + latLong.y = UD_RAD2DEG(-lambda); // West Axis latLong.z = position.z; } else if (zone.projection == udGZPT_EquidistantCylindrical) @@ -2884,18 +2858,12 @@ udDouble3 udGeoZone_CartesianToLatLong(const udGeoZone &zone, const udDouble3 &p double eta = (1 - udSqrt(1 - eSq)) / (1 + udSqrt(1 - eSq)); double lambda = UD_DEG2RAD(zone.meridian) + X * udSqrt(1.0 - eSq * udPow(udSin(zone.parallel), 2)) / (a * udCos(zone.parallel)); - double phi = mu + ((3.0 / 2.0) * eta - (27.0 / 32.0) * udPow(eta, 3) + (269.0 / 512.0) * udPow(eta, 5) - (6607.0 / 24576.0) * udPow(eta, 7)) * udSin(2 * mu) - + ((21.0 / 16.0) * udPow(eta, 2) - (55.0 / 32.0) * udPow(eta, 4) + (6759.0 / 4096.0) * udPow(eta, 6)) * udSin(4 * mu) - + ((151.0 / 96.0) * udPow(eta, 3) - (417.0 / 128.0) * udPow(eta, 5) + (87963.0 / 20480.0) * udPow(eta, 7)) * udSin(6 * mu) - + ((1097.0 / 512.0) * udPow(eta, 4) - (15543.0 / 2560.0) * udPow(eta, 6)) * udSin(8 * mu) - + ((8011.0 / 2560.0) * udPow(eta, 5) - (69119.0 / 6144.0) * udPow(eta, 7)) * udSin(10 * mu) - + ((293393.0 / 61440.0) * udPow(eta, 6)) * udSin(12 * mu) - + ((6845701.0 / 860160.0) * udPow(eta, 7)) * udSin(14 * mu); + double phi = mu + ((3.0 / 2.0) * eta - (27.0 / 32.0) * udPow(eta, 3) + (269.0 / 512.0) * udPow(eta, 5) - (6607.0 / 24576.0) * udPow(eta, 7)) * udSin(2 * mu) + ((21.0 / 16.0) * udPow(eta, 2) - (55.0 / 32.0) * udPow(eta, 4) + (6759.0 / 4096.0) * udPow(eta, 6)) * udSin(4 * mu) + ((151.0 / 96.0) * udPow(eta, 3) - (417.0 / 128.0) * udPow(eta, 5) + (87963.0 / 20480.0) * udPow(eta, 7)) * udSin(6 * mu) + ((1097.0 / 512.0) * udPow(eta, 4) - (15543.0 / 2560.0) * udPow(eta, 6)) * udSin(8 * mu) + ((8011.0 / 2560.0) * udPow(eta, 5) - (69119.0 / 6144.0) * udPow(eta, 7)) * udSin(10 * mu) + ((293393.0 / 61440.0) * udPow(eta, 6)) * udSin(12 * mu) + ((6845701.0 / 860160.0) * udPow(eta, 7)) * udSin(14 * mu); latLong.x = UD_RAD2DEG(phi); latLong.y = UD_RAD2DEG(lambda); latLong.z = position.z; - } + } if (datum != zone.datum) latLong = udGeoZone_ConvertDatum(latLong, zone.datum, datum); diff --git a/Source/udImage.cpp b/Source/udImage.cpp index 56cbc019..49d2fa38 100644 --- a/Source/udImage.cpp +++ b/Source/udImage.cpp @@ -1,7 +1,7 @@ #include "udImage.h" +#include "udCompression.h" #include "udFile.h" #include "udMath.h" -#include "udCompression.h" #include "udStringUtil.h" #include "udThread.h" #define STB_IMAGE_IMPLEMENTATION @@ -147,7 +147,7 @@ static void stbiWriteWrapper(stbiWriteContext *pContext, uint32_t width, uint32_ udResult udImage_Save(const udImage *pImage, const char *pFilename, uint32_t *pSaveSize, udImageSaveType saveType) { udResult result; - void *pRGB = nullptr; // Sadly, stbi has no support for writing 24-bit from a 32-bit source, so we must shrink + void *pRGB = nullptr; // Sadly, stbi has no support for writing 24-bit from a 32-bit source, so we must shrink uint8_t *pSource, *pDest; // For shrinking uint32_t count; stbiWriteContext writeContext; @@ -159,7 +159,7 @@ udResult udImage_Save(const udImage *pImage, const char *pFilename, uint32_t *pS pRGB = udAlloc(count * 3); UD_ERROR_NULL(pRGB, udR_MemoryAllocationFailure); pSource = (uint8_t *)pImage->pImageData; - pDest = (uint8_t*)pRGB; + pDest = (uint8_t *)pRGB; while (count--) { *pDest++ = pSource[0]; @@ -192,7 +192,7 @@ uint32_t udImage_Sample(udImage *pImage, float u, float v, udImageSampleFlags fl v = udClamp(v, 0.f, 1.f); } - u = u * pImage->width; + u = u * pImage->width; if (flags & udISF_TopLeft) v = v * pImage->height; else @@ -227,7 +227,7 @@ uint32_t udImage_Sample(udImage *pImage, float u, float v, udImageSampleFlags fl uint32_t c2 = (pImage->pImageData[x0 + y1 * pImage->width]); uint32_t c3 = (pImage->pImageData[x1 + y1 * pImage->width]); - uint32_t bfB = 0x00ff0000 & (((c0 >> 16) * a) + ((c1 >> 16) * b) + ((c2 >> 16) * c) + ((c3 >> 16) * d)); + uint32_t bfB = 0x00ff0000 & (((c0 >> 16) * a) + ((c1 >> 16) * b) + ((c2 >> 16) * c) + ((c3 >> 16) * d)); uint32_t bfG = 0xff000000 & (((c0 & 0x00ff00) * a) + ((c1 & 0x00ff00) * b) + ((c2 & 0x00ff00) * c) + ((c3 & 0x00ff00) * d)); uint32_t bfR = 0x00ff0000 & (((c0 & 0x0000ff) * a) + ((c1 & 0x0000ff) * b) + ((c2 & 0x0000ff) * c) + ((c3 & 0x0000ff) * d)); @@ -303,7 +303,7 @@ udResult udImageStreaming_Save(const udImage *pImage, udImageStreamingOnDisk **p p24BitData = udAllocType(uint8_t, pImage->width * pImage->height * 3, udAF_None); UD_ERROR_NULL(p24BitData, udR_MemoryAllocationFailure); pOut = p24BitData; - pIn = (uint8_t*)(pImage->pImageData); + pIn = (uint8_t *)(pImage->pImageData); for (uint32_t y = 0; y < pImage->height; ++y) { for (uint32_t x = 0; x < pImage->width; ++x) @@ -637,7 +637,7 @@ void udImageStreaming_Destroy(udImageStreaming **ppImage) if (pImage->mips[i].ppCellImage) { for (uint16_t j = 0; j < (pImage->mips[i].gridW * pImage->mips[i].gridH); ++j) - udFree(const_cast(pImage->mips[i].ppCellImage[j])); + udFree(const_cast(pImage->mips[i].ppCellImage[j])); udFree(pImage->mips[i].ppCellImage); } } diff --git a/Source/udIntersectionTest.cpp b/Source/udIntersectionTest.cpp index 475d36a7..8ef23248 100644 --- a/Source/udIntersectionTest.cpp +++ b/Source/udIntersectionTest.cpp @@ -14,84 +14,150 @@ #include "udIntersectionTest.h" -static bool PlaneBoxOverlap(const udDouble3 &normal, const udDouble3 &vert, const udDouble3 &maxbox) // -NJMP- +static bool PlaneBoxOverlap(const udDouble3 &normal, const udDouble3 &vert, const udDouble3 &maxbox) // -NJMP- { int q; double v; udDouble3 vmin, vmax; for (q = 0; q < 3; ++q) { - v = vert[q]; // -NJMP- + v = vert[q]; // -NJMP- if (normal[q] > 0.0) { - vmin[q] = -maxbox[q] - v; // -NJMP- - vmax[q] = maxbox[q] - v; // -NJMP- + vmin[q] = -maxbox[q] - v; // -NJMP- + vmax[q] = maxbox[q] - v; // -NJMP- } else { - vmin[q] = maxbox[q] - v; // -NJMP- - vmax[q] = -maxbox[q] - v; // -NJMP- + vmin[q] = maxbox[q] - v; // -NJMP- + vmax[q] = -maxbox[q] - v; // -NJMP- } } - if (udDot(normal, vmin) > 0.0) return false; // -NJMP- - if (udDot(normal, vmax) >= 0.0) return true; // -NJMP- + if (udDot(normal, vmin) > 0.0) + return false; // -NJMP- + if (udDot(normal, vmax) >= 0.0) + return true; // -NJMP- return false; } //=================== Find min/max ======================== -#define FINDMINMAX(x0,x1,x2,min,max) \ - min = max = x0; \ - if (x1 < min) min=x1;\ - if (x1 > max) max=x1;\ - if (x2 < min) min=x2;\ - if (x2 > max) max=x2; +#define FINDMINMAX(x0, x1, x2, min, max) \ + min = max = x0; \ + if (x1 < min) \ + min = x1; \ + if (x1 > max) \ + max = x1; \ + if (x2 < min) \ + min = x2; \ + if (x2 > max) \ + max = x2; //======================== X-tests ======================== -#define AXISTEST_X01(a, b, fa, fb) \ - p0 = a*v0.y - b*v0.z; \ - p2 = a*v2.y - b*v2.z; \ - if (p0rad || max<-rad) return 0; - -#define AXISTEST_X2(a, b, fa, fb) \ - p0 = a*v0.y - b*v0.z; \ - p1 = a*v1.y - b*v1.z; \ - if (p0rad || max<-rad) return 0; +#define AXISTEST_X01(a, b, fa, fb) \ + p0 = a * v0.y - b * v0.z; \ + p2 = a * v2.y - b * v2.z; \ + if (p0 < p2) \ + { \ + min = p0; \ + max = p2; \ + } \ + else \ + { \ + min = p2; \ + max = p0; \ + } \ + rad = fa * boxHalfSize.y + fb * boxHalfSize.z; \ + if (min > rad || max < -rad) \ + return 0; + +#define AXISTEST_X2(a, b, fa, fb) \ + p0 = a * v0.y - b * v0.z; \ + p1 = a * v1.y - b * v1.z; \ + if (p0 < p1) \ + { \ + min = p0; \ + max = p1; \ + } \ + else \ + { \ + min = p1; \ + max = p0; \ + } \ + rad = fa * boxHalfSize.y + fb * boxHalfSize.z; \ + if (min > rad || max < -rad) \ + return 0; //======================== Y-tests ======================== -#define AXISTEST_Y02(a, b, fa, fb) \ - p0 = -a*v0.x + b*v0.z; \ - p2 = -a*v2.x + b*v2.z; \ - if (p0rad || max<-rad) return 0; - -#define AXISTEST_Y1(a, b, fa, fb) \ - p0 = -a*v0.x + b*v0.z; \ - p1 = -a*v1.x + b*v1.z; \ - if (p0rad || max<-rad) return 0; +#define AXISTEST_Y02(a, b, fa, fb) \ + p0 = -a * v0.x + b * v0.z; \ + p2 = -a * v2.x + b * v2.z; \ + if (p0 < p2) \ + { \ + min = p0; \ + max = p2; \ + } \ + else \ + { \ + min = p2; \ + max = p0; \ + } \ + rad = fa * boxHalfSize.x + fb * boxHalfSize.z; \ + if (min > rad || max < -rad) \ + return 0; + +#define AXISTEST_Y1(a, b, fa, fb) \ + p0 = -a * v0.x + b * v0.z; \ + p1 = -a * v1.x + b * v1.z; \ + if (p0 < p1) \ + { \ + min = p0; \ + max = p1; \ + } \ + else \ + { \ + min = p1; \ + max = p0; \ + } \ + rad = fa * boxHalfSize.x + fb * boxHalfSize.z; \ + if (min > rad || max < -rad) \ + return 0; //======================== Z-tests ======================== -#define AXISTEST_Z12(a, b, fa, fb) \ - p1 = a*v1.x - b*v1.y; \ - p2 = a*v2.x - b*v2.y; \ - if (p2rad || max<-rad) return 0; +#define AXISTEST_Z12(a, b, fa, fb) \ + p1 = a * v1.x - b * v1.y; \ + p2 = a * v2.x - b * v2.y; \ + if (p2 < p1) \ + { \ + min = p2; \ + max = p1; \ + } \ + else \ + { \ + min = p1; \ + max = p2; \ + } \ + rad = fa * boxHalfSize.x + fb * boxHalfSize.y; \ + if (min > rad || max < -rad) \ + return 0; -#define AXISTEST_Z0(a, b, fa, fb) \ - p0 = a*v0.x - b*v0.y; \ - p1 = a*v1.x - b*v1.y; \ - if (p0rad || max<-rad) return 0; +#define AXISTEST_Z0(a, b, fa, fb) \ + p0 = a * v0.x - b * v0.y; \ + p1 = a * v1.x - b * v1.y; \ + if (p0 < p1) \ + { \ + min = p0; \ + max = p1; \ + } \ + else \ + { \ + min = p1; \ + max = p0; \ + } \ + rad = fa * boxHalfSize.x + fb * boxHalfSize.y; \ + if (min > rad || max < -rad) \ + return 0; // **************************************************************************** // Author: Dave Pevreal, February 2019 (slightly translated from above credited authors) @@ -104,9 +170,9 @@ bool udIntersectionTest_AABBTriangle(const udDouble3 &boxCenter, const udDouble3 // 2) normal of the triangle // 3) crossproduct(edge from tri, {x,y,z}-direction) // this gives 3x3=9 more tests - udDouble3 v0,v1,v2; - double min,max,p0,p1,p2,rad,fex,fey,fez; // -NJMP- "d" local variable removed - udDouble3 normal,e0,e1,e2; + udDouble3 v0, v1, v2; + double min, max, p0, p1, p2, rad, fex, fey, fez; // -NJMP- "d" local variable removed + udDouble3 normal, e0, e1, e2; // This is the fastest branch on Sun // move everything so that the boxcenter is in (0,0,0) @@ -115,9 +181,9 @@ bool udIntersectionTest_AABBTriangle(const udDouble3 &boxCenter, const udDouble3 v2 = triVerts[2] - boxCenter; // compute triangle edges - e0 = v1 - v0; // tri edge 0 - e1 = v2 - v1; // tri edge 1 - e2 = v0 - v2; // tri edge 2 + e0 = v1 - v0; // tri edge 0 + e1 = v2 - v1; // tri edge 1 + e2 = v0 - v2; // tri edge 2 // Bullet 3: // test the 9 tests first (this was faster) @@ -169,17 +235,17 @@ bool udIntersectionTest_AABBTriangle(const udDouble3 &boxCenter, const udDouble3 normal = udCross3(e0, e1); // -NJMP- (line removed here) if (!PlaneBoxOverlap(normal, v0, boxHalfSize)) - return false; // -NJMP- + return false; // -NJMP- - return true; // box and triangle overlaps + return true; // box and triangle overlaps } // AABB vs line segment test. By Miguel Gomez // Taken from http://www.gamasutra.com/view/feature/131790/simple_intersection_tests_for_games.php?page=6 // TODO: Some optimization opportunity on this one, particularly precomputing the abs linedir -static bool AABB_LineSegmentOverlap(udDouble3 lineDir, // line direction - udDouble3 mid, // midpoint of the line segment - double halfLength, // segment half-length +static bool AABB_LineSegmentOverlap(udDouble3 lineDir, // line direction + udDouble3 mid, // midpoint of the line segment + double halfLength, // segment half-length udDouble3 boxCenter, // box center/extents udDouble3 boxExtents) { @@ -191,13 +257,13 @@ static bool AABB_LineSegmentOverlap(udDouble3 lineDir, // line direction // do any of the principal axes form a separating axis? - if( fabs(t.x) > boxExtents.x + halfLength * fabs(lineDir.x) ) + if (fabs(t.x) > boxExtents.x + halfLength * fabs(lineDir.x)) return 0; - if( fabs(t.y) > boxExtents.y + halfLength * fabs(lineDir.y) ) + if (fabs(t.y) > boxExtents.y + halfLength * fabs(lineDir.y)) return 0; - if( fabs(t.z) > boxExtents.z + halfLength * fabs(lineDir.z) ) + if (fabs(t.z) > boxExtents.z + halfLength * fabs(lineDir.z)) return 0; /* NOTE: Since the separating axis is perpendicular to the line in these @@ -207,7 +273,7 @@ static bool AABB_LineSegmentOverlap(udDouble3 lineDir, // line direction r = boxExtents.y * fabs(lineDir.z) + boxExtents.z * fabs(lineDir.y); - if (fabs(t.y*lineDir.z - t.z*lineDir.y) > r) + if (fabs(t.y * lineDir.z - t.z * lineDir.y) > r) return 0; //lineDir.cross(y-axis)? diff --git a/Source/udJSON.cpp b/Source/udJSON.cpp index 6f1d03e7..adc604aa 100644 --- a/Source/udJSON.cpp +++ b/Source/udJSON.cpp @@ -1,34 +1,33 @@ #include "udPlatform.h" #if defined(UD_GCC_VERSION) && !defined(__clang__) && UD_GCC_VERSION > 90000 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wclass-memaccess" +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wclass-memaccess" #endif #include "udJSON.h" #if defined(UD_GCC_VERSION) && !defined(__clang__) && UD_GCC_VERSION > 90000 -# pragma GCC diagnostic push +# pragma GCC diagnostic push #endif -#include "udStringUtil.h" #include "udCrypto.h" +#include "udStringUtil.h" -#define CONTENT_MEMBER "content" -#define DEFAULT_DOUBLE_TOSTRING_PRECISION 6 // This is the printf default +#define CONTENT_MEMBER "content" +#define DEFAULT_DOUBLE_TOSTRING_PRECISION 6 // This is the printf default const udJSON udJSON::s_void; -const size_t udJSON::s_udJSONTypeSize[T_Count] = -{ - 0, // T_Void = 0, // Guaranteed to be zero, thus a non-zero type indicates value exists - 1, // T_Bool, - 8, // T_Int64, - 8, // T_Double, - sizeof(char*), // T_String, - sizeof(udJSONArray*), // T_Array, - sizeof(udJSONObject*), // T_Object, +const size_t udJSON::s_udJSONTypeSize[T_Count] = { + 0, // T_Void = 0, // Guaranteed to be zero, thus a non-zero type indicates value exists + 1, // T_Bool, + 8, // T_Int64, + 8, // T_Double, + sizeof(char *), // T_String, + sizeof(udJSONArray *), // T_Array, + sizeof(udJSONObject *), // T_Object, }; // The XML escape character set. Note: apos MUST come first, it is ignored when writing strings that use double quotes -static const char *s_pXMLEscStrings[] = { "'", "&" , """, "<", ">"}; +static const char *s_pXMLEscStrings[] = { "'", "&", """, "<", ">" }; static const char *s_xmlEscChars = "\'&\"<>"; static const char *s_pJSONEscStrings[] = { "\\\\", "\\\"", "\\b", "\\f", "\\n", "\\r", "\\t" }; @@ -47,12 +46,12 @@ class udJSONExpression void Init(char *pKeyExpression) { - pRemainingExpression = const_cast(udStrSkipWhiteSpace(pKeyExpression)); + pRemainingExpression = const_cast(udStrSkipWhiteSpace(pKeyExpression)); nextOp = 0; if (*pRemainingExpression == '[' || *pRemainingExpression == '.') { nextOp = *pRemainingExpression; - pRemainingExpression = const_cast(udStrSkipWhiteSpace(pRemainingExpression + 1)); + pRemainingExpression = const_cast(udStrSkipWhiteSpace(pRemainingExpression + 1)); } Next(); } @@ -69,7 +68,7 @@ class udJSONExpression char *pTemp = pRemainingExpression; if (pTemp) { - pRemainingExpression = const_cast(udStrchr(pTemp, ".[")); + pRemainingExpression = const_cast(udStrchr(pTemp, ".[")); if (pRemainingExpression) { nextOp = *pRemainingExpression; @@ -85,7 +84,6 @@ class udJSONExpression } }; - // **************************************************************************** // Author: Dave Pevreal, April 2017 void udJSON::Destroy() @@ -314,10 +312,14 @@ bool udJSON::AsBool(bool defaultValue) const { switch (type) { - case T_Bool: return u.bVal; - case T_Int64: return u.i64Val != 0; - case T_Double: return u.dVal >= 1.0; - case T_String: return udStrEquali(u.pStr, "true") || udStrAtof(u.pStr) >= 1.0; + case T_Bool: + return u.bVal; + case T_Int64: + return u.i64Val != 0; + case T_Double: + return u.dVal >= 1.0; + case T_String: + return udStrEquali(u.pStr, "true") || udStrAtof(u.pStr) >= 1.0; default: return defaultValue; } @@ -329,10 +331,14 @@ int udJSON::AsInt(int defaultValue) const { switch (type) { - case T_Bool: return (int)u.bVal; - case T_Int64: return (int)u.i64Val; - case T_Double: return (int)u.dVal; - case T_String: return udStrAtoi(u.pStr); + case T_Bool: + return (int)u.bVal; + case T_Int64: + return (int)u.i64Val; + case T_Double: + return (int)u.dVal; + case T_String: + return udStrAtoi(u.pStr); default: return defaultValue; } @@ -344,10 +350,14 @@ int64_t udJSON::AsInt64(int64_t defaultValue) const { switch (type) { - case T_Bool: return (int64_t)u.bVal; - case T_Int64: return u.i64Val; - case T_Double: return (int64_t)u.dVal; - case T_String: return udStrAtoi64(u.pStr); + case T_Bool: + return (int64_t)u.bVal; + case T_Int64: + return u.i64Val; + case T_Double: + return (int64_t)u.dVal; + case T_String: + return udStrAtoi64(u.pStr); default: return defaultValue; } @@ -359,10 +369,14 @@ float udJSON::AsFloat(float defaultValue) const { switch (type) { - case T_Bool: return (float)u.bVal; - case T_Int64: return (float)u.i64Val; - case T_Double: return (float)u.dVal; - case T_String: return udStrAtof(u.pStr); + case T_Bool: + return (float)u.bVal; + case T_Int64: + return (float)u.i64Val; + case T_Double: + return (float)u.dVal; + case T_String: + return udStrAtof(u.pStr); default: return defaultValue; } @@ -374,10 +388,14 @@ double udJSON::AsDouble(double defaultValue) const { switch (type) { - case T_Bool: return (double)u.bVal; - case T_Int64: return (double)u.i64Val; - case T_Double: return u.dVal; - case T_String: return udStrAtof64(u.pStr); + case T_Bool: + return (double)u.bVal; + case T_Int64: + return (double)u.i64Val; + case T_Double: + return u.dVal; + case T_String: + return udStrAtof64(u.pStr); default: return defaultValue; } @@ -389,8 +407,10 @@ const char *udJSON::AsString(const char *pDefaultValue) const { switch (type) { - case T_Bool: return u.bVal ? "true" : "false"; - case T_String: return u.pStr; + case T_Bool: + return u.bVal ? "true" : "false"; + case T_String: + return u.pStr; default: return pDefaultValue; } @@ -516,7 +536,7 @@ static size_t FindMatch(const udJSONArray *pArray, const udJSONObject *pSearchOb for (; i < pArray->length; ++i) // For each element in the array { attributesMatched = 0; - const udJSONObject *pCurrent = const_cast(pArray->GetElement(i))->AsObject(); + const udJSONObject *pCurrent = const_cast(pArray->GetElement(i))->AsObject(); if (!pCurrent) continue; size_t j; @@ -525,8 +545,7 @@ static size_t FindMatch(const udJSONArray *pArray, const udJSONObject *pSearchOb size_t k; for (k = 0; k < pSearchObj->length; ++k) // For each attribute in the search expression { - if (udStrEqual(pSearchObj->GetElement(k)->pKey, pCurrent->GetElement(j)->pKey) - && pSearchObj->GetElement(k)->value.IsEqualTo(pCurrent->GetElement(j)->value)) + if (udStrEqual(pSearchObj->GetElement(k)->pKey, pCurrent->GetElement(j)->pKey) && pSearchObj->GetElement(k)->value.IsEqualTo(pCurrent->GetElement(j)->value)) { ++attributesMatched; break; @@ -591,7 +610,7 @@ static udResult udJSON_ProcessArrayOperator(const udJSON *pRoot, const udJSON ** UD_ERROR_IF(resultNumberParsed, udR_ParseError); if (pRoot->IsVoid() && createIfNotExist) { - result = const_cast(pRoot)->SetObject(); + result = const_cast(pRoot)->SetObject(); UD_ERROR_HANDLE(); } if (pRoot->IsObject()) @@ -634,7 +653,7 @@ static udResult udJSON_ProcessArrayOperator(const udJSON *pRoot, const udJSON ** // [], which means append to the array if (pRoot->IsVoid() && createIfNotExist) // If the entry is void, we can safely make it an array now { - result = const_cast(pRoot)->SetArray(); + result = const_cast(pRoot)->SetArray(); UD_ERROR_HANDLE(); } UD_ERROR_IF(!pRoot->IsArray() || !createIfNotExist, udR_ParseError); @@ -651,12 +670,12 @@ static udResult udJSON_ProcessArrayOperator(const udJSON *pRoot, const udJSON ** { if (pRoot->IsVoid() && createIfNotExist) // If the entry is void, we can safely make it an array now { - result = const_cast(pRoot)->SetArray(); + result = const_cast(pRoot)->SetArray(); UD_ERROR_HANDLE(); } // Search expression is numeric, which is typically an array index, but we also support [0] on an object which returns itself UD_ERROR_IF(resultNumberParsed, udR_ParseError); - int searchIndex = searchExp.AsInt(); + int searchIndex = searchExp.AsInt(); if (pRoot->IsObject()) { UD_ERROR_IF(searchIndex != 0, udR_ParseError); // We accept objects being accessed as object[0] for xml parsing reasons @@ -733,27 +752,27 @@ static udResult udJSON_GetVA(const udJSON *pRoot, udJSON **ppValue, const char * switch (exp.op) { case '[': - { - int charCount; - size_t index; - result = udJSON_ProcessArrayOperator(pRoot, &pRoot, &index, exp.pKey, &charCount, false); - UD_ERROR_HANDLE(); - } - break; + { + int charCount; + size_t index; + result = udJSON_ProcessArrayOperator(pRoot, &pRoot, &index, exp.pKey, &charCount, false); + UD_ERROR_HANDLE(); + } + break; case 0: // Fall-thru to normal member-of code if root isn't XML case '.': - { - pRoot = pRoot->FindMember(exp.pKey); - if (!pRoot) - UD_ERROR_SET_NO_BREAK(udR_NotFound); - } - break; + { + pRoot = pRoot->FindMember(exp.pKey); + if (!pRoot) + UD_ERROR_SET_NO_BREAK(udR_NotFound); + } + break; } } if (ppValue) - *ppValue = const_cast(pRoot); + *ppValue = const_cast(pRoot); result = udR_Success; epilogue: @@ -774,7 +793,7 @@ udResult udJSON::Get(udJSON **ppValue, const char *pKeyExpression, ...) // **************************************************************************** // Author: Dave Pevreal, April 2017 -const udJSON &udJSON::Get(const char * pKeyExpression, ...) const +const udJSON &udJSON::Get(const char *pKeyExpression, ...) const { udJSON *pValue = nullptr; va_list ap; @@ -806,7 +825,7 @@ static udResult udJSON_SetVA(udJSON *pRoot, udJSON *pSetToValue, const char *pKe UD_ERROR_NULL(pDup, udR_MemoryAllocationFailure); udSprintfVA(pDup, expressionLength + 1, pKeyExpression, ap); // Parse the assignment result here before initialising exp - char *pEquals = const_cast(udStrchr(pDup, "=")); + char *pEquals = const_cast(udStrchr(pDup, "=")); if (pEquals) { UD_ERROR_IF(pSetToValue != nullptr, udR_InvalidConfiguration); @@ -830,35 +849,35 @@ static udResult udJSON_SetVA(udJSON *pRoot, udJSON *pSetToValue, const char *pKe switch (exp.op) { case '[': + { + int charCount; + udJSON *pV = nullptr; + size_t index; + result = udJSON_ProcessArrayOperator(pRoot, const_cast(&pV), &index, exp.pKey, &charCount, pSetToValue != nullptr); + if (!pSetToValue && !exp.pRemainingExpression) { - int charCount; - udJSON *pV = nullptr; - size_t index; - result = udJSON_ProcessArrayOperator(pRoot, const_cast(&pV), &index, exp.pKey, &charCount, pSetToValue != nullptr); - if (!pSetToValue && !exp.pRemainingExpression) + UD_ERROR_NULL(pV, udR_NotFound); + // End of the expression with no set, means remove the item + if (pRoot->IsObject()) { - UD_ERROR_NULL(pV, udR_NotFound); - // End of the expression with no set, means remove the item - if (pRoot->IsObject()) - { - udJSONKVPair *pItem = pRoot->AsObject()->GetElement(index); - udFree(pItem->pKey); - pItem->value.Destroy(); - pRoot->AsObject()->RemoveAt(index); - } - else if (pRoot->IsArray()) - { - pV->Destroy(); - pRoot->AsArray()->RemoveAt(index); - } + udJSONKVPair *pItem = pRoot->AsObject()->GetElement(index); + udFree(pItem->pKey); + pItem->value.Destroy(); + pRoot->AsObject()->RemoveAt(index); } - else + else if (pRoot->IsArray()) { - pRoot = pV; - UD_ERROR_NULL(pRoot, udR_ParseError); + pV->Destroy(); + pRoot->AsArray()->RemoveAt(index); } } - break; + else + { + pRoot = pV; + UD_ERROR_NULL(pRoot, udR_ParseError); + } + } + break; case '.': // Fall through to default case default: // op == 0 here @@ -980,17 +999,39 @@ udResult udJSON::Parse(const char *pString, int *pCharCount, int *pLineNumber) { switch (pString[++si]) { - case 'a': pStr[di++] = '\a'; break; - case 'b': pStr[di++] = '\b'; break; - case 'e': pStr[di++] = 27; break; // GCC extension for escape character - case 'f': pStr[di++] = '\f'; break; - case 'n': pStr[di++] = '\n'; break; - case 'r': pStr[di++] = '\r'; break; - case 't': pStr[di++] = '\t'; break; - case 'v': pStr[di++] = '\v'; break; - case '\\': pStr[di++] = '\\'; break; - case '\'': pStr[di++] = '\''; break; - case '\"': pStr[di++] = '\"'; break; + case 'a': + pStr[di++] = '\a'; + break; + case 'b': + pStr[di++] = '\b'; + break; + case 'e': + pStr[di++] = 27; + break; // GCC extension for escape character + case 'f': + pStr[di++] = '\f'; + break; + case 'n': + pStr[di++] = '\n'; + break; + case 'r': + pStr[di++] = '\r'; + break; + case 't': + pStr[di++] = '\t'; + break; + case 'v': + pStr[di++] = '\v'; + break; + case '\\': + pStr[di++] = '\\'; + break; + case '\'': + pStr[di++] = '\''; + break; + case '\"': + pStr[di++] = '\"'; + break; default: // Any escape sequence not recognised is output verbatim (eg \P remains \P) pStr[di++] = '\\'; @@ -1125,14 +1166,20 @@ udResult udJSON::ToString(const char **ppStr, int indent, const char *pPre, cons switch (type) { - case T_Void: result = udSprintf(ppStr, "%*s%snull%s", indent, "", pPre, pPost); break; - case T_Bool: result = udSprintf(ppStr, "%*s%s%s%s%s%s", indent, "", pPre, pQuote, u.bVal ? "true" : "false", pQuote, pPost); break; - case T_Int64: result = udSprintf(ppStr, "%*s%s%s%" PRId64 "%s%s", indent, "", pPre, pQuote, u.i64Val, pQuote, pPost); break; + case T_Void: + result = udSprintf(ppStr, "%*s%snull%s", indent, "", pPre, pPost); + break; + case T_Bool: + result = udSprintf(ppStr, "%*s%s%s%s%s%s", indent, "", pPre, pQuote, u.bVal ? "true" : "false", pQuote, pPost); + break; + case T_Int64: + result = udSprintf(ppStr, "%*s%s%s%" PRId64 "%s%s", indent, "", pPre, pQuote, u.i64Val, pQuote, pPost); + break; case T_Double: if (dPrec == 255) result = udSprintf(ppStr, "%*s%s%s%la%s%s", indent, "", pPre, pQuote, u.dVal, pQuote, pPost); else - result = udSprintf(ppStr, "%*s%s%s%.*lf%s%s", indent, "", pPre, pQuote, dPrec ? dPrec : DEFAULT_DOUBLE_TOSTRING_PRECISION, u.dVal, pQuote, pPost); + result = udSprintf(ppStr, "%*s%s%s%.*lf%s%s", indent, "", pPre, pQuote, dPrec ? dPrec : DEFAULT_DOUBLE_TOSTRING_PRECISION, u.dVal, pQuote, pPost); break; case T_String: if (escape == 1 || escape == 2) // JSON or XML escape @@ -1159,7 +1206,7 @@ udResult udJSON::ToString(const char **ppStr, int indent, const char *pPre, cons udStrchr(p, pEscChars + offset, &strCharIndex, &escCharIndex); if (p[strCharIndex]) { - newSize += udStrlen(pEscStrings[offset+escCharIndex]) - 1; + newSize += udStrlen(pEscStrings[offset + escCharIndex]) - 1; ++strCharIndex; // Skip the actual character we just escaped } p += strCharIndex; @@ -1176,8 +1223,8 @@ udResult udJSON::ToString(const char **ppStr, int indent, const char *pPre, cons newSize += strCharIndex; if (p[strCharIndex]) { - size_t l = udStrlen(pEscStrings[offset+escCharIndex]); - memcpy(pEscaped + newSize, pEscStrings[offset+escCharIndex], l); + size_t l = udStrlen(pEscStrings[offset + escCharIndex]); + memcpy(pEscaped + newSize, pEscStrings[offset + escCharIndex], l); newSize += l; ++strCharIndex; // Skip the actual character we just escaped } @@ -1210,7 +1257,7 @@ udResult udJSON::ExportJSON(const char *pKey, udJSON::LineList *pLines, int inde indent = 0; if (pKey) - result = udSprintf(&pKeyText, "\"%s\":%s", pKey, (strip) ? "" : " "); + result = udSprintf(&pKeyText, "\"%s\":%s", pKey, (strip) ? "" : " "); else pKeyText = pEmpty; @@ -1225,43 +1272,44 @@ udResult udJSON::ExportJSON(const char *pKey, udJSON::LineList *pLines, int inde break; case T_Array: - { - udJSONArray *pArray = AsArray(); - result = udSprintf(&pStr, "%*s%s%s", indent, "", pKeyText, pArray->length ? "[" : comma ? "[]," : "[]"); - UD_ERROR_HANDLE(); - result = pLines->PushBack(pStr); - UD_ERROR_HANDLE(); - pStr = nullptr; + { + udJSONArray *pArray = AsArray(); + result = udSprintf(&pStr, "%*s%s%s", indent, "", pKeyText, pArray->length ? "[" : comma ? "[]," + : "[]"); + UD_ERROR_HANDLE(); + result = pLines->PushBack(pStr); + UD_ERROR_HANDLE(); + pStr = nullptr; - if (pArray->length) + if (pArray->length) + { + for (size_t i = 0; i < pArray->length; ++i) { - for (size_t i = 0; i < pArray->length; ++i) - { - result = pArray->GetElement(i)->ExportJSON(nullptr, pLines, indent + 2, strip, i < (pArray->length - 1)); - UD_ERROR_HANDLE(); - } - result = udSprintf(&pStr, "%*s]%s", indent, "", pComma); + result = pArray->GetElement(i)->ExportJSON(nullptr, pLines, indent + 2, strip, i < (pArray->length - 1)); + UD_ERROR_HANDLE(); } + result = udSprintf(&pStr, "%*s]%s", indent, "", pComma); } - break; + } + break; case T_Object: + { + udJSONObject *pObject = AsObject(); + result = udSprintf(&pStr, "%*s%s{", indent, "", pKeyText); + UD_ERROR_HANDLE(); + result = pLines->PushBack(pStr); + UD_ERROR_HANDLE(); + pStr = nullptr; + for (size_t i = 0; i < pObject->length; ++i) { - udJSONObject *pObject = AsObject(); - result = udSprintf(&pStr, "%*s%s{", indent, "", pKeyText); + udJSONKVPair *pItem = pObject->GetElement(i); + result = pItem->value.ExportJSON(pItem->pKey, pLines, indent + 2, strip, i < (pObject->length - 1)); UD_ERROR_HANDLE(); - result = pLines->PushBack(pStr); - UD_ERROR_HANDLE(); - pStr = nullptr; - for (size_t i = 0; i < pObject->length; ++i) - { - udJSONKVPair *pItem = pObject->GetElement(i); - result = pItem->value.ExportJSON(pItem->pKey, pLines, indent + 2, strip, i < (pObject->length - 1)); - UD_ERROR_HANDLE(); - } - result = udSprintf(&pStr, "%*s}%s", indent, "", pComma); } - break; + result = udSprintf(&pStr, "%*s}%s", indent, "", pComma); + } + break; default: UD_ERROR_SET(udR_InternalError); @@ -1313,121 +1361,133 @@ udResult udJSON::ExportXML(const char *pKey, udJSON::LineList *pLines, int inden break; case T_Array: + { + udJSONArray *pArray = AsArray(); + if (pArray->length == 0) + { + // Export empty arrays as an empty tag + result = udSprintf(&pStr, "%*s<%s>", indent, "", pKey, pKey); + break; + } + for (size_t i = 0; i < pArray->length; ++i) { - udJSONArray *pArray = AsArray(); - if (pArray->length == 0) + const udJSON *pValue = pArray->GetElement(i); + switch (pValue->type) { - // Export empty arrays as an empty tag - result = udSprintf(&pStr, "%*s<%s>", indent, "", pKey, pKey); break; + case T_Void: + result = udSprintf(&pStr, "%*s<%s>", indent, "", pKey, pKey); + break; + case T_Bool: + result = udSprintf(&pStr, "%*s<%s>%s", indent, "", pKey, pValue->u.bVal ? "true" : "false", pKey); + break; + case T_Int64: + result = udSprintf(&pStr, "%*s<%s>%" PRId64 "", indent, "", pKey, pValue->u.i64Val, pKey); + break; + case T_Double: + result = udSprintf(&pStr, "%*s<%s>%lf", indent, "", pKey, pValue->u.dVal, pKey); + break; + case T_String: + result = udSprintf(&pStr, "%*s<%s>%s", indent, "", pKey, pValue->u.pStr, pKey); + break; + case T_Array: + case T_Object: + result = pArray->GetElement(i)->ExportXML(pKey, pLines, indent, strip); + break; + default: + UD_ERROR_SET(udR_Failure); } - for (size_t i = 0; i < pArray->length; ++i) + UD_ERROR_HANDLE(); + if (pStr) { - const udJSON *pValue = pArray->GetElement(i); - switch (pValue->type) - { - case T_Void: result = udSprintf(&pStr, "%*s<%s>", indent, "", pKey, pKey); break; - case T_Bool: result = udSprintf(&pStr, "%*s<%s>%s", indent, "", pKey, pValue->u.bVal ? "true" : "false", pKey); break; - case T_Int64: result = udSprintf(&pStr, "%*s<%s>%" PRId64 "", indent, "", pKey, pValue->u.i64Val, pKey); break; - case T_Double: result = udSprintf(&pStr, "%*s<%s>%lf", indent, "", pKey, pValue->u.dVal, pKey); break; - case T_String: result = udSprintf(&pStr, "%*s<%s>%s", indent, "", pKey, pValue->u.pStr, pKey); break; - case T_Array: - case T_Object: - result = pArray->GetElement(i)->ExportXML(pKey, pLines, indent, strip); - break; - default: - UD_ERROR_SET(udR_Failure); - } + result = pLines->PushBack(pStr); UD_ERROR_HANDLE(); - if (pStr) - { - result = pLines->PushBack(pStr); - UD_ERROR_HANDLE(); - pStr = nullptr; - } + pStr = nullptr; } } - break; + } + break; case T_Object: - { - udJSONObject *pObject = AsObject(); - int subObjectCount = 0, attributeCount = 0; + { + udJSONObject *pObject = AsObject(); + int subObjectCount = 0, attributeCount = 0; - // First, find out how many simple attributes are present versus subobjects (exported as children) - for (size_t i = 0; i < pObject->length; ++i) - { - const udJSONKVPair *pAttribute = pObject->GetElement(i); - if (pAttribute->value.type == T_Object || pAttribute->value.type == T_Array || pAttribute->value.type == T_Void) - ++subObjectCount; - else if (!pContentString && udStrEqual(pAttribute->pKey, CONTENT_MEMBER)) - pAttribute->value.ToString(&pContentString, 0, "", "", "", 2); - else - ++attributeCount; - } + // First, find out how many simple attributes are present versus subobjects (exported as children) + for (size_t i = 0; i < pObject->length; ++i) + { + const udJSONKVPair *pAttribute = pObject->GetElement(i); + if (pAttribute->value.type == T_Object || pAttribute->value.type == T_Array || pAttribute->value.type == T_Void) + ++subObjectCount; + else if (!pContentString && udStrEqual(pAttribute->pKey, CONTENT_MEMBER)) + pAttribute->value.ToString(&pContentString, 0, "", "", "", 2); + else + ++attributeCount; + } - // Create opening tag, optionally self-closing it if there's nothing else to add to it - result = udSprintf(&pStr, "%*s<%s%s", indent, "", pKeyText, (!attributeCount && !subObjectCount && !pContentString) ? "/>" : (!attributeCount) ? ">" : ""); + // Create opening tag, optionally self-closing it if there's nothing else to add to it + result = udSprintf(&pStr, "%*s<%s%s", indent, "", pKeyText, (!attributeCount && !subObjectCount && !pContentString) ? "/>" : (!attributeCount) ? ">" + : ""); + UD_ERROR_HANDLE(); + // Export all the attributes to a separate list to be combined to a single line + LineList attributeLines; + attributeLines.Init(32); + for (size_t i = 0; i < pObject->length && attributeCount; ++i) + { + const udJSONKVPair *pAttribute = pObject->GetElement(i); + if (pAttribute->value.type == T_Object || pAttribute->value.type == T_Array || pAttribute->value.type == T_Void) // Children exported after the attributes + continue; + else if (udStrEqual(pAttribute->pKey, CONTENT_MEMBER)) + continue; + UD_ERROR_IF(pAttribute->value.type < T_Bool || pAttribute->value.type > T_String, udR_ObjectTypeMismatch); + result = pAttribute->value.ExportXML(pAttribute->pKey, &attributeLines, 0, strip); UD_ERROR_HANDLE(); - // Export all the attributes to a separate list to be combined to a single line - LineList attributeLines; - attributeLines.Init(32); - for (size_t i = 0; i < pObject->length && attributeCount; ++i) + const char *pAttrText; + if (attributeLines.PopBack(&pAttrText)) { - const udJSONKVPair *pAttribute = pObject->GetElement(i); - if (pAttribute->value.type == T_Object || pAttribute->value.type == T_Array || pAttribute->value.type == T_Void) // Children exported after the attributes - continue; - else if (udStrEqual(pAttribute->pKey, CONTENT_MEMBER)) - continue; - UD_ERROR_IF(pAttribute->value.type < T_Bool || pAttribute->value.type > T_String, udR_ObjectTypeMismatch); - result = pAttribute->value.ExportXML(pAttribute->pKey, &attributeLines, 0, strip); + --attributeCount; + // Combine the element onto the tag line, appending a closing or self-closing tag as required + // Complicated a little by injecting the content string if required + result = udSprintf(&pStr, "%s %s%s", pStr, pAttrText, + attributeCount ? "" : ((subObjectCount || pContentString) ? ">" : "/>")); + udFree(pAttrText); UD_ERROR_HANDLE(); - const char *pAttrText; - if (attributeLines.PopBack(&pAttrText)) + + // Append ">pContentString if no subojects following + if (!attributeCount && !subObjectCount && pContentString) { - --attributeCount; - // Combine the element onto the tag line, appending a closing or self-closing tag as required - // Complicated a little by injecting the content string if required - result = udSprintf(&pStr, "%s %s%s", pStr, pAttrText, - attributeCount ? "" : ((subObjectCount || pContentString) ? ">" : "/>")); - udFree(pAttrText); + result = udSprintf(&pStr, "%s%s", pStr, pContentString, pKey); UD_ERROR_HANDLE(); - - // Append ">pContentString if no subojects following - if (!attributeCount && !subObjectCount && pContentString) - { - result = udSprintf(&pStr, "%s%s", pStr, pContentString, pKey); - UD_ERROR_HANDLE(); - } } } - attributeLines.Deinit(); - result = pLines->PushBack(pStr); - UD_ERROR_HANDLE(); - pStr = nullptr; + } + attributeLines.Deinit(); + result = pLines->PushBack(pStr); + UD_ERROR_HANDLE(); + pStr = nullptr; - if (subObjectCount) + if (subObjectCount) + { + for (size_t i = 0; i < pObject->length; ++i) { - for (size_t i = 0; i < pObject->length; ++i) - { - const udJSONKVPair *pAttribute = pObject->GetElement(i); - if (pAttribute->value.type != T_Object && pAttribute->value.type != T_Array && pAttribute->value.type != T_Void) // Attributes already exported - continue; - result = pAttribute->value.ExportXML(pAttribute->pKey, pLines, indent + 2, strip); - UD_ERROR_HANDLE(); - } - if (pContentString) - { - // If a content string present with subobjects, tab in in same as they are - result = udSprintf(&pStr, "%*s%s", indent + 2, "", pContentString); - pLines->PushBack(pStr); - pStr = nullptr; - } - // Closing tag - result = udSprintf(&pStr, "%*s", indent, "", pKeyText); + const udJSONKVPair *pAttribute = pObject->GetElement(i); + if (pAttribute->value.type != T_Object && pAttribute->value.type != T_Array && pAttribute->value.type != T_Void) // Attributes already exported + continue; + result = pAttribute->value.ExportXML(pAttribute->pKey, pLines, indent + 2, strip); UD_ERROR_HANDLE(); } + if (pContentString) + { + // If a content string present with subobjects, tab in in same as they are + result = udSprintf(&pStr, "%*s%s", indent + 2, "", pContentString); + pLines->PushBack(pStr); + pStr = nullptr; + } + // Closing tag + result = udSprintf(&pStr, "%*s", indent, "", pKeyText); + UD_ERROR_HANDLE(); } - break; + } + break; default: UD_ERROR_SET(udR_InternalError); @@ -1581,7 +1641,6 @@ udResult udJSON::ParseJSON(const char *pJSON, int *pCharCount, int *pLineNumber) pJSON = udStrSkipWhiteSpace(pJSON + 1, nullptr, pLineNumber); } ++pJSON; // Skip the final close brace - } else if (*pJSON == '[') { @@ -1666,7 +1725,7 @@ static udResult ParseXMLString(const char **ppStr, const char *pXML, int *pCharC { for (int e = 0; pXML[si] == '&' && !escaped && e < (int)UDARRAYSIZE(s_pXMLEscStrings); ++e) { - if (udStrBeginsWith(pXML+si, s_pXMLEscStrings[e])) + if (udStrBeginsWith(pXML + si, s_pXMLEscStrings[e])) { pStr[di++] = s_xmlEscChars[e]; si += (int)udStrlen(s_pXMLEscStrings[e]); @@ -1731,14 +1790,14 @@ udResult udJSON::ParseXML(const char *pXML, int *pCharCount, int *pLineNumber) pElementName = udStrndup(pXML, len); pXML = udStrSkipWhiteSpace(pXML + len, nullptr, pLineNumber); // So here we have the name of the element, but it might already exist or not - pElement = const_cast(FindMember(pElementName)); + pElement = const_cast(FindMember(pElementName)); if (!pElement) { // Case where the tag hasn't been encountered before, so create an object for it udJSONKVPair *pKVP = AsObject()->PushBack(); UD_ERROR_NULL(pKVP, udR_MemoryAllocationFailure); pKVP->pKey = udStrdup(pElementName); - pKVP->value.Clear(); // Initialise without prior destruction + pKVP->value.Clear(); // Initialise without prior destruction pKVP->value.SetObject(); pElement = &pKVP->value; } @@ -1837,8 +1896,8 @@ udResult udJSON::ParseXML(const char *pXML, int *pCharCount, int *pLineNumber) } } UD_ERROR_IF(!*pXML, udR_ParseError); - pXML = udStrSkipWhiteSpace(pXML + 2, nullptr, pLineNumber); // Skip ', udR_ParseError); pXML = udStrSkipWhiteSpace(pXML + 1, nullptr, pLineNumber); // Skip > diff --git a/Source/udPlatform.cpp b/Source/udPlatform.cpp index 7103b209..0489d872 100644 --- a/Source/udPlatform.cpp +++ b/Source/udPlatform.cpp @@ -4,21 +4,27 @@ #include #if UDPLATFORM_WINDOWS -# include +# include #elif UDPLATFORM_OSX -# include +# include #endif #if !UDPLATFORM_WINDOWS -# if defined(__i386__) || defined(__amd64__) -# include -# endif +# if defined(__i386__) || defined(__amd64__) +# include +# endif #endif #define __BREAK_ON_MEMORY_ALLOCATION_FAILURE 0 -#define DebugTrackMemoryAlloc(pMemory, size, pFile, line) udUnused(pMemory); udUnused(size); udUnused(pFile); udUnused(line); -#define DebugTrackMemoryFree(pMemory, pFile, line) udUnused(pMemory); udUnused(pFile); udUnused(line); - +#define DebugTrackMemoryAlloc(pMemory, size, pFile, line) \ + udUnused(pMemory); \ + udUnused(size); \ + udUnused(pFile); \ + udUnused(line); +#define DebugTrackMemoryFree(pMemory, pFile, line) \ + udUnused(pMemory); \ + udUnused(pFile); \ + udUnused(line); // ---------------------------------------------------------------------------- // Author: Dave Pevreal, August 2022 @@ -72,18 +78,18 @@ void *_udAlloc(size_t size, udAllocationFlags flags, const char *pFile, int line void *_udAllocAligned(size_t size, size_t alignment, udAllocationFlags flags, const char *pFile, int line) { #if defined(_MSC_VER) - void *pMemory = (flags & udAF_Zero) ? _aligned_recalloc_dbg(nullptr, size, 1, alignment, pFile, line) : _aligned_malloc_dbg(size, alignment, pFile, line); + void *pMemory = (flags & udAF_Zero) ? _aligned_recalloc_dbg(nullptr, size, 1, alignment, pFile, line) : _aligned_malloc_dbg(size, alignment, pFile, line); -#if __BREAK_ON_MEMORY_ALLOCATION_FAILURE +# if __BREAK_ON_MEMORY_ALLOCATION_FAILURE if (!pMemory) { udDebugPrintf("udAllocAligned failure, %llu", size); __debugbreak(); } -#endif // __BREAK_ON_MEMORY_ALLOCATION_FAILURE +# endif // __BREAK_ON_MEMORY_ALLOCATION_FAILURE #elif UDPLATFORM_NACL - void *pMemory = (flags & udAF_Zero) ? calloc(size, 1) : malloc(size); + void *pMemory = (flags & udAF_Zero) ? calloc(size, 1) : malloc(size); #elif defined(__GNUC__) if (alignment < sizeof(size_t)) @@ -102,7 +108,7 @@ void *_udAllocAligned(size_t size, size_t alignment, udAllocationFlags flags, co memset(pMemory, 0, size); } #else -# error "Unsupported platform!" +# error "Unsupported platform!" #endif DebugTrackMemoryAlloc(pMemory, size, pFile, line); @@ -115,7 +121,7 @@ void *_udRealloc(void *pMemory, size_t size, const char *pFile, int line) { DebugTrackMemoryFree(pMemory, pFile, line); #if defined(_MSC_VER) - pMemory = _aligned_realloc_dbg(pMemory, size, UD_DEFAULT_ALIGNMENT, pFile, line); + pMemory = _aligned_realloc_dbg(pMemory, size, UD_DEFAULT_ALIGNMENT, pFile, line); #else pMemory = realloc(pMemory, size); #endif // defined(_MSC_VER) @@ -129,7 +135,6 @@ void *_udRealloc(void *pMemory, size_t size, const char *pFile, int line) #endif // __BREAK_ON_MEMORY_ALLOCATION_FAILURE DebugTrackMemoryAlloc(pMemory, size, pFile, line); - return pMemory; } @@ -140,13 +145,13 @@ void *_udReallocAligned(void *pMemory, size_t size, size_t alignment, const char DebugTrackMemoryFree(pMemory, pFile, line); #if defined(_MSC_VER) pMemory = _aligned_realloc_dbg(pMemory, size, alignment, pFile, line); -#if __BREAK_ON_MEMORY_ALLOCATION_FAILURE +# if __BREAK_ON_MEMORY_ALLOCATION_FAILURE if (!pMemory) { udDebugPrintf("udReallocAligned failure, %llu", size); __debugbreak(); } -#endif // __BREAK_ON_MEMORY_ALLOCATION_FAILURE +# endif // __BREAK_ON_MEMORY_ALLOCATION_FAILURE #elif UDPLATFORM_NACL pMemory = realloc(pMemory, size); #elif defined(__GNUC__) @@ -158,24 +163,23 @@ void *_udReallocAligned(void *pMemory, size_t size, size_t alignment, const char { void *pNewMem = _udAllocAligned(size, alignment, udAF_None, pFile, line); - size_t *pSize = (size_t*)((uint8_t*)pMemory - sizeof(size_t)); + size_t *pSize = (size_t *)((uint8_t *)pMemory - sizeof(size_t)); memcpy(pNewMem, pMemory, *pSize); _udFree(pMemory, pFile, line); return pNewMem; } #else -# error "Unsupported platform!" +# error "Unsupported platform!" #endif DebugTrackMemoryAlloc(pMemory, size, pFile, line); - return pMemory; } // ---------------------------------------------------------------------------- // Author: David Ely -void _udFreeInternal(void * pMemory, const char *pFile, int line) +void _udFreeInternal(void *pMemory, const char *pFile, int line) { DebugTrackMemoryFree(pMemory, pFile, line); #if defined(_MSC_VER) @@ -203,13 +207,13 @@ udResult udGetTotalPhysicalMemory(uint64_t *pTotalMemory) } #elif UDPLATFORM_LINUX - // see http://nadeausoftware.com/articles/2012/09/c_c_tip_how_get_physical_memory_size_system for - // explanation. + // see http://nadeausoftware.com/articles/2012/09/c_c_tip_how_get_physical_memory_size_system for + // explanation. -# if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE) - *pTotalMemory = (uint64_t)sysconf(_SC_PHYS_PAGES) * (uint64_t)sysconf(_SC_PAGESIZE); - return udR_Success; -# endif +# if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE) + *pTotalMemory = (uint64_t)sysconf(_SC_PHYS_PAGES) * (uint64_t)sysconf(_SC_PAGESIZE); + return udR_Success; +# endif #elif UDPLATFORM_OSX int mib[2]; @@ -228,7 +232,7 @@ udResult udGetTotalPhysicalMemory(uint64_t *pTotalMemory) } #if ((defined(_WIN32) || defined(_WIN64)) && (_M_IX86 || _M_X64)) || defined(__i386__) || defined(__amd64__) -# define UD_HASCPUID +# define UD_HASCPUID #endif class udCPUFeatureDetection @@ -297,10 +301,10 @@ void udCPUFeatureDetection::DetectFeatures() #if defined(UD_HASCPUID) void udCPUFeatureDetection::cpuid(int out[4], int eax, int ecx) { -#if UDPLATFORM_WINDOWS +# if UDPLATFORM_WINDOWS __cpuidex(out, eax, ecx); -#else +# else __cpuid_count(eax, ecx, out[0], out[1], out[2], out[3]); -#endif +# endif } #endif diff --git a/Source/udPlatformUtil.cpp b/Source/udPlatformUtil.cpp index eec9a357..19249275 100644 --- a/Source/udPlatformUtil.cpp +++ b/Source/udPlatformUtil.cpp @@ -1,27 +1,27 @@ #define _CRT_SECURE_NO_WARNINGS #include "udPlatformUtil.h" -#include "udStringUtil.h" #include "udFile.h" -#include "udMath.h" #include "udJSON.h" +#include "udMath.h" +#include "udStringUtil.h" +#include #include #include -#include #if UDPLATFORM_WINDOWS -# include -# include +# include +# include #else -# include -# include -# include "dirent.h" -# include -# include -# include +# include "dirent.h" +# include +# include +# include +# include +# include static const uint64_t nsec_per_sec = 1000000000; // 1 billion nanoseconds in one second static const uint64_t nsec_per_msec = 1000000; // 1 million nanoseconds in one millisecond -//static const uint64_t usec_per_msec = 1000; // 1 thousand microseconds in one millisecond + //static const uint64_t usec_per_msec = 1000; // 1 thousand microseconds in one millisecond #endif static char s_udStrEmptyString[] = ""; @@ -35,7 +35,7 @@ void udUpdateCamera(double camera[16], double yawRadians, double pitchRadians, d rotation.axis.t = udDouble4::identity(); if (yawRadians != 0.0) - rotation = udDouble4x4::rotationZ(yawRadians) * rotation; // Yaw on global axis + rotation = udDouble4x4::rotationZ(yawRadians) * rotation; // Yaw on global axis if (pitchRadians != 0.0) rotation = rotation * udDouble4x4::rotationX(pitchRadians); // Pitch on local axis udDouble3 trans = udDouble3::zero(); @@ -103,7 +103,6 @@ uint64_t udPerfCounterStart() #endif } - // ********************************************************************* // Author: Dave Pevreal, June 2014 float udPerfCounterMilliseconds(uint64_t startValue, uint64_t end) @@ -141,23 +140,23 @@ float udPerfCounterSeconds(uint64_t startValue, uint64_t end) // Author: Dave Pevreal, April 2018 int udDaysUntilExpired(int maxDays, const char **ppExpireDateStr) { - // Calculate the build year/month compile-time constants - #define BUILDDATE __DATE__ - #define BUILDDATEYEAR (BUILDDATE[7]*1000 + BUILDDATE[8]*100 + BUILDDATE[9]*10 + BUILDDATE[10] - 1111*'0') - #define BUILDDATEMONTH (((BUILDDATE[0] == 'J') && (BUILDDATE[1] == 'a') && (BUILDDATE[2] == 'n')) ? 1 : ( /* Jan */ \ - ((BUILDDATE[0] == 'F') && (BUILDDATE[1] == 'e') && (BUILDDATE[2] == 'b')) ? 2 : ( /* Feb */ \ - ((BUILDDATE[0] == 'M') && (BUILDDATE[1] == 'a') && (BUILDDATE[2] == 'r')) ? 3 : ( /* Mar */ \ - ((BUILDDATE[0] == 'A') && (BUILDDATE[1] == 'p') && (BUILDDATE[2] == 'r')) ? 4 : ( /* Apr */ \ - ((BUILDDATE[0] == 'M') && (BUILDDATE[1] == 'a') && (BUILDDATE[2] == 'y')) ? 5 : ( /* May */ \ - ((BUILDDATE[0] == 'J') && (BUILDDATE[1] == 'u') && (BUILDDATE[2] == 'n')) ? 6 : ( /* Jun */ \ - ((BUILDDATE[0] == 'J') && (BUILDDATE[1] == 'u') && (BUILDDATE[2] == 'l')) ? 7 : ( /* Jul */ \ - ((BUILDDATE[0] == 'A') && (BUILDDATE[1] == 'u') && (BUILDDATE[2] == 'g')) ? 8 : ( /* Aug */ \ - ((BUILDDATE[0] == 'S') && (BUILDDATE[1] == 'e') && (BUILDDATE[2] == 'p')) ? 9 : ( /* Sep */ \ - ((BUILDDATE[0] == 'O') && (BUILDDATE[1] == 'c') && (BUILDDATE[2] == 't')) ? 10 : ( /* Oct */ \ - ((BUILDDATE[0] == 'N') && (BUILDDATE[1] == 'o') && (BUILDDATE[2] == 'v')) ? 11 : ( /* Nov */ \ - ((BUILDDATE[0] == 'D') && (BUILDDATE[1] == 'e') && (BUILDDATE[2] == 'c')) ? 12 : ( /* Dec */ \ - -1 ))))))))))))) - #define BUILDDATEDAY ((BUILDDATE[4] == ' ' ? '0' : BUILDDATE[4]) * 10 + BUILDDATE[5] - 11*'0') +// Calculate the build year/month compile-time constants +#define BUILDDATE __DATE__ +#define BUILDDATEYEAR (BUILDDATE[7] * 1000 + BUILDDATE[8] * 100 + BUILDDATE[9] * 10 + BUILDDATE[10] - 1111 * '0') +#define BUILDDATEMONTH (((BUILDDATE[0] == 'J') && (BUILDDATE[1] == 'a') && (BUILDDATE[2] == 'n')) ? 1 : ( /* Jan */ \ + ((BUILDDATE[0] == 'F') && (BUILDDATE[1] == 'e') && (BUILDDATE[2] == 'b')) ? 2 : ( /* Feb */ \ + ((BUILDDATE[0] == 'M') && (BUILDDATE[1] == 'a') && (BUILDDATE[2] == 'r')) ? 3 : ( /* Mar */ \ + ((BUILDDATE[0] == 'A') && (BUILDDATE[1] == 'p') && (BUILDDATE[2] == 'r')) ? 4 : ( /* Apr */ \ + ((BUILDDATE[0] == 'M') && (BUILDDATE[1] == 'a') && (BUILDDATE[2] == 'y')) ? 5 : ( /* May */ \ + ((BUILDDATE[0] == 'J') && (BUILDDATE[1] == 'u') && (BUILDDATE[2] == 'n')) ? 6 : ( /* Jun */ \ + ((BUILDDATE[0] == 'J') && (BUILDDATE[1] == 'u') && (BUILDDATE[2] == 'l')) ? 7 : ( /* Jul */ \ + ((BUILDDATE[0] == 'A') && (BUILDDATE[1] == 'u') && (BUILDDATE[2] == 'g')) ? 8 : ( /* Aug */ \ + ((BUILDDATE[0] == 'S') && (BUILDDATE[1] == 'e') && (BUILDDATE[2] == 'p')) ? 9 : ( /* Sep */ \ + ((BUILDDATE[0] == 'O') && (BUILDDATE[1] == 'c') && (BUILDDATE[2] == 't')) ? 10 : ( /* Oct */ \ + ((BUILDDATE[0] == 'N') && (BUILDDATE[1] == 'o') && (BUILDDATE[2] == 'v')) ? 11 : ( /* Nov */ \ + ((BUILDDATE[0] == 'D') && (BUILDDATE[1] == 'e') && (BUILDDATE[2] == 'c')) ? 12 : (/* Dec */ \ + -1))))))))))))) +#define BUILDDATEDAY ((BUILDDATE[4] == ' ' ? '0' : BUILDDATE[4]) * 10 + BUILDDATE[5] - 11 * '0') time_t nowMoment = time(0), testMoment; struct tm nowTm = *localtime(&nowMoment); @@ -166,10 +165,10 @@ int udDaysUntilExpired(int maxDays, const char **ppExpireDateStr) buildTm.tm_year = BUILDDATEYEAR - 1900; buildTm.tm_mon = BUILDDATEMONTH - 1; buildTm.tm_mday = BUILDDATEDAY; // Only field that starts at 1 not zero. - #undef BUILDDATE - #undef BUILDDATEYEAR - #undef BUILDDATEMONTH - #undef BUILDDATEDAY +#undef BUILDDATE +#undef BUILDDATEYEAR +#undef BUILDDATEMONTH +#undef BUILDDATEDAY int daysSince = -1; do @@ -213,7 +212,7 @@ double udGetEpochSecsUTCf() udOSString::udOSString(const char *pString) { size_t len = udStrlen(pString) + 1; - pUTF8 = const_cast(pString); + pUTF8 = const_cast(pString); pWide = udAllocType(wchar_t, len, udAF_None); pAllocation = pWide; @@ -228,7 +227,7 @@ udOSString::udOSString(const wchar_t *pString) size_t len = wcslen(pString) + 1; size_t allocSize = len * 4; pUTF8 = udAllocType(char, allocSize, udAF_None); - pWide = const_cast(pString); + pWide = const_cast(pString); pAllocation = pUTF8; if (WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, pString, -1, pUTF8, (int)allocSize, nullptr, nullptr) == 0) @@ -266,7 +265,7 @@ udResult udBase64Decode(const char *pString, size_t length, uint8_t *pOutput, si UD_ERROR_NULL(pString, udR_InvalidParameter); UD_ERROR_NULL(pOutput, udR_InvalidParameter); - for (size_t inputIndex = 0; inputIndex < length; ) + for (size_t inputIndex = 0; inputIndex < length;) { char *c = strchr(b64, pString[inputIndex++]); if (c) @@ -338,7 +337,7 @@ udResult udBase64Encode(const void *pBinary, size_t binaryLength, char *pString, for (size_t inputIndex = 0; inputIndex < binaryLength; ++inputIndex) { - accum = (accum << 8) | ((uint8_t*)pBinary)[inputIndex]; + accum = (accum << 8) | ((uint8_t *)pBinary)[inputIndex]; accumBits += 8; while (accumBits >= 6) { @@ -353,15 +352,15 @@ udResult udBase64Encode(const void *pBinary, size_t binaryLength, char *pString, { UD_ERROR_IF(outputIndex >= strLength + 3, udR_BufferTooSmall); pString[outputIndex] = b64[(accum & 0x3) << 4]; - pString[outputIndex+1] = '='; //Pad chars - pString[outputIndex+2] = '='; + pString[outputIndex + 1] = '='; //Pad chars + pString[outputIndex + 2] = '='; outputIndex += 3; } else if (accumBits == 4) { UD_ERROR_IF(outputIndex + 2 >= strLength, udR_BufferTooSmall); pString[outputIndex] = b64[(accum & 0xF) << 2]; - pString[outputIndex+1] = '='; //Pad chars + pString[outputIndex + 1] = '='; //Pad chars outputIndex += 2; } pString[outputIndex++] = 0; // Null terminate if room in the string @@ -550,17 +549,17 @@ bool udFilename::SetFolder(const char *pFolder) // If the path doesn't have a trailing seperator, look for one so we can // append one already being used. That is c:\path\ or c:/path/ - if (i > 2 && pFolder[i-2] != '/' && pFolder[i-2] != '\\' && pFolder[i-2] != ':') + if (i > 2 && pFolder[i - 2] != '/' && pFolder[i - 2] != '\\' && pFolder[i - 2] != ':') { for (--i; i > 0; --i) { - if (pFolder[i-1] == '\\' || pFolder[i-1] == ':') + if (pFolder[i - 1] == '\\' || pFolder[i - 1] == ':') { separator = '\\'; break; } - if (pFolder[i-1] == '/') + if (pFolder[i - 1] == '/') break; } // TODO: Get correct separator from system when one isn't found @@ -709,7 +708,6 @@ void udFilename::CalculateIndices() filenameIndex = 0; } - // ********************************************************************* // Author: Dave Pevreal, March 2014 void udFilename::Debug() @@ -722,7 +720,6 @@ void udFilename::Debug() udDebugPrintf("folder<%s> name<%s> ext<%s> filename<%s> -> %s\n", folder, name, GetExt(), GetFilenameWithExt(), pPath); } - // ********************************************************************* // Author: Dave Pevreal, March 2014 udResult udURL::SetURL(const char *pURL) @@ -731,8 +728,22 @@ udResult udURL::SetURL(const char *pURL) pScheme = s_udStrEmptyString; pDomain = s_udStrEmptyString; pPath = s_udStrEmptyString; - static const char specialChars[] = { ' ', '#', '%', '+', '?', '\0', }; // Made for extending later, not wanting to encode any more than we need to - static const char *pSpecialSubs[] = { "%20", "%23", "%25", "%2B", "%3F", "", }; + static const char specialChars[] = { + ' ', + '#', + '%', + '+', + '?', + '\0', + }; // Made for extending later, not wanting to encode any more than we need to + static const char *pSpecialSubs[] = { + "%20", + "%23", + "%25", + "%2B", + "%3F", + "", + }; if (pURL) { @@ -759,12 +770,13 @@ udResult udURL::SetURL(const char *pURL) // Isolate the domain - this is slightly painful because ipv6 has colons pDomain = p; udStrchr(p, p[0] == '[' ? "/]" : "/:", &i); // Find the character that breaks the domain, but don't search past a slash - if (p[0] == '[' && p[i] == ']') ++i; // Skip over closing bracket of ipv6 address + if (p[0] == '[' && p[i] == ']') + ++i; // Skip over closing bracket of ipv6 address if (p[i] == ':') { // A colon is present, so decode the port number int portChars; - port = udStrAtoi(&p[i+1], &portChars); + port = udStrAtoi(&p[i + 1], &portChars); p[i] = 0; // null terminate the domain i += portChars + 1; } @@ -776,7 +788,7 @@ udResult udURL::SetURL(const char *pURL) if (p[i] != 0) { memmove(p + i + 1, p + i, udStrlen(p + i) + 1); // Move the string one to the right to retain the separator (note: 1 byte was added to allocation when udStrdup called) - p[i++] = 0; // null terminate the domain + p[i++] = 0; // null terminate the domain } } p += i; @@ -785,7 +797,7 @@ udResult udURL::SetURL(const char *pURL) pPath = p; // Now, find any "special" URL characters in the path and encode them - while ((p = (char*)udStrchr(p, specialChars, nullptr, &charListIndex)) != nullptr) + while ((p = (char *)udStrchr(p, specialChars, nullptr, &charListIndex)) != nullptr) { size_t len = udStrlen(pSpecialSubs[charListIndex]); memmove(p + len - 1, p, udStrlen(p) + 1); @@ -797,28 +809,27 @@ udResult udURL::SetURL(const char *pURL) return udR_Success; // TODO: Perhaps return an error if the url isn't formed properly } - #pragma pack(push) #pragma pack(2) struct udBMPHeader { - uint16_t bfType; // must be 'BM' - uint32_t bfSize; // size of the whole .bmp file - uint16_t bfReserved1; // must be 0 - uint16_t bfReserved2; // must be 0 - uint32_t bfOffBits; - - uint32_t biSize; // size of the structure - int32_t biWidth; // image width - int32_t biHeight; // image height - uint16_t biPlanes; // bitplanes - uint16_t biBitCount; // resolution - uint32_t biCompression; // compression - uint32_t biSizeImage; // size of the image - int32_t biXPelsPerMeter; // pixels per meter X - int32_t biYPelsPerMeter; // pixels per meter Y - uint32_t biClrUsed; // colors used - uint32_t biClrImportant; // important colors + uint16_t bfType; // must be 'BM' + uint32_t bfSize; // size of the whole .bmp file + uint16_t bfReserved1; // must be 0 + uint16_t bfReserved2; // must be 0 + uint32_t bfOffBits; + + uint32_t biSize; // size of the structure + int32_t biWidth; // image width + int32_t biHeight; // image height + uint16_t biPlanes; // bitplanes + uint16_t biBitCount; // resolution + uint32_t biCompression; // compression + uint32_t biSizeImage; // size of the image + int32_t biXPelsPerMeter; // pixels per meter X + int32_t biYPelsPerMeter; // pixels per meter Y + uint32_t biClrUsed; // colors used + uint32_t biClrImportant; // important colors }; #pragma pack(pop) @@ -838,7 +849,7 @@ udResult udSaveBMP(const char *pFilename, int width, int height, uint32_t *pColo if (!pLine) goto error; - header.bfType = 0x4d42; // 0x4d42 = 'BM' + header.bfType = 0x4d42; // 0x4d42 = 'BM' header.bfReserved1 = 0; header.bfReserved2 = 0; header.bfSize = sizeof(header) + paddedLineSize * height; @@ -863,10 +874,10 @@ udResult udSaveBMP(const char *pFilename, int width, int height, uint32_t *pColo if (result != udR_Success) goto error; - for (int y = height - 1; y >= 0 ; --y) + for (int y = height - 1; y >= 0; --y) { for (int x = 0; x < width; ++x) - memcpy(&pLine[x*3], &((uint8_t*)pColorData)[y * pitchInBytes + x * 4], 3); + memcpy(&pLine[x * 3], &((uint8_t *)pColorData)[y * pitchInBytes + x * 4], 3); result = udFile_Write(pFile, pLine, paddedLineSize); if (result != udR_Success) @@ -906,7 +917,7 @@ udResult udLoadBMP(const char *pFilename, int *pWidth, int *pHeight, uint32_t ** pLine = udAllocType(uint8_t, paddedLineSize, udAF_None); UD_ERROR_NULL(pLine, udR_MemoryAllocationFailure); - for (int y = *pHeight - 1; y >= 0 ; --y) + for (int y = *pHeight - 1; y >= 0; --y) { UD_ERROR_CHECK(udFile_Read(pFile, pLine, paddedLineSize)); uint8_t *p = pColors + y * *pWidth * 4; @@ -919,7 +930,7 @@ udResult udLoadBMP(const char *pFilename, int *pWidth, int *pHeight, uint32_t ** } } - *ppColorData = (uint32_t*)pColors; + *ppColorData = (uint32_t *)pColors; pColors = nullptr; result = udR_Success; @@ -959,38 +970,38 @@ struct udFindDirData : public udFindDir #elif UDPLATFORM_NACL //Do nothing #else -#error "Unsupported platform" +# error "Unsupported platform" #endif }; #if UD_32BIT -# define UD_STAT_STRUCT stat -# define UD_STAT_FUNC stat -# define UD_STAT_MODTIME (int64_t)st.st_mtime -# define UD_STAT_ISDIR (st.st_mode & S_IFDIR) +# define UD_STAT_STRUCT stat +# define UD_STAT_FUNC stat +# define UD_STAT_MODTIME (int64_t) st.st_mtime +# define UD_STAT_ISDIR (st.st_mode & S_IFDIR) #elif UDPLATFORM_OSX || UDPLATFORM_IOS_SIMULATOR || UDPLATFORM_IOS // Apple made these 64bit and deprecated the 64bit variants -# define UD_STAT_STRUCT stat -# define UD_STAT_FUNC stat -# define UD_STAT_MODTIME (int64_t)st.st_mtime -# define UD_STAT_ISDIR S_ISDIR(st.st_mode) +# define UD_STAT_STRUCT stat +# define UD_STAT_FUNC stat +# define UD_STAT_MODTIME (int64_t) st.st_mtime +# define UD_STAT_ISDIR S_ISDIR(st.st_mode) #elif UDPLATFORM_WINDOWS -# define UD_STAT_STRUCT _stat64 -# define UD_STAT_FUNC _wstat64 -# define UD_STAT_MODTIME (int64_t)st.st_mtime -# define UD_STAT_ISDIR (st.st_mode & _S_IFDIR) +# define UD_STAT_STRUCT _stat64 +# define UD_STAT_FUNC _wstat64 +# define UD_STAT_MODTIME (int64_t) st.st_mtime +# define UD_STAT_ISDIR (st.st_mode & _S_IFDIR) #elif UDPLATFORM_LINUX -# define UD_STAT_STRUCT stat64 -# define UD_STAT_FUNC stat64 -# define UD_STAT_MODTIME (int64_t)st.st_mtim.tv_sec -# define UD_STAT_ISDIR (st.st_mode & S_IFDIR) +# define UD_STAT_STRUCT stat64 +# define UD_STAT_FUNC stat64 +# define UD_STAT_MODTIME (int64_t) st.st_mtim.tv_sec +# define UD_STAT_ISDIR (st.st_mode & S_IFDIR) #elif UDPLATFORM_ANDROID -# define UD_STAT_STRUCT stat64 -# define UD_STAT_FUNC stat64 -# define UD_STAT_MODTIME (int64_t)st.st_mtime -# define UD_STAT_ISDIR (st.st_mode & S_IFDIR) +# define UD_STAT_STRUCT stat64 +# define UD_STAT_FUNC stat64 +# define UD_STAT_MODTIME (int64_t) st.st_mtime +# define UD_STAT_ISDIR (st.st_mode & S_IFDIR) #else -# error "Unsupported Platform" +# error "Unsupported Platform" #endif // **************************************************************************** @@ -1109,7 +1120,7 @@ udResult udOpenDir(udFindDir **ppFindDir, const char *pFolder) // TODO: See if this implementation is required UD_ERROR_SET(udR_NotFound); #else - #error "Unsupported Platform" +# error "Unsupported Platform" #endif result = udR_Success; @@ -1118,7 +1129,7 @@ udResult udOpenDir(udFindDir **ppFindDir, const char *pFolder) epilogue: if (pFindData) - udCloseDir((udFindDir**)&pFindData); + udCloseDir((udFindDir **)&pFindData); return result; } @@ -1142,9 +1153,9 @@ udResult udReadDir(udFindDir *pFindDir) return udR_NotFound; pFindData->SetMembers(); #elif UDPLATFORM_NACL - // Do nothing + // Do nothing #else - #error "Unsupported Platform" +# error "Unsupported Platform" #endif return udR_Success; } @@ -1165,9 +1176,9 @@ udResult udCloseDir(udFindDir **ppFindDir) if (pFindData->pDir) closedir(pFindData->pDir); #elif UDPLATFORM_NACL - // Do nothing + // Do nothing #else - #error "Unsupported Platform" +# error "Unsupported Platform" #endif udFree(*ppFindDir); @@ -1186,7 +1197,7 @@ udResult udCreateDir(const char *pDirPath, int *pDirsCreatedCount) char truncChar = 0; // Character at truncation point (currPathLen) UD_ERROR_NULL(pDirPath, udR_InvalidParameter); - if (udFile_TranslatePath(const_cast(&pPath), pDirPath) != udR_Success) + if (udFile_TranslatePath(const_cast(&pPath), pDirPath) != udR_Success) { pPath = udStrdup(pDirPath); UD_ERROR_NULL(pPath, udR_MemoryAllocationFailure); @@ -1201,7 +1212,7 @@ udResult udCreateDir(const char *pDirPath, int *pDirsCreatedCount) UD_ERROR_IF(fullPathLen == 0, udR_Success); // Attempt the full path first, if it completes this is the most efficient case - for (currPathLen = fullPathLen; ;) + for (currPathLen = fullPathLen;;) { #if UDPLATFORM_WINDOWS bool actuallyCreated = CreateDirectoryW(udOSString(pPath), nullptr) != 0; @@ -1299,7 +1310,8 @@ udResult udRemoveDir(const char *pDirPath, int removeCount) // Author: Dave Pevreal, May 2018 udResult udParseWKT(udJSON *pValue, const char *pString, int *pCharCount) { - udResult result = udR_Success;; + udResult result = udR_Success; + ; size_t idLen; udJSON temp; int tempCharCount = 0; @@ -1356,7 +1368,6 @@ udResult udParseWKT(udJSON *pValue, const char *pString, int *pCharCount) return result; } - // ---------------------------------------------------------------------------- // Author: Dave Pevreal, May 2018 static udResult GetWKTElementStr(const char **ppOutput, const udJSON &value) diff --git a/Source/udResult.cpp b/Source/udResult.cpp index 193da4be..bcd7aad1 100644 --- a/Source/udResult.cpp +++ b/Source/udResult.cpp @@ -2,8 +2,14 @@ #include "udDebug.h" #include "udPlatformUtil.h" -#define RESULTINFO(x) { &(#x)[4], x } -#define RESULTINFO_CUSTOM(x,str) { str, x } +#define RESULTINFO(x) \ + { \ + &(#x)[4], x \ + } +#define RESULTINFO_CUSTOM(x, str) \ + { \ + str, x \ + } const char *g_udLastErrorFilename = nullptr; int g_udLastErrorLine = 0; @@ -16,8 +22,7 @@ struct udResultInfo udResult result; // Used to make sure the array is correctly filled out }; -udResultInfo udResultInfoArray[] = -{ +udResultInfo udResultInfoArray[] = { RESULTINFO(udR_Success), RESULTINFO(udR_Failure), RESULTINFO(udR_NothingToDo), @@ -75,14 +80,13 @@ udResultInfo udResultInfoArray[] = RESULTINFO(udR_InProgress), }; -UDCOMPILEASSERT(sizeof(udResultInfoArray) == (udR_Count*sizeof(udResultInfoArray[0])), "Result code not entered in strings table"); - +UDCOMPILEASSERT(sizeof(udResultInfoArray) == (udR_Count * sizeof(udResultInfoArray[0])), "Result code not entered in strings table"); // **************************************************************************** // Author: Dave Pevreal, March 2014 const char *udResultAsString(udResult result) { - if (result < 0 || result > udR_Count) + if (result < 0 || result > udR_Count) return "Unknown error"; if (result == udR_Count) @@ -97,4 +101,3 @@ const char *udResultAsString(udResult result) } return udResultInfoArray[result].pString; } - diff --git a/Source/udSocket.cpp b/Source/udSocket.cpp index ef97b9bd..dd8f40b5 100644 --- a/Source/udSocket.cpp +++ b/Source/udSocket.cpp @@ -1,53 +1,52 @@ #include "udSocket.h" +#include "udCrypto.h" #include "udPlatformUtil.h" #include "udStringUtil.h" -#include "udCrypto.h" -#include "mbedtls/net_sockets.h" -#include "mbedtls/ssl.h" -#include "mbedtls/entropy.h" #include "mbedtls/ctr_drbg.h" #include "mbedtls/debug.h" -#include "mbedtls/x509.h" -#include "mbedtls/net_sockets.h" +#include "mbedtls/entropy.h" #include "mbedtls/error.h" +#include "mbedtls/net_sockets.h" +#include "mbedtls/ssl.h" +#include "mbedtls/x509.h" #include #if UDPLATFORM_WINDOWS -# include -# include -# include -# include -# pragma comment(lib, "ws2_32.lib") -# pragma comment(lib, "Crypt32.lib") +# include +# include +# include +# include +# pragma comment(lib, "ws2_32.lib") +# pragma comment(lib, "Crypt32.lib") #else /* Assume that any non-Windows platform uses POSIX-style sockets instead. */ -# include -# include -# include /* Needed for getaddrinfo() and freeaddrinfo() */ -# include /* Needed for close() */ -# if UDPLATFORM_EMSCRIPTEN -# include -# include -# else -# include -# endif +# include +# include /* Needed for getaddrinfo() and freeaddrinfo() */ +# include +# include /* Needed for close() */ +# if UDPLATFORM_EMSCRIPTEN +# include +# include +# else +# include +# endif #endif #if UDPLATFORM_OSX -# include +# include #endif #ifndef INVALID_SOCKET //Some platforms don't have these defined - typedef int SOCKET; -# define INVALID_SOCKET (SOCKET)(~0) -# define SOCKET_ERROR (-1) +typedef int SOCKET; +# define INVALID_SOCKET (SOCKET)(~0) +# define SOCKET_ERROR (-1) #endif //INVALID_SOCKET struct udSocketSharedData { - static std::atomic loadCount; // ref count for loaded certs; must be zero + static std::atomic loadCount; // ref count for loaded certs; must be zero static std::atomic initialised; // set to 1 once initialisation is complete static mbedtls_entropy_context entropy; static mbedtls_x509_crt certificateChain; @@ -68,7 +67,7 @@ struct udSocket { mbedtls_net_context socketContext; //The actual socket mbedtls_ctr_drbg_context ctr_drbg; //The encryption context - mbedtls_ssl_context ssl; //The socket to encryption context + mbedtls_ssl_context ssl; //The socket to encryption context mbedtls_ssl_config conf; //Additional server things @@ -96,11 +95,11 @@ udResult udSocket_LoadCACerts() // Open a scope to prevent various initialisation warnings { #if UDPLATFORM_WINDOWS -# if UDPLATFORM_UWP +# if UDPLATFORM_UWP HCERTSTORE store = CertOpenStore(CERT_STORE_PROV_SYSTEM_A, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_SYSTEM_STORE_CURRENT_USER, "Root"); -# else +# else HCERTSTORE store = CertOpenSystemStoreA(0, "Root"); -# endif +# endif UD_ERROR_NULL(store, udR_Failure); for (PCCERT_CONTEXT cert = CertEnumCertificatesInStore(store, nullptr); cert; cert = CertEnumCertificatesInStore(store, cert)) { @@ -125,7 +124,7 @@ udResult udSocket_LoadCACerts() CFDictionarySetValue(search, kSecReturnRef, kCFBooleanTrue); CFDictionarySetValue(search, kSecMatchSearchList, CFArrayCreate(NULL, (const void **)&keychain, 1, NULL)); - if (SecItemCopyMatching(search, (CFTypeRef*)&cfResult) == errSecSuccess) + if (SecItemCopyMatching(search, (CFTypeRef *)&cfResult) == errSecSuccess) { CFIndex n = CFArrayGetCount(cfResult); for (CFIndex i = 0; i < n; i++) @@ -136,7 +135,7 @@ udResult udSocket_LoadCACerts() dat = SecCertificateCopyData(item); if (dat) { - if (mbedtls_x509_crt_parse_der(&udSocketSharedData::certificateChain, (unsigned char*)CFDataGetBytePtr(dat), CFDataGetLength(dat)) == 0) + if (mbedtls_x509_crt_parse_der(&udSocketSharedData::certificateChain, (unsigned char *)CFDataGetBytePtr(dat), CFDataGetLength(dat)) == 0) certParsed = true; CFRelease(dat); } @@ -267,7 +266,6 @@ bool udSocket_IsValidSocket(udSocket *pSocket) return (pSocket->basicSocket != INVALID_SOCKET); } - // -------------------------------------------------------------------------- // Author: Paul Fox, October 2018 static void udSocketmbedDebug(void * /*pUserData*/, int /*level*/, const char *file, int line, const char *str) @@ -320,10 +318,10 @@ udResult udSocket_Open(udSocket **ppSocket, const char *pAddress, uint32_t port, { udDebugPrintf(" failed! Certificate and private key cannot be null if running a secure server!\n"); UD_ERROR_SET(udR_InvalidConfiguration); - } + } // Set up server certificate - retVal = mbedtls_x509_crt_parse(&pSocket->tlsClient.certificateServer, (const unsigned char *)pPublicCertificate, udStrlen(pPublicCertificate)+1); + retVal = mbedtls_x509_crt_parse(&pSocket->tlsClient.certificateServer, (const unsigned char *)pPublicCertificate, udStrlen(pPublicCertificate) + 1); if (retVal != 0) { udDebugPrintf(" failed! mbedtls_x509_crt_parse returned %d\n", retVal); @@ -332,7 +330,7 @@ udResult udSocket_Open(udSocket **ppSocket, const char *pAddress, uint32_t port, // Set up public key mbedtls_pk_init(&pSocket->tlsClient.publicKey); - retVal = mbedtls_pk_parse_key(&pSocket->tlsClient.publicKey, (const unsigned char *)pPrivateKey, udStrlen(pPrivateKey)+1, NULL, 0, NULL, NULL); + retVal = mbedtls_pk_parse_key(&pSocket->tlsClient.publicKey, (const unsigned char *)pPrivateKey, udStrlen(pPrivateKey) + 1, NULL, 0, NULL, NULL); if (retVal != 0) { udDebugPrintf(" failed! mbedtls_pk_parse_key returned %d\n", retVal); @@ -566,7 +564,7 @@ udResult udSocket_ReceiveData(udSocket *pSocket, uint8_t *pBytes, int64_t buffer if (pSocket->isSecure) actualReceived = mbedtls_ssl_read(&pSocket->tlsClient.ssl, pBytes, bufferSize); else - actualReceived = recv(pSocket->basicSocket, (char*)pBytes, (int)bufferSize, 0); + actualReceived = recv(pSocket->basicSocket, (char *)pBytes, (int)bufferSize, 0); UD_ERROR_IF(actualReceived < 0, udR_SocketError); @@ -621,7 +619,7 @@ bool udSocket_ServerAcceptClientPartA(udSocket *pServerSocket, udSocket **ppClie { sockaddr_storage clientAddr; socklen_t clientAddrSize = sizeof(clientAddr); - SOCKET clientSocket = accept(pServerSocket->basicSocket, (sockaddr*)&clientAddr, &clientAddrSize); + SOCKET clientSocket = accept(pServerSocket->basicSocket, (sockaddr *)&clientAddr, &clientAddrSize); if (clientSocket != INVALID_SOCKET) { @@ -630,7 +628,7 @@ bool udSocket_ServerAcceptClientPartA(udSocket *pServerSocket, udSocket **ppClie if (pIPv4Address != nullptr) { - sockaddr_in *pAddrV4 = (sockaddr_in*)&clientAddr; + sockaddr_in *pAddrV4 = (sockaddr_in *)&clientAddr; memcpy(clientIP, &pAddrV4->sin_addr.s_addr, sizeof(pAddrV4->sin_addr.s_addr)); *pIPv4Address = (clientIP[0] << 24) | (clientIP[1] << 16) | (clientIP[2] << 8) | (clientIP[3]); } diff --git a/Source/udStringUtil.cpp b/Source/udStringUtil.cpp index d188993a..0098135d 100644 --- a/Source/udStringUtil.cpp +++ b/Source/udStringUtil.cpp @@ -2,10 +2,10 @@ #include "udStringUtil.h" #include "udMath.h" +#include #include -#include #include -#include +#include static char s_udStrEmptyString[] = ""; @@ -46,7 +46,7 @@ size_t udStrncpy(char *dest, size_t destLen, const char *src, size_t maxChars) return 0; } memcpy(dest, src, srcChars); // Use crt strcpy as it's likely to be very fast - dest[srcChars] = 0; // Nul terminate + dest[srcChars] = 0; // Nul terminate return srcChars + 1; } @@ -54,8 +54,10 @@ size_t udStrncpy(char *dest, size_t destLen, const char *src, size_t maxChars) // Author: Dave Pevreal, March 2014 size_t udStrcat(char *pDest, size_t destLen, const char *pSrc) { - if (!pDest) return 0; - if (!pSrc) pSrc = s_udStrEmptyString; + if (!pDest) + return 0; + if (!pSrc) + pSrc = s_udStrEmptyString; size_t destChars = strlen(pDest); // Note: Not including terminator size_t srcChars = strlen(pSrc); @@ -69,8 +71,10 @@ size_t udStrcat(char *pDest, size_t destLen, const char *pSrc) // Author: Dave Pevreal, March 2014 int udStrcmp(const char *pStr1, const char *pStr2) { - if (!pStr1) pStr1 = s_udStrEmptyString; - if (!pStr2) pStr2 = s_udStrEmptyString; + if (!pStr1) + pStr1 = s_udStrEmptyString; + if (!pStr2) + pStr2 = s_udStrEmptyString; int result; do @@ -85,8 +89,10 @@ int udStrcmp(const char *pStr1, const char *pStr2) // Author: Dave Pevreal, March 2014 int udStrcmpi(const char *pStr1, const char *pStr2) { - if (!pStr1) pStr1 = s_udStrEmptyString; - if (!pStr2) pStr2 = s_udStrEmptyString; + if (!pStr1) + pStr1 = s_udStrEmptyString; + if (!pStr2) + pStr2 = s_udStrEmptyString; int result; do @@ -101,8 +107,10 @@ int udStrcmpi(const char *pStr1, const char *pStr2) // Author: Samuel Surtees, April 2017 int udStrncmp(const char *pStr1, const char *pStr2, size_t maxChars) { - if (!pStr1) pStr1 = s_udStrEmptyString; - if (!pStr2) pStr2 = s_udStrEmptyString; + if (!pStr1) + pStr1 = s_udStrEmptyString; + if (!pStr2) + pStr2 = s_udStrEmptyString; int result = 0; if (maxChars) @@ -120,8 +128,10 @@ int udStrncmp(const char *pStr1, const char *pStr2, size_t maxChars) // Author: Samuel Surtees, April 2017 int udStrncmpi(const char *pStr1, const char *pStr2, size_t maxChars) { - if (!pStr1) pStr1 = s_udStrEmptyString; - if (!pStr2) pStr2 = s_udStrEmptyString; + if (!pStr1) + pStr1 = s_udStrEmptyString; + if (!pStr2) + pStr2 = s_udStrEmptyString; int result = 0; if (maxChars) @@ -139,7 +149,8 @@ int udStrncmpi(const char *pStr1, const char *pStr2, size_t maxChars) // Author: Dave Pevreal, March 2014 size_t udStrlen(const char *pStr) { - if (!pStr) pStr = s_udStrEmptyString; + if (!pStr) + pStr = s_udStrEmptyString; size_t len = 0; while (*pStr++) @@ -152,8 +163,10 @@ size_t udStrlen(const char *pStr) // Author: Dave Pevreal, March 2014 bool udStrBeginsWith(const char *pStr, const char *pPrefix) { - if (!pStr) pStr = s_udStrEmptyString; - if (!pPrefix) pPrefix = s_udStrEmptyString; + if (!pStr) + pStr = s_udStrEmptyString; + if (!pPrefix) + pPrefix = s_udStrEmptyString; while (*pPrefix) { @@ -167,8 +180,10 @@ bool udStrBeginsWith(const char *pStr, const char *pPrefix) // Author: Samuel Surtees, April 2017 bool udStrBeginsWithi(const char *pStr, const char *pPrefix) { - if (!pStr) pStr = s_udStrEmptyString; - if (!pPrefix) pPrefix = s_udStrEmptyString; + if (!pStr) + pStr = s_udStrEmptyString; + if (!pPrefix) + pPrefix = s_udStrEmptyString; while (*pPrefix) { @@ -182,8 +197,10 @@ bool udStrBeginsWithi(const char *pStr, const char *pPrefix) // Author: Dave Pevreal, August 2018 bool udStrEndsWith(const char *pStr, const char *pSuffix) { - if (!pStr) pStr = s_udStrEmptyString; - if (!pSuffix) pSuffix = s_udStrEmptyString; + if (!pStr) + pStr = s_udStrEmptyString; + if (!pSuffix) + pSuffix = s_udStrEmptyString; size_t sLen = udStrlen(pStr); size_t suffixLen = udStrlen(pSuffix); @@ -196,8 +213,10 @@ bool udStrEndsWith(const char *pStr, const char *pSuffix) // Author: Dave Pevreal, August 2018 bool udStrEndsWithi(const char *pStr, const char *pSuffix) { - if (!pStr) pStr = s_udStrEmptyString; - if (!pSuffix) pSuffix = s_udStrEmptyString; + if (!pStr) + pStr = s_udStrEmptyString; + if (!pSuffix) + pSuffix = s_udStrEmptyString; size_t sLen = udStrlen(pStr); size_t suffixLen = udStrlen(pSuffix); @@ -214,8 +233,10 @@ char *_udStrdup(const char *pStr, size_t additionalChars, const char *pFile, int char *udStrdup(const char *pStr, size_t additionalChars) #endif { - if (!pStr && !additionalChars) return nullptr; // This allows us to duplicate null's as null's - if (!pStr) pStr = s_udStrEmptyString; + if (!pStr && !additionalChars) + return nullptr; // This allows us to duplicate null's as null's + if (!pStr) + pStr = s_udStrEmptyString; size_t len = udStrlen(pStr) + 1; char *pDup = (char *)_udAlloc(sizeof(char) * (len + additionalChars), udAF_None, IF_MEMORY_DEBUG(pFile, line)); @@ -225,13 +246,14 @@ char *udStrdup(const char *pStr, size_t additionalChars) return pDup; } - // ********************************************************************* // Author: Dave Pevreal, May 2017 char *udStrndup(const char *pStr, size_t maxChars, size_t additionalChars) { - if (!pStr && !additionalChars) return nullptr; // This allows us to duplicate null's as null's - if (!pStr) pStr = s_udStrEmptyString; + if (!pStr && !additionalChars) + return nullptr; // This allows us to duplicate null's as null's + if (!pStr) + pStr = s_udStrEmptyString; // Find minimum of maxChars and udStrlen(pStr) without using udStrlen which can be slow size_t len = 0; while (len < maxChars && pStr[len]) @@ -246,14 +268,15 @@ char *udStrndup(const char *pStr, size_t maxChars, size_t additionalChars) return pDup; } - // ********************************************************************* // Author: Dave Pevreal, March 2014 template const char *udStrchr_Internal(const char *pStr, const char *pCharList, size_t *pIndex, size_t *pCharListIndex) { - if (!pStr) pStr = s_udStrEmptyString; - if (!pCharList) pCharList = s_udStrEmptyString; + if (!pStr) + pStr = s_udStrEmptyString; + if (!pCharList) + pCharList = s_udStrEmptyString; size_t index; size_t listLen = udStrlen(pCharList); @@ -279,7 +302,6 @@ const char *udStrchr_Internal(const char *pStr, const char *pCharList, size_t *p return nullptr; } - // ********************************************************************* // Author: Samuel Surtees, December 2020 const char *udStrchr(const char *pStr, const char *pCharList, size_t *pIndex, size_t *pCharListIndex) @@ -287,7 +309,6 @@ const char *udStrchr(const char *pStr, const char *pCharList, size_t *pIndex, si return udStrchr_Internal(pStr, pCharList, pIndex, pCharListIndex); } - // ********************************************************************* // Author: Samuel Surtees, December 2020 const char *udStrchri(const char *pStr, const char *pCharList, size_t *pIndex, size_t *pCharListIndex) @@ -295,14 +316,15 @@ const char *udStrchri(const char *pStr, const char *pCharList, size_t *pIndex, s return udStrchr_Internal(pStr, pCharList, pIndex, pCharListIndex); } - // ********************************************************************* // Author: Samuel Surtees, May 2015 template const char *udStrrchr_Internal(const char *pStr, const char *pCharList, size_t *pIndex, size_t *pCharListIndex) { - if (!pStr) pStr = s_udStrEmptyString; - if (!pCharList) pCharList = s_udStrEmptyString; + if (!pStr) + pStr = s_udStrEmptyString; + if (!pCharList) + pCharList = s_udStrEmptyString; size_t sLen = udStrlen(pStr); size_t listLen = udStrlen(pCharList); @@ -328,7 +350,6 @@ const char *udStrrchr_Internal(const char *pStr, const char *pCharList, size_t * return nullptr; } - // ********************************************************************* // Author: Samuel Surtees, December 2020 const char *udStrrchr(const char *pStr, const char *pCharList, size_t *pIndex, size_t *pCharListIndex) @@ -336,7 +357,6 @@ const char *udStrrchr(const char *pStr, const char *pCharList, size_t *pIndex, s return udStrrchr_Internal(pStr, pCharList, pIndex, pCharListIndex); } - // ********************************************************************* // Author: Samuel Surtees, December 2020 const char *udStrrchri(const char *pStr, const char *pCharList, size_t *pIndex, size_t *pCharListIndex) @@ -344,14 +364,15 @@ const char *udStrrchri(const char *pStr, const char *pCharList, size_t *pIndex, return udStrrchr_Internal(pStr, pCharList, pIndex, pCharListIndex); } - // ********************************************************************* // Author: Dave Pevreal, March 2014 template const char *udStrstr_Internal(const char *pStr, size_t sLen, const char *pSubString, size_t *pIndex) { - if (!pStr) pStr = s_udStrEmptyString; - if (!pSubString) pSubString = s_udStrEmptyString; + if (!pStr) + pStr = s_udStrEmptyString; + if (!pSubString) + pSubString = s_udStrEmptyString; size_t i; size_t subStringIndex = 0; @@ -381,7 +402,6 @@ const char *udStrstr_Internal(const char *pStr, size_t sLen, const char *pSubStr return nullptr; } - // ********************************************************************* // Author: Samuel Surtees, December 2020 const char *udStrstr(const char *pStr, size_t sLen, const char *pSubString, size_t *pIndex) @@ -389,7 +409,6 @@ const char *udStrstr(const char *pStr, size_t sLen, const char *pSubString, size return udStrstr_Internal(pStr, sLen, pSubString, pIndex); } - // ********************************************************************* // Author: Samuel Surtees, December 2020 const char *udStrstri(const char *pStr, size_t sLen, const char *pSubString, size_t *pIndex) @@ -408,15 +427,15 @@ int udStrTokenSplit(char *pLine, const char *pDelimiters, char *pTokenArray[], i while (*pLine && tokenCount < maxTokens) { size_t delimiterIndex; - pTokenArray[tokenCount++] = pLine; // Assign token - if (udStrchr(pLine, pDelimiters, &delimiterIndex)) // Get the index of the delimiter + pTokenArray[tokenCount++] = pLine; // Assign token + if (udStrchr(pLine, pDelimiters, &delimiterIndex)) // Get the index of the delimiter { - pLine[delimiterIndex] = 0; // Null terminate the token - pLine += delimiterIndex + 1; // Move pLine to 1st char after delimiter (possibly another delimiter) + pLine[delimiterIndex] = 0; // Null terminate the token + pLine += delimiterIndex + 1; // Move pLine to 1st char after delimiter (possibly another delimiter) } else { - pLine += delimiterIndex; // Move pLine to end of the line + pLine += delimiterIndex; // Move pLine to end of the line break; } } @@ -605,13 +624,26 @@ size_t udStrMatchBrace(const char *pLine, char escapeChar) switch (*pLine) { - case '{': matchChar = '}'; break; - case '[': matchChar = ']'; break; - case '(': matchChar = ')'; break; - case '<': matchChar = '>'; break; - case '\"': matchChar = '\"'; break; - case '\'': matchChar = '\''; break; - default: return udStrlen(pLine); + case '{': + matchChar = '}'; + break; + case '[': + matchChar = ']'; + break; + case '(': + matchChar = ')'; + break; + case '<': + matchChar = '>'; + break; + case '\"': + matchChar = '\"'; + break; + case '\'': + matchChar = '\''; + break; + default: + return udStrlen(pLine); } int depth = 1; for (offset = 1; pLine[offset]; ++offset) @@ -744,7 +776,8 @@ const char *udStrEscape(const char *pStr, const char *pCharList, bool freeOrigin // Author: Dave Pevreal, August 2014 float udStrAtof(const char *pStr, int *pCharCount) { - if (!pStr) pStr = s_udStrEmptyString; + if (!pStr) + pStr = s_udStrEmptyString; int charCount = 0; int tmpCharCount = 0; @@ -783,12 +816,12 @@ float udStrAtof(const char *pStr, int *pCharCount) return result * negate; } - // ********************************************************************* // Author: Dave Pevreal, August 2014 double udStrAtof64(const char *pStr, int *pCharCount) { - if (!pStr) pStr = s_udStrEmptyString; + if (!pStr) + pStr = s_udStrEmptyString; int charCount = 0; int tmpCharCount = 0; @@ -847,7 +880,7 @@ int udAddToStringTable(char *&pStringTable, uint32_t *pStringTableLength, const offset += curStrLen + 1; } int newLength = offset + addStrLen + 1; - char *newCache = (char*)udRealloc(pStringTable, newLength); + char *newCache = (char *)udRealloc(pStringTable, newLength); if (!newCache) return -1; // A nasty case where memory allocation has failed strcpy(newCache + offset, addString); @@ -857,12 +890,12 @@ int udAddToStringTable(char *&pStringTable, uint32_t *pStringTableLength, const } #define SMALLSTRING_BUFFER_COUNT 32 -#define SMALLSTRING_BUFFER_SIZE 64 +#define SMALLSTRING_BUFFER_SIZE 64 static char s_smallStringBuffers[SMALLSTRING_BUFFER_COUNT][SMALLSTRING_BUFFER_SIZE]; // 32 cycling buffers of 64 characters -static std::atomic s_smallStringBufferIndex(0); // Cycling index, always and with (SMALLSTRING_BUFFER_COUNT-1) to get buffer index +static std::atomic s_smallStringBufferIndex(0); // Cycling index, always and with (SMALLSTRING_BUFFER_COUNT-1) to get buffer index - // **************************************************************************** - // Author: Dave Pevreal, May 2018 +// **************************************************************************** +// Author: Dave Pevreal, May 2018 const char *udTempStr(const char *pFormat, ...) { int32_t bufIndex = (s_smallStringBufferIndex++) & (SMALLSTRING_BUFFER_COUNT - 1); @@ -1059,95 +1092,117 @@ int udSprintfVA(char *pDest, size_t destLength, const char *pFormat, va_list arg // Process formatted string switch (*pFormat) { - case '0': padChar = '0'; break; - case 'l': longSpec = true; break; - case '+': forcePlus = true; break; - case '-': leftJustify = true; break; - case '#': hashSpec = true; break; - case '%': pInjectStr = pFormat; injectLen = 1; break; - case '*': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - { - int value = *pFormat == '*' ? udAbs(va_arg(args, int)) : udStrAtoi(pFormat, &charCount); - if (!widthSpec) - width = (size_t)value; - else - errorCode = -2; - widthSpec = true; - } - break; - case '.': - { - ++pFormat; - int value = *pFormat == '*' ? udAbs(va_arg(args, int)) : udStrAtoi(pFormat, &charCount); - precision = (size_t)value; - precisionSpec = true; - } - break; - case 'c': - { - numericBuffer[0] = (char)va_arg(args, int); // Chars are passed as integers - pInjectStr = numericBuffer; - injectLen = 1; - } - break; - case 's': - { - pInjectStr = va_arg(args, char*); - injectLen = udStrlen(pInjectStr); - } - break; - case 'd': - case 'i': - if (longSpec) - udStrItoa64(numericBuffer, va_arg(args, int64_t), 10, precision); - else - udStrItoa(numericBuffer, va_arg(args, uint32_t), 10, precision); - pInjectStr = numericBuffer; - injectLen = udStrlen(pInjectStr); - break; - case 'u': - if (longSpec) - udStrUtoa(numericBuffer, va_arg(args, uint64_t), 10, precision); - else - udStrUtoa(numericBuffer, va_arg(args, uint32_t), 10, precision); - pInjectStr = numericBuffer; - injectLen = udStrlen(pInjectStr); - break; - case 'x': - case 'X': - udStrcpy(numericBuffer, isupper(*pFormat) ? "0X" : "0x"); - if (longSpec) - udStrUtoa(numericBuffer + 2, sizeof(numericBuffer) - 2, va_arg(args, uint64_t), isupper(*pFormat) ? -16 : 16, precision); - else - udStrUtoa(numericBuffer + 2, sizeof(numericBuffer) - 2, va_arg(args, uint32_t), isupper(*pFormat) ? -16 : 16, precision); - pInjectStr = numericBuffer + ((hashSpec) ? 0 : 2); - injectLen = udStrlen(pInjectStr); + case '0': + padChar = '0'; + break; + case 'l': + longSpec = true; + break; + case '+': + forcePlus = true; + break; + case '-': + leftJustify = true; + break; + case '#': + hashSpec = true; + break; + case '%': + pInjectStr = pFormat; + injectLen = 1; + break; + case '*': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + int value = *pFormat == '*' ? udAbs(va_arg(args, int)) : udStrAtoi(pFormat, &charCount); + if (!widthSpec) + width = (size_t)value; + else + errorCode = -2; + widthSpec = true; + } break; - case 'b': - if (longSpec) - udStrUtoa(numericBuffer, va_arg(args, uint64_t), 2, precision); - else - udStrUtoa(numericBuffer, va_arg(args, uint32_t), 2, precision); - pInjectStr = numericBuffer; - injectLen = udStrlen(pInjectStr); + case '.': + { + ++pFormat; + int value = *pFormat == '*' ? udAbs(va_arg(args, int)) : udStrAtoi(pFormat, &charCount); + precision = (size_t)value; + precisionSpec = true; + } break; - case 'p': - case 'P': - if (sizeof(pInjectStr) == 8) - udStrUtoa(numericBuffer, va_arg(args, uint64_t), isupper(*pFormat) ? -16 : 16, precision); - else - udStrUtoa(numericBuffer, va_arg(args, uint32_t), isupper(*pFormat) ? -16 : 16, precision); - pInjectStr = numericBuffer; - injectLen = udStrlen(pInjectStr); + case 'c': + { + numericBuffer[0] = (char)va_arg(args, int); // Chars are passed as integers + pInjectStr = numericBuffer; + injectLen = 1; + } break; - case 'f': - udStrFtoa(numericBuffer, va_arg(args, double), precisionSpec ? precision : 6, padChar == ' ' ? 1 : udMax((int)width, 1)); - pInjectStr = numericBuffer; - injectLen = udStrlen(pInjectStr); + case 's': + { + pInjectStr = va_arg(args, char *); + injectLen = udStrlen(pInjectStr); + } break; - - default: - errorCode = -1; + case 'd': + case 'i': + if (longSpec) + udStrItoa64(numericBuffer, va_arg(args, int64_t), 10, precision); + else + udStrItoa(numericBuffer, va_arg(args, uint32_t), 10, precision); + pInjectStr = numericBuffer; + injectLen = udStrlen(pInjectStr); + break; + case 'u': + if (longSpec) + udStrUtoa(numericBuffer, va_arg(args, uint64_t), 10, precision); + else + udStrUtoa(numericBuffer, va_arg(args, uint32_t), 10, precision); + pInjectStr = numericBuffer; + injectLen = udStrlen(pInjectStr); + break; + case 'x': + case 'X': + udStrcpy(numericBuffer, isupper(*pFormat) ? "0X" : "0x"); + if (longSpec) + udStrUtoa(numericBuffer + 2, sizeof(numericBuffer) - 2, va_arg(args, uint64_t), isupper(*pFormat) ? -16 : 16, precision); + else + udStrUtoa(numericBuffer + 2, sizeof(numericBuffer) - 2, va_arg(args, uint32_t), isupper(*pFormat) ? -16 : 16, precision); + pInjectStr = numericBuffer + ((hashSpec) ? 0 : 2); + injectLen = udStrlen(pInjectStr); + break; + case 'b': + if (longSpec) + udStrUtoa(numericBuffer, va_arg(args, uint64_t), 2, precision); + else + udStrUtoa(numericBuffer, va_arg(args, uint32_t), 2, precision); + pInjectStr = numericBuffer; + injectLen = udStrlen(pInjectStr); + break; + case 'p': + case 'P': + if (sizeof(pInjectStr) == 8) + udStrUtoa(numericBuffer, va_arg(args, uint64_t), isupper(*pFormat) ? -16 : 16, precision); + else + udStrUtoa(numericBuffer, va_arg(args, uint32_t), isupper(*pFormat) ? -16 : 16, precision); + pInjectStr = numericBuffer; + injectLen = udStrlen(pInjectStr); + break; + case 'f': + udStrFtoa(numericBuffer, va_arg(args, double), precisionSpec ? precision : 6, padChar == ' ' ? 1 : udMax((int)width, 1)); + pInjectStr = numericBuffer; + injectLen = udStrlen(pInjectStr); + break; + + default: + errorCode = -1; } pFormat += charCount; diff --git a/Source/udThread.cpp b/Source/udThread.cpp index 57a222e5..4a5e3373 100644 --- a/Source/udThread.cpp +++ b/Source/udThread.cpp @@ -7,38 +7,40 @@ // SetThreadName function taken from https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code // Usage: SetThreadName ((DWORD)-1, "MainThread"); // -#include +# include const DWORD MS_VC_EXCEPTION = 0x406D1388; -#pragma pack(push,8) +# pragma pack(push, 8) typedef struct tagTHREADNAME_INFO { - DWORD dwType; // Must be 0x1000. - LPCSTR szName; // Pointer to name (in user addr space). + DWORD dwType; // Must be 0x1000. + LPCSTR szName; // Pointer to name (in user addr space). DWORD dwThreadID; // Thread ID (-1=caller thread). - DWORD dwFlags; // Reserved for future use, must be zero. + DWORD dwFlags; // Reserved for future use, must be zero. } THREADNAME_INFO; -#pragma pack(pop) -static void SetThreadName(DWORD dwThreadID, const char* threadName) +# pragma pack(pop) +static void SetThreadName(DWORD dwThreadID, const char *threadName) { THREADNAME_INFO info; info.dwType = 0x1000; info.szName = threadName; info.dwThreadID = dwThreadID; info.dwFlags = 0; -#pragma warning(push) -#pragma warning(disable: 6320 6322) - __try { - RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info); +# pragma warning(push) +# pragma warning(disable : 6320 6322) + __try + { + RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR *)&info); } - __except (EXCEPTION_EXECUTE_HANDLER) { + __except (EXCEPTION_EXECUTE_HANDLER) + { } -#pragma warning(pop) +# pragma warning(pop) } #else -#include -#include -#include -#include +# include +# include +# include +# include void udThread_MsToTimespec(struct timespec *pTimespec, int waitMs) { @@ -54,7 +56,7 @@ void udThread_MsToTimespec(struct timespec *pTimespec, int waitMs) } #endif -#define DEBUG_CACHE 0 +#define DEBUG_CACHE 0 #define MAX_CACHED_THREADS 16 #define CACHE_WAIT_SECONDS 30 static volatile udThread *s_pCachedThreads[MAX_CACHED_THREADS ? MAX_CACHED_THREADS : 1]; @@ -62,11 +64,11 @@ static volatile udThread *s_pCachedThreads[MAX_CACHED_THREADS ? MAX_CACHED_THREA struct udThread { // First element of structure is GUARANTEED to be the operating system thread handle -# if UDPLATFORM_WINDOWS +#if UDPLATFORM_WINDOWS HANDLE handle; -# else +#else pthread_t t; -# endif +#endif udThreadStart threadStarter; void *pThreadData; udSemaphore *pCacheSemaphore; // Semaphore is non-null only while on the cached thread list @@ -141,7 +143,6 @@ static udThreadReturnType udThread_Bootstrap(udThread *pThread) return udThreadReturnTypeConvert(threadReturnValue); } - // **************************************************************************** udResult udThread_Create(udThread **ppThread, udThreadStart threadStarter, void *pThreadData, udThreadCreateFlags /*flags*/, const char *pThreadName) { @@ -153,7 +154,7 @@ udResult udThread_Create(udThread **ppThread, udThreadStart threadStarter, void UD_ERROR_NULL(threadStarter, udR_InvalidParameter); for (slotIndex = 0; pThread == nullptr && slotIndex < MAX_CACHED_THREADS; ++slotIndex) { - pThread = const_cast(s_pCachedThreads[slotIndex]); + pThread = const_cast(s_pCachedThreads[slotIndex]); if (udInterlockedCompareExchangePointer(&s_pCachedThreads[slotIndex], nullptr, pThread) != pThread) pThread = nullptr; } @@ -174,7 +175,7 @@ udResult udThread_Create(udThread **ppThread, udThreadStart threadStarter, void pThread->threadStarter = threadStarter; pThread->pThreadData = pThreadData; pThread->refCount = 1; -# if UDPLATFORM_WINDOWS +#if UDPLATFORM_WINDOWS pThread->handle = CreateThread(NULL, 4096, (LPTHREAD_START_ROUTINE)udThread_Bootstrap, pThread, 0, NULL); #else typedef void *(*PTHREAD_START_ROUTINE)(void *); @@ -210,11 +211,21 @@ void udThread_SetPriority(udThread *pThread, udThreadPriority priority) #if UDPLATFORM_WINDOWS switch (priority) { - case udTP_Lowest: SetThreadPriority(pThread->handle, THREAD_PRIORITY_LOWEST); break; - case udTP_Low: SetThreadPriority(pThread->handle, THREAD_PRIORITY_BELOW_NORMAL); break; - case udTP_Normal: SetThreadPriority(pThread->handle, THREAD_PRIORITY_NORMAL); break; - case udTP_High: SetThreadPriority(pThread->handle, THREAD_PRIORITY_ABOVE_NORMAL); break; - case udTP_Highest: SetThreadPriority(pThread->handle, THREAD_PRIORITY_HIGHEST); break; + case udTP_Lowest: + SetThreadPriority(pThread->handle, THREAD_PRIORITY_LOWEST); + break; + case udTP_Low: + SetThreadPriority(pThread->handle, THREAD_PRIORITY_BELOW_NORMAL); + break; + case udTP_Normal: + SetThreadPriority(pThread->handle, THREAD_PRIORITY_NORMAL); + break; + case udTP_High: + SetThreadPriority(pThread->handle, THREAD_PRIORITY_ABOVE_NORMAL); + break; + case udTP_Highest: + SetThreadPriority(pThread->handle, THREAD_PRIORITY_HIGHEST); + break; } #elif UDPLATFORM_LINUX int policy = sched_getscheduler(0); @@ -331,23 +342,23 @@ udResult udThread_Join(udThread *pThread, int waitMs) } #if UDPLATFORM_OSX || UDPLATFORM_IOS -# define UD_USE_PLATFORM_SEMAPHORE 0 -# define UD_UNSUPPORTED_PLATFORM_SEMAPHORE 1 +# define UD_USE_PLATFORM_SEMAPHORE 0 +# define UD_UNSUPPORTED_PLATFORM_SEMAPHORE 1 #else -# define UD_USE_PLATFORM_SEMAPHORE 0 -# define UD_UNSUPPORTED_PLATFORM_SEMAPHORE 0 +# define UD_USE_PLATFORM_SEMAPHORE 0 +# define UD_UNSUPPORTED_PLATFORM_SEMAPHORE 0 #endif struct udSemaphore { #if UD_USE_PLATFORM_SEMAPHORE -# if UDPLATFORM_WINDOWS +# if UDPLATFORM_WINDOWS HANDLE handle; -# elif UD_UNSUPPORTED_PLATFORM_SEMAPHORE -# error "Unsupported platform." -# else +# elif UD_UNSUPPORTED_PLATFORM_SEMAPHORE +# error "Unsupported platform." +# else sem_t handle; -# endif +# endif #else udMutex *pMutex; udConditionVariable *pCondition; @@ -363,14 +374,14 @@ udSemaphore *udCreateSemaphore() udSemaphore *pSemaphore = udAllocType(udSemaphore, 1, udAF_None); UD_ERROR_NULL(pSemaphore, udR_MemoryAllocationFailure); #if UD_USE_PLATFORM_SEMAPHORE -# if UDPLATFORM_WINDOWS +# if UDPLATFORM_WINDOWS pSemaphore->handle = CreateSemaphore(NULL, 0, 0x7fffffff, NULL); UD_ERROR_NULL(pSemaphore, udR_Failure); -# elif UD_UNSUPPORTED_PLATFORM_SEMAPHORE -# error "Unsupported platform." -# else +# elif UD_UNSUPPORTED_PLATFORM_SEMAPHORE +# error "Unsupported platform." +# else UD_ERROR_IF(sem_init(&pSemaphore->handle, 0, 0) == -1, udR_Failure); -# endif +# endif #else pSemaphore->pMutex = udCreateMutex(); pSemaphore->pCondition = udCreateConditionVariable(); @@ -406,18 +417,18 @@ void udDestroySemaphore(udSemaphore **ppSemaphore) if (ppSemaphore == nullptr || *ppSemaphore == nullptr) return; - udSemaphore *pSemaphore = (*(udSemaphore*volatile*)ppSemaphore); + udSemaphore *pSemaphore = (*(udSemaphore *volatile *)ppSemaphore); if (udInterlockedCompareExchangePointer(ppSemaphore, nullptr, pSemaphore) != pSemaphore) return; #if UD_USE_PLATFORM_SEMAPHORE -# if UDPLATFORM_WINDOWS +# if UDPLATFORM_WINDOWS CloseHandle(pSemaphore->handle); -# elif UD_UNSUPPORTED_PLATFORM_SEMAPHORE -# error "Unsupported platform." -# else +# elif UD_UNSUPPORTED_PLATFORM_SEMAPHORE +# error "Unsupported platform." +# else sem_destroy(&pSemaphore->handle); -# endif +# endif udFree(pSemaphore); #else udLockMutex(pSemaphore->pMutex); @@ -433,14 +444,14 @@ void udIncrementSemaphore(udSemaphore *pSemaphore, int count) return; #if UD_USE_PLATFORM_SEMAPHORE -# if UDPLATFORM_WINDOWS +# if UDPLATFORM_WINDOWS ReleaseSemaphore(pSemaphore->handle, count, nullptr); -# elif UD_UNSUPPORTED_PLATFORM_SEMAPHORE -# error "Unsupported platform." -# else +# elif UD_UNSUPPORTED_PLATFORM_SEMAPHORE +# error "Unsupported platform." +# else while (count-- > 0) sem_post(&pSemaphore->handle); -# endif +# endif #else while (count-- > 0) { @@ -460,18 +471,18 @@ int udWaitSemaphore(udSemaphore *pSemaphore, int waitMs) return -1; #if UD_USE_PLATFORM_SEMAPHORE -# if UDPLATFORM_WINDOWS +# if UDPLATFORM_WINDOWS return WaitForSingleObject(pSemaphore->handle, waitMs); -# elif UD_UNSUPPORTED_PLATFORM_SEMAPHORE -# error "Unsupported platform." -# else +# elif UD_UNSUPPORTED_PLATFORM_SEMAPHORE +# error "Unsupported platform." +# else if (waitMs == UDTHREAD_WAIT_INFINITE) { return sem_wait(&pSemaphore->handle); } else { - struct timespec ts; + struct timespec ts; if (clock_gettime(CLOCK_REALTIME, &ts) == -1) return -1; @@ -483,7 +494,7 @@ int udWaitSemaphore(udSemaphore *pSemaphore, int waitMs) return sem_timedwait(&pSemaphore->handle, &ts); } -# endif +# endif #else udLockMutex(pSemaphore->pMutex); bool retVal; @@ -543,7 +554,7 @@ udConditionVariable *udCreateConditionVariable() pthread_cond_init(pCondition, NULL); #endif - return (udConditionVariable*)pCondition; + return (udConditionVariable *)pCondition; } // **************************************************************************** @@ -568,10 +579,10 @@ void udSignalConditionVariable(udConditionVariable *pConditionVariable, int coun while (count-- > 0) { #if UDPLATFORM_WINDOWS - CONDITION_VARIABLE *pCondition = (CONDITION_VARIABLE*)pConditionVariable; + CONDITION_VARIABLE *pCondition = (CONDITION_VARIABLE *)pConditionVariable; WakeConditionVariable(pCondition); #else - pthread_cond_t *pCondition = (pthread_cond_t*)pConditionVariable; + pthread_cond_t *pCondition = (pthread_cond_t *)pConditionVariable; pthread_cond_signal(pCondition); #endif } @@ -582,13 +593,13 @@ void udSignalConditionVariable(udConditionVariable *pConditionVariable, int coun int udWaitConditionVariable(udConditionVariable *pConditionVariable, udMutex *pMutex, int waitMs) { #if UDPLATFORM_WINDOWS - CONDITION_VARIABLE *pCondition = (CONDITION_VARIABLE*)pConditionVariable; - CRITICAL_SECTION *pCriticalSection = (CRITICAL_SECTION*)pMutex; + CONDITION_VARIABLE *pCondition = (CONDITION_VARIABLE *)pConditionVariable; + CRITICAL_SECTION *pCriticalSection = (CRITICAL_SECTION *)pMutex; BOOL retVal = SleepConditionVariableCS(pCondition, pCriticalSection, (waitMs == UDTHREAD_WAIT_INFINITE ? INFINITE : waitMs)); return (retVal == TRUE ? 0 : 1); // This isn't (!retVal) for clarity. #else - pthread_cond_t *pCondition = (pthread_cond_t*)pConditionVariable; - pthread_mutex_t *pMutexInternal = (pthread_mutex_t*)pMutex; + pthread_cond_t *pCondition = (pthread_cond_t *)pConditionVariable; + pthread_mutex_t *pMutexInternal = (pthread_mutex_t *)pMutex; int retVal = 0; if (waitMs == UDTHREAD_WAIT_INFINITE) { @@ -613,12 +624,12 @@ udRWLock *udCreateRWLock() SRWLOCK *pRWLock = udAllocType(SRWLOCK, 1, udAF_None); if (pRWLock) InitializeSRWLock(pRWLock); - return (udRWLock*)pRWLock; + return (udRWLock *)pRWLock; #else pthread_rwlock_t *pRWLock = (pthread_rwlock_t *)udAlloc(sizeof(pthread_rwlock_t)); if (pRWLock) pthread_rwlock_init(pRWLock, NULL); - return (udRWLock*)pRWLock; + return (udRWLock *)pRWLock; #endif } @@ -633,7 +644,7 @@ void udDestroyRWLock(udRWLock **ppRWLock) udFree(*ppRWLock); #else pthread_rwlock_t *pRWLock = (pthread_rwlock_t *)(*ppRWLock); - if (udInterlockedCompareExchangePointer(ppRWLock, nullptr, pRWLock) == (udRWLock*)pRWLock) + if (udInterlockedCompareExchangePointer(ppRWLock, nullptr, pRWLock) == (udRWLock *)pRWLock) { pthread_rwlock_destroy(pRWLock); udFree(pRWLock); @@ -649,11 +660,11 @@ int udReadLockRWLock(udRWLock *pRWLock) if (pRWLock) { #if UDPLATFORM_WINDOWS - SRWLOCK *pLock = (SRWLOCK*)pRWLock; + SRWLOCK *pLock = (SRWLOCK *)pRWLock; AcquireSRWLockShared(pLock); return 0; // Can't fail #else - pthread_rwlock_t *pLock = (pthread_rwlock_t*)pRWLock; + pthread_rwlock_t *pLock = (pthread_rwlock_t *)pRWLock; return pthread_rwlock_rdlock(pLock); #endif } @@ -667,11 +678,11 @@ int udWriteLockRWLock(udRWLock *pRWLock) if (pRWLock) { #if UDPLATFORM_WINDOWS - SRWLOCK *pLock = (SRWLOCK*)pRWLock; + SRWLOCK *pLock = (SRWLOCK *)pRWLock; AcquireSRWLockExclusive(pLock); return 0; // Can't fail #else - pthread_rwlock_t *pLock = (pthread_rwlock_t*)pRWLock; + pthread_rwlock_t *pLock = (pthread_rwlock_t *)pRWLock; return pthread_rwlock_wrlock(pLock); #endif } @@ -685,10 +696,10 @@ void udReadUnlockRWLock(udRWLock *pRWLock) if (pRWLock) { #if UDPLATFORM_WINDOWS - SRWLOCK *pLock = (SRWLOCK*)pRWLock; + SRWLOCK *pLock = (SRWLOCK *)pRWLock; ReleaseSRWLockShared(pLock); #else - pthread_rwlock_t *pLock = (pthread_rwlock_t*)pRWLock; + pthread_rwlock_t *pLock = (pthread_rwlock_t *)pRWLock; pthread_rwlock_unlock(pLock); #endif } @@ -701,10 +712,10 @@ void udWriteUnlockRWLock(udRWLock *pRWLock) if (pRWLock) { #if UDPLATFORM_WINDOWS - SRWLOCK *pLock = (SRWLOCK*)pRWLock; + SRWLOCK *pLock = (SRWLOCK *)pRWLock; ReleaseSRWLockExclusive(pLock); #else - pthread_rwlock_t *pLock = (pthread_rwlock_t*)pRWLock; + pthread_rwlock_t *pLock = (pthread_rwlock_t *)pRWLock; pthread_rwlock_unlock(pLock); #endif } @@ -729,7 +740,7 @@ udMutex *udCreateMutex() pthread_mutex_init(mutex, &attr); pthread_mutexattr_destroy(&attr); } - return (udMutex*)mutex; + return (udMutex *)mutex; #endif } @@ -739,7 +750,7 @@ void udDestroyMutex(udMutex **ppMutex) if (ppMutex && *ppMutex) { #if UDPLATFORM_WINDOWS - CRITICAL_SECTION *pCriticalSection = (CRITICAL_SECTION*)(*ppMutex); + CRITICAL_SECTION *pCriticalSection = (CRITICAL_SECTION *)(*ppMutex); *ppMutex = NULL; DeleteCriticalSection(pCriticalSection); udFree(pCriticalSection); @@ -758,7 +769,7 @@ udMutex *udLockMutex(udMutex *pMutex) if (pMutex) { #if UDPLATFORM_WINDOWS - EnterCriticalSection((CRITICAL_SECTION*)pMutex); + EnterCriticalSection((CRITICAL_SECTION *)pMutex); #else pthread_mutex_lock((pthread_mutex_t *)pMutex); #endif @@ -772,11 +783,9 @@ void udReleaseMutex(udMutex *pMutex) if (pMutex) { #if UDPLATFORM_WINDOWS - LeaveCriticalSection((CRITICAL_SECTION*)pMutex); + LeaveCriticalSection((CRITICAL_SECTION *)pMutex); #else pthread_mutex_unlock((pthread_mutex_t *)pMutex); #endif } } - - diff --git a/Source/udUUID.cpp b/Source/udUUID.cpp index 91c1f0b9..553a8176 100644 --- a/Source/udUUID.cpp +++ b/Source/udUUID.cpp @@ -1,9 +1,9 @@ #include "udUUID.h" -#include "udStringUtil.h" -#include "udMath.h" #include "udCrypto.h" +#include "udMath.h" #include "udPlatformUtil.h" +#include "udStringUtil.h" // *************************************************************************** // Author: Paul Fox, April 2018 @@ -27,19 +27,19 @@ udResult udUUID_SetFromString(udUUID *pUUID, const char *pStr) // *************************************************************************** // Author: Paul Fox, March 2019 -const char* udUUID_GetAsString(const udUUID &UUID) +const char *udUUID_GetAsString(const udUUID &UUID) { - return (const char*)UUID.internal_bytes; + return (const char *)UUID.internal_bytes; } // *************************************************************************** // Author: Paul Fox, April 2018 -const char* udUUID_GetAsString(const udUUID *pUUID) +const char *udUUID_GetAsString(const udUUID *pUUID) { if (pUUID == nullptr) return nullptr; - return (const char*)pUUID->internal_bytes; + return (const char *)pUUID->internal_bytes; } // *************************************************************************** @@ -93,7 +93,7 @@ udResult udUUID_GenerateFromRandom(udUUID *pUUID) if (i == 19) bytes = (bytes & 0x3F) | 0x80; //Variant bits - udStrUtoa((char*)pUUID->internal_bytes + i, udUUID::udUUID_Length - i + 1, bytes, 16, 2); + udStrUtoa((char *)pUUID->internal_bytes + i, udUUID::udUUID_Length - i + 1, bytes, 16, 2); ++index; ++i; //This block writes 2 bytes @@ -142,7 +142,7 @@ udResult udUUID_GenerateFromString(udUUID *pUUID, const char *pStr) if (i == 19) bytes = (bytes & 0x3F) | 0x80; //Variant bits - udStrUtoa((char*)pUUID->internal_bytes + i, udUUID::udUUID_Length - i + 1, bytes, 16, 2); + udStrUtoa((char *)pUUID->internal_bytes + i, udUUID::udUUID_Length - i + 1, bytes, 16, 2); ++index; ++i; //This block writes 2 bytes @@ -181,14 +181,14 @@ udResult udUUID_GenerateFromInt(udUUID *pUUID, int64_t value) // Author: Paul Fox, March 2019 bool udUUID_IsValid(const udUUID &UUID) { - return udUUID_IsValid((const char*)UUID.internal_bytes); + return udUUID_IsValid((const char *)UUID.internal_bytes); } // *************************************************************************** // Author: Paul Fox, April 2018 bool udUUID_IsValid(const udUUID *pUUID) { - return udUUID_IsValid((const char*)pUUID->internal_bytes); + return udUUID_IsValid((const char *)pUUID->internal_bytes); } // *************************************************************************** @@ -208,14 +208,14 @@ uint64_t udUUID_ToNonce(const udUUID *pUUID) // *************************************************************************** // Author: Paul Fox, April 2018 -bool operator ==(const udUUID a, const udUUID b) +bool operator==(const udUUID a, const udUUID b) { - return (udStrncmpi((const char*)a.internal_bytes, (const char*)b.internal_bytes, udUUID::udUUID_Length) == 0); + return (udStrncmpi((const char *)a.internal_bytes, (const char *)b.internal_bytes, udUUID::udUUID_Length) == 0); } // *************************************************************************** // Author: Paul Fox, May 2018 -bool operator !=(const udUUID a, const udUUID b) +bool operator!=(const udUUID a, const udUUID b) { return !(a == b); } diff --git a/Source/udWorkerPool.cpp b/Source/udWorkerPool.cpp index 92ad434f..36de5aab 100644 --- a/Source/udWorkerPool.cpp +++ b/Source/udWorkerPool.cpp @@ -3,10 +3,10 @@ #include "udSafeDeque.h" #include "udChunkedArray.h" -#include "udPlatformUtil.h" -#include "udThread.h" #include "udMath.h" +#include "udPlatformUtil.h" #include "udStringUtil.h" +#include "udThread.h" #include struct udWorkerPoolThread @@ -43,7 +43,7 @@ uint32_t udWorkerPool_DoWork(void *pPoolPtr) { UDRELASSERT(pPoolPtr != nullptr, "Bad Pool Ptr!"); - udWorkerPoolThread *pThreadData = (udWorkerPoolThread*)pPoolPtr; + udWorkerPoolThread *pThreadData = (udWorkerPoolThread *)pPoolPtr; udWorkerPool *pPool = pThreadData->pPool; udWorkerPoolTask currentTask; diff --git a/udTest/src/main.cpp b/udTest/src/main.cpp index 433f423d..f5645f4a 100644 --- a/udTest/src/main.cpp +++ b/udTest/src/main.cpp @@ -1,8 +1,8 @@ #include "gtest/gtest.h" +#include "udFile.h" #include "udPlatform.h" #include "udThread.h" -#include "udFile.h" #if UDPLATFORM_WINDOWS && UD_DEBUG # define _CRT_SECURE_NO_WARNINGS @@ -12,14 +12,20 @@ #endif #if UDPLATFORM_EMSCRIPTEN -#include +# include int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); udFile_RegisterHTTP(); int testResult = 0; - emscripten_set_main_loop_arg([](void *pArg) { int *pTestResult = (int*)pArg; *pTestResult = RUN_ALL_TESTS(); emscripten_cancel_main_loop(); }, &testResult, 60, 1); + emscripten_set_main_loop_arg([](void *pArg) + { + int *pTestResult = (int *)pArg; + *pTestResult = RUN_ALL_TESTS(); + emscripten_cancel_main_loop(); + }, + &testResult, 60, 1); udThread_DestroyCached(); // Destroy cached threads to prevent reporting of memory leak return testResult; @@ -29,20 +35,20 @@ int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); -#if UDPLATFORM_WINDOWS && UD_DEBUG +# if UDPLATFORM_WINDOWS && UD_DEBUG _CrtMemState m1, m2, diff; // To see allocation details (file and line number) you must // define '__MEMORY_DEBUG__' for all projects you wish to track // and you must also set the CRT debug flag below _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF); _CrtMemCheckpoint(&m1); -#endif //UDPLATFORM_WINDOWS && UD_DEBUG +# endif //UDPLATFORM_WINDOWS && UD_DEBUG int testResult = RUN_ALL_TESTS(); udThread_DestroyCached(); // Destroy cached threads to prevent reporting of memory leak -#if UDPLATFORM_WINDOWS && UD_DEBUG - udSleep(500); // A little extra time for threads to destroy +# if UDPLATFORM_WINDOWS && UD_DEBUG + udSleep(500); // A little extra time for threads to destroy _CrtMemCheckpoint(&m2); if (_CrtMemDifference(&diff, &m1, &m2) && diff.lCounts[_NORMAL_BLOCK] > 1) // gtest leaks 1 allocation, let's ignore it! { @@ -50,7 +56,7 @@ int main(int argc, char **argv) printf("%s\n", "Memory leaks in test found"); testResult = -1; } -#endif //UDPLATFORM_WINDOWS && UD_DEBUG +# endif //UDPLATFORM_WINDOWS && UD_DEBUG return testResult; } diff --git a/udTest/src/udBlankTests.cpp b/udTest/src/udBlankTests.cpp index fec6e981..cfa61aa7 100644 --- a/udTest/src/udBlankTests.cpp +++ b/udTest/src/udBlankTests.cpp @@ -20,5 +20,5 @@ TEST(BlankTests, Validate) EXPECT_STRCASEEQ(realStringValue, copyStringValue); EXPECT_EQ(realHexValue, copyHexValue); EXPECT_EQ(realIntValue, copyIntValue); - EXPECT_NE((void*)-1, pNullPtr); + EXPECT_NE((void *)-1, pNullPtr); } diff --git a/udTest/src/udCallbackTests.cpp b/udTest/src/udCallbackTests.cpp index f3477976..b226cb76 100644 --- a/udTest/src/udCallbackTests.cpp +++ b/udTest/src/udCallbackTests.cpp @@ -6,21 +6,25 @@ TEST(udCallbackTests, Validation) { using TestCallback = udCallback; - TestCallback basic = [](int a) -> int { return a * 2; }; + TestCallback basic = [](int a) -> int + { return a * 2; }; EXPECT_TRUE(basic); EXPECT_EQ(4, basic(2)); int a = 3; - TestCallback valCapture = [a](int b) -> int { return a * b; }; + TestCallback valCapture = [a](int b) -> int + { return a * b; }; EXPECT_EQ(6, valCapture(2)); a = 4; - TestCallback refCapture = [&a](int b) -> int { return a * b; }; + TestCallback refCapture = [&a](int b) -> int + { return a * b; }; EXPECT_EQ(6, valCapture(2)); EXPECT_EQ(8, refCapture(2)); a = 5; - TestCallback allRefCapture = [&](int b) -> int { return basic(a) * basic(b); }; + TestCallback allRefCapture = [&](int b) -> int + { return basic(a) * basic(b); }; EXPECT_EQ(6, valCapture(2)); EXPECT_EQ(10, refCapture(2)); // Note a was captured by reference, this will now produce a different result EXPECT_EQ(40, allRefCapture(2)); @@ -30,16 +34,17 @@ TEST(udCallbackTests, Validation) TestCallback nullFunc = nullptr; EXPECT_FALSE(nullFunc); - EXPECT_TRUE(nullFunc == nullptr); // Test == operator + EXPECT_TRUE(nullFunc == nullptr); // Test == operator EXPECT_FALSE(nullFunc != nullptr); // Test != operator - TestCallback nullAssignFunc = [](int a) -> int { return a * 2; }; + TestCallback nullAssignFunc = [](int a) -> int + { return a * 2; }; EXPECT_TRUE(nullAssignFunc); EXPECT_FALSE(nullAssignFunc == nullptr); // Test == operator - EXPECT_TRUE(nullAssignFunc != nullptr); // Test != operator + EXPECT_TRUE(nullAssignFunc != nullptr); // Test != operator nullAssignFunc = nullptr; EXPECT_FALSE(nullAssignFunc); - EXPECT_TRUE(nullAssignFunc == nullptr); // Test == operator + EXPECT_TRUE(nullAssignFunc == nullptr); // Test == operator EXPECT_FALSE(nullAssignFunc != nullptr); // Test != operator // Test copy constructor @@ -49,9 +54,10 @@ TEST(udCallbackTests, Validation) // Test move constructors and assignments TestCallback moveFunc = std::move(copyFunc); // Test move constructor EXPECT_EQ(basic(3), moveFunc(3)); - copyFunc = basic; // Test copy assignment + copyFunc = basic; // Test copy assignment moveFunc = std::move(copyFunc); // Test move assignment EXPECT_EQ(basic(4), moveFunc(4)); - moveFunc = [](int a) -> int { return a; }; // Test direct assignment + moveFunc = [](int a) -> int + { return a; }; // Test direct assignment EXPECT_EQ(5, moveFunc(a)); } diff --git a/udTest/src/udChunkedArrayTests.cpp b/udTest/src/udChunkedArrayTests.cpp index d8783c08..f30b5c7e 100644 --- a/udTest/src/udChunkedArrayTests.cpp +++ b/udTest/src/udChunkedArrayTests.cpp @@ -1,7 +1,7 @@ -#include "gtest/gtest.h" #include "udChunkedArray.h" -#include +#include "gtest/gtest.h" #include +#include TEST(udChunkedArrayTests, ToArray) { @@ -48,25 +48,25 @@ TEST(udChunkedArrayTests, Basic) array.Init(8); - array.PushBack(10); // 10 + array.PushBack(10); // 10 EXPECT_EQ(1, array.length); - array.PushBack(20); // 10,20 + array.PushBack(20); // 10,20 EXPECT_EQ(2, array.length); - array.PushBack(40); // 10,20,40 + array.PushBack(40); // 10,20,40 EXPECT_EQ(3, array.length); - array.PushBack(50); // 10,20,40,50 + array.PushBack(50); // 10,20,40,50 EXPECT_EQ(4, array.length); temp = 30; - array.Insert(2, &temp); // 10,20,30,40,50 + array.Insert(2, &temp); // 10,20,30,40,50 EXPECT_EQ(30, array[2]); EXPECT_EQ(5, array.length); - array.PopFront(&temp); // 20,30,40,50 + array.PopFront(&temp); // 20,30,40,50 EXPECT_EQ(10, temp); EXPECT_EQ(4, array.length); EXPECT_EQ(1, array.inset); - array.PopBack(&temp); // 20,30,40 + array.PopBack(&temp); // 20,30,40 EXPECT_EQ(50, temp); EXPECT_EQ(3, array.length); EXPECT_EQ(1, array.inset); @@ -92,25 +92,25 @@ TEST(udChunkedArrayTests, Basic) // Now insert again, but this time with an inset, in second chunk temp = 105; - array.Insert(9, &temp); // 20,30,40,50,60,70,80,90,100,105,110,120 + array.Insert(9, &temp); // 20,30,40,50,60,70,80,90,100,105,110,120 EXPECT_EQ(105, array[9]); EXPECT_EQ(1, array.inset); // Now insert again, but this time with an inset, in first chunk (special case to eliminate inset) temp = 65; - array.Insert(5, &temp); // 20,30,40,50,60,65,70,80,90,100,105,110,120 + array.Insert(5, &temp); // 20,30,40,50,60,65,70,80,90,100,105,110,120 EXPECT_EQ(65, array[5]); EXPECT_EQ(0, array.inset); // Insert at start temp = 15; - array.Insert(0, &temp); // 15,20,30,40,50,60,65,70,80,90,100,105,110,120 + array.Insert(0, &temp); // 15,20,30,40,50,60,65,70,80,90,100,105,110,120 EXPECT_EQ(15, array[0]); EXPECT_EQ(0, array.inset); // Insert at end temp = 125; - array.Insert(14, &temp); // 15,20,30,40,50,60,65,70,80,90,100,105,110,120,125 + array.Insert(14, &temp); // 15,20,30,40,50,60,65,70,80,90,100,105,110,120,125 EXPECT_EQ(125, array[14]); EXPECT_EQ(0, array.inset); @@ -154,7 +154,6 @@ TEST(udChunkedArrayTests, ZeroMemory) array.Deinit(); } - TEST(udChunkedArrayTests, FullChunkInsert) { // Test to insert at all positions with the chunk being completely full @@ -184,7 +183,7 @@ TEST(udChunkedArrayTests, FullChunkInsert) } } -template +template bool iteratorIsValid(const udChunkedArrayIterator &it, const udChunkedArray array) { udResult result = udR_Success; @@ -225,7 +224,6 @@ TEST(udChunkedArrayTests, Iterator) } EXPECT_EQ(array.length, i); - // Iterates partially filled chunks correct array.PopBack(); @@ -248,7 +246,7 @@ TEST(udChunkedArrayTests, Iterator) } EXPECT_EQ(array.length, i - 1); // array.end() is over the end of the array and not valid by this definition (dereferencable) - EXPECT_TRUE(iteratorIsValid(array.end() - 1, array)); + EXPECT_TRUE(iteratorIsValid(array.end() - 1, array)); udChunkedArrayIterator it = array.begin(); EXPECT_TRUE(iteratorIsValid(it, array)); @@ -299,7 +297,7 @@ TEST(udChunkedArrayTests, Iterator) EXPECT_EQ(*iter, i); auto iter2 = array.begin() + i; //test that indexing into the array by adding to an interator will give the same result as dereferencing the iterator - EXPECT_EQ(*(iter2 - 1), *iter); + EXPECT_EQ(*(iter2 - 1), *iter); ++i; } EXPECT_EQ(i, array.length + 1); @@ -309,7 +307,7 @@ TEST(udChunkedArrayTests, Iterator) --i; EXPECT_EQ(*iter, i); //test that indexing into the array using an interator will give the same result as dereferencing the iterator - EXPECT_EQ(array.begin()[i - 1], *iter); + EXPECT_EQ(array.begin()[i - 1], *iter); } EXPECT_EQ(array.end() - array.begin(), (int)array.length); @@ -346,4 +344,3 @@ TEST(udChunkedArrayTests, Iterator) array.Deinit(); } - diff --git a/udTest/src/udCompressionTests.cpp b/udTest/src/udCompressionTests.cpp index 70696e54..ea231fe1 100644 --- a/udTest/src/udCompressionTests.cpp +++ b/udTest/src/udCompressionTests.cpp @@ -1,9 +1,9 @@ -#include "gtest/gtest.h" #include "udCompression.h" -#include "udMath.h" #include "udFile.h" +#include "udMath.h" #include "udPlatform.h" #include "udStringUtil.h" +#include "gtest/gtest.h" TEST(udCompressionTests, Basic) { @@ -99,44 +99,44 @@ TEST(udCompressionTests, Zip) int fileCount; // An embedded zip containing 3 text files "Doc1.txt" (deflate), "Doc2.txt" (deflate64) and "Doc3.txt" (stored) static const char *pRawZip = - "zip://raw://UEsDBBQAAAAIADZpUU0Gd9psGAEAANYBAAAIAAAARG9jMS50eHQtUclRQzEMvTNDD68AJk0AN64UIGwl0YxtObYUUj5SPjdre5vftc/Fe3PFr9" - "gVlc+NjF9fvnRxh8ztHVWbLmwxUGd7Q9GxuRibL1CVKbvIuICbxDCg4gAsvrtWGPcZxzKKVKk+DG5o9BPwYEvofHW6DAI1uTmd8G3gIT2w0SUf9yipv+HmsjF0" - "2/IKfvAqYmSiA94a9aIHci7JlmA6IGXGMphCeA9NehgIKjvhIyHJjSHLF6egp1wsjmCuPCovsWzctfkMOg45LVqZGoq0diT0NOQ4+0XIMFIQJq0ofJ3w+Sg8jT" - "1jjAy0FOISe8WnVLK8CBdzqVQemaKPJI15m5S+oeezFKH4oc0rp11byqAMSGrI+c/V++kPUEsDBBUAAAAJADppUU1h67lJGwEAANgBAAAIAAAARG9jMi50eHQt" - "kEFOAzEMRfdI3OEfoJoV4gLAji0HMImntZTEaWKXHp9YM7s4tr//fx9a++A5OeNP7IbMeyHj97fXl28dXCF9ekXWogNTDFTZLkjaJidj8wHK0mUmaVdwkdUMsa" - "xg8Vk1w7h2HZCWJEv2ZnBDod8lD7ZDmlHp2ghU5O604cfATSooo0o8HqukesHdZaLptOEZ/OSRxMhEG7wUqkkP5RiSKXA7JKWvYTAhaV2e9AiwTtmGz5AkN4YM" - "H3xmlYbBC82NW+YhFh8PLd6NjPGIpAhuSFLKSSgCOXa/ChlaGEKnsQofG76eibuxB8Zm0JSIExmSd8lksaENfahkbkHRWxxd/dIpckP3XZIQMk8e0a1awgYFIM" - "ngeXL1uv0DUEsDBAoAAAAAABloUU3pwhanDgAAAA4AAAAIAAAARG9jMy50eHROb3QgY29tcHJlc3NlZFBLAQI/ABQAAAAIADZpUU0Gd9psGAEAANYBAAAIACQA" - "AAAAAAAAICAAAAAAAABEb2MxLnR4dAoAIAAAAAAAAQAYAAPtNNnGZdQBUmjSgsVl1AFSaNKCxWXUAVBLAQI/ABUAAAAJADppUU1h67lJGwEAANgBAAAIACQAAA" - "AAAAAAICAAAD4BAABEb2MyLnR4dAoAIAAAAAAAAQAYACIo993GZdQB99Y6hsVl1AH31jqGxWXUAVBLAQI/AAoAAAAAABloUU3pwhanDgAAAA4AAAAIACQAAAAA" - "AAAAICAAAH8CAABEb2MzLnR4dAoAIAAAAAAAAQAYAJEWSZvFZdQBpylnh8Vl1AGnKWeHxWXUAVBLBQYAAAAAAwADAA4BAACzAgAAAAA="; + "zip://raw://UEsDBBQAAAAIADZpUU0Gd9psGAEAANYBAAAIAAAARG9jMS50eHQtUclRQzEMvTNDD68AJk0AN64UIGwl0YxtObYUUj5SPjdre5vftc/Fe3PFr9" + "gVlc+NjF9fvnRxh8ztHVWbLmwxUGd7Q9GxuRibL1CVKbvIuICbxDCg4gAsvrtWGPcZxzKKVKk+DG5o9BPwYEvofHW6DAI1uTmd8G3gIT2w0SUf9yipv+HmsjF0" + "2/IKfvAqYmSiA94a9aIHci7JlmA6IGXGMphCeA9NehgIKjvhIyHJjSHLF6egp1wsjmCuPCovsWzctfkMOg45LVqZGoq0diT0NOQ4+0XIMFIQJq0ofJ3w+Sg8jT" + "1jjAy0FOISe8WnVLK8CBdzqVQemaKPJI15m5S+oeezFKH4oc0rp11byqAMSGrI+c/V++kPUEsDBBUAAAAJADppUU1h67lJGwEAANgBAAAIAAAARG9jMi50eHQt" + "kEFOAzEMRfdI3OEfoJoV4gLAji0HMImntZTEaWKXHp9YM7s4tr//fx9a++A5OeNP7IbMeyHj97fXl28dXCF9ekXWogNTDFTZLkjaJidj8wHK0mUmaVdwkdUMsa" + "xg8Vk1w7h2HZCWJEv2ZnBDod8lD7ZDmlHp2ghU5O604cfATSooo0o8HqukesHdZaLptOEZ/OSRxMhEG7wUqkkP5RiSKXA7JKWvYTAhaV2e9AiwTtmGz5AkN4YM" + "H3xmlYbBC82NW+YhFh8PLd6NjPGIpAhuSFLKSSgCOXa/ChlaGEKnsQofG76eibuxB8Zm0JSIExmSd8lksaENfahkbkHRWxxd/dIpckP3XZIQMk8e0a1awgYFIM" + "ngeXL1uv0DUEsDBAoAAAAAABloUU3pwhanDgAAAA4AAAAIAAAARG9jMy50eHROb3QgY29tcHJlc3NlZFBLAQI/ABQAAAAIADZpUU0Gd9psGAEAANYBAAAIACQA" + "AAAAAAAAICAAAAAAAABEb2MxLnR4dAoAIAAAAAAAAQAYAAPtNNnGZdQBUmjSgsVl1AFSaNKCxWXUAVBLAQI/ABUAAAAJADppUU1h67lJGwEAANgBAAAIACQAAA" + "AAAAAAICAAAD4BAABEb2MyLnR4dAoAIAAAAAAAAQAYACIo993GZdQB99Y6hsVl1AH31jqGxWXUAVBLAQI/AAoAAAAAABloUU3pwhanDgAAAA4AAAAIACQAAAAA" + "AAAAICAAAH8CAABEb2MzLnR4dAoAIAAAAAAAAQAYAJEWSZvFZdQBpylnh8Vl1AGnKWeHxWXUAVBLBQYAAAAAAwADAA4BAACzAgAAAAA="; static const char *pText = - "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua" - ". Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute ir" - "ure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidat" - "at non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua" + ". Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute ir" + "ure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidat" + "at non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; // First up, load the table of contents (exposed as a text file) int64_t tocLen, doc1Len, doc2Len, doc3Len; - result = udFile_Load(pRawZip, (void**)&pTOC, &tocLen); + result = udFile_Load(pRawZip, (void **)&pTOC, &tocLen); EXPECT_EQ(udR_Success, result); fileCount = (int)udStrTokenSplit(pTOC, "\n", pFilenames, (int)udLengthOf(pFilenames)); EXPECT_EQ(3, fileCount); EXPECT_TRUE(udStrEqual(pFilenames[0], "Doc1.txt")); - result = udFile_Load(udTempStr("%s:%s", pRawZip, pFilenames[0]), (void**)&pDOC, &doc1Len); + result = udFile_Load(udTempStr("%s:%s", pRawZip, pFilenames[0]), (void **)&pDOC, &doc1Len); EXPECT_EQ(udR_Success, result); EXPECT_TRUE(udStrEqual(pDOC, udTempStr("Compressed with deflate\r\n%s", pText))); udFree(pDOC); EXPECT_TRUE(udStrEqual(pFilenames[1], "Doc2.txt")); - result = udFile_Load(udTempStr("%s:%s", pRawZip, pFilenames[1]), (void**)&pDOC, &doc2Len); + result = udFile_Load(udTempStr("%s:%s", pRawZip, pFilenames[1]), (void **)&pDOC, &doc2Len); EXPECT_EQ(udR_Success, result); EXPECT_TRUE(udStrEqual(pDOC, udTempStr("Compressed with deflate64\r\n%s", pText))); udFree(pDOC); EXPECT_TRUE(udStrEqual(pFilenames[2], "Doc3.txt")); - result = udFile_Load(udTempStr("%s:%s", pRawZip, pFilenames[2]), (void**)&pDOC, &doc3Len); + result = udFile_Load(udTempStr("%s:%s", pRawZip, pFilenames[2]), (void **)&pDOC, &doc3Len); EXPECT_EQ(udR_Success, result); EXPECT_TRUE(udStrEqual(pDOC, "Not compressed")); udFree(pDOC); @@ -149,7 +149,6 @@ TEST(udCompressionTests, Zip) EXPECT_EQ(0, len); // No TOC is returned if a single colon follows the name udFile_Close(&pFile); - result = udFile_Open(&pFile, pRawZip, udFOF_Read, &len); EXPECT_EQ(udR_Success, result); EXPECT_EQ(tocLen, len); // TOC is opened and length returned @@ -195,8 +194,8 @@ TEST(udCompressionTests, ZipWithFolder) // Test accessing a file under a folder in the zip static const char *pFolderInZip = - "zip://raw://UEsDBBQAAAAAAHFtdk81p2zRCgAAAAoAAAAWAAAAZm9sZGVyL0RvY0luRm9sZGVyLnR4dGNhcnBlIGRpZW1QSwECFAAUAAAAAABxbXZPNads0Q" - "oAAAAKAAAAFgAAAAAAAAABACAAAAAAAAAAZm9sZGVyL0RvY0luRm9sZGVyLnR4dFBLBQYAAAAAAQABAEQAAAA+AAAAAAA="; + "zip://raw://UEsDBBQAAAAAAHFtdk81p2zRCgAAAAoAAAAWAAAAZm9sZGVyL0RvY0luRm9sZGVyLnR4dGNhcnBlIGRpZW1QSwECFAAUAAAAAABxbXZPNads0Q" + "oAAAAKAAAAFgAAAAAAAAABACAAAAAAAAAAZm9sZGVyL0RvY0luRm9sZGVyLnR4dFBLBQYAAAAAAQABAEQAAAA+AAAAAAA="; result = udFile_Open(&pFile, pFolderInZip, udFOF_Read); EXPECT_EQ(udR_Success, result); diff --git a/udTest/src/udCryptoTests.cpp b/udTest/src/udCryptoTests.cpp index 7aebb2b3..86e5849f 100644 --- a/udTest/src/udCryptoTests.cpp +++ b/udTest/src/udCryptoTests.cpp @@ -1,26 +1,23 @@ -#include "gtest/gtest.h" #include "udCrypto.h" #include "udJSON.h" #include "udStringUtil.h" +#include "gtest/gtest.h" TEST(udCryptoTests, AES_CBC_MonteCarlo) { // Do the first only monte carlo tests for CBC mode (400 tests in official monte carlo) - static const unsigned char aes_test_cbc_dec[2][16] = - { + static const unsigned char aes_test_cbc_dec[2][16] = { { 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73, 0xDF, 0x70, 0x6E, 0x73, 0xF7, 0xC9, 0xAF, 0x86 }, { 0x48, 0x04, 0xE1, 0x81, 0x8F, 0xE6, 0x29, 0x75, 0x19, 0xA3, 0xE8, 0x8C, 0x57, 0x31, 0x04, 0x13 } }; - static const unsigned char aes_test_cbc_enc[2][16] = - { + static const unsigned char aes_test_cbc_enc[2][16] = { { 0x8A, 0x05, 0xFC, 0x5E, 0x09, 0x5A, 0xF4, 0x84, 0x8A, 0x08, 0xD3, 0x28, 0xD3, 0x68, 0x8E, 0x3D }, { 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5, 0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 } }; - static const char *pZeroKeys[2] = - { - "AAAAAAAAAAAAAAAAAAAAAA==", // 16-bytes of zeros + static const char *pZeroKeys[2] = { + "AAAAAAAAAAAAAAAAAAAAAA==", // 16-bytes of zeros "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" // 32-bytes of zeros }; unsigned char buf[64]; @@ -67,20 +64,17 @@ TEST(udCryptoTests, AES_CBC_MonteCarlo) TEST(udCryptoTests, AES_CTR_MonteCarlo) { // Do the first only monte carlo tests for CTR mode (400 tests in official monte carlo) - static const char *aes_test_ctr_key[3] = - { + static const char *aes_test_ctr_key[3] = { "rmhS+BIQZ8xL96V2VXfzng==", "fiQGeBf64NdD1s4fMlORYw==", "dpG+A15QIKisbmGFKfmg3A==" }; - static const udCryptoIV aes_test_ctr_nonce_counter[3] = - { + static const udCryptoIV aes_test_ctr_nonce_counter[3] = { { { 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }, { { 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59, 0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 } }, { { 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F, 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 } } }; - static const unsigned char aes_test_ctr_pt[3][48] = - { + static const unsigned char aes_test_ctr_pt[3][48] = { { 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62, 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 }, { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, @@ -91,8 +85,7 @@ TEST(udCryptoTests, AES_CTR_MonteCarlo) 0x20, 0x21, 0x22, 0x23 } }; - static const unsigned char aes_test_ctr_ct[3][48] = - { + static const unsigned char aes_test_ctr_ct[3][48] = { { 0xE4, 0x09, 0x5D, 0x4F, 0xB7, 0xA7, 0xB3, 0x79, 0x2D, 0x61, 0x75, 0xA3, 0x26, 0x13, 0x11, 0xB8 }, { 0x51, 0x04, 0xA1, 0x06, 0x16, 0x8A, 0x72, 0xD9, 0x79, 0x0D, 0x41, 0xEE, 0x8E, 0xDA, 0xD3, 0x88, @@ -189,37 +182,31 @@ TEST(udCryptoTests, CipherErrorCodes) EXPECT_EQ(udR_InvalidParameter, result); } - TEST(udCryptoTests, SHA) { /* * FIPS-180-1 test vectors. See https://www.di-mgt.com.au/sha_testvectors.html */ - static const char* s_testMessages[3] = - { + static const char *s_testMessages[3] = { "abc", "", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", }; static udCryptoHashes s_testHashes[] = { udCH_SHA1, udCH_SHA256, udCH_SHA512 }; - static const char *s_testHashResults[][3] = - { + static const char *s_testHashResults[][3] = { { // SHA-1 "qZk+NkcGgWq6PiVxeFDCbJzQ2J0=", "2jmj7l5rSw0yVb/vlWAYkK/YBwk=", - "hJg+RBw70m66rkqh+VEp5eVGcPE=" - }, + "hJg+RBw70m66rkqh+VEp5eVGcPE=" }, { // SHA-256 "ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=", "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", - "JI1qYdIGOLjlwCaTDD5gOaM85Flk/yFn9uzt1BnbBsE=" - }, + "JI1qYdIGOLjlwCaTDD5gOaM85Flk/yFn9uzt1BnbBsE=" }, { // SHA-512 "3a81oZNherrMQXNJriBBMRLm+k6JqX6iCp7u5ktV05ohkpkqJ0/BqDa6PCOj/uu9RU1EI2Q86A4qmslPpUyknw==", "z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg==", - "IEqPxt2oLwoM7XvrjgikFlfBbvRosiioJ5vjMacDwzWW/RXBOxsH+aodO+pXeJygMa2Fx6cd1wNU7GMSOMo0RQ==" - } + "IEqPxt2oLwoM7XvrjgikFlfBbvRosiioJ5vjMacDwzWW/RXBOxsH+aodO+pXeJygMa2Fx6cd1wNU7GMSOMo0RQ==" } }; for (size_t shaType = 0; shaType < UDARRAYSIZE(s_testHashes); ++shaType) @@ -258,27 +245,27 @@ TEST(udCryptoTests, Self) TEST(udCryptoTests, RSACreateSig) { static const char *pPrivateKeyText = - "{\n" - " 'Type': 'RSA',\n" - " 'Private': true,\n" - " 'Size': 2048,\n" - " 'N': 'n0pMFfJ0/vkZc1DEm4e1T33XoQZYvJxzFskuQ6E7IvTrR/KlTCMAEsU6rm+vNJQBFt+vEiNbv9qrzTQaW5XHp6k9+hwvQfkLKd2moc+G+ru5inbyOBBNpRfMAUjf6VZkyLbDFYrIFp6SJZYXhx2Pf/HpUKxpte4ZDFJARGpTLvE4GtYPs2Gj9xu6C1yRan3nLSa8MJhndNDxNGh5IF92ThMw0I+Pk1YSzpiJ9ZEX8GLqrVzWgORVdeiaYot3YSSMbf5pcDhrsvCDNSFB5396L3fc7IcWy99e9wiZiVcPUvLlNE/ziInNapOwG5EgPqTUk1jtXyLzuHZQDNADl/N/Uw==',\n" - " 'E': 'AQAB',\n" - " 'D': 'A2GBUenuf8brul3Zfm+X8pL6M6m90msDqlUkzTyr06cdI07MIVyQ0NUs1Kz8LAKEL2caASmM9fp/MQDNGmqIbU+TSC629hCCIyZYNhEAjWvUmVLC+1ulOj7SDqjsT7iMtRHj/B4Q9yHweinAYBbJh+6rhBHUwI7IK1HHmWwkTde6GxKiNxp4hrsxP8AKgX2+lCvPH0YT0jwFdHafcEfFCg0Mk8lIrlZRuD/5XbDVqKdcgrss63AwJthU1cEZztHH19sQfTjp2bEUFGBGQETL/NcJIO+YKbkng1UVvkTDcbJtSZ+PZxrQvzv5EJ4K0YTp26RlNNgTau2feMfyP5o3CQ==',\n" - " 'P': '9dJtUa+v2GIwqhCJqcvSR/FdG53rAYwPYu9lJPmKbPxuSbUhtBJh+OzdVGU9H+xxRrw8w95hgEyaPLdGXfZuaGy3mFRHzCI9lfsShIIk37yKbIYbFPpvMu6M9gcB5LwbpK2IBlYZcSMohKvADv0qRaReWWLoIeVpj3M6tTZLaRU=',\n" - " 'Q': 'peKuzv6ZYtNcERg3hxWyyWTw9TdbTHRJnmA8lVHb+JqxHipcp9uvcZBxHJiSqYY9nmdWPrEHyQIzXvEIclKtjYboKBt/bNfAZ1iLCR7bkX9wHQj6/PmAI9iFvzvvoQbC05C/RZkX3Ug00p7pR8/5qSYk72jC9hRgasNIjlOVkMc=',\n" - " 'DP': 'vTLVUt6+n/OK8wnBer9WPGsHt37G5qzvFr2cgmXR5eov1Gkl5JuVbmqYOyGkdxKbaM7uke5x6raKq5p//UfzWEn80LBlhjcAYZQZf4VPbiiF/dsFsxLBTVkPgziHe45QVGH/ZKkV8d8Wi25JZv/xbiKBP5kBgz04DuGoWNrOFbU=',\n" - " 'DQ': 'ePmRpl9CGTIuqEDS7e7DDeBRYWNXb7A2qAti4zppgym9FVSrcbbigZ1nAAW8n2jIsyaFXP7ZwJucPxbkpArripTh5a34BbZqGHQYITShx7/6URJlh+ukqX+UOlxJa1N07blX5De7kaLA8wD0+2wOlG6+7OGnnLJLhlCYL0OBha0=',\n" - " 'QP': 'YSPeV0tloK7H8XGZ95KCixJfNYkhT29Lcldbm2kUbtk/rChH5OjGwINMc8CewH8/mZDAD7ZpyU9UyWyfK6PpYUjLguvsdmCWuXGVsURRj6MNsv6rHWjyGpfgxLTe2dUKK/xgIOd1mATTUpM3S3q3HRjccy0IfyTh2HdFHILUorU='\n" - "}\n"; + "{\n" + " 'Type': 'RSA',\n" + " 'Private': true,\n" + " 'Size': 2048,\n" + " 'N': 'n0pMFfJ0/vkZc1DEm4e1T33XoQZYvJxzFskuQ6E7IvTrR/KlTCMAEsU6rm+vNJQBFt+vEiNbv9qrzTQaW5XHp6k9+hwvQfkLKd2moc+G+ru5inbyOBBNpRfMAUjf6VZkyLbDFYrIFp6SJZYXhx2Pf/HpUKxpte4ZDFJARGpTLvE4GtYPs2Gj9xu6C1yRan3nLSa8MJhndNDxNGh5IF92ThMw0I+Pk1YSzpiJ9ZEX8GLqrVzWgORVdeiaYot3YSSMbf5pcDhrsvCDNSFB5396L3fc7IcWy99e9wiZiVcPUvLlNE/ziInNapOwG5EgPqTUk1jtXyLzuHZQDNADl/N/Uw==',\n" + " 'E': 'AQAB',\n" + " 'D': 'A2GBUenuf8brul3Zfm+X8pL6M6m90msDqlUkzTyr06cdI07MIVyQ0NUs1Kz8LAKEL2caASmM9fp/MQDNGmqIbU+TSC629hCCIyZYNhEAjWvUmVLC+1ulOj7SDqjsT7iMtRHj/B4Q9yHweinAYBbJh+6rhBHUwI7IK1HHmWwkTde6GxKiNxp4hrsxP8AKgX2+lCvPH0YT0jwFdHafcEfFCg0Mk8lIrlZRuD/5XbDVqKdcgrss63AwJthU1cEZztHH19sQfTjp2bEUFGBGQETL/NcJIO+YKbkng1UVvkTDcbJtSZ+PZxrQvzv5EJ4K0YTp26RlNNgTau2feMfyP5o3CQ==',\n" + " 'P': '9dJtUa+v2GIwqhCJqcvSR/FdG53rAYwPYu9lJPmKbPxuSbUhtBJh+OzdVGU9H+xxRrw8w95hgEyaPLdGXfZuaGy3mFRHzCI9lfsShIIk37yKbIYbFPpvMu6M9gcB5LwbpK2IBlYZcSMohKvADv0qRaReWWLoIeVpj3M6tTZLaRU=',\n" + " 'Q': 'peKuzv6ZYtNcERg3hxWyyWTw9TdbTHRJnmA8lVHb+JqxHipcp9uvcZBxHJiSqYY9nmdWPrEHyQIzXvEIclKtjYboKBt/bNfAZ1iLCR7bkX9wHQj6/PmAI9iFvzvvoQbC05C/RZkX3Ug00p7pR8/5qSYk72jC9hRgasNIjlOVkMc=',\n" + " 'DP': 'vTLVUt6+n/OK8wnBer9WPGsHt37G5qzvFr2cgmXR5eov1Gkl5JuVbmqYOyGkdxKbaM7uke5x6raKq5p//UfzWEn80LBlhjcAYZQZf4VPbiiF/dsFsxLBTVkPgziHe45QVGH/ZKkV8d8Wi25JZv/xbiKBP5kBgz04DuGoWNrOFbU=',\n" + " 'DQ': 'ePmRpl9CGTIuqEDS7e7DDeBRYWNXb7A2qAti4zppgym9FVSrcbbigZ1nAAW8n2jIsyaFXP7ZwJucPxbkpArripTh5a34BbZqGHQYITShx7/6URJlh+ukqX+UOlxJa1N07blX5De7kaLA8wD0+2wOlG6+7OGnnLJLhlCYL0OBha0=',\n" + " 'QP': 'YSPeV0tloK7H8XGZ95KCixJfNYkhT29Lcldbm2kUbtk/rChH5OjGwINMc8CewH8/mZDAD7ZpyU9UyWyfK6PpYUjLguvsdmCWuXGVsURRj6MNsv6rHWjyGpfgxLTe2dUKK/xgIOd1mATTUpM3S3q3HRjccy0IfyTh2HdFHILUorU='\n" + "}\n"; static const char *pPublicKeyText = - "{\n" - " 'Type': 'RSA',\n" - " 'Size': 2048,\n" - " 'N': 'n0pMFfJ0/vkZc1DEm4e1T33XoQZYvJxzFskuQ6E7IvTrR/KlTCMAEsU6rm+vNJQBFt+vEiNbv9qrzTQaW5XHp6k9+hwvQfkLKd2moc+G+ru5inbyOBBNpRfMAUjf6VZkyLbDFYrIFp6SJZYXhx2Pf/HpUKxpte4ZDFJARGpTLvE4GtYPs2Gj9xu6C1yRan3nLSa8MJhndNDxNGh5IF92ThMw0I+Pk1YSzpiJ9ZEX8GLqrVzWgORVdeiaYot3YSSMbf5pcDhrsvCDNSFB5396L3fc7IcWy99e9wiZiVcPUvLlNE/ziInNapOwG5EgPqTUk1jtXyLzuHZQDNADl/N/Uw==',\n" - " 'E': 'AQAB',\n" - "}\n"; + "{\n" + " 'Type': 'RSA',\n" + " 'Size': 2048,\n" + " 'N': 'n0pMFfJ0/vkZc1DEm4e1T33XoQZYvJxzFskuQ6E7IvTrR/KlTCMAEsU6rm+vNJQBFt+vEiNbv9qrzTQaW5XHp6k9+hwvQfkLKd2moc+G+ru5inbyOBBNpRfMAUjf6VZkyLbDFYrIFp6SJZYXhx2Pf/HpUKxpte4ZDFJARGpTLvE4GtYPs2Gj9xu6C1yRan3nLSa8MJhndNDxNGh5IF92ThMw0I+Pk1YSzpiJ9ZEX8GLqrVzWgORVdeiaYot3YSSMbf5pcDhrsvCDNSFB5396L3fc7IcWy99e9wiZiVcPUvLlNE/ziInNapOwG5EgPqTUk1jtXyLzuHZQDNADl/N/Uw==',\n" + " 'E': 'AQAB',\n" + "}\n"; udCryptoSigContext *pPrivCtx = nullptr; udCryptoSigContext *pPubCtx = nullptr; @@ -319,7 +306,7 @@ TEST(udCryptoTests, RSACreateSig) EXPECT_EQ(udR_Success, udCryptoSig_Verify(pPubCtx, pHash, pSignature, udCH_SHA1)); // Change the hash slightly to ensure the message isn't verified - ((char*)pHash)[1] ^= 1; + ((char *)pHash)[1] ^= 1; EXPECT_EQ(udR_SignatureMismatch, udCryptoSig_Verify(pPrivCtx, pHash, pSignature, udCH_SHA1)); EXPECT_EQ(udR_SignatureMismatch, udCryptoSig_Verify(pPubCtx, pHash, pSignature, udCH_SHA1)); @@ -389,7 +376,7 @@ TEST(udCryptoTests, ECDSADigiSig) EXPECT_EQ(udR_Success, udCryptoSig_Verify(pPubCtx, pHash, pSignature, udCH_SHA1)); // Change the hash slightly to ensure the message isn't verified - ((char*)pHash)[1] ^= 1; + ((char *)pHash)[1] ^= 1; EXPECT_EQ(udR_SignatureMismatch, udCryptoSig_Verify(pPrivCtx, pHash, pSignature, udCH_SHA1)); EXPECT_EQ(udR_SignatureMismatch, udCryptoSig_Verify(pPubCtx, pHash, pSignature, udCH_SHA1)); @@ -428,7 +415,7 @@ TEST(udCryptoTests, ECDSADigiSigFromudCloud) EXPECT_EQ(udR_Success, udCryptoSig_Verify(pPubCtx, pHash, pExpectedSignature, udCH_SHA256)); // Change the hash slightly to ensure the message isn't verified - ((char*)pHash)[1] ^= 1; + ((char *)pHash)[1] ^= 1; EXPECT_EQ(udR_SignatureMismatch, udCryptoSig_Verify(pPubCtx, pHash, pExpectedSignature, udCH_SHA1)); udCryptoSig_Destroy(&pPubCtx); @@ -506,7 +493,7 @@ TEST(udCryptoTests, ECDH) EXPECT_EQ(udR_Success, udCryptoKeyECDH_DeriveFromPartyA(pPublicValueA, &pPublicValueB, &pSecretB)); EXPECT_EQ(udR_Success, udCryptoKeyECDH_DeriveFromPartyB(pECDH, pPublicValueB, &pSecretA)); - + EXPECT_STRCASEEQ(pSecretA, pSecretB); udFree(pPublicValueA); @@ -565,7 +552,7 @@ TEST(udCryptoTests, Utilities) TEST(udCryptoTests, PKCS7) { - static const udCryptoIV iv = { { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f } }; + static const udCryptoIV iv = { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f } }; static const char *pPlainText = "There are two great days in every person's life; the day we are born and the day we discover why"; // Multiple of 16 characters char encryptedText[96 + 16]; char decryptedText[96]; // Importantly don't add 16 here so that codepaths dealing with pad overrun are tested @@ -623,19 +610,19 @@ TEST(udCryptoTests, Uninitialised) udCryptoSigContext *pPrivCtx = nullptr; udCryptoCipherContext *pCipherCtx = nullptr; static const char *pPrivateKeyText = - "{\n" - " 'Type': 'RSA',\n" - " 'Private': true,\n" - " 'Size': 2048,\n" - " 'N': 'n0pMFfJ0/vkZc1DEm4e1T33XoQZYvJxzFskuQ6E7IvTrR/KlTCMAEsU6rm+vNJQBFt+vEiNbv9qrzTQaW5XHp6k9+hwvQfkLKd2moc+G+ru5inbyOBBNpRfMAUjf6VZkyLbDFYrIFp6SJZYXhx2Pf/HpUKxpte4ZDFJARGpTLvE4GtYPs2Gj9xu6C1yRan3nLSa8MJhndNDxNGh5IF92ThMw0I+Pk1YSzpiJ9ZEX8GLqrVzWgORVdeiaYot3YSSMbf5pcDhrsvCDNSFB5396L3fc7IcWy99e9wiZiVcPUvLlNE/ziInNapOwG5EgPqTUk1jtXyLzuHZQDNADl/N/Uw==',\n" - " 'E': 'AQAB',\n" - " 'D': 'A2GBUenuf8brul3Zfm+X8pL6M6m90msDqlUkzTyr06cdI07MIVyQ0NUs1Kz8LAKEL2caASmM9fp/MQDNGmqIbU+TSC629hCCIyZYNhEAjWvUmVLC+1ulOj7SDqjsT7iMtRHj/B4Q9yHweinAYBbJh+6rhBHUwI7IK1HHmWwkTde6GxKiNxp4hrsxP8AKgX2+lCvPH0YT0jwFdHafcEfFCg0Mk8lIrlZRuD/5XbDVqKdcgrss63AwJthU1cEZztHH19sQfTjp2bEUFGBGQETL/NcJIO+YKbkng1UVvkTDcbJtSZ+PZxrQvzv5EJ4K0YTp26RlNNgTau2feMfyP5o3CQ==',\n" - " 'P': '9dJtUa+v2GIwqhCJqcvSR/FdG53rAYwPYu9lJPmKbPxuSbUhtBJh+OzdVGU9H+xxRrw8w95hgEyaPLdGXfZuaGy3mFRHzCI9lfsShIIk37yKbIYbFPpvMu6M9gcB5LwbpK2IBlYZcSMohKvADv0qRaReWWLoIeVpj3M6tTZLaRU=',\n" - " 'Q': 'peKuzv6ZYtNcERg3hxWyyWTw9TdbTHRJnmA8lVHb+JqxHipcp9uvcZBxHJiSqYY9nmdWPrEHyQIzXvEIclKtjYboKBt/bNfAZ1iLCR7bkX9wHQj6/PmAI9iFvzvvoQbC05C/RZkX3Ug00p7pR8/5qSYk72jC9hRgasNIjlOVkMc=',\n" - " 'DP': 'vTLVUt6+n/OK8wnBer9WPGsHt37G5qzvFr2cgmXR5eov1Gkl5JuVbmqYOyGkdxKbaM7uke5x6raKq5p//UfzWEn80LBlhjcAYZQZf4VPbiiF/dsFsxLBTVkPgziHe45QVGH/ZKkV8d8Wi25JZv/xbiKBP5kBgz04DuGoWNrOFbU=',\n" - " 'DQ': 'ePmRpl9CGTIuqEDS7e7DDeBRYWNXb7A2qAti4zppgym9FVSrcbbigZ1nAAW8n2jIsyaFXP7ZwJucPxbkpArripTh5a34BbZqGHQYITShx7/6URJlh+ukqX+UOlxJa1N07blX5De7kaLA8wD0+2wOlG6+7OGnnLJLhlCYL0OBha0=',\n" - " 'QP': 'YSPeV0tloK7H8XGZ95KCixJfNYkhT29Lcldbm2kUbtk/rChH5OjGwINMc8CewH8/mZDAD7ZpyU9UyWyfK6PpYUjLguvsdmCWuXGVsURRj6MNsv6rHWjyGpfgxLTe2dUKK/xgIOd1mATTUpM3S3q3HRjccy0IfyTh2HdFHILUorU='\n" - "}\n"; + "{\n" + " 'Type': 'RSA',\n" + " 'Private': true,\n" + " 'Size': 2048,\n" + " 'N': 'n0pMFfJ0/vkZc1DEm4e1T33XoQZYvJxzFskuQ6E7IvTrR/KlTCMAEsU6rm+vNJQBFt+vEiNbv9qrzTQaW5XHp6k9+hwvQfkLKd2moc+G+ru5inbyOBBNpRfMAUjf6VZkyLbDFYrIFp6SJZYXhx2Pf/HpUKxpte4ZDFJARGpTLvE4GtYPs2Gj9xu6C1yRan3nLSa8MJhndNDxNGh5IF92ThMw0I+Pk1YSzpiJ9ZEX8GLqrVzWgORVdeiaYot3YSSMbf5pcDhrsvCDNSFB5396L3fc7IcWy99e9wiZiVcPUvLlNE/ziInNapOwG5EgPqTUk1jtXyLzuHZQDNADl/N/Uw==',\n" + " 'E': 'AQAB',\n" + " 'D': 'A2GBUenuf8brul3Zfm+X8pL6M6m90msDqlUkzTyr06cdI07MIVyQ0NUs1Kz8LAKEL2caASmM9fp/MQDNGmqIbU+TSC629hCCIyZYNhEAjWvUmVLC+1ulOj7SDqjsT7iMtRHj/B4Q9yHweinAYBbJh+6rhBHUwI7IK1HHmWwkTde6GxKiNxp4hrsxP8AKgX2+lCvPH0YT0jwFdHafcEfFCg0Mk8lIrlZRuD/5XbDVqKdcgrss63AwJthU1cEZztHH19sQfTjp2bEUFGBGQETL/NcJIO+YKbkng1UVvkTDcbJtSZ+PZxrQvzv5EJ4K0YTp26RlNNgTau2feMfyP5o3CQ==',\n" + " 'P': '9dJtUa+v2GIwqhCJqcvSR/FdG53rAYwPYu9lJPmKbPxuSbUhtBJh+OzdVGU9H+xxRrw8w95hgEyaPLdGXfZuaGy3mFRHzCI9lfsShIIk37yKbIYbFPpvMu6M9gcB5LwbpK2IBlYZcSMohKvADv0qRaReWWLoIeVpj3M6tTZLaRU=',\n" + " 'Q': 'peKuzv6ZYtNcERg3hxWyyWTw9TdbTHRJnmA8lVHb+JqxHipcp9uvcZBxHJiSqYY9nmdWPrEHyQIzXvEIclKtjYboKBt/bNfAZ1iLCR7bkX9wHQj6/PmAI9iFvzvvoQbC05C/RZkX3Ug00p7pR8/5qSYk72jC9hRgasNIjlOVkMc=',\n" + " 'DP': 'vTLVUt6+n/OK8wnBer9WPGsHt37G5qzvFr2cgmXR5eov1Gkl5JuVbmqYOyGkdxKbaM7uke5x6raKq5p//UfzWEn80LBlhjcAYZQZf4VPbiiF/dsFsxLBTVkPgziHe45QVGH/ZKkV8d8Wi25JZv/xbiKBP5kBgz04DuGoWNrOFbU=',\n" + " 'DQ': 'ePmRpl9CGTIuqEDS7e7DDeBRYWNXb7A2qAti4zppgym9FVSrcbbigZ1nAAW8n2jIsyaFXP7ZwJucPxbkpArripTh5a34BbZqGHQYITShx7/6URJlh+ukqX+UOlxJa1N07blX5De7kaLA8wD0+2wOlG6+7OGnnLJLhlCYL0OBha0=',\n" + " 'QP': 'YSPeV0tloK7H8XGZ95KCixJfNYkhT29Lcldbm2kUbtk/rChH5OjGwINMc8CewH8/mZDAD7ZpyU9UyWyfK6PpYUjLguvsdmCWuXGVsURRj6MNsv6rHWjyGpfgxLTe2dUKK/xgIOd1mATTUpM3S3q3HRjccy0IfyTh2HdFHILUorU='\n" + "}\n"; static const char *pExpectedSignature = "jZzErtTWtEjEIDJsf0HRPJA/9z2MLu2tCvd/OgOojinZ9y+hbQSADgnFVN/cGV965Z6x6burvYVWPT8TjF00+9aXIGY3vFncrdRYhM2ynq+cisOxzIacC1AraDcuQgMvyxv9NKjCNWvLJL1GaP6PzKJmuDT5HDiEz9DqNhya5U43dIFoXu3AlTZlT8uuUuSwbxk4G+rkfG2Jm6cj6l8BhvpMhxA7GYmuiA9ByQ7tcU8/G/zi1xY/zIHTOlzGc7h+BfXXkpNH+NdyMOW0NnQg1jfy5VuK3eYeDfP2xSDlvOivvXwwFR9lQCizx4kzSuSpoIg7pW0HvmjgXXcMC29kqg=="; udCryptoIV iv; diff --git a/udTest/src/udDebugTests.cpp b/udTest/src/udDebugTests.cpp index 84623704..6307809d 100644 --- a/udTest/src/udDebugTests.cpp +++ b/udTest/src/udDebugTests.cpp @@ -12,15 +12,16 @@ static const char *SkipThreadPrefix(const char *pBuffer) TEST(udDebugTests, ShortDebugPrintf) { - gpudDebugPrintfOutputCallback = [](const char *pBuffer) { EXPECT_STRCASEEQ("This is a short udDebugPrintf\n", SkipThreadPrefix(pBuffer)); }; + gpudDebugPrintfOutputCallback = [](const char *pBuffer) + { EXPECT_STRCASEEQ("This is a short udDebugPrintf\n", SkipThreadPrefix(pBuffer)); }; udDebugPrintf("This is a short %s\n", "udDebugPrintf"); gpudDebugPrintfOutputCallback = nullptr; } TEST(udDebugTests, LongDebugPrintf) { - gpudDebugPrintfOutputCallback = [](const char *pBuffer) { EXPECT_STRCASEEQ("This is a really really really really really really really really really really really really long udDebugPrintf\n", SkipThreadPrefix(pBuffer)); }; + gpudDebugPrintfOutputCallback = [](const char *pBuffer) + { EXPECT_STRCASEEQ("This is a really really really really really really really really really really really really long udDebugPrintf\n", SkipThreadPrefix(pBuffer)); }; udDebugPrintf("This is a really really really really really really really really really really really really long %s\n", "udDebugPrintf"); gpudDebugPrintfOutputCallback = nullptr; } - diff --git a/udTest/src/udFileTests.cpp b/udTest/src/udFileTests.cpp index fd8f1c71..9512e13f 100644 --- a/udTest/src/udFileTests.cpp +++ b/udTest/src/udFileTests.cpp @@ -1,15 +1,15 @@ -#include "gtest/gtest.h" +#include "udCrypto.h" #include "udFile.h" #include "udFileHandler.h" -#include "udCrypto.h" +#include "udMath.h" #include "udPlatformUtil.h" #include "udStringUtil.h" -#include "udMath.h" +#include "gtest/gtest.h" static const size_t s_QBF_Len = 43; // Not including NUL character static const char *s_pQBF_Text = "The quick brown fox jumps over the lazy dog"; -static const char *s_pQBF_Uncomp = "raw://VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw=="; -static const char *s_pQBF_RawDef = "raw://compression=RawDeflate,size=43@C8lIVSgszUzOVkgqyi/PU0jLr1DIKs0tKFbIL0stUigBSuckVlUqpOSnAwA="; +static const char *s_pQBF_Uncomp = "raw://VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw=="; +static const char *s_pQBF_RawDef = "raw://compression=RawDeflate,size=43@C8lIVSgszUzOVkgqyi/PU0jLr1DIKs0tKFbIL0stUigBSuckVlUqpOSnAwA="; static const char *s_pQBF_GzipDef = "raw://compression=GzipDeflate,size=43@H4sIAAAAAAAA/wvJSFUoLM1MzlZIKsovz1NIy69QyCrNLShWyC9LLVIoAUrnJFZVKqTkpwMAOaNPQSsAAAA="; static const char *s_pQBF_ZlibDef = "raw://compression=ZlibDeflate,size=43@eJwLyUhVKCzNTM5WSCrKL89TSMuvUMgqzS0oVsgvSy1SKAFK5yRWVSqk5KcDAFvcD9o="; static const char *s_pQBF_DataBase64 = "data:text/plain;base64,VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw=="; @@ -44,7 +44,6 @@ TEST(udFileTests, GeneralFileTests) // Additional destructions of non-existent objects EXPECT_EQ(udR_Success, udFile_Close(&pFile)); EXPECT_EQ(udR_InvalidParameter, udFile_Close(nullptr)); - } TEST(udFileTests, GeneralDirectoryTests) @@ -96,7 +95,7 @@ TEST(udFileTests, BasicReadWriteLoadFILE) // Load char *pLoadBuffer = nullptr; - EXPECT_EQ(udR_Success, udFile_Load(pFilename, (void**)&pLoadBuffer)); + EXPECT_EQ(udR_Success, udFile_Load(pFilename, (void **)&pLoadBuffer)); EXPECT_STREQ(writeBuffer, pLoadBuffer); udFree(pLoadBuffer); @@ -166,20 +165,27 @@ udResult udFileTests_CustomFileHandler_Open(udFile **ppFile, const char *pFilena if (result != udR_Success) pFile->fileLength = 0; - pFile->fpRead = [](udFile *, void *pBuffer, size_t , int64_t , size_t *pActualRead, udFilePipelinedRequest *) -> udResult { + pFile->fpRead = [](udFile *, void *pBuffer, size_t, int64_t, size_t *pActualRead, udFilePipelinedRequest *) -> udResult + { memcpy(pBuffer, s_customFileHandler_buffer, udStrlen(s_customFileHandler_buffer) + 1); if (pActualRead) *pActualRead = udStrlen(s_customFileHandler_buffer) + 1; return udR_Success; }; - pFile->fpWrite = [](udFile *, const void *pBuffer, size_t bufferLength, int64_t , size_t *pActualWritten) -> udResult { + pFile->fpWrite = [](udFile *, const void *pBuffer, size_t bufferLength, int64_t, size_t *pActualWritten) -> udResult + { memcpy(s_customFileHandler_buffer, pBuffer, bufferLength); if (pActualWritten) *pActualWritten = bufferLength; return udR_Success; }; - pFile->fpRelease = [](udFile *) { return udR_Success; }; - pFile->fpClose = [](udFile **ppFile) { udFree(*ppFile); return udR_Success; }; + pFile->fpRelease = [](udFile *) + { return udR_Success; }; + pFile->fpClose = [](udFile **ppFile) + { + udFree(*ppFile); + return udR_Success; + }; *ppFile = pFile; pFile = nullptr; @@ -211,7 +217,7 @@ TEST(udFileTests, CustomFileHandler) EXPECT_EQ(udR_Success, udFile_Close(&pFile)); char *pLoadBuffer = nullptr; - EXPECT_EQ(udR_Success, udFile_Load(pFilename, (void**)&pLoadBuffer)); + EXPECT_EQ(udR_Success, udFile_Load(pFilename, (void **)&pLoadBuffer)); EXPECT_STREQ(writeBuffer, pLoadBuffer); udFree(pLoadBuffer); @@ -228,28 +234,28 @@ TEST(udFileTests, TranslatingPaths) EXPECT_EQ(udR_Success, udFile_TranslatePath(&pNewPath, pPath)); EXPECT_NE(nullptr, pNewPath); -#if UDPLATFORM_WINDOWS +# if UDPLATFORM_WINDOWS EXPECT_TRUE(udStrBeginsWithi(pNewPath, "C:\\Users\\")); -#elif UDPLATFORM_OSX +# elif UDPLATFORM_OSX EXPECT_TRUE(udStrBeginsWithi(pNewPath, "/Users/")); -#else +# else // '/home/' for regular users and '/root' for the root user EXPECT_TRUE(udStrBeginsWithi(pNewPath, "/home/") || udStrBeginsWith(pNewPath, "/root")); -#endif +# endif udFree(pNewPath); // Test with additional path pPath = "~/test.file"; EXPECT_EQ(udR_Success, udFile_TranslatePath(&pNewPath, pPath)); EXPECT_NE(nullptr, pNewPath); -#if UDPLATFORM_WINDOWS +# if UDPLATFORM_WINDOWS EXPECT_TRUE(udStrBeginsWithi(pNewPath, "C:\\Users\\")); -#elif UDPLATFORM_OSX +# elif UDPLATFORM_OSX EXPECT_TRUE(udStrBeginsWithi(pNewPath, "/Users/")); -#else +# else // '/home/' for regular users and '/root' for the root user EXPECT_TRUE(udStrBeginsWithi(pNewPath, "/home/") || udStrBeginsWith(pNewPath, "/root")); -#endif +# endif EXPECT_NE(nullptr, udStrstr(pNewPath, 0, "/test.file")); EXPECT_EQ(nullptr, udStrstr(pNewPath, 0, "//test.file")); udFree(pNewPath); @@ -277,27 +283,27 @@ TEST(udFileTests, RawLoad) result = udFile_Load("raw://SGVsbG8gV29ybGQ=", &pMemory, &len); EXPECT_EQ(udR_Success, result); EXPECT_EQ(11, len); - EXPECT_STREQ("Hello World", (char*)pMemory); // Can do strcmp here because udFile_Load always adds a nul + EXPECT_STREQ("Hello World", (char *)pMemory); // Can do strcmp here because udFile_Load always adds a nul udFree(pMemory); udFile_Load(s_pQBF_Uncomp, &pMemory, &len); EXPECT_EQ(s_QBF_Len, (size_t)len); - EXPECT_STREQ(s_pQBF_Text, (char*)pMemory); + EXPECT_STREQ(s_pQBF_Text, (char *)pMemory); udFree(pMemory); udFile_Load(s_pQBF_RawDef, &pMemory, &len); EXPECT_EQ(s_QBF_Len, (size_t)len); - EXPECT_STREQ(s_pQBF_Text, (char*)pMemory); + EXPECT_STREQ(s_pQBF_Text, (char *)pMemory); udFree(pMemory); udFile_Load(s_pQBF_GzipDef, &pMemory, &len); EXPECT_EQ(s_QBF_Len, (size_t)len); - EXPECT_STREQ(s_pQBF_Text, (char*)pMemory); + EXPECT_STREQ(s_pQBF_Text, (char *)pMemory); udFree(pMemory); udFile_Load(s_pQBF_ZlibDef, &pMemory, &len); EXPECT_EQ(s_QBF_Len, (size_t)len); - EXPECT_STREQ(s_pQBF_Text, (char*)pMemory); + EXPECT_STREQ(s_pQBF_Text, (char *)pMemory); udFree(pMemory); } @@ -372,11 +378,11 @@ TEST(udFileTests, RecursiveCreateDirectoryTests) EXPECT_EQ(udR_Failure, udRemoveDir("./some")); EXPECT_EQ(udR_Success, udRemoveDir("./some/folder.name")); EXPECT_EQ(udR_Success, udRemoveDir("./some")); - + EXPECT_EQ(udR_Success, udFile_Open(&pFile, pFilename3, udFOF_Create | udFOF_Write)); EXPECT_EQ(udR_Success, udFile_Write(pFile, pOutput, udStrlen(pOutput))); EXPECT_EQ(udR_Success, udFile_Close(&pFile)); - + EXPECT_EQ(udR_Success, udFileExists(pFilename3)); EXPECT_EQ(udR_Success, udFileDelete(pFilename3)); EXPECT_NE(udR_Success, udFileExists(pFilename3)); diff --git a/udTest/src/udFilenameTests.cpp b/udTest/src/udFilenameTests.cpp index 5fc6f1c2..c513f975 100644 --- a/udTest/src/udFilenameTests.cpp +++ b/udTest/src/udFilenameTests.cpp @@ -1,7 +1,7 @@ -#include "gtest/gtest.h" #include "udPlatform.h" #include "udPlatformUtil.h" #include "udStringUtil.h" +#include "gtest/gtest.h" // ---------------------------------------------------------------------------- // Author: Samuel Surtees, July 2021 @@ -194,9 +194,9 @@ TEST(udFilenameTests, Validate) // Author: Samuel Surtees, July 2021 TEST(udFilenameTests, LongFilenameValidate) { -# define filenameSuperLongFolder "https://staging.udcloud.euclideon.com/api/workspace/_sharecode/cvPF2W714ky68u1svMhKRw/_file/project/" -# define filenameSuperLongFilename "%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99" -# define filenameSuperLongFilenameExt ".uds" +#define filenameSuperLongFolder "https://staging.udcloud.euclideon.com/api/workspace/_sharecode/cvPF2W714ky68u1svMhKRw/_file/project/" +#define filenameSuperLongFilename "%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99" +#define filenameSuperLongFilenameExt ".uds" const char filenameSuperLong[] = filenameSuperLongFolder filenameSuperLongFilename filenameSuperLongFilenameExt; UDCOMPILEASSERT(udLengthOf(filenameSuperLong) >= udFilename::MaxPath, "This filename isn't long enough!"); diff --git a/udTest/src/udGeoZoneTests.cpp b/udTest/src/udGeoZoneTests.cpp index af05483a..f8b1079f 100644 --- a/udTest/src/udGeoZoneTests.cpp +++ b/udTest/src/udGeoZoneTests.cpp @@ -1,8 +1,8 @@ -#include "gtest/gtest.h" -#include "udGeoZone.h" -#include "udStringUtil.h" #include "udFile.h" +#include "udGeoZone.h" #include "udPlatformUtil.h" +#include "udStringUtil.h" +#include "gtest/gtest.h" // Don't forget to read this PDF!- http://www.epsg.org/Portals/0/373-07-2.pdf @@ -118,7 +118,7 @@ TEST(udGeoZone, RoundTripPrecision) { 28350, -41.953243413307, 146.54738222308 }, { 28350, -70.463470357348, 119.69509496061 }, - { 84, -33.5338767941, 115.00626123502 }, //LatLong + { 84, -33.5338767941, 115.00626123502 }, //LatLong { 4326, -33.5338767941, 115.00626123502 }, //LatLong { 4328, -33.5338767941, 115.00626123502 }, //ECEF @@ -139,7 +139,7 @@ TEST(udGeoZone, RoundTripPrecision) udDouble3 longLat = udDouble3::create(data[i].longitude, data[i].latitude, 0.f); udDouble3 cartesianLongLat = udGeoZone_LatLongToCartesian(zone, longLat, true); udDouble3 longLat2 = udGeoZone_CartesianToLatLong(zone, cartesianLongLat, true); - + EXPECT_EQ(int64_t(udRound(latLong.x * testPrecision)), int64_t(udRound(latLong2.x * testPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; EXPECT_EQ(int64_t(udRound(latLong.y * testPrecision)), int64_t(udRound(latLong2.y * testPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; @@ -156,36 +156,35 @@ TEST(udGeoZone, RoundTripPrecision) udDouble3 cartesianLongLat2 = udGeoZone_TransformPoint(longLat, wgs84LongLat, zone); udDouble3 longLat3 = udGeoZone_TransformPoint(cartesianLongLat2, zone, wgs84LongLat); - EXPECT_EQ(int64_t(udRound(latLong.x *testPrecision)), int64_t(udRound(latLong3.x *testPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; - EXPECT_EQ(int64_t(udRound(latLong.y *testPrecision)), int64_t(udRound(latLong3.y *testPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; + EXPECT_EQ(int64_t(udRound(latLong.x * testPrecision)), int64_t(udRound(latLong3.x * testPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; + EXPECT_EQ(int64_t(udRound(latLong.y * testPrecision)), int64_t(udRound(latLong3.y * testPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; - EXPECT_EQ(int64_t(udRound(longLat.x *testPrecision)), int64_t(udRound(longLat3.x *testPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; - EXPECT_EQ(int64_t(udRound(longLat.y *testPrecision)), int64_t(udRound(longLat3.y *testPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; + EXPECT_EQ(int64_t(udRound(longLat.x * testPrecision)), int64_t(udRound(longLat3.x * testPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; + EXPECT_EQ(int64_t(udRound(longLat.y * testPrecision)), int64_t(udRound(longLat3.y * testPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; - EXPECT_EQ(int64_t(udRound(cartesianLatLong.x *localPrecision)), int64_t(udRound(cartesianLatLong2.x *localPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; - EXPECT_EQ(int64_t(udRound(cartesianLatLong.y *localPrecision)), int64_t(udRound(cartesianLatLong2.y *localPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; + EXPECT_EQ(int64_t(udRound(cartesianLatLong.x * localPrecision)), int64_t(udRound(cartesianLatLong2.x * localPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; + EXPECT_EQ(int64_t(udRound(cartesianLatLong.y * localPrecision)), int64_t(udRound(cartesianLatLong2.y * localPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; - EXPECT_EQ(int64_t(udRound(cartesianLatLong.x *localPrecision)), int64_t(udRound(cartesianLongLat2.x *localPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; - EXPECT_EQ(int64_t(udRound(cartesianLatLong.y *localPrecision)), int64_t(udRound(cartesianLongLat2.y *localPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; + EXPECT_EQ(int64_t(udRound(cartesianLatLong.x * localPrecision)), int64_t(udRound(cartesianLongLat2.x * localPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; + EXPECT_EQ(int64_t(udRound(cartesianLatLong.y * localPrecision)), int64_t(udRound(cartesianLongLat2.y * localPrecision))) << "PointSet:" << i << ", SRID:" << data[i].srid; } } TEST(udGeoZone, LCC) { const int64_t angularPrecision = 1 * 60 * 60; // 60x60 to get to arc seconds - const int64_t localPrecision = 1; // 1m + const int64_t localPrecision = 1; // 1m struct TestInput { uint16_t srid; udDouble3 latLon, localSpace; - } testInput[] = - { - { 2230, udDouble3::create(37.800158, -121.298752, 0), udDouble3::create(5098996.58597981, 3727899.53815973, 0.0) }, // Tesla Motors California - { 2238, udDouble3::create(28.385233, -81.5660627, 0), udDouble3::create(2912217.77788892, -211459.72587146, 0.0) }, // Disney World, Florida - { 3112, udDouble3::create(-28.0386128, 153.2827519, 0), udDouble3::create(1865670.94, -3317869.21, 0.0) }, // Lake Advancement - { 3112, udDouble3::create(-29.014848, 134.7520264, 0), udDouble3::create(72407.23, -3281573.42, 0.0) }, // Coober Pedy - { 3112, udDouble3::create(-22.6979855, 116.2332262, 0), udDouble3::create(-1802424.68, -2717219.62, 0.0) }, // Wyloo Station + } testInput[] = { + { 2230, udDouble3::create(37.800158, -121.298752, 0), udDouble3::create(5098996.58597981, 3727899.53815973, 0.0) }, // Tesla Motors California + { 2238, udDouble3::create(28.385233, -81.5660627, 0), udDouble3::create(2912217.77788892, -211459.72587146, 0.0) }, // Disney World, Florida + { 3112, udDouble3::create(-28.0386128, 153.2827519, 0), udDouble3::create(1865670.94, -3317869.21, 0.0) }, // Lake Advancement + { 3112, udDouble3::create(-29.014848, 134.7520264, 0), udDouble3::create(72407.23, -3281573.42, 0.0) }, // Coober Pedy + { 3112, udDouble3::create(-22.6979855, 116.2332262, 0), udDouble3::create(-1802424.68, -2717219.62, 0.0) }, // Wyloo Station }; udDouble3 latLong, localSpace; @@ -215,7 +214,7 @@ TEST(udGeoZone, CassiniSoldner) // long = -62 udDouble3 latLong = udDouble3::create(10, -62, 0.0); - uint64_t localPrecision = 1; // 1m + uint64_t localPrecision = 1; // 1m udGeoZone geoZone; EXPECT_EQ(udR_Success, udGeoZone_SetFromSRID(&geoZone, 30200)); //Trinidad 1903 @@ -239,7 +238,7 @@ TEST(udGeoZone, CassiniSoldnerHyperbolic) // long = -62 udDouble3 latLong = udDouble3::create(-16.841457, 179.994337, 0.0); - uint64_t localPrecision = 1; // 1m + uint64_t localPrecision = 1; // 1m udGeoZone geoZone = {}; EXPECT_EQ(udR_Success, udGeoZone_SetFromSRID(&geoZone, 3139)); // Vanua Levu 1915 @@ -265,7 +264,7 @@ TEST(udGeoZone, HongKongGrid) //udDouble3 latLong = udDouble3::create(22.3193, 114.1694, 0.0); udDouble3 latLong = udDouble3::create(22.485771, 114.000300, 0.0); - uint64_t localPrecision = 1; // 1m + uint64_t localPrecision = 1; // 1m udGeoZone geoZone = {}; EXPECT_EQ(udR_Success, udGeoZone_SetFromSRID(&geoZone, 2326)); // Hong Kong 1980 @@ -281,12 +280,11 @@ TEST(udGeoZone, HongKongGrid) EXPECT_EQ(udRound(latLong.y * localPrecision), udRound(latLongRes.y * localPrecision)); } - TEST(udGeoZone, ETRS89) { udDouble3 latLong = udDouble3::create(48.520804, 0.040925, 0.0); - uint64_t localPrecision = 1; // 1m + uint64_t localPrecision = 1; // 1m udGeoZone geoZone = {}; EXPECT_EQ(udR_Success, udGeoZone_SetFromSRID(&geoZone, 4936)); // ETRS89 EPSG:4936 @@ -313,7 +311,7 @@ TEST(udGeoZone, Lambert93) //udDouble3 latLong = udDouble3::create(22.3193, 114.1694, 0.0); udDouble3 latLong = udDouble3::create(45.96240165432614, 5.355651287573366, 0.0); - uint64_t localPrecision = 1; // 1m + uint64_t localPrecision = 1; // 1m udGeoZone geoZone = {}; EXPECT_EQ(udR_Success, udGeoZone_SetFromSRID(&geoZone, 2154)); // Lambert-93 @@ -338,7 +336,7 @@ TEST(udGeoZone, StereographicOblique) // long = 6 udDouble3 latLong = udDouble3::create(53, 6, 0.0); - uint64_t localPrecision = 1; // 1m + uint64_t localPrecision = 1; // 1m udGeoZone geoZone = {}; EXPECT_EQ(udR_Success, udGeoZone_SetFromSRID(&geoZone, 28992)); // Amersfoort @@ -362,7 +360,7 @@ TEST(udGeoZone, StereographicPolar) // long = 120 udDouble3 latLong = udDouble3::create(-75.0, 120, 0.0); - uint64_t localPrecision = 1; // 1m + uint64_t localPrecision = 1; // 1m udGeoZone geoZone = {}; EXPECT_EQ(udR_Success, udGeoZone_SetFromSRID(&geoZone, 3032)); // Amersfoort @@ -383,7 +381,7 @@ TEST(udGeoZone, Mercator) // long = -100 20'0.0'' udDouble3 latLong = udDouble3::create(24.381787, -100.333333, 0.0); - uint64_t localPrecision = 1; // 1m + uint64_t localPrecision = 1; // 1m udGeoZone geoZone = {}; EXPECT_EQ(udR_Success, udGeoZone_SetFromSRID(&geoZone, 30175)); // Moon Mercator @@ -399,17 +397,16 @@ TEST(udGeoZone, Mercator) TEST(udGeoZone, WebMercator) { const int64_t angularPrecision = 1 * 60 * 60; // 60x60 to get to arc seconds - const int64_t localPrecision = 1; // 1m + const int64_t localPrecision = 1; // 1m struct TestInput { udDouble3 latLon, localSpace; - } testInput[] = - { - { udDouble3::create(37.800158, -121.298752, 0), udDouble3::create(-13502915.31, 4551233.18, 0.0) }, // Tesla Motors California - { udDouble3::create(28.385233, -81.5660627, 0), udDouble3::create(-9079892.57, 3297630.25, 0.0) }, // Disney World, Florida + } testInput[] = { + { udDouble3::create(37.800158, -121.298752, 0), udDouble3::create(-13502915.31, 4551233.18, 0.0) }, // Tesla Motors California + { udDouble3::create(28.385233, -81.5660627, 0), udDouble3::create(-9079892.57, 3297630.25, 0.0) }, // Disney World, Florida { udDouble3::create(-28.0386128, 153.2827519, 0), udDouble3::create(17063357.89, -3253842.85, 0.0) }, // Lake Advancement - { udDouble3::create(-29.014848, 134.7520264, 0), udDouble3::create(15000526.96, -3377535.99, 0.0) }, // Coober Pedy + { udDouble3::create(-29.014848, 134.7520264, 0), udDouble3::create(15000526.96, -3377535.99, 0.0) }, // Coober Pedy { udDouble3::create(-22.6979855, 116.2332262, 0), udDouble3::create(12939023.55, -2595535.72, 0.0) }, // Wyloo Station }; @@ -439,7 +436,7 @@ TEST(udGeoZone, Krovak) // EPSG 8353 : S-JTSK [JTSK03] udDouble3 latLong = udDouble3::create(50.20901167, 16.84977194, 0.0); - uint64_t localPrecision = 1; // 1m + uint64_t localPrecision = 1; // 1m udGeoZone geoZone = {}; EXPECT_EQ(udR_Success, udGeoZone_SetFromSRID(&geoZone, 8353)); // Amersfoort @@ -461,7 +458,7 @@ TEST(udGeoZone, HotineObliqueMercator) // EPSG 29873 : Timbala 1948 udDouble3 latLong = udDouble3::create(5.38725358, 115.80550544, 0.0); - uint64_t localPrecision = 1; // 1m + uint64_t localPrecision = 1; // 1m udGeoZone geoZone = {}; EXPECT_EQ(udR_Success, udGeoZone_SetFromSRID(&geoZone, 29873)); // Amersfoort @@ -481,7 +478,7 @@ TEST(udGeoZone, AlbersConicEqualArea) // EPSG 3174 : Great Lakes Albers udDouble3 latLong = udDouble3::create(42.75, 78.75, 0.0); - uint64_t localPrecision = 1; // 1m + uint64_t localPrecision = 1; // 1m udGeoZone geoZone = {}; EXPECT_EQ(udR_Success, udGeoZone_SetFromSRID(&geoZone, 3174)); // Amersfoort @@ -499,7 +496,7 @@ TEST(udGeoZone, EquidistantCylindrical) // EPSG 4087 : World Equidistant Cylindrical udDouble3 latLong = udDouble3::create(55.0, 10.0, 0.0); - uint64_t localPrecision = 1; // 1m + uint64_t localPrecision = 1; // 1m udGeoZone geoZone = {}; EXPECT_EQ(udR_Success, udGeoZone_SetFromSRID(&geoZone, 4087)); // Amersfoort @@ -518,7 +515,7 @@ TEST(udGeoZone, OSGB) udGeoZone zone; const int64_t angularPrecision = 20 * 60 * 60; // 20 arc seconds - const int64_t localPrecision = 1; // 1m (OSGB is 2m) + const int64_t localPrecision = 1; // 1m (OSGB is 2m) const double wgs84osgbInaccuracyScalar = 0.001; // This scalar is required because we have inaccuracies in our datum shift. @@ -526,17 +523,17 @@ TEST(udGeoZone, OSGB) // spatialreference conversions const udDouble3 expectedLatLongs[] = { //WGS84 - udDouble3::create(52.7545342, 0.2885422, 0), - udDouble3::create(52.7545342, -0.2885422, 0), - udDouble3::create(52.6575703, 1.7179216, 0), - udDouble3::create(50.5, 0.5, 0) + udDouble3::create(52.7545342, 0.2885422, 0), + udDouble3::create(52.7545342, -0.2885422, 0), + udDouble3::create(52.6575703, 1.7179216, 0), + udDouble3::create(50.5, 0.5, 0) }; const udDouble3 expectedLatLongsOSGB[] = { //OSGB1936 - udDouble3::create(52.754162, 0.2902503, 0), - udDouble3::create(52.7541713, -0.2869015, 0), - udDouble3::create(52.6571619, 1.7197914, 0), - udDouble3::create(50.4993633, 0.5016361, 0) + udDouble3::create(52.754162, 0.2902503, 0), + udDouble3::create(52.7541713, -0.2869015, 0), + udDouble3::create(52.6571619, 1.7197914, 0), + udDouble3::create(50.4993633, 0.5016361, 0) }; @@ -588,70 +585,70 @@ TEST(udGeoZone, ChangingCRSDatums) { // This table generated by using epsg.io/transform to transform the first lat/long pair into each datum const udDouble3 latLongPairs[] = { - { -21.1662907, 149.1603855, 0.0 }, // udGZGD_WGS84 / EPSG:4326 - { -21.1659057, 149.1591458, 0.0 }, // udGZGD_ED50 / EPSG:4230 - { -21.1662907, 149.1603855, 0.0 }, // udGZDD_ETRS89 / EPSG:4258 - { -21.1687980, 149.1617787, 0.0 }, // udGZGD_TM75 / EPSG:4300 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NAD27 /EPSG:4267 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NAD27CGQ77 /EPSG:4609 - { -21.1662907, 149.1603855, 0.0 }, // udGZGD_NAD83 /EPSG:4269 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NAD_83_1996 / EPSG:6307 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NAD_83_CSRS / EPSG:2955 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NAD_83_NSRS2007 / EPSG:3465 - { -21.1662907, 149.1603855, 0.0 }, // udGZGD_NAD83_2011 /EPSG:6318 - { -21.171477, 149.1590602, 0.0 }, // udGZGD_NTF / EPSG:4275 - { -21.1690001, 149.1613207, 0.0 }, // udGZGD_OSGB36 / EPSG:4277 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_Potsdam / EPSG:4746 + { -21.1662907, 149.1603855, 0.0 }, // udGZGD_WGS84 / EPSG:4326 + { -21.1659057, 149.1591458, 0.0 }, // udGZGD_ED50 / EPSG:4230 + { -21.1662907, 149.1603855, 0.0 }, // udGZDD_ETRS89 / EPSG:4258 + { -21.1687980, 149.1617787, 0.0 }, // udGZGD_TM75 / EPSG:4300 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NAD27 /EPSG:4267 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NAD27CGQ77 /EPSG:4609 + { -21.1662907, 149.1603855, 0.0 }, // udGZGD_NAD83 /EPSG:4269 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NAD_83_1996 / EPSG:6307 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NAD_83_CSRS / EPSG:2955 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NAD_83_NSRS2007 / EPSG:3465 + { -21.1662907, 149.1603855, 0.0 }, // udGZGD_NAD83_2011 /EPSG:6318 + { -21.171477, 149.1590602, 0.0 }, // udGZGD_NTF / EPSG:4275 + { -21.1690001, 149.1613207, 0.0 }, // udGZGD_OSGB36 / EPSG:4277 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_Potsdam / EPSG:4746 { -21.17287696, 149.16385735, 0.0 }, // udGZGD_Tokyo / EPSG:7414 - { -21.1663274, 149.1602316, 0.0 }, // udGZGD_WGS72 / EPSG:4322 - { -21.1662908, 149.1603855, 0.0 }, // udGZGD_JDG2000 / EPSG:4612 - { -21.1662908, 149.1603855, 0.0 }, // udGZGD_JDG2011 / EPSG:6668 - { -21.1662907, 149.1603855, 0.0 }, // udGZGD_GDA94 / EPSG:4283 - { -21.1662907, 149.1603855, 0.0 }, // udGZGD_GDA2020 / EPSG:7844 - { -21.1662907, 149.1603855, 0.0 }, // udGZGD_RGF93 / EPSG:4171 - { -21.1662907, 149.1603855, 0.0 }, // udGZGD_NAD83_HARN / EPSG:4152 - { -21.1662907, 149.1603855, 0.0 }, // udGZGD_CGCS2000 / EPSG:4490 - { -21.1649467, 149.1577442, 0.0 }, // udGZGD_HK1980 / EPSG:4611 - { -21.1662908, 149.1603855, 0.0 }, // udGZGD_SVY21 / EPSG:4757 - { -21.1694171, 149.1628993, 0.0 }, // udGZGD_MGI / EPSG:4312 - { -21.1662907, 149.1603855, 0.0 }, // udGZGD_NZGD2000 / EPSG:4167 - { -21.1683349, 149.1640584, 0.1 }, // udGZGD_AMERSFOORT / EPSG:4289 - { -21.1726807, 149.1624330, 0.1 }, // udGZGD_TRI1903 / EPSG:4302 - { -21.1686201, 149.1638699, 0.0 }, // udGZGD_VANUA1915 / EPSG:3139 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_DEALUL1970/ EPSG:4024 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_SINGGRID/ EPSG:19920 - { -21.1662907, 149.1603855, -0.1 }, // udGZGD_MARS_MERC/ // These are derived from our own code and are not to be trusted - { -21.1662907, 149.1603855, -0.1 }, // udGZGD_MARS_PCPF/ // These are derived from our own code and are not to be trusted - { -21.0370272, 149.1603855, -0.1 }, // udGZGD_MOON_MERC/ // These are derived from our own code and are not to be trusted - { -21.0370272, 149.1603855, -0.1 }, // udGZGD_MOON_PCPF/ // These are derived from our own code and are not to be trusted - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_DBREF / EPSG:5681 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_DHDN / EPSG:4314 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_SJTK03 / EPSG:8353 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_PULK1942 / EPSG:4284 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_PULK194258 / EPSG:4179 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_PULK194283 / EPSG:4178 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_PULK1995 / EPSG:20004 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_WGS_72BE / EPSG:32401 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_BEIJING1954 / EPSG:21413 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NEWBEIJING / EPSG:4555 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_XIANG1980 / EPSG:4610 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_TIMB1948 / EPSG:29873 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NZGD49 / EPSG:4272 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_SWEREF99 / EPSG:4619 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_SAD69 / EPSG:4291 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_GR96 / EPSG:4747 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_DGN95 / EPSG:4755 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_UCS2000 / EPSG:5561 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_H94 / EPSG:4148 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_ID74 / EPSG:4238 - { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NGO1948 / EPSG:4273 - { -21.1662907, 149.1603855, 0.0 }, // udGZGD_RGF93v2b / EPSG:9781 + { -21.1663274, 149.1602316, 0.0 }, // udGZGD_WGS72 / EPSG:4322 + { -21.1662908, 149.1603855, 0.0 }, // udGZGD_JDG2000 / EPSG:4612 + { -21.1662908, 149.1603855, 0.0 }, // udGZGD_JDG2011 / EPSG:6668 + { -21.1662907, 149.1603855, 0.0 }, // udGZGD_GDA94 / EPSG:4283 + { -21.1662907, 149.1603855, 0.0 }, // udGZGD_GDA2020 / EPSG:7844 + { -21.1662907, 149.1603855, 0.0 }, // udGZGD_RGF93 / EPSG:4171 + { -21.1662907, 149.1603855, 0.0 }, // udGZGD_NAD83_HARN / EPSG:4152 + { -21.1662907, 149.1603855, 0.0 }, // udGZGD_CGCS2000 / EPSG:4490 + { -21.1649467, 149.1577442, 0.0 }, // udGZGD_HK1980 / EPSG:4611 + { -21.1662908, 149.1603855, 0.0 }, // udGZGD_SVY21 / EPSG:4757 + { -21.1694171, 149.1628993, 0.0 }, // udGZGD_MGI / EPSG:4312 + { -21.1662907, 149.1603855, 0.0 }, // udGZGD_NZGD2000 / EPSG:4167 + { -21.1683349, 149.1640584, 0.1 }, // udGZGD_AMERSFOORT / EPSG:4289 + { -21.1726807, 149.1624330, 0.1 }, // udGZGD_TRI1903 / EPSG:4302 + { -21.1686201, 149.1638699, 0.0 }, // udGZGD_VANUA1915 / EPSG:3139 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_DEALUL1970/ EPSG:4024 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_SINGGRID/ EPSG:19920 + { -21.1662907, 149.1603855, -0.1 }, // udGZGD_MARS_MERC/ // These are derived from our own code and are not to be trusted + { -21.1662907, 149.1603855, -0.1 }, // udGZGD_MARS_PCPF/ // These are derived from our own code and are not to be trusted + { -21.0370272, 149.1603855, -0.1 }, // udGZGD_MOON_MERC/ // These are derived from our own code and are not to be trusted + { -21.0370272, 149.1603855, -0.1 }, // udGZGD_MOON_PCPF/ // These are derived from our own code and are not to be trusted + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_DBREF / EPSG:5681 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_DHDN / EPSG:4314 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_SJTK03 / EPSG:8353 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_PULK1942 / EPSG:4284 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_PULK194258 / EPSG:4179 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_PULK194283 / EPSG:4178 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_PULK1995 / EPSG:20004 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_WGS_72BE / EPSG:32401 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_BEIJING1954 / EPSG:21413 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NEWBEIJING / EPSG:4555 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_XIANG1980 / EPSG:4610 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_TIMB1948 / EPSG:29873 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NZGD49 / EPSG:4272 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_SWEREF99 / EPSG:4619 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_SAD69 / EPSG:4291 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_GR96 / EPSG:4747 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_DGN95 / EPSG:4755 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_UCS2000 / EPSG:5561 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_H94 / EPSG:4148 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_ID74 / EPSG:4238 + { -21.1662907, 149.1603855, 0.1 }, // udGZGD_NGO1948 / EPSG:4273 + { -21.1662907, 149.1603855, 0.0 }, // udGZGD_RGF93v2b / EPSG:9781 }; UDCOMPILEASSERT(UDARRAYSIZE(latLongPairs) == udGZGD_Count, "Please Update the Datums!"); const int64_t HighAccuracy = 108030; // 1m at equator - const int64_t LowAccuracy = 54; // 2km + const int64_t LowAccuracy = 54; // 2km for (size_t i = 0; i < udLengthOf(latLongPairs); ++i) // First iteration will convert 84 to 84 to confirm it works { @@ -672,14 +669,14 @@ TEST(udGeoZone, ChangingCRSDatums) } } -const udDouble2 goldDataLatLong[] = { { 85, -60 },{ 85, -50 },{ 85, -40 },{ 85, -30 },{ 85, -20 },{ 85, -10 },{ 85, 0 },{ 85, 10 },{ 85, 20 },{ 85, 30 },{ 85, 40 },{ 85, 50 },{ 85, 60 },{ 75, -60 },{ 75, -50 },{ 75, -40 },{ 75, -30 },{ 75, -20 },{ 75, -10 },{ 75, 0 },{ 75, 10 },{ 75, 20 },{ 75, 30 },{ 75, 40 },{ 75, 50 },{ 75, 60 },{ 60, -60 },{ 60, -55 },{ 60, -50 },{ 60, -45 },{ 60, -40 },{ 60, -35 },{ 60, -30 },{ 60, -25 },{ 60, -20 },{ 60, -15 },{ 60, -10 },{ 60, -5 },{ 60, 0 },{ 60, 5 },{ 60, 10 },{ 60, 15 },{ 60, 20 },{ 60, 25 },{ 60, 30 },{ 60, 35 },{ 60, 40 },{ 60, 45 },{ 60, 50 },{ 60, 55 },{ 60, 60 },{ 45, -60 },{ 45, -50 },{ 45, -40 },{ 45, -30 },{ 45, -20 },{ 45, -10 },{ 45, 0 },{ 45, 0.125 },{ 45, 0.25 },{ 45, 0.5 },{ 45, 1 },{ 45, 2 },{ 45, 3 },{ 45, 5 },{ 45, 10 },{ 45, 15 },{ 45, 20 },{ 45, 25 },{ 45, 30 },{ 45, 35 },{ 45, 40 },{ 45, 45 },{ 45, 50 },{ 45, 55 },{ 45, 60 },{ 30, -60 },{ 30, -50 },{ 30, -40 },{ 30, -30 },{ 30, -20 },{ 30, -10 },{ 30, 0 },{ 30, 5 },{ 30, 10 },{ 30, 15 },{ 30, 20 },{ 30, 25 },{ 30, 30 },{ 30, 35 },{ 30, 40 },{ 30, 45 },{ 30, 50 },{ 30, 55 },{ 30, 57 },{ 30, 58 },{ 30, 59 },{ 30, 59.25 },{ 30, 59.50 },{ 30, 59.75 },{ 30, 60 },{ 0, -60 },{ 0, -58 },{ 0, -56 },{ 0, -54 },{ 0, -52 },{ 0, -50 },{ 0, -48 },{ 0, -46 },{ 0, -44 },{ 0, -42 },{ 0, -40 },{ 0, -38 },{ 0, -36 },{ 0, -34 },{ 0, -32 },{ 0, -30 },{ 0, -28 },{ 0, -26 },{ 0, -24 },{ 0, -22 },{ 0, -20 },{ 0, -18 },{ 0, -16 },{ 0, -14 },{ 0, -12 },{ 0, -10 },{ 0, -8 },{ 0, -6 },{ 0, -4 },{ 0, -2 },{ 0, 0 },{ 0, 2 },{ 0, 4 },{ 0, 6 },{ 0, 8 },{ 0, 10 },{ 0, 12 },{ 0, 14 },{ 0, 16 },{ 0, 18 },{ 0, 20 },{ 0, 22 },{ 0, 24 },{ 0, 26 },{ 0, 28 },{ 0, 30 },{ 0, 32 },{ 0, 34 },{ 0, 36 },{ 0, 38 },{ 0, 40 },{ 0, 42 },{ 0, 44 },{ 0, 46 },{ 0, 48 },{ 0, 50 },{ 0, 52 },{ 0, 54 },{ 0, 56 },{ 0, 58 },{ 0, 60 },{ -60, -60 },{ -60, -55 },{ -60, -50 },{ -60, -45 },{ -60, -40 },{ -60, -35 },{ -60, -30 },{ -60, -25 },{ -60, -20 },{ -60, -15 },{ -60, -10 },{ -60, -5 },{ -60, 0 },{ -60, 5 },{ -60, 10 },{ -60, 15 },{ -60, 20 },{ -60, 25 },{ -60, 30 },{ -60, 35 },{ -60, 40 },{ -60, 45 },{ -60, 50 },{ -60, 55 },{ -60, 60 },{ -85, -60 },{ -85, -50 },{ -85, -40 },{ -85, -30 },{ -85, -20 },{ -85, -10 },{ -85, 0 },{ -85, 10 },{ -85, 20 },{ -85, 30 },{ -85, 40 },{ -85, 50 },{ -85, 60 },{ 88, 0 },{ 86, 0 },{ 84, 0 },{ 82, 0 },{ 80, 0 },{ 78, 0 },{ 76, 0 },{ 74, 0 },{ 72, 0 },{ 70, 0 },{ 68, 0 },{ 66, 0 },{ 64, 0 },{ 62, 0 },{ 60, 0 },{ 58, 0 },{ 56, 0 },{ 54, 0 },{ 52, 0 },{ 50, 0 },{ 48, 0 },{ 46, 0 },{ 44, 0 },{ 42, 0 },{ 40, 0 },{ 38, 0 },{ 36, 0 },{ 34, 0 },{ 32, 0 },{ 30, 0 },{ 28, 0 },{ 26, 0 },{ 24, 0 },{ 22, 0 },{ 20, 0 },{ 18, 0 },{ 16, 0 },{ 14, 0 },{ 12, 0 },{ 10, 0 },{ 8, 0 },{ 6, 0 },{ 4, 0 },{ 2, 0 },{ 0, 0 },{ -2, 0 },{ -4, 0 },{ -6, 0 },{ -8, 0 },{ -10, 0 },{ 88, 60 },{ 86, 60 },{ 84, 60 },{ 82, 60 },{ 80, 60 },{ 78, 60 },{ 76, 60 },{ 74, 60 },{ 72, 60 },{ 70, 60 },{ 68, 60 },{ 66, 60 },{ 64, 60 },{ 62, 60 },{ 60, 60 },{ 58, 60 },{ 56, 60 },{ 54, 60 },{ 52, 60 },{ 50, 60 },{ 48, 60 },{ 46, 60 },{ 44, 60 },{ 42, 60 },{ 40, 60 },{ 38, 60 },{ 36, 60 },{ 34, 60 },{ 32, 60 },{ 30, 60 },{ 28, 60 },{ 26, 60 },{ 24, 60 },{ 22, 60 },{ 20, 60 },{ 18, 60 },{ 16, 60 },{ 14, 60 },{ 12, 60 },{ 10, 60 },{ 8, 60 },{ 6, 60 },{ 4, 60 },{ 2, 60 },{ 0, 60 },{ -2, 60 },{ -4, 60 },{ -6, 60 },{ -8, 60 },{ -10, 60 } }; +const udDouble2 goldDataLatLong[] = { { 85, -60 }, { 85, -50 }, { 85, -40 }, { 85, -30 }, { 85, -20 }, { 85, -10 }, { 85, 0 }, { 85, 10 }, { 85, 20 }, { 85, 30 }, { 85, 40 }, { 85, 50 }, { 85, 60 }, { 75, -60 }, { 75, -50 }, { 75, -40 }, { 75, -30 }, { 75, -20 }, { 75, -10 }, { 75, 0 }, { 75, 10 }, { 75, 20 }, { 75, 30 }, { 75, 40 }, { 75, 50 }, { 75, 60 }, { 60, -60 }, { 60, -55 }, { 60, -50 }, { 60, -45 }, { 60, -40 }, { 60, -35 }, { 60, -30 }, { 60, -25 }, { 60, -20 }, { 60, -15 }, { 60, -10 }, { 60, -5 }, { 60, 0 }, { 60, 5 }, { 60, 10 }, { 60, 15 }, { 60, 20 }, { 60, 25 }, { 60, 30 }, { 60, 35 }, { 60, 40 }, { 60, 45 }, { 60, 50 }, { 60, 55 }, { 60, 60 }, { 45, -60 }, { 45, -50 }, { 45, -40 }, { 45, -30 }, { 45, -20 }, { 45, -10 }, { 45, 0 }, { 45, 0.125 }, { 45, 0.25 }, { 45, 0.5 }, { 45, 1 }, { 45, 2 }, { 45, 3 }, { 45, 5 }, { 45, 10 }, { 45, 15 }, { 45, 20 }, { 45, 25 }, { 45, 30 }, { 45, 35 }, { 45, 40 }, { 45, 45 }, { 45, 50 }, { 45, 55 }, { 45, 60 }, { 30, -60 }, { 30, -50 }, { 30, -40 }, { 30, -30 }, { 30, -20 }, { 30, -10 }, { 30, 0 }, { 30, 5 }, { 30, 10 }, { 30, 15 }, { 30, 20 }, { 30, 25 }, { 30, 30 }, { 30, 35 }, { 30, 40 }, { 30, 45 }, { 30, 50 }, { 30, 55 }, { 30, 57 }, { 30, 58 }, { 30, 59 }, { 30, 59.25 }, { 30, 59.50 }, { 30, 59.75 }, { 30, 60 }, { 0, -60 }, { 0, -58 }, { 0, -56 }, { 0, -54 }, { 0, -52 }, { 0, -50 }, { 0, -48 }, { 0, -46 }, { 0, -44 }, { 0, -42 }, { 0, -40 }, { 0, -38 }, { 0, -36 }, { 0, -34 }, { 0, -32 }, { 0, -30 }, { 0, -28 }, { 0, -26 }, { 0, -24 }, { 0, -22 }, { 0, -20 }, { 0, -18 }, { 0, -16 }, { 0, -14 }, { 0, -12 }, { 0, -10 }, { 0, -8 }, { 0, -6 }, { 0, -4 }, { 0, -2 }, { 0, 0 }, { 0, 2 }, { 0, 4 }, { 0, 6 }, { 0, 8 }, { 0, 10 }, { 0, 12 }, { 0, 14 }, { 0, 16 }, { 0, 18 }, { 0, 20 }, { 0, 22 }, { 0, 24 }, { 0, 26 }, { 0, 28 }, { 0, 30 }, { 0, 32 }, { 0, 34 }, { 0, 36 }, { 0, 38 }, { 0, 40 }, { 0, 42 }, { 0, 44 }, { 0, 46 }, { 0, 48 }, { 0, 50 }, { 0, 52 }, { 0, 54 }, { 0, 56 }, { 0, 58 }, { 0, 60 }, { -60, -60 }, { -60, -55 }, { -60, -50 }, { -60, -45 }, { -60, -40 }, { -60, -35 }, { -60, -30 }, { -60, -25 }, { -60, -20 }, { -60, -15 }, { -60, -10 }, { -60, -5 }, { -60, 0 }, { -60, 5 }, { -60, 10 }, { -60, 15 }, { -60, 20 }, { -60, 25 }, { -60, 30 }, { -60, 35 }, { -60, 40 }, { -60, 45 }, { -60, 50 }, { -60, 55 }, { -60, 60 }, { -85, -60 }, { -85, -50 }, { -85, -40 }, { -85, -30 }, { -85, -20 }, { -85, -10 }, { -85, 0 }, { -85, 10 }, { -85, 20 }, { -85, 30 }, { -85, 40 }, { -85, 50 }, { -85, 60 }, { 88, 0 }, { 86, 0 }, { 84, 0 }, { 82, 0 }, { 80, 0 }, { 78, 0 }, { 76, 0 }, { 74, 0 }, { 72, 0 }, { 70, 0 }, { 68, 0 }, { 66, 0 }, { 64, 0 }, { 62, 0 }, { 60, 0 }, { 58, 0 }, { 56, 0 }, { 54, 0 }, { 52, 0 }, { 50, 0 }, { 48, 0 }, { 46, 0 }, { 44, 0 }, { 42, 0 }, { 40, 0 }, { 38, 0 }, { 36, 0 }, { 34, 0 }, { 32, 0 }, { 30, 0 }, { 28, 0 }, { 26, 0 }, { 24, 0 }, { 22, 0 }, { 20, 0 }, { 18, 0 }, { 16, 0 }, { 14, 0 }, { 12, 0 }, { 10, 0 }, { 8, 0 }, { 6, 0 }, { 4, 0 }, { 2, 0 }, { 0, 0 }, { -2, 0 }, { -4, 0 }, { -6, 0 }, { -8, 0 }, { -10, 0 }, { 88, 60 }, { 86, 60 }, { 84, 60 }, { 82, 60 }, { 80, 60 }, { 78, 60 }, { 76, 60 }, { 74, 60 }, { 72, 60 }, { 70, 60 }, { 68, 60 }, { 66, 60 }, { 64, 60 }, { 62, 60 }, { 60, 60 }, { 58, 60 }, { 56, 60 }, { 54, 60 }, { 52, 60 }, { 50, 60 }, { 48, 60 }, { 46, 60 }, { 44, 60 }, { 42, 60 }, { 40, 60 }, { 38, 60 }, { 36, 60 }, { 34, 60 }, { 32, 60 }, { 30, 60 }, { 28, 60 }, { 26, 60 }, { 24, 60 }, { 22, 60 }, { 20, 60 }, { 18, 60 }, { 16, 60 }, { 14, 60 }, { 12, 60 }, { 10, 60 }, { 8, 60 }, { 6, 60 }, { 4, 60 }, { 2, 60 }, { 0, 60 }, { -2, 60 }, { -4, 60 }, { -6, 60 }, { -8, 60 }, { -10, 60 } }; // TransMerc26 test from GoldData_v6.3 @ http://earth-info.nga.mil/GandG/coordsys/Conversion_Software/index.html TEST(udGeoZone, GoldData63TransMerc26) { - udDouble2 mercData[] = { { -483943.527503, 9722205.338481 },{ -427895.580459, 9642462.065386 },{ -358888.675495, 9573715.084698 },{ -279050.262683, 9518022.200890 },{ -190817.262239, 9477033.459573 },{ -96859.156300, 9451952.297203 },{ 0.000000, 9443510.140666 },{ 96859.156300, 9451952.297203 },{ 190817.262239, 9477033.459573 },{ 279050.262683, 9518022.200890 },{ 358888.675495, 9573715.084698 },{ 427895.580459, 9642462.065386 },{ 483943.527503, 9722205.338481 },{ -1458869.311637, 9149858.816237 },{ -1285565.198612, 8910698.457266 },{ -1074419.247845, 8706672.371011 },{ -832650.960579, 8543094.337698 },{ -567859.299246, 8423785.611430 },{ -287748.836902, 8351262.808936 },{ 0.000000, 8326937.587280 },{ 287748.836902, 8351262.808936 },{ 567859.299246, 8423785.611430 },{ 832650.960579, 8543094.337698 },{ 1074419.247845, 8706672.371011 },{ 1285565.198612, 8910698.457266 },{ 1458869.311637, 9149858.816237 },{ -2964227.090765, 8205251.234407 },{ -2782064.056031, 7957435.773324 },{ -2580653.930717, 7729962.209904 },{ -2362651.685233, 7523798.004299 },{ -2130566.804588, 7339517.432528 },{ -1886712.043039, 7177385.363796 },{ -1633178.735886, 7037439.986987 },{ -1371833.624649, 6919568.522094 },{ -1104331.837754, 6823572.599735 },{ -832141.189888, 6749222.012765 },{ -556573.889131, 6696296.869256 },{ -278822.758856, 6664618.888100 },{ 0.000000, 6654072.819491 },{ 278822.758856, 6664618.888100 },{ 556573.889131, 6696296.869256 },{ 832141.189888, 6749222.012765 },{ 1104331.837754, 6823572.599735 },{ 1371833.624649, 6919568.522094 },{ 1633178.735886, 7037439.986987 },{ 1886712.043039, 7177385.363796 },{ 2130566.804588, 7339517.432528 },{ 2362651.685233, 7523798.004299 },{ 2580653.930717, 7729962.209904 },{ 2782064.056031, 7957435.773324 },{ 2964227.090765, 8205251.234407 },{ -4552797.983219, 7042021.264274 },{ -3874997.468215, 6353771.575090 },{ -3133139.791765, 5826829.612032 },{ -2360791.676704, 5443001.292697 },{ -1576380.787425, 5183546.587965 },{ -788456.442807, 5033847.161114 },{ 0.000000, 4984944.377978 },{ 9855.854400, 4984951.980138 },{ 19711.708879, 4984974.786691 },{ 39423.418384, 4985066.013998 },{ 78846.841653, 4985430.940726 },{ 157693.718217, 4986890.927643 },{ 236540.642358, 4989325.234793 },{ 394234.438810, 4997123.381818 },{ 788456.442807, 5033847.161114 },{ 1182582.362270, 5095676.477878 },{ 1576380.787425, 5183546.587965 },{ 1969385.344968, 5298764.994976 },{ 2360791.676704, 5443001.292697 },{ 2749334.151719, 5618260.797473 },{ 3133139.791765, 5826829.612032 },{ 3509561.102920, 6071173.921846 },{ 3874997.468215, 6353771.575090 },{ 4224728.010175, 6676851.570206 },{ 4552797.983219, 7042021.264274 },{ -6210906.900160, 5455136.341724 },{ -5100884.293138, 4652262.781639 },{ -4009728.397901, 4101640.403114 },{ -2959830.261718, 3731566.523691 },{ -1949320.326404, 3494725.886266 },{ -967326.622891, 3362593.789817 },{ 0.000000, 3320113.397940 },{ 482739.761374, 3330662.065311 },{ 967326.622891, 3362593.789817 },{ 1455590.738883, 3416780.562222 },{ 1949320.326404, 3494725.886266 },{ 2450218.798188, 3598642.627884 },{ 2959830.261718, 3731566.523691 },{ 3479412.822009, 3897507.894394 },{ 4009728.397901, 4101640.403114 },{ 4550702.122779, 4350515.050072 },{ 5100884.293138, 4652262.781639 },{ 5656629.042264, 5016697.591669 },{ 5879057.348553, 5182521.093137 },{ 5990007.092138, 5270111.030646 },{ 6100658.157988, 5360950.158381 },{ 6128262.329125, 5384179.105403 },{ 6155839.688010, 5407618.771574 },{ 6183388.477643, 5431270.678047 },{ 6210906.900160, 5455136.341724 },{ -8423099.473515, 0.000000 },{ -7986550.230016, 0.000000 },{ -7574316.703085, 0.000000 },{ -7183343.494858, 0.000000 },{ -6811084.435548, 0.000000 },{ -6455393.148674, 0.000000 },{ -6114441.581589, 0.000000 },{ -5786658.285436, 0.000000 },{ -5470680.926552, 0.000000 },{ -5165319.237408, 0.000000 },{ -4869525.747989, 0.000000 },{ -4582372.398706, 0.000000 },{ -4303031.656552, 0.000000 },{ -4030761.119143, 0.000000 },{ -3764890.848480, 0.000000 },{ -3504812.861291, 0.000000 },{ -3249972.337647, 0.000000 },{ -2999860.209058, 0.000000 },{ -2754006.861562, 0.000000 },{ -2511976.745296, 0.000000 },{ -2273363.724682, 0.000000 },{ -2037787.036058, 0.000000 },{ -1804887.744877, 0.000000 },{ -1574325.614256, 0.000000 },{ -1345776.312061, 0.000000 },{ -1118928.895723, 0.000000 },{ -893483.523497, 0.000000 },{ -669149.348267, 0.000000 },{ -445642.555759, 0.000000 },{ -222684.513481, 0.000000 },{ 0.000000, 0.000000 },{ 222684.513481, 0.000000 },{ 445642.555759, 0.000000 },{ 669149.348267, 0.000000 },{ 893483.523497, 0.000000 },{ 1118928.895723, 0.000000 },{ 1345776.312061, 0.000000 },{ 1574325.614256, 0.000000 },{ 1804887.744877, 0.000000 },{ 2037787.036058, 0.000000 },{ 2273363.724682, 0.000000 },{ 2511976.745296, 0.000000 },{ 2754006.861562, 0.000000 },{ 2999860.209058, 0.000000 },{ 3249972.337647, 0.000000 },{ 3504812.861291, 0.000000 },{ 3764890.848480, 0.000000 },{ 4030761.119143, 0.000000 },{ 4303031.656552, 0.000000 },{ 4582372.398706, 0.000000 },{ 4869525.747989, 0.000000 },{ 5165319.237408, 0.000000 },{ 5470680.926552, 0.000000 },{ 5786658.285436, 0.000000 },{ 6114441.581589, 0.000000 },{ 6455393.148674, 0.000000 },{ 6811084.435548, 0.000000 },{ 7183343.494858, 0.000000 },{ 7574316.703085, 0.000000 },{ 7986550.230016, 0.000000 },{ 8423099.473515, 0.000000 },{ -2964227.090765, -8205251.234407 },{ -2782064.056031, -7957435.773324 },{ -2580653.930717, -7729962.209904 },{ -2362651.685233, -7523798.004299 },{ -2130566.804588, -7339517.432528 },{ -1886712.043039, -7177385.363796 },{ -1633178.735886, -7037439.986987 },{ -1371833.624649, -6919568.522094 },{ -1104331.837754, -6823572.599735 },{ -832141.189888, -6749222.012765 },{ -556573.889131, -6696296.869256 },{ -278822.758856, -6664618.888100 },{ 0.000000, -6654072.819491 },{ 278822.758856, -6664618.888100 },{ 556573.889131, -6696296.869256 },{ 832141.189888, -6749222.012765 },{ 1104331.837754, -6823572.599735 },{ 1371833.624649, -6919568.522094 },{ 1633178.735886, -7037439.986987 },{ 1886712.043039, -7177385.363796 },{ 2130566.804588, -7339517.432528 },{ 2362651.685233, -7523798.004299 },{ 2580653.930717, -7729962.209904 },{ 2782064.056031, -7957435.773324 },{ 2964227.090765, -8205251.234407 },{ -483943.527503, -9722205.338481 },{ -427895.580459, -9642462.065386 },{ -358888.675495, -9573715.084698 },{ -279050.262683, -9518022.200890 },{ -190817.262239, -9477033.459573 },{ -96859.156300, -9451952.297203 },{ 0.000000, -9443510.140666 },{ 96859.156300, -9451952.297203 },{ 190817.262239, -9477033.459573 },{ 279050.262683, -9518022.200890 },{ 358888.675495, -9573715.084698 },{ 427895.580459, -9642462.065386 },{ 483943.527503, -9722205.338481 },{ 0.000000, 9778578.687182 },{ 0.000000, 9555197.141480 },{ 0.000000, 9331826.561185 },{ 0.000000, 9108472.360519 },{ 0.000000, 8885139.871937 },{ 0.000000, 8661834.319555 },{ 0.000000, 8438560.793153 },{ 0.000000, 8215324.222895 },{ 0.000000, 7992129.354896 },{ 0.000000, 7768980.727770 },{ 0.000000, 7545882.650267 },{ 0.000000, 7322839.180123 },{ 0.000000, 7099854.104229 },{ 0.000000, 6876930.920205 },{ 0.000000, 6654072.819491 },{ 0.000000, 6431282.672002 },{ 0.000000, 6208563.012457 },{ 0.000000, 5985916.028402 },{ 0.000000, 5763343.550010 },{ 0.000000, 5540847.041684 },{ 0.000000, 5318427.595490 },{ 0.000000, 5096085.926452 },{ 0.000000, 4873822.369715 },{ 0.000000, 4651636.879571 },{ 0.000000, 4429529.030351 },{ 0.000000, 4207498.019154 },{ 0.000000, 3985542.670404 },{ 0.000000, 3763661.442172 },{ 0.000000, 3541852.434256 },{ 0.000000, 3320113.397940 },{ 0.000000, 3098441.747387 },{ 0.000000, 2876834.572604 },{ 0.000000, 2655288.653903 },{ 0.000000, 2433800.477786 },{ 0.000000, 2212366.254172 },{ 0.000000, 1990981.934878 },{ 0.000000, 1769643.233270 },{ 0.000000, 1548345.644978 },{ 0.000000, 1327084.469593 },{ 0.000000, 1105854.833234 },{ 0.000000, 884651.711881 },{ 0.000000, 663469.955375 },{ 0.000000, 442304.311978 },{ 0.000000, 221149.453372 },{ 0.000000, 0.000000 },{ 0.000000, -221149.453372 },{ 0.000000, -442304.311978 },{ 0.000000, -663469.955375 },{ 0.000000, -884651.711881 },{ 0.000000, -1105854.833234 },{ 193478.495744, 9890238.174368 },{ 387070.053266, 9778308.925410 },{ 580887.593439, 9665975.077520 },{ 775043.744138, 9553031.292767 },{ 969650.665433, 9439268.555628 },{ 1164819.839706, 9324472.894622 },{ 1360661.813189, 9208424.058689 },{ 1557285.873746, 9090894.136782 },{ 1754799.647559, 8971646.109077 },{ 1953308.594636, 8850432.318211 },{ 2152915.379650, 8726992.849240 },{ 2353719.090435, 8601053.807452 },{ 2555814.271380, 8472325.484149 },{ 2759289.732889, 8340500.402045 },{ 2964227.090765, 8205251.234407 },{ 3170698.980807, 8066228.595750 },{ 3378766.883776, 7923058.707330 },{ 3588478.484220, 7775340.948452 },{ 3799864.473255, 7622645.315506 },{ 4012934.690389, 7464509.825794 },{ 4227673.483131, 7300437.923867 },{ 4444034.145850, 7129895.976045 },{ 4661932.282425, 6952310.976086 },{ 4881237.922223, 6767068.634161 },{ 5101766.208947, 6573512.085289 },{ 5323266.481326, 6370941.535402 },{ 5545409.580258, 6158615.266273 },{ 5767773.258604, 5935752.547047 },{ 5989825.651007, 5701539.150389 },{ 6210906.900160, 5455136.341724 },{ 6430209.256248, 5195694.390171 },{ 6646756.295488, 4922371.817126 },{ 6859382.370663, 4634361.713402 },{ 7066714.034424, 4330926.453274 },{ 7267155.968366, 4011441.917637 },{ 7458884.868697, 3675451.778875 },{ 7639855.668495, 3322731.344695 },{ 7807825.189291, 2953358.766832 },{ 7960398.439614, 2567789.038934 },{ 8095101.814284, 2166923.285356 },{ 8209484.870500, 1752162.874899 },{ 8301247.860745, 1325435.816676 },{ 8368386.074076, 889182.995388 },{ 8409335.493936, 446295.299669 },{ 8423099.473515, 0.000000 },{ 8409335.493936, -446295.299669 },{ 8368386.074076, -889182.995388 },{ 8301247.860745, -1325435.816676 },{ 8209484.870500, -1752162.874899 },{ 8095101.814284, -2166923.285356 } }; + udDouble2 mercData[] = { { -483943.527503, 9722205.338481 }, { -427895.580459, 9642462.065386 }, { -358888.675495, 9573715.084698 }, { -279050.262683, 9518022.200890 }, { -190817.262239, 9477033.459573 }, { -96859.156300, 9451952.297203 }, { 0.000000, 9443510.140666 }, { 96859.156300, 9451952.297203 }, { 190817.262239, 9477033.459573 }, { 279050.262683, 9518022.200890 }, { 358888.675495, 9573715.084698 }, { 427895.580459, 9642462.065386 }, { 483943.527503, 9722205.338481 }, { -1458869.311637, 9149858.816237 }, { -1285565.198612, 8910698.457266 }, { -1074419.247845, 8706672.371011 }, { -832650.960579, 8543094.337698 }, { -567859.299246, 8423785.611430 }, { -287748.836902, 8351262.808936 }, { 0.000000, 8326937.587280 }, { 287748.836902, 8351262.808936 }, { 567859.299246, 8423785.611430 }, { 832650.960579, 8543094.337698 }, { 1074419.247845, 8706672.371011 }, { 1285565.198612, 8910698.457266 }, { 1458869.311637, 9149858.816237 }, { -2964227.090765, 8205251.234407 }, { -2782064.056031, 7957435.773324 }, { -2580653.930717, 7729962.209904 }, { -2362651.685233, 7523798.004299 }, { -2130566.804588, 7339517.432528 }, { -1886712.043039, 7177385.363796 }, { -1633178.735886, 7037439.986987 }, { -1371833.624649, 6919568.522094 }, { -1104331.837754, 6823572.599735 }, { -832141.189888, 6749222.012765 }, { -556573.889131, 6696296.869256 }, { -278822.758856, 6664618.888100 }, { 0.000000, 6654072.819491 }, { 278822.758856, 6664618.888100 }, { 556573.889131, 6696296.869256 }, { 832141.189888, 6749222.012765 }, { 1104331.837754, 6823572.599735 }, { 1371833.624649, 6919568.522094 }, { 1633178.735886, 7037439.986987 }, { 1886712.043039, 7177385.363796 }, { 2130566.804588, 7339517.432528 }, { 2362651.685233, 7523798.004299 }, { 2580653.930717, 7729962.209904 }, { 2782064.056031, 7957435.773324 }, { 2964227.090765, 8205251.234407 }, { -4552797.983219, 7042021.264274 }, { -3874997.468215, 6353771.575090 }, { -3133139.791765, 5826829.612032 }, { -2360791.676704, 5443001.292697 }, { -1576380.787425, 5183546.587965 }, { -788456.442807, 5033847.161114 }, { 0.000000, 4984944.377978 }, { 9855.854400, 4984951.980138 }, { 19711.708879, 4984974.786691 }, { 39423.418384, 4985066.013998 }, { 78846.841653, 4985430.940726 }, { 157693.718217, 4986890.927643 }, { 236540.642358, 4989325.234793 }, { 394234.438810, 4997123.381818 }, { 788456.442807, 5033847.161114 }, { 1182582.362270, 5095676.477878 }, { 1576380.787425, 5183546.587965 }, { 1969385.344968, 5298764.994976 }, { 2360791.676704, 5443001.292697 }, { 2749334.151719, 5618260.797473 }, { 3133139.791765, 5826829.612032 }, { 3509561.102920, 6071173.921846 }, { 3874997.468215, 6353771.575090 }, { 4224728.010175, 6676851.570206 }, { 4552797.983219, 7042021.264274 }, { -6210906.900160, 5455136.341724 }, { -5100884.293138, 4652262.781639 }, { -4009728.397901, 4101640.403114 }, { -2959830.261718, 3731566.523691 }, { -1949320.326404, 3494725.886266 }, { -967326.622891, 3362593.789817 }, { 0.000000, 3320113.397940 }, { 482739.761374, 3330662.065311 }, { 967326.622891, 3362593.789817 }, { 1455590.738883, 3416780.562222 }, { 1949320.326404, 3494725.886266 }, { 2450218.798188, 3598642.627884 }, { 2959830.261718, 3731566.523691 }, { 3479412.822009, 3897507.894394 }, { 4009728.397901, 4101640.403114 }, { 4550702.122779, 4350515.050072 }, { 5100884.293138, 4652262.781639 }, { 5656629.042264, 5016697.591669 }, { 5879057.348553, 5182521.093137 }, { 5990007.092138, 5270111.030646 }, { 6100658.157988, 5360950.158381 }, { 6128262.329125, 5384179.105403 }, { 6155839.688010, 5407618.771574 }, { 6183388.477643, 5431270.678047 }, { 6210906.900160, 5455136.341724 }, { -8423099.473515, 0.000000 }, { -7986550.230016, 0.000000 }, { -7574316.703085, 0.000000 }, { -7183343.494858, 0.000000 }, { -6811084.435548, 0.000000 }, { -6455393.148674, 0.000000 }, { -6114441.581589, 0.000000 }, { -5786658.285436, 0.000000 }, { -5470680.926552, 0.000000 }, { -5165319.237408, 0.000000 }, { -4869525.747989, 0.000000 }, { -4582372.398706, 0.000000 }, { -4303031.656552, 0.000000 }, { -4030761.119143, 0.000000 }, { -3764890.848480, 0.000000 }, { -3504812.861291, 0.000000 }, { -3249972.337647, 0.000000 }, { -2999860.209058, 0.000000 }, { -2754006.861562, 0.000000 }, { -2511976.745296, 0.000000 }, { -2273363.724682, 0.000000 }, { -2037787.036058, 0.000000 }, { -1804887.744877, 0.000000 }, { -1574325.614256, 0.000000 }, { -1345776.312061, 0.000000 }, { -1118928.895723, 0.000000 }, { -893483.523497, 0.000000 }, { -669149.348267, 0.000000 }, { -445642.555759, 0.000000 }, { -222684.513481, 0.000000 }, { 0.000000, 0.000000 }, { 222684.513481, 0.000000 }, { 445642.555759, 0.000000 }, { 669149.348267, 0.000000 }, { 893483.523497, 0.000000 }, { 1118928.895723, 0.000000 }, { 1345776.312061, 0.000000 }, { 1574325.614256, 0.000000 }, { 1804887.744877, 0.000000 }, { 2037787.036058, 0.000000 }, { 2273363.724682, 0.000000 }, { 2511976.745296, 0.000000 }, { 2754006.861562, 0.000000 }, { 2999860.209058, 0.000000 }, { 3249972.337647, 0.000000 }, { 3504812.861291, 0.000000 }, { 3764890.848480, 0.000000 }, { 4030761.119143, 0.000000 }, { 4303031.656552, 0.000000 }, { 4582372.398706, 0.000000 }, { 4869525.747989, 0.000000 }, { 5165319.237408, 0.000000 }, { 5470680.926552, 0.000000 }, { 5786658.285436, 0.000000 }, { 6114441.581589, 0.000000 }, { 6455393.148674, 0.000000 }, { 6811084.435548, 0.000000 }, { 7183343.494858, 0.000000 }, { 7574316.703085, 0.000000 }, { 7986550.230016, 0.000000 }, { 8423099.473515, 0.000000 }, { -2964227.090765, -8205251.234407 }, { -2782064.056031, -7957435.773324 }, { -2580653.930717, -7729962.209904 }, { -2362651.685233, -7523798.004299 }, { -2130566.804588, -7339517.432528 }, { -1886712.043039, -7177385.363796 }, { -1633178.735886, -7037439.986987 }, { -1371833.624649, -6919568.522094 }, { -1104331.837754, -6823572.599735 }, { -832141.189888, -6749222.012765 }, { -556573.889131, -6696296.869256 }, { -278822.758856, -6664618.888100 }, { 0.000000, -6654072.819491 }, { 278822.758856, -6664618.888100 }, { 556573.889131, -6696296.869256 }, { 832141.189888, -6749222.012765 }, { 1104331.837754, -6823572.599735 }, { 1371833.624649, -6919568.522094 }, { 1633178.735886, -7037439.986987 }, { 1886712.043039, -7177385.363796 }, { 2130566.804588, -7339517.432528 }, { 2362651.685233, -7523798.004299 }, { 2580653.930717, -7729962.209904 }, { 2782064.056031, -7957435.773324 }, { 2964227.090765, -8205251.234407 }, { -483943.527503, -9722205.338481 }, { -427895.580459, -9642462.065386 }, { -358888.675495, -9573715.084698 }, { -279050.262683, -9518022.200890 }, { -190817.262239, -9477033.459573 }, { -96859.156300, -9451952.297203 }, { 0.000000, -9443510.140666 }, { 96859.156300, -9451952.297203 }, { 190817.262239, -9477033.459573 }, { 279050.262683, -9518022.200890 }, { 358888.675495, -9573715.084698 }, { 427895.580459, -9642462.065386 }, { 483943.527503, -9722205.338481 }, { 0.000000, 9778578.687182 }, { 0.000000, 9555197.141480 }, { 0.000000, 9331826.561185 }, { 0.000000, 9108472.360519 }, { 0.000000, 8885139.871937 }, { 0.000000, 8661834.319555 }, { 0.000000, 8438560.793153 }, { 0.000000, 8215324.222895 }, { 0.000000, 7992129.354896 }, { 0.000000, 7768980.727770 }, { 0.000000, 7545882.650267 }, { 0.000000, 7322839.180123 }, { 0.000000, 7099854.104229 }, { 0.000000, 6876930.920205 }, { 0.000000, 6654072.819491 }, { 0.000000, 6431282.672002 }, { 0.000000, 6208563.012457 }, { 0.000000, 5985916.028402 }, { 0.000000, 5763343.550010 }, { 0.000000, 5540847.041684 }, { 0.000000, 5318427.595490 }, { 0.000000, 5096085.926452 }, { 0.000000, 4873822.369715 }, { 0.000000, 4651636.879571 }, { 0.000000, 4429529.030351 }, { 0.000000, 4207498.019154 }, { 0.000000, 3985542.670404 }, { 0.000000, 3763661.442172 }, { 0.000000, 3541852.434256 }, { 0.000000, 3320113.397940 }, { 0.000000, 3098441.747387 }, { 0.000000, 2876834.572604 }, { 0.000000, 2655288.653903 }, { 0.000000, 2433800.477786 }, { 0.000000, 2212366.254172 }, { 0.000000, 1990981.934878 }, { 0.000000, 1769643.233270 }, { 0.000000, 1548345.644978 }, { 0.000000, 1327084.469593 }, { 0.000000, 1105854.833234 }, { 0.000000, 884651.711881 }, { 0.000000, 663469.955375 }, { 0.000000, 442304.311978 }, { 0.000000, 221149.453372 }, { 0.000000, 0.000000 }, { 0.000000, -221149.453372 }, { 0.000000, -442304.311978 }, { 0.000000, -663469.955375 }, { 0.000000, -884651.711881 }, { 0.000000, -1105854.833234 }, { 193478.495744, 9890238.174368 }, { 387070.053266, 9778308.925410 }, { 580887.593439, 9665975.077520 }, { 775043.744138, 9553031.292767 }, { 969650.665433, 9439268.555628 }, { 1164819.839706, 9324472.894622 }, { 1360661.813189, 9208424.058689 }, { 1557285.873746, 9090894.136782 }, { 1754799.647559, 8971646.109077 }, { 1953308.594636, 8850432.318211 }, { 2152915.379650, 8726992.849240 }, { 2353719.090435, 8601053.807452 }, { 2555814.271380, 8472325.484149 }, { 2759289.732889, 8340500.402045 }, { 2964227.090765, 8205251.234407 }, { 3170698.980807, 8066228.595750 }, { 3378766.883776, 7923058.707330 }, { 3588478.484220, 7775340.948452 }, { 3799864.473255, 7622645.315506 }, { 4012934.690389, 7464509.825794 }, { 4227673.483131, 7300437.923867 }, { 4444034.145850, 7129895.976045 }, { 4661932.282425, 6952310.976086 }, { 4881237.922223, 6767068.634161 }, { 5101766.208947, 6573512.085289 }, { 5323266.481326, 6370941.535402 }, { 5545409.580258, 6158615.266273 }, { 5767773.258604, 5935752.547047 }, { 5989825.651007, 5701539.150389 }, { 6210906.900160, 5455136.341724 }, { 6430209.256248, 5195694.390171 }, { 6646756.295488, 4922371.817126 }, { 6859382.370663, 4634361.713402 }, { 7066714.034424, 4330926.453274 }, { 7267155.968366, 4011441.917637 }, { 7458884.868697, 3675451.778875 }, { 7639855.668495, 3322731.344695 }, { 7807825.189291, 2953358.766832 }, { 7960398.439614, 2567789.038934 }, { 8095101.814284, 2166923.285356 }, { 8209484.870500, 1752162.874899 }, { 8301247.860745, 1325435.816676 }, { 8368386.074076, 889182.995388 }, { 8409335.493936, 446295.299669 }, { 8423099.473515, 0.000000 }, { 8409335.493936, -446295.299669 }, { 8368386.074076, -889182.995388 }, { 8301247.860745, -1325435.816676 }, { 8209484.870500, -1752162.874899 }, { 8095101.814284, -2166923.285356 } }; - udGeoZone transMerc = { }; + udGeoZone transMerc = {}; transMerc.projection = udGZPT_TransverseMercator; transMerc.scaleFactor = 1; transMerc.meridian = 0; @@ -691,7 +688,7 @@ TEST(udGeoZone, GoldData63TransMerc26) udGeoZone_SetFromSRID(&transMerc, -1); const int64_t angularPrecision = 20 * 60 * 60; // 20 arc seconds - const int64_t localPrecision = 100; // 1cm + const int64_t localPrecision = 100; // 1cm for (size_t i = 0; i < UDARRAYSIZE(mercData); ++i) { @@ -708,9 +705,9 @@ TEST(udGeoZone, GoldData63TransMerc26) // TransMerc26A test in GoldData_v6.3 @ http://earth-info.nga.mil/GandG/coordsys/Conversion_Software/index.html TEST(udGeoZone, GoldData63TransMerc26A) { - udDouble2 mercData[] = { { -483943.527503, 11402091.940540 },{ -427895.580459, 11322348.667445 },{ -358888.675495, 11253601.686758 },{ -279050.262683, 11197908.802950 },{ -190817.262239, 11156920.061633 },{ -96859.156300, 11131838.899262 },{ 0.000000, 11123396.742726 },{ 96859.156300, 11131838.899262 },{ 190817.262239, 11156920.061633 },{ 279050.262683, 11197908.802950 },{ 358888.675495, 11253601.686758 },{ 427895.580459, 11322348.667445 },{ 483943.527503, 11402091.940540 },{ -1458869.311637, 10829745.418297 },{ -1285565.198612, 10590585.059326 },{ -1074419.247845, 10386558.973071 },{ -832650.960579, 10222980.939758 },{ -567859.299246, 10103672.213490 },{ -287748.836902, 10031149.410996 },{ 0.000000, 10006824.189340 },{ 287748.836902, 10031149.410996 },{ 567859.299246, 10103672.213490 },{ 832650.960579, 10222980.939758 },{ 1074419.247845, 10386558.973071 },{ 1285565.198612, 10590585.059326 },{ 1458869.311637, 10829745.418297 },{ -2964227.090765, 9885137.836467 },{ -2782064.056031, 9637322.375383 },{ -2580653.930717, 9409848.811963 },{ -2362651.685233, 9203684.606359 },{ -2130566.804588, 9019404.034588 },{ -1886712.043039, 8857271.965856 },{ -1633178.735886, 8717326.589046 },{ -1371833.624649, 8599455.124153 },{ -1104331.837754, 8503459.201795 },{ -832141.189888, 8429108.614825 },{ -556573.889131, 8376183.471316 },{ -278822.758856, 8344505.490160 },{ 0.000000, 8333959.421550 },{ 278822.758856, 8344505.490160 },{ 556573.889131, 8376183.471316 },{ 832141.189888, 8429108.614825 },{ 1104331.837754, 8503459.201795 },{ 1371833.624649, 8599455.124153 },{ 1633178.735886, 8717326.589046 },{ 1886712.043039, 8857271.965856 },{ 2130566.804588, 9019404.034588 },{ 2362651.685233, 9203684.606359 },{ 2580653.930717, 9409848.811963 },{ 2782064.056031, 9637322.375383 },{ 2964227.090765, 9885137.836467 },{ -4552797.983219, 8721907.866333 },{ -3874997.468215, 8033658.177150 },{ -3133139.791765, 7506716.214091 },{ -2360791.676704, 7122887.894757 },{ -1576380.787425, 6863433.190025 },{ -788456.442807, 6713733.763174 },{ 0.000000, 6664830.980037 },{ 9855.854400, 6664838.582197 },{ 19711.708879, 6664861.388751 },{ 39423.418384, 6664952.616058 },{ 78846.841653, 6665317.542785 },{ 157693.718217, 6666777.529702 },{ 236540.642358, 6669211.836852 },{ 394234.438810, 6677009.983878 },{ 788456.442807, 6713733.763174 },{ 1182582.362270, 6775563.079937 },{ 1576380.787425, 6863433.190025 },{ 1969385.344968, 6978651.597036 },{ 2360791.676704, 7122887.894757 },{ 2749334.151719, 7298147.399533 },{ 3133139.791765, 7506716.214091 },{ 3509561.102920, 7751060.523906 },{ 3874997.468215, 8033658.177150 },{ 4224728.010175, 8356738.172266 },{ 4552797.983219, 8721907.866333 },{ -6210906.900160, 7135022.943784 },{ -5100884.293138, 6332149.383699 },{ -4009728.397901, 5781527.005174 },{ -2959830.261718, 5411453.125751 },{ -1949320.326404, 5174612.488326 },{ -967326.622891, 5042480.391876 },{ 0.000000, 5000000.000000 },{ 482739.761374, 5010548.667371 },{ 967326.622891, 5042480.391876 },{ 1455590.738883, 5096667.164282 },{ 1949320.326404, 5174612.488326 },{ 2450218.798188, 5278529.229944 },{ 2959830.261718, 5411453.125751 },{ 3479412.822009, 5577394.496453 },{ 4009728.397901, 5781527.005174 },{ 4550702.122779, 6030401.652132 },{ 5100884.293138, 6332149.383699 },{ 5656629.042264, 6696584.193729 },{ 5879057.348553, 6862407.695196 },{ 5990007.092138, 6949997.632705 },{ 6100658.157988, 7040836.760440 },{ 6128262.329125, 7064065.707462 },{ 6155839.688010, 7087505.373633 },{ 6183388.477643, 7111157.280106 },{ 6210906.900160, 7135022.943784 },{ -8423099.473515, 1679886.602060 },{ -7986550.230016, 1679886.602060 },{ -7574316.703085, 1679886.602060 },{ -7183343.494858, 1679886.602060 },{ -6811084.435548, 1679886.602060 },{ -6455393.148674, 1679886.602060 },{ -6114441.581589, 1679886.602060 },{ -5786658.285436, 1679886.602060 },{ -5470680.926552, 1679886.602060 },{ -5165319.237408, 1679886.602060 },{ -4869525.747989, 1679886.602060 },{ -4582372.398706, 1679886.602060 },{ -4303031.656552, 1679886.602060 },{ -4030761.119143, 1679886.602060 },{ -3764890.848480, 1679886.602060 },{ -3504812.861291, 1679886.602060 },{ -3249972.337647, 1679886.602060 },{ -2999860.209058, 1679886.602060 },{ -2754006.861562, 1679886.602060 },{ -2511976.745296, 1679886.602060 },{ -2273363.724682, 1679886.602060 },{ -2037787.036058, 1679886.602060 },{ -1804887.744877, 1679886.602060 },{ -1574325.614256, 1679886.602060 },{ -1345776.312061, 1679886.602060 },{ -1118928.895723, 1679886.602060 },{ -893483.523497, 1679886.602060 },{ -669149.348267, 1679886.602060 },{ -445642.555759, 1679886.602060 },{ -222684.513481, 1679886.602060 },{ 0.000000, 1679886.602060 },{ 222684.513481, 1679886.602060 },{ 445642.555759, 1679886.602060 },{ 669149.348267, 1679886.602060 },{ 893483.523497, 1679886.602060 },{ 1118928.895723, 1679886.602060 },{ 1345776.312061, 1679886.602060 },{ 1574325.614256, 1679886.602060 },{ 1804887.744877, 1679886.602060 },{ 2037787.036058, 1679886.602060 },{ 2273363.724682, 1679886.602060 },{ 2511976.745296, 1679886.602060 },{ 2754006.861562, 1679886.602060 },{ 2999860.209058, 1679886.602060 },{ 3249972.337647, 1679886.602060 },{ 3504812.861291, 1679886.602060 },{ 3764890.848480, 1679886.602060 },{ 4030761.119143, 1679886.602060 },{ 4303031.656552, 1679886.602060 },{ 4582372.398706, 1679886.602060 },{ 4869525.747989, 1679886.602060 },{ 5165319.237408, 1679886.602060 },{ 5470680.926552, 1679886.602060 },{ 5786658.285436, 1679886.602060 },{ 6114441.581589, 1679886.602060 },{ 6455393.148674, 1679886.602060 },{ 6811084.435548, 1679886.602060 },{ 7183343.494858, 1679886.602060 },{ 7574316.703085, 1679886.602060 },{ 7986550.230016, 1679886.602060 },{ 8423099.473515, 1679886.602060 },{ -2964227.090765, -6525364.632348 },{ -2782064.056031, -6277549.171264 },{ -2580653.930717, -6050075.607844 },{ -2362651.685233, -5843911.402239 },{ -2130566.804588, -5659630.830469 },{ -1886712.043039, -5497498.761737 },{ -1633178.735886, -5357553.384927 },{ -1371833.624649, -5239681.920034 },{ -1104331.837754, -5143685.997676 },{ -832141.189888, -5069335.410705 },{ -556573.889131, -5016410.267197 },{ -278822.758856, -4984732.286041 },{ 0.000000, -4974186.217431 },{ 278822.758856, -4984732.286041 },{ 556573.889131, -5016410.267197 },{ 832141.189888, -5069335.410705 },{ 1104331.837754, -5143685.997676 },{ 1371833.624649, -5239681.920034 },{ 1633178.735886, -5357553.384927 },{ 1886712.043039, -5497498.761737 },{ 2130566.804588, -5659630.830469 },{ 2362651.685233, -5843911.402239 },{ 2580653.930717, -6050075.607844 },{ 2782064.056031, -6277549.171264 },{ 2964227.090765, -6525364.632348 },{ -483943.527503, -8042318.736421 },{ -427895.580459, -7962575.463326 },{ -358888.675495, -7893828.482639 },{ -279050.262683, -7838135.598831 },{ -190817.262239, -7797146.857514 },{ -96859.156300, -7772065.695143 },{ 0.000000, -7763623.538607 },{ 96859.156300, -7772065.695143 },{ 190817.262239, -7797146.857514 },{ 279050.262683, -7838135.598831 },{ 358888.675495, -7893828.482639 },{ 427895.580459, -7962575.463326 },{ 483943.527503, -8042318.736421 },{ 0.000000, 11458465.289242 },{ 0.000000, 11235083.743540 },{ 0.000000, 11011713.163245 },{ 0.000000, 10788358.962578 },{ 0.000000, 10565026.473996 },{ 0.000000, 10341720.921615 },{ 0.000000, 10118447.395213 },{ 0.000000, 9895210.824954 },{ 0.000000, 9672015.956956 },{ 0.000000, 9448867.329830 },{ 0.000000, 9225769.252327 },{ 0.000000, 9002725.782183 },{ 0.000000, 8779740.706288 },{ 0.000000, 8556817.522265 },{ 0.000000, 8333959.421550 },{ 0.000000, 8111169.274062 },{ 0.000000, 7888449.614517 },{ 0.000000, 7665802.630462 },{ 0.000000, 7443230.152070 },{ 0.000000, 7220733.643744 },{ 0.000000, 6998314.197549 },{ 0.000000, 6775972.528512 },{ 0.000000, 6553708.971775 },{ 0.000000, 6331523.481631 },{ 0.000000, 6109415.632410 },{ 0.000000, 5887384.621214 },{ 0.000000, 5665429.272463 },{ 0.000000, 5443548.044232 },{ 0.000000, 5221739.036316 },{ 0.000000, 5000000.000000 },{ 0.000000, 4778328.349447 },{ 0.000000, 4556721.174664 },{ 0.000000, 4335175.255962 },{ 0.000000, 4113687.079845 },{ 0.000000, 3892252.856231 },{ 0.000000, 3670868.536938 },{ 0.000000, 3449529.835329 },{ 0.000000, 3228232.247037 },{ 0.000000, 3006971.071653 },{ 0.000000, 2785741.435294 },{ 0.000000, 2564538.313940 },{ 0.000000, 2343356.557434 },{ 0.000000, 2122190.914038 },{ 0.000000, 1901036.055432 },{ 0.000000, 1679886.602060 },{ 0.000000, 1458737.148687 },{ 0.000000, 1237582.290082 },{ 0.000000, 1016416.646685 },{ 0.000000, 795234.890179 },{ 0.000000, 574031.768825 },{ 193478.495744, 11570124.776428 },{ 387070.053266, 11458195.527469 },{ 580887.593439, 11345861.679580 },{ 775043.744138, 11232917.894826 },{ 969650.665433, 11119155.157688 },{ 1164819.839706, 11004359.496682 },{ 1360661.813189, 10888310.660748 },{ 1557285.873746, 10770780.738842 },{ 1754799.647559, 10651532.711137 },{ 1953308.594636, 10530318.920271 },{ 2152915.379650, 10406879.451300 },{ 2353719.090435, 10280940.409512 },{ 2555814.271380, 10152212.086208 },{ 2759289.732889, 10020387.004105 },{ 2964227.090765, 9885137.836467 },{ 3170698.980807, 9746115.197810 },{ 3378766.883776, 9602945.309390 },{ 3588478.484220, 9455227.550511 },{ 3799864.473255, 9302531.917566 },{ 4012934.690389, 9144396.427854 },{ 4227673.483131, 8980324.525927 },{ 4444034.145850, 8809782.578104 },{ 4661932.282425, 8632197.578145 },{ 4881237.922223, 8446955.236220 },{ 5101766.208947, 8253398.687349 },{ 5323266.481326, 8050828.137462 },{ 5545409.580258, 7838501.868332 },{ 5767773.258604, 7615639.149107 },{ 5989825.651007, 7381425.752448 },{ 6210906.900160, 7135022.943784 },{ 6430209.256248, 6875580.992230 },{ 6646756.295488, 6602258.419186 },{ 6859382.370663, 6314248.315462 },{ 7066714.034424, 6010813.055334 },{ 7267155.968366, 5691328.519696 },{ 7458884.868697, 5355338.380934 },{ 7639855.668495, 5002617.946754 },{ 7807825.189291, 4633245.368891 },{ 7960398.439614, 4247675.640994 },{ 8095101.814284, 3846809.887415 },{ 8209484.870500, 3432049.476958 },{ 8301247.860745, 3005322.418736 },{ 8368386.074076, 2569069.597447 },{ 8409335.493936, 2126181.901729 },{ 8423099.473515, 1679886.602060 },{ 8409335.493936, 1233591.302390 },{ 8368386.074076, 790703.606672 },{ 8301247.860745, 354450.785383 },{ 8209484.870500, -72276.272839 },{ 8095101.814284, -487036.683296 } }; + udDouble2 mercData[] = { { -483943.527503, 11402091.940540 }, { -427895.580459, 11322348.667445 }, { -358888.675495, 11253601.686758 }, { -279050.262683, 11197908.802950 }, { -190817.262239, 11156920.061633 }, { -96859.156300, 11131838.899262 }, { 0.000000, 11123396.742726 }, { 96859.156300, 11131838.899262 }, { 190817.262239, 11156920.061633 }, { 279050.262683, 11197908.802950 }, { 358888.675495, 11253601.686758 }, { 427895.580459, 11322348.667445 }, { 483943.527503, 11402091.940540 }, { -1458869.311637, 10829745.418297 }, { -1285565.198612, 10590585.059326 }, { -1074419.247845, 10386558.973071 }, { -832650.960579, 10222980.939758 }, { -567859.299246, 10103672.213490 }, { -287748.836902, 10031149.410996 }, { 0.000000, 10006824.189340 }, { 287748.836902, 10031149.410996 }, { 567859.299246, 10103672.213490 }, { 832650.960579, 10222980.939758 }, { 1074419.247845, 10386558.973071 }, { 1285565.198612, 10590585.059326 }, { 1458869.311637, 10829745.418297 }, { -2964227.090765, 9885137.836467 }, { -2782064.056031, 9637322.375383 }, { -2580653.930717, 9409848.811963 }, { -2362651.685233, 9203684.606359 }, { -2130566.804588, 9019404.034588 }, { -1886712.043039, 8857271.965856 }, { -1633178.735886, 8717326.589046 }, { -1371833.624649, 8599455.124153 }, { -1104331.837754, 8503459.201795 }, { -832141.189888, 8429108.614825 }, { -556573.889131, 8376183.471316 }, { -278822.758856, 8344505.490160 }, { 0.000000, 8333959.421550 }, { 278822.758856, 8344505.490160 }, { 556573.889131, 8376183.471316 }, { 832141.189888, 8429108.614825 }, { 1104331.837754, 8503459.201795 }, { 1371833.624649, 8599455.124153 }, { 1633178.735886, 8717326.589046 }, { 1886712.043039, 8857271.965856 }, { 2130566.804588, 9019404.034588 }, { 2362651.685233, 9203684.606359 }, { 2580653.930717, 9409848.811963 }, { 2782064.056031, 9637322.375383 }, { 2964227.090765, 9885137.836467 }, { -4552797.983219, 8721907.866333 }, { -3874997.468215, 8033658.177150 }, { -3133139.791765, 7506716.214091 }, { -2360791.676704, 7122887.894757 }, { -1576380.787425, 6863433.190025 }, { -788456.442807, 6713733.763174 }, { 0.000000, 6664830.980037 }, { 9855.854400, 6664838.582197 }, { 19711.708879, 6664861.388751 }, { 39423.418384, 6664952.616058 }, { 78846.841653, 6665317.542785 }, { 157693.718217, 6666777.529702 }, { 236540.642358, 6669211.836852 }, { 394234.438810, 6677009.983878 }, { 788456.442807, 6713733.763174 }, { 1182582.362270, 6775563.079937 }, { 1576380.787425, 6863433.190025 }, { 1969385.344968, 6978651.597036 }, { 2360791.676704, 7122887.894757 }, { 2749334.151719, 7298147.399533 }, { 3133139.791765, 7506716.214091 }, { 3509561.102920, 7751060.523906 }, { 3874997.468215, 8033658.177150 }, { 4224728.010175, 8356738.172266 }, { 4552797.983219, 8721907.866333 }, { -6210906.900160, 7135022.943784 }, { -5100884.293138, 6332149.383699 }, { -4009728.397901, 5781527.005174 }, { -2959830.261718, 5411453.125751 }, { -1949320.326404, 5174612.488326 }, { -967326.622891, 5042480.391876 }, { 0.000000, 5000000.000000 }, { 482739.761374, 5010548.667371 }, { 967326.622891, 5042480.391876 }, { 1455590.738883, 5096667.164282 }, { 1949320.326404, 5174612.488326 }, { 2450218.798188, 5278529.229944 }, { 2959830.261718, 5411453.125751 }, { 3479412.822009, 5577394.496453 }, { 4009728.397901, 5781527.005174 }, { 4550702.122779, 6030401.652132 }, { 5100884.293138, 6332149.383699 }, { 5656629.042264, 6696584.193729 }, { 5879057.348553, 6862407.695196 }, { 5990007.092138, 6949997.632705 }, { 6100658.157988, 7040836.760440 }, { 6128262.329125, 7064065.707462 }, { 6155839.688010, 7087505.373633 }, { 6183388.477643, 7111157.280106 }, { 6210906.900160, 7135022.943784 }, { -8423099.473515, 1679886.602060 }, { -7986550.230016, 1679886.602060 }, { -7574316.703085, 1679886.602060 }, { -7183343.494858, 1679886.602060 }, { -6811084.435548, 1679886.602060 }, { -6455393.148674, 1679886.602060 }, { -6114441.581589, 1679886.602060 }, { -5786658.285436, 1679886.602060 }, { -5470680.926552, 1679886.602060 }, { -5165319.237408, 1679886.602060 }, { -4869525.747989, 1679886.602060 }, { -4582372.398706, 1679886.602060 }, { -4303031.656552, 1679886.602060 }, { -4030761.119143, 1679886.602060 }, { -3764890.848480, 1679886.602060 }, { -3504812.861291, 1679886.602060 }, { -3249972.337647, 1679886.602060 }, { -2999860.209058, 1679886.602060 }, { -2754006.861562, 1679886.602060 }, { -2511976.745296, 1679886.602060 }, { -2273363.724682, 1679886.602060 }, { -2037787.036058, 1679886.602060 }, { -1804887.744877, 1679886.602060 }, { -1574325.614256, 1679886.602060 }, { -1345776.312061, 1679886.602060 }, { -1118928.895723, 1679886.602060 }, { -893483.523497, 1679886.602060 }, { -669149.348267, 1679886.602060 }, { -445642.555759, 1679886.602060 }, { -222684.513481, 1679886.602060 }, { 0.000000, 1679886.602060 }, { 222684.513481, 1679886.602060 }, { 445642.555759, 1679886.602060 }, { 669149.348267, 1679886.602060 }, { 893483.523497, 1679886.602060 }, { 1118928.895723, 1679886.602060 }, { 1345776.312061, 1679886.602060 }, { 1574325.614256, 1679886.602060 }, { 1804887.744877, 1679886.602060 }, { 2037787.036058, 1679886.602060 }, { 2273363.724682, 1679886.602060 }, { 2511976.745296, 1679886.602060 }, { 2754006.861562, 1679886.602060 }, { 2999860.209058, 1679886.602060 }, { 3249972.337647, 1679886.602060 }, { 3504812.861291, 1679886.602060 }, { 3764890.848480, 1679886.602060 }, { 4030761.119143, 1679886.602060 }, { 4303031.656552, 1679886.602060 }, { 4582372.398706, 1679886.602060 }, { 4869525.747989, 1679886.602060 }, { 5165319.237408, 1679886.602060 }, { 5470680.926552, 1679886.602060 }, { 5786658.285436, 1679886.602060 }, { 6114441.581589, 1679886.602060 }, { 6455393.148674, 1679886.602060 }, { 6811084.435548, 1679886.602060 }, { 7183343.494858, 1679886.602060 }, { 7574316.703085, 1679886.602060 }, { 7986550.230016, 1679886.602060 }, { 8423099.473515, 1679886.602060 }, { -2964227.090765, -6525364.632348 }, { -2782064.056031, -6277549.171264 }, { -2580653.930717, -6050075.607844 }, { -2362651.685233, -5843911.402239 }, { -2130566.804588, -5659630.830469 }, { -1886712.043039, -5497498.761737 }, { -1633178.735886, -5357553.384927 }, { -1371833.624649, -5239681.920034 }, { -1104331.837754, -5143685.997676 }, { -832141.189888, -5069335.410705 }, { -556573.889131, -5016410.267197 }, { -278822.758856, -4984732.286041 }, { 0.000000, -4974186.217431 }, { 278822.758856, -4984732.286041 }, { 556573.889131, -5016410.267197 }, { 832141.189888, -5069335.410705 }, { 1104331.837754, -5143685.997676 }, { 1371833.624649, -5239681.920034 }, { 1633178.735886, -5357553.384927 }, { 1886712.043039, -5497498.761737 }, { 2130566.804588, -5659630.830469 }, { 2362651.685233, -5843911.402239 }, { 2580653.930717, -6050075.607844 }, { 2782064.056031, -6277549.171264 }, { 2964227.090765, -6525364.632348 }, { -483943.527503, -8042318.736421 }, { -427895.580459, -7962575.463326 }, { -358888.675495, -7893828.482639 }, { -279050.262683, -7838135.598831 }, { -190817.262239, -7797146.857514 }, { -96859.156300, -7772065.695143 }, { 0.000000, -7763623.538607 }, { 96859.156300, -7772065.695143 }, { 190817.262239, -7797146.857514 }, { 279050.262683, -7838135.598831 }, { 358888.675495, -7893828.482639 }, { 427895.580459, -7962575.463326 }, { 483943.527503, -8042318.736421 }, { 0.000000, 11458465.289242 }, { 0.000000, 11235083.743540 }, { 0.000000, 11011713.163245 }, { 0.000000, 10788358.962578 }, { 0.000000, 10565026.473996 }, { 0.000000, 10341720.921615 }, { 0.000000, 10118447.395213 }, { 0.000000, 9895210.824954 }, { 0.000000, 9672015.956956 }, { 0.000000, 9448867.329830 }, { 0.000000, 9225769.252327 }, { 0.000000, 9002725.782183 }, { 0.000000, 8779740.706288 }, { 0.000000, 8556817.522265 }, { 0.000000, 8333959.421550 }, { 0.000000, 8111169.274062 }, { 0.000000, 7888449.614517 }, { 0.000000, 7665802.630462 }, { 0.000000, 7443230.152070 }, { 0.000000, 7220733.643744 }, { 0.000000, 6998314.197549 }, { 0.000000, 6775972.528512 }, { 0.000000, 6553708.971775 }, { 0.000000, 6331523.481631 }, { 0.000000, 6109415.632410 }, { 0.000000, 5887384.621214 }, { 0.000000, 5665429.272463 }, { 0.000000, 5443548.044232 }, { 0.000000, 5221739.036316 }, { 0.000000, 5000000.000000 }, { 0.000000, 4778328.349447 }, { 0.000000, 4556721.174664 }, { 0.000000, 4335175.255962 }, { 0.000000, 4113687.079845 }, { 0.000000, 3892252.856231 }, { 0.000000, 3670868.536938 }, { 0.000000, 3449529.835329 }, { 0.000000, 3228232.247037 }, { 0.000000, 3006971.071653 }, { 0.000000, 2785741.435294 }, { 0.000000, 2564538.313940 }, { 0.000000, 2343356.557434 }, { 0.000000, 2122190.914038 }, { 0.000000, 1901036.055432 }, { 0.000000, 1679886.602060 }, { 0.000000, 1458737.148687 }, { 0.000000, 1237582.290082 }, { 0.000000, 1016416.646685 }, { 0.000000, 795234.890179 }, { 0.000000, 574031.768825 }, { 193478.495744, 11570124.776428 }, { 387070.053266, 11458195.527469 }, { 580887.593439, 11345861.679580 }, { 775043.744138, 11232917.894826 }, { 969650.665433, 11119155.157688 }, { 1164819.839706, 11004359.496682 }, { 1360661.813189, 10888310.660748 }, { 1557285.873746, 10770780.738842 }, { 1754799.647559, 10651532.711137 }, { 1953308.594636, 10530318.920271 }, { 2152915.379650, 10406879.451300 }, { 2353719.090435, 10280940.409512 }, { 2555814.271380, 10152212.086208 }, { 2759289.732889, 10020387.004105 }, { 2964227.090765, 9885137.836467 }, { 3170698.980807, 9746115.197810 }, { 3378766.883776, 9602945.309390 }, { 3588478.484220, 9455227.550511 }, { 3799864.473255, 9302531.917566 }, { 4012934.690389, 9144396.427854 }, { 4227673.483131, 8980324.525927 }, { 4444034.145850, 8809782.578104 }, { 4661932.282425, 8632197.578145 }, { 4881237.922223, 8446955.236220 }, { 5101766.208947, 8253398.687349 }, { 5323266.481326, 8050828.137462 }, { 5545409.580258, 7838501.868332 }, { 5767773.258604, 7615639.149107 }, { 5989825.651007, 7381425.752448 }, { 6210906.900160, 7135022.943784 }, { 6430209.256248, 6875580.992230 }, { 6646756.295488, 6602258.419186 }, { 6859382.370663, 6314248.315462 }, { 7066714.034424, 6010813.055334 }, { 7267155.968366, 5691328.519696 }, { 7458884.868697, 5355338.380934 }, { 7639855.668495, 5002617.946754 }, { 7807825.189291, 4633245.368891 }, { 7960398.439614, 4247675.640994 }, { 8095101.814284, 3846809.887415 }, { 8209484.870500, 3432049.476958 }, { 8301247.860745, 3005322.418736 }, { 8368386.074076, 2569069.597447 }, { 8409335.493936, 2126181.901729 }, { 8423099.473515, 1679886.602060 }, { 8409335.493936, 1233591.302390 }, { 8368386.074076, 790703.606672 }, { 8301247.860745, 354450.785383 }, { 8209484.870500, -72276.272839 }, { 8095101.814284, -487036.683296 } }; - udGeoZone transMerc = { }; + udGeoZone transMerc = {}; transMerc.projection = udGZPT_TransverseMercator; transMerc.scaleFactor = 1; transMerc.meridian = 0; @@ -722,7 +719,7 @@ TEST(udGeoZone, GoldData63TransMerc26A) udGeoZone_SetFromSRID(&transMerc, -1); const int64_t angularPrecision = 20 * 60 * 60; // 20 arc seconds - const int64_t localPrecision = 100; // 1cm + const int64_t localPrecision = 100; // 1cm for (size_t i = 0; i < UDARRAYSIZE(mercData); ++i) { @@ -740,14 +737,13 @@ struct { int srid; const char *pWKT; -} supportedCodes[] = -{ +} supportedCodes[] = { // This is the non-official CRS84 zone which does NOT have an official WKT implementation; This should be able to be handled by other systems but ISO6709 makes this entire thing invalid { 84, "GEOGCS[\"WGS 84\",\nDATUM[\"WGS_1984\",\nSPHEROID[\"WGS 84\",6378137,298.257223563,\nAUTHORITY[\"EPSG\",\"7030\"]],\nAUTHORITY[\"EPSG\",\"6326\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAXIS[\"Lon\",X],\nAXIS[\"Lat\",Y],\nAUTHORITY[\"CRS\",\"84\"]]" }, { 2154, "PROJCS[\"RGF93 / Lambert-93\",\nGEOGCS[\"RGF93\",\nDATUM[\"Reseau_Geodesique_Francais_1993\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6171\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4171\"]],\nPROJECTION[\"Lambert_Conformal_Conic_2SP\"],\nPARAMETER[\"standard_parallel_1\",49],\nPARAMETER[\"standard_parallel_2\",44],\nPARAMETER[\"latitude_of_origin\",46.5],\nPARAMETER[\"central_meridian\",3],\nPARAMETER[\"false_easting\",700000],\nPARAMETER[\"false_northing\",6600000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"X\",EAST],\nAXIS[\"Y\",NORTH],\nAUTHORITY[\"EPSG\",\"2154\"]]" }, - { 2193, "PROJCS[\"NZGD2000 / New Zealand Transverse Mercator 2000\",\nGEOGCS[\"NZGD2000\",\nDATUM[\"New_Zealand_Geodetic_Datum_2000\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6167\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4167\"]],\nPROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",0],\nPARAMETER[\"central_meridian\",173],\nPARAMETER[\"scale_factor\",0.9996],\nPARAMETER[\"false_easting\",1600000],\nPARAMETER[\"false_northing\",10000000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"2193\"]]"}, + { 2193, "PROJCS[\"NZGD2000 / New Zealand Transverse Mercator 2000\",\nGEOGCS[\"NZGD2000\",\nDATUM[\"New_Zealand_Geodetic_Datum_2000\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6167\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4167\"]],\nPROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",0],\nPARAMETER[\"central_meridian\",173],\nPARAMETER[\"scale_factor\",0.9996],\nPARAMETER[\"false_easting\",1600000],\nPARAMETER[\"false_northing\",10000000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"2193\"]]" }, // WKT taken from PostgreSQL, with random sample cross referenced with epsg.io { 2230, "PROJCS[\"NAD83 / California zone 6 (ftUS)\",\nGEOGCS[\"NAD83\",\nDATUM[\"North_American_Datum_1983\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6269\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4269\"]],\nPROJECTION[\"Lambert_Conformal_Conic_2SP\"],\nPARAMETER[\"standard_parallel_1\",33.88333333333333],\nPARAMETER[\"standard_parallel_2\",32.78333333333333],\nPARAMETER[\"latitude_of_origin\",32.16666666666666],\nPARAMETER[\"central_meridian\",-116.25],\nPARAMETER[\"false_easting\",6561666.667],\nPARAMETER[\"false_northing\",1640416.667],\nUNIT[\"US survey foot\",0.3048006096012192,\nAUTHORITY[\"EPSG\",\"9003\"]],\nAXIS[\"X\",EAST],\nAXIS[\"Y\",NORTH],\nAUTHORITY[\"EPSG\",\"2230\"]]" }, @@ -780,14 +776,14 @@ struct { 2771, "PROJCS[\"NAD83(HARN) / California zone 6\",\nGEOGCS[\"NAD83(HARN)\",\nDATUM[\"NAD83_High_Accuracy_Reference_Network\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6152\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4152\"]],\nPROJECTION[\"Lambert_Conformal_Conic_2SP\"],\nPARAMETER[\"standard_parallel_1\",33.88333333333333],\nPARAMETER[\"standard_parallel_2\",32.78333333333333],\nPARAMETER[\"latitude_of_origin\",32.16666666666666],\nPARAMETER[\"central_meridian\",-116.25],\nPARAMETER[\"false_easting\",2000000],\nPARAMETER[\"false_northing\",500000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"X\",EAST],\nAXIS[\"Y\",NORTH],\nAUTHORITY[\"EPSG\",\"2771\"]]" }, - { 3032, "PROJCS[\"WGS 84 / Australian Antarctic Polar Stereographic\",\nGEOGCS[\"WGS 84\",\nDATUM[\"WGS_1984\",\nSPHEROID[\"WGS 84\",6378137,298.257223563,\nAUTHORITY[\"EPSG\",\"7030\"]],\nAUTHORITY[\"EPSG\",\"6326\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4326\"]],\nPROJECTION[\"Polar_Stereographic\"],\nPARAMETER[\"latitude_of_origin\",-71],\nPARAMETER[\"central_meridian\",70],\nPARAMETER[\"scale_factor\",1],\nPARAMETER[\"false_easting\",6000000],\nPARAMETER[\"false_northing\",6000000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"3032\"]]"}, + { 3032, "PROJCS[\"WGS 84 / Australian Antarctic Polar Stereographic\",\nGEOGCS[\"WGS 84\",\nDATUM[\"WGS_1984\",\nSPHEROID[\"WGS 84\",6378137,298.257223563,\nAUTHORITY[\"EPSG\",\"7030\"]],\nAUTHORITY[\"EPSG\",\"6326\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4326\"]],\nPROJECTION[\"Polar_Stereographic\"],\nPARAMETER[\"latitude_of_origin\",-71],\nPARAMETER[\"central_meridian\",70],\nPARAMETER[\"scale_factor\",1],\nPARAMETER[\"false_easting\",6000000],\nPARAMETER[\"false_northing\",6000000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"3032\"]]" }, { 3112, "PROJCS[\"GDA94 / Geoscience Australia Lambert\",\nGEOGCS[\"GDA94\",\nDATUM[\"Geocentric_Datum_of_Australia_1994\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6283\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4283\"]],\nPROJECTION[\"Lambert_Conformal_Conic_2SP\"],\nPARAMETER[\"standard_parallel_1\",-18],\nPARAMETER[\"standard_parallel_2\",-36],\nPARAMETER[\"latitude_of_origin\",0],\nPARAMETER[\"central_meridian\",134],\nPARAMETER[\"false_easting\",0],\nPARAMETER[\"false_northing\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Easting\",EAST],\nAXIS[\"Northing\",NORTH],\nAUTHORITY[\"EPSG\",\"3112\"]]" }, { 3113, "PROJCS[\"GDA94 / BCSG02\",\nGEOGCS[\"GDA94\",\nDATUM[\"Geocentric_Datum_of_Australia_1994\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6283\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4283\"]],\nPROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",-28],\nPARAMETER[\"central_meridian\",153],\nPARAMETER[\"scale_factor\",0.99999],\nPARAMETER[\"false_easting\",50000],\nPARAMETER[\"false_northing\",100000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Easting\",EAST],\nAXIS[\"Northing\",NORTH],\nAUTHORITY[\"EPSG\",\"3113\"]]" }, { 3139, "PROJCS[\"Vanua_Levu_1915 / Vanua Levu 1915\",\nGEOGCS[\"Vanua Levu 1915\",\nDATUM[\"Vanua_Levu_1915\",\nSPHEROID[\"Clarke 1880 (international foot)\",6378306.369,293.466307656,\nAUTHORITY[\"EPSG\",\"7055\"]],\nTOWGS84[51,391,-36,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6748\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4748\"]],\nPROJECTION[\"Hyperbolic_Cassini_Soldner\"],\nPARAMETER[\"latitude_of_origin\",-16.25],\nPARAMETER[\"central_meridian\",179.3333333333333],\nPARAMETER[\"scale_factor\",1],\nPARAMETER[\"false_easting\",1251331.8],\nPARAMETER[\"false_northing\",1662888.5],\nUNIT[\"link\",0.201168,\nAUTHORITY[\"EPSG\",\"9098\"]],\nAUTHORITY[\"EPSG\",\"3139\"]]" }, - { 3174, "PROJCS[\"NAD83 / Great Lakes Albers\",\nGEOGCS[\"NAD83\",\nDATUM[\"North_American_Datum_1983\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6269\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4269\"]],\nPROJECTION[\"Albers_Conic_Equal_Area\"],\nPARAMETER[\"latitude_of_center\",45.568977],\nPARAMETER[\"longitude_of_center\",-84.455955],\nPARAMETER[\"standard_parallel_1\",42.122774],\nPARAMETER[\"standard_parallel_2\",49.01518],\nPARAMETER[\"false_easting\",1000000],\nPARAMETER[\"false_northing\",1000000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"3174\"]]"}, + { 3174, "PROJCS[\"NAD83 / Great Lakes Albers\",\nGEOGCS[\"NAD83\",\nDATUM[\"North_American_Datum_1983\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6269\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4269\"]],\nPROJECTION[\"Albers_Conic_Equal_Area\"],\nPARAMETER[\"latitude_of_center\",45.568977],\nPARAMETER[\"longitude_of_center\",-84.455955],\nPARAMETER[\"standard_parallel_1\",42.122774],\nPARAMETER[\"standard_parallel_2\",49.01518],\nPARAMETER[\"false_easting\",1000000],\nPARAMETER[\"false_northing\",1000000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"3174\"]]" }, { 3414, "PROJCS[\"SVY21 / Singapore TM\",\nGEOGCS[\"SVY21\",\nDATUM[\"SVY21\",\nSPHEROID[\"WGS 84\",6378137,298.257223563,\nAUTHORITY[\"EPSG\",\"7030\"]],\nAUTHORITY[\"EPSG\",\"6757\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4757\"]],\nPROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",1.366666666666667],\nPARAMETER[\"central_meridian\",103.8333333333333],\nPARAMETER[\"scale_factor\",1],\nPARAMETER[\"false_easting\",28001.642],\nPARAMETER[\"false_northing\",38744.572],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"3414\"]]" }, @@ -809,7 +805,7 @@ struct { 4326, "GEOGCS[\"WGS 84\",\nDATUM[\"WGS_1984\",\nSPHEROID[\"WGS 84\",6378137,298.257223563,\nAUTHORITY[\"EPSG\",\"7030\"]],\nAUTHORITY[\"EPSG\",\"6326\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4326\"]]" }, { 4328, "GEOCCS[\"WGS 84\",\nDATUM[\"WGS_1984\",\nSPHEROID[\"WGS 84\",6378137,298.257223563,\nAUTHORITY[\"EPSG\",\"7030\"]],\nAUTHORITY[\"EPSG\",\"6326\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Geocentric X\",OTHER],\nAXIS[\"Geocentric Y\",OTHER],\nAXIS[\"Geocentric Z\",NORTH],\nAUTHORITY[\"EPSG\",\"4328\"]]" }, - + { 4534, "PROJCS[\"CGCS2000 / 3-degree Gauss-Kruger CM 75E\",\nGEOGCS[\"China Geodetic Coordinate System 2000\",\nDATUM[\"China_2000\",\nSPHEROID[\"CGCS2000\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"1024\"]],\nAUTHORITY[\"EPSG\",\"1043\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4490\"]],\nPROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",0],\nPARAMETER[\"central_meridian\",75],\nPARAMETER[\"scale_factor\",1],\nPARAMETER[\"false_easting\",500000],\nPARAMETER[\"false_northing\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"4534\"]]" }, { 4535, "PROJCS[\"CGCS2000 / 3-degree Gauss-Kruger CM 78E\",\nGEOGCS[\"China Geodetic Coordinate System 2000\",\nDATUM[\"China_2000\",\nSPHEROID[\"CGCS2000\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"1024\"]],\nAUTHORITY[\"EPSG\",\"1043\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4490\"]],\nPROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",0],\nPARAMETER[\"central_meridian\",78],\nPARAMETER[\"scale_factor\",1],\nPARAMETER[\"false_easting\",500000],\nPARAMETER[\"false_northing\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"4535\"]]" }, { 4536, "PROJCS[\"CGCS2000 / 3-degree Gauss-Kruger CM 81E\",\nGEOGCS[\"China Geodetic Coordinate System 2000\",\nDATUM[\"China_2000\",\nSPHEROID[\"CGCS2000\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"1024\"]],\nAUTHORITY[\"EPSG\",\"1043\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4490\"]],\nPROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",0],\nPARAMETER[\"central_meridian\",81],\nPARAMETER[\"scale_factor\",1],\nPARAMETER[\"false_easting\",500000],\nPARAMETER[\"false_northing\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"4536\"]]" }, @@ -832,7 +828,7 @@ struct { 4553, "PROJCS[\"CGCS2000 / 3-degree Gauss-Kruger CM 132E\",\nGEOGCS[\"China Geodetic Coordinate System 2000\",\nDATUM[\"China_2000\",\nSPHEROID[\"CGCS2000\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"1024\"]],\nAUTHORITY[\"EPSG\",\"1043\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4490\"]],\nPROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",0],\nPARAMETER[\"central_meridian\",132],\nPARAMETER[\"scale_factor\",1],\nPARAMETER[\"false_easting\",500000],\nPARAMETER[\"false_northing\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"4553\"]]" }, { 4554, "PROJCS[\"CGCS2000 / 3-degree Gauss-Kruger CM 135E\",\nGEOGCS[\"China Geodetic Coordinate System 2000\",\nDATUM[\"China_2000\",\nSPHEROID[\"CGCS2000\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"1024\"]],\nAUTHORITY[\"EPSG\",\"1043\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4490\"]],\nPROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",0],\nPARAMETER[\"central_meridian\",135],\nPARAMETER[\"scale_factor\",1],\nPARAMETER[\"false_easting\",500000],\nPARAMETER[\"false_northing\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"4554\"]]" }, - { 4936, "GEOCCS[\"ETRS89\",\nDATUM[\"European_Terrestrial_Reference_System_1989\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6258\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Geocentric X\",OTHER],\nAXIS[\"Geocentric Y\",OTHER],\nAXIS[\"Geocentric Z\",NORTH],\nAUTHORITY[\"EPSG\",\"4936\"]]"}, + { 4936, "GEOCCS[\"ETRS89\",\nDATUM[\"European_Terrestrial_Reference_System_1989\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6258\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Geocentric X\",OTHER],\nAXIS[\"Geocentric Y\",OTHER],\nAXIS[\"Geocentric Z\",NORTH],\nAUTHORITY[\"EPSG\",\"4936\"]]" }, { 4978, "GEOCCS[\"WGS 84\",\nDATUM[\"WGS_1984\",\nSPHEROID[\"WGS 84\",6378137,298.257223563,\nAUTHORITY[\"EPSG\",\"7030\"]],\nAUTHORITY[\"EPSG\",\"6326\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Geocentric X\",OTHER],\nAXIS[\"Geocentric Y\",OTHER],\nAXIS[\"Geocentric Z\",NORTH],\nAUTHORITY[\"EPSG\",\"4978\"]]" }, @@ -879,10 +875,10 @@ struct { 7858, "PROJCS[\"GDA2020 / MGA zone 58\",\nGEOGCS[\"GDA2020\",\nDATUM[\"Geocentric_Datum_of_Australia_2020\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nAUTHORITY[\"EPSG\",\"1168\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"7844\"]],\nPROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",0],\nPARAMETER[\"central_meridian\",165],\nPARAMETER[\"scale_factor\",0.9996],\nPARAMETER[\"false_easting\",500000],\nPARAMETER[\"false_northing\",10000000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Easting\",EAST],\nAXIS[\"Northing\",NORTH],\nAUTHORITY[\"EPSG\",\"7858\"]]" }, { 7859, "PROJCS[\"GDA2020 / MGA zone 59\",\nGEOGCS[\"GDA2020\",\nDATUM[\"Geocentric_Datum_of_Australia_2020\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nAUTHORITY[\"EPSG\",\"1168\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"7844\"]],\nPROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",0],\nPARAMETER[\"central_meridian\",171],\nPARAMETER[\"scale_factor\",0.9996],\nPARAMETER[\"false_easting\",500000],\nPARAMETER[\"false_northing\",10000000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Easting\",EAST],\nAXIS[\"Northing\",NORTH],\nAUTHORITY[\"EPSG\",\"7859\"]]" }, - // Made up WKT for 8353 (latitude of origin should also be 78.5000000000003) + // Made up WKT for 8353 (latitude of origin should also be 78.5000000000003) { 8353, "PROJCS[\"JTSK03\",\nGEOGCS[\"System of the Unified Trigonometrical Cadastral Network [JTSK03]\",\nDATUM[\"S-JTSK [JTSK03]\",\nSPHEROID[\"Bessel 1841\",6377397.155,299.1528128,\nAUTHORITY[\"EPSG\",\"7004\"]],\nAUTHORITY[\"EPSG\",\"8351\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"8353\"]],\nPROJECTION[\"Krovak (North Orientated)\"],\nPARAMETER[\"latitude_projection_centre\",49.5000000000003],\nPARAMETER[\"latitude_of_origin\",78.5],\nPARAMETER[\"colatitude_cone_axis\",30.2881397527781],\nPARAMETER[\"central_meridian\",24.8333333333336],\nPARAMETER[\"scale_factor\",0.9999],\nPARAMETER[\"false_easting\",0],\nPARAMETER[\"false_northing\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Easting(X)\",east],AXIS[\"Northing(Y)\",north],\nAUTHORITY[\"EPSG\",\"8353\"]]" }, - { 8705, "GEOCCS[\"Mars 2000 / ECEF\",\nDATUM[\"D_Mars_2000\",\nSPHEROID[\"Mars_2000_IAU_IAG\",3396190,169.894447224,\nAUTHORITY[\"EPSG\",\"49900\"]],\nAUTHORITY[\"EPSG\",\"490001\"]],\nPRIMEM[\"AIRY-0\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Geocentric X\",OTHER],\nAXIS[\"Geocentric Y\",OTHER],\nAXIS[\"Geocentric Z\",NORTH],\nAUTHORITY[\"EPSG\",\"8705\"]]"}, + { 8705, "GEOCCS[\"Mars 2000 / ECEF\",\nDATUM[\"D_Mars_2000\",\nSPHEROID[\"Mars_2000_IAU_IAG\",3396190,169.894447224,\nAUTHORITY[\"EPSG\",\"49900\"]],\nAUTHORITY[\"EPSG\",\"490001\"]],\nPRIMEM[\"AIRY-0\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Geocentric X\",OTHER],\nAXIS[\"Geocentric Y\",OTHER],\nAXIS[\"Geocentric Z\",NORTH],\nAUTHORITY[\"EPSG\",\"8705\"]]" }, { 9794, "PROJCS[\"RGF93 v2b / Lambert-93\",\nGEOGCS[\"RGF93 v2b\",\nDATUM[\"Reseau_Geodesique_Francais_1993_v2b\",\nSPHEROID[\"GRS 1980\",6378137,298.257222101,\nAUTHORITY[\"EPSG\",\"7019\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"6171\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"9782\"]],\nPROJECTION[\"Lambert_Conformal_Conic_2SP\"],\nPARAMETER[\"standard_parallel_1\",49],\nPARAMETER[\"standard_parallel_2\",44],\nPARAMETER[\"latitude_of_origin\",46.5],\nPARAMETER[\"central_meridian\",3],\nPARAMETER[\"false_easting\",700000],\nPARAMETER[\"false_northing\",6600000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"X\",EAST],\nAXIS[\"Y\",NORTH],\nAUTHORITY[\"EPSG\",\"9794\"]]" }, @@ -953,7 +949,7 @@ struct { 30200, "PROJCS[\"Trinidad_1903 / Trinidad 1903\",\nGEOGCS[\"Trinidad 1903\",\nDATUM[\"Trinidad_1903\",\nSPHEROID[\"Clarke 1858\",6378293.64520876,294.260676369,\nAUTHORITY[\"EPSG\",\"7007\"]],\nAUTHORITY[\"EPSG\",\"6302\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4302\"]],\nPROJECTION[\"Cassini_Soldner\"],\nPARAMETER[\"latitude_of_origin\",10.44166666666667],\nPARAMETER[\"central_meridian\",-61.3333333333333],\nPARAMETER[\"scale_factor\",1],\nPARAMETER[\"false_easting\",430000],\nPARAMETER[\"false_northing\",325000],\nUNIT[\"Clarke's link\",0.201166195164,\nAUTHORITY[\"EPSG\",\"9039\"]],\nAXIS[\"X\",EAST],\nAXIS[\"Y\",NORTH],\nAUTHORITY[\"EPSG\",\"30200\"]]" }, //{ 30100, "GEOCCS[\"Moon 2000 Planetocentric\",\nDATUM[\"D_Moon_2000\",\nSPHEROID[\"Moon_2000_IAU_IAG\",1737400,0.0,\nAUTHORITY[\"EPSG\",\"39064\"]],\nAUTHORITY[\"EPSG\",\"39065\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Geocentric X\",OTHER],\nAXIS[\"Geocentric Y\",OTHER],\nAXIS[\"Geocentric Z\",NORTH],\nAUTHORITY[\"EPSG\",\"30100\"]]"}, - { 30101, "GEOCCS[\"Moon 2000 / ECEF\",\nDATUM[\"D_Moon_2000\",\nSPHEROID[\"Moon_2000_IAU_IAG\",1737400,0.0,\nAUTHORITY[\"EPSG\",\"39064\"]],\nAUTHORITY[\"EPSG\",\"39065\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Geocentric X\",OTHER],\nAXIS[\"Geocentric Y\",OTHER],\nAXIS[\"Geocentric Z\",NORTH],\nAUTHORITY[\"EPSG\",\"30101\"]]"}, + { 30101, "GEOCCS[\"Moon 2000 / ECEF\",\nDATUM[\"D_Moon_2000\",\nSPHEROID[\"Moon_2000_IAU_IAG\",1737400,0.0,\nAUTHORITY[\"EPSG\",\"39064\"]],\nAUTHORITY[\"EPSG\",\"39065\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Geocentric X\",OTHER],\nAXIS[\"Geocentric Y\",OTHER],\nAXIS[\"Geocentric Z\",NORTH],\nAUTHORITY[\"EPSG\",\"30101\"]]" }, //{ 30174, "PROJCS[\"Moon 2000 Mercator\",\nGEOGCS[\"Moon 2000 Mercator\",\nDATUM[\"D_Moon_2000\",\nSPHEROID[\"Moon_2000_IAU_IAG\",1737400,0.0,\nAUTHORITY[\"EPSG\",\"39064\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"39065\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"39064\"]],\nPROJECTION[\"Mercator\"],\nPARAMETER[\"False_Easting\",0],\nPARAMETER[\"False_Northing\",0],\nPARAMETER[\"Central_Meridian\",0],\nPARAMETER[\"Standard_Parallel_1\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"30174\"]]"}, { 30175, "PROJCS[\"Moon 2000 Mercator\",\nGEOGCS[\"Moon 2000 Mercator\",\nDATUM[\"D_Moon_2000\",\nSPHEROID[\"Moon_2000_IAU_IAG\",1737400,0.0,\nAUTHORITY[\"EPSG\",\"39064\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"39065\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"39064\"]],\nPROJECTION[\"Mercator\"],\nPARAMETER[\"False_Easting\",0],\nPARAMETER[\"False_Northing\",0],\nPARAMETER[\"Central_Meridian\",0],\nPARAMETER[\"Standard_Parallel_1\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"30175\"]]" }, @@ -1093,7 +1089,7 @@ struct { 32760, "PROJCS[\"WGS 84 / UTM zone 60S\",\nGEOGCS[\"WGS 84\",\nDATUM[\"WGS_1984\",\nSPHEROID[\"WGS 84\",6378137,298.257223563,\nAUTHORITY[\"EPSG\",\"7030\"]],\nAUTHORITY[\"EPSG\",\"6326\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"4326\"]],\nPROJECTION[\"Transverse_Mercator\"],\nPARAMETER[\"latitude_of_origin\",0],\nPARAMETER[\"central_meridian\",177],\nPARAMETER[\"scale_factor\",0.9996],\nPARAMETER[\"false_easting\",500000],\nPARAMETER[\"false_northing\",10000000],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAXIS[\"Easting\",EAST],\nAXIS[\"Northing\",NORTH],\nAUTHORITY[\"EPSG\",\"32760\"]]" }, //{ 49974, "PROJCS["Mars 2000 Mercator",\nGEOGCS["Mars 2000 Mercator",\nDATUM["D_Mars_2000",\nSPHEROID["Mars_2000_IAU_IAG",3396190,169.894447224,\nAUTHORITY["EPSG","49900"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY["EPSG","490001"]],\nPRIMEM["Greenwich",0,\nAUTHORITY["EPSG","8901"]],\nUNIT["degree",0.0174532925199433,\nAUTHORITY["EPSG","9122"]],\nAUTHORITY["EPSG","490000"]],\nPROJECTION["Mercator"],\nPARAMETER["False_Easting",0],\nPARAMETER["False_Northing",0],\nPARAMETER["Central_Meridian",0],\nPARAMETER["Standard_Parallel_1",0],\nUNIT["metre",1,\nAUTHORITY["EPSG","9001"]],\nAUTHORITY["EPSG","49975"]])wkt" }, - { 49975, "PROJCS[\"Mars 2000 Mercator\",\nGEOGCS[\"Mars 2000 Mercator\",\nDATUM[\"D_Mars_2000\",\nSPHEROID[\"Mars_2000_IAU_IAG\",3396190,169.894447224,\nAUTHORITY[\"EPSG\",\"49900\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"490001\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"490000\"]],\nPROJECTION[\"Mercator\"],\nPARAMETER[\"False_Easting\",0],\nPARAMETER[\"False_Northing\",0],\nPARAMETER[\"Central_Meridian\",0],\nPARAMETER[\"Standard_Parallel_1\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"49975\"]]"}, + { 49975, "PROJCS[\"Mars 2000 Mercator\",\nGEOGCS[\"Mars 2000 Mercator\",\nDATUM[\"D_Mars_2000\",\nSPHEROID[\"Mars_2000_IAU_IAG\",3396190,169.894447224,\nAUTHORITY[\"EPSG\",\"49900\"]],\nTOWGS84[0,0,0,0,0,0,0],\nAUTHORITY[\"EPSG\",\"490001\"]],\nPRIMEM[\"Greenwich\",0,\nAUTHORITY[\"EPSG\",\"8901\"]],\nUNIT[\"degree\",0.0174532925199433,\nAUTHORITY[\"EPSG\",\"9122\"]],\nAUTHORITY[\"EPSG\",\"490000\"]],\nPROJECTION[\"Mercator\"],\nPARAMETER[\"False_Easting\",0],\nPARAMETER[\"False_Northing\",0],\nPARAMETER[\"Central_Meridian\",0],\nPARAMETER[\"Standard_Parallel_1\",0],\nUNIT[\"metre\",1,\nAUTHORITY[\"EPSG\",\"9001\"]],\nAUTHORITY[\"EPSG\",\"49975\"]]" }, }; TEST(udGeoZone, SetFromWKT) @@ -1134,7 +1130,8 @@ TEST(udGeoZone, SetFromWKT) size_t matched = 0; while (supportedCodes[i].pWKT[matched] == pWKT[matched]) ++matched; - if (matched > 20) matched -= 20; + if (matched > 20) + matched -= 20; udDebugPrintf("Error on code %d [first %d characters matched]\nThem: %s\nus: %s\n", supportedCodes[i].srid, (int)matched, supportedCodes[i].pWKT + matched, pWKT + matched); ++errorCount; } @@ -1161,7 +1158,6 @@ TEST(udGeoZone, SetFromWKT) udFree(pWKT); } - } TEST(udGeoZone, WKT) @@ -1190,7 +1186,8 @@ TEST(udGeoZone, WKT) size_t matched = 0; while (supportedCodes[i].pWKT[matched] == pWKT[matched]) ++matched; - if (matched > 20) matched -= 20; + if (matched > 20) + matched -= 20; udDebugPrintf("Error on code %d [first %d characters matched]\nThem: %s\nus: %s\n", supportedCodes[i].srid, (int)matched, supportedCodes[i].pWKT + matched, pWKT + matched); ++errorCount; } @@ -1255,43 +1252,30 @@ TEST(udGeoZone, TransformMatrix) uint16_t srid; uint16_t destSrid; udDouble4x4 sourceMatrix, destMatrix; - } testInput[] = - { - { 28356, 4978, udDouble4x4::create(41943.039999999994, -0.00011723346849376662, 0.00000000000000000, 0.00000000000000000, - 0.00011723346849376662, 41943.039999999994, -0.00000000000000000, 0.00000000000000000, - 0.00000000000000000, 0.00000000000000000, 41943.040000000001, 0.00000000000000000, - 520170.76652799919, 6887913.9780700011, -18.307474999688566, 1.0000000000000000), - udDouble4x4::create(-18937.460306866040, -37424.421066352581, 62.525321410785416, 0.00000000000000000, - -17622.195979009895, 8978.9572077717567, 36987.229428276594, 0.00000000000000000, - -33015.896329568888, 16673.621074947940, -19777.754024302445, 0.00000000000000000, - -5024342.6119694551, 2537383.3289774507, -2989620.1388719874, 1.0000000000000000) }, - - { 28356, 4978, udDouble4x4::create(78643.199999999997, 0.00000000000000000, 0.00000000000000000, 0.00000000000000000, - 0.00000000000000000, 78643.199999999997, 0.00000000000000000, 0.00000000000000000, - 0.00000000000000000, 0.00000000000000000, 78643.199999999997, 0.00000000000000000, - 496499.99377599999, 6951000.0000000000, -39355.447960999998, 1.0000000000000000), - udDouble4x4::create(-35737.336815801384, -70054.230885914003, -19.963392004642593, 0.00000000000000000, - -32425.793179251697, 16521.767570626784, 69716.225079091731, 0.00000000000000000, - -62098.016073384839, 31688.938725764212, -36392.313315099942, 0.00000000000000000, - -5008824.0755383838, 2556028.8284058729, -2915630.2573309615, 1.0000000000000000) }, - - { 4978, 28356, udDouble4x4::create(-18937.460306866040, -37424.421066352581, 62.525321410785416, 0.00000000000000000, - -17622.195979009895, 8978.9572077717567, 36987.229428276594, 0.00000000000000000, - -33015.896329568888, 16673.621074947940, -19777.754024302445, 0.00000000000000000, - -5024342.6119694551, 2537383.3289774507, -2989620.1388719874, 1.0000000000000000), - udDouble4x4::create(41943.039999999979, -0.00015631129132502209, 0.00000000000000000, 0.00000000000000000, - 0.00015631129132502209, 41943.039999999979, -0.00000000000000000, 0.00000000000000000, - 0.00000000000000000, 0.00000000000000000, 41943.040000000001, 0.00000000000000000, - 520170.76652799919, 6887913.9780700011, -18.307474999688566, 1.0000000000000000) }, - - { 4978, 28356, udDouble4x4::create(-35737.336815801384, -70054.230885914003, -19.963392004642593, 0.00000000000000000, - -32425.793179251697, 16521.767570626784, 69716.225079091731, 0.00000000000000000, - -62098.016073384839, 31688.938725764212, -36392.313315099942, 0.00000000000000000, - -5008824.0755383838, 2556028.8284058729, -2915630.2573309615, 1.0000000000000000), - udDouble4x4::create(78643.200000000012, -0.00014563939461168318, 0.00000000000000000, 0.00000000000000000, - 0.00014563939461168315, 78643.199999999997, -0.00000000000000000, 0.00000000000000000, - 0.00000000000000000, 0.00000000000000000, 78643.200000000012, 0.00000000000000000, - 496499.99377600092, 6951000.0000000000, -39355.447948929854, 1.0000000000000000) }, + } testInput[] = { + { 28356, 4978, udDouble4x4::create(41943.039999999994, -0.00011723346849376662, 0.00000000000000000, 0.00000000000000000, 0.00011723346849376662, 41943.039999999994, -0.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0.00000000000000000, 41943.040000000001, 0.00000000000000000, 520170.76652799919, 6887913.9780700011, -18.307474999688566, 1.0000000000000000), + udDouble4x4::create(-18937.460306866040, -37424.421066352581, 62.525321410785416, 0.00000000000000000, + -17622.195979009895, 8978.9572077717567, 36987.229428276594, 0.00000000000000000, + -33015.896329568888, 16673.621074947940, -19777.754024302445, 0.00000000000000000, + -5024342.6119694551, 2537383.3289774507, -2989620.1388719874, 1.0000000000000000) }, + + { 28356, 4978, udDouble4x4::create(78643.199999999997, 0.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0.00000000000000000, 78643.199999999997, 0.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0.00000000000000000, 78643.199999999997, 0.00000000000000000, 496499.99377599999, 6951000.0000000000, -39355.447960999998, 1.0000000000000000), + udDouble4x4::create(-35737.336815801384, -70054.230885914003, -19.963392004642593, 0.00000000000000000, + -32425.793179251697, 16521.767570626784, 69716.225079091731, 0.00000000000000000, + -62098.016073384839, 31688.938725764212, -36392.313315099942, 0.00000000000000000, + -5008824.0755383838, 2556028.8284058729, -2915630.2573309615, 1.0000000000000000) }, + + { 4978, 28356, udDouble4x4::create(-18937.460306866040, -37424.421066352581, 62.525321410785416, 0.00000000000000000, -17622.195979009895, 8978.9572077717567, 36987.229428276594, 0.00000000000000000, -33015.896329568888, 16673.621074947940, -19777.754024302445, 0.00000000000000000, -5024342.6119694551, 2537383.3289774507, -2989620.1388719874, 1.0000000000000000), + udDouble4x4::create(41943.039999999979, -0.00015631129132502209, 0.00000000000000000, 0.00000000000000000, + 0.00015631129132502209, 41943.039999999979, -0.00000000000000000, 0.00000000000000000, + 0.00000000000000000, 0.00000000000000000, 41943.040000000001, 0.00000000000000000, + 520170.76652799919, 6887913.9780700011, -18.307474999688566, 1.0000000000000000) }, + + { 4978, 28356, udDouble4x4::create(-35737.336815801384, -70054.230885914003, -19.963392004642593, 0.00000000000000000, -32425.793179251697, 16521.767570626784, 69716.225079091731, 0.00000000000000000, -62098.016073384839, 31688.938725764212, -36392.313315099942, 0.00000000000000000, -5008824.0755383838, 2556028.8284058729, -2915630.2573309615, 1.0000000000000000), + udDouble4x4::create(78643.200000000012, -0.00014563939461168318, 0.00000000000000000, 0.00000000000000000, + 0.00014563939461168315, 78643.199999999997, -0.00000000000000000, 0.00000000000000000, + 0.00000000000000000, 0.00000000000000000, 78643.200000000012, 0.00000000000000000, + 496499.99377600092, 6951000.0000000000, -39355.447948929854, 1.0000000000000000) }, }; @@ -1306,4 +1290,3 @@ TEST(udGeoZone, TransformMatrix) EXPECT_TRUE(udMatrixEqualApprox(destMatrix, testInput[i].destMatrix)); } } - diff --git a/udTest/src/udImageTests.cpp b/udTest/src/udImageTests.cpp index d0ef9cd3..d3492ccf 100644 --- a/udTest/src/udImageTests.cpp +++ b/udTest/src/udImageTests.cpp @@ -1,6 +1,6 @@ -#include "gtest/gtest.h" -#include "udImage.h" #include "udFile.h" +#include "udImage.h" +#include "gtest/gtest.h" TEST(udImageTests, SaveLoad) { diff --git a/udTest/src/udJSONTests.cpp b/udTest/src/udJSONTests.cpp index 51479fd3..e5e77aa1 100644 --- a/udTest/src/udJSONTests.cpp +++ b/udTest/src/udJSONTests.cpp @@ -1,9 +1,9 @@ -#include "gtest/gtest.h" +#include "udFile.h" #include "udJSON.h" +#include "udPlatform.h" #include "udPlatformUtil.h" #include "udStringUtil.h" -#include "udPlatform.h" -#include "udFile.h" +#include "gtest/gtest.h" // First-pass most basic tests for udJSON // TODO: Fix udMemoryDebugTracking to be useful and test memory leaks @@ -47,7 +47,6 @@ static void udJSON_TestContent(udJSON &v) EXPECT_EQ(true, v.Get("Settings.TestArray[-4]").IsVoid()); } - // ---------------------------------------------------------------------------- // Author: Dave Pevreal, June 2017 TEST(udJSONTests, CreationSimple) @@ -56,7 +55,7 @@ TEST(udJSONTests, CreationSimple) // Assign attributes, these are present in both JSON and XML EXPECT_EQ(udR_Success, v.Set("Settings.ProjectsPath = '%s'", "C:\\\\Temp&\\\\")); // Note strings need to be escaped - EXPECT_EQ(udR_Success, v.Set("Settings.ImportAtFullScale = true")); // Note the true/false is NOT quoted, making it a boolean internally + EXPECT_EQ(udR_Success, v.Set("Settings.ImportAtFullScale = true")); // Note the true/false is NOT quoted, making it a boolean internally EXPECT_EQ(udR_Success, v.Set("Settings.TerrainIndex = %d", 2)); EXPECT_EQ(udR_Success, v.Set("Settings.Inside.Count = %d", 5)); EXPECT_EQ(udR_Success, v.Set("Settings.Outside.Count = %d", 2)); @@ -68,8 +67,8 @@ TEST(udJSONTests, CreationSimple) EXPECT_EQ(udR_Success, v.Set("Settings.Nothing = null")); // Of note here is that the input string is currently JSON escaped, so there's some additional backslashes EXPECT_EQ(udR_Success, v.Set("Settings.SpecialChars = '%s'", "<>&\\/?[]{}\\\'\\\"%")); - EXPECT_EQ(udR_Success, v.Set("Settings.TestArray[] = 0")); // Append - EXPECT_EQ(udR_Success, v.Set("Settings.TestArray[] = 1")); // Append + EXPECT_EQ(udR_Success, v.Set("Settings.TestArray[] = 0")); // Append + EXPECT_EQ(udR_Success, v.Set("Settings.TestArray[] = 1")); // Append EXPECT_EQ(udR_Success, v.Set("Settings.TestArray[2] = 2")); // Only allowed to create directly when adding last on the array udJSON_TestContent(v); } @@ -82,7 +81,7 @@ TEST(udJSONTests, CreationSpecial) // Assign attributes, these are present in both JSON and XML EXPECT_EQ(udR_Success, v.Set("Settings['ProjectsPath'] = '%s'", "C:\\\\Temp&\\\\")); // Note strings need to be escaped - EXPECT_EQ(udR_Success, v.Set("Settings['ImportAtFullScale'] = true")); // Note the true/false is NOT quoted, making it a boolean internally + EXPECT_EQ(udR_Success, v.Set("Settings['ImportAtFullScale'] = true")); // Note the true/false is NOT quoted, making it a boolean internally EXPECT_EQ(udR_Success, v.Set("Settings['TerrainIndex'] = %d", 2)); EXPECT_EQ(udR_Success, v.Set("Settings['Inside']['Count'] = %d", 5)); EXPECT_EQ(udR_Success, v.Set("Settings['Outside']['Count'] = %d", 2)); @@ -94,8 +93,8 @@ TEST(udJSONTests, CreationSpecial) EXPECT_EQ(udR_Success, v.Set("Settings['Nothing'] = null")); // Of note here is that the input string is currently JSON escaped, so there's some additional backslashes EXPECT_EQ(udR_Success, v.Set("Settings['SpecialChars'] = '%s'", "<>&\\/?[]{}\\\'\\\"%")); - EXPECT_EQ(udR_Success, v.Set("Settings['TestArray'][] = 0")); // Append - EXPECT_EQ(udR_Success, v.Set("Settings['TestArray'][] = 1")); // Append + EXPECT_EQ(udR_Success, v.Set("Settings['TestArray'][] = 0")); // Append + EXPECT_EQ(udR_Success, v.Set("Settings['TestArray'][] = 1")); // Append EXPECT_EQ(udR_Success, v.Set("Settings['TestArray'][2] = 2")); // Only allowed to create directly when adding last on the array udJSON_TestContent(v); } @@ -305,8 +304,7 @@ TEST(udJSONTests, udMathSpecialSupport) } } -static const char *pTestWKTs[] = -{ +static const char *pTestWKTs[] = { "PROJCS[\"GDA94 / MGA zone 52\",GEOGCS[\"GDA94\",DATUM[\"Geocentric_Datum_of_Australia_1994\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6283\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4283\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",129],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",10000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH],AUTHORITY[\"EPSG\",\"28352\"]]", "PROJCS[\"GDA94 / MGA zone 53\",GEOGCS[\"GDA94\",DATUM[\"Geocentric_Datum_of_Australia_1994\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6283\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4283\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",135],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",10000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH],AUTHORITY[\"EPSG\",\"28353\"]]", "PROJCS[\"GDA94 / MGA zone 54\",GEOGCS[\"GDA94\",DATUM[\"Geocentric_Datum_of_Australia_1994\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6283\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4283\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",141],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",10000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH],AUTHORITY[\"EPSG\",\"28354\"]]", @@ -354,7 +352,6 @@ TEST(udJSONTests, WKT) } } - // ---------------------------------------------------------------------------- // Author: Dave Pevreal, May 2018 TEST(udJSONTests, XMLExport) @@ -494,7 +491,6 @@ TEST(udJSONTests, CDATAXML) EXPECT_STREQ("Station 018", json.Get("vectorChild.name.content").AsString()); } - #if !UDPLATFORM_EMSCRIPTEN // Disabled because of local file access issues TEST(udJSONTests, CDATAXMLE57) { diff --git a/udTest/src/udMathTests.cpp b/udTest/src/udMathTests.cpp index 9c345078..af5b0548 100644 --- a/udTest/src/udMathTests.cpp +++ b/udTest/src/udMathTests.cpp @@ -1,14 +1,31 @@ #include "udMath.h" -#include "gtest/gtest.h" -#include "udPlatform.h" #include "udMathUtility.h" +#include "udPlatform.h" +#include "gtest/gtest.h" // Due to IEEE-754 supporting two different ways to specify 8.f and 2.f, the next three EXPECT_* calls are different // This appears to only occur when using Clang in Release, and only for udFloat4 - SIMD optimizations perhaps? -#define EXPECT_UDFLOAT2_EQ(expected, _actual) { udFloat2 actual = _actual; EXPECT_FLOAT_EQ(expected.x, actual.x); EXPECT_FLOAT_EQ(expected.y, actual.y); } -#define EXPECT_UDFLOAT3_EQ(expected, _actual) { udFloat3 actual = _actual; EXPECT_FLOAT_EQ(expected.x, actual.x); EXPECT_FLOAT_EQ(expected.y, actual.y); EXPECT_FLOAT_EQ(expected.z, actual.z); } -#define EXPECT_UDFLOAT4_EQ(expected, _actual) { udFloat4 actual = _actual; EXPECT_FLOAT_EQ(expected.x, actual.x); EXPECT_FLOAT_EQ(expected.y, actual.y); EXPECT_FLOAT_EQ(expected.z, actual.z); EXPECT_FLOAT_EQ(expected.w, actual.w); } - +#define EXPECT_UDFLOAT2_EQ(expected, _actual) \ + { \ + udFloat2 actual = _actual; \ + EXPECT_FLOAT_EQ(expected.x, actual.x); \ + EXPECT_FLOAT_EQ(expected.y, actual.y); \ + } +#define EXPECT_UDFLOAT3_EQ(expected, _actual) \ + { \ + udFloat3 actual = _actual; \ + EXPECT_FLOAT_EQ(expected.x, actual.x); \ + EXPECT_FLOAT_EQ(expected.y, actual.y); \ + EXPECT_FLOAT_EQ(expected.z, actual.z); \ + } +#define EXPECT_UDFLOAT4_EQ(expected, _actual) \ + { \ + udFloat4 actual = _actual; \ + EXPECT_FLOAT_EQ(expected.x, actual.x); \ + EXPECT_FLOAT_EQ(expected.y, actual.y); \ + EXPECT_FLOAT_EQ(expected.z, actual.z); \ + EXPECT_FLOAT_EQ(expected.w, actual.w); \ + } // This test slerps 2 quaterions rotating about the -Y axis (backwards) q0 theta PI/4 and q1 theta 3PI/4 template @@ -19,7 +36,7 @@ bool udQuaternion_SlerpBasicUnitTest() const T rad1 = T(3.0 * UD_PI / 4.0); udQuaternion q0 = udQuaternion::create(axis, rad0); udQuaternion q1 = udQuaternion::create(axis, rad1); - udVector3 v = { T(1.0), T(0.0), T(0.0) }; + udVector3 v = { T(1.0), T(0.0), T(0.0) }; const int32_t count = 1024; const T tCount = T(count); @@ -212,7 +229,6 @@ bool udQuaternion_SlerpDefinedInputsTest(int incrementCount) return false; } - return true; } @@ -363,8 +379,8 @@ TEST(MathTests, MathCPPSuite) float f = udDot3(v, v); udPow(f, (float)UD_PI); - v = 2.f*v; - v = v*v + v; + v = 2.f * v; + v = v * v + v; m.transpose(); m.determinant(); @@ -390,26 +406,26 @@ TEST(MathTests, MathCPPSuite) TEST(MathTests, UnitLengthCanaries) { - EXPECT_TRUE(EqualApproxUnitTest >()); - EXPECT_TRUE(EqualApproxUnitTest >()); - EXPECT_TRUE(EqualApproxUnitTest >()); - EXPECT_TRUE(EqualApproxUnitTest >()); - EXPECT_TRUE(EqualApproxUnitTest >()); - EXPECT_TRUE(EqualApproxUnitTest >()); - EXPECT_TRUE(EqualApproxUnitTest >()); - EXPECT_TRUE(EqualApproxUnitTest >()); + EXPECT_TRUE(EqualApproxUnitTest>()); + EXPECT_TRUE(EqualApproxUnitTest>()); + EXPECT_TRUE(EqualApproxUnitTest>()); + EXPECT_TRUE(EqualApproxUnitTest>()); + EXPECT_TRUE(EqualApproxUnitTest>()); + EXPECT_TRUE(EqualApproxUnitTest>()); + EXPECT_TRUE(EqualApproxUnitTest>()); + EXPECT_TRUE(EqualApproxUnitTest>()); EXPECT_TRUE(MatrixEqualApproxUnitTest()); EXPECT_TRUE(MatrixEqualApproxUnitTest()); - EXPECT_TRUE(IsUnitLengthUnitTest >()); - EXPECT_TRUE(IsUnitLengthUnitTest >()); - EXPECT_TRUE(IsUnitLengthUnitTest >()); - EXPECT_TRUE(IsUnitLengthUnitTest >()); - EXPECT_TRUE(IsUnitLengthUnitTest >()); - EXPECT_TRUE(IsUnitLengthUnitTest >()); - EXPECT_TRUE(IsUnitLengthUnitTest >()); - EXPECT_TRUE(IsUnitLengthUnitTest >()); + EXPECT_TRUE(IsUnitLengthUnitTest>()); + EXPECT_TRUE(IsUnitLengthUnitTest>()); + EXPECT_TRUE(IsUnitLengthUnitTest>()); + EXPECT_TRUE(IsUnitLengthUnitTest>()); + EXPECT_TRUE(IsUnitLengthUnitTest>()); + EXPECT_TRUE(IsUnitLengthUnitTest>()); + EXPECT_TRUE(IsUnitLengthUnitTest>()); + EXPECT_TRUE(IsUnitLengthUnitTest>()); } TEST(MathTests, QuaternionCanaries) @@ -1090,34 +1106,34 @@ void udPerpendicular3_Check(const udDouble3 &v, double epsilon, int expectedMode TEST(MathTests, UtilityFunctions) { { - double epsilon = 1e-12; + double epsilon = 1e-12; double epsilonSmaller = 1e-13; - udPerpendicular3_Check({1.0, 0.0, 0.0}, epsilon, 0); - udPerpendicular3_Check({0.0, 1.0, 0.0}, epsilon, 0); - udPerpendicular3_Check({0.0, 0.0, 1.0}, epsilon, 0); - udPerpendicular3_Check({1.0, 1.0, 0.0}, epsilon, 0); - udPerpendicular3_Check({1.0, 0.0, 1.0}, epsilon, 0); - udPerpendicular3_Check({1.0, 1.0, 1.0}, epsilon, 0); - - udPerpendicular3_Check({-1.0, 0.0, 0.0}, epsilon, 0); - udPerpendicular3_Check({0.0, -1.0, 0.0}, epsilon, 0); - udPerpendicular3_Check({0.0, 0.0, -1.0}, epsilon, 0); - udPerpendicular3_Check({-1.0, -1.0, 0.0}, epsilon, 0); - udPerpendicular3_Check({-1.0, 0.0, -1.0}, epsilon, 0); - udPerpendicular3_Check({-1.0, -1.0, -1.0}, epsilon, 0); - - udPerpendicular3_Check({23.45, -45.89, 4597.13}, epsilon, 0); - udPerpendicular3_Check({-3421750394.3, 987715.3457, 184573763.437}, epsilon, 0); - udPerpendicular3_Check({-1e43, -2e109, 42.0}, epsilon, 0); - - udPerpendicular3_Check({0.0, 0.0, 0.0}, epsilon, 2); - udPerpendicular3_Check({epsilonSmaller, 0.0, 0.0}, epsilon, 2); - udPerpendicular3_Check({0.0, epsilonSmaller, 0.0}, epsilon, 2); - udPerpendicular3_Check({0.0, 0.0, epsilonSmaller}, epsilon, 2); - udPerpendicular3_Check({-epsilonSmaller, 0.0, 0.0}, epsilon, 2); - udPerpendicular3_Check({0.0, -epsilonSmaller, 0.0}, epsilon, 2); - udPerpendicular3_Check({0.0, 0.0, -epsilonSmaller}, epsilon, 2); + udPerpendicular3_Check({ 1.0, 0.0, 0.0 }, epsilon, 0); + udPerpendicular3_Check({ 0.0, 1.0, 0.0 }, epsilon, 0); + udPerpendicular3_Check({ 0.0, 0.0, 1.0 }, epsilon, 0); + udPerpendicular3_Check({ 1.0, 1.0, 0.0 }, epsilon, 0); + udPerpendicular3_Check({ 1.0, 0.0, 1.0 }, epsilon, 0); + udPerpendicular3_Check({ 1.0, 1.0, 1.0 }, epsilon, 0); + + udPerpendicular3_Check({ -1.0, 0.0, 0.0 }, epsilon, 0); + udPerpendicular3_Check({ 0.0, -1.0, 0.0 }, epsilon, 0); + udPerpendicular3_Check({ 0.0, 0.0, -1.0 }, epsilon, 0); + udPerpendicular3_Check({ -1.0, -1.0, 0.0 }, epsilon, 0); + udPerpendicular3_Check({ -1.0, 0.0, -1.0 }, epsilon, 0); + udPerpendicular3_Check({ -1.0, -1.0, -1.0 }, epsilon, 0); + + udPerpendicular3_Check({ 23.45, -45.89, 4597.13 }, epsilon, 0); + udPerpendicular3_Check({ -3421750394.3, 987715.3457, 184573763.437 }, epsilon, 0); + udPerpendicular3_Check({ -1e43, -2e109, 42.0 }, epsilon, 0); + + udPerpendicular3_Check({ 0.0, 0.0, 0.0 }, epsilon, 2); + udPerpendicular3_Check({ epsilonSmaller, 0.0, 0.0 }, epsilon, 2); + udPerpendicular3_Check({ 0.0, epsilonSmaller, 0.0 }, epsilon, 2); + udPerpendicular3_Check({ 0.0, 0.0, epsilonSmaller }, epsilon, 2); + udPerpendicular3_Check({ -epsilonSmaller, 0.0, 0.0 }, epsilon, 2); + udPerpendicular3_Check({ 0.0, -epsilonSmaller, 0.0 }, epsilon, 2); + udPerpendicular3_Check({ 0.0, 0.0, -epsilonSmaller }, epsilon, 2); } { @@ -1126,36 +1142,36 @@ TEST(MathTests, UtilityFunctions) udDouble3 extentsOut = {}; double epsilon = 1e-12; - q = udDoubleQuat::create({0, 0, 0}); + q = udDoubleQuat::create({ 0, 0, 0 }); EXPECT_TRUE(udIsRotatedAxisStillAxisAligned(q, extentsIn, extentsOut, epsilon)); EXPECT_EQ(extentsOut, extentsIn); - q = udDoubleQuat::create({UD_HALF_PI, 0, 0}); + q = udDoubleQuat::create({ UD_HALF_PI, 0, 0 }); EXPECT_TRUE(udIsRotatedAxisStillAxisAligned(q, extentsIn, extentsOut, epsilon)); EXPECT_EQ(extentsOut, udDouble3::create(-2, 1, 3)); - q = udDoubleQuat::create({0, UD_HALF_PI, 0}); + q = udDoubleQuat::create({ 0, UD_HALF_PI, 0 }); EXPECT_TRUE(udIsRotatedAxisStillAxisAligned(q, extentsIn, extentsOut, epsilon)); EXPECT_EQ(extentsOut, udDouble3::create(1, -3, 2)); - q = udDoubleQuat::create({0, 0, UD_HALF_PI}); + q = udDoubleQuat::create({ 0, 0, UD_HALF_PI }); EXPECT_TRUE(udIsRotatedAxisStillAxisAligned(q, extentsIn, extentsOut, epsilon)); EXPECT_EQ(extentsOut, udDouble3::create(3, 2, -1)); - q = udDoubleQuat::create({UD_HALF_PI, UD_HALF_PI, UD_HALF_PI}); + q = udDoubleQuat::create({ UD_HALF_PI, UD_HALF_PI, UD_HALF_PI }); EXPECT_TRUE(udIsRotatedAxisStillAxisAligned(q, extentsIn, extentsOut, epsilon)); EXPECT_EQ(extentsOut, udDouble3::create(-1, 3, 2)); - q = udDoubleQuat::create({3, 0, 0}); + q = udDoubleQuat::create({ 3, 0, 0 }); EXPECT_FALSE(udIsRotatedAxisStillAxisAligned(q, extentsIn, extentsOut, epsilon)); - q = udDoubleQuat::create({0, 2, 0}); + q = udDoubleQuat::create({ 0, 2, 0 }); EXPECT_FALSE(udIsRotatedAxisStillAxisAligned(q, extentsIn, extentsOut, epsilon)); - q = udDoubleQuat::create({0, 0, 1}); + q = udDoubleQuat::create({ 0, 0, 1 }); EXPECT_FALSE(udIsRotatedAxisStillAxisAligned(q, extentsIn, extentsOut, epsilon)); - q = udDoubleQuat::create({3, 2, 1}); + q = udDoubleQuat::create({ 3, 2, 1 }); EXPECT_FALSE(udIsRotatedAxisStillAxisAligned(q, extentsIn, extentsOut, epsilon)); } diff --git a/udTest/src/udMemoryTests.cpp b/udTest/src/udMemoryTests.cpp index 06b37b0a..203b67bf 100644 --- a/udTest/src/udMemoryTests.cpp +++ b/udTest/src/udMemoryTests.cpp @@ -1,6 +1,6 @@ -#include "gtest/gtest.h" #include "udPlatform.h" #include "udStringUtil.h" +#include "gtest/gtest.h" // ---------------------------------------------------------------------------- // Author: Paul Fox, January 2019 @@ -16,7 +16,7 @@ TEST(udMemoryTests, Validate) // udMemdup test const char numbers[] = "1,2,3,4,5,6,7,8,9"; const char expectedNumbers[] = { '1', ',', '2', ',', '3', ',', '4', ',', '5', ',', '6', ',', '7', ',', '8', ',', '9', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' }; - void *pNumbersMemory = udMemDup(numbers, sizeof(numbers)-1, 10, udAF_Zero); //-1 to strip the \0 + void *pNumbersMemory = udMemDup(numbers, sizeof(numbers) - 1, 10, udAF_Zero); //-1 to strip the \0 EXPECT_EQ(0, memcmp(pNumbersMemory, expectedNumbers, sizeof(expectedNumbers))); udFree(pNumbersMemory); } diff --git a/udTest/src/udResultTests.cpp b/udTest/src/udResultTests.cpp index a1efbfe2..3f6b93cd 100644 --- a/udTest/src/udResultTests.cpp +++ b/udTest/src/udResultTests.cpp @@ -1,9 +1,12 @@ #include "gtest/gtest.h" -#include "udStringUtil.h" #include "udResult.h" +#include "udStringUtil.h" -#define CHECK_STR(x) case x: EXPECT_TRUE(udStrEqual(udResultAsString(x), &(#x)[4])); break; +#define CHECK_STR(x) \ + case x: \ + EXPECT_TRUE(udStrEqual(udResultAsString(x), &(#x)[4])); \ + break; TEST(udResult, StringNamesMatch) { diff --git a/udTest/src/udSafeDequeTests.cpp b/udTest/src/udSafeDequeTests.cpp index 6e066ed9..0f78b0c2 100644 --- a/udTest/src/udSafeDequeTests.cpp +++ b/udTest/src/udSafeDequeTests.cpp @@ -1,5 +1,5 @@ -#include "gtest/gtest.h" #include "udSafeDeque.h" +#include "gtest/gtest.h" TEST(udSafeDequeTests, ValidationTests) { diff --git a/udTest/src/udSocketTests.cpp b/udTest/src/udSocketTests.cpp index 3fb68dc0..68a8f171 100644 --- a/udTest/src/udSocketTests.cpp +++ b/udTest/src/udSocketTests.cpp @@ -1,14 +1,14 @@ -#include "gtest/gtest.h" -#include "udThread.h" #include "udSocket.h" #include "udStringUtil.h" +#include "udThread.h" +#include "gtest/gtest.h" // Emscripten requires more work for sockets #if !UDPLATFORM_EMSCRIPTEN uint8_t clientSend[] = "ClientSendData"; uint8_t serverSend[] = "ServerSendData"; -#define UDSOCKETTEST_CERTIFICATE_PRIVATE_KEY "-----BEGIN PRIVATE KEY-----\n\ +# define UDSOCKETTEST_CERTIFICATE_PRIVATE_KEY "-----BEGIN PRIVATE KEY-----\n\ MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDY1f2s/EeofcuL\n\ FshdPoInwR30ZWAuKFl0dCcMB74P4zuKucVgcil26sjKjFLAJwFH+d2iOXUmgy7/\n\ dzz5dJxUESA8yLlOL4LX3HBlKKQ17WQkjjAxiOpxLq5QzaHtoH9nR963yc6igT6I\n\ @@ -36,7 +36,7 @@ Vc+teD6M9yB4i0g3D5n72TuM4izk03Qz1fXfBDCeUPb7CvXF8Oco/4baSjoz+62U\n\ +8jdUnx/AOSac2LauzWhziOPiDz4WGN3BfsHcDQN+xOxZLrII/yP9ky8YKPuJeGj\n\ hJUnrbVwYTWLHnkV2tC3txE=\n\ -----END PRIVATE KEY-----" -#define UDSOCKETTEST_CERTIFICATE_PUBLIC_KEY "-----BEGIN CERTIFICATE-----\n\ +# define UDSOCKETTEST_CERTIFICATE_PUBLIC_KEY "-----BEGIN CERTIFICATE-----\n\ MIIDpDCCAowCCQDkMz5PqaQQAzANBgkqhkiG9w0BAQsFADCBkzELMAkGA1UEBhMC\n\ QVUxEzARBgNVBAgMClF1ZWVuc2xhbmQxETAPBgNVBAcMCEJyaXNiYW5lMRowGAYD\n\ VQQKDBFFdWNsaWRlb24gUHR5IEx0ZDEOMAwGA1UECwwFVmF1bHQxDTALBgNVBAMM\n\ @@ -63,7 +63,7 @@ const int32_t BigTestSize = 1024 * 1024 * 40; //40MB; Anything over a few MB wil uint32_t udSocketTestsServerThread(void *data) { - udSocket *pListenSocket = (udSocket*)data; + udSocket *pListenSocket = (udSocket *)data; udSocket *pSocket = nullptr; EXPECT_TRUE(udSocket_ServerAcceptClient(pListenSocket, &pSocket)); @@ -81,7 +81,7 @@ uint32_t udSocketTestsServerThread(void *data) uint32_t udSocketTestsSocketSetServerThread(void *data) { - udSocket *pListenSocket = (udSocket*)data; + udSocket *pListenSocket = (udSocket *)data; udSocket *pSocket = nullptr; udSocketSet *pReadSet = nullptr; udSocketSet *pWriteSet = nullptr; @@ -222,7 +222,7 @@ TEST(udSocket, BigReadWriteTest) EXPECT_EQ(udR_Success, udSocket_InitSystem()); uint8_t *pData = udAllocType(uint8_t, BigTestSize, udAF_None); - + udSocket *sockets[2]; udThread *pServerThread; @@ -341,7 +341,7 @@ TEST(udSocket, RealWebsiteSecureTest) const char *pRequest = "GET /favicon.ico HTTP/1.1\r\nHost: www.euclideon.com\r\nUser-Agent: HTTPTestAgent\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\nPragma: no-cache\r\nCache-Control: no-cache\r\n\r\n"; - EXPECT_EQ(udR_Success, udSocket_SendData(pSockets, (const uint8_t*)pRequest, udStrlen(pRequest)+1)); + EXPECT_EQ(udR_Success, udSocket_SendData(pSockets, (const uint8_t *)pRequest, udStrlen(pRequest) + 1)); uint8_t recv[8192]; diff --git a/udTest/src/udStrTests.cpp b/udTest/src/udStrTests.cpp index 59b3db58..c8c579c5 100644 --- a/udTest/src/udStrTests.cpp +++ b/udTest/src/udStrTests.cpp @@ -1,21 +1,20 @@ -#include "gtest/gtest.h" #include "udPlatform.h" #include "udStringUtil.h" +#include "gtest/gtest.h" #define GENERATE_EXPECTED 0 -#define GETSIGN(x) (((x) < 0) ? -1 : ((x) > 0) ? 1 : 0) +#define GETSIGN(x) (((x) < 0) ? -1 : ((x) > 0) ? 1 \ + : 0) // ---------------------------------------------------------------------------- // Author: Paul Fox, July 2017 TEST(udStrTests, udStrncmp) { - static const char *strings[] = - { + static const char *strings[] = { "", "abc", "ABC", "123", "Hello", "[symbols%!]" }; - static int expectedStrcmp[UDARRAYSIZE(strings)][UDARRAYSIZE(strings)] = - { + static int expectedStrcmp[UDARRAYSIZE(strings)][UDARRAYSIZE(strings)] = { { 0, -1, -1, -1, -1, -1 }, { 1, 0, 1, 1, 1, 1 }, { 1, -1, 0, 1, -1, -1 }, @@ -23,8 +22,7 @@ TEST(udStrTests, udStrncmp) { 1, -1, 1, 1, 0, -1 }, { 1, -1, 1, 1, 1, 0 }, }; - static int expectedStrcmpi[UDARRAYSIZE(strings)][UDARRAYSIZE(strings)] = - { + static int expectedStrcmpi[UDARRAYSIZE(strings)][UDARRAYSIZE(strings)] = { { 0, -1, -1, -1, -1, -1 }, { 1, 0, 0, 1, -1, 1 }, { 1, 0, 0, 1, -1, 1 }, @@ -32,8 +30,7 @@ TEST(udStrTests, udStrncmp) { 1, 1, 1, 1, 0, 1 }, { 1, -1, -1, 1, -1, 0 }, }; - static int expectedStrncmp[UDARRAYSIZE(strings)][UDARRAYSIZE(strings)] = - { + static int expectedStrncmp[UDARRAYSIZE(strings)][UDARRAYSIZE(strings)] = { { 0, 0, 0, 0, 0, 0 }, { 1, 0, 1, 1, 1, 1 }, { 1, -1, 0, 1, -1, -1 }, @@ -41,8 +38,7 @@ TEST(udStrTests, udStrncmp) { 1, -1, 1, 1, 0, -1 }, { 1, -1, 1, 1, 1, 0 }, }; - static int expectedStrncmpi[UDARRAYSIZE(strings)][UDARRAYSIZE(strings)] = - { + static int expectedStrncmpi[UDARRAYSIZE(strings)][UDARRAYSIZE(strings)] = { { 0, 0, 0, 0, 0, 0 }, { 1, 0, 0, 1, -1, 1 }, { 1, 0, 0, 1, -1, 1 }, @@ -246,12 +242,12 @@ TEST(udStrTests, udAddToStringTable) } static const char *s_pTestParagraph = -"Today, historians relate that, as a general rule, buying and selling securities was very much unorganized before the year 1792. " -"Every person who owned a security faced the problem of finding interested buyers who might consider the purchase of a debt - free investment. " -"This meant most people were somewhat slow in investing in stocks and bonds because these securities could not readily be converted into money. " -"We have been told that an interesting number of traders and merchants agreed to try to do something to help correct the situation. " -"At this first crucial meeting, they decided that it was a good idea to visit regularly on a daily basis to buy and sell securities. " -"The group of leaders, whose meeting place was under an old, tall cottonwood tree, found the needed time to plot the financial future of our nation. "; + "Today, historians relate that, as a general rule, buying and selling securities was very much unorganized before the year 1792. " + "Every person who owned a security faced the problem of finding interested buyers who might consider the purchase of a debt - free investment. " + "This meant most people were somewhat slow in investing in stocks and bonds because these securities could not readily be converted into money. " + "We have been told that an interesting number of traders and merchants agreed to try to do something to help correct the situation. " + "At this first crucial meeting, they decided that it was a good idea to visit regularly on a daily basis to buy and sell securities. " + "The group of leaders, whose meeting place was under an old, tall cottonwood tree, found the needed time to plot the financial future of our nation. "; TEST(udStrTests, udTempStr) { @@ -261,7 +257,7 @@ TEST(udStrTests, udTempStr) EXPECT_STREQ("3.2mm", udTempStr_HumanMeasurement(0.0032)); EXPECT_STREQ("01:23", udTempStr_ElapsedTime(60 + 23)); EXPECT_STREQ("0:01:23", udTempStr_ElapsedTime(60 + 23, false)); - EXPECT_STREQ("2:01:23", udTempStr_ElapsedTime(120*60 + 60 + 23, false)); + EXPECT_STREQ("2:01:23", udTempStr_ElapsedTime(120 * 60 + 60 + 23, false)); EXPECT_STREQ("0", udTempStr_TrimDouble(0, 10, 0)); EXPECT_STREQ("0.0", udTempStr_TrimDouble(0, 10, 1)); @@ -313,4 +309,3 @@ TEST(udStrTests, udTempStr) EXPECT_EQ(i, udStrAtoi(pStr2)); } } - diff --git a/udTest/src/udThreadTests.cpp b/udTest/src/udThreadTests.cpp index ed5bf9e2..061f942b 100644 --- a/udTest/src/udThreadTests.cpp +++ b/udTest/src/udThreadTests.cpp @@ -45,8 +45,13 @@ TEST(udThreadTests, Thread) { int value = 0; udThread *pThread; - udThreadStart startFunc = [](void *data) -> unsigned int { int *pValue = (int*)data; (*pValue) = 1; return 0; }; - udResult result = udThread_Create(&pThread, startFunc, (void*)&value); + udThreadStart startFunc = [](void *data) -> unsigned int + { + int *pValue = (int *)data; + (*pValue) = 1; + return 0; + }; + udResult result = udThread_Create(&pThread, startFunc, (void *)&value); EXPECT_EQ(udR_Success, result); @@ -76,8 +81,9 @@ TEST(udThreadTests, ThreadConditionVariable) data.pConditionVariable = udCreateConditionVariable(); udThread *pThread; - udThreadStart startFunc = [](void *data) -> unsigned int { - TestStruct *pData = (TestStruct*)data; + udThreadStart startFunc = [](void *data) -> unsigned int + { + TestStruct *pData = (TestStruct *)data; udSleep(100); udLockMutex(pData->pMutex); @@ -87,7 +93,7 @@ TEST(udThreadTests, ThreadConditionVariable) return 0; }; - udResult result = udThread_Create(&pThread, startFunc, (void*)&data); + udResult result = udThread_Create(&pThread, startFunc, (void *)&data); EXPECT_EQ(udR_Success, result); udLockMutex(data.pMutex); @@ -123,8 +129,9 @@ TEST(udThreadTests, ThreadSemaphore) data.p500 = udCreateSemaphore(); data.value = 0; - udThreadStart startFunc1 = [](void *data) -> unsigned int { - TestStruct *pData = (TestStruct*)data; + udThreadStart startFunc1 = [](void *data) -> unsigned int + { + TestStruct *pData = (TestStruct *)data; bool running = true; while (running) { @@ -141,11 +148,12 @@ TEST(udThreadTests, ThreadSemaphore) } return 0; }; - udResult result = udThread_Create(&pThread1, startFunc1, (void*)&data); + udResult result = udThread_Create(&pThread1, startFunc1, (void *)&data); EXPECT_EQ(udR_Success, result); - udThreadStart startFunc2 = [](void *data) -> unsigned int { - TestStruct *pData = (TestStruct*)data; + udThreadStart startFunc2 = [](void *data) -> unsigned int + { + TestStruct *pData = (TestStruct *)data; bool running = true; while (running) { @@ -162,11 +170,12 @@ TEST(udThreadTests, ThreadSemaphore) } return 0; }; - result = udThread_Create(&pThread2, startFunc2, (void*)&data); + result = udThread_Create(&pThread2, startFunc2, (void *)&data); EXPECT_EQ(udR_Success, result); - udThreadStart startFunc3 = [](void *data) -> unsigned int { - TestStruct *pData = (TestStruct*)data; + udThreadStart startFunc3 = [](void *data) -> unsigned int + { + TestStruct *pData = (TestStruct *)data; udWaitSemaphore(pData->p500); EXPECT_GE(pData->value, 500); @@ -184,7 +193,7 @@ TEST(udThreadTests, ThreadSemaphore) } return 0; }; - result = udThread_Create(&pThread3, startFunc3, (void*)&data); + result = udThread_Create(&pThread3, startFunc3, (void *)&data); EXPECT_EQ(udR_Success, result); for (int i = 0; i < 3000; i++) @@ -221,7 +230,14 @@ TEST(udThreadTests, TimeSemaphore) { udSemaphore *pSemaphore = udCreateSemaphore(); udThread *pThread; - udThread_Create(&pThread, [](void *pData) -> unsigned int { udSemaphore *pSemaphore = (udSemaphore*)pData; EXPECT_EQ(0, udWaitSemaphore(pSemaphore, 5000)); return 0; }, pSemaphore); + udThread_Create( + &pThread, [](void *pData) -> unsigned int + { + udSemaphore *pSemaphore = (udSemaphore *)pData; + EXPECT_EQ(0, udWaitSemaphore(pSemaphore, 5000)); + return 0; + }, + pSemaphore); EXPECT_NE(0, udWaitSemaphore(pSemaphore, 200)); diff --git a/udTest/src/udUUIDTests.cpp b/udTest/src/udUUIDTests.cpp index 30d7d962..78da47cd 100644 --- a/udTest/src/udUUIDTests.cpp +++ b/udTest/src/udUUIDTests.cpp @@ -44,7 +44,7 @@ TEST(udUUID, ValidationTests) EXPECT_FALSE(udUUID_IsValid("DC8EA1A9-BECD-4534-ADAD-900B3972EE8")); // Missing the last character //Some very invalid UUIDs - EXPECT_FALSE(udUUID_IsValid((const char*)nullptr)); + EXPECT_FALSE(udUUID_IsValid((const char *)nullptr)); EXPECT_FALSE(udUUID_IsValid("")); EXPECT_FALSE(udUUID_IsValid("1234-")); } diff --git a/udTest/src/udWorkerPoolTests.cpp b/udTest/src/udWorkerPoolTests.cpp index 53775d77..449de125 100644 --- a/udTest/src/udWorkerPoolTests.cpp +++ b/udTest/src/udWorkerPoolTests.cpp @@ -1,8 +1,8 @@ #include "gtest/gtest.h" -#include "udWorkerPool.h" #include "udPlatformUtil.h" #include "udThread.h" +#include "udWorkerPool.h" struct WorkerTestData { @@ -12,7 +12,7 @@ struct WorkerTestData void UpdateDataPlusOne(void *pDataPtr) { - WorkerTestData *pData = (WorkerTestData*)pDataPtr; + WorkerTestData *pData = (WorkerTestData *)pDataPtr; *pData->pInt = (*pData->pInt) + 1; @@ -21,7 +21,7 @@ void UpdateDataPlusOne(void *pDataPtr) void UpdateDataMultiNeg25(void *pDataPtr) { - WorkerTestData *pData = (WorkerTestData*)pDataPtr; + WorkerTestData *pData = (WorkerTestData *)pDataPtr; *pData->pInt = (*pData->pInt) * -25; @@ -66,9 +66,9 @@ TEST(udWorkerPoolTests, Validate) EXPECT_EQ(1250, value); // Queue other combinations - EXPECT_EQ(udR_Success, udWorkerPool_AddTask(pPool, nullptr, &data, false)); // Doesn't do anything + EXPECT_EQ(udR_Success, udWorkerPool_AddTask(pPool, nullptr, &data, false)); // Doesn't do anything EXPECT_EQ(udR_Success, udWorkerPool_AddTask(pPool, nullptr, &data, false, UpdateDataMultiNeg25)); // Multiply by 25 but don't do anything on a thread - EXPECT_EQ(udR_Success, udWorkerPool_AddTask(pPool, UpdateDataPlusOne, &data, false)); // Only +1 + EXPECT_EQ(udR_Success, udWorkerPool_AddTask(pPool, UpdateDataPlusOne, &data, false)); // Only +1 // Should be hit once udWaitSemaphore(data.pSema); @@ -90,7 +90,7 @@ TEST(udWorkerPoolTests, Validate) for (int i = 0; i < TotalQueue; ++i) { - WorkerTestData *pCopiedData = (WorkerTestData*)udMemDup(&data, sizeof(data), i, udAF_Zero); + WorkerTestData *pCopiedData = (WorkerTestData *)udMemDup(&data, sizeof(data), i, udAF_Zero); EXPECT_EQ(udR_Success, udWorkerPool_AddTask(pPool, UpdateDataPlusOne, pCopiedData, true, UpdateDataPlusOne)); }