
    ^j:                      d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
mZ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 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%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0m1Z1 ddl2m3Z3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z=m>Z> ddl?m@Z@ ddlAmBZBmCZC ddlDmEZEmFZFmGZGmHZHmIZImJZJmKZK ddlLmMZMmNZN ddlOmPZP ddlQmRZRmSZSmTZTmUZUmVZVmWZW ddlXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZa ddlbmcZcmdZdmeZe dd lfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZp dd!lqmrZrmsZsmtZtmuZu dd"lvmwZwmxZxmyZy dd#lzm{Z{ e
rdd$l|m}Z}m~Z~  G d% d&eieg         Z G d' d(eeJ         Z G d) d*e      Zy)+a  
build123d topology

name: three_d.py
by:   Gumyr
date: January 07, 2025

desc:

This module defines the `Solid` class and associated methods for creating, manipulating, and
querying three-dimensional solid geometries in the build123d CAD system. It provides powerful tools
for constructing complex 3D models, including operations such as extrusion, sweeping, filleting,
chamfering, and Boolean operations. The module integrates with OpenCascade to leverage its robust
geometric kernel for precise 3D modeling.

Key Features:
- **Solid Class**:
  - Represents closed, bounded 3D shapes with methods for volume calculation, bounding box
    computation, and validity checks.
  - Includes constructors for primitive solids (e.g., box, cylinder, cone, torus) and advanced
    operations like lofting, revolving, and sweeping profiles along paths.

- **Mixin3D**:
  - Adds shared methods for operations like filleting, chamfering, splitting, and hollowing solids.
  - Supports advanced workflows such as finding maximum fillet radii and extruding with rotation or
    taper.

- **Boolean Operations**:
  - Provides utilities for union, subtraction, and intersection of solids.

- **Thickening and Offsetting**:
  - Allows transformation of faces or shells into solids through thickening.

This module is essential for generating and manipulating complex 3D geometries in the build123d
library, offering a comprehensive API for CAD modeling.

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)Iterable)cosradianstan)TYPE_CHECKINGLiteralcastN)BRepAlgoAPI_CommonBRepAlgoAPI_Cut)BRepBuilderAPI_MakeSolid)BRepClass3d_SolidClassifier)BRepExtrema_DistShapeShape)BRepFeat_MakeDPrism)BRepFilletAPI_MakeChamferBRepFilletAPI_MakeFillet)BRepGProp_Face)BRepOffset_MakeOffsetBRepOffset_Skin)BRepOffsetAPI_DraftAngleBRepOffsetAPI_MakePipeShellBRepOffsetAPI_MakeThickSolid)BRepPrimAPI_MakeBoxBRepPrimAPI_MakeConeBRepPrimAPI_MakeCylinderBRepPrimAPI_MakeRevolBRepPrimAPI_MakeSphereBRepPrimAPI_MakeTorusBRepPrimAPI_MakeWedge)GeomAbs_IntersectionGeomAbs_JoinType)gp_Ax2gp_Pntgp_Vec)GProp_GProps)LocOpe_DPrism)ShapeFix_Solid)Standard_FailureStandard_TypeMismatch)StdFail_NotDone)TopExpTopExp_Explorer)TopoDSTopoDS_CompoundTopoDS_FaceTopoDS_ShapeTopoDS_ShellTopoDS_SolidTopoDS_Wire))TopTools_IndexedDataMapOfShapeListOfShapeTopTools_ListOfShape)Self)CenterOfGeomTypeKeepKind
TransitionUntil)	DEG2RADAxisBoundBoxColorLocationOrientedBoundBoxPlaneVector
VectorLike   )EdgeMixin1DWire)
TOPODSJointShape	ShapeList_sew_topods_facesdowncastget_top_level_topods_shapes	shapetypeunwrap_topods_compound!_make_topods_compound_from_shapes)FaceMixin2DShellsort_wires_by_build_order)_extrude_topods_shape
_make_loftfind_max_dimension)Vertex)CompoundPartc                     e Zd ZdZej
                  Zedd       Zedd       Z	e	 	 	 	 	 	 dd       Z
edd       Zej                  fddZ	 d	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Zdd
Zdej(                  f	 	 	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 ddZdd dZ	 	 d!	 	 	 	 	 d"dZdej(                  f	 	 	 	 	 	 	 	 	 d#dZ	 	 	 d$	 	 	 	 	 	 	 	 	 d%dZy)&Mixin3Dz-Additional methods to add to 3D Shape classesc                     y)zDimension of Solids    selfs    S/opt/ringagent/.cad-venv/lib/python3.12/site-packages/build123d/topology/three_d.py_dimzMixin3D._dim   s         c                4   t         j                  t        t         j                  t        t         j
                  t        t         j                  t        t         j                  t        t         j                  t        i}t        |      } ||   t        |            S )z6Returns the right type of wrapper, given a OCCT object)taTopAbs_VERTEXr[   TopAbs_EDGErG   TopAbs_WIRErI   TopAbs_FACErT   TopAbs_SHELLrV   TopAbs_SOLIDSolidrQ   rO   )clsobjconstructor_lut
shape_types       re   r
   zMixin3D.cast   sd     fNNDNNDNNDOOUOOU
 s^
*z*8C=99rg   c                    t         S )z9Unused - only here because Mixin1D is a subclass of Shape)NotImplementedrq   rr   	directions      re   extrudezMixin3D.extrude   s
    
 rg   c                4   t        |       }t        |t              rt        t        |d            }t        |t              r;t	        d t        |      D              }t        dt        j                  |d            S t        t        j                  |            S )zCWrap a 3D operation result as topology, not as the source subclass.Tc              3  X   K   | ]"  }t        t        j                   |             $ y wN)rp   r-   ).0ss     re   	<genexpr>z*Mixin3D._make_3d_result.<locals>.<genexpr>   s"      +,fll1o&s   (*r]   ra   )rO   
isinstancer.   rR   rM   rP   r
   rL   make_compositerp   r-   )shaperesultsolidss      re   _make_3d_resultzMixin3D._make_3d_result   s     %fo.4VTBCFfo. 0KF0S F  4 4VQ ?@@V\\&)**rg   c                h   |t         j                  k(  rt        d      |t         j                  k(  rbt	               }t
        j                  t        | j                           }|J  || j                  |       t        |j                               }|S | j                         j                         }|S )a  Return center of object

        Find center of object

        Args:
            center_of (CenterOf, optional): center option. Defaults to CenterOf.MASS.

        Raises:
            ValueError: Center of GEOMETRY is not supported for this object
            NotImplementedError: Unable to calculate center of mass of this object

        Returns:
            Vector: center
        z3Center of GEOMETRY is not supported for this object)r7   GEOMETRY
