1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
struct Plage
{
Plage(CRect r,int n){RectPlage=r;nIndice=n;}
CRect RectPlage; // le rectangle des pour les <> plages
int nIndice; // l'indice dans le tableau CArray correspondant a la plage graphique
};
CPoint ptFind; // le point a rechercher issu du clic souris .
// la fonction de recherche.
bool InRegion(const Plage& rgn)
{
return (rgn.RectPlage.PtInRect(ptFind)?true:false);
}
// foncteur servant à trier suivant les rectangles.
struct SortByRect
{
bool operator ()(const Plage& p1, const Plage& p2) const
{
// trié suivant l'axe des x a voir suivant les cas.
return p1.RectPlage.left < p2.RectPlage.left;
}
};
std::vector<Plage> v; // le tableau
// le remplissage au debut des plages graphiques avec correspondance de l'indice du CArray.
v.push_back(Plage(CRect(20,20,30,30),1));
v.push_back(Plage(CRect(10,10,15,15),0));
// Tri une fois .
std::sort(v.begin(), v.end(), SortByRect());
// la recherche de l'indice ...
ptFind=CPoint(21,29); // le point a rechercher
std::vector<Plage>::iterator p=std::find_if(v.begin(), v.end(), InRegion);
TRACE("\n%d",p->nIndice); |
Partager