<commit_before>/*********************************************************************************
* Copyright (c) 2014 <NAME> <<EMAIL>>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*    <NAME> - initial code and implementation
********************************************************************************/

#ifndef eli_geom_surface_piecewise_capped_surface_creator_hpp
#define eli_geom_surface_piecewise_capped_surface_creator_hpp

#include <list>
#include <iterator>

#include "eli/code_eli.hpp"

#include "eli/util/tolerance.hpp"

#include "eli/geom/curve/bezier.hpp"
#include "eli/geom/curve/piecewise.hpp"

#include "eli/geom/surface/bezier.hpp"
#include "eli/geom/surface/piecewise.hpp"
#include "eli/geom/surface/piecewise_connection_data.hpp"
#include "eli/geom/surface/piecewise_general_skinning_surface_creator.hpp"

namespace eli
{
  namespace geom
  {
    namespace surface
    {
      template<typename data__, unsigned short dim__, typename tol__>
      class piecewise_capped_surface_creator : public piecewise_creator_base<data__, dim__, tol__>
      {
        public:
          enum edge_cap_identifier
          {
            CAP_NONE,
            CAP_UMIN,
            CAP_UMAX,
            CAP_VMIN,
            CAP_VMAX
          };

          typedef piecewise_creator_base<data__, dim__, tol__> base_class_type;
          typedef typename base_class_type::data_type data_type;
          typedef typename base_class_type::point_type point_type;
          typedef typename base_class_type::index_type index_type;
          typedef typename base_class_type::tolerance_type tolerance_type;
          typedef typename base_class_type::piecewise_surface_type piecewise_surface_type;

          piecewise_capped_surface_creator()
            : piecewise_creator_base<data__, dim__, tol__>(0, 0), delta_param(1), edge_to_cap(CAP_NONE)
          {
          }
          piecewise_capped_surface_creator(const piecewise_surface_type &os, const data_type &dp, edge_cap_identifier ec)
            : piecewise_creator_base<data__, dim__, tol__>(0, 0), orig_surface(os), delta_param(dp), edge_to_cap(ec)
          {
          }
          piecewise_capped_surface_creator(const piecewise_capped_surface_creator<data_type, dim__, tolerance_type> & gs)
            : piecewise_creator_base<data_type, dim__, tolerance_type>(gs), orig_surface(gs.orig_surface),
              delta_param(gs.delta_param), edge_to_cap(gs.edge_to_cap)
          {
          }
          virtual ~piecewise_capped_surface_creator()
          {
          }

          bool set_conditions(const piecewise_surface_type &os, const data_type &dp, edge_cap_identifier ec)
          {
            // all deltas are positive, even on the min edges
            if (dp<=0)
              return false;

            orig_surface = os;
            edge_to_cap = ec;
            delta_param = dp;

            return true;
          }