ValueErrorMASSr%   rL   shape_properties_LUTrQ   wrappedrD   CentreOfMassbounding_boxcenter)rd   	center_of
propertiescalc_functionmiddles        re   r   zMixin3D.center   s     )))RSS%%J!66y7NOM ,,,$,,
3J3356F  &&(//1Frg   Nc           	        t        |      }rt        fd|D              rt        d      |D cg c]  }|j                   }}t	               }t        j                  | j                  t        j                  t        j                  |       t        | j                        }|r|}	|}
n|}	|}
|D ]W  }rj                  }n|j                  |      j                         }|j                  |	|
|t        j                  |             Y 	 | j!                  |j#                               }|j$                  st&        	 |S c c}w # t(        t&        f$ r}t        d      |d}~ww xY w)au  Chamfer

        Chamfers the specified edges of this solid.

        Args:
            length (float): length > 0, the length (length) of the chamfer
            length2 (Optional[float]): length2 > 0, optional parameter for asymmetrical
                chamfer. Should be `None` if not required.
            edge_list (Iterable[Edge]): a list of Edge objects, which must belong to
                this solid
            face (Face, optional): identifies the side where length is measured. The edge(s)
                must be part of the face

        Returns:
            Solid | Part:  Chamfered solid or 3D composite
        c              3  H   K   | ]  }|j                         vs|  y wr|   )edges)r}   edgefaces     re   r   z"Mixin3D.chamfer.<locals>.<genexpr>   s     JDTZZ\1I4Js   ""z#Some edges are not part of the facez8Failed creating a chamfer, try a smaller length value(s)N)listanyr   r   r4   r+   MapShapesAndAncestors_sri   rk   rm   r   FindFromKeyFirstAddr-   rT   r   rL   is_validr(   r*   )rd   lengthlength2	edge_listr   enative_edgesedge_face_mapchamfer_builder	distance1	distance2native_edge	topo_face	new_shapeerrs       `          re   chamferzMixin3D.chamfer   sW   . O	JIJJ !FGG+45a		55 BC&&LL".."..-	

 4DLLAIIII' 	K LL	)55kBHHJ	9k6;;y3I		,,_-B-B-DEI%%&& & K 6@  !12 	J	s   E 1E E%E  E%c           	        t        |d   t              r+t        |      }|D 	cg c]  }	t        |	d   |	dd        }
}	n|}
| j                  }|
D ]  }t        ||j                  |r|j                  n	t               |t        z  |d      }||j                  |j                         n&|s||j                          n|j                  |       |j                         } | j                  |      S c c}	w )a~  dprism

        Make a prismatic feature (additive or subtractive)

        Args:
            basis (Optional[Face]): face to perform the operation on
            bounds (list[Union[Face,Wire]]): list of profiles
            depth (float, optional): depth of the cut or extrusion. Defaults to None.
            taper (float, optional): in degrees. Defaults to 0.
            up_to_face (Face, optional): a face to extrude until. Defaults to None.
            thru_all (bool, optional): cut thru_all. Defaults to True.
            additive (bool, optional): Defaults to True.

        Returns:
            Solid: prismatic feature
        r   rF   NF)r   rI   rW   rT   r   r   r/   r=   PerformPerformThruAllrL   	__class__)rd   basisboundsdepthtaper
up_to_facethru_alladditivesorted_profilespfacesr   r   feats                 re   dprismzMixin3D.dprism%  s    4 fQi&7?O0?@1T!A$!"&@E@E-1\\ 	!D&!&KMD %Z//0U]##%U#JJLE#	!& ~~e$$1 As   C0c                R   |D cg c]  }|j                    }}t        | j                         }|D ]  }|j                  ||        	 | j                  |j	                               }|j
                  st        	 |S c c}w # t        t        f$ r}t        d| d      |d}~ww xY w)a=  Fillet

        Fillets the specified edges of this solid.

        Args:
            radius (float): float > 0, the radius of the fillet
            edge_list (Iterable[Edge]): a list of Edge objects, which must belong to this solid

        Returns:
            Solid | Part: Filleted solid or 3D composite
        z(Failed creating a fillet with radius of zQ, try a smaller value or use max_fillet() to find the largest valid fillet radiusN)	r   r   r   r   rL   r   r(   r*   r   )	rd   radiusr   r   r   fillet_builderr   r   r   s	            re   filletzMixin3D.fillet[  s     ,55a		551$,,?' 	4Kv{3	4	,,^-A-A-CDI%%&& & # 6  !12 	:6( CO P 	s   A=	1B B&B!!B&g-C6?c           	     v   |rt        |      ng }|t        j                  k(  rt        d      t        j                  t
        j                  t        j                  t
        j                  i}t               }|D ]  }|j                  |j                          t               }|j                  | j                  |||d||          |j                          |r+| j                  j!                  |j#                               }	|	S | j                  j!                  |j#                               j%                         d   j                  }
| j%                         d   j                  }|dkD  rt'        |
|      }nt'        ||
      }| j                  j!                  |j#                               j)                         }	|	S )an  Hollow

        Return the outer shelled solid of self.

        Args:
            faces (Optional[Iterable[Face]]): faces to be removed,
            which must be part of the solid. Can be an empty list.
            thickness (float): shell thickness - positive shells outwards, negative
                shells inwards.
            tolerance (float, optional): modelling tolerance of the method. Defaults to 0.0001.
            kind (Kind, optional): intersection type. Defaults to Kind.ARC.

        Raises:
            ValueError: Kind.TANGENT not supported

        Returns:
            Solid: A hollow solid.
        Kind.TANGENT not supportedT)IntersectionJoinr   )r   r:   TANGENTr   ARCr!   GeomAbs_ArcINTERSECTIONr    r5   Appendr   r   MakeThickSolidByJoinBuildr   r
   rL   shellsr   fix)rd   r   	thickness	tolerancekind	kind_dictocc_faces_listr   shell_builderreturn_valueshell1shell2sols                re   hollowzMixin3D.hollowz  s   2  %U"4<<9:: HH&22/DD
	
 ./ 	0D!!$,,/	0 56**LL4 	+ 	
 	>>..}/B/B/DEL  ^^(()<)<)>?FFHKSSF[[]1%--F 1}.vv>.vv>  >>..syy{;??ALrg   c                2   t        |t              rt        |      }n]t        |t              rt        |j                        }n7t        |t
              rt        |      }nt        |t              rt        |      }dfd}t               }t        |t              re|j                  rY| j                  d      }|j                  |j                  |j                         |j                         z
  j                  z         }t        |t         t        t"        t        t$        f      r=| j'                  | f|ft)                     }|j+                  |j-                                ndt        |t              r-| j/                  t        |            r9|j1                  |       n'|j3                  | d      }|r|j+                  |       |rKt        | t               r;|j+                  | j5                  |              |t        t7        |                  }|r|S dS )u   Single-object intersection for Solid.

        Returns same-dimension overlap or crossing geometry:
        - Solid + Solid → Solid (volume overlap)
        - Solid + Face → Face (portion in/on solid)
        - Solid + Edge → Edge (portion through solid)

        Args:
            other: Shape or geometry object to intersect with
            tolerance: tolerance for intersection detection
            include_touched: if True, include boundary contacts
                (shapes touching the solid's surface without penetrating)
        c                   | D cg c]  }t        |t              s| c}| D cg c]  }t        |t              s| c}| D cg c]  }t        |t              s| c}t	        fd| D              S c c}w c c}w c c}w )z=Remove vertices/edges that lie on higher-dimensional results.c              3    K   | ]z  t        t              r?t        fd D              sSt        fdD              s>t        fdD              s)t        t              rt        fdD              s | yw)c              3  F   K   | ]  }|j                        k    y wr|   distance_to)r}   r   rr   s     re   r   zQMixin3D._intersect.<locals>.filter_redundant_touches.<locals>.<genexpr>.<genexpr>  s     IaAMM!,	9I   !c              3  F   K   | ]  }|j                        k    y wr|   r   r}   fr   r   s     re   r   zQMixin3D._intersect.<locals>.filter_redundant_touches.<locals>.<genexpr>.<genexpr>  s     Lq}}Q/9<Lr   c              3  p   K   | ]-  }|j                         D ]  }|j                        k    / y wr|   )r   r   )r}   r~   sfr   r   s      re   r   zQMixin3D._intersect.<locals>.filter_redundant_touches.<locals>.<genexpr>.<genexpr>  sB       !&'ggi !# NN1-::   36c              3  b   K   | ]&  }|j                  j                               k   ( y wr|   )r   r   r   s     re   r   zQMixin3D._intersect.<locals>.filter_redundant_touches.<locals>.<genexpr>.<genexpr>  s%     RqAMM!((*5BRs   ,/N)r   r[   r   rG   )r}   r   r   r   r   r   s    @re   r   zGMixin3D._intersect.<locals>.filter_redundant_touches.<locals>.<genexpr>  sn      q&)I5IILeLL %+  q$'RERR! s   B B)r   rG   rT   rp   rM   )itemsr   r   r   r   r   s     @@@re   filter_redundant_touchesz4Mixin3D._intersect.<locals>.filter_redundant_touches  ss     %=1At)<Q=E %=1At)<Q=E!&?A*Q*>a?F    >=?s!   A?A?B BB	!B	Foptimalinclude_touchedN)r   rM   returnrM   )r   rD   r[   rA   positionr>   rG   rC   rT   rM   is_infiniter   trim_infinitediagonalr   r   rp   rV   rI   _bool_op_listr   extendexpand	is_insideappend
_intersecttouchset)	rd   otherr   r   r   resultsbboxintersectionr   s	     `      re   r   zMixin3D._intersect  s   ( eV$5MEx(5>>*Et$KEu%KE	4 '[ eT"u'8'8$$U$3D''$++-!? G GGE
 eeT5$=>--tgxASAUVLNN<..01v&~~fUmY7u%
 %%dIu%MFv& z$6NN4::eY78.yW/FGG!w+t+rg   c                    t        | j                        }|j                  t        t	        |       |       |j                         t        j                  k(  xs |j                         S )a  Returns whether or not the point is inside a solid or compound
        object within the specified tolerance.

        Args:
          point: tuple or Vector representing 3D point to be tested
          tolerance: tolerance for inside determination, default=1.0e-6
          point: VectorLike:
          tolerance: float:  (Default value = 1.0e-6)

        Returns:
          bool indicating whether or not point is within solid

        )	r   r   r   r#   rD   Stateri   	TopAbs_IN	IsOnAFace)rd   pointr   solid_classifiers       re   r   zMixin3D.is_inside  sS     7t||D  !7C%%'2<<7W;K;U;U;WWrg   c                     d fd j                   st        d      |D cg c]  }|j                   c} dd j                         j                  z  d      }|S c c}w )a5  Find Maximum Fillet Size

        Find the largest fillet radius for the given Shape and edges with a
        recursive binary search.

        Example:

              max_fillet_radius = my_shape.max_fillet(shape_edges)
              max_fillet_radius = my_shape.max_fillet(shape_edges, tolerance=0.5, max_iterations=8)


        Args:
            edge_list (Iterable[Edge]): a sequence of Edge objects, which must belong to this solid
            tolerance (float, optional): maximum error from actual value. Defaults to 0.1.
            max_iterations (int, optional): maximum number of recursive iterations. Defaults to 10.

        Raises:
            RuntimeError: failed to find the max value
            ValueError: the provided Shape is invalid

        Returns:
            float: maximum fillet radius
        c                |   | |z   dz  }|	k(  rt        d d	       t        j                        }
D ]  }|j                  ||        	 j	                  |j                               }|j                  st        	 || z
  k  r|}|S  |||dz         }|S # t        t        f$ r  | ||dz         cY S w xY w)N   z$Failed to find the max value within z in rF   )	RuntimeErrorr   r   r   r   rL   r   r(   r*   )
window_min
window_maxcurrent_iteration
window_midr   r   r   r   _Mixin3D__max_filletmax_iterationsr   rd   r   s           re   __max_filletz(Mixin3D.max_fillet.<locals>.__max_filletE  s   $z1Q6J N2":9+T.IYZ  6dllCN+ <"":{;<S 001E1E1GH	 ))** * J&)3)
    ,
,=,A    %o6 S#J
<MPQ<QRRSs   1B B;:B;zInvalid Shapeg        r  r   )r	  floatr
  r  r  int)r   r   r   r   r   )rd   r   r   r  r   
max_radiusr  r   s   ` ``  @@re   
max_filletzMixin3D.max_fillet'  se    <	  	 @ }}_--+45a		5 "#q4+<+<+>+G+G'GK
 6s   A(c           
        |rt        |      ng }|t        j                  k(  rt        d      t        j                  t
        j                  t        j                  t
        j                  t        j                  t
        j                  i}t               }|D ]  }|j                  |j                          t               }|j                  | j                  |||dd||          |j                          	 |j!                         }	| j(                  j+                  |	      }|j                  J |j,                  dk  r|j                  j/                          |S # t"        t$        f$ r}
