text: /*
  Copyright (C) 2019 Rodrigo Jose Hernandez Cordoba
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  */
  //----------------------------------------------------------------------------
  // Anti-Grain Geometry - Version 2.4
  // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
  //
  // Permission to copy, use, modify, sell and distribute this software 
  // is granted provided this copyright notice appears in all copies. 
  // This software is provided "as is" without express or implied
  // warranty, and with no claim as to its suitability for any purpose.
  //
  //----------------------------------------------------------------------------
  // Contact: mcseem@antigrain.com
  //          mcseemagg@yahoo.com
  //          http://www.antigrain.com
  //----------------------------------------------------------------------------
  
  #ifndef AGG_VPGEN_CLIP_POLYGON_INCLUDED
  #define AGG_VPGEN_CLIP_POLYGON_INCLUDED
  
  #include <array>
  #include "agg_basics.h"
  
  namespace agg
  {
  
      //======================================================vpgen_clip_polygon
      //
      // See Implementation agg_vpgen_clip_polygon.cpp
      //
      class vpgen_clip_polygon
      {
      public:
          vpgen_clip_polygon() : 
              m_clip_box(0, 0, 1, 1)
              
          {
          }
  
          void clip_box(double x1, double y1, double x2, double y2)
          {
              m_clip_box.x1 = x1;
              m_clip_box.y1 = y1;
              m_clip_box.x2 = x2;
              m_clip_box.y2 = y2;
              m_clip_box.normalize();
          }
  
  
          [[nodiscard]] double x1() const { return m_clip_box.x1; }
          [[nodiscard]] double y1() const { return m_clip_box.y1; }
          [[nodiscard]] double x2() const { return m_clip_box.x2; }
          [[nodiscard]] double y2() const { return m_clip_box.y2; }
  
          static bool auto_close()   { return true;  }
          static bool auto_unclose() { return false; }
  
          void     reset();
          void     move_to(double x, double y);
          void     line_to(double x, double y);
          unsigned vertex(double* x, double* y);
  
      private:
          unsigned clipping_flags(double x, double y);
  
      private:
          rect_d        m_clip_box;
          double        m_x1{0};
          double        m_y1{0};
          unsigned      m_clip_flags{0};
          std::array<double,4> m_x{};
          std::array<double,4> m_y{};
          unsigned      m_num_vertices{0};
          unsigned      m_vertex{0};
          unsigned      m_cmd{path_cmd_move_to};
      };
  
  }
  
  
  #endif
  