diff --git a/masque/shapes/path.py b/masque/shapes/path.py index feb1700..43cff34 100644 --- a/masque/shapes/path.py +++ b/masque/shapes/path.py @@ -449,11 +449,15 @@ class Path(Shape): for v in normed_vertices]) # Reorder the vertices so that the one with lowest x, then y, comes first. - x_min = rotated_vertices[:, 0].argmin() - if not is_scalar(x_min): - y_min = rotated_vertices[x_min, 1].argmin() - x_min = cast('Sequence', x_min)[y_min] - reordered_vertices = numpy.roll(rotated_vertices, -x_min, axis=0) + x_min_val = rotated_vertices[:, 0].min() + x_min_inds = numpy.where(rotated_vertices[:, 0] == x_min_val)[0] + if x_min_inds.size > 1: + y_min_val = rotated_vertices[x_min_inds, 1].min() + tie_breaker = numpy.where(rotated_vertices[x_min_inds, 1] == y_min_val)[0][0] + start_ind = x_min_inds[tie_breaker] + else: + start_ind = x_min_inds[0] + reordered_vertices = numpy.roll(rotated_vertices, -start_ind, axis=0) width0 = self.width / norm_value diff --git a/masque/shapes/polygon.py b/masque/shapes/polygon.py index c9617a9..34a784b 100644 --- a/masque/shapes/polygon.py +++ b/masque/shapes/polygon.py @@ -417,11 +417,15 @@ class Polygon(Shape): for v in normed_vertices]) # Reorder the vertices so that the one with lowest x, then y, comes first. - x_min = rotated_vertices[:, 0].argmin() - if not is_scalar(x_min): - y_min = rotated_vertices[x_min, 1].argmin() - x_min = cast('Sequence', x_min)[y_min] - reordered_vertices = numpy.roll(rotated_vertices, -x_min, axis=0) + x_min_val = rotated_vertices[:, 0].min() + x_min_inds = numpy.where(rotated_vertices[:, 0] == x_min_val)[0] + if x_min_inds.size > 1: + y_min_val = rotated_vertices[x_min_inds, 1].min() + tie_breaker = numpy.where(rotated_vertices[x_min_inds, 1] == y_min_val)[0][0] + start_ind = x_min_inds[tie_breaker] + else: + start_ind = x_min_inds[0] + reordered_vertices = numpy.roll(rotated_vertices, -start_ind, axis=0) # TODO: normalize mirroring?