t'        d      |
d}
~
ww xY w)aQ  Shell

        Make an offset solid of self.

        Args:
            openings (Optional[Iterable[Face]]): faces to be removed,
                which must be part of the solid. Can be an empty list.
            thickness (float): offset amount - positive offset outwards, negative inwards
            tolerance (float, optional): modelling tolerance of the method. Defaults to 0.0001.
            kind (Kind, optional): intersection type. Defaults to Kind.ARC.

        Raises:
            ValueError: Kind.TANGENT not supported

        Returns:
            Solid: A shelled solid.
        r   T)r   RemoveIntEdgesr   z8offset Error, an alternative kind may resolve this errorNr   )r   r:   r   r   r   r!   r   r   r    GeomAbs_Tangentr5   r   r   r   r   r   rL   r*   r(   r  r   r
   volumeReverse)rd   openingsr   r   r   r   r   r   offset_builderoffset_occt_solidr   offset_solids               re   	offset_3dzMixin3D.offset_3du  sg   0 &.4>24<<9:: HH&22/DDLL*::
	 ./ 	0D!!$,,/	0 67++LL4 	, 	
 		 . 4 4 6 ~~**+<=##/// "  ((*  !12 	J	s   6E E:)E55E:c                4    t        j                  | ||||      S )a  project_to_viewport

        Project a shape onto a viewport returning visible and hidden Edges.

        Args:
            viewport_origin (VectorLike): location of viewport
            viewport_up (VectorLike, optional): direction of the viewport y axis.
                Defaults to (0, 0, 1).
            look_at (VectorLike, optional): point to look at.
                Defaults to None (center of shape).
            focus (float, optional): the focal length for perspective projection
                Defaults to None (orthographic projection)

        Returns:
            tuple[ShapeList[Edge],ShapeList[Edge]]: visible & hidden Edges
        )rH   project_to_viewport)rd   viewport_originviewport_uplook_atfocuss        re   r  zMixin3D.project_to_viewport  s"    . **/;
 	
rg   )r   z
int | None)rr   r0   r   r6   )rr   rL   rx   rE   r   z&Edge | Face | Shell | Solid | Compound)r   r0   r   Solid | Part)r   r7   r   rD   r|   )
r   r  r   float | Noner   Iterable[Edge]r   Face | Noner   r$  )Nr   NTT)r   r'  r   zlist[Face | Wire]r   r%  r   r  r   r'  r   boolr   r(  r   rp   )r   r  r   r&  r   r$  )
r   Iterable[Face] | Noner   r  r   r  r   r:   r   rp   )ư>F)r   z(Shape | Vector | Location | Axis | Planer   r  r   r(  r   ShapeList | None)r*  )r  rE   r   r  r   r(  )g?
   )r   r&  r  r  r   r  )
r  r)  r   r  r   r  r   r:   r   rp   ))r   r   rF   NN)
r   rE   r!  rE   r"  VectorLike | Noner#  r%  r   z'tuple[ShapeList[Edge], ShapeList[Edge]])__name__
__module____qualname____doc__rU   find_intersection_pointspropertyrf   classmethodr
   ry   staticmethodr   r7   r   r   r   r   r   r:   r   r   r   r   r  r  r  rb   rg   re   r_   r_      sq   7&??   : :" $.	/  + +" ,4== @ !AA A "	A
 A 
AN #"&4%4% "4% 	4%
 4%  4% 4% 4% 
4%lF "XXA$A A 	A
 A 
AL   %	U,7U, U, 	U,
 
U,nX,  	L!L 	L
 
Ld "XX@'@ @ 	@
 @ 
@J #,%)"
#
  
 #	

 
 
