
    ^ju              
         d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
mZmZmZ ddl	mZ ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ ddlAmBZB ddlCmDZDmEZE ddlFmGZGmHZH ddlImJZJmKZK ddlLmMZMmNZNmOZOmPZP ddlQmRZR ddlSmTZT erddlUmVZV  ed      ZW e> e9 e?ddd       e;ddd                  ZX eeX      ZYd5dZZd6d Z[	 	 	 	 	 	 d7d!Z\d8d"Z]	 	 	 	 	 	 	 	 	 	 d9d#Z^e
	 	 	 	 	 	 d:d$       Z_e
	 	 	 	 	 	 d;d%       Z_d<d&Z_	 	 	 	 	 	 	 	 d=d'Z`	 	 	 	 	 	 d>d(Zad?d)Zbd@d*Zc	 	 	 	 	 	 	 	 dAd+ZdeJj                  d,	 	 	 	 	 	 	 	 	 dBd-ZfeJj                  d,	 	 	 	 	 	 	 	 	 dCd.ZgeJj                  d,	 	 	 	 	 	 	 dDd/Zh	 	 	 	 	 	 	 	 dEd0Zi	 	 	 	 	 	 	 	 	 	 dFd1Zj	 	 	 	 	 	 	 	 dGd2Zk	 	 	 	 	 	 	 	 	 	 dHd3Zly4)Ia  
build123d topology

name: constrained_lines.py
by:   Gumyr
date: September 07, 2025

desc:

This module generates lines and arcs that are constrained against other objects.

license:

    Copyright 2025 Gumyr

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    )annotations)atan2cosisnansinpi)overloadTYPE_CHECKINGCallableTypeVar)cast)	BRep_Tool)BRepAdaptor_Curve)BRepBuilderAPI_MakeEdgeBRepBuilderAPI_MakeVertex)BRepLib)GCPnts_AbscissaPoint)
Geom_Curve
Geom_Plane)Geom2d_CartesianPointGeom2d_CircleGeom2d_CurveGeom2d_LineGeom2d_PointGeom2d_TrimmedCurve)Geom2dAdaptor_Curve)Geom2dAPI_ProjectPointOnCurveGeom2dAPI_InterCurveCurve)Geom2dGcc_Circ2d2TanOnGeom2dGcc_Circ2d2TanRadGeom2dGcc_Circ2d3TanGeom2dGcc_Circ2dTanCenGeom2dGcc_Circ2dTanOnRadGeom2dGcc_Lin2dTanOblGeom2dGcc_Lin2d2TanGeom2dGcc_QualifiedCurve)GeomAbs_CurveType)GeomAPI)	gp_Ax2dgp_Ax3	gp_Circ2dgp_Dirgp_Dir2dgp_Lin2dgp_Plngp_Pntgp_Pnt2d)IntAna2d_AnaIntersection)Standard_ConstructionErrorStandard_Failure)TopoDS_EdgeTopoDS_Vertex)SagittaTangency)Axis	TOLERANCEVector
VectorLike   )Vertex)	ShapeList)EdgeTWrap              ?c                    | |z
  |z  |z   S )z(Map parameter u into [first, first+per). )ufirstperiods      ]/opt/ringagent/.cad-venv/lib/python3.12/site-packages/build123d/topology/constrained_lines.py_norm_on_periodrJ   a   s    I%''    c                X    t        | ||      }t        |||      }||z
  }|dk  r||z  }|S )z^
    Forward (positive) delta from u1 to u2 on a periodic domain anchored at
    'first'.
    rB   )rJ   )u1u2rG   rH   u1nu2ndeltas          rI   _forward_deltarR   f   s>    
 "eV
,C
"eV
,C#IEs{LrK   c                   t        j                  | t               t                     }t        j                  |       \  }}t	        j
                  |t              }t        |||      }t        ||j                        }|||||fS )z8Convert a TopoDS_Edge into 2d curve & extract properties)
r   Curve_sfloatRange_sr(   To2d_s_pln_xyr   r&   value)edgeposition_constainthcurve3drG   lasthcurve2dadapt2dqcurves           rI   _edge_to_qualified_2dra   v   sx       uw8H##D)KE4 ~~h0H "(E48G &g/A/G/GHF8UD'11rK   c                    t        | ||d      }t        |t              j                         }t	        j
                  |       |S )z@Build a 3D edge on XY from a trimmed 2D circle segment [u1, u2].T)r   r   _surf_xyr@   r   BuildCurves3d_s)
h2d_circlerM   rN   arc2dcircle_edges        rI   _edge_from_circlerh      s;    
BD9E)%:??AKK(rK   c                    | |||t        d      |j                         rt        | ||j                               n| } | |t        z
  k\  xr | |t        z   k  S )z?Normalize (if periodic) then test [first, last] with tolerance.z$Invalid parameters to _param_in_trim)	TypeError
IsPeriodicrJ   Periodr:   )rF   rG   r]   h2ds       rI   _param_in_trimrn      s_     	yEMT\S[>??36>>3C5#**,/A""?dY.>)>?rK   c                     y NrE   obj	constaints     rI   _as_gcc_argrt      s    
 rK   c                     y rp   rE   rq   s     rI   rt   rt      s     <?rK   c                    | st        d      t        | j                  t              rt	        | j                  |      dd dz   S t        | j                  | j                        }t        |      ddddfS )z
    Normalize input to a GCC argument.
    Returns: (q_obj, h2d, first, last, is_edge)
    - Edge -> (QualifiedCurve, h2d, first, last, True)
    - Vector -> (CartesianPoint, None, None, None, False)
    z.Can't create a qualified curve from empty edger      )TNF)	rj   
isinstancewrappedr5   ra   r1   XYr   )rr   rs   gp_pnts      rI   rt   rt      sh     HII#++{+$S[[)<QqAGKKceeSUU#F ($dEAArK   c                &   t        |       }|j                         }t        ||d|      }t        |d|      }t        |d|      }|t        k  st        ||z
        t        k  r
t               S t        ||||z         }t        |||||z
  z         }	||	gS )z
    Given two parameters on a circle, return both the forward (minor)
    and complementary (major) arcs as TopoDS_Edge(s).
    Uses centralized normalization utilities.
    rB   )r   rl   rR   rJ   r:   absr?   rh   )
circrM   rN   re   rH   drO   rP   minormajors
             rI   _two_arc_edges_from_paramsr      s     t$J F 	r2sF+A
"c6
*C
"c6
*C 	I~VaZI5{j#sQw7Ej#sfqj/ABE5>rK   c                p   t        t        | j                         | j                         d            j	                         }t        t        |j                         |j                         d            j	                         }t        ||      }|j                         st        d      |j                         S )ad  
    Build a finite Edge from two 2D contact points.

    Parameters
    ----------
    p1, p2 : gp_Pnt2d
        Endpoints of the line segment (in 2D).
    edge_factory : type[Edge], optional
        Factory for building the Edge subtype (defaults to Edge).

    Returns
    -------
    TopoDS_Edge
        Finite line segment between the two points.
    r   z'Failed to build edge from line contacts)	r   r0   rz   r{   r>   r   IsDoneRuntimeErrorr@   )p1p2v1v2mk_edges        rI   _edge_from_liner      s    & 
#6"$$&"$$&!#<	=	D	D	FB	"6"$$&"$$&!#<	=	D	D	FB%b"-G>>DEE<<>rK   c                    t        | j                  j                  | j                  j                        }t	        | j
                  j                  | j
                  j                        }t        t        ||            S )z2Build a 2D reference line from an Axis (XY plane).)r1   positionrz   r{   r-   	directionr.   r)   )axpr   s      rI   _gp_lin2d_from_axisr      sK    .A0AGAqM""rK   c                    	 ddl m}m}m} 	 ddl m} |d|d|d|di}|j                  | d	t        |        d
      S # t
        $ r	 ddl m} Y :w xY w# t        $ r t        t        |             cY S w xY w)z;Debugging facility that works with OCP's GccEnt enum valuesr   )GccEnt_enclosedGccEnt_enclosingGccEnt_outside)GccEnt_unqualified)GccEnt_noqualifierenclosed	enclosingoutsideunqualifiedzunknown())
