from warnings import warn
import ddg.datastructures.nets.utils as nutils
from ddg.datastructures.nets.domain import SmoothDomain
from ddg.geometry.intersection import Intersection, Join
from ddg.geometry.quadrics import Quadric
from ddg.geometry.spheres import SphereLike
from ddg.geometry.subspaces import Subspace
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_ : Subspace, Point, Quadric, Intersection or Join
Object to be converted. Currently supported:
* :py:class:`~.subspaces.Subspace` and :py:class:`~.subspaces.Point` in
any ambient space,
* :py:class:`~.quadrics.Quadric` contained in 1D,
2D and 3D subspaces in any ambient space,
* :py:class:`~.Intersection` and :py:class:`~.Join`. These will be
resolved and converted if resolving produces an object of a
different, supported type.
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.datastructures.nets.utils.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_, (Intersection, Join)):
object_ = object_.resolve()
if isinstance(object_, Subspace):
net = subspace_to_smooth_net(object_, **kwargs)
elif isinstance(object_, 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 = nutils.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