1
rg   r_   c                      e Zd ZdZdZ	 	 	 	 	 	 d 	 	 	 	 	 	 	 	 	 	 	 d! fdZed"d       Z	 	 d#	 	 	 	 	 	 	 d$dZe	d%d       Z
e		 	 	 	 	 	 	 	 d&d       Ze	d'd	       Ze		 d(	 	 	 	 	 	 	 	 	 	 	 d)d
       Ze		 d*	 	 	 	 	 	 	 	 	 d+d       Ze	ej                   f	 	 	 	 	 	 	 	 	 d,d       Ze	d-d       Ze	ej(                  f	 	 	 	 	 	 	 	 	 d.d       Ze	ej(                  df	 	 	 	 	 	 	 	 	 	 	 d/d       Ze	ej(                  df	 	 	 	 	 	 	 	 	 d0d       Ze	d1d2d       Ze	ej(                  dddf	 	 	 	 	 	 	 	 	 	 	 d3d       Ze	ej(                  dddf	 	 	 	 	 	 	 	 	 	 	 	 	 d4d       Ze	ej(                  f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5d       Ze		 d(	 	 	 	 	 	 	 	 	 d6d       Ze	ddddej<                  f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d7d       Ze		 	 	 d8	 	 	 	 	 	 	 	 	 	 	 d9d       Z e		 d(	 	 	 	 	 	 	 d:d       Z!d;dZ" xZ#S )<rp   a  A Solid in build123d represents a three-dimensional solid geometry
    in a topological structure. A solid is a closed and bounded volume, enclosing
    a region in 3D space. It comprises faces, edges, and vertices connected in a
    well-defined manner. Solid modeling operations, such as Boolean
    operations (union, intersection, and difference), are often performed on
    Solid objects to create or modify complex geometries.g      @Nc                    t        |t              rt        j                  |      }t        |   ||||       |dn|| _        |i | _        y|| _        y)a  Build a solid from an OCCT TopoDS_Shape/TopoDS_Solid

        Args:
            obj (TopoDS_Shape | Shell, optional): OCCT Solid or Shell.
            label (str, optional): Defaults to ''.
            color (Color, optional): Defaults to None.
            material (str, optional): tag for external tools. Defaults to ''.
            joints (dict[str, Joint], optional): names joints. Defaults to None.
            parent (Compound, optional): assembly parent. Defaults to None.
        )rr   labelcolorparentN )r   rV   rp   _make_solidsuper__init__materialjoints)rd   rr   r8  r9  r?  r@  r:  r   s          re   r>  zSolid.__init__  s^    ( c5!##C(C 	 	
 '.H"Nbrg   c                ,    t        j                  |       S )z!volume - the volume of this Solid)rL   compute_massrc   s    re   r  zSolid.volume  s     !!$''rg   c                    !"#$ dfd!dfd#d fdd!fd"d#fd$dfdddddfd d fd	}t               }t        |t        t        t        f      rg }t        |t              rI|!t         j                  |d
      xs g       }|D cg c]  }|j                         D ]  }|  }}} j                         D cg c]  }||j                  d
      f }	}|j                         D cg c]  }||j                  d
      f }
}t               }|	D ]  \  }}|
D ]  \  }}|j                  |      s|j                  |      D ]'  } |||      r $||      r|j                  |       ) |j                  |      xs g D ]'  } |||      r ||      r|j                  |       )   |D cg c]  }t        |t              s| c}|D cg c]  }t        |t              s| c}d"$fd}|D ]  } ||      s|j                  |        nt        |t        t        f      r j                         D cg c]  }||j                  d
      f }	}|j                  d
      }|j                         D ](  }|	D ]!  \  }} #||      s|j                  |        ( * |	D ]  \  }}|j                  |      st        |j                   |j                         }|j#                         r|j%                         kD  r^t'        d|j)                         dz         D ]  }|j+                  |      }|j-                  |      }|j/                  |      kD  r:t1        |j3                         |j5                         |j7                               } |||      r{|j                  |         nct        |t0              r2 j                         D ]  } #||      s|j                  |        n# n!|j9                  |j                                t        t;        |            S c c}}w c c}w c c}w c c}w c c}w c c}w )u  Find where this Solid's boundary contacts another shape.

        Returns geometry where boundaries contact without interior overlap:
        - Solid + Solid → Face + Edge + Vertex (all boundary contacts)
        - Solid + Face/Shell → Face + Edge + Vertex (boundary contacts)
        - Solid + Edge/Wire → Vertex (edge endpoints on solid boundary)
        - Solid + Vertex → Vertex if on boundary
        - Solid + Compound → distributes over compound elements

        Args:
            other: Shape to check boundary contacts with
            tolerance: tolerance for contact detection
            found_solids: pre-found intersection solids to filter against

        Returns:
            ShapeList of boundary contact geometry (empty if no contact)
        c                ,    | j                  |      k  S r|   r   )vr   r   s     re   vertex_on_edgez#Solid.touch.<locals>.vertex_on_edge#      ==#y00rg   c                ,    | j                  |      k  S r|   r   )rE  r   r   s     re   vertex_on_facez#Solid.touch.<locals>.vertex_on_face&  rG  rg   c                P    t        j                  | f|ft                           S r|   )r(  r   r   )r   r   rd   s     re   edge_on_facez!Solid.touch.<locals>.edge_on_face)  s%    **A4!7I7KLMMrg   c                0     t         fd|D              S )Nc              3  0   K   | ]  } |        y wr|   rb   )r}   r   rE  rF  s     re   r   z7Solid.touch.<locals>.vertex_on_edges.<locals>.<genexpr>/       ;~a+;   r   )rE  r   rF  s   ` re   vertex_on_edgesz$Solid.touch.<locals>.vertex_on_edges.      ;U;;;rg   c                0     t         fd|D              S )Nc              3  0   K   | ]  } |        y wr|   rb   )r}   r   rE  rI  s     re   r   z7Solid.touch.<locals>.vertex_on_faces.<locals>.<genexpr>2  rN  rO  rP  )rE  r   rI  s   ` re   vertex_on_facesz$Solid.touch.<locals>.vertex_on_faces1  rR  rg   c                0     t         fd|D              S )Nc              3  0   K   | ]  } |        y wr|   rb   )r}   r   r   rK  s     re   r   z5Solid.touch.<locals>.edge_on_faces.<locals>.<genexpr>5  s     9a|Aq)9rO  rP  )r   r   rK  s   ` re   edge_on_facesz"Solid.touch.<locals>.edge_on_faces4  s    95999rg   c                    | j                         \  }}}}||||z
  z  z   }||||z
  z  z   }t               }	t               }
t        | j                        j                  |||	|
       t        |	      t        |
      fS )a  Get both position and normal at UV coordinates.
            Args
                u (float): the horizontal coordinate in the parameter space of the Face,
                    between 0.0 and 1.0
                v (float): the vertical coordinate in the parameter space of the Face,
                    between 0.0 and 1.0
            Returns:
                tuple[Vector, Vector]: [point on Face, normal at point]
            )
_uv_boundsr#   r$   r   r   NormalrD   )r   urE  u0u1v0v1u_valv_valgp_pntgp_norms              re   face_point_normalz&Solid.touch.<locals>.face_point_normal7  sz     "__.NBBb2g&Eb2g&EXFhG4<<(//ufgN&>6'?22rg   c                l   | j                  d      }|j                  d      }|j                  |      syt        |      D ]n  }||dz
  z  }t        |      D ]V  }||dz
  z  } | ||      \  }	}
 |||      \  }}|	|z
  j                  kD  st	        |
