Skip to content
Snippets Groups Projects
Commit 3b170954 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

MNT: Use custom error type (sub-classed from ValueError, so not an API change)

parent 9dfb554f
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,13 @@ import fsl.transform.affine as affine ...@@ -41,6 +41,13 @@ import fsl.transform.affine as affine
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class IncompatibleVerticesError(ValueError):
"""``ValueError`` raised by the :meth:`Mesh.addVertices` method if
an attempt is made to add a vertex set with the wrong number of
vertices.
"""
class Mesh(notifier.Notifier, meta.Meta): class Mesh(notifier.Notifier, meta.Meta):
"""The ``Mesh`` class represents a 3D model. A mesh is defined by a """The ``Mesh`` class represents a 3D model. A mesh is defined by a
collection of ``N`` vertices, and ``M`` triangles. The triangles are collection of ``N`` vertices, and ``M`` triangles. The triangles are
...@@ -412,8 +419,8 @@ class Mesh(notifier.Notifier, meta.Meta): ...@@ -412,8 +419,8 @@ class Mesh(notifier.Notifier, meta.Meta):
:returns: The vertices, possibly reshaped :returns: The vertices, possibly reshaped
:raises: ``ValueError`` if the provided ``vertices`` array :raises: ``IncompatibleVerticesError`` if the provided
has the wrong number of vertices. ``vertices`` array has the wrong number of vertices.
""" """
if self.__indices is None: if self.__indices is None:
...@@ -434,10 +441,9 @@ class Mesh(notifier.Notifier, meta.Meta): ...@@ -434,10 +441,9 @@ class Mesh(notifier.Notifier, meta.Meta):
# reshape raised an error - # reshape raised an error -
# wrong number of vertices # wrong number of vertices
except ValueError: except ValueError:
raise ValueError('{}: invalid number of vertices: ' raise IncompatibleVerticesError(
'{} != ({}, 3)'.format(key, f'{key}: invalid number of vertices: '
vertices.shape, f'{vertices.shape} != ({self.nvertices}, 3)')
self.nvertices))
self.__vertices[key] = vertices self.__vertices[key] = vertices
self.__vindices[key] = self.__indices self.__vindices[key] = self.__indices
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment