
    ^j8                     .   U d Z ddlZddlZddlmZ ddlmZmZ ddl	m
Z
mZ ddlmZm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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&m'Z'm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?  ej                  d      j                   ej                                 ej                  d      ZCe4e>z  e5z  e<z  e2z  ez  ZDe
eEd<   	 ddej                  fdeDeeD   z  deGe(z  dz  deHdede2f
dZIdej                  fde8ee8   z  dz  dede;e7z  fdZKe4e=z  ZLe
eEd<   	 	 	 	 dDdeLeeL   z  deGdeGdz  deGdz  d e4e5z  dz  de;e7z  fd!ZMdeLeeL   z  d"eGde;e7z  e3z  fd#ZNe4e>z  e5z  e2z  e3z  e;z  e7z  ZOe
eEd$<   	 de&j                  ej                  fdeOeeO   z  dz  d%e&dede3e;z  e7z  e2z  fd&ZQe4e5z  e<z  e2z  ZRe
eEd'<   	 dddej                  ej                  ddej                  fdeReeR   z  dz  d(eGd)e5eVe5   z  dz  d*ed+ed,eHd-eGdz  dede3e;z  e7z  e2z  fd.ZWe4e5z  e>z  e)z  e=z  ZXe
eEd/<   	 dddej                  fdeXeeX   z  dz  d0e&dz  d1e<e2z  e7z  dz  dede3e;z  e2z  e9e)   z  f
d2ZYdd3dej                  fde8ee8   z  dz  d4eGeZeGeGeGf   z  d%e*dz  dede3e;z  e7z  e2z  f
d5Z[e4e>z  e5z  e<z  Z\e
eEd6<   	 de&j                  ej                  ej                  fde\ee\   z  dz  d7e&e5z  e:z  d8edefd9Z^e2e4z  e>z  e5z  e<z  Z_e
eEd:<   	 ddd;d;ej                  dddej                  f	d<e_ee_   z  dz  d=e3e4z  e>z  ee4   z  dz  d>eHd?eHd@edAe*dz  dBe4e>z  dz  deHdede7e;z  fdCZay)Ea$  
Generic Operations

name: operations_generic.py
by:   Gumyr
date: March 21th 2023

desc:
    This python module contains operations (functions) that work on combinations
    of Curves, Sketches and Parts.

license:

    Copyright 2022 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.

    N)Iterable)radianstan)	TypeAliascast)Standard_ConstructionErrorStandard_Failure)StdFail_NotDone)BuilderLocationListWorkplaneListflatten_sequencevalidate_inputs)GeomTypeKeepKindModeSide
Transition)	BuildLine)	BuildPart)BuildSketch)AxisPlaneRotationRotationLikeVector
VectorLike)BaseLineObject)BasePartObject)BaseSketchObject)CompoundCurveEdgeFaceGroupByPartShape	ShapeListShellSketchSolidVertexWire	isclose_b	build123dAddTypeTobjectsrotationcleanmodereturnc           
      z   t        j                  d      }|t        d      t        | t              rt        | t
              st        |       }n| g}|D cg c]j  }t        |t               r|j                  Lt        |t
              r|j                  d      n)t        |t               r|j                  |j                  n|l }}t        |d|       t        |t              r|t        ddd      }n$t        |t              r	t        | }nt        d      |D cg c]  }|j                  |       }}|D cg c]  }t        |t              s| }}|D cg c]  }t        |t               s| }	}|D cg c]  }t        |t"              s| }
}|D cg c]  }t        |t$              s| }}t'        d |      D ]  }|j)                  |j+                  t                     |	j)                  |j+                  t                      |
j)                  |j+                  t"                     |j)                  |j+                  t$                      |	D ]!  }|j)                  |j-                                # t/        j                         st        d	      |D cg c]6  }t/        j                         j0                  D ]  }|j                  |       8 }}} |j2                  |  |}t5        j                         j6                  D ]q  }g }t/        j                         j0                  D ])  }|
D ]"  }|j9                  |j                  |             $ +  |j2                  |d
|i |j)                  |       s |D cg c]6  }t/        j                         j0                  D ]  }|j                  |       8 }}} |j:                  |||d |j)                  |       t        |      S t        |t<              rt        |t>        t@        f      r|nd}g }|D ]j  }|j)                  t/        j                         jB                  D cg c]1  }|jE                  tF        jH                  |      j                  |      3 c}       l  |j:                  |d|i t        |      S t        |tJ              rt        |t>        t@        f      r|nd}g }|D ]j  }|j)                  t/        j                         jB                  D cg c]1  }|jE                  tF        jH                  |      j                  |      3 c}       l  |j:                  |d|i t        |      S t        d|jL                  jN                   d      c c}w c c}w c c}w c c}w c c}w c c}w c c}}w c c}}w c c}w c c}w )a<  Generic Object: Add Object to Part or Sketch

    Add an object to a builder.

    BuildPart:
        Edges and Wires are added to pending_edges. Compounds of Face are added to
        pending_faces. Solids or Compounds of Solid are combined into the part.
    BuildSketch:
        Edges and Wires are added to pending_edges. Compounds of Face are added to sketch.
    BuildLine:
        Edges and Wires are added to line.

    Args:
        objects (Edge |  Wire |  Face |  Solid |  Compound  or Iterable of): objects to add
        rotation (float |  RotationLike, optional): rotation angle for sketch,
            rotation about each axis for part. Defaults to None.
        clean (bool, optional): Remove extraneous internal structure. Defaults to True.
       mode (Mode, optional): combine mode. Defaults to Mode.ADD.
    Nz'Add must have an active builder contextFfullyaddr   zInvalid rotation valuec                 "    t        | t              S )N)
