Draw a zig-zagged line from p1 to p2.
(
self,
p1: point_like,
p2: point_like,
breadth: float = 2,
)
| 3364 | return self.draw_polyline([q.ul, q.ll, q.lr, q.ur, q.ul]) |
| 3365 | |
| 3366 | def draw_zigzag( |
| 3367 | self, |
| 3368 | p1: point_like, |
| 3369 | p2: point_like, |
| 3370 | breadth: float = 2, |
| 3371 | ) -> Point: |
| 3372 | """Draw a zig-zagged line from p1 to p2.""" |
| 3373 | p1 = Point(p1) |
| 3374 | p2 = Point(p2) |
| 3375 | S = p2 - p1 # vector start - end |
| 3376 | rad = abs(S) # distance of points |
| 3377 | cnt = 4 * int(round(rad / (4 * breadth), 0)) # always take full phases |
| 3378 | if cnt < 4: |
| 3379 | raise ValueError("points too close") |
| 3380 | mb = rad / cnt # revised breadth |
| 3381 | matrix = Matrix(util_hor_matrix(p1, p2)) # normalize line to x-axis |
| 3382 | i_mat = ~matrix # get original position |
| 3383 | points = [] # stores edges |
| 3384 | for i in range(1, cnt): |
| 3385 | if i % 4 == 1: # point "above" connection |
| 3386 | p = Point(i, -1) * mb |
| 3387 | elif i % 4 == 3: # point "below" connection |
| 3388 | p = Point(i, 1) * mb |
| 3389 | else: # ignore others |
| 3390 | continue |
| 3391 | points.append(p * i_mat) |
| 3392 | self.draw_polyline([p1] + points + [p2]) # add start and end points |
| 3393 | return p2 |
| 3394 | |
| 3395 | def draw_squiggle( |
| 3396 | self, |
no test coverage detected