          virtual bool create(piecewise_surface_type &ps) const
          {
            typedef typename eli::geom::curve::piecewise<eli::geom::curve::bezier, data_type, dim__, tolerance_type> piecewise_curve_type;

            tolerance_type tol;

            // extract the curve corresonding to the edge of surface wanting to cap
            piecewise_curve_type edge;
            switch (edge_to_cap)
            {
              case (CAP_UMIN):
              {
                orig_surface.get_uconst_curve(edge, orig_surface.get_u0());
                break;
              }
              case (CAP_UMAX):
              {
                orig_surface.get_uconst_curve(edge, orig_surface.get_umax());
                break;
              }
              case (CAP_VMIN):
              {
                orig_surface.get_vconst_curve(edge, orig_surface.get_v0());
                break;
              }
              case (CAP_VMAX):
              {
                orig_surface.get_vconst_curve(edge, orig_surface.get_vmax());
                break;
              }
              default:
              {
                // must not want any edge capped
                assert(edge_to_cap==CAP_NONE);
                return false;
              }
            }

            // make sure extracted curve is closed
            if (edge.open())
            {
              return false;
            }

            // make sure that the split location is different than the start/end location otherwise
            // the edge is a point and no need to cap
            data_type tmin(edge.get_t0()), tmax(edge.get_tmax()), tsplit((tmin+tmax)/2);
            if (tol.approximately_equal(edge.f(tmin), edge.f(tsplit)))
            {
              return false;
            }

            // split the curve at the mid-parameter location and reverse the second piece's parameterization
            piecewise_curve_type first_half, second_half;
            edge.split(first_half, second_half, tsplit);
            second_half.reverse();
            second_half.set_t0(first_half.get_t0());<commit_msg>Use direct boundary curve extraction in surface capper.<commit_after>/*********************************************************************************
* Copyright (c) 2014 <NAME> <<EMAIL>>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*    <NAME> - initial code and implementation
********************************************************************************/

#ifndef eli_geom_surface_piecewise_capped_surface_creator_hpp
#define eli_geom_surface_piecewise_capped_surface_creator_hpp

#include <list>
#include <iterator>

#include "eli/code_eli.hpp"

#include "eli/util/tolerance.hpp"

#include "eli/geom/curve/bezier.hpp"
#include "eli/geom/curve/piecewise.hpp"

#include "eli/geom/surface/bezier.hpp"
#include "eli/geom/surface/piecewise.hpp"
#include "eli/geom/surface/piecewise_connection_data.hpp"
#include "eli/geom/surface/piecewise_general_skinning_surface_creator.hpp"

namespace eli
{
  namespace geom
  {
    namespace surface
    {
      template<typename data__, unsigned short dim__, typename tol__>
      class piecewise_capped_surface_creator : public piecewise_creator_base<data__, dim__, tol__>
      {
        public:
          enum edge_cap_identifier
          {
            CAP_NONE,
            CAP_UMIN,
            CAP_UMAX,
            CAP_VMIN,
            CAP_VMAX
          };

          typedef piecewise_creator_base<data__, dim__, tol__> base_class_type;
          typedef typename base_class_type::data_type data_type;
          typedef typename base_class_type::point_type point_type;
          typedef typename base_class_type::index_type index_type;
          typedef typename base_class_type::tolerance_type tolerance_type;
          typedef typename base_class_type::piecewise_surface_type piecewise_surface_type;

          piecewise_capped_surface_creator()
            : piecewise_creator_base<data__, dim__, tol__>(0, 0), delta_param(1), edge_to_cap(CAP_NONE)
          {
          }
          piecewise_capped_surface_creator(const piecewise_surface_type &os, const data_type &dp, edge_cap_identifier ec)
            : piecewise_creator_base<data__, dim__, tol__>(0, 0), orig_surface(os), delta_param(dp), edge_to_cap(ec)
          {
          }
          piecewise_capped_surface_creator(const piecewise_capped_surface_creator<data_type, dim__, tolerance_type> & gs)
            : piecewise_creator_base<data_type, dim__, tolerance_type>(gs), orig_surface(gs.orig_surface),
              delta_param(gs.delta_param), edge_to_cap(gs.edge_to_cap)
          {
          }
          virtual ~piecewise_capped_surface_creator()
          {
          }

          bool set_conditions(const piecewise_surface_type &os, const data_type &dp, edge_cap_identifier ec)
          {
            // all deltas are positive, even on the min edges
            if (dp<=0)
              return false;

            orig_surface = os;
            edge_to_cap = ec;
            delta_param = dp;

            return true;
          }

          virtual bool create(piecewise_surface_type &ps) const
          {
            typedef typename eli::geom::curve::piecewise<eli::geom::curve::bezier, data_type, dim__, tolerance_type> piecewise_curve_type;

            tolerance_type tol;

            // extract the curve corresonding to the edge of surface wanting to cap
            piecewise_curve_type edge;
            switch (edge_to_cap)
            {
              case (CAP_UMIN):
              {
                orig_surface.get_umin_bndy_curve( edge );
                break;
              }
              case (CAP_UMAX):
              {
                orig_surface.get_umax_bndy_curve( edge );
                break;
              }
              case (CAP_VMIN):
              {
                orig_surface.get_vmin_bndy_curve( edge );
                break;
              }
              case (CAP_VMAX):
              {
                orig_surface.get_vmax_bndy_curve( edge );
                break;
              }
              default:
              {
                // must not want any edge capped
                assert(edge_to_cap==CAP_NONE);
                return false;
              }
            }

            // make sure extracted curve is closed
            if (edge.open())
            {
              return false;
            }

            // make sure that the split location is different than the start/end location otherwise
            // the edge is a point and no need to cap
            data_type tmin(edge.get_t0()), tmax(edge.get_tmax()), tsplit((tmin+tmax)/2);
            if (tol.approximately_equal(edge.f(tmin), edge.f(tsplit)))
            {
              return false;
            }

            // split the curve at the mid-parameter location and reverse the second piece's parameterization
            piecewise_curve_type first_half, second_half;
            edge.split(first_half, second_half, tsplit);
            second_half.reverse();
            second_half.set_t0(first_half.get_t0());
{'fraction_non_alphanumeric': 0.10787704130643612, 'fraction_numerical': 0.003650336215177714, 'mean_word_length': 2.1711848918671945, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5830192', 'n_tokens_mistral': 3013, 'n_tokens_neox': 2873, 'n_words': 618}