Source code for ddg.conversion.nets.core

from warnings import warn

import ddg
from ddg.geometry.spheres import SphereLike
from ddg.nets import SmoothDomain

from .geometry.quadrics import quadric_to_smooth_net
from .geometry.spheres import sphere_to_smooth_net
from .geometry.subspaces import subspace_to_smooth_net

__all__ = ["to_smooth_net"]


[docs]def to_smooth_net(object_, domain=None, **kwargs): """Convert an object to a smooth net. Parameters ---------- object_ : ddg.geometry.Subspace, ddg.geometry.Point, ddg.geometry.Quadric Object to be converted. Currently supported: * :py:class:`~ddg.geometry.Subspace` and :py:class:`~ddg.geometry.Point` in any ambient space, * :py:class:`~ddg.geometry.Quadric` contained in 1D, 2D and 3D subspaces in any ambient space. domain : list or SmoothDomain (default=None) Optionally a domain to assign to the net. If `domain` is not contained in the default domain, they are intersected and a warning is raised. Uses :py:func:`ddg.nets.create_subdomain`. **kwargs : dict Keyword arguments to be passed to the type-specific conversion. See submodules for available options. Returns ------- SmoothNet, SmoothCurve, PointNet or EmptyNet Warns ----- RuntimeWarning If `domain` is not contained in the default domain of the object. Raises ------ TypeError If object has a type for which conversion is not possible. """ if isinstance(object_, ddg.geometry.Subspace): net = subspace_to_smooth_net(object_, **kwargs) elif isinstance(object_, ddg.geometry.Quadric): net = quadric_to_smooth_net(object_, **kwargs) elif isinstance(object_, SphereLike): net = sphere_to_smooth_net(object_, **kwargs) else: raise TypeError( f"Object of type {type(object_)} could not be converted to smooth net." ) if domain is not None: restricted_net = ddg.nets.create_subdomain(net, domain) if isinstance(domain, list): domain = SmoothDomain(domain) if ( domain.intervals != net.domain.intervals or domain.periodicity != restricted_net.domain.periodicity ): warn( ( "The domain given to to_smooth_net was not a subdomain. The " "default domain and the given domain were intersected." ), category=RuntimeWarning, ) return restricted_net else: return net