j                  |            dk  sU  y p y)aZ  Check if two faces are geometrically equal.

            Face == uses topological equality (same OCC object), but we need
            geometric equality. For performance reasons apply a heuristic
            approach: Compare a grid of UV sample points, checking both position and
            normal direction match within tolerance.
            Fr   rF   gGz?T)r   overlapsranger   absdot)f1f2	grid_sizebb1bb2ir\  jrE  pos1norm1pos2norm2re  r   s                re   faces_equalz Solid.touch.<locals>.faces_equalI  s     //%/0C//%/0C<<Y/ 9% %Q'y) %AY]+A"3B1"=KD%"3B1"=KD%t++i73uyy?O;PSW;W$%% rg   c                     t         t              rt         fd|D              S t         t              rt         fd|D              S t         t              rt         fd|D              S y)Nc              3  p   K   | ]-  }t        |t              xr t              t        |      k(   / y wr|   )r   r[   rD   )r}   rE  r   s     re   r   z4Solid.touch.<locals>.is_duplicate.<locals>.<genexpr>d  s5       q&)HfUmvay.HHr   c              3  f   K   | ](  }t        |t              xr j                  |       * y wr|   )r   rG   
geom_equal)r}   r   r   r   s     re   r   z4Solid.touch.<locals>.is_duplicate.<locals>.<genexpr>i  s5       q$'JE,<,<Q	,JJs   .1c              3  T   K   | ]  }t        |t              xr	  |       ! y wr|   )r   rT   )r}   r   rv  r   s     re   r   z4Solid.touch.<locals>.is_duplicate.<locals>.<genexpr>o  s,      FGJq$'AKq,AAs   %(F)r   r[   r   rG   rT   )r   existingrv  r   s   ` re   is_duplicatez!Solid.touch.<locals>.is_duplicateb  sx    %( %   %& %   %& KS   rg   Fr   r   )r   c                    t        | t              ryt        | t              r
 |        S t        | t              r |        xr
  |        S y)zDReturn True if shape isn't contained by a higher-dimensional result.TF)r   rT   rG   r[   )r   	all_edges	all_facesrX  rQ  rU  s    re   is_maximal_touch_resultz,Solid.touch.<locals>.is_maximal_touch_result  sc    eT*eT*,UI>>>eV,.ui@@ yJ F  rg   rF   )rE  r[   r   rG   r   r(  )rE  r[   r   rT   r   r(  )r   rG   r   rT   r   r(  )rE  r[   r   r&  r   r(  )rE  r[   r   Iterable[Face]r   r(  )r   rG   r   r  r   r(  )r   rT   r\  r  rE  r  r   ztuple[Vector, Vector])   )rk  rT   rl  rT   rm  r  r   r(  )r   rL   r|  zIterable[Shape]r   r(  )r   rL   r   r(  )rM   r   rp   rT   rV   r   r   r   rg  r   r   	intersectrG   rI   verticesr   r   IsDoneValuerh  
NbSolutionPointOnShape1PointOnShape2Distancer[   XYZr   r   )%rd   r   r   found_solidsr}  r   intersect_facesr~   r   
self_facesother_facesraw_resultsr   sf_bbofof_bbr   r   r  other_bbov_extremarp  pnt1pnt2
new_vertexr  r  rK  rX  re  rv  rF  rQ  rI  rU  s%   ` `                        @@@@@@@@@@re   r   zSolid.touch	  s+   4	1	1	N
	<	<	:	3$	2	$ '[eeT512 !O%''#,y%PVTV$L /;"NAGGI"Nq1"N1"N"N GKjjlS1annUn;<SJSGL{{}U!Aq~~e~<=UKU &/[K' 2	E!, 2IB >>%;   XXbIX> 2+A{;OE (..q1	2  \\"	\BHb 2+A{;ME (..q1	222* %0Gq:a3FGI$/Gq:a3FGI
 
 ! &*1-NN1%& d|, GKjjlS1annUn;<SJS))%)8Hnn& ' EB%b"-r* ( 3	E~~h	:4RZZO~~'7==?Y+Fq'"4"4"6":; 3A"003D"003D}}T*Y6 !'$&&(DFFH!EJ'
G<z233 v&jjl !%,NN5) NN5;;tY78 W&&s #O TU4 HG* Ts0   $QQ Q%Q*,Q*7Q/Q/*Q4c                H    t               j                  |j                        S )z,Create a Solid object from the surface shell)r'   SolidFromShellr   )rq   shells     re   r<  zSolid._make_solid  s     ..u}}==rg   c                v   d}t        |t              rkt               }|j                  |j	                         j                                |j                  |j                                |j                  |       d}|S t        |t        t        f      r%|j                  t        |      j                  d       |S )NFT)r   rD   r"   SetLocationstart_pointto_pntSetDirectionto_dirSetModerI   rG   r   )rq   builderpathbinormalrotatecoordinate_systems         re   _set_sweep_modezSolid._set_sweep_mode  s     h' &))$*:*:*<*C*C*EF**8??+<=OO-.F  4,/OODN22D9rg   c                f    t        t        j                   t        |j                  |                  S )a/  extrude

        Extrude a Face into a Solid.

        Args:
            direction (VectorLike): direction and magnitude of extrusion

        Raises:
            ValueError: Unsupported class
            RuntimeError: Generated invalid result

        Returns:
            Edge: extruded shape
        )rp   r-   rX   r   rw   s      re   ry   zSolid.extrude  s$      V\\"7Y"OPQQrg   c           	     v   |r|ng }t        |      }t        |      }	 	 	 	 	 	 	 	 dd}t        |t              r!|j                         }|j	                         }n|}t        j                  ||j                  |            }t        j                  |g      }	|	d   j                  }
d|z  |j                  z  }t        t        j                  ||j                  d||      g      j                  } ||j                  |
|      }|D cg c]  } ||j                  |
|       }}t        |      }t        ||      j                         }	 t!        j"                  |      }t#        |      S c c}w # t$        $ r? t!        j"                  t'        t!        j(                  |      d            }Y t#        |      S w xY w)an  Extrude with Rotation

        Creates a 'twisted prism' by extruding, while simultaneously rotating around the
        extrusion vector.

        Args:
            section (Union[Face,Wire]): cross section
            vec_center (VectorLike): the center point about which to rotate
            vec_normal (VectorLike): a vector along which to extrude the wires
            angle (float): the angle to rotate through while extruding
            inner_wires (list[Wire], optional): holes - only used if section is of type Wire.
                Defaults to None.

        Returns:
            Solid: extruded object
        c                    t        |      }|j                  |d       |j                  |        |j                          |j	                          |j                         S )zHelper functionF)r   r  r   r   	MakeSolidrL   )wirespine	aux_spineextrude_builders       re   extrude_aux_spinez=Solid.extrude_linear_with_rotation.<locals>.extrude_aux_spine.  sS     :%@O##Iu5%!!#%%'"((**rg   r   g     v@rF   )r   normalT)r  r3   r  r3   r  r3   r   r0   )rD   r   rT   
outer_wireinner_wiresrG   	make_lineaddrI   combiner   r   
make_helixrS   r   rL   r-   rp   r)   rR   r\   )rq   sectionr   r  angler  r  r  straight_spine_estraight_spine_wiresstraight_spine_wpitchaux_spine_wouter_solidwinner_solids
inner_comp
differencer   s                      re   extrude_linear_with_rotationz"Solid.extrude_linear_with_rotation  s   F &1kb		+		+&1		+>I		+		+ gt$ ++-J!--/K J  >>&&**V2DE#||-=,>?/2:: -__UFMM1VFST

' 	
 ( 0+
 !
 aii)9;G
 
 7|D
 %[*=CCE
	\\*-F V}'
 % 	\\&vz'BDIF V}	s   E+E0 0;F87F8Tc           	     `   t        |      }|j                         |j                         k(  rt        |      j                  j
                  dkD  r|dkD  r}|j                         smt        |j                  |j                  t        t        |            z  t        |            }t        t        j                  |j                                     }|S |j                   t        t        |            z  }|j!                         }t        |      j#                  |      }	|	j%                  |t&        j(                        }
