static void test2(bor_rand_mt_t *rand, bor_nn_t *n, bor_list_t *list, size_t num) { bor_nn_el_t *nn[10]; bor_list_t *nn2[10]; el_t *el, *el2; bor_vec2_t p; size_t len, len2, i; borVec2Set(&p, borRandMT(rand, -3, 3), borRandMT(rand, -3, 3)); len = borNNNearest(n, (const bor_vec_t *)&p, num, nn); len2 = borNearestLinear(list, (void *)&p, dist2, nn2, num, NULL); assertEquals(len, num); assertEquals(len2, num); for (i = 0; i < num; i++){ el = bor_container_of(nn[i], el_t, el); el2 = bor_container_of(nn2[i], el_t, list); if (el == el2){ assertEquals(el, el2); }else{ fprintf(stderr, "%.30f %.30f [%.30f] - %.30f %.30f [%.30f]\n", borVec2X(&el->w), borVec2Y(&el->w), borVec2Dist(&el->w, &p), borVec2X(&el2->w), borVec2Y(&el2->w), borVec2Dist(&el2->w, &p)); } } }
void borPoly2Init(bor_poly2_t *p, const bor_vec2_t *corners, int size) { int i; poly2Init(p, size); for (i = 0; i < size; ++i){ p->px[i] = borVec2X(corners + i); p->py[i] = borVec2Y(corners + i); } poly2InitConstantMultiple(p); }
static void elsInit(void) { size_t i; for (i = 0; i < vecs2_len; ++i){ els[i].val = borVec2X(&vecs2[i]) * 1000000; borListInit(&els[i].htable); els[i].hash = hash(&els[i].htable, NULL); } els_len = vecs2_len; }
int borPoly2PointIn(const bor_poly2_t *p, const bor_vec2_t *v) { int i, j, odd = 0; bor_real_t x, y; x = borVec2X(v); y = borVec2Y(v); for (i = 0, j = p->size - 1; i < p->size; j = i++){ if ((p->py[i] < y && p->py[j] >= y) || (p->py[j] < y && p->py[i] >= y)){ odd ^= (y * p->multiple[i] + p->constant[i] < x); } } return odd; }