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_Line2d_HeaderFile
0015 #define GeomBndLib_Line2d_HeaderFile
0016 
0017 #include <Bnd_Box2d.hxx>
0018 #include <GeomBndLib_InfiniteHelpers.pxx>
0019 #include <ElCLib.hxx>
0020 #include <Geom2d_Line.hxx>
0021 #include <gp_Lin2d.hxx>
0022 #include <Standard_DefineAlloc.hxx>
0023 #include <Standard_Failure.hxx>
0024 
0025 //! Computes bounding box for a 2D line (Geom2d_Line).
0026 //! Handles infinite parameters by opening the box in appropriate directions.
0027 //!
0028 //! Static method accepting gp_Lin2d can be used directly without
0029 //! constructing a Geom2d_Line handle.
0030 class GeomBndLib_Line2d
0031 {
0032 public:
0033   DEFINE_STANDARD_ALLOC
0034 
0035   GeomBndLib_Line2d(const occ::handle<Geom2d_Line>& theLine)
0036       : myGeom(theLine)
0037   {
0038   }
0039 
0040   GeomBndLib_Line2d(const GeomBndLib_Line2d&)            = delete;
0041   GeomBndLib_Line2d& operator=(const GeomBndLib_Line2d&) = delete;
0042   GeomBndLib_Line2d(GeomBndLib_Line2d&&)                 = delete;
0043   GeomBndLib_Line2d& operator=(GeomBndLib_Line2d&&)      = delete;
0044 
0045   const occ::handle<Geom2d_Line>& Geometry() const { return myGeom; }
0046 
0047   //! Compute bounding box for line segment [theU1, theU2].
0048   [[nodiscard]] Bnd_Box2d Box(double theU1, double theU2, double theTol) const
0049   {
0050     return Box(myGeom->Lin2d(), theU1, theU2, theTol);
0051   }
0052 
0053   //! Compute bounding box for full curve.
0054   [[nodiscard]] Bnd_Box2d 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_Box2d BoxOptimal(double theU1, double theU2, double theTol) const
0061   {
0062     return Box(theU1, theU2, theTol);
0063   }
0064 
0065   //! Compute bounding box for a 2D line segment [theU1, theU2] defined by gp_Lin2d.
0066   [[nodiscard]] static Bnd_Box2d Box(const gp_Lin2d& theLin,
0067                                      double          theU1,
0068                                      double          theU2,
0069                                      double          theTol)
0070   {
0071     Bnd_Box2d aBox;
0072     if (Precision::IsNegativeInfinite(theU1))
0073     {
0074       if (Precision::IsNegativeInfinite(theU2))
0075       {
0076         throw Standard_Failure("GeomBndLib_Line2d::Box - bad parameter");
0077       }
0078       else if (Precision::IsPositiveInfinite(theU2))
0079       {
0080         GeomBndLib_InfiniteHelpers::OpenMinMax(theLin.Direction(), aBox);
0081         aBox.Add(ElCLib::Value(0., theLin));
0082       }
0083       else
0084       {
0085         GeomBndLib_InfiniteHelpers::OpenMin(theLin.Direction(), aBox);
0086         aBox.Add(ElCLib::Value(theU2, theLin));
0087       }
0088     }
0089     else if (Precision::IsPositiveInfinite(theU1))
0090     {
0091       if (Precision::IsNegativeInfinite(theU2))
0092       {
0093         GeomBndLib_InfiniteHelpers::OpenMinMax(theLin.Direction(), aBox);
0094         aBox.Add(ElCLib::Value(0., theLin));
0095       }
0096       else if (Precision::IsPositiveInfinite(theU2))
0097       {
0098         throw Standard_Failure("GeomBndLib_Line2d::Box - bad parameter");
0099       }
0100       else
0101       {
0102         GeomBndLib_InfiniteHelpers::OpenMax(theLin.Direction(), aBox);
0103         aBox.Add(ElCLib::Value(theU2, theLin));
0104       }
0105     }
0106     else
0107     {
0108       aBox.Add(ElCLib::Value(theU1, theLin));
0109       if (Precision::IsNegativeInfinite(theU2))
0110       {
0111         GeomBndLib_InfiniteHelpers::OpenMin(theLin.Direction(), aBox);
0112       }
0113       else if (Precision::IsPositiveInfinite(theU2))
0114       {
0115         GeomBndLib_InfiniteHelpers::OpenMax(theLin.Direction(), aBox);
0116       }
0117       else
0118       {
0119         aBox.Add(ElCLib::Value(theU2, theLin));
0120       }
0121     }
0122     aBox.Enlarge(theTol);
0123     return aBox;
0124   }
0125 
0126 private:
0127   occ::handle<Geom2d_Line> myGeom;
0128 };
0129 
0130 #endif // GeomBndLib_Line2d_HeaderFile