t        |      j+                  |
      }|j-                  t/        |             |j!                         g|j                         z   }g }t1        |      D ]  \  }}|dkD  r|rdnd}t        |      j#                  |      }|j%                  ||z  t&        j(                        }t        |      j+                  |      }|j-                  t/        |             |j3                  |        t5        ||      D cg c]  \  }}t        j7                  ||g       }}}t9        |      dkD  r+ |d   j:                  |dd  }t=        |t              sJ |}|S |d   }|S c c}}w )a  Extrude a cross section with a taper

        Extrude a cross section into a prismatic solid in the provided direction.

        Note that two difference algorithms are used. If direction aligns with
        the profile normal (which must be positive), the taper is positive and the profile
        contains no holes the OCP LocOpe_DPrism algorithm is used as it generates the most
        accurate results. Otherwise, a loft is created between the profile and the profile
        with a 2D offset set at the appropriate direction.

        Args:
            section (Face]): cross section
            normal (VectorLike): a vector along which to extrude the wires. The length
                of the vector controls the length of the extrusion.
            taper (float): taper angle in degrees.
            flip_inner (bool, optional): outer and inner geometry have opposite tapers to
                allow for part extraction when injection molding.

        Returns:
            Solid: extruded cross section
        r   )r   rF   N)rD   
normalized	normal_atrC   z_dirr  r  r&   r   r   r   r   rp   r-   rL   r   r  to_local_coords	offset_2dr:   r   from_local_coordsmoverA   	enumerater   zip	make_loftlencutr   )rq   profilerx   r   
flip_innerprism_builder	new_solid
offset_amtouterlocal_outerlocal_taper_outertaper_outerprofile_wirestaper_wiresrp  r  fliplocallocal_taper
taper_wirer   tr   complex_solids                           re   extrude_taperzSolid.extrude_tapere  ss   4 9%	   "g&7&7&99g$$&&*	''))  3wu~#66M
 fll=+>+>+@ABID ? $***S-@@J&&(E %g > >u EK + 5 5!2!2 !6 !  .::;LMKXi01$//12W5H5H5JJMK$]3 /4Uzrq#Gn<<TB#oodZ.?dFWFWoX#(>#C#CK#P
 34"":./ 58{4S,0AqA'F  6{Q -q	vabz :!-777)	  #1I	s   !J*c                   t        |      }|t        j                  t        j                  fv r8|dz  }|t        j                  k(  rt        j                  nt        j
                  }t        |g      }t        j                  ||z        }t        |j                  |j                        }|j                          |j                         }t        |t        j                        }	|	j!                         st#        d      |j%                         }