isinstancer"   )os    U/opt/ringagent/.cad-venv/lib/python3.12/site-packages/build123d/operations_generic.py<lambda>zadd.<locals>.<lambda>   s    Ax)@     z$There is no active Locations context
face_planer4   r5           r5   zBuilder z is unsupported)(r   _get_contextRuntimeErrorr<   r   r"   list_objunwrapr   r   r   tuple
ValueErrormovedr$   r.   r%   r,   filterextendget_typeedgesr   	locations_add_to_pendingr   
workplanesappend_add_to_contextr   intfloatlocal_locationsrotater   Zr   	__class____name__)r2   r3   r4   r5   contextobject_listobjobject_iter	new_edges	new_wires	new_faces
new_solidscompoundnew_wireedgelocationlocated_edgesnew_objects	workplanefaces_per_workplanefacesolidlocated_solidsrotation_angles                           r>   r:   r:   N   sZ   2 &2248GDEE'8$Z-J7mi  3(SXX-=	 #x( JJUJ#'W5#((:NTWXK  GUK0'9%1a(H%(*H5666ABssyy*BB$/IS:c43HSI	I$/IS:c43HSI	I$/IS:c43HSI	I%0KcJsE4JcK
K@+N 	8HX..t45X..t45X..t45h//67		8
 " 	/HX^^-.	/ ((*EFF "
(557AA
  JJx 
 
 

 	 /# '335@@ 	4I"$(557AA E% ED'..tzz(/CDEE $G##%8OYO23	4 $
(557AA
  KK!
!
 

 	 u4H>*: K  7 
G[	)%/3,%GS 	C %1$=$=$?$O$O  JJtvv~6<<XF	 	 848" K   
GY	'%/3,%GS 	C %1$=$=$?$O$O  JJtvv~6<<XF	 	 848
 K   Xg&7&7&@&@%AQRRm& CIIIK
$
sU   A/V	V;VVV1V;VVV"1V"#;V'	;V-6V3

6V8
c                    t        j                  d      }| )|||j                  t        d      |j                  g}nt	        |       }t        |d|       t        |D cg c]  }|j                  dk(   c}      r{g }|D ]A  }t        |t              r|j                         }|j                  j                  |j                  j                  f|j                  j                  |j                  j                  f|j                  j                  |j                  j                  f|j                  j                  |j                  j                  f|j                  j                  |j                  j                  fg}|j                  t!        t#        j$                  |D cg c]  }t'        |       c}                   D | |j(                  |d|i t+        t-        |      j.                        S g }	|D ]  }t        |t              r|j                         }|	j                  t1        j2                  |j4                  j                  |j4                  j                  |j4                  j6                  t9        |j                  j                  |j                  j                  |j                  j6                  f                    | |j(                  |	d|i t;        t-        |	      j.                        S c c}w c c}w )a$  Generic Operation: Add Bounding Box

    Applies to: BuildSketch and BuildPart

    Add the 2D or 3D bounding boxes of the object sequence

    Args:
        objects (Shape or Iterable of): objects to create bbox for
        mode (Mode, optional): combination mode. Defaults to Mode.ADD.
    bounding_boxobjects must be provided   r5   )r   rD   rG   rJ   r   r   all_dimr<   r-   rq   minXYmaxrS   r%   r.   make_polygonr   rT   r+   r"   wrappedr,   make_boxsizerY   r   r'   )
r2   r5   r\   r]   r^   rb   bboxverticesvri   s
             r>   rq   rq      sV    &22>BG?g1gll6J788||n&w/G^[9
[1cCHHM12	 	UC#v&##%DTXXZZ(TXXZZ(TXXZZ(TXXZZ(TXXZZ(H T$"3"34Q1VAY4Q"RST	U #G##Y:T:hy)1122K 
c6"!NN						txxzz488::txxzz:;		
	
 848%--..C 2 5Rs   "L%LChamferFilletTypelengthlength2angle	referencec           	      >   t        j                  d      }|r|rt        d      |r|t        t	        |            z  }|r|s|st        d      ||n|}| || ||j
                  t        d      t        |       }t        |d|       ||j
                  n|d   j                  t        d      j                  dk(  rt        t              rt        j                        nt        |D cg c]  }t        |t               c}      st        d      j!                  ||t#        |      |      }|!|j%                  |t&        j(                  	       t        t+        |g      j                        S j                  d
k(  rt        t,              rt/        j                        nt        |D cg c]  }t        |t0               c}      st        d      g }	j3                         D ][  }
|
j5                         D cg c]	  }||v s| }}|r$|	j7                  |
j9                  ||||             K|	j7                  |
       ] t/        t+        |	      j                        }|!|j%                  |t&        j(                  	       |S j                  dk(  rt        t:              r$st=        g       n)t=        j                        nj?                         d   t        |D cg c]  }t        |t0               c}      st        d      j@                  stC        tE        fd|            }j9                  ||||      }|!|j%                  |t&        j(                  	       |S t        d      c c}w c c}w c c}w c c}w )aa  Generic Operation: chamfer

    Applies to 2 and 3 dimensional objects.

    Chamfer the given sequence of edges or vertices.

    Args:
        objects (Edge | Vertex  or Iterable of): edges or vertices to chamfer
        length (float): chamfer size
        length2 (float, optional): asymmetric chamfer size. Defaults to None.
        angle (float, optional): chamfer angle in degrees. Defaults to None.
        reference (Edge | Face): identifies the side where length is measured. Edge(s) must
            be part of the face. Vertex/Vertices must be part of edge

    Raises:
        ValueError: no objects provided
        ValueError: objects must be Edges
        ValueError: objects must be Vertices
        ValueError: Only one of length2 or angle should be provided
        ValueError: reference can only be used in conjunction with length2 or angle
    chamferz/Only one of length2 or angle should be providedz?reference can only be used in conjunction with length2 or angleNo objects providedr   zNothing to chamfer   z%3D chamfer operation takes only Edgesr5   rs   z(2D chamfer operation takes only Vertices   '1D fillet operation takes only Verticesc                     t        t        |       j                  d      z
  j                  d      xs1 t        t        |       j                  d      z
  j                  d       S Nr   rC   r   r/   r   position_atr   r   targets    r>   r?   zchamfer.<locals>.<lambda>v  Y    !6!9v/A/A!/D#D"L"LcR V$fQi&2D2DQ2G&G%O%OQTU r@   Invalid object dimension)#r   rD   rJ   r   r   rG   r   r   topo_parentru   r<   r    r'   r{   rt   r$   r   rF   rT   r   REPLACEr"   r!   r+   r-   facesr   rS   
chamfer_2dr   r.   wires	is_closedr)   rL   )r2   r   r   r   r   r\   r]   r^   new_partrb   rl   r   vertices_in_face
new_sketchre   r   s                  @r>   r   r     sN   8 &229=G5JKK3wu~..'UM
 	
  fWGGOG/GLL4H.//"7+KGY4Q++~-..{{a)3FN)Kfnn%QW[AcJsD)ABDEE>>&'43DiP##H4<<#@HhZ(0011{{a '19I&JF6>>"PV 	 {CJsF+CDGHH	LLN 	'D+/==?Oaa;>NOO  OOFG5EyQ   &	' HY/778
