MCPcopy Create free account
hub / github.com/SaschaWillems/HowToVulkan / fixIndex

Function fixIndex

source/external/tinyobj/tiny_obj_loader.h:830–863  ·  view source on GitHub ↗

Make index zero-base, and also support relative index.

Source from the content-addressed store, hash-verified

828
829// Make index zero-base, and also support relative index.
830static inline bool fixIndex(int idx, int n, int *ret, bool allow_zero,
831 const warning_context &context) {
832 if (!ret) {
833 return false;
834 }
835
836 if (idx > 0) {
837 (*ret) = idx - 1;
838 return true;
839 }
840
841 if (idx == 0) {
842 // zero is not allowed according to the spec.
843 if (context.warn) {
844 (*context.warn) +=
845 "A zero value index found (will have a value of -1 for normal and "
846 "tex indices. Line " +
847 toString(context.line_number) + ").\n";
848 }
849
850 (*ret) = idx - 1;
851 return allow_zero;
852 }
853
854 if (idx < 0) {
855 (*ret) = n + idx; // negative value = relative
856 if ((*ret) < 0) {
857 return false; // invalid relative index
858 }
859 return true;
860 }
861
862 return false; // never reach here.
863}
864
865static inline std::string parseString(const char **token) {
866 std::string s;

Callers 1

parseTripleFunction · 0.85

Calls 1

toStringFunction · 0.85

Tested by

no test coverage detected