g }t        |j                  t        j                        }|j!                         rt'        j(                  |j+                               }|
j-                  |      }|j/                         sUt'        j(                  |j1                               }|j3                          |j5                  |       |j/                         sU|j7                          |j!                         rt9        |      }t;        |      }t=               }|D ]n  }t?        |t@              r|j5                  t)        |             .t?        |tB              r|j5                  tE        |             YtG        dtI        |              |jK                  fd      }||t        j                  t        j                  fv rdnd   }|t        j                  t        j                  fv rtL        jN                  ntL        jP                  }|jS                  ||      }|tG        d      t?        |t              r|S t=        |      jK                  tU        jW                         |            d   S )u  extrude_until

        Extrude `profile` in the provided `direction` until it encounters a
        bounding surface on the `target`. The termination surface is chosen
        according to the `until` option:

            * ``Until.NEXT`` — Extrude forward until the first intersecting surface.
            * ``Until.LAST`` — Extrude forward through all intersections, stopping at
            the farthest surface.
            * ``Until.PREVIOUS`` — Reverse the extrusion direction and stop at the
            first intersecting surface behind the profile.
            * ``Until.FIRST`` — Reverse the direction and stop at the farthest
            surface behind the profile.

        When ``Until.PREVIOUS`` or ``Until.FIRST`` are used, the extrusion
        direction is automatically inverted before execution.

        Note:
            The bounding surface on the target must be large enough to
            completely cover the extruded profile at the contact region.
            Partial overlaps may yield open or invalid solids.

        Args:
            profile (Face): The face to extrude.
            target (Union[Compound, Solid]): The object that limits the extrusion.
            direction (VectorLike): Extrusion direction.
            until (Until, optional): Surface selection mode controlling which
                intersection to stop at. Defaults to ``Until.NEXT``.

        Raises:
            ValueError: If the provided profile does not intersect the target.

        Returns:
            Solid: The extruded and limited solid.
        r  z2No intersection: extrusion does not contact targetzInvalid sewn shape c                &    | j                        S r|   r   )r~   r  s    re   <lambda>z%Solid.extrude_until.<locals>.<lambda>  s    ammG, rg   r   )keepzExtrusion is None),rD   r<   PREVIOUSFIRSTNEXTLASTrZ   rp   ry   r   r   r   rL   r,   ri   rm   Morer   Historyr-   rT   CurrentModifiedIsEmptyr   RemoveFirstr   NextrN   rP   rM   r   r/   r1   rV   r  typesort_byr9   TOPBOTTOMsplitr>   r   )rq   r  targetrx   untilmax_dimension	extrusionintersect_opr   face_exphistorymodified_target_facesface_explorertarget_facemodified_losmodified_facesewed_shapetop_level_shapesmodified_target_surfacestop_level_shapelimitr  clipped_extrusions    `                     re   extrude_untilzSolid.extrude_until  s   V 9%	U^^U[[11OI"'5>>"9EJJuzzE +GV+<=MM'9}+DE	 *&..):K:KL#))+"<@}}QRR &&( "'G  " ++m&;&;&=>K181A1A+1NL"**, &L,>,>,@ A((*%,,]; #**,     " ((=> 7{C<EK   0 	RO/;7(//_0EFO\:(//o0FG"%8o9N8O#PQQ	R $<#C#C,$
  )5::u~~66AB
 %**enn!==DHH4;; 	
 &OOEO= $233'/$$*+33D9I94UV
 	
rg   c                   t        |t              r>t        j                  |j                   j                  t        |j                              S t        t        |j                   dz              j                  |j                        }t        j                  |j                  j                  |j                  j                  |j                  j                  |      S )z)A box of the same dimensions and locationr  )plane)r   r?   rp   make_boxsizelocaterA   minrC   movedlocationr  r  r  )rq   r   moved_planes      re   from_bounding_boxzSolid.from_bounding_box!  s     dH%>>499-44Xdhh5GHH"8TYYJN#;<BB4==Q~~diikk499;;		;~WWrg   c           
          | t        j                  t        |j                         |||      j	                                     S )a<  make box

        Make a box at the origin of plane extending in positive direction of each axis.

        Args:
            length (float):
            width (float):
            height (float):
            plane (Plane, optional): base plane. Defaults to Plane.XY.

        Returns:
            Solid: Box
        )r-   rp   r   	to_gp_ax2rL   )rq   r   widthheightr  s        re   r  zSolid.make_box)  sA    " LL#OO%	
 %'	
 		
rg   ih  c                     | t        j                  t        |j                         ||||t        z        j                                     S )af  make cone

        Make a cone with given radii and height

        Args:
            base_radius (float):
            top_radius (float):
            height (float):
            plane (Plane): base plane. Defaults to Plane.XY.
            angle (float, optional): arc size. Defaults to 360.

        Returns:
            Solid: Full or partial cone
        )r-   rp   r   r  r=   rL   )rq   base_radius
top_radiusr  r  r  s         re   	make_conezSolid.make_coneE  sH    . LL$OO%GO %'

 
	
rg   c                     | t        j                  t        |j                         |||t        z        j                                     S )av  make cylinder

        Make a cylinder with a given radius and height with the base center on plane origin.

        Args:
            radius (float):
            height (float):
            plane (Plane): base plane. Defaults to Plane.XY.
            angle (float, optional): arc size. Defaults to 360.

        Returns:
            Solid: Full or partial cylinder
        )r-   rp   r   r  r=   rL   )rq   r   r  r  r  s        re   make_cylinderzSolid.make_cylinderh  sE    * LL(OO%GO	
 %'	
 		
rg   Fc           	     N     | t        j                  t        |d|                  S )a  make loft

        Makes a loft from a list of wires and vertices. Vertices can appear only at the
        beginning or end of the list, but cannot appear consecutively within the list
        nor between wires.

        Args:
            objs (list[Vertex, Wire]): wire perimeters or vertices
            ruled (bool, optional): stepped or smooth. Defaults to False (smooth).

        Raises:
            ValueError: Too few wires

        Returns:
            Solid: Lofted object
        T)r-   rp   rY   )rq   objsruleds      re   r  zSolid.make_loft  s!    $ 6<<
4u =>??rg   iZ   c                     | t        j                  t        |j                         ||t        z  |t        z  |t        z        j                                     S )a  Sphere

        Make a full or partial sphere - with a given radius center on the origin or plane.

        Args:
            radius (float):
            plane (Plane): base plane. Defaults to Plane.XY.
            angle1 (float, optional): Defaults to -90.
            angle2 (float, optional): Defaults to 90.
            angle3 (float, optional): Defaults to 360.

        Returns:
            Solid: sphere
        )r-   rp   r   r  r=   rL   )rq   r   r  angle1angle2angle3s         re   make_spherezSolid.make_sphere  sS    . LL&OO%W$W$W$ %'

 
	
rg   r   c                     | t        j                  t        |j                         |||t        z  |t        z  |t        z        j                                     S )a  make torus

        Make a torus with a given radii and angles

        Args:
            major_radius (float):
            minor_radius (float):
            plane (Plane): base plane. Defaults to Plane.XY.
            start_angle (float, optional): start major arc. Defaults to 0.
            end_angle (float, optional): end major arc. Defaults to 360.

        Returns:
            Solid: Full or partial torus
        )r-   rp   r   r  r=   rL   )rq   major_radiusminor_radiusr  start_angle	end_anglemajor_angles          re   
make_toruszSolid.make_torus  sV    0 LL%OO%  ')'') %'	
 	
rg   c	                     | t        j                  t        |j                         |||||||      j                                     S )aO  Make a wedge

        Args:
            delta_x (float):
            delta_y (float):
            delta_z (float):
            min_x (float):
            min_z (float):
            max_x (float):
            max_z (float):
            plane (Plane): base plane. Defaults to Plane.XY.

        Returns:
            Solid: wedge
        )r-   rp   r   r  )	rq   delta_xdelta_ydelta_zmin_xmin_zmax_xmax_zr  s	            re   
make_wedgezSolid.make_wedge  sM    6 LL%OO%	 %'
 	
rg   c                    |r|ng }t        |t              rt        ||      }n|}t        |j                  |j                  |t
        z  d      } | t        j                  |j                                     S )a  Revolve

        Revolve a cross section about the given Axis by the given angle.

        Args:
            section (Union[Face,Wire]): cross section
            angle (float): the angle to revolve through
            axis (Axis): rotation Axis
            inner_wires (list[Wire], optional): holes - only used if section is of type Wire.
                Defaults to [].

        Returns:
            Solid: the revolved cross section
        T)	r   rI   rT   r   r   r=   r-   rp   rL   )rq   r  r  axisr  section_facerevol_builders          re   revolvezSolid.revolve  sk    , &1kbgt$5L"L-  LLGO	
 6<< 3 3 5677rg   c                   t        |t              r!|j                         }|j                         }n|}|r|ng }g }	|g|z   D ]  }
t	        t        |      j                        }d}|rt        j                  |||      }n|j                  |       |j                  t        j                  |          |j                  |
j                  d|       |j                          |r|j                          |	j!                  t"        j%                  |j                                       |	d   |	dd }}|r# |j&                  | }t        |t              sJ |S |S )a8  Sweep

        Sweep the given cross section into a prismatic solid along the provided path

        The is_frenet parameter controls how the profile orientation changes as it
        follows along the sweep path. If is_frenet is False, the orientation of the
        profile is kept consistent from point to point. The resulting shape has the
        minimum possible twisting. Unintuitively, when a profile is swept along a
        helix, this results in the orientation of the profile slowly creeping
        (rotating) as it follows the helix. Setting is_frenet to True prevents this.

        If is_frenet is True the orientation of the profile is based on the local
        curvature and tangency vectors of the path. This keeps the orientation of the
        profile consistent when sweeping along a helix (because the curvature vector of
        a straight helix always points to its axis). However, when path is not a helix,
        the resulting shape can have strange looking twists sometimes. For more
        information, see Frenet Serret formulas
        http://en.wikipedia.org/wiki/Frenet%E2%80%93Serret_formulas.

        Args:
            section (Union[Face, Wire]): cross section to sweep
            path (Union[Wire, Edge]): sweep path
            inner_wires (list[Wire]): holes - only used if section is a wire
            make_solid (bool, optional): return Solid or Shell. Defaults to True.
            is_frenet (bool, optional): Frenet mode. Defaults to False.
            mode (Union[Vector, Wire, Edge, None], optional): additional sweep
                mode parameters. Defaults to None.
            transition (Transition, optional): handling of profile orientation at C1 path
                discontinuities. Defaults to Transition.TRANSFORMED.

        Returns:
            Solid: the swept cross section
        Fr   rF   N)r   rT   r  r  r   rI   r   rp   r  r  SetTransitionModerL   _transModeDictr   r   r  r   r_   r
   r  )rq   r  r  r  
make_solid	is_frenetmode
transitionr  shapesr  r  r  outer_shapeinner_shapeshollow_outer_shapes                   re   sweepzSolid.sweep3  s8   X gt$ ++-J!--/K J)4+"K.0L;. 	9D1$t*2D2DEGF ..wdC	*%%e&:&::&FGKKeV4MMO!!#MM',,w}}78'	9* %+1Ivabz\!0,!?0%888%%rg   c                   t        |      j                  }t        |      }d}d}	|r| j                  |||      }	n|j	                  |       |D ]K  }
t        |
t               r|
j                  n|
j                         j                  }|j                  |||	       M |j                          |r|j                           | t        j                  |j                                     S )ap  Multi section sweep

        Sweep through a sequence of profiles following a path.

        The is_frenet parameter controls how the profile orientation changes as it
        follows along the sweep path. If is_frenet is False, the orientation of the
        profile is kept consistent from point to point. The resulting shape has the
        minimum possible twisting. Unintuitively, when a profile is swept along a
        helix, this results in the orientation of the profile slowly creeping
        (rotating) as it follows the helix. Setting is_frenet to True prevents this.

        If is_frenet is True the orientation of the profile is based on the local
        curvature and tangency vectors of the path. This keeps the orientation of the
        profile consistent when sweeping along a helix (because the curvature vector of
        a straight helix always points to its axis). However, when path is not a helix,
        the resulting shape can have strange looking twists sometimes. For more
        information, see Frenet Serret formulas
        http://en.wikipedia.org/wiki/Frenet%E2%80%93Serret_formulas.

        Args:
            profiles (Iterable[Union[Wire, Face]]): list of profiles
            path (Union[Wire, Edge]): The wire to sweep the face resulting from the wires over
            make_solid (bool, optional): Solid or Shell. Defaults to True.
            is_frenet (bool, optional): Select frenet mode. Defaults to False.
            binormal (Union[Vector, Wire, Edge, None], optional): additional sweep mode parameters.
                Defaults to None.

        Returns:
            Solid: swept object
        F)rI   r   r   r  r  r   r  r   r   r  r-   rp   rL   )rq   profilesr  rG  rH  r  path_as_wirer  	translater  r  s              re   sweep_multizSolid.sweep_multi  s    N Dz))-l;	(($AFOOI& 	9G gt, '')11 
 KKi8	9 	6<<011rg   c                   |}t        |t              r_|]|j                         }|j                  |      j	                         }|j                  t        |      j	                               dk  r| }t               }|j                  |j                  |dt        ddt        dd	       |j                          	 t        t        j                  |j                                     }|S # t         $ r}	t#        d      |	d}	~	ww xY w)a  Thicken Face or Shell

        Create a solid from a potentially non planar face or shell by thickening along
        the normals.

        .. image:: thickenFace.png

        Non-planar faces are thickened both towards and away from the center of the sphere.

        Args:
            depth (float): Amount to thicken face(s), can be positive or negative.
            normal_override (Vector, optional): Face only. The normal_override vector can be
                used to indicate which way is 'up', potentially flipping the face normal
                direction such that many faces with different normals all go in the same
                direction (direction need only be +/- 90 degrees from the face normal).
                Defaults to None.

        Raises:
            RuntimeError: Opencascade internal failures

        Returns:
            Solid: The resulting Solid object
        Nr   gh㈵>TF)OffsetTolModer   	SelfInterr   
Thickeningr  z'Error applying thicken to given surface)r   rT   r   r  r  rj  rD   r   
Initializer   r   r    MakeOffsetShaperp   r-   rL   r*   r  )
rq   surfacer   normal_overrideadjusted_depthsurface_centersurface_normalr  r   r   s
             re   thickenzSolid.thicken  s    > gt$)D$^^-N$..~>IIKN!!&"9"D"D"FG!K"'.0!!OO!  % 	" 	
 	&&(	S6<<(<(<(>?@F   	SHIsR	Ss   9,C' '	D0C<<Dc                   t         j                  t         j                  t         j                  h}|D ]6  }|j                  |vst        d| d|j                  j                   d       t        | j                        }|D ]y  }|j                  |j                  |j                  j                         t        |      |j                  d       |j                         r_t        d||j                                	 |j!                          t#        t%        j"                  |j'                                     }|S # t(        $ r"}t        dd	|j                               |d	}~ww xY w)
a  Apply a draft angle to the given faces of the solid.

        Args:
            faces: Faces to which the draft should be applied.
            neutral_plane: Plane defining the neutral direction and position.
            angle: Draft angle in degrees.

        Returns:
            Solid with the specified draft angles applied.

        Raises:
            RuntimeError: If draft application fails on any face or during build.
        zFace z has unsupported geometry type z<. Only PLANAR, CYLINDRICAL, and CONICAL faces are supported.T)Flagz#Draft could not be added to a face.)r   problematic_shapez&Draft build failed on the given solid.N)r8   PLANECYLINDERCONE	geom_typer   namer   r   r   r  r  r   AddDoneDraftAngleErrorProblematicShaper   rp   r-   rL   r*   )	rd   r   neutral_planer  valid_geom_typesr   draft_angle_builderr   r   s	            re   draftzSolid.draft  se    %NNH,=,=x}}M 	D~~%55 D6!@ATAT@U VQ Q 	 7t||D 	D####**,%% $  '..0%9&9&J&J&L 		%%'6<<(;(A(A(CDEF   	!8"5"F"F"H 		s   ?<D= =	E(E##E()Nr;  Nr;  NN)rr   zTopoDS_Solid | Shell | Noner8  strr9  zColor | Noner?  rr  r@  zdict[str, Joint] | Noner:  zCompound | None)r   r  )r*  N)r   rL   r   r  r  r+  r   zShapeList[Vertex | Edge | Face])r  rV   r   r2   )r  r   r  Wire | Edger  zVector | Wire | Edger   r(  )rr   rT   rx   rE   r   rp   r|   )r  Face | Wirer   rE   r  rE   r  r  r  list[Wire] | Noner   rp   )T)
r  rT   rx   rE   r   r  r  r(  r   rp   )
r  rT   r  zCompound | Solidrx   rE   r   r<   r   rp   )r   zBoundBox | OrientedBoundBoxr   rp   )
r   r  r  r  r  r  r  rC   r   rp   )r!  r  r"  r  r  r  r  rC   r  r  r   rp   )
r   r  r  r  r  rC   r  r  r   rp   )F)r'  zIterable[Vertex | Wire]r(  r(  r   rp   )r   r  r  rC   r+  r  r,  r  r-  r  r   rp   )r0  r  r1  r  r  rC   r2  r  r3  r  r4  r  r   rp   )r7  r  r8  r  r9  r  r:  r  r;  r  r<  r  r=  r  r  rC   r   rp   )
r  rt  r  r  r@  r>   r  ru  r   rp   )r  rt  r  rs  r  ru  rG  r(  rH  r(  rI  Vector | Wire | Edge | NonerJ  r;   r   rp   )TFN)rQ  zIterable[Wire | Face]r  rs  rG  r(  rH  r(  r  rv  r   rp   )r]  zFace | Shellr   r  r^  r-  r   rp   )r   r  rn  rC   r  r  r   rp   )$r.  r/  r0  r1  orderr>  r3  r  r   r4  r<  r  ry   r  r  r<   r  r  r  rC   XYr  r#  r%  r  r.  r5  r>  rC  r;   TRANSFORMEDrO  rT  rb  rq  __classcell__r   s   @re   rp   rp     s   = E
 ,0"*."&7(7 7 	7
 7 (7  7F ( (  )-	O'O' O' '	O'
 
)O'f > > ,  '	
 
 & R R"  *.[[ [ 	[
 [ '[ 
[ [z TXHH'1H:?HMQH	H HT  zzn
n
 !n
 	n

 n
 
n
 n
` X X HM