##JT\\#B{{afn-bfnn-\\^A&F{CJsF+CDFGG#  K $$VWk9M##H4<<#@
/
00s B D  P, Ds   7N?N	NN:Nradiusc           	         t        j                  d      }| || ||j                  t        d      t	        |       }t        |d|       ||j                  n|d   j                  t        d      j                  dk(  rt        t              rt        j                        nt        |D cg c]  }t        |t               c}      st        d      j                  |t        |            }|!|j!                  |t"        j$                         t        t'        |g      j                        S j                  dk(  rt        t(              rt+        j                        nt        |D cg c]  }t        |t,               c}      st        d	      g }j/                         D ]b  }|j1                         D cg c]  }|t        |      v s| }	}|	r"|j3                  |j5                  ||	             R|j3                  |       d t+        t'        |      j                        }
|!|j!                  |
t"        j$                         |
S j                  d
k(  rt        t6              r$st9        g       n)t9        j                        nj;                         d   t        |D cg c]  }t        |t,               c}      st        d      j<                  st?        tA        fd|            }j5                  ||      }|!|j!                  |t"        j$                         |S t        d      c c}w c c}w c c}w c c}w )a%  Generic Operation: fillet

    Applies to 2 and 3 dimensional objects.

    Fillet the given sequence of edges or vertices. Note that vertices on
    either end of an open line will be automatically skipped.

    Args:
        objects (Edge | Vertex or Iterable of): edges or vertices to fillet
        radius (float): fillet size - must be less than 1/2 local width

    Raises:
        ValueError: no objects provided
        ValueError: objects must be Edges
        ValueError: objects must be Vertices
        ValueError: nothing to fillet
    filletr   r   zNothing to filletr   z$3D fillet operation takes only Edgesr   rs   z'2D fillet operation takes only Verticesr   r   c                     t        t        |       j                  d      z
  j                  d      xs1 t        t        |       j                  d      z
  j                  d       S r   r   r   s    r>   r?   zfillet.<locals>.<lambda>  r   r@   r   )!r   rD   rG   rJ   r   r   r   ru   r<   r    r'   r{   rt   r$   r   rF   rT   r   r   r"   r!   r+   r-   r   r   rS   	fillet_2dr   r.   r   r   r)   rL   )r2   r   r\   r]   r^   r   rb   rl   r   r   r   re   r   s               @r>   r   r     s   * &228<GGOG/GLL4H.//"7+KGX{3Q++~,--{{a)3FN)Kfnn%QW[AcJsD)ABCDD==k):;##H4<<#@HhZ(0011{{a '19I&JF6>>"PV 	 {CJsF+CDFGG	LLN 	'D+/==?Uaa4CT>TUU  8H!IJ  &	' HY/778
##JT\\#B{{afn-bfnn-\\^A&F{CJsF+CDFGG#  K ##FK8##H4<<#@
/
00q B D  V( Ds   8M>MM!M M
MirrorTypeaboutc                 >   t        j                  d      }t        | t              rt        | t              st        |       }n| g}| )|||j                  t        d      |j                  g}nt        |       }t        |d|       |D cg c]&  }t        j                  |      j                  |      ( }}| |j                  |d|i t	        |      }t        |D cg c]  }|j                  dk(   c}      rt!        |j"                        S t        |D cg c]  }|j                  dk(   c}      rt%        |j"                        S t        |D cg c]  }|j                  dk(   c}      rt'        |j"                        S |S c c}w c c}w c c}w c c}w )a  Generic Operation: mirror

    Applies to 1, 2, and 3 dimensional objects.

    Mirror a sequence of objects over the given plane.

    Args:
        objects (Edge |  Face | Compound  or Iterable of): objects to mirror
        about (Plane, optional): reference plane. Defaults to "XZ".
        mode (Mode, optional): combination mode. Defaults to Mode.ADD.

    Raises:
        ValueError: missing objects
    mirrorrr   r5   r   rs   r   )r   rD   r<   r   r"   rF   rG   rJ   r   r   copy_moduledeepcopyr   rT   rt   ru   r'   r{   r+   r#   )	r2   r   r5   r\   r]   r=   mirroredmirrored_compoundr^   s	            r>   r   r     si   & &228<G'8$Z-J7mi?g1gll6J788||n&w/GX{3?JK!$$Q'..u5KHK55 *
[1cCHHM12%--..
[1cCHHM12'//00
[1cCHHM12&..// L 211s   +F!FFF
OffsetTypeamountopeningskindsideclosedmin_edge_lengthc                 
   t        j                  d      }| )|||j                  t        d      |j                  g}	nt	        |       }	t        |d|	       g }
