<commit_before>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2017 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#ifndef MAPNIK_SVG_PATH_GRAMMAR_X3_DEF_HPP
#define MAPNIK_SVG_PATH_GRAMMAR_X3_DEF_HPP

// mapnik
#include <mapnik/config.hpp>
#include <mapnik/svg/svg_path_grammar_x3.hpp>
#include <mapnik/util/math.hpp>

#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
#pragma GCC diagnostic pop

namespace mapnik { namespace svg { namespace grammar {

namespace x3 = boost::spirit::x3;

using x3::lit;
using x3::double_;
using x3::char_;
using x3::no_case;

using coord_type = std::tuple<double,double>;

template <typename Context>
svg_converter_type & extract_path(Context const& ctx)
{
    return x3::get<svg_path_tag>(ctx);
}

template <typename Context>
bool & extract_relative(Context const& ctx)
{
    return x3::get<relative_tag>(ctx);
}

auto const move_to = [] (auto const& ctx)
{
    extract_path(ctx).move_to(std::get<0>(_attr(ctx)), std::get<1>(_attr(ctx)), x3::get<relative_tag>(ctx));
};

auto const line_to = [] (auto const & ctx)
{
    extract_path(ctx).line_to(std::get<0>(_attr(ctx)), std::get<1>(_attr(ctx)), x3::get<relative_tag>(ctx));
};

auto const hline_to = [] (auto const& ctx)
{
    extract_path(ctx).hline_to(_attr(ctx), x3::get<relative_tag>(ctx));
};

auto const vline_to = [] (auto const& ctx)
{
    extract_path(ctx).vline_to(_attr(ctx), x3::get<relative_tag>(ctx));
};

auto const curve4 = [] (auto const& ctx)
{
    auto const& attr = _attr(ctx);
    auto const& p0 = boost::fusion::at_c<0>(attr);
    auto const& p1 = boost::fusion::at_c<1>(attr);
    auto const& p2 = boost::fusion::at_c<2>(attr);
    extract_path(ctx).curve4(std::get<0>(p0),std::get<1>(p0),
                                            std::get<0>(p1),std::get<1>(p1),
                                            std::get<0>(p2),std::get<1>(p2),
                                            x3::get<relative_tag>(ctx));
};

auto const curve4_smooth = [] (auto const& ctx)
{
    auto const& attr = _attr(ctx);
    auto const& p0 = boost::fusion::at_c<0>(attr);
    auto const& p1 = boost::fusion::at_c<1>(attr);
    extract_path(ctx).curve4(std::get<0>(p0),std::get<1>(p0),
                                            std::get<0>(p1),std::get<1>(p1),
                                            x3::get<relative_tag>(ctx));
};

auto const curve3 = [] (auto const& ctx)
{
    auto const& attr = _attr(ctx);
    auto const& p0 = boost::fusion::at_c<0>(attr);
    auto const& p1 = boost::fusion::at_c<1>(attr);
    extract_path(ctx).curve3(std::get<0>(p0),std::get<1>(p0),
                                            std::get<0>(p1),std::get<1>(p1),
                                            x3::get<relative_tag>(ctx));
};

auto const curve3_smooth = [] (auto const& ctx)
{
    auto const& attr = _attr(ctx);
    extract_path(ctx).curve3(std::get<0>(attr),std::get<1>(attr),
                                            x3::get<relative_tag>(ctx));
};


auto const arc_to = [] (auto & ctx)
{
    auto const& attr = _attr(ctx);
    auto const& p = boost::fusion::at_c<0>(attr);
    double angle = boost::fusion::at_c<1>(attr);
    bool large_arc_flag = boost::fusion::at_c<2>(attr);
    bool sweep_flag = boost::fusion::at_c<3>(attr);
    auto const& v = boost::fusion::at_c<4>(attr);
    extract_path(ctx).arc_to(std::get<0>(p), std::get<1>(p),
                        util::radians(angle),
                        large_arc_flag, sweep_flag,
                        std::get<0>(v),std::get<1>(v),
                        x3::get<relative_tag>(ctx));
};

auto const close_path = [] (auto const& ctx)
{
    extract_path(ctx).close_subpath();
};

auto const relative = [] (auto const& ctx)
{
    extract_relative(ctx) = true;
};

auto const absolute = [] (auto const& ctx)
{
    extract_relative(ctx) = false;
};

// arc flags parser 0/1
x3::uint_parser<std::uint8_t, 10, 1, 1> flag;<commit_msg>format<commit_after>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2017 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#ifndef MAPNIK_SVG_PATH_GRAMMAR_X3_DEF_HPP
#define MAPNIK_SVG_PATH_GRAMMAR_X3_DEF_HPP

// mapnik
#include <mapnik/config.hpp>
#include <mapnik/svg/svg_path_grammar_x3.hpp>
#include <mapnik/util/math.hpp>

#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
#pragma GCC diagnostic pop

namespace mapnik { namespace svg { namespace grammar {

namespace x3 = boost::spirit::x3;

using x3::lit;
using x3::double_;
using x3::char_;
using x3::no_case;

using coord_type = std::tuple<double,double>;

template <typename Context>
svg_converter_type & extract_path(Context const& ctx)
{
    return x3::get<svg_path_tag>(ctx);
}

template <typename Context>
bool & extract_relative(Context const& ctx)
{
    return x3::get<relative_tag>(ctx);
}

auto const move_to = [] (auto const& ctx)
{
    extract_path(ctx).move_to(std::get<0>(_attr(ctx)), std::get<1>(_attr(ctx)), x3::get<relative_tag>(ctx));
};

auto const line_to = [] (auto const & ctx)
{
    extract_path(ctx).line_to(std::get<0>(_attr(ctx)), std::get<1>(_attr(ctx)), x3::get<relative_tag>(ctx));
};

auto const hline_to = [] (auto const& ctx)
{
    extract_path(ctx).hline_to(_attr(ctx), x3::get<relative_tag>(ctx));
};

auto const vline_to = [] (auto const& ctx)
{
    extract_path(ctx).vline_to(_attr(ctx), x3::get<relative_tag>(ctx));
};

auto const curve4 = [] (auto const& ctx)
{
    auto const& attr = _attr(ctx);
    auto const& p0 = boost::fusion::at_c<0>(attr);
    auto const& p1 = boost::fusion::at_c<1>(attr);
    auto const& p2 = boost::fusion::at_c<2>(attr);
    extract_path(ctx).curve4(std::get<0>(p0),std::get<1>(p0),
                             std::get<0>(p1),std::get<1>(p1),
                             std::get<0>(p2),std::get<1>(p2),
                             x3::get<relative_tag>(ctx));
};

auto const curve4_smooth = [] (auto const& ctx)
{
    auto const& attr = _attr(ctx);
    auto const& p0 = boost::fusion::at_c<0>(attr);
    auto const& p1 = boost::fusion::at_c<1>(attr);
    extract_path(ctx).curve4(std::get<0>(p0),std::get<1>(p0),
                             std::get<0>(p1),std::get<1>(p1),
                             x3::get<relative_tag>(ctx));
};

auto const curve3 = [] (auto const& ctx)
{
    auto const& attr = _attr(ctx);
    auto const& p0 = boost::fusion::at_c<0>(attr);
    auto const& p1 = boost::fusion::at_c<1>(attr);
    extract_path(ctx).curve3(std::get<0>(p0),std::get<1>(p0),
                             std::get<0>(p1),std::get<1>(p1),
                             x3::get<relative_tag>(ctx));
};

auto const curve3_smooth = [] (auto const& ctx)
{
    auto const& attr = _attr(ctx);
    extract_path(ctx).curve3(std::get<0>(attr),
                             std::get<1>(attr),
                             x3::get<relative_tag>(ctx));
};


auto const arc_to = [] (auto & ctx)
{
    auto const& attr = _attr(ctx);
    auto const& p = boost::fusion::at_c<0>(attr);
    double angle = boost::fusion::at_c<1>(attr);
    bool large_arc_flag = boost::fusion::at_c<2>(attr);
    bool sweep_flag = boost::fusion::at_c<3>(attr);
    auto const& v = boost::fusion::at_c<4>(attr);
    extract_path(ctx).arc_to(std::get<0>(p), std::get<1>(p),
                             util::radians(angle),
                             large_arc_flag, sweep_flag,
                             std::get<0>(v),std::get<1>(v),
                             x3::get<relative_tag>(ctx));
};

auto const close_path = [] (auto const& ctx)
{
    extract_path(ctx).close_subpath();
};

auto const relative = [] (auto const& ctx)
{
    extract_relative(ctx) = true;
};

auto const absolute = [] (auto const& ctx)
{
    extract_relative(ctx) = false;
};

// arc flags parser 0/1
x3::uint_parser<std::uint8_t, 10, 1, 1> flag;
{'fraction_non_alphanumeric': 0.18418043862384367, 'fraction_numerical': 0.022866645878806775, 'mean_word_length': 3.4036613272311214, 'pattern_counts': {'":': 0, '<': 117, '<?xml version=': 0, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '816804', 'n_tokens_mistral': 3258, 'n_tokens_neox': 3134, 'n_words': 740}