first sparse steps
This commit is contained in:
parent
3810e64a5c
commit
24ca402f67
1 changed files with 139 additions and 12 deletions
|
|
@ -445,8 +445,25 @@ class SBend:
|
|||
|
||||
# tan(theta / 2) = local_dy / local_dx
|
||||
theta = 2 * numpy.arctan2(abs(local_dy), local_dx)
|
||||
|
||||
if abs(theta) < 1e-9:
|
||||
# Practically straight, but offset implies we need a bend.
|
||||
# If offset is also tiny, return a straight?
|
||||
if abs(offset) < 1e-6:
|
||||
# Degenerate case: effectively straight
|
||||
return Straight.generate(start_port, numpy.sqrt(local_dx**2 + local_dy**2), width, snap_to_grid=False, dilation=dilation)
|
||||
raise ValueError("SBend calculation failed: theta close to zero")
|
||||
|
||||
# Avoid division by zero if theta is 0 (though unlikely due to offset check)
|
||||
actual_radius = abs(local_dy) / (2 * (1 - numpy.cos(theta))) if theta > 1e-9 else radius
|
||||
denom = (2 * (1 - numpy.cos(theta)))
|
||||
if abs(denom) < 1e-9:
|
||||
raise ValueError("SBend calculation failed: radius denominator zero")
|
||||
|
||||
actual_radius = abs(local_dy) / denom
|
||||
|
||||
# Limit radius to prevent giant arcs
|
||||
if actual_radius > 100000.0:
|
||||
raise ValueError("SBend calculation failed: radius too large")
|
||||
|
||||
direction = 1 if local_dy > 0 else -1
|
||||
c1_angle = rad_start + direction * numpy.pi / 2
|
||||
|
|
|
|||
Loading…
Reference in a new issue