g }g }|	D ]/  }t        |t              rm|
j                  |j                  t                     |j                  |j                  t                     |j                  |j                  t                     t        |t              r|j                  |       t        |t              r|j                  |       t        |t              r|
j                  |       t        |t              r!|
j                  |j                                t!        dt#        |       d|        g }|D ]v  }|j%                         j'                  ||      }||j)                  |      }g }|j+                         D ]K  }	 |j'                  | |      }|!|j                  |j)                  |             n|j                  |       M t        |      }|j5                         |j5                         z
  j6                  dkD  r| }|r|D cg c]  }t        |       }} |j8                  | }t        |t              r#|j                  |j;                  d             0t        |t<              r|j                  |       S|j                  |       f|j                  |       y |
rt?        |
      d	k(  r|
d
   j@                  tB        jD                  k(  rbt        t        jF                  |
d
   dz  |
d
   dz        t        jF                  |
d
   dz  |
d
   dz        g      j'                  ||||      g}nt        |
      j'                  ||||      g}|!|D cg c]  }|j)                  |       }}ng }t        |t              r|g}g }|D ]Z  }|r#|D cg c]  }||jI                         v s| }}ng }|j                  |jK                  |||      jM                                \ ||z   |z   }| |jN                  |d|i t        |      }tQ        |	D cg c]  }|jR                  dk(   c}      rtU        |jV                        S tQ        |	D cg c]  }|jR                  dk(   c}      rtY        |jV                        S tQ        |	D cg c]  }|jR                  d	k(   c}      rt[        |jV                        S |S # t,        t.        t0        t2        f$ r Y nw xY wc c}w c c}w c c}w c c}w c c}w c c}w )a  Generic Operation: offset

    Applies to 1, 2, and 3 dimensional objects.

    Offset the given sequence of Edges, Faces, Compound of Faces, or Solids.
    The kind parameter controls the shape of the transitions. For Solid
    objects, the openings parameter allows selected faces to be open, like
    a hollow box with no lid.

    Args:
        objects (Edge |  Face |  Solid |  Compound  or Iterable of): objects to offset
        amount (float): positive values external, negative internal
        openings (list[Face], optional), sequence of faces to open in part.
            Defaults to None.
        kind (Kind, optional): transition shape. Defaults to Kind.ARC.
        side (Side, optional): side to place offset. Defaults to Side.BOTH.
        closed (bool, optional): if Side!=BOTH, close the LEFT or RIGHT
            offset. Defaults to True.
        min_edge_length (float, optional): repair degenerate edges generated by offset
            by eliminating edges of minimum length in offset wire. Defaults to None.
        mode (Mode, optional): combination mode. Defaults to Mode.REPLACE.

    Raises:
        ValueError: missing objects
        ValueError: Invalid object type
    offsetrr   zUnsupported type z for )r   gMbP?Tr8   r   r   rC   g      ?g      ?)r   r   r   r5   r   rs   ).r   rD   rG   rJ   r   r   r<   r"   rM   rN   r$   r%   r,   rS   r.   rO   	TypeErrortype
outer_wire	offset_2dfix_degenerate_edgesinner_wiresrE   r	   r   r
   	normal_atr   cutrH   r)   len	geom_typer   LINE	make_liner   	offset_3dfixrT   rt   ru   r'   r{   r+   r#   )r2   r   r   r   r   r   r   r5   r\   r]   rO   r   solidsr^   rb   rl   r   r   
inner_wireoffset_wirenew_facewinner_facessubtractionra   rc   rm   r=   openings_in_this_solidri   offset_compounds                                  r>   r   r   "  s   H &228<G?g1gll6J788||n&w/GX{3EEF Gc8$LLd+,LLd+,MM#,,u-.U#MM#T"LLT"LLT"LL%/S	{%uEFFG  I $'__&00d0C
&#88IJ**, 	J(22F72F".&&#88I  &&{3	$ 
# 4>>#33;;eC yH,78q478K8&(,,4K+x0  t!<=K3  -  -X&I$'J u:?uQx11X]]BuQx#~uQx#~FuQx#~uQx#~F
 )FD)HI U%%f4d6%RI &JSTQ//@TIT	(D!:J 
19%PAQ%++-=Oa%P"%P%'"OO2FOFJJL	

 i'*4K848{+O
[1cCHHM12O++,,
[1cCHHM12o--..
[1cCHHM12_,,--C  *	   92 U &Q 211s=   &AT42U	UUU
U#U( U-4UUProjectTyperj   r   c           	      
   t        j                  d      }t        | t              rt	        d      | s|t	        d      | sx|vt        |t
              rf|j                  |j                  z   }g |_        g |_        t        |j                        dkD  r|j                  d   }g |_	        n|j                  d   }nt        |       }|D cg c]  }t        |t              rt        |      n|! }}t        |      j                  d      j                   }|D cg c]  }t        |t        t        f      s| }	}|	D 
