%%
%% This is file `spath3.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% spath3_code.dtx  (with options: `spath3')
%% ----------------------------------------------------------------
%% spath3 --- Functions for manipulating PGF soft paths
%% E-mail: Andrew Stacey <loopspace@mathforge.org>
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ----------------------------------------------------------------
%% 
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}
\RequirePackage{pgf}
\ProvidesExplPackage {spath3} {2024/05/31} {2.8} {Functions for
manipulating PGF soft paths}
\RequirePackage{xparse}
\cs_new_protected:Nn \__spath_tl_put_right_braced:Nn
{
  \tl_put_right:Nn #1 { { #2 } }
}
\cs_generate_variant:Nn \__spath_tl_put_right_braced:Nn { NV, cV, cv, Nx, cx }

\cs_new_protected:Nn \__spath_tl_gput_right_braced:Nn
{
  \tl_gput_right:Nn #1 { { #2 } }
}
\cs_generate_variant:Nn \__spath_tl_gput_right_braced:Nn { NV, cV, cv, Nx, cx }
\cs_new_protected:Nn \__spath_tl_put_left_braced:Nn
{
  \tl_put_left:Nn #1 { { #2 } }
}
\cs_generate_variant:Nn \__spath_tl_put_left_braced:Nn { NV, cV, cv, Nx, cx }

\cs_new_protected:Nn \__spath_tl_gput_left_braced:Nn
{
  \tl_gput_left:Nn #1 { { #2 } }
}
\cs_generate_variant:Nn \__spath_tl_gput_left_braced:Nn { NV, cV, cv, Nx, cx }
\tl_new:N \g__spath_output_tl
\int_new:N \g__spath_output_int
\seq_new:N \g__spath_output_seq
\bool_new:N \g__spath_output_bool
\tl_new:N \l__spath_tmpa_tl
\tl_new:N \l__spath_tmpb_tl
\tl_new:N \l__spath_tmpc_tl
\tl_new:N \l__spath_tmpd_tl
\tl_new:N \l__spath_tmpe_tl
\tl_new:N \l__spath_tmpf_tl
\tl_new:N \l__spath_tmpg_tl
\tl_new:N \l__spath_tmph_tl
\tl_new:N \l__spath_tmpi_tl

\seq_new:N \l__spath_tmpa_seq
\seq_new:N \l__spath_tmpb_seq
\seq_new:N \l__spath_tmpc_seq

\dim_new:N \l__spath_tmpa_dim
\dim_new:N \l__spath_tmpb_dim

\fp_new:N \l__spath_tmpa_fp
\fp_new:N \l__spath_tmpb_fp
\fp_new:N \l__spath_tmpc_fp
\fp_new:N \l__spath_tmpd_fp
\fp_new:N \l__spath_tmpe_fp
\fp_new:N \l__spath_tmpf_fp

\int_new:N \l__spath_tmpa_int
\int_new:N \l__spath_tmpb_int

\bool_new:N \l__spath_tmpa_bool
\dim_new:N \l__spath_move_x_dim
\dim_new:N \l__spath_move_y_dim
\bool_new:N \l__spath_closed_bool
\dim_new:N \l__spath_rectx_dim
\dim_new:N \l__spath_recty_dim

