void SplitPaneLayout::clearQuadrantInfo() { _quadrants[QuadrantTopLeft] = Quadrant(); _quadrants[QuadrantTopRight] = Quadrant(); _quadrants[QuadrantBottomLeft] = Quadrant(); _quadrants[QuadrantBottomRight] = Quadrant(); }
void Galaxy::generate(int seed) { srand(seed); int q = rand() % 3 +3; //random int betweeen 3 and 6 for(int i = 0; i < q; i++) { Quadrant x = Quadrant(); x.generate(seed + q); addQuad(x); } }
void QuadtreeNode<Item>::Insert(Item item, const Vector2d &pos) { if (quadrant_items_.find(item) != quadrant_items_.end()) { Remove(item); } if (level_ > 0 && items_.size() >= max_items_) { Split(); int quadrant = Quadrant(pos); quadrant_items_[item] = quadrant; nodes_->at(quadrant).Insert(item, pos); } else { quadrant_items_[item] = -1; items_[item] = pos; } item_count_++; }
void QuadtreeNode<Item>::GetFromPosition(const Vector2d &pos, Items *items) const { int quadrant = Quadrant(pos); if (quadrant < 0) { return; } typename Items::const_iterator it; for (it = items_.begin(); it != items_.end(); ++it) { if (it->second == pos) { (*items)[it->first] = pos; } } if (!nodes_) { return; } for (int i = 0; i < 4; i++) { nodes_->at(i).GetFromPosition(pos, items); } }
int nmg_class_pt_euvu(const fastf_t *pt, struct edgeuse *eu_in, const struct bn_tol *tol) { struct loopuse *lu; struct edgeuse *prev_eu; struct edgeuse *eu; struct vertex *v0, *v1, *v2; vect_t left; vect_t eu_dir; vect_t other_eudir; vect_t pt_dir; fastf_t xo, yo; fastf_t xpt, ypt; fastf_t len; int quado, quadpt; int nmg_class = NMG_CLASS_Unknown; int eu_is_crack = 0; int prev_eu_is_crack = 0; NMG_CK_EDGEUSE(eu_in); BN_CK_TOL(tol); eu = eu_in; if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("nmg_class_pt_euvu((%g %g %g), eu=%p)\n", V3ARGS(pt), (void *)eu); if (UNLIKELY(*eu->up.magic_p != NMG_LOOPUSE_MAGIC)) { bu_log("nmg_class_pt_euvu() called with eu (%p) that isn't part of a loop\n", (void *)eu); bu_bomb("nmg_class_pt_euvu() called with eu that isn't part of a loop"); } lu = eu->up.lu_p; NMG_CK_LOOPUSE(lu); eu_is_crack = nmg_eu_is_part_of_crack(eu); prev_eu = BU_LIST_PPREV_CIRC(edgeuse, &eu->l); prev_eu_is_crack = nmg_eu_is_part_of_crack(prev_eu); /* if both EU's are cracks, we cannot classify */ if (eu_is_crack && prev_eu_is_crack) return NMG_CLASS_Unknown; if (eu_is_crack) { struct edgeuse *eu_test; int done = 0; if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("nmg_class_pt_euvu: eu %p is a crack\n", (void *)eu); /* find next eu from this vertex that is not a crack */ eu_test = BU_LIST_PNEXT_CIRC(edgeuse, &eu->l); while (!done) { while (eu_test->vu_p->v_p != eu->vu_p->v_p && eu_test != eu) eu_test = BU_LIST_PNEXT_CIRC(edgeuse, &eu_test->l); if (eu_test == eu) done = 1; if (!nmg_eu_is_part_of_crack(eu_test)) done = 1; if (!done) eu_test = BU_LIST_PNEXT_CIRC(edgeuse, &eu_test->l); } if (eu_test == eu) /* can't get away from crack */ return NMG_CLASS_Unknown; else eu = eu_test; if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("\tUsing eu %p instead\n", (void *)eu); } if (prev_eu_is_crack) { struct edgeuse *eu_test; int done = 0; if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("nmg_class_pt_euvu: prev_eu (%p) is a crack\n", (void *)prev_eu); /* find previous eu ending at this vertex that is not a crack */ eu_test = BU_LIST_PPREV_CIRC(edgeuse, &prev_eu->l); while (!done) { while (eu_test->eumate_p->vu_p->v_p != eu->vu_p->v_p && eu_test != prev_eu) eu_test = BU_LIST_PPREV_CIRC(edgeuse, &eu_test->l); if (eu_test == prev_eu) done = 1; if (!nmg_eu_is_part_of_crack(eu_test)) done = 1; if (!done) eu_test = BU_LIST_PPREV_CIRC(edgeuse, &eu_test->l); } if (eu_test == prev_eu) /* can't get away from crack */ return NMG_CLASS_Unknown; else prev_eu = eu_test; if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("\tUsing prev_eu %p instead\n", (void *)prev_eu); } /* left is the Y-axis of our XY-coordinate system */ if (UNLIKELY(nmg_find_eu_leftvec(left, eu))) { bu_log("nmg_class_pt_euvu: nmg_find_eu_leftvec() for eu=%p failed!\n", (void *)eu); bu_bomb("nmg_class_pt_euvu: nmg_find_eu_leftvec() failed!"); } if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("\tprev_eu = %p, left = (%g %g %g)\n", (void *)prev_eu, V3ARGS(left)); /* v0 is the origin of the XY-coordinate system */ v0 = eu->vu_p->v_p; NMG_CK_VERTEX(v0); /* v1 is on the X-axis */ v1 = eu->eumate_p->vu_p->v_p; NMG_CK_VERTEX(v1); /* v2 determines angle prev_eu makes with X-axis */ v2 = prev_eu->vu_p->v_p; NMG_CK_VERTEX(v2); if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("\tv0=%p, v1=%p, v2=%p\n", (void *)v0, (void *)v1, (void *)v2); /* eu_dir is our X-direction */ VSUB2(eu_dir, v1->vg_p->coord, v0->vg_p->coord); /* other_eudir is direction along the previous EU (from origin) */ VSUB2(other_eudir, v2->vg_p->coord, v0->vg_p->coord); if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("\teu_dir=(%g %g %g), other_eudir=(%g %g %g)\n", V3ARGS(eu_dir), V3ARGS(other_eudir)); /* get X and Y components for other_eu */ xo = VDOT(eu_dir, other_eudir); yo = VDOT(left, other_eudir); /* which quadrant does this XY point lie in */ quado = Quadrant(xo, yo); if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("\txo=%g, yo=%g, quadrant=%d\n", xo, yo, quado); /* get direction to PT from origin */ VSUB2(pt_dir, pt, v0->vg_p->coord); if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("\tpt_dir=(%g %g %g)\n", V3ARGS(pt_dir)); /* get X and Y components for PT */ xpt = VDOT(eu_dir, pt_dir); ypt = VDOT(left, pt_dir); /* which quadrant does this XY point lie in */ quadpt = Quadrant(xpt, ypt); if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("\txpt=%g, ypt=%g, quadrant=%d\n", xpt, ypt, quadpt); /* do a quadrant comparison first (cheap!!!) */ if (quadpt < quado) return NMG_CLASS_AinB; if (quadpt > quado) return NMG_CLASS_AoutB; /* both are in the same quadrant, need to normalize the coordinates */ len = sqrt(xo*xo + yo*yo); xo = xo/len; yo = yo/len; len = sqrt(xpt*xpt + ypt*ypt); xpt = xpt/len; ypt = ypt/len; if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("\tNormalized xo, yo=(%g %g), xpt, ypt=(%g %g)\n", xo, yo, xpt, ypt); switch (quadpt) { case 1: if (xpt >= xo && ypt <= yo) nmg_class = NMG_CLASS_AinB; else nmg_class = NMG_CLASS_AoutB; break; case 2: if (xpt >= xo && ypt >= yo) nmg_class = NMG_CLASS_AinB; else nmg_class = NMG_CLASS_AoutB; break; case 3: if (xpt <= xo && ypt >= yo) nmg_class = NMG_CLASS_AinB; else nmg_class = NMG_CLASS_AoutB; break; case 4: if (xpt <= xo && ypt <= yo) nmg_class = NMG_CLASS_AinB; else nmg_class = NMG_CLASS_AoutB; break; default: bu_log("This can't happen (illegal quadrant %d)\n", quadpt); bu_bomb("This can't happen (illegal quadrant)\n"); break; } if (UNLIKELY(RTG.NMG_debug & DEBUG_PT_FU)) bu_log("returning %s\n", nmg_class_name(nmg_class)); return nmg_class; }