OCP.GccEntr   r   r   r   ImportErrorr   getint	Exceptionstr)qr   r   r   r   mappings         rI   _qstrr      s    PP	L5
 ZkI	
 {{1Q233  	LK	L  3q6{s1   
A < (A AA AA A10A1c                   | D cg c]9  }t        |d   j                  t              rt        |d   j                        nd; }}|D cg c])  }|duxr! |j	                         t
        j                  k(  + }}t        |      rt        |      S |j                         }t        |j                         |j                         d      }t        |      }	t        t        |||             D ]Y  \  }
\  }}}t        |d   t              r|s!||d   j                  z
  j                   |d   j"                  k  sN|t$        z   |	|
<   [ |	S c c}w c c}w )aa  
    Adjusts solution-circle parameters by adding pi if the solution circle is
    enclosed within a tangent circular edge.

    Only applies when at least one tangent input is non-circular: GccAna_Circ2d3Tan
    (invoked for all-circle inputs) already computes the correct tangent direction
    for the enclosed case, so no offset is needed there.
    r   N)rx   ry   r5   r   GetTyper'   GeomAbs_CirclealllistLocationr;   rz   r{   	enumeratezip
arc_centerlengthradiusr   )tangent_tuplesr   paramstadaptsais_circ
center_pnt
center_vrtparsipar	circ_flags                rI   _enclosed_circ_param_offsetr     sG   &    !A$,,4 adll+F   	
I!))+):)I)IIIG 
 7|F|J

:J<D"+C,P"Q CAadF#*qt6>>1LBhDG	 K5s   >E	.E)sagittac                   |D cg c]&  }t        |t              r|n|t        j                  f( }}|D cg c]
  }t	        |  }}t        t        t        |       \  }t        g || t         }|j                         r|j                         dk(  rt        d      dfd}	g }
t        d|j                         dz         D ]  }|j                  |      }t               }|j                  ||      \  }} |	d|      s=t               }|j!                  ||      \  }} |	d|      sf|t"        j$                  k(  r|
j'                  t)        |||             t)        |||      }t+        |d       }|
j-                  ||j.                             t1        |
D cg c]
  } ||       c}      S c c}w c c}w c c}w )a  
    Create all planar circular arcs of a given radius that are tangent/contacting
    the two provided objects on the XY plane.

    Inputs must be coplanar with ``Plane.XY``. Non-coplanar edges are not supported.

    Args:
        tangencies (tuple[Edge, PositionConstraint] | Edge | Vertex | VectorLike:
            Geometric entity to be contacted/touched by the circle(s)
        radius (float): Circle radius for all candidate solutions.

    Raises:
        ValueError: Invalid input
        ValueError: Invalid curve
        RuntimeError: no valid circle solutions found

    Returns:
        ShapeList[Edge]: A list of planar circular edges (on XY) representing both
            the minor and major arcs between the two tangency points for every valid
            circle solution.

    r   zUnable to find a tangent arcc                @    |    sdS t        ||    |    |          S z9Does the given parameter value lie within the edge range?Trn   r   rF   e_firste_lasth_eis_edges     rI   _okz _make_2tan_rad_arcs.<locals>._okg  5      
D	
(6q'!*fQiQTUVQW(X	
rK   r=   c                >    t        j                  t        |             S rp   r   Length_sr   es    rI   <lambda>z%_make_2tan_rad_arcs.<locals>.<lambda>      $8$A$ABSTUBV$W rK   keyr   r   rF   rU   returnbool)rx   tupler8   UNQUALIFIEDrt   mapr   r    r:   r   NbSolutionsr   rangeThisSolutionr1   	Tangency1	Tangency2r7   BOTHextendr   sortedappendrY   r?   )r   r   edge_factory
tangenciesr   r   resultsq_ogccr   	solutionsr   r   r   u_circ1u_arg1r   u_circ2u_arg2arcsr   r   r   r   r   s                        @@@@rI   _make_2tan_rad_arcsr   <  s   > KUEFZ5!8+?+?'@@N 
 )771{A7G7),UCM)B&Cgvw
!
:3
:
:	
:C::<3??,19::
 
 $&I1coo'!+, !2**1- Z--2.1f~ Z--2.1f~ gll"7gwOP-dGWEDWD T'--01C!2D y9!l1o9::s
 8h :s   +G G*G
