Draw a squiggly line from p1 to p2.
(
self,
p1: point_like,
p2: point_like,
breadth=2,
)
| 3393 | return p2 |
| 3394 | |
| 3395 | def draw_squiggle( |
| 3396 | self, |
| 3397 | p1: point_like, |
| 3398 | p2: point_like, |
| 3399 | breadth=2, |
| 3400 | ) -> Point: |
| 3401 | """Draw a squiggly line from p1 to p2.""" |
| 3402 | p1 = Point(p1) |
| 3403 | p2 = Point(p2) |
| 3404 | S = p2 - p1 # vector start - end |
| 3405 | rad = abs(S) # distance of points |
| 3406 | cnt = 4 * int(round(rad / (4 * breadth), 0)) # always take full phases |
| 3407 | if cnt < 4: |
| 3408 | raise ValueError("points too close") |
| 3409 | mb = rad / cnt # revised breadth |
| 3410 | matrix = Matrix(util_hor_matrix(p1, p2)) # normalize line to x-axis |
| 3411 | i_mat = ~matrix # get original position |
| 3412 | k = 2.4142135623765633 # y of draw_curve helper point |
| 3413 | |
| 3414 | points = [] # stores edges |
| 3415 | for i in range(1, cnt): |
| 3416 | if i % 4 == 1: # point "above" connection |
| 3417 | p = Point(i, -k) * mb |
| 3418 | elif i % 4 == 3: # point "below" connection |
| 3419 | p = Point(i, k) * mb |
| 3420 | else: # else on connection line |
| 3421 | p = Point(i, 0) * mb |
| 3422 | points.append(p * i_mat) |
| 3423 | |
| 3424 | points = [p1] + points + [p2] |
| 3425 | cnt = len(points) |
| 3426 | i = 0 |
| 3427 | while i + 2 < cnt: |
| 3428 | self.draw_curve(points[i], points[i + 1], points[i + 2]) |
| 3429 | i += 2 |
| 3430 | return p2 |
| 3431 | |
| 3432 | # ============================================================================== |
| 3433 | # Shape.insert_text |
no test coverage detected