[Arc] return clearer errors when working with an invalid arclength
This commit is contained in:
parent
bdc4dfdd06
commit
d95ddbb6b9
2 changed files with 16 additions and 2 deletions
|
|
@ -231,6 +231,8 @@ class Arc(PositionableImpl, Shape):
|
|||
if (num_vertices is None) and (max_arclen is None):
|
||||
raise PatternError('Max number of points and arclength left unspecified'
|
||||
+ ' (default was also overridden)')
|
||||
if max_arclen is not None and (numpy.isnan(max_arclen) or max_arclen <= 0):
|
||||
raise PatternError('Max arclength must be positive and not NaN')
|
||||
|
||||
r0, r1 = self.radii
|
||||
|
||||
|
|
@ -257,13 +259,19 @@ class Arc(PositionableImpl, Shape):
|
|||
return arc_lengths, tt
|
||||
|
||||
wh = self.width / 2.0
|
||||
arclen_limits: list[float] = []
|
||||
if max_arclen is not None:
|
||||
arclen_limits.append(max_arclen)
|
||||
if num_vertices is not None:
|
||||
n_pts = numpy.ceil(max(self.radii + wh) / min(self.radii) * num_vertices * 100).astype(int)
|
||||
perimeter_inner = get_arclens(n_pts, *a_ranges[0], dr=-wh)[0].sum()
|
||||
perimeter_outer = get_arclens(n_pts, *a_ranges[1], dr= wh)[0].sum()
|
||||
implied_arclen = (perimeter_outer + perimeter_inner + self.width * 2) / num_vertices
|
||||
max_arclen = min(implied_arclen, max_arclen if max_arclen is not None else numpy.inf)
|
||||
assert max_arclen is not None
|
||||
if not (numpy.isnan(implied_arclen) or implied_arclen <= 0):
|
||||
arclen_limits.append(implied_arclen)
|
||||
if not arclen_limits:
|
||||
raise PatternError('Arc polygonization could not determine a valid max_arclen')
|
||||
max_arclen = min(arclen_limits)
|
||||
|
||||
def get_thetas(inner: bool) -> NDArray[numpy.float64]:
|
||||
""" Figure out the parameter values at which we should place vertices to meet the arclength constraint"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue