Пример #1
0
/* RTreeSearch in an index tree or subtree for all data retangles that
** overlap the argument rectangle.
** Returns the number of qualifying data rects.
*/
LeafList_t *RTreeSearch(RTree_t * rtp, Node_t * n, Rect_t * r)
{
    register int i;
    LeafList_t *llp = 0;

    assert(n);
    assert(n->level >= 0);
    assert(r);

    rtp->SeTouchCount++;

    if (n->level > 0) {		/* this is an internal node in the tree */
	for (i = 0; i < NODECARD; i++)
	    if (n->branch[i].child && Overlap(r, &n->branch[i].rect)) {
		LeafList_t *tlp = RTreeSearch(rtp, n->branch[i].child, r);
		if (llp) {
		    LeafList_t *xlp = llp;
		    while (xlp->next)
			xlp = xlp->next;
		    xlp->next = tlp;
		} else
		    llp = tlp;
	    }
    } else {			/* this is a leaf node */
	for (i = 0; i < NODECARD; i++) {
	    if (n->branch[i].child && Overlap(r, &n->branch[i].rect)) {
		llp = RTreeLeafListAdd(llp, (Leaf_t *) & n->branch[i]);
#				ifdef RTDEBUG
		PrintRect(&n->branch[i].rect);
#				endif
	    }
	}
    }
    return llp;
}
RTREE_TEMPLATE
bool RTREE_QUAL::Search(Node* a_node, Rect* a_rect, int& a_foundCount, t_resultCallback a_resultCallback, void* a_context) {
    ASSERT(a_node);
    ASSERT(a_node->m_level >= 0);
    ASSERT(a_rect);

    if (a_node->IsInternalNode()) {
        // This is an internal node in the tree
        for (int index = 0; index < a_node->m_count; ++index) {
            if (Overlap(a_rect, &a_node->m_branch[index].m_rect)) {
                if (!Search(a_node->m_branch[index].m_child, a_rect, a_foundCount, a_resultCallback, a_context)) {
                    // The callback indicated to stop searching
                    return false;
                }
            }
        }
    } else {
        // This is a leaf node
        for (int index = 0; index < a_node->m_count; ++index) {
            if (Overlap(a_rect, &a_node->m_branch[index].m_rect)) {
                DATATYPE& id = a_node->m_branch[index].m_data;
                ++a_foundCount;

                // NOTE: There are different ways to return results.  Here's where to modify
                if (a_resultCallback) {
                    if (!a_resultCallback(id, a_context)) {
                        return false; // Don't continue searching
                    }
                }
            }
        }
    }

    return true; // Continue searching
}
Пример #3
0
Dtype Calc_iou(const vector<Dtype>& box, const vector<Dtype>& truth) {
  Dtype w = Overlap(box[0], box[2], truth[0], truth[2]);
  Dtype h = Overlap(box[1], box[3], truth[1], truth[3]);
  if (w < 0 || h < 0) return 0;
  Dtype inter_area = w * h;
  Dtype union_area = box[2] * box[3] + truth[2] * truth[3] - inter_area;
  return inter_area / union_area;
}
Пример #4
0
int IIX::LookupGlobal(int GlobalFrom, int GlobalTo, int **ptrHits) const
{
    *ptrHits = 0;
    if (!ValidInterval(GlobalFrom, GlobalTo))
        return 0;

    int *Hits = 0;
    int HitCount = 0;
    int HitBufferSize = 0;
    const int BlockFrom = PosToBlockIndex(GlobalFrom);
    const int BlockTo = PosToBlockIndex(GlobalTo);
    for (int BlockIndex = BlockFrom; BlockIndex <= BlockTo; ++BlockIndex)
    {
        for (INTERVAL *ii = m_Blocks[BlockIndex]; ii; ii = ii->Next)
        {
            if (Overlap(GlobalFrom, GlobalTo, ii->From, ii->To) > 0)
            {
                if (HitCount >= HitBufferSize)
                {
                    HitBufferSize += 128;
                    reall(Hits, int, HitBufferSize);
                }
                Hits[HitCount++] = ii->User;
            }
        }
    }
    *ptrHits = Hits;
    return HitCount;
}
RTREE_TEMPLATE
bool RTREE_QUAL::RemoveRectRec(Rect* a_rect, const DATATYPE& a_id, Node* a_node, ListNode** a_listNode) {
    ASSERT(a_rect && a_node && a_listNode);
    ASSERT(a_node->m_level >= 0);

    if (a_node->IsInternalNode()) // not a leaf node
    {
        for (int index = 0; index < a_node->m_count; ++index) {
            if (Overlap(a_rect, &(a_node->m_branch[index].m_rect))) {
                if (!RemoveRectRec(a_rect, a_id, a_node->m_branch[index].m_child, a_listNode)) {
                    if (a_node->m_branch[index].m_child->m_count >= MINNODES) {
                        // child removed, just resize parent rect
                        a_node->m_branch[index].m_rect = NodeCover(a_node->m_branch[index].m_child);
                    } else {
                        // child removed, not enough entries in node, eliminate node
                        ReInsert(a_node->m_branch[index].m_child, a_listNode);
                        DisconnectBranch(a_node, index); // Must return after this call as count has changed
                    }
                    return false;
                }
            }
        }
        return true;
    } else // A leaf node
    {
        for (int index = 0; index < a_node->m_count; ++index) {
            if (a_node->m_branch[index].m_data == a_id) {
                DisconnectBranch(a_node, index); // Must return after this call as count has changed
                return false;
            }
        }
        return true;
    }
}
int TopLeptonicPair::Train(boca::Event const& event, boca::PreCuts const&, Tag tag)
{
    INFO0;
    auto triplets = top_leptonic_reader_.Multiplets(event);
    DEBUG(triplets.size());
    auto particles = event.GenParticles();
    auto top_particles = CopyIfParticle(particles, Id::top);
    CHECK(top_particles.size() == 2, top_particles.size());
//    std::vector<Jet>neutrinos = CopyIfNeutrino(particles);
    if (top_particles.size() != 2 && tag == Tag::signal) DEBUG(particles.size());
    auto final_triplets = BestMatches(triplets, top_particles, tag);
//     CHECK(final_triplets.size()==2, final_triplets.size());
    auto sextets = UnorderedPairs(final_triplets, [](Triplet const & triplet_1, Triplet const & triplet_2) {
        Quartet22 quartet(Doublet(triplet_1.Singlet(), triplet_1.Doublet().Jet()), Doublet(triplet_2.Singlet(), triplet_2.Doublet().Jet()));
        if (quartet.Overlap()) throw Overlap();
        quartet.Doublet1().SetBdt(triplet_1.Bdt());
        quartet.Doublet2().SetBdt(triplet_2.Bdt());
        WimpMass wimp_mass;
        //             Insert(sextets, wimp_mass.Sextet(quartet, event.MissingEt(), neutrinos, tag));
        return wimp_mass.Fake(quartet);
    });

    if (tag == Tag::signal && sextets.size() > 1) {
        DEBUG(sextets.size());
        sextets = BestRapidity(sextets);
    }
    return SaveEntries(sextets);
}
Пример #7
0
int GRect::Near(GRect &r)
{
	if (Overlap(&r))
		return 0;

	if (r.x1 > x2)
	{
		// Off the right edge
		return r.x1 - x2;
	}
	else if (r.x2 < x1)
	{
		// Off the left edge
		return x1 - r.x2;
	}
	else if (r.y2 < y1)
	{
		// Off the top edge
		return y1 - r.y2;
	}
	else
	{
		// Off the bottom edge
		return r.y1 - y2;
	}
}
Пример #8
0
bool CDecalsDrawerGL4::TryToCombineDecalGroups(SDecalGroup& g1, SDecalGroup& g2)
{
	// g1 is full -> we cannot move anything from g2 to it
	if (g1.ids.back() != 0)
		return false;

	if (!Overlap(g1, g2))
		return false;


	if ((g1.size() + g2.size()) <= CDecalsDrawerGL4::MAX_DECALS_PER_GROUP) {
		// move all g2 decals to g1 (and remove g2 later)
		for (int n = g1.size(), k = 0; n < g1.ids.size(); ++n,++k) {
			g1.ids[n] = g2.ids[k];
		}
		g2.ids.fill(0);

		UpdateBoundingBox(g1);
		//UpdateBoundingBox(g2); gets removed, no reason to update
		return true;
	}


	// move n decals from g2 to g1
	const int s = g1.size();
	const int n = g1.ids.size() - s;
	memcpy(&g1.ids[s], &g2.ids[0], sizeof(int) * n);
	for (int i = 0; i<g2.ids.size(); ++i) {
		g2.ids[i] = ((n + i) < g2.ids.size()) ? g2.ids[n + i] : 0;
	}
	UpdateBoundingBox(g1);
	UpdateBoundingBox(g2);
	return false;
}
Пример #9
0
void YARPBlobFinder::MergeBoxes (void)
{
	// do not take i = 0 into account.
	//const double overlap = 1.5;
	for (int i = 1; i <= m_last_tag-1; i++)
	{
		int j = i + 1;
		while (j <= m_last_tag) 
		{
			//if (CenterDistance (i, j) < CombinedSize (i, j) * overlap &&
			if (Overlap (i, j) &&
				HueDistance (i, j) < m_hue_thr/2 /*4*/)
			{
				FuseBoxes (i, j);

				if (j == m_last_tag)
				{
					m_last_tag--;
				}
				else
				{
					memcpy (&(m_boxes[j]), &(m_boxes[j+1]), sizeof(YARPBox) * (m_last_tag - j /*- 1*/));
					m_last_tag--;
				}
			}
			else
				j++;
		}
	}
}
Пример #10
0
MultipletSignature<Quartet211> SignatureLeptonTagger::Signature(Doublet const& doublet, Singlet const& singlet_1, Singlet const& singlet_2) const
{
    Quartet211 quartet;
    if ((doublet.Jet() + singlet_1.Jet()).Mass() > (doublet.Jet() + singlet_2.Jet()).Mass()) quartet.SetMultiplets(doublet, singlet_1, singlet_2);
    else quartet.SetMultiplets(doublet, singlet_2, singlet_1);
    if (quartet.Overlap()) throw Overlap();
    return MultipletSignature<Quartet211>(quartet);
}
Пример #11
0
MultipletSignature<Octet332> SignatureT::Signature(Triplet const& triplet_1, Triplet const& triplet_2, Doublet const& doublet) const
{
    Octet332 octet;
    if (boca::Jet((triplet_1.Jet() + doublet.Jet())).Mass() > boca::Jet(triplet_2.Jet() + doublet.Jet()).Mass()) octet.SetMultiplets(triplet_1, triplet_2, doublet);
    else octet.SetMultiplets(triplet_2, triplet_1, doublet);
    if (octet.Overlap()) throw Overlap();
    return MultipletSignature<Octet332>(octet);
}
std::vector<Quintet> NewPartnerLeptonic::Quintets(boca::Event const& event, std::function<Quintet(Quintet&)> const& function)
{
    return Pairs(top_reader_.Multiplets(event), boson_reader_.Multiplets(event), [&](Triplet const & triplet, Doublet const & doublet) {
        Quintet quintet(triplet, doublet);
        if (quintet.Overlap()) throw Overlap();
        return function(quintet);
    });
}
Пример #13
0
std::vector<int> CDecalsDrawerGL4::UpdateOverlap_CheckQueries()
{
	// query the results of the last issued test (if any pixels were rendered for the decal)
	std::vector<int> candidatesForRemoval;
	candidatesForRemoval.reserve(waitingOverlapGlQueries.size());
	for (auto& p: waitingOverlapGlQueries) {
		GLint rendered = GL_FALSE;
		glGetQueryObjectiv(p.second, GL_QUERY_RESULT, &rendered);
		glDeleteQueries(1, &p.second);
		if (rendered == GL_FALSE) {
			candidatesForRemoval.push_back(p.first);
		}
	}
	waitingOverlapGlQueries.clear();

	// no candidates left, restart with stage 0
	if (candidatesForRemoval.empty()) {
		overlapStage = 0;
		return candidatesForRemoval;
	}

	//FIXME comment
	auto sortBeginIt = candidatesForRemoval.begin();
	auto sortEndIt = candidatesForRemoval.end();
	while (sortBeginIt != sortEndIt) {
		std::sort(sortBeginIt, sortEndIt, [&](const int& idx1, const int& idx2){
			return decals[idx1].generation < decals[idx2].generation;
		});
		sortEndIt = std::partition(sortBeginIt+1, sortEndIt, [&](const int& idx){
			return !Overlap(decals[*sortBeginIt], decals[idx]);
		});
		++sortBeginIt;
	}
	auto eraseIt = sortEndIt;

	// free one decal (+ remove it from the overlap texture)
	int freed = 0;
	CVertexArray* va = GetVertexArray();
	glStencilFunc(GL_ALWAYS, 0, 0xFF);
	glStencilOp(GL_DECR_WRAP, GL_DECR_WRAP, GL_DECR_WRAP);
	va->Initialize();
	for (auto it = candidatesForRemoval.begin(); it != eraseIt; ++it) {
		const int curIndex = *it;
		const Decal& d = decals[curIndex];
		DRAW_DECAL(va, &d);
		FreeDecal(curIndex);
		freed++;
	}
	va->DrawArray2dT(GL_QUADS);
	candidatesForRemoval.erase(candidatesForRemoval.begin(), eraseIt);

	//FIXME
	LOG_L(L_ERROR, "Query freed: %i of %i (decals:%i groups:%i)", freed, int(candidatesForRemoval.size()), int(decals.size() - freeIds.size()), int(groups.size()));

	// overlap texture changed, so need to retest the others
	return candidatesForRemoval;
}
Пример #14
0
int GRect::Near(int x, int y)
{
	if (Overlap(x, y))
	{
		return 0;
	}
	else if (x >= x1 && x <= x2)
	{
		if (y < y1)
			return y1 - y;
		else
			return y - y2;
	}
	else if (y >= y1 && y <= y2)
	{
		if (x < x1)
			return x1 - x;
		else
			return x - x2;
	}

	int dx = 0;
	int dy = 0;	
	if (x < x1)
	{
		if (y < y1)
		{
			// top left
			dx = x1 - x;
			dy = y1 - y;
		}
		else
		{
			// bottom left
			dx = x1 - x;
			dy = y - y2;
		}
	}
	else
	{
		if (y < y1)
		{
			// top right
			dx = x - x2;
			dy = y1 - y;
		}
		else
		{
			// bottom right
			dx = x - x2;
			dy = y - y2;
		}
	}

	return (int)ceil(sqrt( (double) ((dx * dx) + (dy * dy)) ));
}
Пример #15
0
//
// This function sets a random spawn point for an AI without overlapping with the player's starting
// position and any other AI in the group
//
// @Param ai - Pointer to the AI in question
//
void AI_Group::SetRandomSpawn(AI* ai)
{
	ai->SetSpawn(*dungeon);  // Set a spawn point
	// If the AI overlaps with another AI or the player's starting position, move it away from it.
	if (Overlap(ai) || OverlapWithPlayerStart(ai))
	{
		ai->SetXPosition(ai->GetXPosition() + Random(0, T_SIZE));
		ai->SetYPosition(ai->GetYPosition() + Random(0, T_SIZE));
	}
}
Пример #16
0
void mitk::ImageReadAccessor::OrganizeReadAccess()
{
  m_Image->m_ReadWriteLock.Lock();

  // Check, if there is any Write-Access going on
  if (m_Image->m_Writers.size() > 0)
  {
    // Check for every WriteAccessors, if the Region of this ImageAccessors overlaps
    // make sure this iterator is not used, when m_ReadWriteLock is Unlocked!
    auto it = m_Image->m_Writers.begin();

    for (; it != m_Image->m_Writers.end(); ++it)
    {
      ImageAccessorBase *w = *it;
      if (Overlap(w))
      {
        // An Overlap was detected. There are two possibilities to deal with this situation:
        // Throw an exception or wait for the WriteAccessor w until it is released and start again with the request
        // afterwards.
        if (!(m_Options & ExceptionIfLocked))
        {
          PreventRecursiveMutexLock(w);

          // WAIT
          w->Increment();
          m_Image->m_ReadWriteLock.Unlock();
          ImageAccessorBase::WaitForReleaseOf(w->m_WaitLock);

          // after waiting for the WriteAccessor w, start this method again
          OrganizeReadAccess();
          return;
        }
        else
        {
          // THROW EXCEPTION
          m_Image->m_ReadWriteLock.Unlock();
          mitkThrowException(mitk::MemoryIsLockedException)
            << "The image part being ordered by the ImageAccessor is already in use and locked";
          return;
        }
      } // if
    }   // for
  }     // if

  // Now, we know, that there is no conflict with a Write-Access
  // Lock the Mutex in ImageAccessorBase, to make sure that every other ImageAccessor has to wait if it locks the mutex
  m_WaitLock->m_Mutex.Lock();

  // insert self into readers list in Image
  m_Image->m_Readers.push_back(this);

  // printf("ReadAccess %d %d\n",(int) m_Image->m_Readers.size(),(int) m_Image->m_Writers.size());
  // fflush(0);
  m_Image->m_ReadWriteLock.Unlock();
}
Пример #17
0
void IntervalTree::EnumerateDepthFirst(IntervalTreeNode *x, TemplateStack<void *> *enumResultStack, int low, int high) {

  if(x != nil) {
    if(x->left->maxHigh >= low)
      EnumerateDepthFirst(x->left,enumResultStack,low,high);
    if (Overlap(low,high,x->key,x->high))
      enumResultStack->Push(x);
    EnumerateDepthFirst(x->right,enumResultStack,low,high);
  }

  return;
}
Пример #18
0
int32_t Horse::Collide()
{
    for(uint32_t i=0; i<m_state->GetGridSize(); i++)
    {
        if(i == m_id)
            continue;
        const Horse& tmpHorse = m_state->GetHorse(i);
        if(Overlap(tmpHorse))
            return i;
    }
    return -1;
}
Пример #19
0
TemplateStack<void *> * IntervalTree::Enumerate(int low,
							int high)  {
  TemplateStack<void *> * enumResultStack;
  IntervalTreeNode* x=root->left;
  int stuffToDo = (x != nil);

  // Possible speed up: add min field to prune right searches //

#ifdef DEBUG_ASSERT
  Assert((recursionNodeStackTop == 1),
	 "recursionStack not empty when entering IntervalTree::Enumerate");
#endif
  currentParent = 0;
  enumResultStack = new TemplateStack<void *>(4);

  while(stuffToDo) {
    if (Overlap(low,high,x->key,x->high) ) {
      enumResultStack->Push(x->storedInterval);
      recursionNodeStack[currentParent].tryRightBranch=1;
    }
    if(x->left->maxHigh >= low) { // implies x != nil
      if ( recursionNodeStackTop == recursionNodeStackSize ) {
	recursionNodeStackSize *= 2;
	recursionNodeStack = (it_recursion_node *)
	  realloc(recursionNodeStack,
		  recursionNodeStackSize * sizeof(it_recursion_node));
	if (recursionNodeStack == NULL)
	  exit(1);
      }
      recursionNodeStack[recursionNodeStackTop].start_node = x;
      recursionNodeStack[recursionNodeStackTop].tryRightBranch = 0;
      recursionNodeStack[recursionNodeStackTop].parentIndex = currentParent;
      currentParent = recursionNodeStackTop++;
      x = x->left;
    } else {
      x = x->right;
    }
    stuffToDo = (x != nil);
    while( (!stuffToDo) && (recursionNodeStackTop > 1) ) {
	if(recursionNodeStack[--recursionNodeStackTop].tryRightBranch) {
	  x=recursionNodeStack[recursionNodeStackTop].start_node->right;
	  currentParent=recursionNodeStack[recursionNodeStackTop].parentIndex;
	  recursionNodeStack[currentParent].tryRightBranch=1;
	  stuffToDo = ( x != nil);
	}
    }
  }
#ifdef DEBUG_ASSERT
  Assert((recursionNodeStackTop == 1),
	 "recursionStack not empty when exiting IntervalTree::Enumerate");
#endif
  return(enumResultStack);
}
Пример #20
0
bool CDecalsDrawerGL4::AddDecalToGroup(SDecalGroup& g, const Decal& d, const int decalIdx)
{
	if (g.ids.back() != 0)
		return false;

	if (!Overlap(g, d))
		return false;

	auto it = spring::find(g.ids, 0);
	*it = decalIdx;
	UpdateBoundingBox(g);
	return true;
}
Пример #21
0
TopWindow& TopWindow::FullScreen(bool b)
{
	LLOG("TopWindow::FullScreen " << UPP::Name(this));
	fullscreen = b;
	HWND hwnd = GetOwnerHWND();
	bool pinloop = inloop;
	WndDestroy();
	Overlap();
	SetRect(overlapped); // 12-05-23 Tom changed from GetDefaultWindowRect() to 'overlapped' to restore back to previous window position
	Open(hwnd);
	inloop = pinloop;
	return *this;
}
Пример #22
0
void GRect::Intersection(GRect *a)
{
	if (Overlap(a))
	{
		x1 = max(a->x1, x1);
		y1 = max(a->y1, y1);
		x2 = min(a->x2, x2);
		y2 = min(a->y2, y2);
	}
	else
	{
		x1 = y1 = 0;
		x2 = y2 = -1;
	}
}
Пример #23
0
std::vector<Quattuordecuplet554> SignatureEffectiveTagger::Quattuordecuplets(boca::Event const& event, std::function< Quattuordecuplet554(Quattuordecuplet554&)> const& function)
{
    INFO0;
    auto hadronic = top_partner_hadronic_reader_.Multiplets(event, 8);
    auto leptonic = top_partner_leptonic_reader_.Multiplets(event, 8);
    auto higgs_pairs = higgs_pair_reader_.Multiplets(event, 8);
    auto signatures = Triples(hadronic, leptonic, higgs_pairs, [&](Quintet const & quintet_1, Quintet const & quintet_2) {
        Decuplet55 decuplet(quintet_1, quintet_2);
        if (decuplet.Overlap()) throw Overlap();
        return decuplet;
    }, [&](Decuplet55 const & decuplet, Quartet22 const & quartet) {
        Quattuordecuplet554 quattuordecuplet;
        quattuordecuplet.SetMultiplets12(decuplet, quartet);
        if (quattuordecuplet.Overlap()) throw Overlap();
        return function(quattuordecuplet);
    });
//     static int sig = 0;
//     static int eve = 0;
//     ++eve;
//     if (!signatures.empty()) ++sig;
//     double fraction = double(sig) / eve;
//     ERROR(signatures.size(), hadronic.size(), leptonic.size(), higgs_pairs.size(), fraction);
    return signatures;
}
bool Aliens::isHitBy(const ShapeObject& object)
{
    if( ! object.isVisible())
    {
        return false;
    }

    std::vector<Alien>::iterator i = std::find_if(aliens_.begin(), aliens_.end(), Overlap(object.getBoundary()));

    if(i == aliens_.end())
    {
        return false;
    }

    aliens_.erase(i);
    return true;
}
std::vector<Sextet33> TopLeptonicPair::Multiplets(boca::Event const& event, boca::PreCuts const&, TMVA::Reader const& reader)
{
    auto triplets = top_leptonic_reader_.Multiplets(event);
    INFO(triplets.size());
    auto  sextets = UnorderedPairs(triplets, [&](Triplet const & triplet_1, Triplet const & triplet_2) {
        Quartet22 quartet(Doublet(triplet_1.Singlet(), triplet_1.Doublet().Jet()), Doublet(triplet_2.Singlet(), triplet_2.Doublet().Jet()));
        if (quartet.Overlap()) throw Overlap();
        quartet.Doublet1().SetBdt(triplet_1.Bdt());
        quartet.Doublet2().SetBdt(triplet_2.Bdt());
        WimpMass wimp_mass;
//             for (auto sextet : wimp_mass.Sextets(quartet, event.MissingEt())) {
        Sextet33 sextet = wimp_mass.Fake(quartet);
        sextet.SetBdt(Bdt(sextet, reader));
        return sextet;
//             }
    });
    INFO(sextets.size());
    return sextets;
}
Пример #26
0
void
spawn_planet (void)
{
	HELEMENT hPlanetElement;
	
	hPlanetElement = AllocElement ();
	if (hPlanetElement)
	{
		ELEMENT *PlanetElementPtr;
		extern FRAME planet[];

		LockElement (hPlanetElement, &PlanetElementPtr);
		PlanetElementPtr->playerNr = NEUTRAL_PLAYER_NUM;
		PlanetElementPtr->hit_points = 200;
		PlanetElementPtr->state_flags = APPEARING;
		PlanetElementPtr->life_span = NORMAL_LIFE + 1;
		SetPrimType (&DisplayArray[PlanetElementPtr->PrimIndex], STAMP_PRIM);
		PlanetElementPtr->current.image.farray = planet;
		PlanetElementPtr->current.image.frame =
				PlanetElementPtr->current.image.farray[0];
		PlanetElementPtr->collision_func = collision;
		PlanetElementPtr->postprocess_func =
				(void (*) (struct element *ElementPtr))CalculateGravity;
		ZeroVelocityComponents (&PlanetElementPtr->velocity);
		do
		{
			PlanetElementPtr->current.location.x =
					WRAP_X (DISPLAY_ALIGN_X (TFB_Random ()));
			PlanetElementPtr->current.location.y =
					WRAP_Y (DISPLAY_ALIGN_Y (TFB_Random ()));
		} while (CalculateGravity (PlanetElementPtr)
				|| Overlap (PlanetElementPtr));
		PlanetElementPtr->mass_points = PlanetElementPtr->hit_points;

		PlanetElementPtr->triggers_teleport_safety = TRUE;

		UnlockElement (hPlanetElement);

		PutElement (hPlanetElement);
	}
}
Пример #27
0
int Heuristic::run() const
{
  const int n = instance_.num_words();
  std::vector<Overlap> overlaps;

  std::vector<bool> prefix_used(n, false);
  std::vector<bool> suffix_used(n, false);
  std::vector<int> next(n, -1);

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i == j)
        continue;
      overlaps.push_back(Overlap(instance_.ov(i, j), i, j));
    }
  }

  std::sort(overlaps.begin(), overlaps.end());
  FindUnion fu(n);
  int size = 0;


  while(!overlaps.empty()){
    Overlap cur = overlaps.back();
    overlaps.pop_back();

    if(prefix_used[cur.right] || suffix_used[cur.left])
      continue;

    if(fu.find(cur.right) == fu.find(cur.left))
      continue;
    
    prefix_used[cur.right] = true;    
    suffix_used[cur.left] = true;
    next[cur.left] = cur.right;
    fu.sum(cur.left, cur.right);
    size += instance_[cur.left].size() - cur.len;
  }
  
  return size; 
}
Пример #28
0
std::vector<int> CDecalsDrawerGL4::CandidatesForOverlap() const
{
	std::vector<int> candidatesForOverlap;
	std::vector<bool> decalsInserted(decals.size(), false);

	for (int i: waitingDecalsForOverlapTest) {
		const Decal& d1 = decals[i];

		if (!d1.IsValid())
			continue;

		for (int j = 0; j < decals.size(); ++j) {
			const Decal& d2 = decals[j];

			if (!d2.IsValid())
				continue;

			if (decalsInserted[i] && decalsInserted[j])
				continue;

			if (i == j)
				continue;

			if (!Overlap(d1, d2))
				continue;

			if (!decalsInserted[i]) {
				decalsInserted[i] = true;
				candidatesForOverlap.push_back(i);
			}
			if (!decalsInserted[j]) {
				decalsInserted[j] = true;
				candidatesForOverlap.push_back(j);
			}
		}
	}

	return candidatesForOverlap;
}
Пример #29
0
void TopWindow::SerializePlacement(Stream& s, bool reminimize)
{
	GuiLock __;
#ifndef PLATFORM_WINCE
	int version = 1;
	s / version;
	Rect rect = GetRect();
	s % overlapped % rect;
	bool mn = state == MINIMIZED;
	bool mx = state == MAXIMIZED;
	bool fs = fullscreen;	// 12-05-23 Tom added fullscreen serialization
	if(version >= 1)
		s.Pack(mn, mx, fs);		// 12-05-23 Tom changed from: s.Pack(mn, mx);
	else
		s.Pack(mn, mx);
	LLOG("TopWindow::SerializePlacement / " << (s.IsStoring() ? "write" : "read"));
	LLOG("minimized = " << mn << ", maximized = " << mx << ", fullscreen = " << fs); // 12-05-23 Tom extended with fullscreen
	LLOG("rect = " << rect << ", overlapped = " << overlapped);
	if(s.IsLoading()) {
		rect = overlapped;
		Rect limit = GetVirtualWorkArea();
		Rect outer = rect;
		::AdjustWindowRect(outer, WS_OVERLAPPEDWINDOW, FALSE);
		limit.left   += rect.left   - outer.left;
		limit.top    += rect.top    - outer.top;
		limit.right  += rect.right  - outer.right;
		limit.bottom += rect.bottom - outer.bottom;
		Size sz = min(rect.Size(), limit.Size());
		rect = RectC(
			minmax(rect.left, limit.left, limit.right - sz.cx),
			minmax(rect.top,  limit.top,  limit.bottom - sz.cy),
			sz.cx, sz.cy);

		Overlap();
		SetRect(rect);
		
		if(mn && reminimize){
			state = MINIMIZED;
			//Minimize(); // 12-05-23 Tom removed
		}
		if(mx){
			state = MAXIMIZED;
			//Maximize(); // 12-05-23 Tom removed
		}
		if(IsOpen()) {
			switch(state) {
				case MINIMIZED:
					Minimize();
					break;
				case MAXIMIZED:
					Maximize();
					break;
			}
/*			WINDOWPLACEMENT wp;
			memset(&wp,0,sizeof(WINDOWPLACEMENT));
			wp.length=sizeof(WINDOWPLACEMENT);
			wp.showCmd = state==MINIMIZED ? SW_MINIMIZE : state==MAXIMIZED ? SW_MAXIMIZE : SW_RESTORE;
			wp.rcNormalPosition.left=rect.left;
			wp.rcNormalPosition.top=rect.top;
			wp.rcNormalPosition.right=rect.right;
			wp.rcNormalPosition.bottom=rect.bottom;
			::SetWindowPlacement(GetHWND(),&wp);
*/
			if(fs) {
				Overlap(); // Needed to restore normal position before fullscreen mode
				FullScreen(fs); // 12-05-23 Tom added for fullscreen serialization
			}
		}
		else // 12-05-23 Tom added for fullscreen serialization
			fullscreen=fs; // 12-05-23 Tom added for fullscreen serialization
	}
#endif
}
bool Aliens::hits(const ShapeObject& object)
{
    return std::find_if(bullets_.begin(), bullets_.end(), Overlap(object.getBoundary())) != bullets_.end();
}