<commit_before><commit_msg>Add a TruncateFilter<commit_after>#ifndef LEPP2_FILTER_SENSOR_TRUNCATE_FILTER_H__
#define LEPP2_FILTER_SENSOR_TRUNCATE_FILTER_H__

#include "lepp2/filter/PointFilter.hpp"

namespace {
  int genFactor(int decimals) {
    int factor = 1;
    for (int i = 0; i < decimals; ++i) factor *= 10;

    return factor;
  }
}

/**
 * Truncates the x, y, z coordinates of the given point to the given number of
 * decimal points.
 */
template<class PointT>
class TruncateFilter : public PointFilter<PointT> {
public:
  /**
   * Creates a new `TruncateFilter` that will truncate all coordinates to the
   * given number of decimal places.
   */
  TruncateFilter(int decimals) : factor_(genFactor(decimals)) {}
  /**
   * Implementation of the `PointFilter` interface.
   */
  bool apply(PointT& pt) {
    pt.x = static_cast<int>(pt.x * factor_) / static_cast<double>(factor_);
    pt.y = static_cast<int>(pt.y * factor_) / static_cast<double>(factor_);
    pt.z = static_cast<int>(pt.z * factor_) / static_cast<double>(factor_);
    return true;
  }

  void prepareNext() {}
private:
  int const factor_;
};

#endif
{'fraction_non_alphanumeric': 0.1204605845881311, 'fraction_numerical': 0.006200177147918512, 'mean_word_length': 4.022222222222222, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, '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': '2214573', 'n_tokens_mistral': 396, 'n_tokens_neox': 382, 'n_words': 98}