cg c]  }
t        |
       }}
|D cg c]  }t        |t"              s| }}|D cg c]  }t        |t$        t&        f      s| }}||t	        d      t        |t(              r1|j*                  d   }|t,        j.                  k7  rP|s|rLt	        d	      t        |t0              r1|j*                  d   }|t,        j.                  k7  r|s|rt	        d
      t3        t4        |      }d}|At        |t
              r1|t,        j.                  k7  r|rt	        d      ||j6                  }d}nt#        j8                  d|z  d|z  |      }|t	        d      t;        |d       g }||z   D ]  }|j=                         |j=                         z
  j?                         }|jA                  |      jB                  dk  r|jD                   |z  }n|jD                  |z  }|jG                  ||      }|st        |t0              r/|jI                  |D cg c]  }|jK                  |       c}       t        |t(              r|jI                  |       |jI                  |jM                                 tO               }|D ]  }
|jP                  |
z
  j?                         }|jA                  |      jB                  dk  rtS        |
|jD                  |z         }ntS        |
|jD                  |z        }|jU                  |      }t        |tR              rtW        d      ||jY                  |jK                  |              | |jZ                  |d|i |r|}|S t        |      }t]        |D cg c]  }|j^                  dk(   c}      rta        |jb                        }|S t]        |D cg c]  }|j^                  dk(   c}      rte        |jb                        }|S c c}w c c}w c c}
w c c}w c c}w c c}w c c}w c c}w )a  Generic Operation: project

    Applies to 0, 1, and 2 dimensional objects.

    Project the given objects or points onto a BuildLine or BuildSketch workplane in
    the direction of the normal of that workplane. When projecting onto a
    sketch a Face(s) are generated while Edges are generated for BuildLine.
    Will only use the first if BuildSketch has multiple active workplanes.
    In algebra mode a workplane must be provided and the output is either
    a Face, Curve, Sketch, Compound, or ShapeList[Vector].

    Note that only if mode is not Mode.PRIVATE only Faces can be projected into
    BuildSketch and Edge/Wires into BuildLine.

    Args:
        objects (Edge |  Face |  Wire |  VectorLike |  Vertex or Iterable of):
            objects or points to project
        workplane (Plane, optional): screen workplane
        mode (Mode, optional): combination mode. Defaults to Mode.ADD.

    Raises:
        ValueError: project doesn't accept group_by
        ValueError: Either a workplane must be provided or a builder must be active
        ValueError: Points and faces can only be projected in PRIVATE mode
        ValueError: Edges, wires and points can only be projected in PRIVATE mode
        RuntimeError: BuildPart doesn't have a project operation
    projectz2project doesn't accept group_by, did you miss [n]?zNo object to projectr   )childrenF)optimalz?Either a workplane must be provided or a builder must be activez6Points and faces can only be projected in PRIVATE modez=Edges, wires and points can only be projected in PRIVATE moder   z,Points can only be projected in PRIVATE moder   )planez'A target object could not be determinedz.working_plane and projection_axis are parallelr5   rs   )3r   rD   r<   r&   rJ   r   pending_edgespending_facesr   pending_face_planesexit_workplanesr   r   r-   r"   rq   diagonalr%   r$   r.   r   rR   r   PRIVATEr   r   r   part	make_rectr   center
