<commit_before>#include "cell_id.hpp"

#include "../geometry/pointu_to_uint64.hpp"

#include "../base/bits.hpp"

#include "../std/algorithm.hpp"

#include "../base/start_mem_debug.hpp"


#define POINT_COORD_BITS 30

namespace
{

inline double CoordSize(uint32_t coordBits) { return (1 << coordBits); }

}

m2::PointU PointD2PointU(CoordT x, CoordT y)
{
  x = my::clamp(x, MercatorBounds::minX, MercatorBounds::maxX);
  y = my::clamp(y, MercatorBounds::minY, MercatorBounds::maxY);

  uint32_t const ix = static_cast<uint32_t>(0.5 + (x - MercatorBounds::minX)
                         / (MercatorBounds::maxX - MercatorBounds::minX) * CoordSize());
  uint32_t const iy = static_cast<uint32_t>(0.5 + (y - MercatorBounds::minY)
                         / (MercatorBounds::maxY - MercatorBounds::minY) * CoordSize());

  ASSERT_LESS_OR_EQUAL(ix, CoordSize(), ());
  ASSERT_LESS_OR_EQUAL(iy, CoordSize(), ());

  return m2::PointU(ix, iy);
}

int64_t PointToInt64(CoordT x, CoordT y)
{
  int64_t const res =  static_cast<int64_t>(m2::PointUToUint64(PointD2PointU(x, y)));

  ASSERT_LESS_OR_EQUAL(res, 3ULL << 2 * POINT_COORD_BITS, ());
  ASSERT_GREATER_OR_EQUAL(res, 0,
                          ("Highest bits of (ix, iy) are not used, so res should be > 0."));
  return res;
}

CoordPointT PointU2PointD(m2::PointU const & pt)
{
  return CoordPointT(
        static_cast<CoordT>(pt.x) * (MercatorBounds::maxX - MercatorBounds::minX)
            / CoordSize() + MercatorBounds::minX,
        static_cast<CoordT>(pt.y) * (MercatorBounds::maxY - MercatorBounds::minY)
            / CoordSize() + MercatorBounds::minY);
}

CoordPointT Int64ToPoint(int64_t v)
{
  ASSERT_LESS_OR_EQUAL(v, 3ULL << 2 * POINT_COORD_BITS, ());
  return PointU2PointD(m2::Uint64ToPointU(static_cast<uint64_t>(v)));
}

pair<int64_t, int64_t> RectToInt64(m2::RectD const & r)
{
  int64_t const p1 = PointToInt64(r.minX(), r.minY());
  int64_t const p2 = PointToInt64(r.maxX(), r.maxY());
  return make_pair(p1, p2);
}

m2::RectD Int64ToRect(pair<int64_t, int64_t> const & p)
{
  CoordPointT const pt1 = Int64ToPoint(p.first);
  CoordPointT const pt2 = Int64ToPoint(p.second);
  return m2::RectD(m2::PointD(pt1.first, pt1.second), m2::PointD(pt2.first, pt2.second));
}<commit_msg>Fix compilation after previous commit!<commit_after>#include "cell_id.hpp"

#include "../geometry/pointu_to_uint64.hpp"

#include "../base/bits.hpp"

#include "../std/algorithm.hpp"

#include "../base/start_mem_debug.hpp"


#define POINT_COORD_BITS 30

namespace
{

inline double CoordSize(uint32_t coordBits) { return (1 << coordBits); }

}

m2::PointU PointD2PointU(CoordT x, CoordT y, uint32_t coordBits)
{
  x = my::clamp(x, MercatorBounds::minX, MercatorBounds::maxX);
  y = my::clamp(y, MercatorBounds::minY, MercatorBounds::maxY);

  uint32_t const ix = static_cast<uint32_t>(0.5 + (x - MercatorBounds::minX)
                         / (MercatorBounds::maxX - MercatorBounds::minX) * CoordSize(coordBits));
  uint32_t const iy = static_cast<uint32_t>(0.5 + (y - MercatorBounds::minY)
                         / (MercatorBounds::maxY - MercatorBounds::minY) * CoordSize(coordBits));

  ASSERT_LESS_OR_EQUAL(ix, CoordSize(coordBits), ());
  ASSERT_LESS_OR_EQUAL(iy, CoordSize(coordBits), ());

  return m2::PointU(ix, iy);
}

int64_t PointToInt64(CoordT x, CoordT y, uint32_t coordBits)
{
  int64_t const res =  static_cast<int64_t>(m2::PointUToUint64(PointD2PointU(x, y, coordBits)));

  ASSERT_LESS_OR_EQUAL(res, 3ULL << 2 * POINT_COORD_BITS, ());
  ASSERT_GREATER_OR_EQUAL(res, 0,
                          ("Highest bits of (ix, iy) are not used, so res should be > 0."));
  return res;
}

CoordPointT PointU2PointD(m2::PointU const & pt, uint32_t coordBits)
{
  return CoordPointT(
        static_cast<CoordT>(pt.x) * (MercatorBounds::maxX - MercatorBounds::minX)
            / CoordSize(coordBits) + MercatorBounds::minX,
        static_cast<CoordT>(pt.y) * (MercatorBounds::maxY - MercatorBounds::minY)
            / CoordSize(coordBits) + MercatorBounds::minY);
}

CoordPointT Int64ToPoint(int64_t v, uint32_t coordBits)
{
  ASSERT_LESS_OR_EQUAL(v, 3ULL << 2 * POINT_COORD_BITS, ());
  return PointU2PointD(m2::Uint64ToPointU(static_cast<uint64_t>(v)), coordBits);
}

pair<int64_t, int64_t> RectToInt64(m2::RectD const & r, uint32_t coordBits)
{
  int64_t const p1 = PointToInt64(r.minX(), r.minY(), coordBits);
  int64_t const p2 = PointToInt64(r.maxX(), r.maxY(), coordBits);
  return make_pair(p1, p2);
}

m2::RectD Int64ToRect(pair<int64_t, int64_t> const & p, uint32_t coordBits)
{
  CoordPointT const pt1 = Int64ToPoint(p.first, coordBits);
  CoordPointT const pt2 = Int64ToPoint(p.second, coordBits);
  return m2::RectD(m2::PointD(pt1.first, pt1.second), m2::PointD(pt2.first, pt2.second));
}
{'fraction_non_alphanumeric': 0.14898087833578483, 'fraction_numerical': 0.04076486656860685, 'mean_word_length': 4.415244596131968, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '89956', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1852, 'n_words': 324}