|
13 | 13 | cast as tcast, |
14 | 14 | ) |
15 | 15 | from typing_extensions import Literal |
16 | | -from math import tan, sin, cos, pi, radians |
| 16 | +from math import tan, sin, cos, pi, radians, remainder |
17 | 17 | from itertools import product, chain |
18 | 18 | from multimethod import multimethod |
19 | 19 | from typish import instance_of, get_type |
@@ -336,46 +336,43 @@ def rarray(self: T, xs: Real, ys: Real, nx: int, ny: int) -> T: |
336 | 336 | for el in selection |
337 | 337 | ) |
338 | 338 |
|
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: |
340 | 340 | """ |
341 | 341 | Generate a polar array of locations. |
342 | 342 | """ |
343 | 343 |
|
344 | 344 | 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}") |
346 | 346 |
|
347 | | - x = r * sin(radians(a1)) |
348 | | - y = r * cos(radians(a1)) |
| 347 | + locs = [] |
349 | 348 |
|
350 | | - if rotate: |
351 | | - loc = Location(Vector(x, y), Vector(0, 0, 1), -a1) |
| 349 | + if abs(remainder(da, 360)) < 1e-3: |
| 350 | + angle = da / n |
352 | 351 | else: |
353 | | - loc = Location(Vector(x, y)) |
354 | | - |
355 | | - locs = [loc] |
| 352 | + angle = da / (n - 1) if n > 1 else a1 |
356 | 353 |
|
357 | | - angle = (a2 - a1) / (n - 1) |
358 | | - |
359 | | - for i in range(1, n): |
| 354 | + for i in range(0, n): |
360 | 355 | 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)) |
368 | 358 |
|
| 359 | + loc = Location(Vector(x, y)) |
369 | 360 | locs.append(loc) |
370 | 361 |
|
371 | 362 | if self._selection: |
372 | 363 | selection: Sequence[Union[Shape, Location, Vector]] = self._selection |
373 | 364 | else: |
374 | | - selection = [Vector()] |
| 365 | + selection = [Location()] |
375 | 366 |
|
376 | 367 | return self.push( |
377 | | - (l * el if isinstance(el, Location) else l * Location(el.Center())) |
378 | | - for l in locs |
| 368 | + ( |
| 369 | + l |
| 370 | + * el |
| 371 | + * Location( |
| 372 | + Vector(0, 0), Vector(0, 0, 1), (a1 + (angle * i)) * int(rotate) |
| 373 | + ) |
| 374 | + ) |
| 375 | + for i, l in enumerate(locs) |
379 | 376 | for el in selection |
380 | 377 | ) |
381 | 378 |
|
|
0 commit comments