#(
27
@E
	
 
6  xx 
 
  
 	 

  
  
 
 
  
D 
 xx

 
 	

 
 

 
> @ @&  xx 
 
  
 	 

  
  
 
 
  
D 
 xx "
"
 "
 	"

 "
 "
 "
 
"
 "
H  xx'
'
 '
 	'

 '
 '
 '
 '
 '
 
'
 '
R  *."8"8 "8 	"8
 '"8 
"8 "8H 
 *.,0!+!7!7OO O '	O
 O O *O O 
O Ob 
  04?2'?2 ?2 	?2
 ?2 .?2 
?2 ?2B 
 .2	99 9 +	9
 
9 9v0rg   rp   c                  $     e Zd ZdZd fd	Z xZS )rl  zSolid.draft custom exceptionc                @    t         |   |       || _        || _        y r|   )r=  r>  r   re  )rd   messager   re  r   s       re   r>  zDraftAngleError.__init__9  s    !	!2rg   )NN)r.  r/  r0  r1  r>  rz  r{  s   @re   rl  rl  6  s    &3 3rg   rl  )r1  
__future__r   collections.abcr   mathr   r   r   typingr   r	   r
   
OCP.TopAbsTopAbsri   OCP.BRepAlgoAPIr   r   OCP.BRepBuilderAPIr   OCP.BRepClass3dr   OCP.BRepExtremar   OCP.BRepFeatr   OCP.BRepFilletAPIr   r   OCP.BRepGPropr   OCP.BRepOffsetr   r   OCP.BRepOffsetAPIr   r   r   OCP.BRepPrimAPIr   r   r   r   r   r   r   OCP.GeomAbsr    r!   OCP.gpr"   r#   r$   	OCP.GPropr%   
OCP.LocOper&   OCP.ShapeFixr'   OCP.Standardr(   r)   OCP.StdFailr*   
OCP.TopExpr+   r,   
OCP.TopoDSr-   r.   r/   r0   r1   r2   r3   OCP.TopToolsr4   r5   typing_extensionsr6   build123d.build_enumsr7   r8   r9   r:   r;   r<   build123d.geometryr=   r>   r?   r@   rA   rB   rC   rD   rE   one_drG   rH   rI   
shape_corerJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   two_drT   rU   rV   rW   utilsrX   rY   rZ   zero_dr[   	compositer\   r]   r_   rp   r  rl  rb   rg   re   <module>r     s  4l # $ " " / /  ? 7 7 6 , Q ( A 
   ? ) ) " $ ' @ ' .   Y " S S
 
 
 ' &   C B 
 )B	
eFm B	
J`GL! `F#3l 3rg   