c                0   t        |      | gz   D cg c]&  }t        |t              r|n|t        j                  f( }}|D cg c]
  }t        |  }}t        t        t        |       \  }t        d   d   d         }t        t        |            D 	cg c]  }	|	   r|	   |	   z
  dz  |	   z    }
}	t              dkD  rt        |d   |d   |t        g|
 }nBt        |d   t              sJ t        |d   t              sJ t        |d   |d   |t              }|j                         r|j!                         dk(  rt#        d      dfd}g }t        d|j!                         dz         D ]  }	|j%                  |	      }t'               }|j)                  |	|      \  }} |d|      s=t'               }|j+                  |	|      \  }} |d|      sft-        ||||g      \  }}|t.        j0                  k(  r|j3                  t5        |||             t5        |||      }t7        |d       }|j9                  ||j:                             t=        |D cg c]
  } ||       c}      S c c}w c c}w c c}	w c c}w )	a  
    Create all planar circular arcs whose circle is tangent to two objects and whose
    CENTER lies on a given locus (line/circle/curve) on the XY plane.

    Notes
    -----
    - `center_on` is treated as a **center locus** (not a tangency target).
       r=   r   z6Unable to find a tangent arc with center_on constraintc                @    |    sdS t        ||    |    |          S r   r   r   s     rI   r   z_make_2tan_on_arcs.<locals>._ok  r   rK   c                >    t        j                  t        |             S rp   r   r   s    rI   r   z$_make_2tan_on_arcs.<locals>.<lambda>  r   rK   r   r   )r   rx   r   r8   r   rt   r   r   r   r   lensumr   r:   r   r   r   r   r   r1   r   r   r   r7   r   r   r   r   r   rY   r?   )	center_onr   r   r   r   r   r   r   adapt_onr   guessesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s                          @@@@rI   _make_2tan_on_arcsr     s   $ j!YK/ 5!8+?+?'@@N  )771{A7G7 *-UCM)B&Cgvw"3q671:vayAH
 s>*+1: 
WQZ	1$wqz1G  7|a$SVSVXyS7S#a&,///#a&,///$SVSVXyI::<3??,1STT
 
 $&I1coo'!+, 2**1- Z--2.1f~ Z--2.1f~6D7G"4

 gll"7gwOP-dGWEDWD T'--0172: y9!l1o9::K 8n :s   +JJ	  J.Jc                   |D cg c]&  }t        |t              r|n|t        j                  f( }}|D cg c]
  }t	        |  }}t        t        t        |       \  }t        t        d      D cg c]  }|   |   z
  dz  |   z    c}      }d}		 t        g |t        | }
|
j                         r|
j                         dk(  rt        |	      d
fd}g }t        d|
j                         dz         D ]  }|
j                  |      }t!               }|
j#                  ||      \  }} |d|      s>t!               }|
j%                  ||      \  }} |d|      sgt!               }|
j'                  ||      \  }} |d|      st)        |||||g      \  }}}| t*        j,                  k(  r|j/                  t1        |||             t1        |||      }t3        |d 	      }|j5                  || j6                             t9        |D cg c]
  } ||       c}      S c c}w c c}w c c}w # t        t        f$ r}t        |	      |d}~ww xY wc c}w )aw  
    Create planar circular arc(s) on XY tangent to three provided objects.

    The circle is determined by the three tangency constraints; the returned arc(s)
    are trimmed between the two tangency points corresponding to `tangencies[0]` and
    `tangencies[1]`. Use `sagitta` to select the shorter/longer (or both) arc.
    Inputs must be representable on Plane.XY.
       r   z4Unable to find a circle tangent to all three objectsNr   c                @    |    sdS t        ||    |    |          S r   r   r   s     rI   r   z_make_3tan_arcs.<locals>._ok  r   rK   r=   c                >    t        j                  t        |             S rp   r   r   s    rI   r   z!_make_3tan_arcs.<locals>.<lambda>G  s    2;;<Ma<PQ rK   r   r   )rx   r   r8   r   rt   r   r   r   r!   r:   r3   r4   r   r   r   r   r1   r   r   	Tangency3r   r7   r   r   r   r   r   rY   r?   )r   r   r   r   r   r   r   r   r   msgr   con_errr   	out_toposr   r   r   r   r   r   r   p3_u_circ3u_arg3r   r   r   r   r   r   s                             @@@@rI   _make_3tan_arcsr    s     KUEFZ5!8+?+?'@@N 
 )771{A7G7 *-UCM)B&Cgvw +0<A!HEq&)gaj
 A	%
	2E+G
 AC-"=C==W= ::<3??,13
 
 $&I1coo'!+, )2**1- Z--2.1f~ Z--2.1f~ Z==B/&1f~%@gx(&
