本文整理汇总了C++中std::list::size方法的典型用法代码示例。如果您正苦于以下问题:C++ list::size方法的具体用法?C++ list::size怎么用?C++ list::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::list
的用法示例。
在下文中一共展示了list::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: size
std::list<Pingu*>::size_type size () { return pingus.size (); }
示例2: getBankerInChargingDB
void getBankerInChargingDB() {
float countOfBanker = 0;
float countOfNeutralBanker = 0;
float countOfNagtiveBanker = 0;
float countOfPositiveBanker = 0;
std::list<std::string> fileNames;
getAllDatabase(fileNames, "dbs");
fileNames.sort();
std::list<std::string> listOfDBs;
std::list<std::string>::iterator itrOfDBNames = fileNames.begin();
TurnOverDiscover* pTurnOverDiscover = NULL;
for (int i = 0; i < fileNames.size(); i++) {
pTurnOverDiscover = new TurnOverDiscover(*itrOfDBNames, "FilterResult20W");
/*
if (pTurnOverDiscover->isTodayBankerInCharge(DAY_OF_TARGET)) {
if (pTurnOverDiscover->isTodayNeutralBankerInCharge(DAY_OF_TARGET)) {
//printf("Is Positive:%s\n", itrOfDBNames->c_str());
countOfNeutralBanker += 1;
}
if (pTurnOverDiscover->isTodayNagtiveBankerInCharge(DAY_OF_TARGET)) {
//printf("Is Nagtive:%s\n", itrOfDBNames->c_str());
countOfNagtiveBanker += 1;
}
if (pTurnOverDiscover->isTodayPositiveBankerInCharge(DAY_OF_TARGET)) {
//printf("Is Positive:%s\n", itrOfDBNames->c_str());
std::vector<double> bankerTurnOvers;
pTurnOverDiscover->getBankerTurnOvers(bankerTurnOvers);
//printf("BankerTurnOvers, Buy:%lf, Sale:%lf\n", bankerTurnOvers[0], bankerTurnOvers[1]);
PositiveDB tmpPositiveDB;
tmpPositiveDB.Name = *itrOfDBNames;
tmpPositiveDB.BankerBuyingTurnOver = bankerTurnOvers[0];
tmpPositiveDB.BankerSalingTurnOver = bankerTurnOvers[1];
tmpPositiveDB.RatioBS = bankerTurnOvers[0]/bankerTurnOvers[1];
sPositiveDBs.push_back(tmpPositiveDB);
countOfPositiveBanker += 1;
}
countOfBanker += 1;
}
*/
pTurnOverDiscover->updateBankerResultTable();
//if (pTurnOverDiscover->isPreviousDaysSuckIn(20)) {
// printf("isDBBankedInDays for DB:%s\n", itrOfDBNames->c_str());
//}
//printf("updateBankerResultTable for DB:%s\n", itrOfDBNames->c_str());
itrOfDBNames++;
delete pTurnOverDiscover;
pTurnOverDiscover = NULL;
}
//printf("BankerInCharge size:%lf ratio:%lf\n", countOfBanker, countOfBanker / fileNames.size());
//printf("NeutralBanker size:%lf ratio:%lf\n", countOfNeutralBanker ,countOfNeutralBanker / countOfBanker);
//printf("NagtiveBanker size:%lf ratio:%lf\n", countOfNagtiveBanker, countOfNagtiveBanker / countOfBanker);
//printf("PositiveBanker size:%lf ratio:%lf\n", countOfPositiveBanker, countOfPositiveBanker / countOfBanker);
sPositiveDBs.sort(LargeToSmall);
std::list<PositiveDB>::iterator iterPositionDB = sPositiveDBs.begin();
for (int i = 0; i < sPositiveDBs.size(); i++) {
printf("PositiveBanker, name:%s, buying:%lf sale:%lf, ratio:%lf\n", iterPositionDB->Name.c_str(), iterPositionDB->BankerBuyingTurnOver, iterPositionDB->BankerSalingTurnOver, iterPositionDB->RatioBS);
iterPositionDB++;
}
}
示例3: OffsetWithLoops
static void OffsetWithLoops(const TPolyPolygon &pp, TPolyPolygon &pp_new, double inwards_value)
{
Clipper c;
bool inwards = (inwards_value > 0);
bool reverse = false;
double radius = -fabs(inwards_value);
if(inwards)
{
// add a large square on the outside, to be removed later
TPolygon p;
p.push_back(DoubleAreaPoint(-10000.0, -10000.0).int_point());
p.push_back(DoubleAreaPoint(-10000.0, 10000.0).int_point());
p.push_back(DoubleAreaPoint(10000.0, 10000.0).int_point());
p.push_back(DoubleAreaPoint(10000.0, -10000.0).int_point());
c.AddPath(p, ptSubject, true);
}
else
{
reverse = true;
}
for(unsigned int i = 0; i < pp.size(); i++)
{
const TPolygon& p = pp[i];
pts_for_AddVertex.clear();
if(p.size() > 2)
{
if(reverse)
{
for(std::size_t j = p.size()-1; j > 1; j--)MakeLoop(p[j], p[j-1], p[j-2], radius);
MakeLoop(p[1], p[0], p[p.size()-1], radius);
MakeLoop(p[0], p[p.size()-1], p[p.size()-2], radius);
}
else
{
MakeLoop(p[p.size()-2], p[p.size()-1], p[0], radius);
MakeLoop(p[p.size()-1], p[0], p[1], radius);
for(unsigned int j = 2; j < p.size(); j++)MakeLoop(p[j-2], p[j-1], p[j], radius);
}
TPolygon loopy_polygon;
loopy_polygon.reserve(pts_for_AddVertex.size());
for(std::list<DoubleAreaPoint>::iterator It = pts_for_AddVertex.begin(); It != pts_for_AddVertex.end(); It++)
{
loopy_polygon.push_back(It->int_point());
}
c.AddPath(loopy_polygon, ptSubject, true);
pts_for_AddVertex.clear();
}
}
//c.ForceOrientation(false);
c.Execute(ctUnion, pp_new, pftNonZero, pftNonZero);
if(inwards)
{
// remove the large square
if(pp_new.size() > 0)
{
pp_new.erase(pp_new.begin());
}
}
else
{
// reverse all the resulting polygons
TPolyPolygon copy = pp_new;
pp_new.clear();
pp_new.resize(copy.size());
for(unsigned int i = 0; i < copy.size(); i++)
{
const TPolygon& p = copy[i];
TPolygon p_new;
p_new.resize(p.size());
std::size_t size_minus_one = p.size() - 1;
for(unsigned int j = 0; j < p.size(); j++)p_new[j] = p[size_minus_one - j];
pp_new[i] = p_new;
}
}
}
示例4: drop_on_map
void drop_on_map( const Character &c, item_drop_reason reason, const std::list<item> &items,
const tripoint &where )
{
if( items.empty() ) {
return;
}
const std::string ter_name = g->m.name( where );
const bool can_move_there = g->m.passable( where );
if( same_type( items ) ) {
const item &it = items.front();
const int dropcount = items.size() * it.count();
const std::string it_name = it.tname( dropcount );
switch( reason ) {
case item_drop_reason::deliberate:
if( can_move_there ) {
c.add_msg_player_or_npc(
ngettext( "You drop your %1$s on the %2$s.",
"You drop your %1$s on the %2$s.", dropcount ),
ngettext( "<npcname> drops their %1$s on the %2$s.",
"<npcname> drops their %1$s on the %2$s.", dropcount ),
it_name, ter_name
);
} else {
c.add_msg_player_or_npc(
ngettext( "You put your %1$s in the %2$s.",
"You put your %1$s in the %2$s.", dropcount ),
ngettext( "<npcname> puts their %1$s in the %2$s.",
"<npcname> puts their %1$s in the %2$s.", dropcount ),
it_name, ter_name
);
}
break;
case item_drop_reason::too_large:
c.add_msg_if_player(
ngettext( "There's no room in your inventory for the %s, so you drop it.",
"There's no room in your inventory for the %s, so you drop them.", dropcount ),
it_name
);
break;
case item_drop_reason::too_heavy:
c.add_msg_if_player(
ngettext( "The %s is too heavy to carry, so you drop it.",
"The %s is too heavy to carry, so you drop them.", dropcount ),
it_name
);
break;
case item_drop_reason::tumbling:
c.add_msg_if_player(
m_bad,
ngettext( "Your %1$s tumbles to the %2$s.",
"Your %1$s tumble to the %2$s.", dropcount ),
it_name, ter_name
);
break;
}
} else {
switch( reason ) {
case item_drop_reason::deliberate:
if( can_move_there ) {
c.add_msg_player_or_npc(
_( "You drop several items on the %s." ),
_( "<npcname> drops several items on the %s." ),
ter_name
);
} else {
c.add_msg_player_or_npc(
_( "You put several items in the %s." ),
_( "<npcname> puts several items in the %s." ),
ter_name
);
}
break;
case item_drop_reason::too_large:
case item_drop_reason::too_heavy:
case item_drop_reason::tumbling:
c.add_msg_if_player( m_bad, _( "Some items tumble to the %s." ), ter_name );
break;
}
}
for( const auto &it : items ) {
g->m.add_item_or_charges( where, it );
}
}
示例5: exec
static void exec(OutArcType& oarc, const std::list<T>& vec){
serialize_iterator(oarc,vec.begin(),vec.end(), vec.size());
}
示例6: fpathAStarRoute
ASR_RETVAL fpathAStarRoute(MOVE_CONTROL *psMove, PATHJOB *psJob)
{
ASR_RETVAL retval = ASR_OK;
bool mustReverse = true;
const PathCoord tileOrig(map_coord(psJob->origX), map_coord(psJob->origY));
const PathCoord tileDest(map_coord(psJob->destX), map_coord(psJob->destY));
PathCoord endCoord; // Either nearest coord (mustReverse = true) or orig (mustReverse = false).
std::list<PathfindContext>::iterator contextIterator = fpathContexts.begin();
for (contextIterator = fpathContexts.begin(); contextIterator != fpathContexts.end(); ++contextIterator)
{
if (!contextIterator->matches(psJob->blockingMap, tileDest))
{
// This context is not for the same droid type and same destination.
continue;
}
// We have tried going to tileDest before.
if (contextIterator->map[tileOrig.x + tileOrig.y*mapWidth].iteration == contextIterator->iteration
&& contextIterator->map[tileOrig.x + tileOrig.y*mapWidth].visited)
{
// Already know the path from orig to dest.
endCoord = tileOrig;
}
else
{
// Need to find the path from orig to dest, continue previous exploration.
fpathAStarReestimate(*contextIterator, tileOrig);
endCoord = fpathAStarExplore(*contextIterator, tileOrig);
}
if (endCoord != tileOrig)
{
// orig turned out to be on a different island than what this context was used for, so can't use this context data after all.
continue;
}
mustReverse = false; // We have the path from the nearest reachable tile to dest, to orig.
break; // Found the path! Don't search more contexts.
}
if (contextIterator == fpathContexts.end())
{
// We did not find an appropriate context. Make one.
if (fpathContexts.size() < 30)
{
fpathContexts.push_back(PathfindContext());
}
--contextIterator;
// Init a new context, overwriting the oldest one if we are caching too many.
// We will be searching from orig to dest, since we don't know where the nearest reachable tile to dest is.
fpathInitContext(*contextIterator, psJob->blockingMap, tileOrig, tileOrig, tileDest);
endCoord = fpathAStarExplore(*contextIterator, tileDest);
contextIterator->nearestCoord = endCoord;
}
PathfindContext &context = *contextIterator;
// return the nearest route if no actual route was found
if (context.nearestCoord != tileDest)
{
retval = ASR_NEAREST;
}
// Get route, in reverse order.
static std::vector<Vector2i> path; // Declared static to save allocations.
path.clear();
PathCoord newP;
for (PathCoord p = endCoord; p != context.tileS; p = newP)
{
ASSERT_OR_RETURN(ASR_FAILED, tileOnMap(p.x, p.y), "Assigned XY coordinates (%d, %d) not on map!", (int)p.x, (int)p.y);
ASSERT_OR_RETURN(ASR_FAILED, path.size() < (unsigned)mapWidth*mapHeight, "Pathfinding got in a loop.");
path.push_back(Vector2i(world_coord(p.x) + TILE_UNITS / 2, world_coord(p.y) + TILE_UNITS / 2));
PathExploredTile &tile = context.map[p.x + p.y*mapWidth];
newP = PathCoord(p.x - tile.dx, p.y - tile.dy);
if (p == newP)
{
break; // We stopped moving, because we reached the closest reachable tile to context.tileS. Give up now.
}
}
if (path.empty())
{
// We are probably already in the destination tile. Go to the exact coordinates.
path.push_back(Vector2i(psJob->destX, psJob->destY));
}
else if (retval == ASR_OK)
{
// Found exact path, so use exact coordinates for last point, no reason to lose precision
Vector2i v(psJob->destX, psJob->destY);
if (mustReverse)
{
//.........这里部分代码省略.........
示例7: operator
void operator()( std::list<T> & v ) const
{
simple::serialize<int>::write(v.size());
std::for_each(v.begin(),v.end(),*this);
}
示例8: abrirPista
void abrirPista(int idPista){
thread_pista[idPista] = -1;
if(landList.size()>0) NotifyLandingPlanesThatHadRunWay(idPista, idPista);
else if(takeoffList.size()>0)NotifyTakeOffPlanesThatHadRunWay(idPista, idPista);
}
示例9: alertaFuracao
void alertaFuracao(bool al){
_furacao = al;
if(_furacao == false && takeoffList.size()>0){
NotifyTakeOffPlanesThatHadRunWay(0,1);
}
}
示例10: UpdateAI
void UpdateAI(const uint32 uiDiff)
{
if (!UpdateVictim())
return;
switch (m_uiStage)
{
case 0:
if (m_uiFreezeSlashTimer <= uiDiff)
{
DoCastVictim(SPELL_FREEZE_SLASH);
m_uiFreezeSlashTimer = 15*IN_MILLISECONDS;
} else m_uiFreezeSlashTimer -= uiDiff;
if (m_uiPenetratingColdTimer <= uiDiff)
{
me->CastCustomSpell(RAID_MODE(SPELL_PENETRATING_COLD_10_N, SPELL_PENETRATING_COLD_25_N, SPELL_PENETRATING_COLD_10_H, SPELL_PENETRATING_COLD_25_H) , SPELLVALUE_MAX_TARGETS, RAID_MODE(2, 5));
m_uiPenetratingColdTimer = 20*IN_MILLISECONDS;
} else m_uiPenetratingColdTimer -= uiDiff;
if (m_uiSummonNerubianTimer <= uiDiff && (IsHeroic() || !m_bReachedPhase3))
{
me->CastCustomSpell(SPELL_SUMMON_BURROWER, SPELLVALUE_MAX_TARGETS, RAID_MODE(1, 2, 2, 4));
m_uiSummonNerubianTimer = 45*IN_MILLISECONDS;
} else m_uiSummonNerubianTimer -= uiDiff;
if (IsHeroic() && m_uiNerubianShadowStrikeTimer <= uiDiff)
{
Summons.DoAction(NPC_BURROWER, ACTION_SHADOW_STRIKE);
m_uiNerubianShadowStrikeTimer = 30*IN_MILLISECONDS;
} else m_uiNerubianShadowStrikeTimer -= uiDiff;
if (m_uiSubmergeTimer <= uiDiff && !m_bReachedPhase3 && !me->HasAura(SPELL_BERSERK))
{
m_uiStage = 1;
m_uiSubmergeTimer = 60*IN_MILLISECONDS;
} else m_uiSubmergeTimer -= uiDiff;
break;
case 1:
DoCast(me, SPELL_SUBMERGE_ANUBARAK);
DoCast(me, SPELL_CLEAR_ALL_DEBUFFS);
me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE);
DoScriptText(SAY_BURROWER, me);
m_uiScarabSummoned = 0;
m_uiSummonScarabTimer = 4*IN_MILLISECONDS;
m_uiStage = 2;
break;
case 2:
if (m_uiPursuingSpikeTimer <= uiDiff)
{
DoCast(SPELL_SPIKE_CALL);
// Just to make sure it won't happen again in this phase
m_uiPursuingSpikeTimer = 90*IN_MILLISECONDS;
} else m_uiPursuingSpikeTimer -= uiDiff;
if (m_uiSummonScarabTimer <= uiDiff)
{
/* WORKAROUND
* - The correct implementation is more likely the comment below but it needs spell knowledge
*/
std::list<uint64>::iterator i = m_vBurrowGUID.begin();
uint32 at = urand(0, m_vBurrowGUID.size()-1);
for (uint32 k = 0; k < at; k++)
++i;
if (Creature* pBurrow = Unit::GetCreature(*me, *i))
pBurrow->CastSpell(pBurrow, 66340, false);
m_uiScarabSummoned++;
m_uiSummonScarabTimer = 4*IN_MILLISECONDS;
if (m_uiScarabSummoned == 4) m_uiSummonScarabTimer = RAID_MODE(4, 20)*IN_MILLISECONDS;
/*It seems that this spell have something more that needs to be taken into account
//Need more sniff info
DoCast(SPELL_SUMMON_BEATLES);
// Just to make sure it won't happen again in this phase
m_uiSummonScarabTimer = 90*IN_MILLISECONDS;*/
} else m_uiSummonScarabTimer -= uiDiff;
if (m_uiSubmergeTimer <= uiDiff)
{
m_uiStage = 3;
m_uiSubmergeTimer = 80*IN_MILLISECONDS;
} else m_uiSubmergeTimer -= uiDiff;
break;
case 3:
m_uiStage = 0;
DoCast(SPELL_SPIKE_TELE);
if (Creature* pSpike = Unit::GetCreature(*me, m_uiSpikeGUID))
me->NearTeleportTo(pSpike->GetPositionX(), pSpike->GetPositionY(), pSpike->GetPositionZ(), pSpike->GetOrientation());
Summons.DespawnEntry(NPC_SPIKE);
me->RemoveAurasDueToSpell(SPELL_SUBMERGE_ANUBARAK);
me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE);
DoCast(me, SPELL_EMERGE_ANUBARAK);
me->GetMotionMaster()->MoveChase(me->getVictim());
m_uiSummonNerubianTimer = 10*IN_MILLISECONDS;
m_uiNerubianShadowStrikeTimer = 30*IN_MILLISECONDS;
m_uiSummonScarabTimer = 2*IN_MILLISECONDS;
break;
}
if (!IsHeroic())
//.........这里部分代码省略.........
示例11: ValAttr
void cElXMLTree::GenAccessor
(
bool Recurs,
cElXMLTree * anAnc,
int aProf,
FILE* aFile,
std::list<cElXMLTree *> & aList, // Empile les fils pour imbrication
bool isH
)
{
// std::cout << "GA " << mValTag << "\n";
const std::string & aPat = ValAttr("Nb");
aList.push_back(this);
if (Recurs && ((aProf==0) || (aPat=="1") || (aPat=="?")))
{
for
(
std::list<cElXMLTree *>::iterator itF=mFils.begin();
itF != mFils.end();
itF++
)
{
if (TagFilsIsClass((*itF)->mValTag))
{
std::string aDefAccFils = "true";
bool GenAccFils = ((*itF)->ValAttr("AccessorFils",aDefAccFils)=="true");
if ( ! HasAttr("RefType"))
(*itF)->GenAccessor(GenAccFils,anAnc,aProf+1,aFile,aList,isH);
}
}
}
if (aProf==0)
return;
fprintf(aFile,"\n");
std::string aPortee = isH ? "" : (anAnc->NameOfClass()+"::");
for (int aK=0 ; aK<2; aK++) // aK : 1 Const - 0 Non Const
{
std::string aContsQual = (aK==0) ? "" : "const ";
// if (aProf !=1) fprintf(aFileH," // %d ",aProf);
if (isH) fprintf(aFile," ");
fprintf
(
aFile,
"%s%s & %s%s()%s",
aContsQual.c_str(),
NameImplemOfClass().c_str(),
aPortee.c_str(),
mValTag.c_str(),
aContsQual.c_str()
);
if (isH)
{
fprintf(aFile,";\n");
}
else
{
fprintf(aFile,"\n");
fprintf(aFile,"{\n");
fprintf(aFile," return ");
if (aProf ==1)
fprintf(aFile,"m%s",mValTag.c_str());
else
{
std::list<cElXMLTree *>::iterator itT = aList.begin();
itT++;
int aK=0;
int aL = (int) aList.size();
while (itT != aList.end())
{
if (aK!=0) fprintf(aFile,".");
fprintf(aFile,"%s()",(*itT)->mValTag.c_str());
const std::string & aPatLoc = (*itT)->ValAttr("Nb");
if ((aK!= aL-2) && (aPatLoc == "?"))
fprintf(aFile,".Val()");
itT++;
aK++;
}
}
fprintf(aFile,";\n");
fprintf(aFile,"}\n\n");
}
}
aList.pop_back();
}
示例12: output_html_results
void output_html_results(bool show_description, const std::string& tagname)
{
std::stringstream os;
if(result_list.size())
{
//
// start by outputting the table header:
//
os << "<table border=\"1\" cellspacing=\"1\">\n";
os << "<tr><td><strong>Expression</strong></td>";
if(show_description)
os << "<td><strong>Text</strong></td>";
#if defined(BOOST_HAS_GRETA)
if(time_greta == true)
os << "<td><strong>GRETA</strong></td>";
if(time_safe_greta == true)
os << "<td><strong>GRETA<BR>(non-recursive mode)</strong></td>";
#endif
if(time_boost == true)
os << "<td><strong>Boost</strong></td>";
if(time_localised_boost == true)
os << "<td><strong>Boost + C++ locale</strong></td>";
#if defined(BOOST_HAS_POSIX)
if(time_posix == true)
os << "<td><strong>POSIX</strong></td>";
#endif
#ifdef BOOST_HAS_PCRE
if(time_pcre == true)
os << "<td><strong>PCRE</strong></td>";
#endif
#ifdef BOOST_HAS_XPRESSIVE
if(time_xpressive == true)
os << "<td><strong>Dynamic Xpressive</strong></td>";
#endif
#ifndef BOOST_NO_CXX11_HDR_REGEX
if(time_std == true)
os << "<td><strong>std::regex</strong></td>";
#endif
os << "</tr>\n";
//
// Now enumerate through all the test results:
//
std::list<results>::const_iterator first, last;
first = result_list.begin();
last = result_list.end();
while(first != last)
{
os << "<tr><td><code>" << html_quote(first->expression) << "</code></td>";
if(show_description)
os << "<td>" << html_quote(first->description) << "</td>";
#if defined(BOOST_HAS_GRETA)
if(time_greta == true)
{
print_result(os, first->greta_time, first->factor);
if(first->greta_time > 0)
{
greta_total += first->greta_time / first->factor;
++greta_test_count;
}
}
if(time_safe_greta == true)
{
print_result(os, first->safe_greta_time, first->factor);
if(first->safe_greta_time > 0)
{
safe_greta_total += first->safe_greta_time / first->factor;
++safe_greta_test_count;
}
}
#endif
if(time_boost == true)
{
print_result(os, first->boost_time, first->factor);
if(first->boost_time > 0)
{
boost_total += first->boost_time / first->factor;
++boost_test_count;
}
}
if(time_localised_boost == true)
{
print_result(os, first->localised_boost_time, first->factor);
if(first->localised_boost_time > 0)
{
locale_boost_total += first->localised_boost_time / first->factor;
++locale_boost_test_count;
}
}
if(time_posix == true)
{
print_result(os, first->posix_time, first->factor);
if(first->posix_time > 0)
{
posix_total += first->posix_time / first->factor;
++posix_test_count;
}
}
#if defined(BOOST_HAS_PCRE)
if(time_pcre == true)
//.........这里部分代码省略.........
示例13: e
bool ccContourExtractor::ExtractConcaveHull2D( std::vector<Vertex2D>& points,
std::list<Vertex2D*>& hullPoints,
ContourType contourType,
bool allowMultiPass,
PointCoordinateType maxSquareEdgeLength/*=0*/,
bool enableVisualDebugMode/*=false*/,
double maxAngleDeg/*=0.0*/)
{
//first compute the Convex hull
if (!CCLib::PointProjectionTools::extractConvexHull2D(points,hullPoints))
return false;
//do we really need to compute the concave hull?
if (hullPoints.size() < 2 || maxSquareEdgeLength < 0)
return true;
unsigned pointCount = static_cast<unsigned>(points.size());
std::vector<HullPointFlags> pointFlags;
try
{
pointFlags.resize(pointCount, POINT_NOT_USED);
}
catch(...)
{
//not enough memory
return false;
}
double minCosAngle = maxAngleDeg <= 0 ? -1.0 : std::cos(maxAngleDeg * M_PI / 180.0);
//hack: compute the theoretical 'minimal' edge length
PointCoordinateType minSquareEdgeLength = 0;
{
CCVector2 minP, maxP;
for (size_t i=0; i<pointCount; ++i)
{
const Vertex2D& P = points[i];
if (i)
{
minP.x = std::min(P.x,minP.x);
minP.y = std::min(P.y,minP.y);
maxP.x = std::max(P.x,maxP.x);
maxP.y = std::max(P.y,maxP.y);
}
else
{
minP = maxP = P;
}
}
minSquareEdgeLength = (maxP - minP).norm2() / static_cast<PointCoordinateType>(1.0e7); //10^-7 of the max bounding rectangle side
minSquareEdgeLength = std::min(minSquareEdgeLength, maxSquareEdgeLength / 10);
//we remove very small edges
for (VertexIterator itA = hullPoints.begin(); itA != hullPoints.end(); ++itA)
{
VertexIterator itB = itA; ++itB;
if (itB == hullPoints.end())
itB = hullPoints.begin();
if ((**itB-**itA).norm2() < minSquareEdgeLength)
{
pointFlags[(*itB)->index] = POINT_FROZEN;
hullPoints.erase(itB);
}
}
if (contourType != FULL)
{
//we will now try to determine which part of the contour is the 'upper' one and which one is the 'lower' one
//search for the min and max vertices
VertexIterator itLeft = hullPoints.begin();
VertexIterator itRight = hullPoints.begin();
{
for (VertexIterator it = hullPoints.begin(); it != hullPoints.end(); ++it)
{
if ((*it)->x < (*itLeft)->x || ((*it)->x == (*itLeft)->x && (*it)->y < (*itLeft)->y))
{
itLeft = it;
}
if ((*it)->x > (*itRight)->x || ((*it)->x == (*itRight)->x && (*it)->y < (*itRight)->y))
{
itRight = it;
}
}
}
assert(itLeft != itRight);
//find the right way to go
{
VertexIterator itBefore = itLeft;
if (itBefore == hullPoints.begin())
itBefore = hullPoints.end(); --itBefore;
VertexIterator itAfter = itLeft; ++itAfter;
if (itAfter == hullPoints.end())
itAfter = hullPoints.begin();
bool forward = ((**itBefore - **itLeft).cross(**itAfter - **itLeft) < 0 && contourType == LOWER);
if (!forward)
std::swap(itLeft,itRight);
}
//.........这里部分代码省略.........
示例14: is_empty
/// Check if the memory block is empty.
inline bool is_empty() const
{
return (free_subblocks_.size() == 1 &&
free_subblocks_.front().first == 0 &&
free_subblocks_.front().second == size_);
}
示例15: ManageSelection
bool IGFrame::ManageSelection (const IGLibrary::SELECTIONPARAMS& selParams, const std::list<POINT>& lPts)
{
// Request thread access
if (!RequestAccess ())
return false;
CxImage *pCurrentLayer = GetWorkingLayer();
if (!pCurrentLayer)
return false;
int nCurLayerId = (int)pCurrentLayer->GetId();
int nCurLayerWidth = (int)pCurrentLayer->GetWidth();
int nCurLayerHeight = (int)pCurrentLayer->GetHeight();
_ASSERTE ((nCurLayerId >= 0) && L"Current layer is not identified");
if (nCurLayerId < 0)
return false;
bool bRes = false;
POINT ptTopLeft = {0, 0};
POINT ptBottomRight = {-1, -1};
IGSELECTIONENUM eSelectionType = selParams.eSelectionType;
if (((eSelectionType & IGSELECTION_SQUARE) == IGSELECTION_SQUARE) ||
((eSelectionType & IGSELECTION_LASSO) == IGSELECTION_LASSO))
{
if (lPts.size() > 0)
{
bool bAllEqual = true;
for (list <POINT>::const_iterator itPt = lPts.cbegin(); itPt != lPts.cend(); ++itPt)
{
if (((*itPt).x != lPts.front().x) || ((*itPt).y != lPts.front().y))
bAllEqual = false;
}
if (bAllEqual)
eSelectionType = IGSELECTION_CLEAR;
}
}
if ((eSelectionType & IGSELECTION_CLEAR) == IGSELECTION_CLEAR)
{
if ((eSelectionType & IGSELECTION_INVERT) == IGSELECTION_INVERT)
bRes = pCurrentLayer->SelectionInvert();
else
bRes = pCurrentLayer->SelectionDelete();
}
else
{
if ((eSelectionType & IGSELECTION_REPLACE) == IGSELECTION_REPLACE)
pCurrentLayer->SelectionClear();
BYTE level = ((eSelectionType & IGSELECTION_REMOVE) == IGSELECTION_REMOVE) ? 0 : 255;
std::list<POINT> lConvertedPts (lPts);
// convert IG coordinates to Cx coordinates
IGConvertible::FromIGtoCxCoords(lConvertedPts, pCurrentLayer->GetHeight());
// apply selection
if ((eSelectionType & IGSELECTION_SQUARE) == IGSELECTION_SQUARE)
{
if (lPts.size() != 2)
return false;
// read rectangle coordinates
ptTopLeft = lConvertedPts.front();
ptBottomRight = lConvertedPts.back();
int nPosX = ptTopLeft.x;
int nPosY = ptBottomRight.y;
RECT rcSel;
rcSel.left = nPosX; rcSel.top = nPosY;
nPosX = ptBottomRight.x;
nPosY = ptTopLeft.y;
rcSel.right = nPosX; rcSel.bottom = nPosY;
// adjust rectangle orientation
int nWidth = rcSel.right - rcSel.left;
int nHeight = rcSel.top - rcSel.bottom;
nWidth = (nWidth < 0) ? -1 * nWidth : nWidth;
nHeight = (nHeight < 0) ? -1 * nHeight : nHeight;
rcSel.left = (rcSel.left < rcSel.right) ? rcSel.left : rcSel.right;
rcSel.bottom = (rcSel.bottom < rcSel.top) ? rcSel.bottom : rcSel.top;
rcSel.right = rcSel.left + nWidth;
rcSel.top = rcSel.bottom + nHeight;
// test if rectangle is inside the frame
if ((rcSel.right < 0) || (rcSel.left >= nCurLayerWidth)
|| (rcSel.top < 0) || (rcSel.bottom >= nCurLayerHeight))
return false; // selection out of bounds
// adjust bounds
rcSel.left = (rcSel.left < 0) ? 0 : rcSel.left;
rcSel.right = (rcSel.right >= nCurLayerWidth) ? nCurLayerWidth - 1 : rcSel.right;
rcSel.bottom = (rcSel.bottom < 0) ? 0 : rcSel.bottom;
rcSel.top = (rcSel.top >= nCurLayerHeight) ? nCurLayerHeight - 1 : rcSel.top;
// add the selection
bRes = pCurrentLayer->SelectionAddRect (rcSel, level);
}
else if ((eSelectionType & IGSELECTION_LASSO) == IGSELECTION_LASSO)
{
bRes = pCurrentLayer->SelectionAddPolygon (lConvertedPts, level);
}
else if ((eSelectionType & IGSELECTION_MAGIC) == IGSELECTION_MAGIC)
{
bRes = pCurrentLayer->SelectionAddMagic (lConvertedPts.front(), level, selParams.nTolerance);
}
else if ((eSelectionType & IGSELECTION_FACES) == IGSELECTION_FACES)
{
bRes = pCurrentLayer->SelectionAddFaces (level);
}
else if ((eSelectionType & IGSELECTION_EYES) == IGSELECTION_EYES)
{
//.........这里部分代码省略.........