[search] Add angle from center of viewport to the return result.
This commit is contained in:
parent
90a79d1952
commit
77be271e39
5 changed files with 33 additions and 17 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "intermediate_result.hpp"
|
||||
#include "../indexer/feature_rect.hpp"
|
||||
#include "../indexer/mercator.hpp"
|
||||
#include "../geometry/angles.hpp"
|
||||
#include "../geometry/distance_on_sphere.hpp"
|
||||
#include "../base/string_utils.hpp"
|
||||
|
||||
|
@ -21,7 +22,8 @@ IntermediateResult::IntermediateResult(m2::RectD const & viewportRect,
|
|||
feature.ForEachTypeRef(types);
|
||||
ASSERT_GREATER(types.m_size, 0, ());
|
||||
m_type = types.m_types[0];
|
||||
m_distance = ResultDistance(viewportRect, m_rect);
|
||||
m_distance = ResultDistance(viewportRect.Center(), m_rect.Center());
|
||||
m_direction = ResultDirection(viewportRect.Center(), m_rect.Center());
|
||||
}
|
||||
|
||||
bool IntermediateResult::operator < (IntermediateResult const & o) const
|
||||
|
@ -38,22 +40,25 @@ Result IntermediateResult::GenerateFinalResult() const
|
|||
#ifdef DEBUG
|
||||
return Result(m_str
|
||||
+ ' ' + strings::to_string(m_distance * 0.001)
|
||||
+ ' ' + strings::to_string(m_direction / math::pi * 180.0)
|
||||
+ ' ' + strings::to_string(m_matchPenalty)
|
||||
+ ' ' + strings::to_string(m_minVisibleScale),
|
||||
#else
|
||||
return Result(m_str,
|
||||
#endif
|
||||
m_type, m_rect, m_distance);
|
||||
m_type, m_rect, m_distance, m_direction);
|
||||
}
|
||||
|
||||
double IntermediateResult::ResultDistance(m2::RectD const & viewportRect,
|
||||
m2::RectD const & featureRect)
|
||||
double IntermediateResult::ResultDistance(m2::PointD const & a, m2::PointD const & b)
|
||||
{
|
||||
m2::PointD const a = viewportRect.Center();
|
||||
m2::PointD const b = featureRect.Center();
|
||||
return ms::DistanceOnEarth(MercatorBounds::YToLat(a.y), MercatorBounds::XToLon(a.x),
|
||||
MercatorBounds::YToLat(b.y), MercatorBounds::XToLon(b.x));
|
||||
}
|
||||
|
||||
double IntermediateResult::ResultDirection(m2::PointD const & a, m2::PointD const & b)
|
||||
{
|
||||
return ang::AngleTo(a, b);
|
||||
}
|
||||
|
||||
} // namespace search::impl
|
||||
} // namespace search
|
||||
|
|
|
@ -21,8 +21,10 @@ public:
|
|||
|
||||
Result GenerateFinalResult() const;
|
||||
|
||||
static double ResultDistance(m2::RectD const & viewportRect,
|
||||
m2::RectD const & featureRect);
|
||||
static double ResultDistance(m2::PointD const & viewportCenter,
|
||||
m2::PointD const & featureCenter);
|
||||
static double ResultDirection(m2::PointD const & viewportCenter,
|
||||
m2::PointD const & featureCenter);
|
||||
|
||||
private:
|
||||
string m_str;
|
||||
|
@ -31,6 +33,7 @@ private:
|
|||
int m_matchPenalty;
|
||||
int m_minVisibleScale;
|
||||
double m_distance;
|
||||
double m_direction;
|
||||
};
|
||||
|
||||
} // namespace search::impl
|
||||
|
|
|
@ -114,7 +114,9 @@ void Query::Search(function<void (Result const &)> const & f)
|
|||
MercatorBounds::LonToX(lon + precision),
|
||||
MercatorBounds::LatToY(lat + precision));
|
||||
f(Result("(" + strings::to_string(lat) + ", " + strings::to_string(lon) + ")",
|
||||
0, rect, IntermediateResult::ResultDistance(m_viewport, rect)));
|
||||
0, rect,
|
||||
IntermediateResult::ResultDistance(m_viewport.Center(), rect.Center()),
|
||||
IntermediateResult::ResultDirection(m_viewport.Center(), rect.Center())));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,9 @@ namespace search
|
|||
{
|
||||
|
||||
Result::Result(string const & str, uint32_t featureType, m2::RectD const & featureRect,
|
||||
double distance)
|
||||
: m_str(str), m_featureRect(featureRect), m_featureType(featureType), m_disance(distance)
|
||||
double distanceFromCenter, double directionFromCenter)
|
||||
: m_str(str), m_featureRect(featureRect), m_featureType(featureType),
|
||||
m_distanceFromCenter(distanceFromCenter), m_directionFromCenter(directionFromCenter)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -33,10 +34,10 @@ uint32_t Result::GetFetureType() const
|
|||
return m_featureType;
|
||||
}
|
||||
|
||||
double Result::GetDistanceToCenter() const
|
||||
double Result::GetDistanceFromCenter() const
|
||||
{
|
||||
ASSERT_EQUAL(GetResultType(), RESULT_FEATURE, ());
|
||||
return m_disance;
|
||||
return m_distanceFromCenter;
|
||||
}
|
||||
|
||||
string Result::GetSuggestionString() const
|
||||
|
|
|
@ -15,7 +15,8 @@ public:
|
|||
RESULT_SUGGESTION
|
||||
};
|
||||
|
||||
Result(string const & str, uint32_t featureType, m2::RectD const & featureRect, double distance);
|
||||
Result(string const & str, uint32_t featureType, m2::RectD const & featureRect,
|
||||
double distanceFromCenter, double directionFromCenter);
|
||||
Result(string const & str, string const & suggestionStr);
|
||||
|
||||
// String that is displayed in the GUI.
|
||||
|
@ -30,8 +31,11 @@ public:
|
|||
// Type of a feature, if GetResultType() == RESULT_FEATURE.
|
||||
uint32_t GetFetureType() const;
|
||||
|
||||
// Distance to the center of the screen, if GetResultType() == RESULT_FEATURE.
|
||||
double GetDistanceToCenter() const;
|
||||
// Distance from the center of the screen, if GetResultType() == RESULT_FEATURE.
|
||||
double GetDistanceFromCenter() const;
|
||||
|
||||
// Direction from thethe center of the screen in radians, if GetResultType() == RESULT_FEATURE.
|
||||
double GetDirectionFromCenter() const;
|
||||
|
||||
// String writo in the search box.
|
||||
string GetSuggestionString() const;
|
||||
|
@ -40,7 +44,8 @@ private:
|
|||
string m_str;
|
||||
m2::RectD m_featureRect;
|
||||
uint32_t m_featureType;
|
||||
double m_disance;
|
||||
double m_distanceFromCenter;
|
||||
double m_directionFromCenter;
|
||||
string m_suggestionStr;
|
||||
};
|
||||
|
||||
|
|
Reference in a new issue