normalizedfrom_local_coordsrY   z_dirproject_to_shaperM   to_local_coordsr   r)   originr   	intersectrE   rS   rT   rt   ru   r+   r{   r#   )r2   rj   r   r5   r\   r]   r=   
shape_listobject_sizevct_vrt_listpnt
point_list	face_list	line_listworking_planeprojection_flipprojected_shapesr^   obj_to_screenprojection_direction
projectionpprojected_pointspnt_to_targetprojection_axisintersectionresults                              r>   r   r     s   B &229=G'7#MNNw/00w*z'9/M++g.C.CC " "w**+a/33A6I*,G'//2I&w/ FQQz!V4&)!;QJQJ/<<U<KTTK*N!jVV<L.MANLN)56#&+6J6'?q:a+>?I?'Gq:a$+FGIG?Q  gy)**1-It||#j L  -**1-It||#j S  	*M Oz'9=4<<JKLL>\\FK[V~BCCGY'9$ <3::<7CCE**=9;;a?$1$7$7#7/#I #0#6#6#H ))&2FG
';/ ''?IJ!]2215J GY/ ''
3 ''
(8(8(:;<" +4+ 
Q&--3??A**=9;;a?#C)<)<)NOOO"3(;(;o(MNO$..?lD)OPP###M$A$A,$OP
Q !1==! M *+5#A56FNN+F M ;7C#((a-786>>*FMq R O6?Gd K6 67sB   	$T4T95T9?T>U-U7UU"U
U Ur   byc                    t        j                  d      }| )|||j                  t        d      |j                  g}nt	        |       }t        |d|       g }|D ]'  }||j                  |j                  ||             ) | |j                  |d|i t        |      }t        |D cg c]  }|j                  dk(   c}      rt        |j                        }nwt        |D cg c]  }|j                  dk(   c}      rt        |j                        }n;t        |D cg c]  }|j                  dk(   c}      rt        |j                        }|j!                  d	      S c c}w c c}w c c}w )
a  Generic Operation: scale

    Applies to 1, 2, and 3 dimensional objects.

    Scale a sequence of objects. Note that when scaling non-uniformly across
    the three axes, the type of the underlying object may change to bspline from
    line, circle, etc.

    Args:
        objects (Edge |  Face |  Compound |  Solid or Iterable of): objects to scale
        by (float | tuple[float, float, float]): scale factor
        about (VectorLike, optional): point to scale about. Defaults to each
            object's location position.
        mode (Mode, optional): combination mode. Defaults to Mode.REPLACE.

    Raises:
        ValueError: missing objects
    scalerr   )r   r5   r   rs   r   Fr8   )r   rD   rG   rJ   r   r   rS   r   rT   r"   rt   ru   r'   r{   r+   r#   rH   )	r2   r   r   r5   r\   r]   ri   r^   scale_compounds	            r>   r   r   M  sW   0 &227;G?g1gll6J788||n&w/GWk2K 7;399Ru9567
 848k*N
[1cCHHM12n445	{3chh!m3	4 6 67	{3chh!m3	4~556  u -- 233s   /E++E0'E5	SplitType	bisect_bykeepc                 ~   t        j                  d      }| )|||j                  t        d      |j                  g}nt	        |       }t        |d|       g }|D ]~  }d}|t        j                  k(  r|j                  ||      \  }	}n|j                  ||      }	|	|fD ]8  }
t        |
t              r|j                  |
       %|
(|j                  |
       :  | |j                  |d|i t        |      }t        |D cg c]  }|j                   dk(   c}      rt#        |j$                        S t        |D cg c]  }|j                   dk(   c}      rt'        |j$                        S t        |D cg c]  }|j                   dk(   c}      rt)        |j$                        S |S c c}w c c}w c c}w )a(  Generic Operation: split

    Applies to 1, 2, and 3 dimensional objects.

    Bisect object with plane and keep either top, bottom or both.

    Args:
        objects (Edge |  Wire |  Face |  Solid or Iterable of), objects to split
        bisect_by (Plane |  Face, optional): plane to segment part.
            Defaults to Plane.XZ.
        keep (Keep, optional): selector for which segment to keep. Defaults to Keep.TOP.
        mode (Mode, optional): combination mode. Defaults to Mode.REPLACE.

    Raises:
        ValueError: missing objects
    splitNrr   r5   r   rs   r   )r   rD   rG   rJ   r   r   r   BOTHr   r<   r   rM   rS   rT   r"   rt   ru   r'   r{   r+   r#   )r2   r   r   r5   r\   r]   ri   r^   bottomtopsubpartsplit_compounds               r>   r   r     s   , &227;G?g1gll6J788||n&w/GWk2#%K 
,499))It4KC))It,CV} 	,G'8,""7+$""7+		,
, 848k*N
[1cCHHM12N**++
[1cCHHM12n,,--
[1cCHHM12^++,, 211s   F0F5<F:	SweepTypeFsectionspathmultisection	is_frenet
transitionnormalbinormalc	                 \   t        j                  d      }	| g }
n&t        | t              r| D cg c]  }||	 }
}n| g}
t	        |	d|
       |L|	"t        |	t
        t        f      r|	j                  st        d      t        |	j                        }g |	_        nHt        |t              r	 t        |      }n+t        |t              st        |j                               n|}|
sD|	7t        |	t
              r'|	j                  r|	j                  }