"( gll"7gwOP-dGWEDQD T'--01S)2V y9!l1o9::]
 8 	F '(89 -3W,-t :s.   +H6H;9I I  I(I%I  I%c          	        t        | t              r| \  }}n| t        j                  }}t        |t              rj|j
                  |j
                  nt        dd      }t        |      }t        |j                  |j                  z   |j                  |j                  z         }n+t        |      }t        |j                  |j                        }t        ||      \  }	}
}}}g }|st        |	t              r|	j                         }|j                         |j                         z
  |j                         |j                         z
  }}||z  ||z  z   dz  }|t        k  rt        g       S t        t!        |t#        dd            |      }t%        |      }|j'                         }|j)                  t+        |d|             nt        |	t,              sJ t/        |	t        |      t              }|j1                         r|j3                         dkD  sJ d       t5        d|j3                         dz         D ]z  }|j7                  |      }t               }|j9                  ||      \  }}|rt;        ||||
      sDt%        |      }|j'                         }|j)                  t+        |d|             | t        |D cg c]
  } ||       c}      S c c}w )u  
    Create planar circle(s) on XY whose center is fixed and that are tangent/contacting
    a single object.

    Notes
    -----
    - With a **fixed center** and a single tangency constraint, the natural geometric
      result is a full circle; there are no second endpoints to define an arc span.
      This routine therefore returns closed circular edges (full 2π trims).
    - If the tangency target is a point (Vertex/VectorLike), the circle is the one
      centered at `center` and passing through that point (built directly).
    r   g      ?rC   rB   z1Unexpected: GCC failed to return a tangent circler=   )rx   r   r8   r   r>   r   r;   r1   rz   r{   rt   r   Pnt2dr:   r?   r+   r)   r-   r   rl   r   rh   r&   r"   r   r   r   r   r   rn   )tangencycenterr   
