1313 cast as tcast ,
1414)
1515from typing_extensions import Literal
16- from math import tan , sin , cos , pi , radians
16+ from math import tan , sin , cos , pi , radians , remainder
1717from itertools import product , chain
1818from multimethod import multimethod
1919from typish import instance_of , get_type
@@ -336,36 +336,27 @@ def rarray(self: T, xs: Real, ys: Real, nx: int, ny: int) -> T:
336336 for el in selection
337337 )
338338
339- def parray (self : T , r : Real , a1 : Real , a2 : Real , n : int , rotate : bool = True ) -> T :
339+ def parray (self : T , r : Real , a1 : Real , da : Real , n : int , rotate : bool = True ) -> T :
340340 """
341341 Generate a polar array of locations.
342342 """
343343
344344 if n < 1 :
345- raise ValueError (f"At least 1 elements required, requested { n } " )
345+ raise ValueError (f"At least 1 element required, requested { n } " )
346346
347- x = r * sin (radians (a1 ))
348- y = r * cos (radians (a1 ))
347+ locs = []
349348
350- if rotate :
351- loc = Location ( Vector ( x , y ), Vector ( 0 , 0 , 1 ), - a1 )
349+ if abs ( remainder ( da , 360 )) < 1e-6 :
350+ angle = da / n
352351 else :
353- loc = Location (Vector (x , y ))
354-
355- locs = [loc ]
352+ angle = da / (n - 1 ) if n > 1 else a1
356353
357- angle = (a2 - a1 ) / (n - 1 )
358-
359- for i in range (1 , n ):
354+ for i in range (0 , n ):
360355 phi = a1 + (angle * i )
361- x = r * sin (radians (phi ))
362- y = r * cos (radians (phi ))
363-
364- if rotate :
365- loc = Location (Vector (x , y ), Vector (0 , 0 , 1 ), - phi )
366- else :
367- loc = Location (Vector (x , y ))
356+ x = r * cos (radians (phi ))
357+ y = r * sin (radians (phi ))
368358
359+ loc = Location (Vector (x , y ))
369360 locs .append (loc )
370361
371362 if self ._selection :
@@ -374,9 +365,18 @@ def parray(self: T, r: Real, a1: Real, a2: Real, n: int, rotate: bool = True) ->
374365 selection = [Vector ()]
375366
376367 return self .push (
377- (l * el if isinstance (el , Location ) else l * Location (el .Center ()))
378- for l in locs
379- for el in selection
368+ (
369+ l
370+ * el
371+ * Location (
372+ Vector (0 , 0 ), Vector (0 , 0 , 1 ), (a1 + (angle * i )) if rotate else 0
373+ )
374+ )
375+ for i , l in enumerate (locs )
376+ for el in [
377+ el if isinstance (el , Location ) else Location (el .Center ())
378+ for el in selection
379+ ]
380380 )
381381
382382 def distribute (
@@ -387,7 +387,7 @@ def distribute(
387387 """
388388
389389 if not self ._selection :
390- raise ValueError ("Nothing selected to distirbute over" )
390+ raise ValueError ("Nothing selected to distribute over" )
391391
392392 params = [start + i * (stop - start ) / n for i in range (n + 1 )]
393393
0 commit comments