
    ^jP                       d 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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mZ dd
lmZmZmZmZmZmZm Z m!Z!  G d de      Z" G d de"      Z# G d de"      Z$ G d de"      Z% G d de"      Z& G d de"      Z' G d de"      Z( G d de"      Z) G d de"      Z* G d de"      Z+ G d d e"      Z,y!)"a  
Part Objects

name: objects_part.py
by:   Gumyr
date: March 22nd 2023

desc:
    This python module contains objects (classes) that create 3D Parts.

license:

    Copyright 2023 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)Iterable)radianstan)
ConvexHull)LocationListvalidate_inputs)AlignMode)	BuildPart)LocationPlaneRotationRotationLikeVector
VectorLike)CompoundFacePart	ShapeListShellSolidWiretuplifyc                  h     e Zd ZdZej
                  gZddej                  f	 	 	 	 	 	 	 d fdZ	 xZ
S )BasePartObjecta  BasePartObject

    Base class for all BuildPart objects & operations

    Args:
        solid (Solid): object to create
        rotation (RotationLike, optional): angles to rotate about axes. Defaults to (0, 0, 0)
        align (Align | tuple[Align, Align, Align] | None, optional): align MIN, CENTER,
            or MAX of object. Defaults to None
        mode (Mode, optional): combination mode. Defaults to Mode.ADD
    r   r   r   Nc                   |Gt        |d      }|j                         }|j                  |      }|j                  t	        |             t        j                  | d      }t        |t              rt        | n|}|| _
        |#|t               k7  r|j                  |      gn|g}	n|| _        t        j                         st        d      t        j                         j                  D 
cg c]2  }
|t               k7  s|
t	               k7  r|j                  |
|z        n|4 }	}
t        |t
              r |j                   |	d|i t#        |	      dkD  rt%        |	      j&                  }n8t        |	d   t$              r|	d   j&                  }nt%        |	      j&                  }t(        | U  ||j,                  |j.                  |j0                  |j2                  |j4                         y c c}
