forked from organicmaps/organicmaps
Add more possible input values for GetScaleIndex and dependent functions
(GetLimitRect, ...). -1 : best geometry -2 : worst geometry
This commit is contained in:
parent
be79e7763a
commit
3fa1f70bf5
2 changed files with 43 additions and 22 deletions
|
@ -580,39 +580,53 @@ namespace
|
|||
int FeatureType::GetScaleIndex(int scale) const
|
||||
{
|
||||
int const count = m_header->GetScalesCount();
|
||||
if (scale == -1) return count-1;
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
if (scale <= m_header->GetScale(i))
|
||||
return i;
|
||||
return -1;
|
||||
switch (scale)
|
||||
{
|
||||
case -2: return 0;
|
||||
case -1: return count-1;
|
||||
default:
|
||||
for (int i = 0; i < count; ++i)
|
||||
if (scale <= m_header->GetScale(i))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int FeatureType::GetScaleIndex(int scale, offsets_t const & offsets) const
|
||||
{
|
||||
if (scale == -1)
|
||||
int ind = -1;
|
||||
int const count = static_cast<int>(offsets.size());
|
||||
|
||||
switch (scale)
|
||||
{
|
||||
case -2:
|
||||
// Choose the worst existing geometry.
|
||||
ind = count-1;
|
||||
while (ind >= 0 && offsets[ind] == kInvalidOffset) --ind;
|
||||
break;
|
||||
|
||||
case -1:
|
||||
// Choose the best geometry for the last visible scale.
|
||||
int i = offsets.size()-1;
|
||||
while (i >= 0 && offsets[i] == kInvalidOffset) --i;
|
||||
if (i >= 0)
|
||||
return i;
|
||||
else
|
||||
CHECK ( false, ("Feature should have any geometry ...") );
|
||||
}
|
||||
else
|
||||
{
|
||||
ind = 0;
|
||||
while (ind < count && offsets[ind] == kInvalidOffset) ++ind;
|
||||
break;
|
||||
|
||||
default:
|
||||
for (size_t i = 0; i < m_header->GetScalesCount(); ++i)
|
||||
{
|
||||
if (scale <= m_header->GetScale(i))
|
||||
{
|
||||
if (offsets[i] != kInvalidOffset)
|
||||
return i;
|
||||
else
|
||||
break;
|
||||
}
|
||||
return (offsets[i] != kInvalidOffset ? i : -1);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
if (ind >= 0 && ind < count)
|
||||
return ind;
|
||||
else
|
||||
{
|
||||
CHECK ( false, ("Feature should have any geometry ...") );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
|
|
|
@ -443,8 +443,15 @@ private:
|
|||
|
||||
void ReadOffsets(ArrayByteSource & src, uint8_t mask, offsets_t & offsets) const;
|
||||
|
||||
/// Get the index for geometry serialization.
|
||||
/// @param[in] scale:
|
||||
/// -1 : index for the best geometry
|
||||
/// -2 : index for the worst geometry
|
||||
/// default : needed geometry
|
||||
//@{
|
||||
int GetScaleIndex(int scale) const;
|
||||
int GetScaleIndex(int scale, offsets_t const & offset) const;
|
||||
//@}
|
||||
|
||||
mutable offsets_t m_ptsOffsets, m_trgOffsets;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue