| 179 | } |
| 180 | |
| 181 | drape_ptr<Animation> KineticScroller::CreateKineticAnimation(ScreenBase const & modelView) |
| 182 | { |
| 183 | auto const [dir, velocity] = GetDirectionAndVelocity(modelView); |
| 184 | // Cancel current animation in any case. |
| 185 | Cancel(); |
| 186 | if (velocity < 1E-6) |
| 187 | return {}; |
| 188 | |
| 189 | // Before we start animation we have to convert velocity vector from pixel space to mercator space. |
| 190 | m2::PointD const center = modelView.GlobalRect().GlobalCenter(); |
| 191 | double const offset = (modelView.PtoG(modelView.GtoP(center) + dir * velocity) - center).Length(); |
| 192 | double const glbLength = kKineticAcceleration * offset; |
| 193 | m2::PointD const glbDirection = dir * glbLength; |
| 194 | m2::PointD const targetCenter = center + glbDirection; |
| 195 | if (!df::GetWorldRect().IsPointInside(targetCenter)) |
| 196 | return {}; |
| 197 | |
| 198 | return make_unique_dp<KineticScrollAnimation>(center, glbDirection, kKineticDuration); |
| 199 | } |
| 200 | } // namespace df |
no test coverage detected