| 274 | } |
| 275 | |
| 276 | struct LNLib::Halfedge* LNLib::VoronoiDiagramGenerator::ELleftbnd(struct PointVDG* p) |
| 277 | { |
| 278 | int i, bucket; |
| 279 | struct Halfedge* he; |
| 280 | |
| 281 | /* Use hash table to get close to desired halfedge */ |
| 282 | bucket = (int)((p->x - xmin) / deltax * ELhashsize); //use the hash function to find the place in the hash map that this HalfEdge should be |
| 283 | |
| 284 | if (bucket < 0) bucket = 0; //make sure that the bucket position in within the range of the hash array |
| 285 | if (bucket >= ELhashsize) bucket = ELhashsize - 1; |
| 286 | |
| 287 | he = ELgethash(bucket); |
| 288 | if (he == (struct Halfedge*)NULL) //if the HE isn't found, search backwards and forwards in the hash map for the first non-null entry |
| 289 | { |
| 290 | for (i = 1; 1; i += 1) |
| 291 | { |
| 292 | if ((he = ELgethash(bucket - i)) != (struct Halfedge*)NULL) |
| 293 | break; |
| 294 | if ((he = ELgethash(bucket + i)) != (struct Halfedge*)NULL) |
| 295 | break; |
| 296 | }; |
| 297 | totalsearch += i; |
| 298 | }; |
| 299 | ntry += 1; |
| 300 | /* Now search linear list of halfedges for the correct one */ |
| 301 | if (he == ELleftend || (he != ELrightend && right_of(he, p))) |
| 302 | { |
| 303 | do |
| 304 | { |
| 305 | he = he->ELright; |
| 306 | } while (he != ELrightend && right_of(he, p)); //keep going right on the list until either the end is reached, or you find the 1st edge which the point |
| 307 | he = he->ELleft; //isn't to the right of |
| 308 | } |
| 309 | else //if the point is to the left of the HalfEdge, then search left for the HE just to the left of the point |
| 310 | do |
| 311 | { |
| 312 | he = he->ELleft; |
| 313 | } while (he != ELleftend && !right_of(he, p)); |
| 314 | |
| 315 | /* Update hash table and reference counts */ |
| 316 | if (bucket > 0 && bucket < ELhashsize - 1) |
| 317 | { |
| 318 | if (ELhash[bucket] != (struct Halfedge*)NULL) |
| 319 | { |
| 320 | ELhash[bucket]->ELrefcnt -= 1; |
| 321 | } |
| 322 | ELhash[bucket] = he; |
| 323 | ELhash[bucket]->ELrefcnt += 1; |
| 324 | }; |
| 325 | return (he); |
| 326 | } |
| 327 | |
| 328 | |
| 329 | /* This delete routine can't reclaim node, since pointers from hash |
nothing calls this directly
no outgoing calls
no test coverage detected