2222"""Provides for creating and managing a NURBS curve."""
2323
2424from functools import cached_property
25- from typing import Optional
25+ from typing import TYPE_CHECKING , Optional
2626
2727from beartype import beartype as check_input_types
28- import geomdl .NURBS as geomdl_nurbs # noqa: N811
2928
3029from ansys .geometry .core .math import Matrix44 , Point3D
3130from ansys .geometry .core .math .vector import Vector3D
3938)
4039from ansys .geometry .core .typing import Real
4140
41+ if TYPE_CHECKING : # pragma: no cover
42+ import geomdl .NURBS as geomdl_nurbs # noqa: N811
43+
4244
4345class NURBSCurve (Curve ):
4446 """Represents a NURBS curve.
@@ -53,14 +55,20 @@ class NURBSCurve(Curve):
5355
5456 """
5557
56- def __init__ (
57- self ,
58- ):
58+ def __init__ (self ):
5959 """Initialize ``NURBSCurve`` class."""
60+ try :
61+ import geomdl .NURBS as geomdl_nurbs # noqa: N811
62+ except ImportError as e : # pragma: no cover
63+ raise ImportError (
64+ "The `geomdl` library is required to use the NURBSCurve class. "
65+ "Please install it using `pip install geomdl`."
66+ ) from e
67+
6068 self ._nurbs_curve = geomdl_nurbs .Curve ()
6169
6270 @property
63- def geomdl_nurbs_curve (self ) -> geomdl_nurbs .Curve :
71+ def geomdl_nurbs_curve (self ) -> " geomdl_nurbs.Curve" :
6472 """Get the underlying NURBS curve.
6573
6674 Notes
@@ -237,7 +245,7 @@ def project_point(
237245
238246 # Function to minimize (distance squared)
239247 def distance_squared (
240- u : float , geomdl_nurbs_curbe : geomdl_nurbs .Curve , point : np .ndarray
248+ u : float , geomdl_nurbs_curbe : " geomdl_nurbs.Curve" , point : np .ndarray
241249 ) -> np .ndarray :
242250 point_on_curve = np .array (geomdl_nurbs_curbe .evaluate_single (u ))
243251 return np .sum ((point_on_curve - point ) ** 2 )
0 commit comments