| 134 | } |
| 135 | |
| 136 | static unsigned short addVertex(unsigned short x, unsigned short y, unsigned short z, |
| 137 | unsigned short* verts, int* firstVert, int* nextVert, int& nv) |
| 138 | { |
| 139 | int bucket = computeVertexHash(x, 0, z); |
| 140 | int i = firstVert[bucket]; |
| 141 | |
| 142 | while (i != -1) |
| 143 | { |
| 144 | const unsigned short* v = &verts[i*3]; |
| 145 | if (v[0] == x && (rcAbs(v[1] - y) <= 2) && v[2] == z) |
| 146 | return (unsigned short)i; |
| 147 | i = nextVert[i]; // next |
| 148 | } |
| 149 | |
| 150 | // Could not find, create new. |
| 151 | i = nv; nv++; |
| 152 | unsigned short* v = &verts[i*3]; |
| 153 | v[0] = x; |
| 154 | v[1] = y; |
| 155 | v[2] = z; |
| 156 | nextVert[i] = firstVert[bucket]; |
| 157 | firstVert[bucket] = i; |
| 158 | |
| 159 | return (unsigned short)i; |
| 160 | } |
| 161 | |
| 162 | // Last time I checked the if version got compiled using cmov, which was a lot faster than module (with idiv). |
| 163 | inline int prev(int i, int n) { return i-1 >= 0 ? i-1 : n-1; } |
no test coverage detected