g |	_        g |	_        nt        d      g }g }|
D ]\  }t        |t        t        t        f      r |j                  |j                                >|j                  |j!                                ^ g }|r||t#        |      }nt        |t              rt        |g      }n|}|r8|D cg c]  }|j%                          } }t'        j(                  | |d||      g}n(|D cg c]  }t'        j*                  ||d|||       }}g }|r=|
D ]8  }t-        j*                  |||      }|j                  |j!                                : |	 |	j.                  ||z   ||d n<|r:|D cg c]  }|j1                          }}|D cg c]  }|j1                          }}|rt3        t5        |      j6                        S t9        t5        |      j6                        S c c}w # t        $ r}t        d      |d}~ww xY wc c}w c c}w c c}w c c}w )	a{  Generic Operation: sweep

    Sweep pending 1D or 2D objects along path.

    Args:
        sections (Compound |  Edge |  Wire |  Face |  Solid): cross sections to sweep into object
        path (Curve |  Edge |  Wire, optional): path to follow.
            Defaults to context pending_edges.
        multisection (bool, optional): sweep multiple on path. Defaults to False.
        is_frenet (bool, optional): use frenet algorithm. Defaults to False.
        transition (Transition, optional): discontinuity handling option.
            Defaults to Transition.TRANSFORMED.
        normal (VectorLike, optional): fixed normal. Defaults to None.
        binormal (Edge |  Wire, optional): guide rotation along path. Defaults to None.
        clean (bool, optional): Remove extraneous internal structure. Defaults to True.
        mode (Mode, optional): combination. Defaults to Mode.ADD.
    sweepNzpath must be providedzUnable to build path from edgeszNo sections providedT)sectionr  
make_solidr  r5   r  rB   )r   rD   r<   r   r   r   r   r   rJ   r.   rO   r   r   r#   r$   rM   r   r   r   r,   sweep_multir  r*   rT   r4   r'   r"   r{   r+   )r  r  r  r  r  r	  r
  r4   r5   r\   section_listsec	path_wireerr	edge_listr   rc   binormal_moderl   rb   sweptrm   s                         r>   r  r    s   8 &227;G	Hh	''/C3?CC zGWl3|Og	;'?@((455../	 "dH%M J	 3=T42HTZZ\*dI7I.%%"00L$&G!*,G'344II *cE4./SYY[)SYY[)	* J 2"6NM$' (,M$M6?@d)@H@!!(ItYVJ &
   "#'&)
J 
 I 	,CKKY
;EU[[]+	, *y"8TR	1;<ekkm<
<.78dTZZ\8	8HZ(0011(9%--..o D&  M !BCLMH A

, =8s:   K8K8-K= L "LL$!L)=	LLL)NNN)b__doc__copyr   loggingcollections.abcr   mathr   r   typingr   r   OCP.Standardr   r	   OCP.StdFailr
   build123d.build_commonr   r   r   r   r   build123d.build_enumsr   r   r   r   r   r   build123d.build_liner   build123d.build_partr   build123d.build_sketchr   build123d.geometryr   r   r   r   r   r   build123d.objects_curver   build123d.objects_partr    build123d.objects_sketchr!   build123d.topologyr"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   	getLogger
addHandlerNullHandlerloggerr1   __annotations__ADDrV   boolr:   r   rq   r   r   r   r   XZr   r   ARCr   r   rF   r   r   r   rI   r   r   TOPr   r  TRANSFORMEDr   r@   r>   <module>r5     s  :   $  " E '  O N * * . V V 2 1 5   "   +  ) )*='*=*=*? @			;	'D[4'%/(:WD D 5
 -1	y!x((y!l"T)y! y! 	y!
 y!z /3:/Xe_$t+:/
:/ d]:/z  $f} 9 , 8 !$(w1*;!<<w1w1 T\w1 4<	w1
 d{T!w1 d]w1ta1*;!<<a1a1 d]Ua1H td*X5=FM
I M + 9=88.(:..5.. . V^dX%	.b te+h6
I 6 ) 9=)-$(S(:..5SS T$Z$&S 	S
 S S T\S S V^dX%Sl t+f4v=Y = , ;?"-1	N8K0047Nt|N Ht#d*N 	N
 V^h6!22Nd /3-.#	3.Xe_$t+3.eUE)**3. 3. 	3.
 V^dX%3.l d{T)E1	9 1 ( 7;&+hh	8),,t38t|e#8 8 	8v  $-4u<	9 < ( 8<8<'33 $#'x/(9--4x/
$,

.
5x/ x/ 	x/
 x/ x/ TkD x/ x/ x/ 
F]x/r@   