\bool_new:N \l__spath_rect_bool
\bool_new:N \l_spath_movetorelevant_bool
\bool_new:N \l_spath_arrow_shortening_bool
\bool_set_true:N \l_spath_arrow_shortening_bool
\tl_new:N \l__spath_intersecta_tl
\tl_new:N \l__spath_intersectb_tl
\tl_const:Nn \c_spath_moveto_tl {\pgfsyssoftpath@movetotoken}
\tl_const:Nn \c_spath_lineto_tl {\pgfsyssoftpath@linetotoken}
\tl_const:Nn \c_spath_curveto_tl {\pgfsyssoftpath@curvetotoken}
\tl_const:Nn \c_spath_curvetoa_tl {\pgfsyssoftpath@curvetosupportatoken}
\tl_const:Nn \c_spath_curvetob_tl {\pgfsyssoftpath@curvetosupportbtoken}
\tl_const:Nn \c_spath_closepath_tl {\pgfsyssoftpath@closepathtoken}
\tl_const:Nn \c_spath_rectcorner_tl {\pgfsyssoftpath@rectcornertoken}
\tl_const:Nn \c_spath_rectsize_tl {\pgfsyssoftpath@rectsizetoken}
\int_new:N \g__spath_anon_int
\int_gzero:N \g__spath_anon_int
\cs_new_protected_nopar:Npn \spath_anonymous:N #1
{
  \tl_set:Nx #1 {anonymous_\int_use:N \g__spath_anon_int}
  \int_gincr:N \g__spath_anon_int
}
\cs_new_protected_nopar:Npn \spath_ganonymous:N #1
{
  \tl_gset:Nx #1 {anonymous_\int_use:N \g__spath_anon_int}
  \int_gincr:N \g__spath_anon_int
}
\cs_generate_variant:Nn \spath_anonymous:N {c}
\cs_generate_variant:Nn \spath_ganonymous:N {c}
\msg_new:nnn { spath3 } { unknown path construction }
{ The~ path~ construction~ element~ #1~ is~ not~ currently~ supported.}
\cs_new_protected_nopar:Npn \__spath_segments_to_seq:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \tl_clear:N \l__spath_tmpb_tl
  \seq_clear:N \l__spath_tmpa_seq
  \dim_zero:N \l__spath_tmpa_dim
  \dim_zero:N \l__spath_tmpb_dim

  \bool_until_do:nn {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    \token_case_meaning:NnF \l__spath_tmpc_tl
    {
      \c_spath_moveto_tl
      {
        \tl_set_eq:NN \l__spath_tmpb_tl \c_spath_moveto_tl
        \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
        \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

        \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
        \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

        \tl_set:Nx \l__spath_tmpd_tl {\tl_head:N \l__spath_tmpa_tl}
        \tl_if_eq:NNF \l__spath_tmpd_tl \c_spath_moveto_tl
        {
          \tl_clear:N \l__spath_tmpb_tl
        }

      }

      \c_spath_lineto_tl
      {
        \tl_set_eq:NN \l__spath_tmpb_tl \c_spath_moveto_tl
        \tl_put_right:Nx \l__spath_tmpb_tl
        {
          {\dim_use:N \l__spath_tmpa_dim}
          {\dim_use:N \l__spath_tmpb_dim}
        }
        \tl_put_right:NV \l__spath_tmpb_tl \c_spath_lineto_tl

        \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
        \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

        \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
        \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

      }

      \c_spath_curvetoa_tl
      {
        \tl_set_eq:NN \l__spath_tmpb_tl \c_spath_moveto_tl
        \tl_put_right:Nx \l__spath_tmpb_tl
        {
          {\dim_use:N \l__spath_tmpa_dim}
          {\dim_use:N \l__spath_tmpb_dim}
        }
        \tl_put_right:NV \l__spath_tmpb_tl \c_spath_curvetoa_tl

        \prg_replicate:nn {2} {
          \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
          \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
          \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
          \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
          \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
          \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
        }

        \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
        \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

        \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
        \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

      }

      \c_spath_rectcorner_tl
      {
        \tl_set_eq:NN \l__spath_tmpb_tl \c_spath_rectcorner_tl

        \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
        \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
        \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

        \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
        \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

        \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
        \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

      }

      \c_spath_closepath_tl
      {
        \tl_set_eq:NN \l__spath_tmpb_tl \c_spath_moveto_tl
        \tl_put_right:Nx \l__spath_tmpb_tl
        {
          {\dim_use:N \l__spath_tmpa_dim}
          {\dim_use:N \l__spath_tmpb_dim}
        }
        \tl_put_right:NV \l__spath_tmpb_tl \c_spath_lineto_tl

        \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
        \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

        \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
        \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

      }

    }
    {

      \tl_set_eq:NN \l__spath_tmpb_tl \l__spath_tmpc_tl
      \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
      \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

      \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
      \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

    }

    \tl_if_empty:NF \l__spath_tmpb_tl
    {
      \seq_put_right:NV \l__spath_tmpa_seq \l__spath_tmpb_tl
    }
    \tl_clear:N \l__spath_tmpb_tl
  }

  \seq_gclear:N \g__spath_output_seq
  \seq_gset_eq:NN \g__spath_output_seq \l__spath_tmpa_seq
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_segments_to_seq:Nn #1#2
{
  \__spath_segments_to_seq:n {#2}
  \seq_clear_new:N #1
  \seq_set_eq:NN #1 \g__spath_output_seq
  \seq_gclear:N \g__spath_output_seq
}
\cs_generate_variant:Nn \spath_segments_to_seq:Nn {NV, cn, cV, Nv, cv}
\cs_new_protected_nopar:Npn \spath_segments_gto_seq:Nn #1#2
{
  \__spath_segments_to_seq:n {#2}
  \seq_clear_new:N #1
  \seq_gset_eq:NN #1 \g__spath_output_seq
  \seq_gclear:N \g__spath_output_seq
}
\cs_generate_variant:Nn \spath_segments_gto_seq:Nn {NV, cn, cV, Nv, cv}
\cs_new_protected_nopar:Npn \__spath_components_to_seq:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \seq_clear:N \l__spath_tmpa_seq
  \tl_set:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
  \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

  \tl_put_right:NV \l__spath_tmpa_tl \c_spath_moveto_tl

  \bool_do_until:nn {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
    \tl_if_eq:NNT \l__spath_tmpc_tl \c_spath_moveto_tl
    {
      \seq_put_right:NV \l__spath_tmpa_seq \l__spath_tmpb_tl
      \tl_clear:N \l__spath_tmpb_tl
    }
    \tl_if_eq:NNT \l__spath_tmpc_tl \c_spath_rectcorner_tl
    {
      \seq_put_right:NV \l__spath_tmpa_seq \l__spath_tmpb_tl
      \tl_clear:N \l__spath_tmpb_tl
    }
    \tl_if_single:NTF \l__spath_tmpc_tl
    {
      \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl
    }
    {
      \tl_put_right:Nx \l__spath_tmpb_tl {{\l__spath_tmpc_tl}}
    }
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
  }

  \seq_gclear:N \g__spath_output_seq
  \seq_gset_eq:NN \g__spath_output_seq \l__spath_tmpa_seq
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_components_to_seq:Nn #1#2
{
  \__spath_components_to_seq:n {#2}
  \seq_clear_new:N #1
  \seq_set_eq:NN #1 \g__spath_output_seq
  \seq_gclear:N \g__spath_output_seq
}
\cs_generate_variant:Nn \spath_components_to_seq:Nn {NV, cn, cV, cv, Nv}
\cs_new_protected_nopar:Npn \spath_components_gto_seq:Nn #1#2
{
  \__spath_components_to_seq:n {#2}
  \seq_clear_new:N #1
  \seq_gset_eq:NN #1 \g__spath_output_seq
  \seq_gclear:N \g__spath_output_seq
}
\cs_generate_variant:Nn \spath_components_gto_seq:Nn {NV, cn, cV, cv, Nv}
\cs_new_protected_nopar:Npn \spath_components_to_clist:Nn #1#2
{
  \__spath_components_to_seq:n {#2}
  \clist_clear_new:N #1
  \clist_set_from_seq:NN #1 \g__spath_output_seq
  \seq_gclear:N \g__spath_output_seq
}
\cs_generate_variant:Nn \spath_components_to_clist:Nn {NV, cn, cV, cv, Nv}
\cs_new_protected_nopar:Npn \spath_components_gto_clist:Nn #1#2
{
  \__spath_components_to_seq:n {#2}
  \clist_clear_new:N #1
  \clist_gset_from_seq:NN #1 \g__spath_output_seq
  \seq_gclear:N \g__spath_output_seq
}
\cs_generate_variant:Nn \spath_components_gto_clist:Nn {NV, cn, cV, cv, Nv}
\cs_new_protected_nopar:Npn \spath_length:n #1
{
  \int_eval:n {\tl_count:n {#1} / 3}
}
\cs_generate_variant:Nn \spath_length:n {V}
\cs_new_protected_nopar:Npn \__spath_reallength:n #1
{
  \group_begin:
  \int_set:Nn \l__spath_tmpa_int {0}
  \tl_map_inline:nn {#1} {
    \tl_set:Nn \l__spath_tmpa_tl {##1}
    \token_case_meaning:NnT \l__spath_tmpa_tl
    {
      \c_spath_lineto_tl {}
      \c_spath_curveto_tl {}
      \c_spath_closepath_tl {}
      \c_spath_rectsize_tl {}
    }
    {
      \int_incr:N \l__spath_tmpa_int
    }
  }
  \int_gzero:N \g__spath_output_int
  \int_gset_eq:NN \g__spath_output_int \l__spath_tmpa_int
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_reallength:Nn #1#2
{
  \__spath_reallength:n {#2}
  \int_set_eq:NN #1 \g__spath_output_int
  \int_gzero:N \g__spath_output_int
}
\cs_generate_variant:Nn \spath_reallength:Nn {NV, cn, cV, Nv, cv}
\cs_new_protected_nopar:Npn \spath_greallength:Nn #1#2
{
  \__spath_reallength:n {#2}
  \int_gset_eq:NN #1 \g__spath_output_int
  \int_gzero:N \g__spath_output_int
}
\cs_generate_variant:Nn \spath_greallength:Nn {NV, cn, cV}
\cs_new_protected_nopar:Npn \__spath_numberofcomponents:n #1
{
  \group_begin:
  \int_set:Nn \l__spath_tmpa_int {0}
  \tl_map_inline:nn {#1} {
    \tl_set:Nn \l__spath_tmpa_tl {##1}
    \token_case_meaning:Nn \l__spath_tmpa_tl
    {
      \c_spath_moveto_tl
      {
        \int_incr:N \l__spath_tmpa_int
      }
      \c_spath_rectcorner_tl
      {
        \int_incr:N \l__spath_tmpa_int
      }
    }
  }
  \int_gzero:N \g__spath_output_int
  \int_gset_eq:NN \g__spath_output_int \l__spath_tmpa_int
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_numberofcomponents:Nn #1#2
{
  \__spath_numberofcomponents:n {#2}
  \int_set_eq:NN #1 \g__spath_output_int
  \int_gzero:N \g__spath_output_int
}
\cs_generate_variant:Nn \spath_numberofcomponents:Nn {NV, cn, cV, Nv}
\cs_new_protected_nopar:Npn \spath_gnumberofcomponents:Nn #1#2
{
  \__spath_numberofcomponents:n {#2}
  \int_gset_eq:NN #1 \g__spath_output_int
  \int_gzero:N \g__spath_output_int
}
\cs_generate_variant:Nn \spath_gnumberofcomponents:Nn {NV, cn, cV, Nv}
\cs_new_protected_nopar:Npn \__spath_initialpoint:n #1
{
  \group_begin:
  \tl_clear:N \l__spath_tmpa_tl
  \tl_set:Nx \l__spath_tmpa_tl
  {
    { \tl_item:nn {#1} {2} }
    { \tl_item:nn {#1} {3} }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_initialpoint:Nn #1#2
{
  \__spath_initialpoint:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_initialpoint:Nn {NV, cn, cV, Nv}
\cs_new_protected_nopar:Npn \spath_ginitialpoint:Nn #1#2
{
  \__spath_initialpoint:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_ginitialpoint:Nn {NV, cn, cV, Nv}
\cs_new_protected_nopar:Npn \__spath_finalpoint:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \tl_reverse:N \l__spath_tmpa_tl
  \tl_clear:N \l__spath_tmpb_tl
  \tl_set:Nx \l__spath_tmpc_tl {\tl_item:Nn \l__spath_tmpa_tl {3}}
  \tl_if_eq:NNTF \l__spath_tmpc_tl \c_spath_rectsize_tl
  {
    \tl_set:Nx \l__spath_tmpb_tl
    {
      {
        \dim_eval:n
        {
          \tl_item:Nn \l__spath_tmpa_tl {2}
          +
          \tl_item:Nn \l__spath_tmpa_tl {5}
        }
      }
      {
        \dim_eval:n
        {
          \tl_item:Nn \l__spath_tmpa_tl {1}
          +
          \tl_item:Nn \l__spath_tmpa_tl {4}
        }
      }
    }
  }
  {
    \tl_set:Nx \l__spath_tmpb_tl
    {
      { \tl_item:Nn \l__spath_tmpa_tl {2} }
      { \tl_item:Nn \l__spath_tmpa_tl {1} }
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_finalpoint:Nn #1#2
{
  \__spath_finalpoint:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_finalpoint:Nn {NV, cn, cV, Nv}
\cs_new_protected_nopar:Npn \spath_gfinalpoint:Nn #1#2
{
  \__spath_finalpoint:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gfinalpoint:Nn {NV, cn, cV, Nv}
\cs_new_protected_nopar:Npn \__spath_finalmovepoint:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpc_tl { {0pt} {0pt} }
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \bool_do_until:nn
  {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_set:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
    \token_case_meaning:Nn \l__spath_tmpb_tl
    {
      \c_spath_moveto_tl
      {
        \tl_set:Nx \l__spath_tmpc_tl
        {
          { \tl_item:Nn \l__spath_tmpa_tl {2} }
          { \tl_item:Nn \l__spath_tmpa_tl {3} }
        }
      }

      \c_spath_rectcorner_tl
      {
        \tl_set:Nx \l__spath_tmpc_tl
        {
          { \tl_item:Nn \l__spath_tmpa_tl {2} }
          { \tl_item:Nn \l__spath_tmpa_tl {3} }
        }
      }

    }
    \prg_replicate:nn {3}
    {
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpc_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_finalmovepoint:Nn #1#2
{
  \__spath_finalmovepoint:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_finalmovepoint:Nn {NV, cn, cV}
\cs_new_protected_nopar:Npn \spath_gfinalmovepoint:Nn #1#2
{
  \__spath_finalmovepoint:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gfinalmovepoint:Nn {NV, cn, cV}
\cs_new_protected_nopar:Npn \__spath_initialtangent:n #1
{
  \group_begin:
  \tl_set:Nx \l__spath_tmpb_tl {\tl_item:nn {#1} {4}}
  \tl_if_eq:NNTF \l__spath_tmpb_tl \c_spath_curvetoa_tl
  {
    \fp_set:Nn \l__spath_tmpa_fp {3}
  }
  {
    \fp_set:Nn \l__spath_tmpa_fp {1}
  }
  \tl_clear:N \l__spath_tmpa_tl
  \tl_set:Nx \l__spath_tmpa_tl
  {
    {
      \fp_to_dim:n {
        \l__spath_tmpa_fp
        *
        (
        \tl_item:nn {#1} {5}
        -
        \tl_item:nn {#1} {2}
        )
      }
    }
    {
      \fp_to_dim:n {
        \l__spath_tmpa_fp
        *
        (
        \tl_item:nn {#1} {6}
        -
        \tl_item:nn {#1} {3}
        )
      }
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_initialtangent:Nn #1#2
{
  \__spath_initialtangent:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_initialtangent:Nn {NV, cn, cV, Nv}
\cs_new_protected_nopar:Npn \spath_ginitialtangent:Nn #1#2
{
  \__spath_initialtangent:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_ginitialtangent:Nn {NV, cn, cV, Nv}
\cs_new_protected_nopar:Npn \__spath_finaltangent:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \tl_reverse:N \l__spath_tmpa_tl
  \tl_set:Nx \l__spath_tmpb_tl {\tl_item:nn {#1} {6}}
  \tl_if_eq:NNTF \l__spath_tmpb_tl \c_spath_curveto_tl
  {
    \fp_set:Nn \l__spath_tmpa_fp {3}
  }
  {
    \fp_set:Nn \l__spath_tmpa_fp {1}
  }
  \tl_clear:N \l__spath_tmpb_tl
  \tl_set:Nx \l__spath_tmpb_tl
  {
    {
      \fp_to_dim:n {
        \l__spath_tmpa_fp
        *
        (
        \tl_item:Nn \l__spath_tmpa_tl {2}
        -
        \tl_item:Nn \l__spath_tmpa_tl {5}
        )
      }
    }
    {
      \fp_to_dim:n {
        \l__spath_tmpa_fp
        *
        (
        \tl_item:Nn \l__spath_tmpa_tl {1}
        -
        \tl_item:Nn \l__spath_tmpa_tl {4}
        )
      }
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_finaltangent:Nn #1#2
{
  \__spath_finaltangent:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_finaltangent:Nn {NV, cn, cV, Nv}
\cs_new_protected_nopar:Npn \spath_gfinaltangent:Nn #1#2
{
  \__spath_finaltangent:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gfinaltangent:Nn {NV, cn, cV, Nv}
\cs_new_protected_nopar:Npn \__spath_finalmovetangent:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpc_tl { {0pt} {0pt} }
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \bool_do_until:nn
  {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_set:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
    \token_case_meaning:Nn \l__spath_tmpb_tl
    {
      \c_spath_moveto_tl
      {
        \tl_set:Nx \l__spath_tmpd_tl { \tl_item:Nn \l__spath_tmpa_tl {4} }
        \tl_if_eq:NNTF \l__spath_tmpd_tl \c_spath_curveto_tl
        {
          \fp_set:Nn \l__spath_tmpa_fp {3}
        }
        {
          \fp_set:Nn \l__spath_tmpa_fp {1}
        }
        \tl_set:Nx \l__spath_tmpc_tl
        {
          {
            \fp_to_dim:n
            {
              \l__spath_tmpa_fp
              *
              (
              \tl_item:Nn \l__spath_tmpa_tl {5}
              -
              \tl_item:Nn \l__spath_tmpa_tl {2}
              )
            }
          }
          {
            \fp_to_dim:n
            {
              \l__spath_tmpa_fp
              *
              (
              \tl_item:Nn \l__spath_tmpa_tl {6}
              -
              \tl_item:Nn \l__spath_tmpa_tl {3}
              )
            }
          }
        }
      }
    }
    \prg_replicate:nn {3}
    {
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpc_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_finalmovetangent:Nn #1#2
{
  \__spath_finalmovetangent:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_finalmovetangent:Nn {NV, cn, cV}
\cs_new_protected_nopar:Npn \spath_gfinalmovetangent:Nn #1#2
{
  \__spath_finalmovetangent:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gfinalmovetangent:Nn {NV, cn, cV}
\cs_new_protected_nopar:Npn \__spath_reverse:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}

  \tl_clear:N \l__spath_tmpb_tl
  \tl_clear:N \l__spath_tmpd_tl

  \bool_set_false:N \l__spath_rect_bool

  \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
  \bool_while_do:nn {
    \tl_if_eq_p:NN \l__spath_tmpc_tl \c_spath_rectcorner_tl
  }
  {
    \tl_put_left:Nx \l__spath_tmpd_tl
    {
      \tl_item:Nn \l__spath_tmpa_tl {1}
      {\tl_item:Nn \l__spath_tmpa_tl {2}}
      {\tl_item:Nn \l__spath_tmpa_tl {3}}
      \tl_item:Nn \l__spath_tmpa_tl {4}
      {\tl_item:Nn \l__spath_tmpa_tl {5}}
      {\tl_item:Nn \l__spath_tmpa_tl {6}}
    }
    \prg_replicate:nn {6}
    {
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    }
    \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
    \bool_set_true:N \l__spath_rect_bool
  }

  \tl_if_empty:NF \l__spath_tmpa_tl
  {
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

    \tl_put_left:Nx \l__spath_tmpd_tl
    {
      {\dim_use:N \l__spath_tmpa_dim}
      {\dim_use:N \l__spath_tmpb_dim}
    }

    \bool_set_false:N \l__spath_closed_bool

    \bool_until_do:nn {
      \tl_if_empty_p:N \l__spath_tmpa_tl
    }
    {
      \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
      \bool_set_false:N \l__spath_rect_bool

      \token_case_meaning:NnTF \l__spath_tmpc_tl
      {
        \c_spath_moveto_tl {

          \bool_if:NT \l__spath_closed_bool
          {
            \tl_put_right:NV \l__spath_tmpd_tl \c_spath_closepath_tl
            \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpd_tl}
            \tl_put_right:Nx \l__spath_tmpd_tl
            {
              { \tl_head:N \l__spath_tmpd_tl }
              { \tl_head:N \l__spath_tmpe_tl }
            }
          }
          \bool_set_false:N \l__spath_closed_bool
          \tl_put_left:NV \l__spath_tmpd_tl \c_spath_moveto_tl
          \tl_put_left:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
          \tl_clear:N \l__spath_tmpd_tl
        }
        \c_spath_rectcorner_tl {

          \bool_if:NT \l__spath_closed_bool
          {
            \tl_put_right:NV \l__spath_tmpd_tl \c_spath_closepath_tl
            \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpd_tl}
            \tl_put_right:Nx \l__spath_tmpd_tl
            {
              { \tl_head:N \l__spath_tmpd_tl }
              { \tl_head:N \l__spath_tmpe_tl }
            }
          }
          \bool_set_false:N \l__spath_closed_bool
          \tl_put_left:NV \l__spath_tmpd_tl \c_spath_moveto_tl
          \tl_put_left:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
          \tl_clear:N \l__spath_tmpd_tl

          \bool_while_do:nn {
            \tl_if_eq_p:NN \l__spath_tmpc_tl \c_spath_rectcorner_tl
          }
          {
            \tl_put_left:Nx \l__spath_tmpb_tl
            {
              \tl_item:Nn \l__spath_tmpa_tl {1}
              {\tl_item:Nn \l__spath_tmpa_tl {2}}
              {\tl_item:Nn \l__spath_tmpa_tl {3}}
              \tl_item:Nn \l__spath_tmpa_tl {4}
              {\tl_item:Nn \l__spath_tmpa_tl {5}}
              {\tl_item:Nn \l__spath_tmpa_tl {6}}
            }
            \prg_replicate:nn {6}
            {
              \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
            }
            \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
          }
          \bool_set_true:N \l__spath_rect_bool

        }
        \c_spath_lineto_tl {
          \tl_put_left:NV \l__spath_tmpd_tl \c_spath_lineto_tl
        }
        \c_spath_curveto_tl {
          \tl_put_left:NV \l__spath_tmpd_tl \c_spath_curvetoa_tl
        }
        \c_spath_curvetoa_tl {
          \tl_put_left:NV \l__spath_tmpd_tl \c_spath_curveto_tl
        }
        \c_spath_curvetob_tl {
          \tl_put_left:NV \l__spath_tmpd_tl \c_spath_curvetob_tl
        }
      }
      {
        \tl_if_empty:NF \l__spath_tmpa_tl
        {
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

        \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
        \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

        \tl_put_left:Nx \l__spath_tmpd_tl
        {
          {\dim_use:N \l__spath_tmpa_dim}
          {\dim_use:N \l__spath_tmpb_dim}
        }
        }
      }
      {
        \tl_if_eq:NNTF \l__spath_tmpc_tl \c_spath_closepath_tl
        {
          \bool_set_true:N \l__spath_closed_bool
        }
        {
          \msg_warning:nnx
          { spath3 }
          { unknown path construction }
          { \l__spath_tmpc_tl }
        }

        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

      }
    }

    \bool_if:NT \l__spath_closed_bool
    {
      \tl_put_right:NV \l__spath_tmpd_tl \c_spath_closepath_tl
      \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpd_tl}
      \tl_put_right:Nx \l__spath_tmpd_tl
      {
        { \tl_head:N \l__spath_tmpd_tl }
        { \tl_head:N \l__spath_tmpe_tl }
      }
    }

    \bool_set_false:N \l__spath_closed_bool
    \bool_if:NF \l__spath_rect_bool
    {
      \tl_put_left:NV \l__spath_tmpd_tl \c_spath_moveto_tl
    }
  }

  \tl_put_left:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_reverse:Nn #1#2
{
  \__spath_reverse:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_reverse:Nn {NV, cn, cV, Nv}
\cs_new_protected_nopar:Npn \spath_reverse:N #1
{
  \spath_reverse:NV #1#1
}
\cs_generate_variant:Nn \spath_reverse:N {c}
\cs_new_protected_nopar:Npn \spath_greverse:Nn #1#2
{
  \__spath_reverse:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_greverse:Nn {NV, cn, cV, Nv}
\cs_new_protected_nopar:Npn \spath_greverse:N #1
{
  \spath_greverse:NV #1#1
}
\cs_generate_variant:Nn \spath_greverse:N {c}
\cs_new_protected_nopar:Npn \__spath_initialaction:n #1
{
  \group_begin:
  \tl_clear:N \l__spath_tmpa_tl
  \tl_set:Nx \l__spath_tmpb_tl {\tl_head:n {#1}}
  \tl_if_eq:NNTF \l__spath_tmpb_tl \c_spath_rectcorner_tl
  {
    \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_rectcorner_tl
  }
  {
    \int_compare:nT
    {
      \tl_count:n {#1} > 3
    }
    {
      \tl_set:Nx \l__spath_tmpa_tl
      {
        \tl_item:Nn {#1} {4}
      }
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_initialaction:Nn #1#2
{
  \__spath_initialaction:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_initialaction:Nn {NV}
\cs_new_protected_nopar:Npn \spath_ginitialaction:Nn #1#2
{
  \__spath_initialaction:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_ginitialaction:Nn {NV}
\cs_new_protected_nopar:Npn \__spath_finalaction:n #1
{
  \group_begin:
  \tl_clear:N \l__spath_tmpb_tl
  \int_compare:nT
  {
    \tl_count:n {#1} > 3
  }
  {
    \tl_set:Nn \l__spath_tmpa_tl {#1}
    \tl_reverse:N \l__spath_tmpa_tl
    \tl_set:Nx \l__spath_tmpb_tl
    {
      \tl_item:Nn \l__spath_tmpa_tl {3}
    }
    \tl_if_eq:NNT \l__spath_tmpb_tl \c_spath_curvetoa_tl
    {
      \tl_set_eq:NN \l__spath_tmpb_tl \c_spath_curveto_tl
    }
    \tl_if_eq:NNT \l__spath_tmpb_tl \c_spath_rectsize_tl
    {
      \tl_set_eq:NN \l__spath_tmpb_tl \c_spath_rectcorner_tl
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_finalaction:Nn #1#2
{
  \__spath_finalaction:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_finalaction:Nn {NV}
\cs_new_protected_nopar:Npn \spath_gfinalaction:Nn #1#2
{
  \__spath_finalaction:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gfinalaction:Nn {NV}
\cs_new_protected_nopar:Npn \__spath_minbb:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}

  \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
  \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

  \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
  \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

  \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
  \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

  \tl_if_eq:NNT \l__spath_tmpc_tl \c_spath_rectcorner_tl
  {
    \dim_set_eq:NN \l__spath_rectx_dim \l__spath_tmpa_dim
    \dim_set_eq:NN \l__spath_recty_dim \l__spath_tmpb_dim
  }
  \bool_until_do:nn {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

    \tl_if_eq:NNTF \l__spath_tmpc_tl \c_spath_rectsize_tl
    {
      \dim_set:Nn \l__spath_tmpa_dim
      {\dim_min:nn
        {\tl_head:N \l__spath_tmpa_tl + \l__spath_rectx_dim} {\l__spath_tmpa_dim}
      }
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

      \dim_set:Nn \l__spath_tmpb_dim
      {\dim_min:nn
        {\tl_head:N \l__spath_tmpa_tl + \l__spath_recty_dim} {\l__spath_tmpb_dim}
      }
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    }
    {
      \dim_set:Nn \l__spath_tmpa_dim
      {\dim_min:nn {\tl_head:N \l__spath_tmpa_tl} {\l__spath_tmpa_dim}}
      \tl_if_eq:NNT \l__spath_tmpc_tl \c_spath_rectcorner_tl
      {
        \dim_set:Nn \l__spath_rectx_dim {\tl_head:N \l__spath_tmpa_tl}
      }
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

      \dim_set:Nn \l__spath_tmpb_dim
      {\dim_min:nn {\tl_head:N \l__spath_tmpa_tl} {\l__spath_tmpb_dim}}
      \tl_if_eq:NNT \l__spath_tmpc_tl \c_spath_rectcorner_tl
      {
        \dim_set:Nn \l__spath_recty_dim {\tl_head:N \l__spath_tmpa_tl}
      }
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    }

  }
  \tl_clear:N \l__spath_tmpb_tl
  \tl_put_right:Nx \l__spath_tmpb_tl
  {
    {\dim_use:N \l__spath_tmpa_dim}
    {\dim_use:N \l__spath_tmpb_dim}
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_minbb:Nn #1#2
{
  \__spath_minbb:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_minbb:Nn {NV, cn, cV}
\cs_new_protected_nopar:Npn \spath_gminbb:Nn #1#2
{
  \__spath_minbb:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gminbb:Nn {NV, cn, cV}
\cs_new_protected_nopar:Npn \__spath_maxbb:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}

  \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
  \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

  \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
  \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

  \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
  \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

  \tl_if_eq:NNT \l__spath_tmpc_tl \c_spath_rectcorner_tl
  {
    \dim_set_eq:NN \l__spath_rectx_dim \l__spath_tmpa_dim
    \dim_set_eq:NN \l__spath_recty_dim \l__spath_tmpb_dim
  }
  \bool_until_do:nn {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

    \tl_if_eq:NNTF \l__spath_tmpc_tl \c_spath_rectsize_tl
    {
      \dim_set:Nn \l__spath_tmpa_dim
      {\dim_max:nn
        {\tl_head:N \l__spath_tmpa_tl + \l__spath_rectx_dim} {\l__spath_tmpa_dim}
      }
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

      \dim_set:Nn \l__spath_tmpb_dim
      {\dim_max:nn
        {\tl_head:N \l__spath_tmpa_tl + \l__spath_recty_dim} {\l__spath_tmpb_dim}
      }
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    }
    {
      \dim_set:Nn \l__spath_tmpa_dim
      {\dim_max:nn {\tl_head:N \l__spath_tmpa_tl} {\l__spath_tmpa_dim}}
      \tl_if_eq:NNT \l__spath_tmpc_tl \c_spath_rectcorner_tl
      {
        \dim_set:Nn \l__spath_rectx_dim {\tl_head:N \l__spath_tmpa_tl}
      }
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

      \dim_set:Nn \l__spath_tmpb_dim
      {\dim_max:nn {\tl_head:N \l__spath_tmpa_tl} {\l__spath_tmpb_dim}}
      \tl_if_eq:NNT \l__spath_tmpc_tl \c_spath_rectcorner_tl
      {
        \dim_set:Nn \l__spath_recty_dim {\tl_head:N \l__spath_tmpa_tl}
      }
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    }

  }
  \tl_clear:N \l__spath_tmpb_tl
  \tl_set:Nx \l__spath_tmpb_tl
  {
    {\dim_use:N \l__spath_tmpa_dim}
    {\dim_use:N \l__spath_tmpb_dim}
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_maxbb:Nn #1#2
{
  \__spath_maxbb:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_maxbb:Nn {NV, cn, cV}
\cs_new_protected_nopar:Npn \spath_gmaxbb:Nn #1#2
{
  \__spath_maxbb:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gmaxbb:Nn {NV, cn, cV}
\int_set:Nn \l__spath_tmpa_int {\char_value_catcode:n {`@}}
\char_set_catcode_letter:N @
\cs_new_protected_nopar:Npn \spath_save_to_aux:Nn #1#2 {
  \tl_if_empty:nF {#2}
  {
    \tl_clear:N \l__spath_tmpa_tl
    \tl_put_right:Nn \l__spath_tmpa_tl {
      \ExplSyntaxOn
      \tl_gclear_new:N #1
      \tl_gset:Nn #1 {#2}
      \ExplSyntaxOff
    }
    \protected@write\@auxout{}{
      \tl_to_str:N \l__spath_tmpa_tl
    }
  }
}
\char_set_catcode:nn {`@} {\l__spath_tmpa_int}
\cs_generate_variant:Nn \spath_save_to_aux:Nn {cn, cV, NV}
\cs_new_protected_nopar:Npn \spath_save_to_aux:N #1
{
  \tl_if_exist:NT #1
  {
    \spath_save_to_aux:NV #1#1
  }
}
\cs_generate_variant:Nn \spath_save_to_aux:N {c}
\cs_new_protected_nopar:Npn \__spath_translate:nnn #1#2#3
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \tl_clear:N \l__spath_tmpb_tl
  \bool_until_do:nn {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}

    \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

    \tl_if_eq:NNTF \l__spath_tmpc_tl \c_spath_rectsize_tl
    {
      \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
    }
    {
      \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl + #2}
    }
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

    \tl_if_eq:NNTF \l__spath_tmpc_tl \c_spath_rectsize_tl
    {
      \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
    }
    {
      \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl + #3}
    }
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

    \tl_put_right:Nx \l__spath_tmpb_tl
    {
      {\dim_use:N \l__spath_tmpa_dim}
      {\dim_use:N \l__spath_tmpb_dim}
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_generate_variant:Nn \__spath_translate:nnn {nVV}
\cs_new_protected_nopar:Npn \spath_translate:Nnnn #1#2#3#4
{
  \__spath_translate:nnn {#2}{#3}{#4}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_translate:Nnnn {NVxx, NVVV, NVnn}
\cs_new_protected_nopar:Npn \spath_translate:Nnn #1#2#3
{
  \spath_translate:NVnn #1#1{#2}{#3}
}
\cs_generate_variant:Nn \spath_translate:Nnn {NVV, cnn, cVV}
\cs_new_protected_nopar:Npn \spath_gtranslate:Nnnn #1#2#3#4
{
  \__spath_translate:nnn {#2}{#3}{#4}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gtranslate:Nnnn {NVxx, NVVV, NVnn}
\cs_new_protected_nopar:Npn \spath_gtranslate:Nnn #1#2#3
{
  \spath_gtranslate:NVnn #1#1{#2}{#3}
}
\cs_generate_variant:Nn \spath_gtranslate:Nnn {NVV, cnn, cVV}
\cs_new_protected_nopar:Npn \spath_translate:Nn #1#2
{
  \spath_translate:Nnn #1 #2
}
\cs_generate_variant:Nn \spath_translate:Nn {NV}
\cs_new_protected_nopar:Npn \spath_gtranslate:Nn #1#2
{
  \spath_gtranslate:Nnn #1 #2
}
\cs_generate_variant:Nn \spath_gtranslate:Nn {NV}
\cs_new_protected_nopar:Npn \__spath_translate_to:nnn #1#2#3
{
  \group_begin:
  \spath_initialpoint:Nn \l__spath_tmpa_tl {#1}

  \dim_set:Nn \l__spath_tmpa_dim
  {
    #2
    -
    \tl_item:Nn \l__spath_tmpa_tl {1}
  }
  \dim_set:Nn \l__spath_tmpb_dim
  {
    #3
    -
    \tl_item:Nn \l__spath_tmpa_tl {2}
  }

  \__spath_translate:nVV {#1} \l__spath_tmpa_dim \l__spath_tmpb_dim
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_translate_to:Nnnn #1#2#3#4
{
  \__spath_translate_to:nnn {#2}{#3}{#4}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_translate_to:Nnnn {NVxx, NVVV, NVnn}
\cs_new_protected_nopar:Npn \spath_translate_to:Nnn #1#2#3
{
  \spath_translate_to:NVnn #1#1{#2}{#3}
}
\cs_generate_variant:Nn \spath_translate_to:Nnn {NVV, cnn, cVV}
\cs_new_protected_nopar:Npn \spath_gtranslate_to:Nnnn #1#2#3#4
{
  \__spath_translate_to:nnn {#2}{#3}{#4}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gtranslate_to:Nnnn {NVxx, NVVV, NVnn}
\cs_new_protected_nopar:Npn \spath_gtranslate_to:Nnn #1#2#3
{
  \spath_gtranslate_to:NVnn #1#1{#2}{#3}
}
\cs_generate_variant:Nn \spath_gtranslate_to:Nnn {NVV, cnn, cVV}
\cs_new_protected_nopar:Npn \spath_translate_to:Nn #1#2
{
  \spath_translate_to:Nnn #1 #2
}
\cs_generate_variant:Nn \spath_translate_to:Nn {NV}
\cs_new_protected_nopar:Npn \spath_gtranslate_to:Nn #1#2
{
  \spath_gtranslate_to:Nnn #1 #2
}
\cs_generate_variant:Nn \spath_gtranslate_to:Nn {NV}
\cs_new_protected_nopar:Npn \__spath_scale:nnn #1#2#3
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \tl_clear:N \l__spath_tmpb_tl
  \bool_until_do:nn {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

    \fp_set:Nn \l__spath_tmpa_fp {\tl_head:N \l__spath_tmpa_tl * #2}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

    \fp_set:Nn \l__spath_tmpb_fp {\tl_head:N \l__spath_tmpa_tl * #3}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

    \tl_put_right:Nx \l__spath_tmpb_tl
    {
      {\fp_to_dim:N \l__spath_tmpa_fp}
      {\fp_to_dim:N \l__spath_tmpb_fp}
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_scale:Nnnn #1#2#3#4
{
  \__spath_scale:nnn {#2}{#3}{#4}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_scale:Nnnn {NVnn, Nnxx}
\cs_new_protected_nopar:Npn \spath_scale:Nnn #1#2#3
{
  \spath_scale:NVnn #1#1{#2}{#3}
}
\cs_generate_variant:Nn \spath_scale:Nnn {cnn, cVV, NVV}
\cs_new_protected_nopar:Npn \spath_gscale:Nnnn #1#2#3#4
{
  \__spath_scale:nnn {#2}{#3}{#4}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gscale:Nnnn {NVnn, Nnxx}
\cs_new_protected_nopar:Npn \spath_gscale:Nnn #1#2#3
{
  \spath_gscale:NVnn #1#1{#2}{#3}
}
\cs_generate_variant:Nn \spath_gscale:Nnn {cnn, cVV, NVV}
\cs_new_protected_nopar:Npn \spath_scale:Nn #1#2
{
  \spath_scale:Nnn #1 #2
}

\cs_generate_variant:Nn \spath_scale:Nn {NV}
\cs_new_protected_nopar:Npn \spath_gscale:Nn #1#2
{
  \spath_gscale:Nnn #1 #2
}

\cs_generate_variant:Nn \spath_gscale:Nn {NV}
\cs_new_protected_nopar:Npn \__spath_transform:nnnnnnn #1#2#3#4#5#6#7
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \tl_clear:N \l__spath_tmpb_tl
  \bool_until_do:nn {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_set:Nx \l__spath_tmpe_tl {\tl_head:N \l__spath_tmpa_tl}

    \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpd_tl {\tl_head:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

    \tl_if_eq:NNTF \l__spath_tmpe_tl \c_spath_rectsize_tl
    {
      \fp_set:Nn \l__spath_tmpa_fp
      {\l__spath_tmpc_tl * #2 + \l__spath_tmpd_tl * #4}
      \fp_set:Nn \l__spath_tmpb_fp
      {\l__spath_tmpc_tl * #3 + \l__spath_tmpd_tl * #5}
    }
    {
      \fp_set:Nn \l__spath_tmpa_fp
      {\l__spath_tmpc_tl * #2 + \l__spath_tmpd_tl * #4 + #6}
      \fp_set:Nn \l__spath_tmpb_fp
      {\l__spath_tmpc_tl * #3 + \l__spath_tmpd_tl * #5 + #7}
    }

    \tl_put_right:Nx \l__spath_tmpb_tl
    {
      {\fp_to_dim:N \l__spath_tmpa_fp}
      {\fp_to_dim:N \l__spath_tmpb_fp}
    }
  }

  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_transform:Nnnnnnnn #1#2#3#4#5#6#7#8
{
  \__spath_transform:nnnnnnn {#2}{#3}{#4}{#5}{#6}{#7}{#8}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_transform:Nnnnnnnn
{NVnnnnnn, Nnxxxxxx, cnnnnnnn}
\cs_new_protected_nopar:Npn \spath_transform:Nnnnnnn #1#2#3#4#5#6#7
{
  \spath_transform:NVnnnnnn #1#1{#2}{#3}{#4}{#5}{#6}{#7}
}
\cs_generate_variant:Nn \spath_transform:Nnnnnnn {cnnnnnn}
\cs_new_protected_nopar:Npn \spath_transform:Nnn #1#2#3
{
  \spath_transform:Nnnnnnnn #1{#2}#3
}
\cs_generate_variant:Nn \spath_transform:Nnn {cnn, cVn, NVn, NnV}
\cs_new_protected_nopar:Npn \spath_transform:Nn #1#2
{
  \spath_transform:NVnnnnnn #1#1#2
}
\cs_generate_variant:Nn \spath_transform:Nn {cn, cV, NV}

\cs_new_protected_nopar:Npn \spath_gtransform:Nnnnnnnn #1#2#3#4#5#6#7#8
{
  \__spath_transform:nnnnnnn {#2}{#3}{#4}{#5}{#6}{#7}{#8}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gtransform:Nnnnnnnn {NVnnnnnn, Nnxxxxxx, cnnnnnnn}
\cs_new_protected_nopar:Npn \spath_gtransform:Nnnnnnn #1#2#3#4#5#6#7
{
  \spath_gtransform:NVnnnnnn #1#1{#2}{#3}{#4}{#5}{#6}{#7}
}
\cs_generate_variant:Nn \spath_gtransform:Nnnnnnn {cnnnnnn}
\cs_new_protected_nopar:Npn \spath_gtransform:Nnn #1#2#3
{
  \spath_gtransform:Nnnnnnnn #1{#2}#3
}
\cs_generate_variant:Nn \spath_gtransform:Nnn {cnn, cVn, NVn, NnV}
\cs_new_protected_nopar:Npn \spath_gtransform:Nn #1#2
{
  \spath_gtransform:NVnnnnnn #1#1#2
}
\cs_generate_variant:Nn \spath_gtransform:Nn {cn, cV, NV}
\cs_new_protected_nopar:Npn \__spath_span:nnn #1#2#3
{
  \group_begin:
  \spath_initialpoint:Nn \l__spath_tmpa_tl {#1}
  \spath_finalpoint:Nn \l__spath_tmpb_tl {#1}

  \fp_set:Nn \l__spath_tmpa_fp
  {
    (\tl_item:Nn \l__spath_tmpb_tl {1}) -
    (\tl_item:Nn \l__spath_tmpa_tl {1})
  }
  \fp_set:Nn \l__spath_tmpb_fp
  {
    (\tl_item:Nn \l__spath_tmpb_tl {2}) -
    (\tl_item:Nn \l__spath_tmpa_tl {2})
  }
  \fp_set:Nn \l__spath_tmpc_fp
  {
    (\l__spath_tmpa_fp) * (\l__spath_tmpa_fp)
    +
    (\l__spath_tmpb_fp * \l__spath_tmpb_fp)
  }

  \fp_compare:nTF
  {
    \l__spath_tmpc_fp < 0.001
  }
  {
    \spath_translate_to:Nnnn \l__spath_tmpd_tl {#1} #2
  }
  {
    \fp_set:Nn \l__spath_tmpa_fp
    {
      (
      ((\tl_item:nn {#3} {1})
      -
      (\tl_item:nn {#2} {1}))
      *
      ((\tl_item:Nn \l__spath_tmpb_tl {1})
      -
      (\tl_item:Nn \l__spath_tmpa_tl {1}))
      +
      ((\tl_item:nn {#3} {2})
      -
      (\tl_item:nn {#2} {2}))
      *
      ((\tl_item:Nn \l__spath_tmpb_tl {2})
      -
      (\tl_item:Nn \l__spath_tmpa_tl {2}))
      )
      /
      \l__spath_tmpc_fp
    }
    \fp_set:Nn \l__spath_tmpb_fp
    {
      (
      ((\tl_item:nn {#3} {2})
      -
      (\tl_item:nn {#2} {2}))
      *
      ((\tl_item:Nn \l__spath_tmpb_tl {1})
      -
      (\tl_item:Nn \l__spath_tmpa_tl {1}))
      -
      ((\tl_item:nn {#3} {1})
      -
      (\tl_item:nn {#2} {1}))
      *
      ((\tl_item:Nn \l__spath_tmpb_tl {2})
      -
      (\tl_item:Nn \l__spath_tmpa_tl {2}))
      )
      /
      \l__spath_tmpc_fp
    }

    \tl_set:Nx \l__spath_tmpc_tl
    {
      {
        \fp_to_decimal:N \l__spath_tmpa_fp
      }
      {
        \fp_to_decimal:N \l__spath_tmpb_fp
      }
      {
        \fp_eval:n { - \l__spath_tmpb_fp }
      }
      {
        \fp_to_decimal:N \l__spath_tmpa_fp
      }
      {
        \fp_to_dim:n
        {
          \tl_item:nn {#2} {1}
          -
          \l__spath_tmpa_fp * (\tl_item:Nn \l__spath_tmpa_tl {1})
          +
          \l__spath_tmpb_fp * (\tl_item:Nn \l__spath_tmpa_tl {2})
        }
      }
      {
        \fp_to_dim:n
        {
          \tl_item:nn {#2} {2}
          -
          \l__spath_tmpb_fp * (\tl_item:Nn \l__spath_tmpa_tl {1})
          -
          \l__spath_tmpa_fp * (\tl_item:Nn \l__spath_tmpa_tl {2})
        }
      }
    }
    \spath_transform:NnV \l__spath_tmpd_tl {#1} \l__spath_tmpc_tl
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpd_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_span:Nnnn #1#2#3#4
{
  \__spath_span:nnn {#2}{#3}{#4}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_span:Nnnn {NVnn, NVVV, NnVV}
\cs_new_protected_nopar:Npn \spath_span:Nnn #1#2#3
{
  \spath_span:NVnn #1#1{#2}{#3}
}
\cs_generate_variant:Nn \spath_span:Nnn {NVV, cnn, cvv, cVV}
\cs_new_protected_nopar:Npn \spath_gspan:Nnnn #1#2#3#4
{
  \__spath_span:nnn {#2}{#3}{#4}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gspan:Nnnn {NVnn, NVVV}
\cs_new_protected_nopar:Npn \spath_gspan:Nnn #1#2#3
{
  \spath_gspan:NVnn #1#1{#2}{#3}
}
\cs_generate_variant:Nn \spath_gspan:Nnn {NVV, cnn, cvv, cVV}
\cs_new_protected_nopar:Npn \__spath_normalise:n #1
{
  \__spath_span:nnn {#1}{{0pt}{0pt}}{{1pt}{0pt}}
}
\cs_new_protected_nopar:Npn \spath_normalise:Nn #1#2
{
  \__spath_normalise:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_normalise:Nn {cn,NV, cV, cv}
\cs_new_protected_nopar:Npn \spath_normalise:N #1
{
  \spath_normalise:NV #1#1
}
\cs_generate_variant:Nn \spath_normalise:N {c}
\cs_new_protected_nopar:Npn \spath_gnormalise:Nn #1#2
{
  \__spath_normalise:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gnormalise:Nn {cn,NV, cV, cv}
\cs_new_protected_nopar:Npn \spath_gnormalise:N #1
{
  \spath_gnormalise:NV #1#1
}
\cs_generate_variant:Nn \spath_gnormalise:N {c}
\cs_new_protected_nopar:Npn \__spath_splice_between:nnn #1#2#3
{
  \group_begin:
  \spath_finalpoint:Nn \l__spath_tmpd_tl {#1}
  \spath_initialpoint:Nn \l__spath_tmpe_tl {#3}
  \spath_span:NnVV \l__spath_tmpb_tl {#2} \l__spath_tmpd_tl \l__spath_tmpe_tl
  \spath_append_no_move:NnV \l__spath_tmpa_tl {#1} \l__spath_tmpb_tl
  \spath_append_no_move:Nn \l__spath_tmpa_tl {#3}
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_splice_between:Nnnn #1#2#3#4
{
  \__spath_splice_between:nnn {#2}{#3}{#4}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_splice_between:Nnnn {NVnn, NVVV}
\cs_new_protected_nopar:Npn \spath_splice_between:Nnn #1#2#3
{
  \spath_splice_between:NVnn #1#1{#2}{#3}
}
\cs_generate_variant:Nn \spath_splice_between:Nnn {NVV, cnn, cvv, Nvn, NVn}
\cs_new_protected_nopar:Npn \spath_gsplice_between:Nnnn #1#2#3#4
{
  \__spath_splice_between:nnn {#2}{#3}{#4}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplice_between:Nnnn {NVnn, NVVV}
\cs_new_protected_nopar:Npn \spath_gsplice_between:Nnn #1#2#3
{
  \spath_gsplice_between:NVnn #1#1{#2}{#3}
}
\cs_generate_variant:Nn \spath_gsplice_between:Nnn {NVV, cnn, cvv, Nvn, NVn}
\cs_new_protected_nopar:Npn \__spath_hobby_curve:nnnn #1#2#3#4
{
  \group_begin:
  \fp_set:Nn \l__spath_tmpa_fp
  {
    (
    (\tl_item:nn {#2} {1})
    *
    (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})
    +
    (\tl_item:nn {#2} {2})
    *
    (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})
    )
    /
    sqrt
    (
    (
    (\tl_item:nn {#2} {1})^2
    +
    (\tl_item:nn {#2} {2})^2
    )
    *
    (
    (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})^2
    +
    (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})^2
    )
    )
  }
  \fp_set:Nn \l__spath_tmpb_fp
  {
    (
    -
    (\tl_item:nn {#2} {1})
    *
    (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})
    +
    (\tl_item:nn {#2} {2})
    *
    (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})
    )
    /
    sqrt
    (
    (
    (\tl_item:nn {#2} {1})^2
    +
    (\tl_item:nn {#2} {2})^2
    )
    *
    (
    (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})^2
    +
    (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})^2
    )
    )
  }
  \fp_set:Nn \l__spath_tmpc_fp
  {
    (
    (\tl_item:nn {#3} {1})
    *
    (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})
    +
    (\tl_item:nn {#3} {2})
    *
    (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})
    )
    /
    sqrt
    (
    (
    (\tl_item:nn {#3} {1})^2
    +
    (\tl_item:nn {#3} {2})^2
    )
    *
    (
    (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})^2
    +
    (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})^2
    )
    )
  }
  \fp_set:Nn \l__spath_tmpd_fp
  {
    (
    (\tl_item:nn {#3} {1})
    *
    (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})
    -
    (\tl_item:nn {#3} {2})
    *
    (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})
    )
    /
    sqrt
    (
    (
    (\tl_item:nn {#3} {1})^2
    +
    (\tl_item:nn {#3} {2})^2
    )
    *
    (
    (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})^2
    +
    (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})^2
    )
    )
  }

  \fp_set:Nn \l__spath_tmpe_fp
  {
    (
    2 + sqrt(2) *
    (\l__spath_tmpb_fp - 1/16 * \l__spath_tmpd_fp)
    *
    (\l__spath_tmpd_fp - 1/16 * \l__spath_tmpb_fp)
    *
    (\l__spath_tmpa_fp - \l__spath_tmpc_fp)
    )
    /
    (
    1
    +
    (1 - (3 - sqrt(5))/2)
    *
    \l__spath_tmpa_fp
    +
    (3 - sqrt(5))/2
    *
    \l__spath_tmpc_fp
    )
    *
    sqrt
    (
    (
    (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})^2
    +
    (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})^2
    )
    /
    (
    (\tl_item:nn {#2} {1})^2
    +
    (\tl_item:nn {#2} {2})^2
    )
    )
    /3
  }
  \fp_set:Nn \l__spath_tmpf_fp
  {
    (
    2 - sqrt(2) *
    (\l__spath_tmpb_fp - 1/16 * \l__spath_tmpd_fp)
    *
    (\l__spath_tmpd_fp - 1/16 * \l__spath_tmpb_fp)
    *
    (\l__spath_tmpa_fp - \l__spath_tmpc_fp)
    )
    /
    (
    1
    +
    (1 - (3 - sqrt(5))/2)
    *
    \l__spath_tmpc_fp
    +
    (3 - sqrt(5))/2
    *
    \l__spath_tmpa_fp
    )
    *
    sqrt
    (
    (
    (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})^2
    +
    (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})^2
    )
    /
    (
    (\tl_item:nn {#3} {1})^2
    +
    (\tl_item:nn {#3} {2})^2
    )
    )
    /3
  }

  \tl_set:Nx \l__spath_tmpa_tl
  {
    {
      \fp_to_dim:n
      {
        \tl_item:nn {#1} {1}
        +
        \l__spath_tmpe_fp
        *
        (\tl_item:nn {#2} {1})
      }
    }
    {
      \fp_to_dim:n
      {
        \tl_item:nn {#1} {2}
        +
        \l__spath_tmpe_fp
        *
        (\tl_item:nn {#2} {2})
      }
    }
  }
  \tl_set:Nx \l__spath_tmpb_tl
  {
    {
      \fp_to_dim:n
      {
        \tl_item:nn {#4} {1}
        -
        \l__spath_tmpf_fp
        *
        (\tl_item:nn {#3} {1})
      }
    }
    {
      \fp_to_dim:n
      {
        \tl_item:nn {#4} {2}
        -
        \l__spath_tmpf_fp
        *
        (\tl_item:nn {#3} {2})
      }
    }
  }

  \tl_clear:N \l__spath_tmpc_tl
  \tl_set:NV \l__spath_tmpc_tl \c_spath_moveto_tl
  \tl_put_right:Nn \l__spath_tmpc_tl {#1}
  \tl_put_right:NV \l__spath_tmpc_tl \c_spath_curvetoa_tl
  \tl_put_right:NV \l__spath_tmpc_tl \l__spath_tmpa_tl
  \tl_put_right:NV \l__spath_tmpc_tl \c_spath_curvetob_tl
  \tl_put_right:NV \l__spath_tmpc_tl \l__spath_tmpb_tl
  \tl_put_right:NV \l__spath_tmpc_tl \c_spath_curveto_tl
  \tl_put_right:Nn \l__spath_tmpc_tl {#4}
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpc_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_hobby_curve:Nnnnn #1#2#3#4#5
{
  \__spath_hobby_curve:nnnn {#2}{#3}{#4}{#5}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_hobby_curve:Nnnnn {NVVVV}
\cs_new_protected_nopar:Npn \spath_ghobby_curve:Nnnnn #1#2#3#4#5
{
  \__spath_hobby_curve:nnnn {#2}{#3}{#4}{#5}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_ghobby_curve:Nnnnn {NVVVV}
\cs_new_protected_nopar:Npn \__spath_curve_between:nn #1#2
{
  \group_begin:
  \spath_finalpoint:Nn \l__spath_tmpa_tl {#1}
  \spath_finaltangent:Nn \l__spath_tmpb_tl {#1}
  \spath_initialpoint:Nn \l__spath_tmpc_tl {#2}
  \spath_initialtangent:Nn \l__spath_tmpd_tl {#2}

  \spath_hobby_curve:NVVVV \l__spath_tmpe_tl
  \l__spath_tmpa_tl \l__spath_tmpb_tl \l__spath_tmpd_tl \l__spath_tmpc_tl

  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \spath_append_no_move:NV \l__spath_tmpa_tl \l__spath_tmpe_tl
  \spath_append_no_move:Nn \l__spath_tmpa_tl {#2}
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_curve_between:Nnn #1#2#3
{
  \__spath_curve_between:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_curve_between:Nnn {NVn, NVV}
\cs_new_protected_nopar:Npn \spath_curve_between:Nn #1#2
{
  \spath_curve_between:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_curve_between:Nn {NV, cn, cv}
\cs_new_protected_nopar:Npn \spath_gcurve_between:Nnn #1#2#3
{
  \__spath_curve_between:nn {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gcurve_between:Nnn {NVn, NVV}
\cs_new_protected_nopar:Npn \spath_gcurve_between:Nn #1#2
{
  \spath_gcurve_between:NVnn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gcurve_between:Nn {NV, cn, cv}
\cs_new_protected_nopar:Npn \__spath_close_with:nn #1#2
{
  \group_begin:
  \spath_finalmovepoint:Nn \l__spath_tmpa_tl {#1}
  \spath_finalpoint:Nn \l__spath_tmpb_tl {#1}
  \dim_compare:nTF
  {
    \dim_abs:n
    {
      \tl_item:Nn \l__spath_tmpa_tl {1}
      -
      \tl_item:Nn \l__spath_tmpb_tl {1}
    }
    +
    \dim_abs:n
    {
      \tl_item:Nn \l__spath_tmpa_tl {2}
      -
      \tl_item:Nn \l__spath_tmpb_tl {2}
    }
    < 0.01pt
  }
  {
    \__spath_close:n {#1}
  }
  {
    \spath_span:NnVV \l__spath_tmpc_tl {#2} \l__spath_tmpb_tl \l__spath_tmpa_tl
    \spath_append_no_move:NnV \l__spath_tmpd_tl {#1} \l__spath_tmpc_tl
    \__spath_close:V \l__spath_tmpd_tl
  }
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_close_with:Nnn #1#2#3
{
  \__spath_close_with:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_close_with:Nnn {cnn, cVV, cvv, NVn}
\cs_new_protected_nopar:Npn \spath_close_with:Nn #1#2
{
  \spath_close_with:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_close_with:Nn {cn, cV, cv, NV}
\cs_new_protected_nopar:Npn \spath_gclose_with:Nnn #1#2#3
{
  \__spath_close_with:nn {#2}{#3}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gclose_with:Nnn {cnn, cVV, cvv, NVn}
\cs_new_protected_nopar:Npn \spath_gclose_with:Nn #1#2
{
  \spath_gclose_with:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gclose_with:Nn {cn, cV, cv, NV}
\cs_new_protected_nopar:Npn \__spath_close_with_curve:n #1
{
  \group_begin:
  \spath_finalpoint:Nn \l__spath_tmpa_tl {#1}
  \spath_finaltangent:Nn \l__spath_tmpb_tl {#1}
  \spath_finalmovepoint:Nn \l__spath_tmpc_tl {#1}
  \spath_finalmovetangent:Nn \l__spath_tmpd_tl {#1}
  \dim_compare:nTF
  {
    \dim_abs:n
    {
      \tl_item:Nn \l__spath_tmpa_tl {1}
      -
      \tl_item:Nn \l__spath_tmpc_tl {1}
    }
    +
    \dim_abs:n
    {
      \tl_item:Nn \l__spath_tmpa_tl {2}
      -
      \tl_item:Nn \l__spath_tmpc_tl {2}
    }
    < 0.01pt
  }
  {
    \__spath_close:n {#1}
  }
  {

    \spath_hobby_curve:NVVVV \l__spath_tmpe_tl
    \l__spath_tmpa_tl \l__spath_tmpb_tl \l__spath_tmpd_tl \l__spath_tmpc_tl

    \tl_set:Nn \l__spath_tmpa_tl {#1}
    \spath_append_no_move:NV \l__spath_tmpa_tl \l__spath_tmpe_tl
    \__spath_close:V \l__spath_tmpa_tl
  }
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_close_with_curve:Nn #1#2
{
  \__spath_close_with_curve:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_close_with_curve:Nn {cn, cV, cv, NV}
\cs_new_protected_nopar:Npn \spath_close_with_curve:N #1
{
  \spath_close_with_curve:NV #1#1
}
\cs_generate_variant:Nn \spath_close_with_curve:N {c}
\cs_new_protected_nopar:Npn \spath_gclose_with_curve:Nn #1#2
{
  \__spath_close_with_curve:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gclose_with_curve:Nn {cn, cV, cv, NV}
\cs_new_protected_nopar:Npn \spath_gclose_with_curve:N #1
{
  \spath_gclose_with_curve:NV #1#1
}
\cs_generate_variant:Nn \spath_gclose_with_curve:N {c}
\cs_new_protected_nopar:Npn \__spath_weld:nn #1#2
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \tl_set:Nn \l__spath_tmpb_tl {#2}
  \spath_finalpoint:Nn \l__spath_tmpc_tl {#1}
  \spath_translate_to:NV \l__spath_tmpb_tl \l__spath_tmpc_tl

  \__spath_append_no_move:VV \l__spath_tmpa_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_weld:Nnn #1#2#3
{
  \__spath_weld:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_weld:Nnn {NVV,NVn}
\cs_new_protected_nopar:Npn \spath_weld:Nn #1#2
{
  \spath_weld:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_weld:Nn {NV, Nv, cV, cv}
\cs_new_protected_nopar:Npn \spath_gweld:Nnn #1#2#3
{
  \__spath_weld:nn {#2}{#3}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gweld:Nnn {NVV, NVn}
\cs_new_protected_nopar:Npn \spath_gweld:Nn #1#2
{
  \spath_gweld:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gweld:Nn {NV, Nv, cV, cv}
\cs_new_protected_nopar:Npn \__spath_append_no_move:nn #1#2
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \tl_set:Nn \l__spath_tmpb_tl {#2}
  \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpb_tl}
  \spath_finalaction:Nn \l__spath_tmpd_tl {#1}
  \bool_if:nT {
    ! \tl_if_eq_p:NN \l__spath_tmpd_tl \c_spath_closepath_tl
    &&
    ! \tl_if_eq_p:NN \l__spath_tmpd_tl \c_spath_rectcorner_tl
    &&
    \tl_if_eq_p:NN \l__spath_tmpc_tl \c_spath_moveto_tl
  }
  {
    \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
    \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
    \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
  }

  \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_generate_variant:Nn \__spath_append_no_move:nn {VV}
\cs_new_protected_nopar:Npn \spath_append_no_move:Nnn #1#2#3
{
  \__spath_append_no_move:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_append_no_move:Nnn {NVV, NVn, NnV}
\cs_new_protected_nopar:Npn \spath_append_no_move:Nn #1#2
{
  \spath_append_no_move:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_append_no_move:Nn {NV, cv, Nv, cV}
\cs_new_protected_nopar:Npn \spath_gappend_no_move:Nnn #1#2#3
{
  \__spath_append_no_move:nn {#2}{#3}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gappend_no_move:Nnn {NVV, NVn}
\cs_new_protected_nopar:Npn \spath_gappend_no_move:Nn #1#2
{
  \spath_gappend_no_move:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gappend_no_move:Nn {NV, cv, Nv, cV}
\cs_new_protected_nopar:Npn \spath_append:Nnn #1#2#3
{
  \tl_set:Nn #1 {#2}
  \tl_put_right:Nn #1 {#3}
}
\cs_generate_variant:Nn \spath_append:Nnn {NVV, NVn}
\cs_new_protected_nopar:Npn \spath_append:Nn #1#2
{
  \spath_append:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_append:Nn {NV, Nv, cv, cV}
\cs_new_protected_nopar:Npn \spath_gappend:Nnn #1#2#3
{
  \tl_gset:Nn #1 {#2}
  \tl_gput_right:Nn #1 {#3}
}
\cs_generate_variant:Nn \spath_gappend:Nnn {NVV, NVn}
\cs_new_protected_nopar:Npn \spath_gappend:Nn #1#2
{
  \spath_gappend:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gappend:Nn {NV, Nv, cv, cV}
\cs_new_protected_nopar:Npn \spath_prepend_no_move:Nnn #1#2#3
{
  \spath_append_no_move:Nnn #1{#3}{#2}
}
\cs_generate_variant:Nn \spath_prepend_no_move:Nnn {NVV, NVn}
\cs_new_protected_nopar:Npn \spath_prepend_no_move:Nn #1#2
{
  \spath_prepend_no_move:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_prepend_no_move:Nn {NV, cv}
\cs_new_protected_nopar:Npn \spath_gprepend_no_move:Nnn #1#2#3
{
  \spath_gappend_no_move:Nnn #1{#3}{#2}
}
\cs_generate_variant:Nn \spath_gprepend_no_move:Nnn {NVV, NVn}
\cs_new_protected_nopar:Npn \spath_gprepend_no_move:Nn #1#2
{
  \spath_gprepend_no_move:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gprepend_no_move:Nn {NV, cv}
\cs_new_protected_nopar:Npn \spath_prepend:Nnn #1#2#3
{
  \spath_append:Nnn #1{#3}{#2}
}
\cs_generate_variant:Nn \spath_prepend:Nnn {NVV, NVn}
\cs_new_protected_nopar:Npn \spath_prepend:Nn #1#2
{
  \spath_prepend:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_prepend:Nn {NV}
\cs_new_protected_nopar:Npn \spath_gprepend:Nnn #1#2#3
{
  \spath_gappend:Nnn #1{#3}{#2}
}
\cs_generate_variant:Nn \spath_gprepend:Nnn {NVV, NVn}
\cs_new_protected_nopar:Npn \spath_gprepend:Nn #1#2
{
  \spath_gprepend:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gprepend:Nn {NV}
\cs_new_protected_nopar:Npn \__spath_bake_round:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \pgf@@processround \l__spath_tmpa_tl\l__spath_tmpb_tl
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_bake_round:Nn #1#2
{
  \__spath_bake_round:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_bake_round:Nn {NV}
\cs_new_protected_nopar:Npn \spath_bake_round:N #1
{
  \spath_bake_round:NV #1#1
}
\cs_generate_variant:Nn \spath_bake_round:N {c}
\cs_new_protected_nopar:Npn \spath_gbake_round:Nn #1#2
{
  \__spath_bake_round:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gbake_round:Nn {NV}
\cs_new_protected_nopar:Npn \spath_gbake_round:N #1
{
  \spath_gbake_round:NV #1#1
}
\cs_generate_variant:Nn \spath_gbake_round:N {c}
\cs_new_protected_nopar:Npn \__spath_bake_shorten:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \pgfsyssoftpath@getcurrentpath\l__spath_tmpb_tl
  \pgfsyssoftpath@setcurrentpath\l__spath_tmpa_tl
  \pgf@prepare@end@of@path
  \pgf@prepare@start@of@path
  \pgfsyssoftpath@getcurrentpath\l__spath_tmpa_tl
  \pgfsyssoftpath@setcurrentpath\l__spath_tmpb_tl
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_bake_shorten:Nn #1#2
{
  \__spath_bake_shorten:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_bake_shorten:Nn {NV}
\cs_new_protected_nopar:Npn \spath_bake_shorten:N #1
{
  \spath_bake_shorten:NV #1#1
}
\cs_generate_variant:Nn \spath_bake_shorten:N {c}
\cs_new_protected_nopar:Npn \spath_gbake_shorten:Nn #1#2
{
  \__spath_bake_shorten:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gbake_shorten:Nn {NV}
\cs_new_protected_nopar:Npn \spath_gbake_shorten:N #1
{
  \spath_gbake_shorten:NV #1#1
}
\cs_generate_variant:Nn \spath_gbake_shorten:N {c}
\cs_set_eq:Nc \__spath_pgf_arrow_compute_shortening:n {pgf@arrow@compute@shortening}
\cs_new_nopar:Npn \__spath_arrow_compute_shortening:n #1
{
  \__spath_pgf_arrow_compute_shortening:n {#1}
  \bool_if:NF \l_spath_arrow_shortening_bool
  {
    \dim_sub:cn {pgf@xb} {\dim_use:c {pgf@xa}}
    \dim_zero:c {pgf@xa}
  }
}

\cs_set_eq:cN {pgf@arrow@compute@shortening} \__spath_arrow_compute_shortening:n
\cs_new_protected_nopar:Npn \__spath_close:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \spath_finalmovepoint:NV \l__spath_tmpb_tl \l__spath_tmpa_tl
  \tl_put_right:NV \l__spath_tmpa_tl \c_spath_closepath_tl
  \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_generate_variant:Nn \__spath_close:n {V}
\cs_new_protected_nopar:Npn \spath_close:Nn #1#2
{
  \__spath_close:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_close:Nn {NV}
\cs_new_protected_nopar:Npn \spath_close:N #1
{
  \spath_close:NV #1#1
}
\cs_generate_variant:Nn \spath_close:N {c}
\cs_new_protected_nopar:Npn \spath_gclose:Nn #1#2
{
  \__spath_close:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gclose:Nn {NV}
\cs_new_protected_nopar:Npn \spath_gclose:N #1
{
  \spath_gclose:NV #1#1
}
\cs_generate_variant:Nn \spath_gclose:N {c}
\cs_new_protected_nopar:Npn \__spath_adjust_close:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \spath_finalmovepoint:NV \l__spath_tmpb_tl \l__spath_tmpa_tl
  \spath_finalpoint:NV \l__spath_tmpc_tl \l__spath_tmpa_tl
  \tl_reverse:N \l__spath_tmpa_tl
  \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
  \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
  \tl_set:Nx \l__spath_tmpd_tl {\tl_head:N \l__spath_tmpa_tl}
  \tl_if_eq:NNT \l__spath_tmpd_tl \c_spath_curveto_tl
  {
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    \tl_clear:N \l__spath_tmpe_tl
    \tl_set:Nx \l__spath_tmpe_tl {
      {
        \dim_eval:n
        {
          \tl_item:Nn \l__spath_tmpa_tl {1}
          -
          \tl_item:Nn \l__spath_tmpc_tl {2}
          +
          \tl_item:Nn \l__spath_tmpb_tl {2}
        }
      }
      {
        \dim_eval:n
        {
          \tl_item:Nn \l__spath_tmpa_tl {2}
          -
          \tl_item:Nn \l__spath_tmpc_tl {1}
          +
          \tl_item:Nn \l__spath_tmpb_tl {1}
        }
      }
    }
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    \tl_put_left:NV \l__spath_tmpa_tl \l__spath_tmpe_tl
    \tl_put_left:NV \l__spath_tmpa_tl \l__spath_tmpd_tl
  }
  \tl_reverse:N \l__spath_tmpa_tl
  \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
  \tl_put_right:NV \l__spath_tmpa_tl \c_spath_closepath_tl
  \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_generate_variant:Nn \__spath_adjust_close:n {V}
\cs_new_protected_nopar:Npn \spath_adjust_close:Nn #1#2
{
  \__spath_adjust_close:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_adjust_close:Nn {NV}
\cs_new_protected_nopar:Npn \spath_adjust_close:N #1
{
  \spath_adjust_close:NV #1#1
}
\cs_generate_variant:Nn \spath_adjust_close:N {c}
\cs_new_protected_nopar:Npn \spath_adjust_gclose:Nn #1#2
{
  \__spath_adjust_close:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_adjust_gclose:Nn {NV}
\cs_new_protected_nopar:Npn \spath_adjust_gclose:N #1
{
  \spath_adjust_gclose:NV #1#1
}
\cs_generate_variant:Nn \spath_adjust_gclose:N {c}
\cs_new_protected_nopar:Npn \__spath_open:n #1
{
  \group_begin:
  \spath_replace_rectangles:Nn \l__spath_tmpa_tl {#1}
  \tl_clear:N \l__spath_tmpb_tl
  \bool_until_do:nn {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

    \token_case_meaning:NnF \l__spath_tmpc_tl
    {
      \c_spath_closepath_tl {

        \bool_if:nF
        {
          \dim_compare_p:n
          {
            \l__spath_move_x_dim == \l__spath_tmpa_dim
          }
          &&
          \dim_compare_p:n
          {
            \l__spath_move_y_dim == \l__spath_tmpb_dim
          }
        }
        {
          \tl_put_right:NV \l__spath_tmpb_tl \c_spath_lineto_tl

          \tl_put_right:Nx \l__spath_tmpb_tl {
            { \dim_use:N \l__spath_move_x_dim }
            { \dim_use:N \l__spath_move_y_dim }
          }
        }

        \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
        \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
      }

      \c_spath_moveto_tl {
        \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl

        \dim_set:Nn \l__spath_move_x_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
        \dim_set:Nn \l__spath_move_y_dim {\tl_head:N \l__spath_tmpa_tl}
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

        \tl_put_right:Nx \l__spath_tmpb_tl {
          { \dim_use:N \l__spath_move_x_dim }
          { \dim_use:N \l__spath_move_y_dim }
        }

        \dim_set_eq:NN \l__spath_tmpa_dim \l__spath_move_x_dim
        \dim_set_eq:NN \l__spath_tmpb_dim \l__spath_move_y_dim
      }
    }
    {
      \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl

      \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
      \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}

      \tl_put_right:Nx \l__spath_tmpb_tl {
        { \dim_use:N \l__spath_tmpa_dim }
        { \dim_use:N \l__spath_tmpb_dim }
      }
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_generate_variant:Nn \__spath_open:n {V}
\cs_new_protected_nopar:Npn \spath_open:Nn #1#2
{
  \__spath_open:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_open:Nn {NV}
\cs_new_protected_nopar:Npn \spath_open:N #1
{
  \spath_open:NV #1#1
}
\cs_new_protected_nopar:Npn \spath_gopen:Nn #1#2
{
  \__spath_open:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gopen:Nn {NV}
\cs_new_protected_nopar:Npn \spath_gopen:N #1
{
  \spath_gopen:NV #1#1
}
\cs_generate_variant:Nn \spath_open:N {c}
\cs_generate_variant:Nn \spath_gopen:N {c}
\cs_new_protected_nopar:Npn \__spath_replace_lines:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \tl_clear:N \l__spath_tmpb_tl
  \dim_set:Nn \l__spath_tmpa_dim {0pt}
  \dim_set:Nn \l__spath_tmpb_dim {0pt}

  \bool_do_until:nn
  {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_set:Nx \l__spath_tmpc_tl {\tl_item:Nn \l__spath_tmpa_tl {1}}
    \tl_set:Nx \l__spath_tmpd_tl {\tl_item:Nn \l__spath_tmpa_tl {2}}
    \tl_set:Nx \l__spath_tmpe_tl {\tl_item:Nn \l__spath_tmpa_tl {3}}

    \tl_if_eq:NNTF \l__spath_tmpc_tl \c_spath_lineto_tl
    {
      \tl_put_right:NV \l__spath_tmpb_tl \c_spath_curvetoa_tl
      \tl_put_right:Nx \l__spath_tmpb_tl
      {
        {
          \fp_to_dim:n
          {
            2/3 * (\l__spath_tmpa_dim)
            +
            1/3 * (\l__spath_tmpd_tl)
          }
        }
      }
      \tl_put_right:Nx \l__spath_tmpb_tl
      {
        {
          \fp_to_dim:n
          {
            2/3 * (\l__spath_tmpb_dim)
            +
            1/3 * (\l__spath_tmpe_tl)
          }
        }
      }
      \tl_put_right:NV \l__spath_tmpb_tl \c_spath_curvetob_tl
      \tl_put_right:Nx \l__spath_tmpb_tl
      {
        {
          \fp_to_dim:n
          {
            1/3 * (\l__spath_tmpa_dim)
            +
            2/3 * (\l__spath_tmpd_tl)
          }
        }
      }
      \tl_put_right:Nx \l__spath_tmpb_tl
      {
        {
          \fp_to_dim:n
          {
            1/3 * (\l__spath_tmpb_dim)
            +
            2/3 * (\l__spath_tmpe_tl)
          }
        }
      }
      \tl_put_right:NV \l__spath_tmpb_tl \c_spath_curveto_tl
      \__spath_tl_put_right_braced:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
      \__spath_tl_put_right_braced:NV \l__spath_tmpb_tl \l__spath_tmpe_tl
    }
    {
      \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl
      \__spath_tl_put_right_braced:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
      \__spath_tl_put_right_braced:NV \l__spath_tmpb_tl \l__spath_tmpe_tl
    }

    \dim_set:Nn \l__spath_tmpa_dim {\l__spath_tmpd_tl}
    \dim_set:Nn \l__spath_tmpb_dim {\l__spath_tmpe_tl}

    \prg_replicate:nn {3}
    {
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_generate_variant:Nn \__spath_replace_lines:n {V}
\cs_new_protected_nopar:Npn \spath_replace_lines:Nn #1#2
{
  \__spath_replace_lines:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_replace_lines:Nn {NV, cV, cv, Nv}
\cs_new_protected_nopar:Npn \spath_replace_lines:N #1
{
  \spath_replace_lines:NV #1#1
}
\cs_generate_variant:Nn \spath_replace_lines:N {c}
\cs_new_protected_nopar:Npn \spath_greplace_lines:Nn #1#2
{
  \__spath_replace_lines:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_greplace_lines:Nn {NV, cV, cv, Nv}
\cs_new_protected_nopar:Npn \spath_greplace_lines:N #1
{
  \spath_greplace_lines:NV #1#1
}
\cs_generate_variant:Nn \spath_greplace_lines:N {c}
\cs_new_protected_nopar:Npn \__spath_replace_rectangles:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \tl_clear:N \l__spath_tmpb_tl

  \bool_do_until:nn
  {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl }
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl }
    \tl_set:Nx \l__spath_tmpd_tl {\tl_head:N \l__spath_tmpa_tl }
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl }
    \tl_set:Nx \l__spath_tmpe_tl {\tl_head:N \l__spath_tmpa_tl }
    \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl }

    \tl_if_eq:NNTF \l__spath_tmpc_tl \c_spath_rectcorner_tl
    {

      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl }
      \dim_set:Nn \l__spath_tmpa_dim
      {
        \tl_item:Nn \l__spath_tmpa_tl {1}
      }
      \dim_set:Nn \l__spath_tmpb_dim
      {
        \tl_item:Nn \l__spath_tmpa_tl {2}
      }

      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl }
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl }

      \tl_put_right:NV \l__spath_tmpb_tl \c_spath_moveto_tl
      \__spath_tl_put_right_braced:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
      \__spath_tl_put_right_braced:NV \l__spath_tmpb_tl \l__spath_tmpe_tl

      \tl_put_right:NV \l__spath_tmpb_tl \c_spath_lineto_tl
      \tl_put_right:Nx \l__spath_tmpb_tl
      {
        {
          \fp_to_dim:n { \l__spath_tmpd_tl + \l__spath_tmpa_dim }
        }
      }
      \__spath_tl_put_right_braced:NV \l__spath_tmpb_tl \l__spath_tmpe_tl

      \tl_put_right:NV \l__spath_tmpb_tl \c_spath_lineto_tl
      \tl_put_right:Nx \l__spath_tmpb_tl
      {
        {
          \fp_to_dim:n { \l__spath_tmpd_tl + \l__spath_tmpa_dim }
        }
      }
      \tl_put_right:Nx \l__spath_tmpb_tl
      {
        {
          \fp_to_dim:n { \l__spath_tmpe_tl + \l__spath_tmpb_dim }
        }
      }

      \tl_put_right:NV \l__spath_tmpb_tl \c_spath_lineto_tl
      \__spath_tl_put_right_braced:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
      \tl_put_right:Nx \l__spath_tmpb_tl
      {
        {
          \fp_to_dim:n { \l__spath_tmpe_tl + \l__spath_tmpb_dim }
        }
      }

      \tl_put_right:NV \l__spath_tmpb_tl \c_spath_closepath_tl
      \__spath_tl_put_right_braced:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
      \__spath_tl_put_right_braced:NV \l__spath_tmpb_tl \l__spath_tmpe_tl

    }
    {
      \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl
      \__spath_tl_put_right_braced:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
      \__spath_tl_put_right_braced:NV \l__spath_tmpb_tl \l__spath_tmpe_tl
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_generate_variant:Nn \__spath_replace_rectangles:n {V}
\cs_new_protected_nopar:Npn \spath_replace_rectangles:Nn #1#2
{
  \__spath_replace_rectangles:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_replace_rectangles:Nn {NV, cV, cv, Nv}
\cs_new_protected_nopar:Npn \spath_replace_rectangles:N #1
{
  \spath_replace_rectangles:NV #1#1
}
\cs_generate_variant:Nn \spath_replace_rectangles:N {c}
\cs_new_protected_nopar:Npn \spath_greplace_rectangles:Nn #1#2
{
  \__spath_replace_rectangles:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_greplace_rectangles:Nn {NV, cV, cv, Nv}
\cs_new_protected_nopar:Npn \spath_greplace_rectangles:N #1
{
  \spath_greplace_rectangles:NV #1#1
}
\cs_generate_variant:Nn \spath_greplace_rectangles:N {c}
\cs_new_protected_nopar:Npn \__spath_remove_empty_components:n #1
{
  \group_begin:
  \spath_components_to_seq:Nn \l__spath_tmpa_seq {#1}
  \tl_clear:N \l__spath_tmpa_tl
  \seq_map_inline:Nn \l__spath_tmpa_seq
  {
    \int_compare:nF
    {
      \tl_count:n {##1} == 3
    }
    {
      \tl_put_right:Nn \l__spath_tmpa_tl {##1}
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_remove_empty_components:Nn #1#2
{
  \__spath_remove_empty_components:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_remove_empty_components:Nn {NV}
\cs_new_protected_nopar:Npn \spath_remove_empty_components:N #1
{
  \spath_remove_empty_components:NV #1#1
}
\cs_generate_variant:Nn \spath_remove_empty_components:N {c}
\cs_new_protected_nopar:Npn \spath_gremove_empty_components:Nn #1#2
{
  \__spath_remove_empty_components:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gremove_empty_components:Nn {NV}
\cs_new_protected_nopar:Npn \spath_gremove_empty_components:N #1
{
  \spath_gremove_empty_components:NV #1#1
}
\cs_generate_variant:Nn \spath_gremove_empty_components:N {c}
\prg_new_protected_conditional:Npnn \spath_if_eq:nn #1#2 { T, F, TF }
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \tl_set:Nn \l__spath_tmpb_tl {#2}
  \bool_gset_true:N \g__spath_tmpa_bool
  \int_compare:nNnTF
  {\tl_count:N \l__spath_tmpa_tl}
  =
  {\tl_count:N \l__spath_tmpb_tl}
  {
    \int_step_inline:nnnn {1} {3} {\tl_count:N \l__spath_tmpa_tl}
    {
      \tl_set:Nx \l__spath_tmpc_tl {\tl_item:Nn \l__spath_tmpa_tl {##1}}
      \tl_set:Nx \l__spath_tmpd_tl {\tl_item:Nn \l__spath_tmpb_tl {##1}}
      \tl_if_eq:NNF \l__spath_tmpc_tl \l__spath_tmpd_tl
      {
        \bool_gset_false:N \g__spath_tmpa_bool
      }
      \dim_set:Nn \l__spath_tmpa_dim {\tl_item:Nn \l__spath_tmpa_tl {##1+1}}
      \dim_set:Nn \l__spath_tmpb_dim {\tl_item:Nn \l__spath_tmpb_tl {##1+1}}
      \dim_compare:nF
      {
        \dim_abs:n
        {
          \l__spath_tmpa_dim - \l__spath_tmpb_dim
        }
        < 0.001pt
      }
      {
        \bool_gset_false:N \g__spath_tmpa_bool
      }
      \dim_set:Nn \l__spath_tmpa_dim {\tl_item:Nn \l__spath_tmpa_tl {##1+2}}
      \dim_set:Nn \l__spath_tmpb_dim {\tl_item:Nn \l__spath_tmpb_tl {##1+2}}
      \dim_compare:nF
      {
        \dim_abs:n
        {
          \l__spath_tmpa_dim - \l__spath_tmpb_dim
        }
        < 0.001pt
      }
      {
        \bool_gset_false:N \g__spath_tmpa_bool
      }
    }
  }
  {
    \bool_gset_false:N \g__spath_tmpa_bool
  }
  \group_end:
  \bool_if:NTF \g__spath_tmpa_bool
  {
    \prg_return_true:
  }
  {
    \prg_return_false:
  }
}
\prg_generate_conditional_variant:Nnn \spath_if_eq:nn {VV, Vn, nV, vv} {TF, T, F}
\cs_new_protected_nopar:Npn \__spath_split_curve:nn #1#2
{
  \group_begin:
  \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_moveto_tl
  \tl_put_right:Nx \l__spath_tmpa_tl {
    {\tl_item:nn {#1} {2}}
    {\tl_item:nn {#1} {3}}
  }
  \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curvetoa_tl
  \tl_put_right:Nx \l__spath_tmpa_tl
  {
    {\fp_to_dim:n
    {
      (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5}
    }}
    {\fp_to_dim:n
    {
      (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6}
    }}
  }

  \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curvetob_tl
  \tl_put_right:Nx \l__spath_tmpa_tl
  {
    {\fp_to_dim:n
    {
      (1 - #2)^2 * \tl_item:nn {#1} {2}
      + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {5}
      + (#2)^2 * \tl_item:nn {#1} {8}
    }}
    {\fp_to_dim:n
    {
      (1 - #2)^2 * \tl_item:nn {#1} {3}
      + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {6}
      + (#2)^2 * \tl_item:nn {#1} {9}
    }}
  }

  \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curveto_tl
  \tl_put_right:Nx \l__spath_tmpa_tl
  {
    {\fp_to_dim:n
      {
        (1 - #2)^3 * \tl_item:nn {#1} {2}
        + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {5}
        + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {8}
        + (#2)^3 * \tl_item:nn {#1} {11}
    }}
    {\fp_to_dim:n
    {
      (1 - #2)^3 * \tl_item:nn {#1} {3}
      + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {6}
      + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {9}
      + (#2)^3 * \tl_item:nn {#1} {12}
    }}
  }

  \tl_gclear:N \g__spath_output_tl
  \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpa_tl

  \tl_clear:N \l__spath_tmpa_tl
  \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_moveto_tl
  \tl_put_right:Nx \l__spath_tmpa_tl
  {
    {\fp_to_dim:n
      {
        (1 - #2)^3 * \tl_item:nn {#1} {2}
        + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {5}
        + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {8}
        + (#2)^3 * \tl_item:nn {#1} {11}
    }}
    {\fp_to_dim:n
    {
      (1 - #2)^3 * \tl_item:nn {#1} {3}
      + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {6}
      + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {9}
      + (#2)^3 * \tl_item:nn {#1} {12}
    }}
  }

  \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curvetoa_tl
  \tl_put_right:Nx \l__spath_tmpa_tl
  {
    {\fp_to_dim:n
    {
      (1 - #2)^2 * \tl_item:nn {#1} {5}
      + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {8}
      + (#2)^2 * \tl_item:nn {#1} {11}
    }}
    {\fp_to_dim:n
    {
      (1 - #2)^2 * \tl_item:nn {#1} {6}
      + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {9}
      + (#2)^2 * \tl_item:nn {#1} {12}
    }}
  }
  \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curvetob_tl
  \tl_put_right:Nx \l__spath_tmpa_tl
  {
    {\fp_to_dim:n
    {
      (1 - #2) * \tl_item:nn {#1} {8} + (#2) * \tl_item:nn {#1} {11}
    }}
    {\fp_to_dim:n
    {
      (1 - #2) * \tl_item:nn {#1} {9} + (#2) * \tl_item:nn {#1} {12}
    }}
  }
  \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curveto_tl
  \tl_put_right:Nx \l__spath_tmpa_tl {
    {\tl_item:nn {#1} {11}}
    {\tl_item:nn {#1} {12}}
  }

  \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_generate_variant:Nn \__spath_split_curve:nn {nv, nV}
\cs_new_protected_nopar:Npn \spath_split_curve:NNnn #1#2#3#4
{
  \__spath_split_curve:nn {#3}{#4}
  \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_curve:NNnn {NNnV, NNVn, NNVV}
\cs_new_protected_nopar:Npn \spath_gsplit_curve:NNnn #1#2#3#4
{
  \__spath_split_curve:nn {#3}{#4}
  \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_curve:NNnn {NNnV, NNVn, NNVV}
\cs_new_protected_nopar:Npn \__spath_maybe_split_curve:n #1
{
  \group_begin:
  \fp_set:Nn \l__spath_tmpa_fp
  {
    (
    \tl_item:nn {#1} {3}
    - 3 * \tl_item:nn {#1} {6}
    + 3 * \tl_item:nn {#1} {9}
    - \tl_item:nn {#1} {12}
    )
    *
    (3 * \tl_item:nn {#1} {8} - 3 * \tl_item:nn {#1} {11})
    -
    (
    \tl_item:nn {#1} {2}
    - 3 * \tl_item:nn {#1} {5}
    + 3 * \tl_item:nn {#1} {8}
    - \tl_item:nn {#1} {11}
    )
    *
    (3 * \tl_item:nn {#1} {9} - 3 * \tl_item:nn {#1} {12})
  }
  \fp_set:Nn \l__spath_tmpb_fp
  {
    (
    \tl_item:nn {#1} {2}
    - 3 * \tl_item:nn {#1} {5}
    + 3 * \tl_item:nn {#1} {8}
    - \tl_item:nn {#1} {11}
    )
    *
    (
    3 * \tl_item:nn {#1} {6}
    - 6 * \tl_item:nn {#1} {9}
    + 3 * \tl_item:nn {#1} {12}
    )
    -
    (
    \tl_item:nn {#1} {3}
    - 3 * \tl_item:nn {#1} {6}
    + 3 * \tl_item:nn {#1} {9}
    - \tl_item:nn {#1} {12}
    )
    *
    (
    3 * \tl_item:nn {#1} {5}
    - 6 * \tl_item:nn {#1} {8}
    + 3 * \tl_item:nn {#1} {11}
    )
  }
  \fp_compare:nTF
  {
    \l__spath_tmpb_fp != 0
  }
  {
    \fp_set:Nn \l__spath_tmpa_fp {.5 * \l__spath_tmpa_fp / \l__spath_tmpb_fp}
    \bool_if:nTF
    {
      \fp_compare_p:n {0 < \l__spath_tmpa_fp}
      &&
      \fp_compare_p:n {\l__spath_tmpa_fp < 1}
    }
    {
      \__spath_split_curve:nV {#1} \l__spath_tmpa_fp
    }
    {
      \tl_gset:Nn \g__spath_output_tl { {#1} {} }
    }
  }
  {
    \tl_gset:Nn \g__spath_output_tl { {#1} {} }
  }
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_maybe_split_curve:NNn #1#2#3
{
  \__spath_maybe_split_curve:n {#3}
  \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_maybe_split_curve:NNn {NNn, NNV }
\cs_new_protected_nopar:Npn \spath_maybe_gsplit_curve:NNn #1#2#3
{
  \__spath_maybe_split_curve:n {#3}
  \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_maybe_gsplit_curve:NNn {NNn, NNV}
\cs_new_protected_nopar:Npn \__spath_split_curves:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \tl_clear:N \l__spath_tmpb_tl
  \tl_clear:N \l__spath_tmpc_tl
  \bool_do_until:nn
  {
    \tl_if_empty_p:N \l__spath_tmpa_tl
  }
  {
    \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
    \token_case_meaning:NnF \l__spath_tmpc_tl
    {
      \c_spath_curvetoa_tl
      {
        \tl_clear:N \l__spath_tmpd_tl
        \tl_set_eq:NN \l__spath_tmpd_tl \c_spath_moveto_tl
        \tl_put_right:Nx \l__spath_tmpd_tl
        {
          { \dim_use:N \l__spath_tmpa_dim }
          { \dim_use:N \l__spath_tmpb_dim }
        }
        \dim_set:Nn \l__spath_tmpa_dim
        {
          \tl_item:Nn \l__spath_tmpa_tl {8}
        }
        \dim_set:Nn \l__spath_tmpb_dim
        {
          \tl_item:Nn \l__spath_tmpa_tl {9}
        }
        \prg_replicate:nn {3}
        {
          \tl_put_right:Nx \l__spath_tmpd_tl
          {
            \tl_item:Nn \l__spath_tmpa_tl {1}
            {\tl_item:Nn \l__spath_tmpa_tl {2}}
            {\tl_item:Nn \l__spath_tmpa_tl {3}}
          }
          \prg_replicate:nn {3}
          {
            \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
          }
        }

        \spath_maybe_split_curve:NNV
        \l__spath_tmpd_tl
        \l__spath_tmpe_tl
        \l__spath_tmpd_tl
        \prg_replicate:nn {3}
        {
          \tl_set:Nx \l__spath_tmpd_tl {\tl_tail:N \l__spath_tmpd_tl}
          \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl}
        }
        \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
        \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpe_tl
      }
    }
    {
      \dim_set:Nn \l__spath_tmpa_dim
      {
        \tl_item:Nn \l__spath_tmpa_tl {2}
      }
      \dim_set:Nn \l__spath_tmpb_dim
      {
        \tl_item:Nn \l__spath_tmpa_tl {3}
      }
      \tl_put_right:Nx \l__spath_tmpb_tl
      {
        \tl_item:Nn \l__spath_tmpa_tl {1}
        {\tl_item:Nn \l__spath_tmpa_tl {2}}
        {\tl_item:Nn \l__spath_tmpa_tl {3}}
      }
      \prg_replicate:nn {3}
      {
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
      }
    }
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_split_curves:Nn #1#2
{
  \__spath_split_curves:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_curves:Nn {NV, cV, cn, cv }
\cs_new_protected_nopar:Npn \spath_split_curves:N #1
{
  \spath_split_curves:NV #1#1
}
\cs_generate_variant:Nn \spath_split_curves:N {c}
\cs_new_protected_nopar:Npn \spath_gsplit_curves:Nn #1#2
{
  \__spath_split_curves:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_curves:Nn {NV, cV, cn, cv }
\cs_new_protected_nopar:Npn \spath_gsplit_curves:N #1
{
  \spath_gsplit_curves:NV #1#1
}
\cs_generate_variant:Nn \spath_gsplit_curves:N {c}
\cs_new_protected_nopar:Npn \__spath_split_line:nn #1#2
{
  \group_begin:
  \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_moveto_tl
  \tl_put_right:Nx \l__spath_tmpa_tl {
    {\tl_item:nn {#1} {2}}
    {\tl_item:nn {#1} {3}}
  }
  \tl_put_right:NV \l__spath_tmpa_tl \c_spath_lineto_tl
  \tl_put_right:Nx \l__spath_tmpa_tl
  {
    {\fp_to_dim:n
    {
      (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5}
    }}
    {\fp_to_dim:n
    {
      (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6}
    }}
  }
  \tl_gclear:N \g__spath_output_tl
  \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpa_tl

  \tl_clear:N \l__spath_tmpa_tl
  \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_moveto_tl
  \tl_put_right:Nx \l__spath_tmpa_tl
  {
    {\fp_to_dim:n
    {
      (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5}
    }}
    {\fp_to_dim:n
    {
      (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6}
    }}
  }
  \tl_put_right:NV \l__spath_tmpa_tl \c_spath_lineto_tl
  \tl_put_right:Nx \l__spath_tmpa_tl {
    {\tl_item:nn {#1} {5}}
    {\tl_item:nn {#1} {6}}
  }

  \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_split_line:NNnn #1#2#3#4
{
  \__spath_split_line:nn {#3}{#4}
  \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_line:NNnn {NNnV, NNVn, NNVV}
\cs_new_protected_nopar:Npn \spath_gsplit_line:NNnn #1#2#3#4
{
  \__spath_split_line:nn {#3}{#4}
  \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_line:NNnn {NNnV, NNVn, NNVV}
\cs_new_protected_nopar:Npn \__spath_split_rectangle:nn #1#2
{
  \group_begin:
  \spath_open:Nn \l__spath_tmpa_tl {#1}
  \fp_set:Nn \l__spath_tmpa_fp {4*(#2)}
  \spath_split_at:NNVV
  \l__spath_tmpa_tl \l__spath_tmpb_tl \l__spath_tmpa_tl \l__spath_tmpa_fp
  \__spath_append_no_move:VV \l__spath_tmpb_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_split_rectangle:Nnn #1#2#3
{
  \__spath_split_rectangle:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_rectangle:Nnn {NnV, NVn, NVV}
\cs_new_protected_nopar:Npn \spath_gsplit_rectangle:Nnn #1#2#3
{
  \__spath_split_rectangle:nn {#2}{#3}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_rectangle:Nnn {NnV, NVn, NVV}
\cs_new_protected_nopar:Npn \__spath_split_at:nn #1#2
{
  \group_begin:
  \int_set:Nn \l__spath_tmpa_int {\fp_to_int:n {floor(#2) + 1}}
  \fp_set:Nn \l__spath_tmpa_fp {#2 - floor(#2)}

  % Is split point near one end or other of a component?
  \fp_compare:nT
  {
    \l__spath_tmpa_fp < 0.01
  }
  {
    % Near the start, so we'll place it at the start
    \fp_set:Nn \l__spath_tmpa_fp {0}
  }
  \fp_compare:nT
  {
    \l__spath_tmpa_fp > 0.99
  }
  {
    % Near the end, so we'll place it at the end
    \fp_set:Nn \l__spath_tmpa_fp {0}
    \int_incr:N \l__spath_tmpa_int
  }

  \int_zero:N \l__spath_tmpb_int
  \bool_set_true:N \l__spath_tmpa_bool

  \tl_set:Nn \l__spath_tmpe_tl {#1}

  \dim_zero:N \l__spath_tmpa_dim
  \dim_zero:N \l__spath_tmpb_dim

  % Remember if the component is closed
  \spath_finalaction:NV \l__spath_tmpa_tl \l__spath_tmpe_tl

  \bool_set:Nn \l__spath_closed_bool
  {
    \tl_if_eq_p:NN \l__spath_tmpa_tl \c_spath_closepath_tl
    ||
    \tl_if_eq_p:NN \l__spath_tmpa_tl \c_spath_rectcorner_tl
  }

  % Open it
  \spath_open:N \l__spath_tmpe_tl

  \tl_clear:N \l__spath_tmpa_tl
  \tl_clear:N \l__spath_tmpb_tl
  \tl_clear:N \l__spath_tmpc_tl
  \tl_clear:N \l__spath_tmpd_tl

  \bool_until_do:nn {
    \tl_if_empty_p:N \l__spath_tmpe_tl
    ||
    \int_compare_p:n { \l__spath_tmpa_int == \l__spath_tmpb_int  }
  }
  {
    \tl_set:Nx \l__spath_tmpf_tl {\tl_head:N \l__spath_tmpe_tl}
    \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl }
    \token_case_meaning:Nn \l__spath_tmpf_tl
    {
      \c_spath_lineto_tl
      {
        \int_incr:N \l__spath_tmpb_int
      }
      \c_spath_curvetoa_tl
      {
        \int_incr:N \l__spath_tmpb_int
      }
      \c_spath_rectcorner_tl
      {
        \int_incr:N \l__spath_tmpb_int
      }
    }
    \int_compare:nT { \l__spath_tmpb_int < \l__spath_tmpa_int  }
    {
      \tl_put_right:NV \l__spath_tmpc_tl \l__spath_tmpf_tl

      \tl_put_right:Nx \l__spath_tmpc_tl
      {{ \tl_head:N \l__spath_tmpe_tl }}
      \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpe_tl}
      \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl }

      \tl_put_right:Nx \l__spath_tmpc_tl
      {{ \tl_head:N \l__spath_tmpe_tl }}
      \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpe_tl}
      \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl }

    }
  }

  \tl_clear:N \l__spath_tmpd_tl
  \tl_put_right:NV \l__spath_tmpd_tl \c_spath_moveto_tl
  \tl_put_right:Nx \l__spath_tmpd_tl
  {
    {\dim_use:N \l__spath_tmpa_dim}
    {\dim_use:N \l__spath_tmpb_dim}
  }

  \fp_compare:nTF
  {
    \l__spath_tmpa_fp == 0
  }
  {
    \tl_set_eq:NN \l__spath_tmpb_tl \l__spath_tmpd_tl
    \tl_if_empty:NF \l__spath_tmpe_tl
    {
      \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpf_tl
      \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpe_tl
    }
  }
  {

    \token_case_meaning:Nn \l__spath_tmpf_tl
    {
      \c_spath_lineto_tl
      {
        \tl_put_right:NV \l__spath_tmpd_tl \l__spath_tmpf_tl
        \tl_put_right:Nx \l__spath_tmpd_tl
        {{ \tl_head:N \l__spath_tmpe_tl }}
        \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl }

        \tl_put_right:Nx \l__spath_tmpd_tl
        {{ \tl_head:N \l__spath_tmpe_tl }}
        \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl }

        \spath_split_line:NNVV
        \l__spath_tmpa_tl
        \l__spath_tmpb_tl
        \l__spath_tmpd_tl
        \l__spath_tmpa_fp

        \prg_replicate:nn {3} {
          \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
        }

        \tl_put_right:NV \l__spath_tmpc_tl \l__spath_tmpa_tl
        \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpe_tl
      }
      \c_spath_curvetoa_tl
      {
        \tl_put_right:NV \l__spath_tmpd_tl \l__spath_tmpf_tl
        \tl_put_right:Nx \l__spath_tmpd_tl
        {{ \tl_head:N \l__spath_tmpe_tl }}
        \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl }

        \tl_put_right:Nx \l__spath_tmpd_tl
        {{ \tl_head:N \l__spath_tmpe_tl }}
        \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl }

        \prg_replicate:nn {2} {

          \tl_put_right:Nx \l__spath_tmpd_tl
          { \tl_head:N \l__spath_tmpe_tl }
          \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl }

          \tl_put_right:Nx \l__spath_tmpd_tl
          {{ \tl_head:N \l__spath_tmpe_tl }}
          \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl }

          \tl_put_right:Nx \l__spath_tmpd_tl
          {{ \tl_head:N \l__spath_tmpe_tl }}
          \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl }
        }

        \spath_split_curve:NNVV
        \l__spath_tmpa_tl
        \l__spath_tmpb_tl
        \l__spath_tmpd_tl \l__spath_tmpa_fp

        \prg_replicate:nn {3} {
          \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
        }

        \tl_put_right:NV \l__spath_tmpc_tl \l__spath_tmpa_tl
        \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpe_tl
      }

      \c_spath_rectcorner_tl
      {
        \tl_clear:N \l__spath_tmpd_tl
        \tl_put_right:NV \l__spath_tmpd_tl \l__spath_tmpf_tl

        \tl_put_right:Nx \l__spath_tmpd_tl {{\tl_head:N \l__spath_tmpe_tl}}
        \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl}
        \tl_put_right:Nx \l__spath_tmpd_tl {{\tl_head:N \l__spath_tmpe_tl}}
        \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl}

        \tl_put_right:Nx \l__spath_tmpd_tl {\tl_head:N \l__spath_tmpe_tl}
        \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl}

        \tl_put_right:Nx \l__spath_tmpd_tl {{\tl_head:N \l__spath_tmpe_tl}}
        \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl}
        \tl_put_right:Nx \l__spath_tmpd_tl {{\tl_head:N \l__spath_tmpe_tl}}
        \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpe_tl}

        \spath_split_rectangle:NVV
        \l__spath_tmpa_tl
        \l__spath_tmpd_tl
        \l__spath_tmpa_fp

        \tl_put_right:NV \l__spath_tmpc_tl \l__spath_tmpa_tl
        \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpe_tl
      }

    }
  }

  \bool_if:NT \l__spath_closed_bool
  {
    \prg_replicate:nn {3}
    {
      \tl_set:Nx \l__spath_tmpc_tl {\tl_tail:N \l__spath_tmpc_tl}
    }
    \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl
    \tl_set_eq:NN \l__spath_tmpc_tl \l__spath_tmpb_tl
    \tl_clear:N \l__spath_tmpb_tl
  }

  \tl_gclear:N \g__spath_output_tl
  \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpc_tl
  \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpb_tl
  \group_end:
}
\cs_generate_variant:Nn  \__spath_split_at:nn {nV, VV}
\cs_new_protected_nopar:Npn \__spath_split_at_normalised:nn #1#2
{
  \group_begin:
  \spath_reallength:Nn \l__spath_tmpa_int {#1}

  \tl_set:Nx \l__spath_tmpa_tl
  {\fp_to_decimal:n {(#2) * (\l__spath_tmpa_int)}}
  \__spath_split_at:nV {#1} \l__spath_tmpa_tl
  \group_end:
}
\cs_generate_variant:Nn  \__spath_split_at_normalised:nn {nV}
\cs_new_protected_nopar:Npn \spath_split_at:NNnn #1#2#3#4
{
  \__spath_split_at:nn {#3}{#4}
  \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_at:NNnn {NNVn, NNVV, NNnV}
\cs_new_protected_nopar:Npn \spath_gsplit_at:NNnn #1#2#3#4
{
  \__spath_split_at:nn {#3}{#4}
  \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_at:NNnn {NNVn, NNVV, NNnV}
\cs_new_protected_nopar:Npn \spath_split_at_keep_start:Nnn #1#2#3
{
  \__spath_split_at:nn {#2}{#3}
  \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_at_keep_start:Nnn {NVn}
\cs_new_protected_nopar:Npn \spath_split_at_keep_start:Nn #1#2
{
  \spath_split_at_keep_start:NVn #1#1{#2}
}
\cs_new_protected_nopar:Npn \spath_gsplit_at_keep_start:Nnn #1#2#3
{
  \__spath_split_at:nn {#2}{#3}
  \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_at_keep_start:Nnn {NVn}
\cs_new_protected_nopar:Npn \spath_gsplit_at_keep_start:Nn #1#2
{
  \spath_gsplit_at_keep_start:NVn #1#1{#2}
}
\cs_new_protected_nopar:Npn \spath_split_at_keep_end:Nnn #1#2#3
{
  \__spath_split_at:nn {#2}{#3}
  \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_at_keep_end:Nnn {NVn}
\cs_new_protected_nopar:Npn \spath_split_at_keep_end:Nn #1#2
{
  \spath_split_at_keep_end:NVn #1#1{#2}
}
\cs_new_protected_nopar:Npn \spath_gsplit_at_keep_end:Nnn #1#2#3
{
  \__spath_split_at:nn {#2}{#3}
  \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_at_keep_end:Nnn {NVn}
\cs_new_protected_nopar:Npn \spath_gsplit_at_keep_end:Nn #1#2
{
  \spath_gsplit_at_keep_end:NVn #1#1{#2}
}
\cs_new_protected_nopar:Npn \spath_split_at_normalised:NNnn #1#2#3#4
{
  \__spath_split_at_normalised:nn {#3}{#4}
  \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_at_normalised:NNnn {NNVn, NNVV, NNnV, ccvn}
\cs_new_protected_nopar:Npn \spath_gsplit_at_normalised:NNnn #1#2#3#4
{
  \__spath_split_at_normalised:nn {#3}{#4}
  \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_at_normalised:NNnn {NNVn, NNVV, NNnV, ccvn}
\cs_new_protected_nopar:Npn \spath_split_at_normalised_keep_start:Nnn #1#2#3
{
  \__spath_split_at_normalised:nn {#2}{#3}
  \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_at_normalised_keep_start:Nnn {NVn}
\cs_new_protected_nopar:Npn \spath_split_at_normalised_keep_start:Nn #1#2
{
  \spath_split_at_normalised_keep_start:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_split_at_normalised_keep_start:Nn {cn}
\cs_new_protected_nopar:Npn \spath_gsplit_at_normalised_keep_start:Nnn #1#2#3
{
  \__spath_split_at_normalised:nn {#2}{#3}
  \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_at_normalised_keep_start:Nnn {NVn}
\cs_new_protected_nopar:Npn \spath_gsplit_at_normalised_keep_start:Nn #1#2
{
  \spath_gsplit_at_normalised_keep_start:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gsplit_at_normalised_keep_start:Nn {cn}
\cs_new_protected_nopar:Npn \spath_split_at_normalised_keep_end:Nnn #1#2#3
{
  \__spath_split_at_normalised:nn {#2}{#3}
  \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_at_normalised_keep_end:Nnn {NVn}
\cs_new_protected_nopar:Npn \spath_split_at_normalised_keep_end:Nn #1#2
{
  \spath_split_at_normalised_keep_end:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_split_at_normalised_keep_end:Nn {cn}
\cs_new_protected_nopar:Npn \spath_gsplit_at_normalised_keep_end:Nnn #1#2#3
{
  \__spath_split_at_normalised:nn {#2}{#3}
  \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {2}}
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_at_normalised_keep_end:Nnn {NVn}
\cs_new_protected_nopar:Npn \spath_gsplit_at_normalised_keep_end:Nn #1#2
{
  \spath_gsplit_at_normalised_keep_end:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gsplit_at_normalised_keep_end:Nn {cn}
\cs_new_protected_nopar:Npn \spath_split_at:Nnn #1#2#3
{
  \__spath_split_at:nn {#2}{#3}
  \tl_set:Nx #1
  {
    \tl_item:Nn \g__spath_output_tl {1}
    \tl_item:Nn \g__spath_output_tl {2}
  }
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_at:Nnn {NVn, NVV}
\cs_new_protected_nopar:Npn \spath_split_at:Nn #1#2
{
  \spath_split_at:NVn #1#1{#2}
}
\cs_new_protected_nopar:Npn \spath_gsplit_at:Nnn #1#2#3
{
  \__spath_split_at:nn {#2}{#3}
  \tl_gset:Nx #1
  {
    \tl_item:Nn \g__spath_output_tl {1}
    \tl_item:Nn \g__spath_output_tl {2}
  }
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_at:Nnn {NVn, NVV}
\cs_new_protected_nopar:Npn \spath_gsplit_at:Nn #1#2
{
  \spath_gsplit_at:NVn #1#1{#2}
}
\cs_new_protected_nopar:Npn \spath_split_at_normalised:Nnn #1#2#3
{
  \__spath_split_at_normalised:nn {#2}{#3}
  \tl_set:Nx #1
  {
    \tl_item:Nn \g__spath_output_tl {1}
    \tl_item:Nn \g__spath_output_tl {2}
  }
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_at_normalised:Nnn {NVn, NVV}
\cs_new_protected_nopar:Npn \spath_split_at_normalised:Nn #1#2
{
  \spath_split_at_normalised:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_split_at_normalised:Nn {cn}
\cs_new_protected_nopar:Npn \spath_gsplit_at_normalised:Nnn #1#2#3
{
  \__spath_split_at_normalised:nn {#2}{#3}
  \tl_gset:Nx #1
  {
    \tl_item:Nn \g__spath_output_tl {1}
    \tl_item:Nn \g__spath_output_tl {2}
  }
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_at_normalised:Nnn {NVn, NVV}
\cs_new_protected_nopar:Npn \spath_gsplit_at_normalised:Nn #1#2
{
  \spath_gsplit_at_normalised:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gsplit_at_normalised:Nn {cn}
\cs_new_protected_nopar:Npn \__spath_shorten_at_end:nn #1#2
{
  \int_compare:nTF
  {
    \tl_count:n {#1} > 3
  }
  {
    \group_begin:
    \tl_set:Nn \l__spath_tmpa_tl {#1}
    \tl_reverse:N \l__spath_tmpa_tl

    \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {3}}

    \tl_clear:N \l__spath_tmpe_tl
    \tl_if_eq:NNTF \l__spath_tmpb_tl \c_spath_curveto_tl
    {
      \int_set:Nn \l__spath_tmpa_int {3}
    }
    {
      \int_set:Nn \l__spath_tmpa_int {1}
    }

    \prg_replicate:nn { \l__spath_tmpa_int }
    {
      \tl_put_right:Nx \l__spath_tmpe_tl
      {
        {\tl_head:N \l__spath_tmpa_tl}
      }
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
      \tl_put_right:Nx \l__spath_tmpe_tl
      {
        {\tl_head:N \l__spath_tmpa_tl}
      }
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
      \tl_put_right:Nx \l__spath_tmpe_tl
      {
        \tl_head:N \l__spath_tmpa_tl
      }
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    }

    \tl_put_right:Nx \l__spath_tmpe_tl
    {
      {\tl_item:Nn \l__spath_tmpa_tl {1}}
      {\tl_item:Nn \l__spath_tmpa_tl {2}}
    }
    \tl_put_right:NV \l__spath_tmpe_tl \c_spath_moveto_tl

    \tl_reverse:N \l__spath_tmpa_tl

    \fp_set:Nn \l__spath_tmpa_fp
    {
      \dim_to_fp:n {\tl_item:Nn \l__spath_tmpe_tl {4}}
      -
      \dim_to_fp:n {\tl_item:Nn \l__spath_tmpe_tl {1}}
    }

    \fp_set:Nn \l__spath_tmpb_fp
    {
      \dim_to_fp:n {\tl_item:Nn \l__spath_tmpe_tl {5}}
      -
      \dim_to_fp:n {\tl_item:Nn \l__spath_tmpe_tl {2}}
    }

    \fp_set:Nn \l__spath_tmpc_fp
    {
      sqrt(
      \l__spath_tmpa_fp * \l__spath_tmpa_fp
      +
      \l__spath_tmpb_fp *  \l__spath_tmpb_fp
      ) * \l__spath_tmpa_int
    }

    \fp_compare:nTF
    {
      \l__spath_tmpc_fp > #2
    }
    {

      \fp_set:Nn \l__spath_tmpc_fp
      {
        (\l__spath_tmpc_fp - #2)/ \l__spath_tmpc_fp
      }

      \tl_reverse:N \l__spath_tmpe_tl

      \tl_if_eq:NNTF \l__spath_tmpb_tl \c_spath_curveto_tl
      {
        \spath_split_curve:NNVV
        \l__spath_tmpc_tl
        \l__spath_tmpd_tl
        \l__spath_tmpe_tl
        \l__spath_tmpc_fp
      }
      {
        \spath_split_line:NNVV
        \l__spath_tmpc_tl
        \l__spath_tmpd_tl
        \l__spath_tmpe_tl
        \l__spath_tmpc_fp
      }

      \prg_replicate:nn {3}
      {
        \tl_set:Nx \l__spath_tmpc_tl {\tl_tail:N \l__spath_tmpc_tl}
      }

      \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpc_tl

    }
    {

      \int_compare:nT
      {
        \tl_count:N \l__spath_tmpa_tl > 3
      }
      {
        \dim_set:Nn \l__spath_tmpa_dim {\fp_to_dim:n {#2 - \l__spath_tmpc_fp } }
        \spath_shorten_at_end:NV \l__spath_tmpa_tl \l__spath_tmpa_dim
      }
    }

    \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
    \group_end:
  }
  {
    \tl_gset:Nn \g__spath_output_tl {#1}
  }
}
\cs_new_protected_nopar:Npn \spath_shorten_at_end:Nnn #1#2#3
{
  \__spath_shorten_at_end:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_shorten_at_end:Nnn {NVV, cnn, cVV, NVn}
\cs_new_protected_nopar:Npn \spath_shorten_at_end:Nn #1#2
{
  \spath_shorten_at_end:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_shorten_at_end:Nn {cn, cV, NV}
\cs_new_protected_nopar:Npn \spath_gshorten_at_end:Nnn #1#2#3
{
  \__spath_shorten_at_end:nn {#2}{#3}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gshorten_at_end:Nnn {NVV, cnn, cVV, NVn}
\cs_new_protected_nopar:Npn \spath_gshorten_at_end:Nn #1#2
{
  \spath_gshorten_at_end:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gshorten_at_end:Nn {cn, cV, NV}
\cs_new_protected_nopar:Npn \__spath_shorten_at_start:nn #1#2
{
  \int_compare:nTF
  {
    \tl_count:n {#1} > 3
  }
  {
  \group_begin:
  \tl_set:Nn \l__spath_tmpa_tl {#1}

  \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {4}}

    \tl_clear:N \l__spath_tmpe_tl

  \tl_if_eq:NNTF \l__spath_tmpb_tl \c_spath_curvetoa_tl
  {
    \int_set:Nn \l__spath_tmpa_int {3}
  }
  {
    \int_set:Nn \l__spath_tmpa_int {1}
  }

  \tl_set_eq:NN \l__spath_tmpe_tl \c_spath_moveto_tl
  \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl }

  \prg_replicate:nn { \l__spath_tmpa_int }
  {
    \__spath_tl_put_right_braced:Nx
    \l__spath_tmpe_tl
    {\tl_item:Nn \l__spath_tmpa_tl {1}}
    \__spath_tl_put_right_braced:Nx
    \l__spath_tmpe_tl
    {\tl_item:Nn \l__spath_tmpa_tl {2}}
    \tl_put_right:Nx \l__spath_tmpe_tl {\tl_item:Nn \l__spath_tmpa_tl {3}}

    \prg_replicate:nn {3}
    {
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl }
    }
  }
  \__spath_tl_put_right_braced:Nx
  \l__spath_tmpe_tl
  {\tl_item:Nn \l__spath_tmpa_tl {1}}
  \__spath_tl_put_right_braced:Nx
  \l__spath_tmpe_tl
  {\tl_item:Nn \l__spath_tmpa_tl {2}}

  \fp_set:Nn \l__spath_tmpa_fp
  {
    \dim_to_fp:n {\tl_item:Nn \l__spath_tmpe_tl {5}}
    -
    \dim_to_fp:n {\tl_item:Nn \l__spath_tmpe_tl {2}}
  }

  \fp_set:Nn \l__spath_tmpb_fp
  {
    \dim_to_fp:n {\tl_item:Nn \l__spath_tmpe_tl {6}}
    -
    \dim_to_fp:n {\tl_item:Nn \l__spath_tmpe_tl {3}}
  }

  \fp_set:Nn \l__spath_tmpc_fp
  {
    sqrt(
    \l__spath_tmpa_fp * \l__spath_tmpa_fp
    +
    \l__spath_tmpb_fp *  \l__spath_tmpb_fp
    )
    *
    \l__spath_tmpa_int
  }

  \fp_compare:nTF
  {
    \l__spath_tmpc_fp > #2
  }
  {

    \fp_set:Nn \l__spath_tmpc_fp
    {
      #2/ \l__spath_tmpc_fp
    }

    \tl_if_eq:NNTF \l__spath_tmpb_tl \c_spath_curvetoa_tl
    {
      \spath_split_curve:NNVV
      \l__spath_tmpc_tl
      \l__spath_tmpd_tl
      \l__spath_tmpe_tl
      \l__spath_tmpc_fp
    }
    {
      \spath_split_line:NNVV
      \l__spath_tmpc_tl
      \l__spath_tmpd_tl
      \l__spath_tmpe_tl
      \l__spath_tmpc_fp
    }

    \prg_replicate:nn {2}
    {
      \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
    }

    \tl_put_left:NV \l__spath_tmpa_tl \l__spath_tmpd_tl

  }
  {

    \tl_put_left:NV \l__spath_tmpa_tl \c_spath_moveto_tl

    \int_compare:nT
    {
      \tl_count:N \l__spath_tmpa_tl > 3
    }
    {
      \dim_set:Nn \l__spath_tmpa_dim {\fp_to_dim:n {#2 - \l__spath_tmpc_fp } }
      \spath_shorten_at_start:NV \l__spath_tmpa_tl \l__spath_tmpa_dim
    }
  }

  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
  }
  {
    \tl_gset:Nn \g__spath_output_tl {#1}
  }
}
\cs_new_protected_nopar:Npn \spath_shorten_at_start:Nnn #1#2#3
{
  \__spath_shorten_at_start:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_shorten_at_start:Nnn {NVV, cnn, cVV, NVn}
\cs_new_protected_nopar:Npn \spath_shorten_at_start:Nn #1#2
{
  \spath_shorten_at_start:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_shorten_at_start:Nn {cn, cV, NV}
\cs_new_protected_nopar:Npn \spath_gshorten_at_start:Nnn #1#2#3
{
  \__spath_shorten_at_start:nn {#2}{#3}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gshorten_at_start:Nnn {NVV, cnn, cVV, NVn}
\cs_new_protected_nopar:Npn \spath_gshorten_at_start:Nn #1#2
{
  \spath_gshorten_at_start:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gshorten_at_start:Nn {cn, cV, NV}
\cs_new_protected_nopar:Npn \spath_shorten_at_both_ends:Nnn #1#2#3
{
  \spath_shorten_at_start:Nnn #1{#2}{#3}
  \spath_shorten_at_end:Nnn #1{#2}{#3}
}
\cs_new_protected_nopar:Npn \spath_shorten_at_both_ends:Nn #1#2
{
  \spath_shorten_at_start:Nn #1{#2}
  \spath_shorten_at_end:Nn #1{#2}
}
\cs_generate_variant:Nn \spath_shorten_at_both_ends:Nn {cn, cV, NV}
\cs_new_protected_nopar:Npn \spath_gshorten_at_both_ends:Nnn #1#2#3
{
  \spath_gshorten_at_start:Nnn #1{#2}{#3}
  \spath_gshorten_at_end:Nnn #1{#2}{#3}
}
\cs_new_protected_nopar:Npn \spath_gshorten_at_both_ends:Nn #1#2
{
  \spath_gshorten_at_start:Nn #1{#2}
  \spath_gshorten_at_end:Nn #1{#2}
}
\cs_generate_variant:Nn \spath_gshorten_at_both_ends:Nn {cn, cV, NV}
\cs_new_protected_nopar:Npn \__spath_point_at:nn #1#2
{
  \group_begin:
  \int_set:Nn \l__spath_tmpa_int {\fp_to_int:n {floor(#2) + 1}}
  \fp_set:Nn \l__spath_tmpa_fp {#2 - floor(#2)}

  \spath_segments_to_seq:Nn \l__spath_tmpa_seq {#1}

  \int_compare:nTF
  {
    \l__spath_tmpa_int < 1
  }
  {
    \spath_initialpoint:Nn \l__spath_tmpc_tl {#1}
  }
  {
    \int_compare:nTF
    {
      \l__spath_tmpa_int > \seq_count:N \l__spath_tmpa_seq
    }
    {
      \spath_finalpoint:Nn \l__spath_tmpc_tl {#1}
    }
    {

      \tl_set:Nx
      \l__spath_tmpa_tl
      {\seq_item:Nn \l__spath_tmpa_seq { \l__spath_tmpa_int} }

      \int_compare:nTF
      {
        \tl_count:N \l__spath_tmpa_tl > 3
      }
      {
        \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {4}}
      }
      {
        \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {1}}
      }

      \tl_clear:N \l__spath_tmpc_tl

      \token_case_meaning:Nn \l__spath_tmpb_tl
      {
        \c_spath_moveto_tl
        {
          \tl_set:Nx \l__spath_tmpc_tl
          {
            {
              \tl_item:Nn \l__spath_tmpa_tl {2}
            }
            {
              \tl_item:Nn \l__spath_tmpa_tl {3}
            }
          }
        }

        \c_spath_lineto_tl
        {
          \tl_set:Nx \l__spath_tmpc_tl
          {
            {\fp_to_dim:n
              {
                (1 - \l__spath_tmpa_fp) * ( \tl_item:Nn \l__spath_tmpa_tl {2} )
                +
                \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {5} )
              }
            }
            {\fp_to_dim:n
              {
                (1 - \l__spath_tmpa_fp) * ( \tl_item:Nn \l__spath_tmpa_tl {3} )
                +
                \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {6} )
              }
            }
          }
        }

        \c_spath_rectsize_tl
        {
          \fp_compare:nTF
          {
            \l__spath_tmpa_fp <= .25
          }
          {
            \tl_set:Nx \l__spath_tmpc_tl
            {
              {\fp_to_dim:n
                {
                  ( \tl_item:Nn \l__spath_tmpa_tl {2} )
                  +
                  4 * \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {5} )
                }
              }
              {\fp_to_dim:n {\tl_item:Nn \l__spath_tmpa_tl {3} } }
            }
          }
          {
            \fp_compare:nTF
            {
              \l__spath_tmpa_fp <= .5
            }
            {
              \tl_set:Nx \l__spath_tmpc_tl
              {
                {\fp_to_dim:n
                  {
                    ( \tl_item:Nn \l__spath_tmpa_tl {2} )
                    +
                    ( \tl_item:Nn \l__spath_tmpa_tl {5} )
                  }
                }
                {\fp_to_dim:n
                  {
                    ( \tl_item:Nn \l__spath_tmpa_tl {3} )
                    +
                    (4 * (\l__spath_tmpa_fp) - 1) * ( \tl_item:Nn \l__spath_tmpa_tl {6} )
                  }
                }
              }
            }
            {
              \fp_compare:nTF
              {
                \l__spath_tmpa_fp <= .75
              }
              {
                \tl_set:Nx \l__spath_tmpc_tl
                {
                  {\fp_to_dim:n
                    {
                      ( \tl_item:Nn \l__spath_tmpa_tl {2} )
                      +
                      (3 - 4 * (\l__spath_tmpa_fp)) *( \tl_item:Nn \l__spath_tmpa_tl {5} )
                    }
                  }
                  {\fp_to_dim:n
                    {
                      ( \tl_item:Nn \l__spath_tmpa_tl {3} )
                      +
                      ( \tl_item:Nn \l__spath_tmpa_tl {6} )
                    }
                  }
                }

              }
              {
                \tl_set:Nx \l__spath_tmpc_tl
                {
                  {\fp_to_dim:n
                    {
                      ( \tl_item:Nn \l__spath_tmpa_tl {2} )
                    }
                  }
                  {\fp_to_dim:n
                    {
                      ( \tl_item:Nn \l__spath_tmpa_tl {3} )
                      +
                      (4 - 4 *(\l__spath_tmpa_fp)) * ( \tl_item:Nn \l__spath_tmpa_tl {6} )
                    }
                  }
                }
              }
            }
          }
        }

        \c_spath_closepath_tl
        {
          \tl_set:Nx \l__spath_tmpc_tl
          {
            {\fp_to_dim:n
              {
                (1 - \l__spath_tmpa_fp) * ( \tl_item:Nn \l__spath_tmpa_tl {2} )
                +
                \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {5} )
              }
            }
            {\fp_to_dim:n
              {
                (1 - \l__spath_tmpa_fp) * ( \tl_item:Nn \l__spath_tmpa_tl {3} )
                +
                \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {6} )
              }
            }
          }
        }

        \c_spath_curvetoa_tl
        {
          \tl_set:Nx \l__spath_tmpc_tl
          {
            {\fp_to_dim:n
              {
                (1 - \l__spath_tmpa_fp)^3 * \tl_item:Nn \l__spath_tmpa_tl {2}
                + 3 * (1 - \l__spath_tmpa_fp)^2 * (\l__spath_tmpa_fp)
                * \tl_item:Nn \l__spath_tmpa_tl {5}
                + 3 * (1 - \l__spath_tmpa_fp) * (\l__spath_tmpa_fp)^2
                * \tl_item:Nn \l__spath_tmpa_tl {8}
                + (\l__spath_tmpa_fp)^3 * \tl_item:Nn \l__spath_tmpa_tl {11}
            }}
            {\fp_to_dim:n
              {
                (1 - \l__spath_tmpa_fp)^3 * \tl_item:Nn \l__spath_tmpa_tl {3}
                + 3 * (1 - \l__spath_tmpa_fp)^2 * (\l__spath_tmpa_fp)
                * \tl_item:Nn \l__spath_tmpa_tl {6}
                + 3 * (1 - \l__spath_tmpa_fp) * (\l__spath_tmpa_fp)^2
                * \tl_item:Nn \l__spath_tmpa_tl {9}
                + (\l__spath_tmpa_fp)^3 * \tl_item:Nn \l__spath_tmpa_tl {12}
            }}
          }
        }
      }
    }
  }

  \tl_gclear:N \g__spath_output_tl
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpc_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_point_at:Nnn #1#2#3
{
  \__spath_point_at:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_point_at:Nnn {NVn, NVV, NnV}
\cs_new_protected_nopar:Npn \spath_gpoint_at:Nnn #1#2#3
{
  \__spath_point_at:nn {#2}{#3}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gpoint_at:Nnn {NVn, NVV, NnV}
\cs_new_protected_nopar:Npn \__spath_tangent_at:nn #1#2
{
  \group_begin:
  \int_set:Nn \l__spath_tmpa_int {\fp_to_int:n {floor(#2) + 1}}
  \fp_set:Nn \l__spath_tmpa_fp {#2 - floor(#2)}

  \spath_segments_to_seq:Nn \l__spath_tmpa_seq {#1}

  \int_compare:nTF
  {
    \l__spath_tmpa_int < 1
  }
  {
    \spath_initialpoint:Nn \l__spath_tmpc_tl {#1}
  }
  {
    \int_compare:nTF
    {
      \l__spath_tmpa_int > \seq_count:N \l__spath_tmpa_seq
    }
    {
      \spath_finalpoint:Nn \l__spath_tmpc_tl {#1}
    }
    {

      \tl_set:Nx
      \l__spath_tmpa_tl
      {\seq_item:Nn \l__spath_tmpa_seq { \l__spath_tmpa_int} }

      \int_compare:nTF
      {
        \tl_count:N \l__spath_tmpa_tl > 3
      }
      {
        \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {4}}
      }
      {
        \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {1}}
      }

      \tl_clear:N \l__spath_tmpc_tl

      \token_case_meaning:Nn \l__spath_tmpb_tl
      {
        \c_spath_moveto_tl
        {
          \tl_set:Nx \l__spath_tmpc_tl
          {
            {
              \tl_item:Nn \l__spath_tmpa_tl {2}
            }
            {
              \tl_item:Nn \l__spath_tmpa_tl {3}
            }
          }
        }

        \c_spath_lineto_tl
        {
          \tl_set:Nx \l__spath_tmpc_tl
          {
            {\fp_to_dim:n
              {
                ( \tl_item:Nn \l__spath_tmpa_tl {5} )
                -
                ( \tl_item:Nn \l__spath_tmpa_tl {2} )
              }
            }
            {\fp_to_dim:n
              {
                ( \tl_item:Nn \l__spath_tmpa_tl {6} )
                -
                ( \tl_item:Nn \l__spath_tmpa_tl {3} )
              }
            }
          }
        }

        \c_spath_rectsize_tl
        {
          \fp_compare:nTF
          {
            \l__spath_tmpa_fp <= .25
          }
          {
            \tl_set:Nx \l__spath_tmpc_tl
            {
              {\fp_to_dim:n
                {
                  \tl_item:Nn \l__spath_tmpa_tl {5}
                }
              }
              {0pt}
            }
          }
          {
            \fp_compare:nTF
            {
              \l__spath_tmpa_fp <= .5
            }
            {
              \tl_set:Nx \l__spath_tmpc_tl
              {
                {0pt}
                {\fp_to_dim:n
                  {
                    ( \tl_item:Nn \l__spath_tmpa_tl {6} )
                  }
                }
              }
            }
            {
              \fp_compare:nTF
              {
                \l__spath_tmpa_fp <= .75
              }
              {
                \tl_set:Nx \l__spath_tmpc_tl
                {
                  {\fp_to_dim:n
                    {
                      -( \tl_item:Nn \l__spath_tmpa_tl {5} )
                    }
                  }
                  {0pt}
                }

              }
              {
                \tl_set:Nx \l__spath_tmpc_tl
                {
                  {0pt}
                  {\fp_to_dim:n
                    {
                      - ( \tl_item:Nn \l__spath_tmpa_tl {6} )
                    }
                  }
                }
              }
            }
          }
        }

        \c_spath_closepath_tl
        {
          \tl_set:Nx \l__spath_tmpc_tl
          {
            {\fp_to_dim:n
              {
                ( \tl_item:Nn \l__spath_tmpa_tl {5} )
                -
                ( \tl_item:Nn \l__spath_tmpa_tl {2} )
              }
            }
            {\fp_to_dim:n
              {
                ( \tl_item:Nn \l__spath_tmpa_tl {6} )
                -
                ( \tl_item:Nn \l__spath_tmpa_tl {3} )
              }
            }
          }
        }

        \c_spath_curvetoa_tl
        {
          \tl_set:Nx \l__spath_tmpc_tl
          {
            {\fp_to_dim:n
              {
                3*(1 - \l__spath_tmpa_fp)^2 * (\tl_item:Nn \l__spath_tmpa_tl {5}
                - \tl_item:Nn \l__spath_tmpa_tl {2})
                + 6 * (1 - \l__spath_tmpa_fp) * (\l__spath_tmpa_fp) *
                (\tl_item:Nn \l__spath_tmpa_tl {8}
                - \tl_item:Nn \l__spath_tmpa_tl {5})
                + 3*(\l__spath_tmpa_fp)^2 * (\tl_item:Nn \l__spath_tmpa_tl {11}
                - \tl_item:Nn \l__spath_tmpa_tl {8})
              }
            }
            {\fp_to_dim:n
              {
                3*(1 - \l__spath_tmpa_fp)^2 * (\tl_item:Nn \l__spath_tmpa_tl {6}
                - \tl_item:Nn \l__spath_tmpa_tl {3})
                + 6 * (1 - \l__spath_tmpa_fp) * (\l__spath_tmpa_fp) *
                (\tl_item:Nn \l__spath_tmpa_tl {9}
                - \tl_item:Nn \l__spath_tmpa_tl {6})
                + 3*(\l__spath_tmpa_fp)^2 * (\tl_item:Nn \l__spath_tmpa_tl {12}
                - \tl_item:Nn \l__spath_tmpa_tl {9})
            }}
          }
        }
      }
    }
  }

  \tl_gclear:N \g__spath_output_tl
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpc_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_tangent_at:Nnn #1#2#3
{
  \__spath_tangent_at:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_tangent_at:Nnn {NVn, NVV, NnV}
\cs_new_protected_nopar:Npn \spath_gtangent_at:Nnn #1#2#3
{
  \__spath_tangent_at:nn {#2}{#3}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gtangent_at:Nnn {NVn, NVV, NnV}
\cs_new_protected_nopar:Npn \__spath_transformation_at:nn #1#2
{
  \group_begin:
  \tl_clear:N \l__spath_tmpa_tl
  \__spath_tangent_at:nn {#1}{#2}
  \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_output_tl
  \fp_set:Nn \l__spath_tmpa_fp
  {
    sqrt(
    (\tl_item:Nn \l__spath_tmpb_tl {1})^2
    +
    (\tl_item:Nn \l__spath_tmpb_tl {2})^2
    )
  }
  \fp_compare:nTF {\l__spath_tmpa_fp = 0}
  {
    \fp_set:Nn \l__spath_tmpa_fp {1}
    \fp_set:Nn \l__spath_tmpb_fp {0}
  }
  {
    \fp_set:Nn \l__spath_tmpb_fp
    { (\tl_item:Nn \l__spath_tmpb_tl {2}) / \l__spath_tmpa_fp }
    \fp_set:Nn \l__spath_tmpa_fp
    { (\tl_item:Nn \l__spath_tmpb_tl {1}) / \l__spath_tmpa_fp }
  }
  \tl_set:Nx \l__spath_tmpa_tl
  {
    { \fp_to_decimal:n { \l__spath_tmpa_fp } }
    { \fp_to_decimal:n { \l__spath_tmpb_fp } }
    { \fp_to_decimal:n {- \l__spath_tmpb_fp } }
    { \fp_to_decimal:n { \l__spath_tmpa_fp } }
  }
  \__spath_point_at:nn {#1}{#2}
  \tl_put_right:NV \l__spath_tmpa_tl \g__spath_output_tl
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_transformation_at:Nnn #1#2#3
{
  \__spath_transformation_at:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_transformation_at:Nnn {NVn, NVV, NnV, NvV}
\cs_new_protected_nopar:Npn \spath_gtransformation_at:Nnn #1#2#3
{
  \__spath_transformation_at:nn {#2}{#3}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gtransformation_at:Nnn {NVn, NVV, NnV}
\cs_new_protected_nopar:Npn \spath_intersect:NN #1#2
{
  \pgfintersectionofpaths%
  {%
    \pgfsetpath #1
  }{%
    \pgfsetpath #2
  }
}
\cs_new_protected_nopar:Npn \spath_intersect:nn #1#2
{
  \tl_set:Nn \l__spath_intersecta_tl {#1}
  \tl_set:Nn \l__spath_intersectb_tl {#2}
  \spath_intersect:NN \l__spath_intersecta_tl \l__spath_intersectb_tl
}
\cs_new_protected_nopar:Npn \__spath_split_component_at_intersections:nn #1#2
{
  \group_begin:
  \tl_clear:N \l__spath_tmpe_tl
  \seq_clear:N \l__spath_tmpb_seq

  % Find the intersections of these segments
  \tl_set:Nn \l__spath_tmpb_tl {#1}
  \tl_set:Nn \l__spath_tmpc_tl {#2}

  % Remember if the component is closed
  \spath_finalaction:NV \l__spath_tmpa_tl \l__spath_tmpb_tl

  \bool_set:Nn \l__spath_closed_bool
  {
    \tl_if_eq_p:NN \l__spath_tmpa_tl \c_spath_closepath_tl
    ||
    \tl_if_eq_p:NN \l__spath_tmpa_tl \c_spath_rectcorner_tl
  }

  % Open it
  \spath_open:N \l__spath_tmpb_tl

  \spath_reallength:NV \l__spath_tmpa_int \l__spath_tmpb_tl

  % Sort intersections along the component
  \pgfintersectionsortbyfirstpath
  \spath_intersect:NN \l__spath_tmpb_tl \l__spath_tmpc_tl

  % If we get intersections
  \int_compare:nT {\pgfintersectionsolutions > 0}
  {
    % Find the times of the intersections on the component
    \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
    {
      \pgfintersectiongetsolutiontimes{##1}{\l__spath_tmph_tl}{\l__spath_tmpi_tl}
      \seq_put_left:NV \l__spath_tmpb_seq \l__spath_tmph_tl
    }

    \seq_get_left:NN \l__spath_tmpb_seq \l__spath_tmpa_tl
    \fp_compare:nT
    {
      \l__spath_tmpa_tl > \l__spath_tmpa_int - .01
    }
    {
      \bool_set_false:N \l__spath_closed_bool
    }

    \seq_get_right:NN \l__spath_tmpb_seq \l__spath_tmpa_tl
    \fp_compare:nT
    {
      \l__spath_tmpa_tl < .01
    }
    {
      \bool_set_false:N \l__spath_closed_bool
    }

    \tl_set:Nn \l__spath_tmpg_tl {-1}

    \seq_map_inline:Nn \l__spath_tmpb_seq
    {
      \tl_set:Nn \l__spath_tmph_tl {##1}

      \tl_set_eq:NN \l__spath_tmpa_tl \l__spath_tmph_tl
      \int_compare:nT
      {
        \fp_to_int:n {floor( \l__spath_tmph_tl) }
        =
        \fp_to_int:n {floor( \l__spath_tmpg_tl) }
      }
      {
        \tl_set:Nx \l__spath_tmph_tl
        {
          \fp_eval:n {
            floor( \l__spath_tmph_tl )
            +
            ( \l__spath_tmph_tl - floor( \l__spath_tmph_tl) )
            /
            ( \l__spath_tmpg_tl - floor( \l__spath_tmpg_tl) )
          }
        }
      }
      \tl_set_eq:NN \l__spath_tmpg_tl \l__spath_tmpa_tl

      \spath_split_at:NNVV
      \l__spath_tmpd_tl
      \l__spath_tmpf_tl
      \l__spath_tmpb_tl
      \l__spath_tmph_tl

      \tl_put_left:NV \l__spath_tmpe_tl \l__spath_tmpf_tl
      \tl_set_eq:NN \l__spath_tmpb_tl \l__spath_tmpd_tl

    }

    \tl_put_left:NV \l__spath_tmpe_tl \l__spath_tmpb_tl

    \spath_remove_empty_components:N \l__spath_tmpe_tl

    \tl_set_eq:NN \l__spath_tmpb_tl \l__spath_tmpe_tl
  }

  \bool_if:NT \l__spath_closed_bool
  {
    \spath_join_component:Nn \l__spath_tmpb_tl {1}
  }

  \tl_gclear:N \g__spath_output_tl
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl

  \group_end:
}
\cs_new_protected_nopar:Npn \spath_split_component_at_intersections:Nnn #1#2#3
{
  \__spath_split_component_at_intersections:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_component_at_intersections:Nnn {NVn, NVV}
\cs_new_protected_nopar:Npn \spath_split_component_at_intersections:Nn #1#2
{
  \spath_split_component_at_intersections:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_split_component_at_intersections:Nn {cn, cv}
\cs_new_protected_nopar:Npn \spath_gsplit_component_at_intersections:Nnn #1#2#3
{
  \__spath_split_component_at_intersections:nn {#2}{#3}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_component_at_intersections:Nnn {NVn, NVV}
\cs_new_protected_nopar:Npn \spath_gsplit_component_at_intersections:Nn #1#2
{
  \spath_gsplit_component_at_intersections:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gsplit_component_at_intersections:Nn {cn, cv}
\cs_new_protected_nopar:Npn \__spath_split_path_at_intersections:nn #1#2
{
  \group_begin:

  \seq_clear:N \l__spath_tmpa_seq
  \seq_clear:N \l__spath_tmpb_seq

  \spath_components_to_seq:Nn \l__spath_tmpa_seq {#1}
  \seq_map_inline:Nn \l__spath_tmpa_seq
  {
    \spath_split_component_at_intersections:Nnn \l__spath_tmpa_tl {##1} {#2}
    \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpa_tl
  }

  \tl_gclear:N \g__spath_output_tl
  \tl_gset:Nx \g__spath_output_tl {\seq_use:Nn \l__spath_tmpb_seq {} }
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_split_path_at_intersections:Nnn #1#2#3
{
  \__spath_split_path_at_intersections:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_path_at_intersections:Nnn
{NVn, NVV, cVn, cVV, cvn, cvv}
\cs_new_protected_nopar:Npn \spath_split_path_at_intersections:Nn #1#2
{
  \spath_split_path_at_intersections:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_split_path_at_intersections:Nn {cv, NV}
\cs_new_protected_nopar:Npn \spath_gsplit_path_at_intersections:Nnn #1#2#3
{
  \__spath_split_path_at_intersections:nn {#2}{#3}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_path_at_intersections:Nnn
{NVn, NVV, cVn, cVV, cvn, cvv}
\cs_new_protected_nopar:Npn \spath_gsplit_path_at_intersections:Nn #1#2
{
  \spath_gsplit_path_at_intersections:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gsplit_path_at_intersections:Nn {cv, NV}
\cs_new_protected_nopar:Npn \spath_split_at_intersections:NNnn #1#2#3#4
{
  \__spath_split_path_at_intersections:nn {#3}{#4}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \__spath_split_path_at_intersections:nn {#4}{#3}
  \tl_set_eq:NN #2 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_at_intersections:NNnn
{NNVn, NNVV, ccVn, ccVV, ccvn, ccvv}
\cs_new_protected_nopar:Npn \spath_split_at_intersections:NN #1#2
{
  \spath_split_at_intersections:NNVV #1#2#1#2
}
\cs_generate_variant:Nn \spath_split_at_intersections:NN {cc}
\cs_new_protected_nopar:Npn \spath_gsplit_at_intersections:NNnn #1#2#3#4
{
  \__spath_split_path_at_intersections:nn {#3}{#4}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \__spath_split_path_at_intersections:nn {#4}{#3}
  \tl_gset_eq:NN #2 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_at_intersections:NNnn
{NNVn, NNVV, ccVn, ccVV, ccvn, ccvv}
\cs_new_protected_nopar:Npn \spath_gsplit_at_intersections:NN #1#2
{
  \spath_gsplit_at_intersections:NNVV #1#2#1#2
}
\cs_generate_variant:Nn \spath_gsplit_at_intersections:NN {cc}
\cs_new_protected_nopar:Npn \__spath_split_component_at_self_intersections:n #1
{
  \group_begin:
  \tl_set:Nn \l__spath_tmpe_tl {#1}

  % Remember if the component is closed
  \spath_finalaction:NV \l__spath_tmpa_tl \l__spath_tmpe_tl

  \bool_set:Nn \l__spath_closed_bool
  {
    \tl_if_eq_p:NN \l__spath_tmpa_tl \c_spath_closepath_tl
  }

  % Copy the path
  \tl_set:Nn \l__spath_tmpe_tl {#1}

  % Open the path
  \spath_open:N \l__spath_tmpe_tl
  % Ensure beziers don't self-intersect
  \spath_split_curves:N \l__spath_tmpe_tl

  % Make a copy for later
  \tl_set_eq:NN \l__spath_tmpg_tl \l__spath_tmpe_tl

  % Clear some token lists and sequences
  \tl_clear:N \l__spath_tmpd_tl
  \seq_clear:N \l__spath_tmpb_seq
  \int_zero:N \l__spath_tmpa_int

  \pgfintersectionsortbyfirstpath

  % Split the path into a sequence of segments
  \spath_segments_to_seq:NV \l__spath_tmpa_seq \l__spath_tmpe_tl

  \seq_map_indexed_inline:Nn \l__spath_tmpa_seq
  {
    \seq_map_indexed_inline:Nn \l__spath_tmpa_seq
    {
      % Don't intersect a segment with itself
      \int_compare:nF
      {
        ##1 == ####1
      }
      {
        \spath_intersect:nn {##2} {####2}

        \int_compare:nT {\pgfintersectionsolutions > 0}
        {
          % Find the times of the intersections on each path
          \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
          {
            \pgfintersectiongetsolutiontimes
            {########1}{\l__spath_tmpb_tl}{\l__spath_tmpc_tl}

            \bool_if:nT
            {
              !(
              \fp_compare_p:n { \l__spath_tmpb_tl > .99 }
              &&
              \int_compare_p:n {##1 + 1 == ####1}
              )
              &&
              !(
              \fp_compare_p:n { \l__spath_tmpb_tl < .01 }
              &&
              \int_compare_p:n {##1 - 1 == ####1}
              )
              &&
              !(
              \l__spath_closed_bool
              &&
              \fp_compare_p:n { \l__spath_tmpb_tl < .01 }
              &&
              \int_compare_p:n {##1 == 1}
              &&
              \int_compare_p:n {\seq_count:N \l__spath_tmpa_seq == ####1}
              )
              &&
              !(
              \l__spath_closed_bool
              &&
              \fp_compare_p:n { \l__spath_tmpb_tl > .99 }
              &&
              \int_compare_p:n {####1 == 1}
              &&
              \int_compare_p:n {\seq_count:N \l__spath_tmpa_seq == ##1}
              )
            }
            {
              \tl_set:Nx \l__spath_tmpa_tl
              {\fp_to_decimal:n {\l__spath_tmpb_tl +  ##1 - 1}}
              \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpa_tl
            }
          }
        }
      }
    }
  }

  % Sort the sequence by reverse order along the path
  \seq_sort:Nn \l__spath_tmpb_seq
  {
    \fp_compare:nNnTF { ##1 } < { ##2 }
    { \sort_return_swapped: }
    { \sort_return_same: }
  }

  \seq_get_left:NN \l__spath_tmpb_seq \l__spath_tmpa_tl
  \fp_compare:nT
  {
    \l__spath_tmpa_tl > \seq_count:N \l__spath_tmpa_seq - .01
  }
  {
    \bool_set_false:N \l__spath_closed_bool
  }
  \seq_get_right:NN \l__spath_tmpb_seq \l__spath_tmpa_tl
  \fp_compare:nT
  {
    \l__spath_tmpa_tl < .01
  }
  {
    \bool_set_false:N \l__spath_closed_bool
  }

  % Restore the original copy of the path
  \tl_set_eq:NN \l__spath_tmpe_tl \l__spath_tmpg_tl

  % Clear the token lists
  \tl_clear:N \l__spath_tmpf_tl
  \tl_clear:N \l__spath_tmph_tl
  \tl_clear:N \l__spath_tmpg_tl

  \tl_set:Nn \l__spath_tmpi_tl {-1}

  \seq_map_inline:Nn \l__spath_tmpb_seq
  {
    \tl_set:Nn \l__spath_tmpb_tl {##1}
    \tl_set_eq:NN \l__spath_tmpa_tl \l__spath_tmpb_tl
    \int_compare:nT
    {
      \fp_to_int:n {floor( \l__spath_tmpb_tl ) }
      =
      \fp_to_int:n {floor( \l__spath_tmpi_tl) }
    }
    {
      \tl_set:Nx \l__spath_tmpb_tl
      {
        \fp_eval:n {
          floor( \l__spath_tmpb_tl )
          +
          ( \l__spath_tmpb_tl - floor( \l__spath_tmpb_tl) )
          /
          ( \l__spath_tmpi_tl - floor( \l__spath_tmpi_tl) )
        }
      }
    }
    \tl_set_eq:NN \l__spath_tmpi_tl \l__spath_tmpa_tl

    \spath_split_at:NNVV
    \l__spath_tmpf_tl
    \l__spath_tmph_tl
    \l__spath_tmpe_tl
    \l__spath_tmpb_tl

    \tl_put_left:NV \l__spath_tmpg_tl \l__spath_tmph_tl
    \tl_set_eq:NN \l__spath_tmpe_tl \l__spath_tmpf_tl

  }

  \tl_put_left:NV \l__spath_tmpg_tl \l__spath_tmpe_tl

  \tl_if_empty:NT \l__spath_tmpg_tl
  {
    \tl_set_eq:NN \l__spath_tmpg_tl \l__spath_tmpe_tl
  }

  \spath_remove_empty_components:N \l__spath_tmpg_tl

  % Do something with closed
  \bool_if:NT \l__spath_closed_bool
  {
    \spath_join_component:Nn \l__spath_tmpg_tl {1}
  }

  \tl_gclear:N \g__spath_output_tl
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpg_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_split_component_at_self_intersections:Nn #1#2
{
  \__spath_split_component_at_self_intersections:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_component_at_self_intersections:Nn {NV}
\cs_new_protected_nopar:Npn \spath_split_component_at_self_intersections:N #1
{
  \spath_split_component_at_self_intersections:NV #1#1
}
\cs_generate_variant:Nn \spath_split_component_at_self_intersections:N {c}
\cs_new_protected_nopar:Npn \spath_gsplit_component_at_self_intersections:Nn #1#2
{
  \__spath_split_component_at_self_intersections:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_component_at_self_intersections:Nn {NV}
\cs_new_protected_nopar:Npn \spath_gsplit_component_at_self_intersections:N #1
{
  \spath_gsplit_component_at_self_intersections:NV #1#1
}
\cs_generate_variant:Nn \spath_gsplit_component_at_self_intersections:N {c}
\cs_new_protected_nopar:Npn \__spath_split_at_self_intersections:n #1
{
  \group_begin:
  \spath_components_to_seq:Nn \l__spath_tmpa_seq {#1}
  \seq_clear:N \l__spath_tmpb_seq
  \seq_clear:N \l__spath_tmpc_seq

  % Iterate over the components of the original path.
  \bool_do_until:nn
  {
    \seq_if_empty_p:N \l__spath_tmpa_seq
  }
  {
    % Get the next component
    \seq_pop_left:NN \l__spath_tmpa_seq \l__spath_tmpa_tl
    % Copy for later
    \tl_set_eq:NN \l__spath_tmpc_tl \l__spath_tmpa_tl
    \int_compare:nT
    {
      \tl_count:N \l__spath_tmpa_tl > 3
    }
    {

      % Split against itself
      \spath_split_component_at_self_intersections:N \l__spath_tmpa_tl
      % Grab the rest of the path
      \tl_set:Nx \l__spath_tmpb_tl
      {
        \seq_use:Nn \l__spath_tmpb_seq {}
        \seq_use:Nn \l__spath_tmpa_seq {}
      }
      % Split against the rest of the path
      \spath_split_path_at_intersections:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
    }
    % Save the split path
    \seq_put_right:NV \l__spath_tmpc_seq \l__spath_tmpa_tl
    % Add the original copy to the sequence of processed components
    \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpc_tl
  }

  \tl_gclear:N \g__spath_output_tl
  \tl_gset:Nx \g__spath_output_tl {\seq_use:Nn \l__spath_tmpc_seq {} }
  \group_end:
}
\cs_generate_variant:Nn \__spath_split_at_self_intersections:n {V, v}
\cs_new_protected_nopar:Npn \spath_split_at_self_intersections:Nn #1#2
{
  \__spath_split_at_self_intersections:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_split_at_self_intersections:Nn {NV, cn, cV, cv}
\cs_new_protected_nopar:Npn \spath_split_at_self_intersections:N #1
{
  \spath_split_at_self_intersections:NV #1#1
}
\cs_generate_variant:Nn \spath_split_at_self_intersections:N {c}
\cs_new_protected_nopar:Npn \spath_gsplit_at_self_intersections:Nn #1#2
{
  \__spath_split_at_self_intersections:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gsplit_at_self_intersections:Nn {NV, cn, cV, cv}
\cs_new_protected_nopar:Npn \spath_gsplit_at_self_intersections:N #1
{
  \spath_gsplit_at_self_intersections:NV #1#1
}
\cs_generate_variant:Nn \spath_gsplit_at_self_intersections:N {c}
\cs_new_protected_nopar:Npn \__spath_join_component:nn #1#2
{
  \group_begin:
  \spath_numberofcomponents:Nn \l__spath_tmpa_int {#1}

  \bool_if:nTF
  {
    \int_compare_p:n { #2 >= 1 }
    &&
    \int_compare_p:n { #2 <= \l__spath_tmpa_int }
  }
  {
    \int_compare:nTF
    {
      #2 == 1
    }
    {
      \int_compare:nTF
      {
        \l__spath_tmpa_int == 1
      }
      {
        \tl_set:Nn \l__spath_tmpa_tl {#1}
        \spath_initialpoint:Nn \l__spath_tmpb_tl {#1}
        \tl_put_right:NV \l__spath_tmpa_tl \c_spath_closepath_tl
        \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
        \tl_gclear:N \g__spath_output_tl
        \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
      }
      {
        \spath_components_to_seq:Nn \l__spath_tmpa_seq {#1}
        \seq_pop_left:NN \l__spath_tmpa_seq \l__spath_tmpa_tl

        \prg_replicate:nn {3}
        {
          \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
        }

        \seq_put_right:NV \l__spath_tmpa_seq \l__spath_tmpa_tl

        \tl_gclear:N \g__spath_output_tl
        \tl_gset:Nx \g__spath_output_tl {\seq_use:Nn \l__spath_tmpa_seq {}}
      }
    }
    {
      \spath_components_to_seq:Nn \l__spath_tmpa_seq {#1}

      \seq_clear:N \l__spath_tmpb_seq
      \seq_map_indexed_inline:Nn \l__spath_tmpa_seq
      {
        \tl_set:Nn \l__spath_tmpa_tl {##2}
        \int_compare:nT {##1 = #2}
        {
          \prg_replicate:nn {3}
          {
            \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
          }
        }
        \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpa_tl
      }

      \tl_gclear:N \g__spath_output_tl
      \tl_gset:Nx \g__spath_output_tl {\seq_use:Nn \l__spath_tmpb_seq {}}
    }
  }
  {
    \tl_gclear:N \g__spath_output_tl
    \tl_gset:Nn \g__spath_output_tl {#1}
  }

  \group_end:
}
\cs_new_protected_nopar:Npn \spath_join_component:Nnn #1#2#3
{
  \__spath_join_component:nn {#2}{#3}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_join_component:Nnn {NVn, NVV}
\cs_new_protected_nopar:Npn \spath_join_component:Nn #1#2
{
  \spath_join_component:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_join_component:Nn {cn, NV, cV}
\cs_new_protected_nopar:Npn \spath_gjoin_component:Nnn #1#2#3
{
  \__spath_join_component:nn {#2}{#3}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_gjoin_component:Nnn {NVn, NVV}
\cs_new_protected_nopar:Npn \spath_gjoin_component:Nn #1#2
{
  \spath_gjoin_component:NVn #1#1{#2}
}
\cs_generate_variant:Nn \spath_gjoin_component:Nn {cn, NV, cV}
\cs_new_protected_nopar:Npn \__spath_spot_weld_components:n #1
{
  \group_begin:
  \dim_zero:N \l__spath_move_x_dim
  \dim_zero:N \l__spath_move_y_dim

  \spath_components_to_seq:Nn \l__spath_tmpa_seq {#1}
  \seq_clear:N \l__spath_tmpb_seq
  \dim_set:Nn \l__spath_move_x_dim {\tl_item:nn {#1} {2} + 10 pt}
  \dim_set:Nn \l__spath_move_y_dim {\tl_item:nn {#1} {3} + 10 pt}

  \int_set:Nn \l__spath_tmpa_int {\seq_count:N \l__spath_tmpa_seq}

  \seq_map_inline:Nn \l__spath_tmpa_seq
  {
    \tl_set:Nn \l__spath_tmpa_tl {##1}
    \bool_if:nT
    {
      \dim_compare_p:n
      {
        \dim_abs:n
        {\l__spath_move_x_dim - \tl_item:Nn \l__spath_tmpa_tl {2} }
        < 0.01pt
      }
      &&
      \dim_compare_p:n
      {
        \dim_abs:n
        {\l__spath_move_y_dim - \tl_item:Nn \l__spath_tmpa_tl {3} }
        < 0.01pt
      }
    }
    {
      \prg_replicate:nn {3}
      {
        \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
      }
      \int_decr:N \l__spath_tmpa_int
    }
    \tl_reverse:N \l__spath_tmpa_tl
    \dim_set:Nn \l__spath_move_x_dim {\tl_item:Nn \l__spath_tmpa_tl {2}}
    \dim_set:Nn \l__spath_move_y_dim {\tl_item:Nn \l__spath_tmpa_tl {1}}
    \tl_reverse:N \l__spath_tmpa_tl
    \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpa_tl
  }

  \tl_set:Nx \l__spath_tmpa_tl {\seq_use:Nn \l__spath_tmpb_seq {} }
  \spath_components_to_seq:NV \l__spath_tmpb_seq \l__spath_tmpa_tl

  \spath_initialpoint:Nn \l__spath_tmpa_tl {#1}
  \spath_finalpoint:Nn \l__spath_tmpb_tl {#1}

  \bool_if:nT
  {
    \dim_compare_p:n
    {
      \dim_abs:n
      {
        \tl_item:Nn \l__spath_tmpa_tl {1} - \tl_item:Nn \l__spath_tmpb_tl {1}
      }
      <
      0.01pt
    }
    &&
    \dim_compare_p:n
    {
      \dim_abs:n
      {
        \tl_item:Nn \l__spath_tmpa_tl {2} - \tl_item:Nn \l__spath_tmpb_tl {2}
      }
      <
      0.01pt
    }
  }
  {
    \int_compare:nTF
    {
      \seq_count:N \l__spath_tmpb_seq > 1
    }
    {
      \seq_pop_left:NN \l__spath_tmpb_seq \l__spath_tmpb_tl

      \prg_replicate:nn {3}
      {
        \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
      }
      \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpb_tl
    }
    {
      \tl_set:NV \l__spath_tmpb_tl \c_spath_closepath_tl
      \tl_put_right:Nx \l__spath_tmpb_tl
      {
        { \tl_item:Nn \l__spath_tmpa_tl {1} }
        { \tl_item:Nn \l__spath_tmpa_tl {2} }
      }
      \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpb_tl
    }
  }

  \tl_gset:Nx \g__spath_output_tl {\seq_use:Nn \l__spath_tmpb_seq {}}
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_spot_weld_components:Nn #1#2
{
  \__spath_spot_weld_components:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_spot_weld_components:Nn {NV, cV, cn}
\cs_new_protected_nopar:Npn \spath_spot_weld_components:N #1
{
  \spath_spot_weld_components:NV #1#1
}
\cs_generate_variant:Nn \spath_spot_weld_components:N {c}
\cs_new_protected_nopar:Npn \spath_spot_gweld_components:Nn #1#2
{
  \__spath_spot_weld_components:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_generate_variant:Nn \spath_spot_gweld_components:Nn {NV, cV, cn}
\cs_new_protected_nopar:Npn \spath_spot_gweld_components:N #1
{
  \spath_spot_gweld_components:NV #1#1
}
\cs_generate_variant:Nn \spath_spot_gweld_components:N {c}
\cs_new_protected_nopar:Npn \__spath_convert_to_svg:n #1
{
  \group_begin:
  \tl_clear:N \l__spath_tmpa_tl
  \tl_put_right:Nn \l__spath_tmpa_tl
  {
    <?xml~ version="1.0"~ standalone="no"?>
    \iow_newline:
    <!DOCTYPE~ svg~ PUBLIC~ "-//W3C//DTD SVG 1.1//EN"~
    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    \iow_newline:
    <svg~ xmlns="http://www.w3.org/2000/svg"~ version="1.1"~viewBox="
  }

  \spath_minbb:Nn \l__spath_tmpb_tl {#1}
  \spath_maxbb:Nn \l__spath_tmpc_tl {#1}
  \tl_put_right:Nx \l__spath_tmpa_tl
  {
    \dim_to_decimal:n
    {
      \tl_item:Nn \l__spath_tmpb_tl {1} - 10pt
    }
    \exp_not:n {~}
    \dim_to_decimal:n
    {
      \tl_item:Nn \l__spath_tmpb_tl {2} - 10pt
    }
    \exp_not:n {~}
    \dim_to_decimal:n
    {
      \tl_item:Nn \l__spath_tmpc_tl {1}
      -
      \tl_item:Nn \l__spath_tmpb_tl {1}
      + 20pt
    }
    \exp_not:n {~}
    \dim_to_decimal:n
    {
      \tl_item:Nn \l__spath_tmpc_tl {2}
      -
      \tl_item:Nn \l__spath_tmpb_tl {2}
      + 20pt
    }
  }

  \tl_put_right:Nn \l__spath_tmpa_tl
  {
    ">
    \iow_newline:
    <path~ d="
  }
  \tl_set:Nn \l__spath_tmpc_tl {use:n}
  \tl_map_inline:nn {#1}
  {
    \tl_set:Nn \l__spath_tmpb_tl {##1}
    \token_case_meaning:NnF \l__spath_tmpb_tl
    {
      \c_spath_moveto_tl
      {
        \tl_put_right:Nn \l__spath_tmpa_tl {M~}
        \tl_set:Nn \l__spath_tmpc_tl {use:n}
      }
      \c_spath_lineto_tl
      {
        \tl_put_right:Nn \l__spath_tmpa_tl {L~}
        \tl_set:Nn \l__spath_tmpc_tl {use:n}
      }
      \c_spath_closepath_tl
      {
        \tl_put_right:Nn \l__spath_tmpa_tl {Z~}
        \tl_set:Nn \l__spath_tmpc_tl {use_none:n}
      }
      \c_spath_curvetoa_tl
      {
        \tl_put_right:Nn \l__spath_tmpa_tl {C~}
        \tl_set:Nn \l__spath_tmpc_tl {use:n}
      }
      \c_spath_curvetob_tl {
        \tl_set:Nn \l__spath_tmpc_tl {use:n}
      }
      \c_spath_curveto_tl {
        \tl_set:Nn \l__spath_tmpc_tl {use:n}
      }
    }
    {
      \tl_put_right:Nx
      \l__spath_tmpa_tl
      {\use:c { \l__spath_tmpc_tl } {\dim_to_decimal:n {##1}} ~}
    }
  }
  \tl_put_right:Nn \l__spath_tmpa_tl
  {
    "~ fill="none"~ stroke="black"~ />
    \iow_newline:
    </svg>
    \iow_newline:
  }
  \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
  \group_end:
}
\cs_new_protected_nopar:Npn \spath_convert_to_svg:Nn #1#2
{
  \__spath_convert_to_svg:n {#2}
  \tl_set_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\cs_new_protected_nopar:Npn \spath_gconvert_to_svg:Nn #1#2
{
  \__spath_convert_to_svg:n {#2}
  \tl_gset_eq:NN #1 \g__spath_output_tl
  \tl_gclear:N \g__spath_output_tl
}
\iow_new:N \g__spath_stream
\cs_new_protected_nopar:Npn \spath_export_to_svg:nn #1#2
{
  \group_begin:
  \spath_convert_to_svg:Nn \l__spath_tmpa_tl {#2}
  \iow_open:Nn \g__spath_stream {#1 .svg}
  \iow_now:Nx \g__spath_stream
  {
    \tl_use:N \l__spath_tmpa_tl
  }
  \iow_close:N \g__spath_stream
  \group_end:
}
\cs_generate_variant:Nn \spath_export_to_svg:nn {nv, nV}
\cs_new_protected_nopar:Npn \spath_show:n #1
{
  \int_step_inline:nnnn {1} {3} {\tl_count:n {#1}}
  {
    \iow_term:x {
      \tl_item:nn {#1} {##1}
      {\tl_item:nn {#1} {##1+1}}
      {\tl_item:nn {#1} {##1+2}}
    }
  }
}
\cs_generate_variant:Nn \spath_show:n {V, v}
\cs_new_protected_nopar:Npn \spath_get_current_path:N #1
{
  \pgfsyssoftpath@getcurrentpath #1
}
\cs_generate_variant:Nn \spath_get_current_path:N {c}
\cs_new_protected_nopar:Npn \spath_gget_current_path:N #1
{
  \pgfsyssoftpath@getcurrentpath #1
  \tl_gset_eq:NN #1 #1
}
\cs_generate_variant:Nn \spath_gget_current_path:N {c}
\cs_new_protected_nopar:Npn \spath_protocol_path:n #1
{
  \spath_minbb:Nn \l__spath_tmpa_tl {#1}
  \dim_set:Nn \l__spath_tmpa_dim {\tl_item:Nn \l__spath_tmpa_tl {1}}
  \dim_set:Nn \l__spath_tmpb_dim {\tl_item:Nn \l__spath_tmpa_tl {2}}
  \pgf@protocolsizes\l__spath_tmpa_dim\l__spath_tmpb_dim

  \spath_maxbb:Nn \l__spath_tmpa_tl {#1}
  \dim_set:Nn \l__spath_tmpa_dim {\tl_item:Nn \l__spath_tmpa_tl {1}}
  \dim_set:Nn \l__spath_tmpb_dim {\tl_item:Nn \l__spath_tmpa_tl {2}}
  \pgf@protocolsizes\l__spath_tmpa_dim\l__spath_tmpb_dim
}
\cs_generate_variant:Nn \spath_protocol_path:n {V}
\cs_new_protected_nopar:Npn \spath_set_current_path:n #1
{
  \spath_protocol_path:n {#1}
  \tl_set:Nn \l__spath_tmpa_tl {#1}
  \pgfsyssoftpath@setcurrentpath\l__spath_tmpa_tl
}
\cs_new_protected_nopar:Npn \spath_set_current_path:N #1
{
  \spath_protocol_path:V #1
  \pgfsyssoftpath@setcurrentpath #1
}
\cs_generate_variant:Nn \spath_set_current_path:N {c}
\cs_new_protected_nopar:Npn \spath_use_path:nn #1#2
{
  \spath_set_current_path:n {#1}
  \pgfusepath{#2}
}
\cs_new_protected_nopar:Npn \spath_tikz_path:nn #1#2
{
  \tl_if_empty:nF {#2}
  {
    \path[#1] \pgfextra{
      \spath_set_current_path:n {#2}
      \tl_put_left:Nn \tikz@preactions {\def\tikz@actions@path{#2}}
    };
  }
}
\cs_generate_variant:Nn \spath_tikz_path:nn {Vn, VV, nv, Vv, nV}
\cs_new_protected_nopar:Npn \spath_set_tikz_data:n #1
{
  \spath_finalpoint:Nn \l__spath_tmpa_tl {#1}
  \tl_set:Nx \l__spath_tmpa_tl
  {
    \exp_not:c {pgf@x}=\tl_item:Nn \l__spath_tmpa_tl {1} \relax
    \exp_not:c {pgf@y}=\tl_item:Nn \l__spath_tmpa_tl {2} \relax
  }
  \use:c {pgf@process}{%
    \tl_use:N \l__spath_tmpa_tl
    \pgftransforminvert
    \use:c {pgf@pos@transform@glob}
  }
  \tl_set:Nx \l__spath_tmpa_tl
  {
    \exp_not:c {tikz@lastx}=\exp_not:c {pgf@x} \relax
    \exp_not:c {tikz@lasty}=\exp_not:c {pgf@y} \relax
    \exp_not:c {tikz@lastxsaved}=\exp_not:c {pgf@x} \relax
    \exp_not:c {tikz@lastysaved}=\exp_not:c {pgf@y} \relax
  }
  \tl_use:N \l__spath_tmpa_tl
  \spath_finalmovepoint:Nn \l__spath_tmpa_tl {#1}
  \bool_if:NT \l_spath_movetorelevant_bool
  {
    \ifpgfsyssoftpathmovetorelevant%
    \tl_gset_eq:cN {pgfsyssoftpath@lastmoveto} \l__spath_tmpa_tl
    \fi
  }
  \tl_set:Nx \l__spath_tmpa_tl
  {
    \exp_not:c {pgf@x}=\tl_item:Nn \l__spath_tmpa_tl {1} \relax
    \exp_not:c {pgf@y}=\tl_item:Nn \l__spath_tmpa_tl {2} \relax
  }
  \use:c {pgf@process}{%
    \tl_use:N \l__spath_tmpa_tl
    \pgftransforminvert
    \use:c {pgf@pos@transform@glob}
  }
  \bool_if:NT \l_spath_movetorelevant_bool
  {
    \dim_if_exist:cT {tikz@lastmovetox}
    {
      \tl_set:Nx \l__spath_tmpa_tl
      {
        \exp_not:c {tikz@lastmovetox}=\exp_not:c {pgf@x} \relax
        \exp_not:c {tikz@lastmovetoy}=\exp_not:c {pgf@y} \relax
      }
      \tl_use:N \l__spath_tmpa_tl
    }
  }
  \tl_clear_new:c {tikz@timer}
  \tl_set:cn {tikz@timer}
  {
    \pgftransformreset
    \spath_reallength:Nn \l__spath_tmpa_int {#1}
    \tl_set_eq:Nc \l__spath_tmpb_tl {tikz@time}
    \tl_set:Nx \l__spath_tmpb_tl
    {\fp_to_decimal:n {(\l__spath_tmpb_tl) * (\l__spath_tmpa_int)}}
    \spath_transformation_at:NnV \l__spath_tmpc_tl {#1} \l__spath_tmpb_tl

    \tl_set:Nx \l__spath_tmpa_tl
    {
      \exp_not:N \pgfpoint
      { \tl_item:Nn \l__spath_tmpc_tl {5} }
      { \tl_item:Nn \l__spath_tmpc_tl {6} }
    }
    \exp_args:NV \pgftransformshift \l__spath_tmpa_tl

    \ifpgfresetnontranslationattime
    \pgftransformresetnontranslations
    \fi

    \ifpgfslopedattime

    \tl_set:Nx \l__spath_tmpa_tl
    {
      { \tl_item:Nn \l__spath_tmpc_tl {1} }
      { \tl_item:Nn \l__spath_tmpc_tl {2} }
      { \tl_item:Nn \l__spath_tmpc_tl {3} }
      { \tl_item:Nn \l__spath_tmpc_tl {4} }
    }
    \ifpgfallowupsidedownattime
    \else
    \fp_compare:nT { \tl_item:Nn \l__spath_tmpc_tl {4} < 0}
    {
      \tl_set:Nx \l__spath_tmpa_tl
      {
        { \fp_eval:n { - (\tl_item:Nn \l__spath_tmpc_tl {1})} }
        { \fp_eval:n { - (\tl_item:Nn \l__spath_tmpc_tl {2})} }
        { \fp_eval:n { - (\tl_item:Nn \l__spath_tmpc_tl {3})} }
        { \fp_eval:n { - (\tl_item:Nn \l__spath_tmpc_tl {4})} }
      }
    }
    \fi
    \tl_put_right:Nn \l__spath_tmpa_tl {{\pgfpointorigin}}
    \exp_last_unbraced:NV \pgftransformcm \l__spath_tmpa_tl
    \fi
  }
}
\cs_generate_variant:Nn \spath_set_tikz_data:n {V, v}
%% 
%% Copyright (C) 2011-2024 by Andrew Stacey <loopspace@mathforge.org>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License (LPPL), either
%% version 1.3c of this license or (at your option) any later
%% version.  The latest version of this license is in the file:
%% 
%% http://www.latex-project.org/lppl.txt
%% 
%% This work is "maintained" (as per LPPL maintenance status) by
%% Andrew Stacey.
%% 
%% This work consists of the files  spath3_code.dtx
%%                                  calligraphy_doc.tex
%%                                  knots_doc.tex
%%                                  spath3.tex
%% and the derived files            spath3.ins,
%%                                  spath3_code.pdf,
%%                                  spath3.sty,
%%                                  tikzlibrarycalligraphy.code.tex
%%                                  tikzlibraryknots.code.tex
%%                                  tikzlibraryspath3.code.tex
%%                                  calligraphy.pdf
%%                                  knots.pdf
%%                                  spath3.pdf
%%                                  README.txt
%% 
%%
%% End of file `spath3.sty'.
