<commit_before>#include "pen_info.hpp"
#include "../std/algorithm.hpp"
#include "../std/iterator.hpp"
#include "../std/numeric.hpp"
#include "../base/logging.hpp"

namespace yg
{
  PenInfo::PenInfo()
  {}

  PenInfo::PenInfo(Color const & color, double w, double const * pattern, size_t patternSize, double offset)
    : m_color(color), m_w(w), m_offset(offset), m_isSolid(false)
  {
    if (m_w < 1.25)
      m_w = 1.25;

    /// if pattern is solid
    if ((pattern == 0 ) || (patternSize == 0))
      m_isSolid = true;
    else
    {
      buffer_vector<double, 4> tmpV;
      copy(pattern, pattern + patternSize, back_inserter(tmpV));

      if (tmpV.size() % 2)
        tmpV.push_back(0);

      double length = 0;

      length = accumulate(tmpV.begin(), tmpV.end(), 0);

      int i = 0;

      buffer_vector<double, 4> vec;

      if ((offset >= length) || (offset < 0))
        offset -= floor(offset / length) * length;

      length = 0;

      /// shifting pattern
      while (true)
      {
        if (length + tmpV[i] > offset)
        {
          //we're inside, let's split the pattern

          if (i % 2 == 1)
            vec.push_back(0);

          vec.push_back(length + tmpV[i] - offset);
          std::copy(tmpV.data() + i + 1, tmpV.end(), back_inserter(vec));
          std::copy(tmpV.begin(), tmpV.data() + i, back_inserter(vec));
          vec.push_back(offset - length);

          if (i % 2 == 0)
            vec.push_back(0);

          break;
        }
        else
          length += tmpV[i++];
      }

      /// ensuring that a minimal element has a length of 2px

      length = 0;
      for (size_t i = 0; i < vec.size(); ++i)
      {
        if ((vec[i] < 2) && (vec[i] > 0))
          vec[i] = 2;
        length += vec[i];
      }

      int periods = max(int(256 / length), 1);
      m_pat.reserve(periods * vec.size());
      for (int i = 0; i < periods; ++i)
        copy(vec.begin(), vec.end(), back_inserter(m_pat));
    }
  }

  double PenInfo::firstDashOffset() const<commit_msg>minor code refactoring.<commit_after>#include "pen_info.hpp"
#include "../std/algorithm.hpp"
#include "../std/iterator.hpp"
#include "../std/numeric.hpp"
#include "../base/logging.hpp"

namespace yg
{
  PenInfo::PenInfo()
  {}

  PenInfo::PenInfo(Color const & color, double w, double const * pattern, size_t patternSize, double offset)
    : m_color(color), m_w(w), m_offset(offset), m_isSolid(false)
  {
    if (m_w < 1.25)
      m_w = 1.25;

    /// if pattern is solid
    if ((pattern == 0 ) || (patternSize == 0))
      m_isSolid = true;
    else
    {
      buffer_vector<double, 4> tmpV;
      copy(pattern, pattern + patternSize, back_inserter(tmpV));

      if (tmpV.size() % 2)
        tmpV.push_back(0);

      double length = 0;

      /// ensuring that a minimal element has a length of 2px
      for (size_t i = 0; i < tmpV.size(); ++i)
      {
        if ((tmpV[i] < 2) && (tmpV[i] > 0))
          tmpV[i] = 2;
        length += tmpV[i];
      }

      int i = 0;

      buffer_vector<double, 4> vec;

      if ((offset >= length) || (offset < 0))
        offset -= floor(offset / length) * length;

      double curLen = 0;

      /// shifting pattern
      while (true)
      {
        if (curLen + tmpV[i] > offset)
        {
          //we're inside, let's split the pattern

          if (i % 2 == 1)
            vec.push_back(0);

          vec.push_back(curLen + tmpV[i] - offset);
          std::copy(tmpV.data() + i + 1, tmpV.end(), back_inserter(vec));
          std::copy(tmpV.begin(), tmpV.data() + i, back_inserter(vec));
          vec.push_back(offset - curLen);

          if (i % 2 == 0)
            vec.push_back(0);

          break;
        }
        else
          curLen += tmpV[i++];
      }

      int periods = max(int(256 / length), 1);
      m_pat.reserve(periods * vec.size());
      for (int i = 0; i < periods; ++i)
        copy(vec.begin(), vec.end(), back_inserter(m_pat));
    }
  }

  double PenInfo::firstDashOffset() const
{'fraction_non_alphanumeric': 0.16275, 'fraction_numerical': 0.017, 'mean_word_length': 1.9747211895910781, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, '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': '6388467', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1371, 'n_words': 338}