object_one	obj1_qualloc_xyzbasec2dvq_o1h_e1e1_firste1_lastis_edge1solutions_topor   dxdyrr   rm   perr   r   r   
_u_on_circu_on_argr   s                               rI   _make_tan_cen_arcsr  N  sm   ( (E" (
I ((*>*>I

 &&!%+__%@&//fQPQlf~tvv		)466GII+=>6NqssACC 
 /:*i.P+D$'8(*N 
4)>?JJL!##%#%%'/B"WrBw3&	>R= hsC&891=D!jjl/S#>? $ 8999$T+@+EyQJJLS__.2	?>	?2 q#//+a/0 	DA##A&D B#&==B#7 Jx7D Q  %C**,C!!"3Cc"BC	D ~>!l1o>??>s   9Kc                  t        | t              r| \  }}n| t        j                  }}t	        ||      \  }t        |t              r|d   n|}t        |j
                  t              st        d      t        |j
                  t        j                        \  }}	}
}}t        |||t              }|j                         r|j                         dk(  rt        d      dfd}g }t        d|j                         dz         D ]  }|j                  |      }t!               }|j#                  ||      \  }} ||      s<|j%                         }t'        ||	      }t)        t*        |j-                  d            }t/        ||
||	      st1        |      }|j3                         }|j5                  t7        |d|              t9        |D cg c]
  } ||       c}      S c c}w )uE  
    Create planar circle(s) on XY that:
      - are tangent/contacting a single object, and
      - have a fixed radius, and
      - have their CENTER constrained to lie on a given locus curve.

    Notes
    -----
    - The center locus must be a 2D curve (line/circle/any Geom2d curve) — i.e. an Edge
      after projection to XY.
    - With only one tangency, the natural geometric result is a full circle; arc cropping
      would require an additional endpoint constraint. This routine therefore returns
      closed circular edges (2π trims) for each valid solution.
    r   z;center_on must be an Edge (line/circle/curve) for TanOnRad.z1Unable to find circle(s) for TanOnRad constraintsc                (    sdS t        |       S )NTr   )rF   r  r  r  r  s    rI   _ok1z#_make_tan_on_rad_arcs.<locals>._ok1  s    #tS8Wd)SSrK   r=   rB   )rF   rU   r   r   )rx   r   r8   r   rt   ry   r5   rj   ra   r#   r:   r   r   r   r   r   r1   r   r   r   tcastrU   	Parameterrn   r   rl   r   rh   r?   )r  r   r   r   r	  r
  r  on_obj_h_on2don_firston_lastr   r   r  r   r   r   r   r  r  center2dproju_onrm   r  r   r  r  r  r  s                              @@@@rI   _make_tan_on_rad_arcsr)    s   . (E" (
I ((*>*>I
 /:*i.P+D$'8 (	59Yq\yFfnnk2UVV .C,,.*Avx( #469
EC::<3??,1NOOT T $&I1coo'!+, ;**1- J"}}Q2
HH~ ==? -Xv>UDNN1-. dHgv>D!jjl*3S9:-;0 y9!l1o9::9s   G+c                  t        | t              r| \  }}n| t        j                  }}t	        ||      \  }}}}}t        |t
              r2t        |j                  |j                        }t        ||t              }	nKt        |t              r|\  }
}n|t        j                  }}
t	        |
|      \  }}}}}t        ||t              }	|	j                         r|	j                         dk(  rt        d      g }t        d|	j                         dz         D ]  }t        |	j!                  |            }t#        ||      }|j%                  d      }t        |t
              r!t        |j                  |j                        }nt#        |      }|j%                  d      }|j'                  |      }t)        |      s	|t        k  r|j+                  t-        ||              t/        |D cg c]
  } ||       c}      S c c}w )z
    Construct line(s) tangent to two curves.

    Parameters
    ----------
    curve1, curve2 : Edge
        Target curves.

    Returns
    -------
    ShapeList[Edge]
        Finite tangent line(s).
    r   z%Unable to find common tangent line(s)r=   )rx   r   r8   r   rt   r;   r1   rz   r{   r%   r:   r   r   r   r   r   r   r   PointDistancer   r   r   r?   )	tangency1	tangency2r   r	  r
  q1c1r"  pnt_2dr   
object_two	obj2_qualq2c2	out_edgesr   lin2dinter_ccpt1pt2
separationr   s                         rI   _make_2tan_linesr<    s   & )U# )
I )8+?+?I
!*i8OBAq!)V$)++y{{3!"fi8i'$-!J	$-x/C/C	J%j)<B1a!"b)4::<3??,1BCC#%I1coo'!+, 4C,,Q/0 -UB7nnQi(9;;	4C0;H..#C \\#&

Y 6c23'4( y9!l1o9::9s   )G?c                  t        | t              r| \  }}n| t        j                  }}t	        t	        |j
                  j                        dz
        t        k  rt        d      t        ||      \  }}}}}|j
                  }t        |j                  |j                        }	|	|z   }
t        t        |
      t        |
            }t!        |      }t#        ||t        |      }g }t%        d|j'                         dz         D ]  }t)               }|j+                  ||       t-        ||      }t/        ||      }|j1                         r|j3                         dk(  r[|j5                  d      j7                         }|j9                  |      }t;        |      s	|t        k  r|j=                  t?        ||              tA        |D cg c]
  } ||       c}      S c c}w )z
    Construct line(s) tangent to a curve and forming a given angle with a
    reference line (Axis) per Geom2dGcc_Lin2dTanObl. Trimmed between:
    - the tangency point on the curve, and
    - the intersection with the reference line.
    r=   z1reference Axis can't be perpendicular to Plane.XYr   )!rx   r   r8   r   r~   r   Zr:   
