From 4541146561d43ce2ad4ce9c3236ff60241e2b5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 12 Aug 2012 10:13:29 +0200 Subject: [PATCH] raise exception if matrix and implicit parameter arguments provided --- skimage/transform/_geometric.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index 19e3cb2d..13bcc7f6 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -271,12 +271,16 @@ class AffineTransform(ProjectiveTransform): def __init__(self, matrix=None, scale=None, rotation=None, shear=None, translation=None): - if matrix is not None and matrix.shape != (3, 3): - raise ValueError("invalid shape of transformation matrix") self._matrix = matrix + params = any(param is not None + for param in (scale, rotation, shear, translation)) - params = (scale, rotation, shear, translation) - if any(param is not None for param in params): + if params and matrix is not None: + raise ValueError("You cannot specify the transformation matrix and " + "the implicit parameters at the same time.") + elif matrix is not None and matrix.shape != (3, 3): + raise ValueError("Invalid shape of transformation matrix.") + elif params: if scale is None: scale = (1, 1) if rotation is None: @@ -344,12 +348,16 @@ class SimilarityTransform(ProjectiveTransform): def __init__(self, matrix=None, scale=None, rotation=None, translation=None): - if matrix is not None and matrix.shape != (3, 3): - raise ValueError("invalid shape of transformation matrix") self._matrix = matrix + params = any(param is not None + for param in (scale, rotation, translation)) - params = (scale, rotation, translation) - if any(param is not None for param in params): + if params and matrix is not None: + raise ValueError("You cannot specify the transformation matrix and " + "the implicit parameters at the same time.") + elif matrix is not None and matrix.shape != (3, 3): + raise ValueError("Invalid shape of transformation matrix.") + elif params: if scale is None: scale = 1 if rotation is None: