[generator:regions] Fix commutative property of RelateByWeight(): -1 or 1 return value

This commit is contained in:
Anatoly Serdtcev 2019-08-12 12:12:33 +03:00 committed by LaGrunge
parent d162b877e8
commit d5b6f4410d
5 changed files with 30 additions and 7 deletions

View file

@ -102,12 +102,28 @@ int CountrySpecifier::RelateByWeight(LevelRegion const & l, LevelRegion const &
return 1;
}
}
if (lAdminLevel != AdminLevel::Unknown)
return 1;
if (rAdminLevel != AdminLevel::Unknown)
return -1;
else
{
if (lAdminLevel != AdminLevel::Unknown)
return 1;
else if (rAdminLevel != AdminLevel::Unknown)
return -1;
}
return 0;
// Let leveled region is derived region.
if (lLevel != PlaceLevel::Unknown && rLevel == PlaceLevel::Unknown)
return -1;
if (rLevel != PlaceLevel::Unknown && lLevel == PlaceLevel::Unknown)
return 1;
// Let place-marked region is derived region.
if (lPlaceType != PlaceType::Unknown && rPlaceType == PlaceType::Unknown)
return -1;
if (rPlaceType != PlaceType::Unknown && lPlaceType == PlaceType::Unknown)
return 1;
CHECK_NOT_EQUAL(l.GetOriginId(), r.GetOriginId(), ());
return l.GetOriginId() < r.GetOriginId() ? 1 : -1;
}
} // namespace regions
} // namespace generator

View file

@ -16,8 +16,7 @@ public:
virtual void AdjustRegionsLevel(Node::PtrList & outers);
PlaceLevel GetLevel(Region const & region) const;
// Return -1 - |l| is under place of |r|, 0 - undefined relation, 1 - |r| is under place of |l|.
// Non-transitive.
// Return -1 - |l| is under place of |r|, 1 - |r| is under place of |l|.
virtual int RelateByWeight(LevelRegion const & l, LevelRegion const & r) const;
static PlaceLevel GetLevel(PlaceType placeType);

View file

@ -72,6 +72,11 @@ base::GeoObjectId Region::GetId() const
return RegionWithData::GetId();
}
base::GeoObjectId Region::GetOriginId() const
{
return RegionWithData::GetId();
}
PlaceType Region::GetPlaceType() const
{
if (m_placeLabel)

View file

@ -32,6 +32,7 @@ public:
std::string GetName(int8_t lang = StringUtf8Multilang::kDefaultCode) const;
base::GeoObjectId GetId() const;
base::GeoObjectId GetOriginId() const;
using RegionWithData::GetAdminLevel;
PlaceType GetPlaceType() const;
boost::optional<std::string> GetIsoCode() const;

View file

@ -174,6 +174,8 @@ Node::Ptr RegionsBuilder::ChooseParent(std::vector<Node::Ptr> const & nodesInAre
}
}
CHECK(!parent || -1 == CompareAffiliation(region, parent->GetData(), countrySpecifier),
(GetRegionNotation(region), GetRegionNotation(parent->GetData())));
return parent;
}