MailRuChamps / raic-2018

Russian AI Cup — artificial intelligence programming contest. Official website: http://russianaicup.ru

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How is `clamp()` for 3D vectors implemented?

leloykun opened this issue · comments

How is `clamp()` for 3D vectors implemented?

That's variant from my working code:

inline Vec3D clamp(const Vec3D &v, double lim)
{
    double v2 = v.sqr();  return v2 < lim * lim ? v : v * (lim / std::sqrt(v2));
}

Thanks @MrSmile!

correct me if I'm wrong but is clamp() for doubles implemented as:

inline double clamp(double v, double minv, double maxv) {
  return std::min(std::max(v, minv), maxv);
}

?

Yes, that looks right.