2222
2323from beartype .roar import BeartypeCallHintParamViolation
2424import geomdl
25- from geomdl .visualization import VisMPL
2625import numpy as np
2726from pint import Quantity
2827import pytest
5352 ParamForm ,
5453 ParamType ,
5554)
56- from ansys .geometry .core .shapes .surfaces .nurbs import NURBSSurface
55+ from ansys .geometry .core .shapes .surfaces .nurbs import NURBSSurface , NURBSSurfaceEvaluation
5756from ansys .geometry .core .shapes .surfaces .sphere import SphereEvaluation
5857
5958
@@ -1664,3 +1663,143 @@ def test_nurbs_surface_fitting():
16641663 assert len (surface .knotvector_u ) == 6
16651664 assert len (surface .knotvector_v ) == 6
16661665 assert len (surface .control_points ) == 9
1666+
1667+
1668+ def test_nurbs_surface_equality ():
1669+ """Test if two NURBSSurface instances are equal."""
1670+ points = [
1671+ Point3D ([0 , 0 , 0 ]),
1672+ Point3D ([0 , 1 , 1 ]),
1673+ Point3D ([0 , 2 , 0 ]),
1674+ Point3D ([1 , 0 , 1 ]),
1675+ Point3D ([1 , 1 , 2 ]),
1676+ Point3D ([1 , 2 , 1 ]),
1677+ Point3D ([2 , 0 , 0 ]),
1678+ Point3D ([2 , 1 , 1 ]),
1679+ Point3D ([2 , 2 , 0 ]),
1680+ ]
1681+ degree_u = 2
1682+ degree_v = 2
1683+
1684+ surface = NURBSSurface .fit_surface_from_points (
1685+ points = points , size_u = 3 , size_v = 3 , degree_u = degree_u , degree_v = degree_v
1686+ )
1687+ other_surface = NURBSSurface .fit_surface_from_points (
1688+ points = points , size_u = 3 , size_v = 3 , degree_u = degree_u , degree_v = degree_v
1689+ )
1690+
1691+ assert surface == other_surface
1692+
1693+ # Test with a different, non-equivalent, surface
1694+ different_points = [
1695+ Point3D ([0 , 0 , 0 ]),
1696+ Point3D ([0 , 1 , 1 ]),
1697+ Point3D ([0 , 2 , 0 ]),
1698+ Point3D ([2 , 0 , 1 ]),
1699+ Point3D ([2 , 1 , 2 ]),
1700+ Point3D ([2 , 2 , 1 ]),
1701+ Point3D ([4 , 0 , 0 ]),
1702+ Point3D ([4 , 1 , 1 ]),
1703+ Point3D ([4 , 2 , 0 ]),
1704+ ]
1705+ different_surface = NURBSSurface .fit_surface_from_points (
1706+ points = different_points , size_u = 3 , size_v = 3 , degree_u = degree_u , degree_v = degree_v
1707+ )
1708+
1709+ assert surface != different_surface
1710+
1711+ # Test comparison with a non-NURBSSurface object
1712+ non_nurbs_object = "Not a NURBSSurface"
1713+ assert surface != non_nurbs_object
1714+
1715+
1716+ def test_nurbs_surface_parameterization ():
1717+ """Test the parameterization method of the NURBSSurface class."""
1718+ # Define valid inputs for the NURBS surface
1719+ degree_u = 2
1720+ degree_v = 2
1721+ knots_u = [0 , 0 , 0 , 1 , 1 , 1 ]
1722+ knots_v = [0 , 0 , 0 , 1 , 1 , 1 ]
1723+ control_points = [
1724+ Point3D ([0 , 0 , 0 ]),
1725+ Point3D ([0 , 1 , 1 ]),
1726+ Point3D ([0 , 2 , 0 ]),
1727+ Point3D ([1 , 0 , 1 ]),
1728+ Point3D ([1 , 1 , 2 ]),
1729+ Point3D ([1 , 2 , 1 ]),
1730+ Point3D ([2 , 0 , 0 ]),
1731+ Point3D ([2 , 1 , 1 ]),
1732+ Point3D ([2 , 2 , 0 ]),
1733+ ]
1734+
1735+ # Create a NURBS surface instance
1736+ nurbs_surface = NURBSSurface .from_control_points (
1737+ degree_u = degree_u ,
1738+ degree_v = degree_v ,
1739+ knots_u = knots_u ,
1740+ knots_v = knots_v ,
1741+ control_points = control_points ,
1742+ )
1743+
1744+ # Call the parameterization method
1745+ u_param , v_param = nurbs_surface .parameterization ()
1746+
1747+ # Validate the u parameterization
1748+ assert isinstance (u_param , Parameterization )
1749+ assert u_param .form == ParamForm .OTHER
1750+ assert u_param .type == ParamType .OTHER
1751+ assert u_param .interval .start == nurbs_surface ._nurbs_surface .domain [0 ][0 ]
1752+ assert u_param .interval .end == nurbs_surface ._nurbs_surface .domain [0 ][1 ]
1753+
1754+ # Validate the v parameterization
1755+ assert isinstance (v_param , Parameterization )
1756+ assert v_param .form == ParamForm .OTHER
1757+ assert v_param .type == ParamType .OTHER
1758+ assert v_param .interval .start == nurbs_surface ._nurbs_surface .domain [1 ][0 ]
1759+ assert v_param .interval .end == nurbs_surface ._nurbs_surface .domain [1 ][1 ]
1760+
1761+
1762+ def test_nurbs_surface_simple_evaluation ():
1763+ """Test NURBSSurface evaluation."""
1764+ degree_u = 2
1765+ degree_v = 2
1766+ knots_u = [0 , 0 , 0 , 1 , 1 , 1 ]
1767+ knots_v = [0 , 0 , 0 , 1 , 1 , 1 ]
1768+ control_points = [
1769+ Point3D ([0 , 0 , 0 ]),
1770+ Point3D ([0 , 1 , 1 ]),
1771+ Point3D ([0 , 2 , 0 ]),
1772+ Point3D ([1 , 0 , 1 ]),
1773+ Point3D ([1 , 1 , 2 ]),
1774+ Point3D ([1 , 2 , 1 ]),
1775+ Point3D ([2 , 0 , 0 ]),
1776+ Point3D ([2 , 1 , 1 ]),
1777+ Point3D ([2 , 2 , 0 ]),
1778+ ]
1779+
1780+ nurbs_surface = NURBSSurface .from_control_points (
1781+ degree_u = degree_u ,
1782+ degree_v = degree_v ,
1783+ knots_u = knots_u ,
1784+ knots_v = knots_v ,
1785+ control_points = control_points ,
1786+ )
1787+
1788+ # Test invalid evaluation at (-1,0)
1789+ with pytest .raises (ValueError ):
1790+ _ = nurbs_surface .evaluate (ParamUV (- 1 , 0 ))
1791+
1792+ # Test evaluation at (0,0)
1793+ eval = nurbs_surface .evaluate (ParamUV (0.5 , 0.5 ))
1794+
1795+ assert isinstance (eval , NURBSSurfaceEvaluation )
1796+ assert eval .parameter .u == 0.5
1797+ assert eval .parameter .v == 0.5
1798+ assert eval .position == Point3D ([1 , 1 , 1 ])
1799+ assert isinstance (eval .u_derivative , Vector3D )
1800+ assert isinstance (eval .v_derivative , Vector3D )
1801+ assert isinstance (eval .uu_derivative , Vector3D )
1802+ assert isinstance (eval .uv_derivative , Vector3D )
1803+ assert isinstance (eval .vv_derivative , Vector3D )
1804+ assert isinstance (eval .normal , UnitVector3D )
1805+ assert isinstance (eval .surface , NURBSSurface )
0 commit comments