ValueErrorrt   r   r{   rz   r-   r   r   r   r$   r   r   r1   r   r.   r2   r   NbPointsr+  Valuer,  r   r   r   r?   )r  	referenceangler   r	  r
  q_curver"  ref_dir	theta_ref	theta_absdir2dref_linr   outr   p_tantan_lineinterp_isectr;  r   s                         rI   _make_tan_oriented_linesrO  2  s    (E" (
I ((*>*>I

3y""$$%)*Y6LMM%j)<GQ1a !!Ggii+I E!IS^S^4E "),G  )U
CCC1coo'!+, 4
aE5) )7;||~!1Q!6++a.&&( ^^G,

Y 6

?5'23'4* s3!l1o3443s   	GN)rF   rU   rG   rU   rH   rU   r   rU   )
rM   rU   rN   rU   rG   rU   rH   rU   r   rU   )rZ   r5   r[   r8   r   zPtuple[Geom2dGcc_QualifiedCurve, Geom2d_Curve, float, float, Geom2dAdaptor_Curve])re   r   rM   rU   rN   rU   r   r5   )
rF   float | NonerG   rP  r]   rP  rm   zGeom2d_Curve | Noner   r   )rr   r@   rs   r8   r   zVtuple[Geom2dGcc_QualifiedCurve, Geom2d_Curve | None, float | None, float | None, bool])rr   r;   rs   r8   r   z4tuple[Geom2d_CartesianPoint, None, None, None, bool])rr   zEdge | Vectorrs   r8   r   zntuple[Geom2dGcc_QualifiedCurve | Geom2d_CartesianPoint, Geom2d_Curve | None, float | None, float | None, bool])r   r+   rM   rU   rN   rU   r   zlist[TopoDS_Edge])r   r1   r   r1   r   r5   )r   r9   r   r.   )r   r   )r   z$list[tuple[Edge | Vector, Tangency]]r   r+   r   list[float]r   rQ  )
r   %tuple[Edge, Tangency] | Edge | Vectorr   rU   r   r7   r   Callable[[TopoDS_Edge], Edge]r   ShapeList[Edge])
r   rR  r   r@   r   r7   r   rS  r   rT  )r   rR  r   r7   r   rS  r   rT  )r  rR  r  zVectorLike | Vertexr   rS  r   rT  )
r  rR  r   r@   r   rU   r   rS  r   rT  )r-  tuple[Edge, Tangency] | Edger.  rR  r   rS  r   rT  )
r  rU  rB  r9   rC  rU   r   rS  r   rT  )m__doc__
__future__r   mathr   r   r   r   r   typingr	   r
   r   r   r   r  OCP.BRepr   OCP.BRepAdaptorr   OCP.BRepBuilderAPIr   r   OCP.BRepLibr   
OCP.GCPntsr   OCP.Geomr   r   
OCP.Geom2dr   r   r   r   r   r   OCP.Geom2dAdaptorr   OCP.Geom2dAPIr   r   OCP.Geom2dGccr   r    r!   r"   r#   r$   r%   r&   OCP.GeomAbsr'   OCP.GeomAPIr(   OCP.gpr)   r*   r+   r,   r-   r.   r/   r0   r1   OCP.IntAna2dr2   OCP.Standardr3   r4   
OCP.TopoDSr5   r6   build123d.build_enumsr7   r8   build123d.geometryr9   r:   r;   r<   zero_dr>   
shape_corer?   build123d.topology.one_dr@   rA   rX   rc   rJ   rR   ra   rh   rn   rt   r   r   r   r   r   SHORTr   r   r  r  r)  r<  rO  rE   rK   rI   <module>rp     s  : # + + = =    - Q  + +  2 R	 	 	 * 
 
 
 2 E 1 3 B B  !- sC-vc3/DE
Fg(

 2
2+32U2(@@(@0<@CV@	@ 
	" 

 
?	?$?9? 
?
B.
$)2 8#,'8'
' ' 	'Z }}W;6W;W; W; 0	W;
 W;z }}U;6U;U; U; 0	U;
 U;t }}];6];]; 0]; 	];@P@3P@  P@ 0	P@
 P@fJ;3J; J; 	J;
 0J; J;d<;+<;4<; 0	<;
 <;~<5*<5<5 <5
 0<5 <5rK   