Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:20:07

0001 // Copyright (c) 2025 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef GeomBndLib_Line_HeaderFile
0015 #define GeomBndLib_Line_HeaderFile
0016 
0017 #include <Bnd_Box.hxx>
0018 #include <GeomBndLib_InfiniteHelpers.pxx>
0019 #include <ElCLib.hxx>
0020 #include <Geom_Line.hxx>
0021 #include <gp_Lin.hxx>
0022 #include <Standard_DefineAlloc.hxx>
0023 #include <Standard_Failure.hxx>
0024 
0025 //! Computes bounding box for a 3D line (Geom_Line).
0026 //! Handles infinite parameters by opening the box in appropriate directions.
0027 //!
0028 //! Static method accepting gp_Lin can be used directly without
0029 //! constructing a Geom_Line handle.
0030 class GeomBndLib_Line
0031 {
0032 public:
0033   DEFINE_STANDARD_ALLOC
0034 
0035   GeomBndLib_Line(const occ::handle<Geom_Line>& theLine)
0036       : myGeom(theLine)
0037   {
0038   }
0039 
0040   GeomBndLib_Line(const GeomBndLib_Line&)            = delete;
0041   GeomBndLib_Line& operator=(const GeomBndLib_Line&) = delete;
0042   GeomBndLib_Line(GeomBndLib_Line&&)                 = delete;
0043   GeomBndLib_Line& operator=(GeomBndLib_Line&&)      = delete;
0044 
0045   const occ::handle<Geom_Line>& Geometry() const { return myGeom; }
0046 
0047   //! Compute bounding box for line segment [theU1, theU2].
0048   [[nodiscard]] Bnd_Box Box(double theU1, double theU2, double theTol) const
0049   {
0050     return Box(myGeom->Lin(), theU1, theU2, theTol);
0051   }
0052 
0053   //! Compute bounding box for full curve.
0054   [[nodiscard]] Bnd_Box Box(double theTol) const
0055   {
0056     return Box(myGeom->FirstParameter(), myGeom->LastParameter(), theTol);
0057   }
0058 
0059   //! For analytical curves, BoxOptimal is same as Box.
0060   [[nodiscard]] Bnd_Box BoxOptimal(double theU1, double theU2, double theTol) const
0061   {
0062     return Box(theU1, theU2, theTol);
0063   }
0064 
0065   //! Compute bounding box for a line segment [theU1, theU2] defined by gp_Lin.
0066   [[nodiscard]] static Bnd_Box Box(const gp_Lin& theLin, double theU1, double theU2, double theTol)
0067   {
0068     Bnd_Box aBox;
0069     if (Precision::IsNegativeInfinite(theU1))
0070     {
0071       if (Precision::IsNegativeInfinite(theU2))
0072       {
0073         throw Standard_Failure("GeomBndLib_Line::Box - bad parameter");
0074       }
0075       else if (Precision::IsPositiveInfinite(theU2))
0076       {
0077         GeomBndLib_InfiniteHelpers::OpenMinMax(theLin.Direction(), aBox);
0078         aBox.Add(ElCLib::Value(0., theLin));
0079       }
0080       else
0081       {
0082         GeomBndLib_InfiniteHelpers::OpenMin(theLin.Direction(), aBox);
0083         aBox.Add(ElCLib::Value(theU2, theLin));
0084       }
0085     }
0086     else if (Precision::IsPositiveInfinite(theU1))
0087     {
0088       if (Precision::IsNegativeInfinite(theU2))
0089       {
0090         GeomBndLib_InfiniteHelpers::OpenMinMax(theLin.Direction(), aBox);
0091         aBox.Add(ElCLib::Value(0., theLin));
0092       }
0093       else if (Precision::IsPositiveInfinite(theU2))
0094       {
0095         throw Standard_Failure("GeomBndLib_Line::Box - bad parameter");
0096       }
0097       else
0098       {
0099         GeomBndLib_InfiniteHelpers::OpenMax(theLin.Direction(), aBox);
0100         aBox.Add(ElCLib::Value(theU2, theLin));
0101       }
0102     }
0103     else
0104     {
0105       aBox.Add(ElCLib::Value(theU1, theLin));
0106       if (Precision::IsNegativeInfinite(theU2))
0107       {
0108         GeomBndLib_InfiniteHelpers::OpenMin(theLin.Direction(), aBox);
0109       }
0110       else if (Precision::IsPositiveInfinite(theU2))
0111       {
0112         GeomBndLib_InfiniteHelpers::OpenMax(theLin.Direction(), aBox);
0113       }
0114       else
0115       {
0116         aBox.Add(ElCLib::Value(theU2, theLin));
0117       }
0118     }
0119     aBox.Enlarge(theTol);
0120     return aBox;
0121   }
0122 
0123 private:
0124   occ::handle<Geom_Line> myGeom;
0125 };
0126 
0127 #endif // GeomBndLib_Line_HeaderFile