w )	N   F)logzNo valid context foundmode   r   )objlabelmaterialjointsparentchildren)r   bounding_boxto_align_offsetmover   r   _get_context
isinstancetupler   rotationmovedr!   r   RuntimeError	locations_add_to_contextlenr   wrappedsuper__init__r$   r%   r&   r'   r(   )selfpartr/   alignr!   bboxoffsetcontextrotate
new_solidslocationnew_part	__class__s               O/opt/ringagent/.cad-venv/lib/python3.12/site-packages/build123d/objects_part.pyr7   zBasePartObject.__init__I   s    E1%E$$&D))%0FIIhv&'$-$:$:4U$K(28U(C8$?178:1E$**V,-D6JDI,,."#;<< !- 9 9 ; E E  +x8:/E JJx&01J  '9-'''?$?z?Q
+33H
1x0!!},,H
+33H**]];;;;]] 	 	
%s   .7G-)r9   zPart | Solidr/   r   r:   )Align | tuple[Align, Align, Align] | Noner!   r   )__name__
__module____qualname____doc__r   _tag_applies_tor   ADDr7   __classcell__rB   s   @rC   r   r   :   sU    
 >>"K
 "+;?XX1
1
 1
 9	1

 1
 1
    r   c                       e Zd ZdZej
                  gZdej                  ej                  ej                  fe	j                  f	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )Boxa  Part Object: Box

    Create a box defined by length, width, and height.

    Args:
        length (float): box length
        width (float): box width
        height (float): box height
        rotation (RotationLike, optional): angles to rotate about axes. Defaults to (0, 0, 0)
        align (Align | tuple[Align, Align, Align] | None, optional): align MIN, CENTER,
            or MAX of object. Defaults to (Align.CENTER, Align.CENTER, Align.CENTER)
        mode (Mode, optional): combine mode. Defaults to Mode.ADD
    r   c                    t        j                  |       }t        ||        || _        || _        || _        t        j                  |||      }t        	| %  ||t        |d      |       y Nr   r9   r/   r:   r!   )r   r,   r	   lengthwidth
box_heightr   make_boxr6   r7   r   )
r8   rT   rU   heightr/   r:   r!   r=   solidrB   s
            rC   r7   zBox.__init__   sh     %.$:$:4$@&
 vuf51B 	 	
rN   )rT   floatrU   rZ   rX   rZ   r/   r   r:   "Align | tuple[Align, Align, Align]r!   r   rE   rF   rG   rH   r   rI   rJ   r
   CENTERr   rK   r7   rL   rM   s   @rC   rP   rP   }   s     >>"K "+LLLLLL5

 XX

 
 	

 
 2
 
 
rN   rP   c                       e Zd ZdZej
                  gZddej                  ej                  ej                  fe	j                  f	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )Conea  Part Object: Cone

    Create a cone defined by bottom radius, top radius, and height.

    Args:
        bottom_radius (float): bottom radius
        top_radius (float): top radius, may be zero
        height (float): cone height
        arc_size (float, optional): angular size of cone. Defaults to 360
        rotation (RotationLike, optional): angles to rotate about axes. Defaults to (0, 0, 0)
        align (Align | tuple[Align, Align, Align] | None, optional): align MIN, CENTER,
            or MAX of object. Defaults to (Align.CENTER, Align.CENTER, Align.CENTER)
        mode (Mode, optional): combine mode. Defaults to Mode.ADD
    h  r   c                    t        j                  |       }t        ||        || _        || _        || _        || _        || _        t        j                  ||||      }	t        
| -  |	|t        |d      |       y N)angler   rS   )r   r,   r	   bottom_radius
top_radiuscone_heightarc_sizer:   r   	make_coner6   r7   r   )r8   rd   re   rX   rg   r/   r:   r!   r=   rY   rB   s             rC   r7   zCone.__init__   s     %.$:$:4$@&*$! 
	
 	1B 	 	
rN   )rd   rZ   re   rZ   rX   rZ   rg   rZ   r/   r   r:   r[   r!   r   r\   rM   s   @rC   r_   r_      s     >>"K !*LLLLLL5

 XX 
 
  
 	 

  
  
 2 
  
  
rN   r_   c                  |     e Zd ZdZej
                  gZdej                  e	j                  f	 	 	 	 	 	 	 d fdZ xZS )ConvexPolyhedrona  Part Object: ConvexPolyhedron

    Create a convex solid from the convex hull of the provided points.

    Args:
        points (Iterable[VectorLike]): vertices of the polyhedron
        rotation (RotationLike, optional): angles to rotate about axes. Defaults to (0, 0, 0)
        align (Align | tuple[Align, Align, Align] | None, optional): align MIN, CENTER,
            or MAX of object. Defaults to Align.NONE
        mode (Mode, optional): combine mode. Defaults to Mode.ADD
    r   c                   t        j                  |       }t        ||        |D cg c]  }t        t	        |             }}t        |      j                  j                         }g }	|D ]A  }
|
D cg c]  }||   	 }}|	j                  t        t        j                  |                   C t        t        |	            j                         }t        | A  ||t#        |d      |       y c c}w c c}w rR   )r   r,   r	   r.   r   r   	simplicestolistappendr   r   make_polygonr   r   cleanr6   r7   r   )r8   pointsr/   r:   r!   r=   ppntsconvex_hullpolyhedron_facesface_vertex_indicesicorner_vertices
polyhedronrB   s                 rC   r7   zConvexPolyhedron.__init__   s     %.$:$:4$@&7=>!U6!9->> !&00779 #. 	N0CD1tAwDOD##D):):?)K$LM	N
 5!12399;
hgeQ6Gd 	 	
 ? Es   C/2C4)rq   zIterable[VectorLike]r/   r   r:   rD   r!   r   )rE   rF   rG   rH   r   rI   rJ   r
   NONEr   rK   r7   rL   rM   s   @rC   rj   rj      sY    
 >>"K
 "+;@::XX
$
 
 9	

 
 
rN   rj   c                  j     e Zd ZdZej
                  gZdej                  f	 	 	 	 	 	 	 	 	 d fdZ	 xZ
S )CounterBoreHolea  Part Operation: Counter Bore Hole

    Create a counter bore hole defined by radius, counter bore radius, counter bore and depth.

    Args:
        radius (float): hole radius
        counter_bore_radius (float): counter bore radius
        counter_bore_depth (float): counter bore depth
        depth (float, optional): hole depth, through part if None. Defaults to None
        mode (Mode, optional): combination mode. Defaults to Mode.SUBTRACT
    Nc                
   t        j                  |       }t        ||        || _        || _        || _        ||| _        n!|||j                  | _        nt        d      || _	        t        j                  || j                  t        dd            j                  t        j                  ||| j                  z   t        dd| f                  }t        |t              rt!        |      }n|}t"        	| I  |d|       y )NNo depth providedr   r   r   originz_dirr   r9   r/   r!   )r   r,   r	   radiuscounter_bore_radiuscounter_bore_depth
hole_depthmax_dimension
ValueErrorr!   r   make_cylinderr   fuser-   r   r   r6   r7   )
r8   r   r   r   depthr!   r=   fusedrY   rB   s
            rC   r7   zCounterBoreHole.__init__  s     %.$:$:4$@&#6 "4#DO]w2%33DO011	##DOOU):%N

$#"T__4q!0012
 	 eY'KEEeidCrN   )
r   rZ   r   rZ   r   rZ   r   float | Noner!   r   rE   rF   rG   rH   r   rI   rJ   r   SUBTRACTr7   rL   rM   s   @rC   r|   r|   
  sc    
 >>"K #]]#D#D ##D "	#D
 #D #D #DrN   r|   c                  l     e Zd ZdZej
                  gZddej                  f	 	 	 	 	 	 	 	 	 d fdZ	 xZ
S )CounterSinkHolea  Part Operation: Counter Sink Hole

    Create a countersink hole defined by radius, countersink radius, countersink
    angle, and depth.

    Args:
        radius (float): hole radius
        counter_sink_radius (float): countersink radius
        depth (float, optional): hole depth, through part if None. Defaults to None
        counter_sink_angle (float, optional): cone angle. Defaults to 82
        mode (Mode, optional): combination mode. Defaults to Mode.SUBTRACT
    NR   c                `   t        j                  |       }t        ||        || _        || _        ||| _        n!|||j                  | _        nt        d      || _        || _	        |t        t        |dz              z  }t        j                  || j
                  t        dd            j                  t        j                   |d|t        dd            t        j                  || j
                              }t#        |t$              rt'        |      }	n|}	t(        
| U  |	d|       y )Nr~   g       @r   r   r   g        r   )r   r,   r	   r   counter_sink_radiusr   r   r   counter_sink_angler!   r   r   r   r   r   r   rh   r-   r   r   r6   r7   )r8   r   r   r   r   r!   r=   rf   r   rY   rB   s             rC   r7   zCounterSinkHole.__init__O  s    %.$:$:4$@&#6 #DO]w2%33DO011"4	)C8JS8P0Q,RR##DOOU):%N

$OO#Yj9	  3T__E
 	 eY'KEEeidCrN   )
r   rZ   r   rZ   r   r   r   rZ   r!   r   r   rM   s   @rC   r   r   ?  sf     >>"K #$&]]'D'D #'D 	'D
 "'D 'D 'DrN   r   c                       e Zd ZdZej
                  gZddej                  ej                  ej                  fe	j                  f	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )CylinderaB  Part Object: Cylinder

    Create a cylinder defined by radius and height.

    Args:
        radius (float): cylinder radius
        height (float): cylinder height
        arc_size (float, optional): angular size of cone. Defaults to 360.
        rotation (RotationLike, optional): angles to rotate about axes. Defaults to (0, 0, 0)
        align (Align | tuple[Align, Align, Align] | None, optional): align MIN, CENTER,
            or MAX of object. Defaults to (Align.CENTER, Align.CENTER, Align.CENTER)
        mode (Mode, optional): combine mode. Defaults to Mode.ADD
    r`   r   c                    t        j                  |       }t        ||        || _        || _        || _        || _        t        j                  |||      }t        	| )  ||t        |d      |       y rb   )r   r,   r	   r   cylinder_heightrg   r:   r   r   r6   r7   r   )
r8   r   rX   rg   r/   r:   r!   r=   rY   rB   s
            rC   r7   zCylinder.__init__  sy     %.$:$:4$@&% 
##

 	1B 	 	
rN   )r   rZ   rX   rZ   rg   rZ   r/   r   r:   r[   r!   r   r\   rM   s   @rC   r   r   y  s     >>"K !*LLLLLL5

 XX

 
 	

 
 2
 
 
rN   r   c                  b     e Zd ZdZej
                  gZdej                  f	 	 	 	 	 d fdZ	 xZ
S )Holea  Part Operation: Hole

    Create a hole defined by radius and depth.

    Args:
        radius (float): hole radius
        depth (float, optional): hole depth, through part if None. Defaults to None
        mode (Mode, optional): combination mode. Defaults to Mode.SUBTRACT
    Nc                   t        j                  |       }t        ||        || _        |d|z  | _        n$||d|j
                  z  | _        nt        d      || _        |dd| j                  dz  fnd}t        j                  || j                  t        |d            }t        | 1  |t        j                  t        j                  t        j                  fd|       y )N   r~   r   r   r   r   )r9   r:   r/   r!   )r   r,   r	   r   r   r   r   r!   r   r   r   r6   r7   r
   r]   )r8   r   r   r!   r=   
hole_startrY   rB   s          rC   r7   zHole.__init__  s     %.$:$:4$@&%iDO]w2'"7"77DO011	 5:MaDOOa/0y
##DOOU*J%O
 	<<u||<	 	 	
rN   )r   rZ   r   r   r!   r   r   rM   s   @rC   r   r     sH     >>"K
 #]]	

 
 	
 
rN   r   c                       e Zd ZdZej
                  gZddddej                  ej                  ej                  fe	j                  f	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )Spherea  Part Object: Sphere

    Create a sphere defined by a radius.

    Args:
        radius (float): sphere radius
        arc_size1 (float, optional): angular size of bottom hemisphere. Defaults to -90.
        arc_size2 (float, optional): angular size of top hemisphere. Defaults to 90.
        arc_size3 (float, optional): angular revolution about pole. Defaults to 360.
        rotation (RotationLike, optional): angles to rotate about axes. Defaults to (0, 0, 0)
        align (Align | tuple[Align, Align, Align] | None, optional): align MIN, CENTER,
            or MAX of object. Defaults to (Align.CENTER, Align.CENTER, Align.CENTER)
        mode (Mode, optional): combine mode. Defaults to Mode.ADD
    iZ   r`   r   c                    t        j                  |       }t        ||        || _        || _        || _        || _        || _        t        j                  ||||      }	t        
| -  |	|t        |d      |       y )N)angle1angle2angle3r   rS   )r   r,   r	   r   	arc_size1	arc_size2	arc_size3r:   r   make_spherer6   r7   r   )r8   r   r   r   r   r/   r:   r!   r=   rY   rB   s             rC   r7   zSphere.__init__  s     %.$:$:4$@&"""
!!	
 	1B 	 	
rN   )r   rZ   r   rZ   r   rZ   r   rZ   r/   r   r:   r[   r!   r   r\   rM   s   @rC   r   r     s     >>"K
 !*LLLLLL5

 XX

 
 	

 
 
 2
 
 
rN   r   c                       e Zd ZdZej
                  gZddddej                  ej                  ej                  fe	j                  f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )Torusa  Part Object: Torus

    Create a torus defined by major and minor radii.

    Args:
        major_radius (float): major torus radius
        minor_radius (float): minor torus radius
        minor_start_angle (float, optional): angle to start minor arc. Defaults to 0
        minor_end_angle (float, optional): angle to end minor arc. Defaults to 360
        major_angle (float, optional): angle to revolve minor arc. Defaults to 360
        rotation (RotationLike, optional): angles to rotate about axes. Defaults to (0, 0, 0)
        align (Align | tuple[Align, Align, Align] | None, optional): align MIN, CENTER,
            or MAX of object. Defaults to (Align.CENTER, Align.CENTER, Align.CENTER)
        mode (Mode, optional): combine mode. Defaults to Mode.ADD
    r   r`   r   c	                
   t        j                  |       }	t        |	|        || _        || _        || _        || _        || _        || _        t        j                  |||||      }
t        | 1  |
|t        |d      |       y )N)start_angle	end_anglemajor_angler   rS   )r   r,   r	   major_radiusminor_radiusminor_start_angleminor_end_angler   r:   r   
make_torusr6   r7   r   )r8   r   r   r   r   r   r/   r:   r!   r=   rY   rB   s              rC   r7   zTorus.__init__  s     %.$:$:4$@&((!2.&
  )%#
 	1B 	 	
rN   )r   rZ   r   rZ   r   rZ   r   rZ   r   rZ   r/   r   r:   r[   r!   r   r\   rM   s   @rC   r   r     s      >>"K $%!$ !*LLLLLL5

 XX"
"
 "
 !	"

 "
 "
 "
 2"
 "
 "
rN   r   c                       e Zd ZdZej
                  gZdej                  ej                  ej                  fe	j                  f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )Wedgea  Part Object: Wedge

    Create a wedge with a near face defined by xsize and z size, a far face defined by
    xmin to xmax and zmin to zmax, and a depth of ysize.

    Args:
        xsize (float): length of near face along x-axis
        ysize (float): length of part along y-axis
        zsize (float): length of near face z-axis
        xmin (float): minimum position far face along x-axis
        zmin (float): minimum position far face along z-axis
        xmax (float): maximum position far face along x-axis
        zmax (float): maximum position far face along z-axis
        rotation (RotationLike, optional): angles to rotate about axes. Defaults to (0, 0, 0)
        align (Align | tuple[Align, Align, Align] | None, optional): align MIN, CENTER,
            or MAX of object. Defaults to (Align.CENTER, Align.CENTER, Align.CENTER)
        mode (Mode, optional): combine mode. Defaults to Mode.ADD
    r   c           	        t        j                  |       }t        ||        t        |||fD cg c]  }|dk  	 c}      rt	        d      || _        || _        || _        || _        || _	        || _
        || _        |	| _        t        j                  |||||||      }t        | A  ||t#        |	d      |
       y c c}w )Nr   z2xsize, ysize & zsize must all be greater than zeror   rS   )r   r,   r	   anyr   xsizeysizezsizexminzminxmaxzmaxr:   r   
make_wedger6   r7   r   )r8   r   r   r   r   r   r   r   r/   r:   r!   r=   valuerY   rB   s                 rC   r7   zWedge.__init__\  s    " %.$:$:4$@&u(=>u
>?QRR


				
  udD$M1B 	 	
 ?s   B>)r   rZ   r   rZ   r   rZ   r   rZ   r   rZ   r   rZ   r   rZ   r/   r   r:   r[   r!   r   r\   rM   s   @rC   r   r   D  s    & >>"K "+LLLLLL5

 XX#
#
 #
 	#

 #
 #
 #
 #
 #
 2#
 #
 #
rN   r   N)-rH   
__future__r   collections.abcr   mathr   r   scipy.spatialr   build123d.build_commonr   r	   build123d.build_enumsr
   r   build123d.build_partr   build123d.geometryr   r   r   r   r   r   build123d.topologyr   r   r   r   r   r   r   r   r   rP   r_   rj   r|   r   r   r   r   r   r    rN   rC   <module>r      s   8 # $  $ @ - * 	 	 	@
T @
F)
. )
X2
> 2
j)
~ )
X2Dn 2Dj7Dn 7Dt-
~ -
`,
> ,
^1
^ 1
h5
N 5
p;
N ;
rN   