diff options
author | jaseg <git@jaseg.de> | 2023-04-04 19:06:04 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2023-04-10 23:57:15 +0200 |
commit | 07b2628dbb08de7120ef3c760cd91f0d8901fe73 (patch) | |
tree | b640afbcf0da447185e72f572e373149f4aff079 /gerbonara/utils.py | |
parent | 387ff3de76664e620afebb6dabbccc0424710546 (diff) | |
download | gerbonara-07b2628dbb08de7120ef3c760cd91f0d8901fe73.tar.gz gerbonara-07b2628dbb08de7120ef3c760cd91f0d8901fe73.tar.bz2 gerbonara-07b2628dbb08de7120ef3c760cd91f0d8901fe73.zip |
Various convenience improvements, and make board name guessing really smart
Diffstat (limited to 'gerbonara/utils.py')
-rw-r--r-- | gerbonara/utils.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/gerbonara/utils.py b/gerbonara/utils.py index 53f6398..32954bd 100644 --- a/gerbonara/utils.py +++ b/gerbonara/utils.py @@ -442,7 +442,7 @@ def svg_arc(old, new, center, clockwise): :rtype: str """ - r = math.hypot(*center) + r = float(math.hypot(*center)) # invert sweep flag since the svg y axis is mirrored sweep_flag = int(not clockwise) # In the degenerate case where old == new, we always take the long way around. To represent this "full-circle arc" @@ -451,13 +451,13 @@ def svg_arc(old, new, center, clockwise): intermediate = old[0] + 2*center[0], old[1] + 2*center[1] # Note that we have to preserve the sweep flag to avoid causing self-intersections by flipping the direction of # a circular cutin - return f'A {r:.6} {r:.6} 0 1 {sweep_flag} {intermediate[0]:.6} {intermediate[1]:.6} ' +\ - f'A {r:.6} {r:.6} 0 1 {sweep_flag} {new[0]:.6} {new[1]:.6}' + return f'A {r:.6} {r:.6} 0 1 {sweep_flag} {float(intermediate[0]):.6} {float(intermediate[1]):.6} ' +\ + f'A {r:.6} {r:.6} 0 1 {sweep_flag} {float(new[0]):.6} {float(new[1]):.6}' else: # normal case d = point_line_distance(old, new, (old[0]+center[0], old[1]+center[1])) large_arc = int((d < 0) == clockwise) - return f'A {r:.6} {r:.6} 0 {large_arc} {sweep_flag} {new[0]:.6} {new[1]:.6}' + return f'A {r:.6} {r:.6} 0 {large_arc} {sweep_flag} {float(new[0]):.6} {float(new[1]):.6}' def svg_rotation(angle_rad, cx=0, cy=0): @@ -525,3 +525,13 @@ def point_in_polygon(point, poly): return res + +def bbox_intersect(a, b): + (xa_min, ya_min), (xa_max, ya_max) = a + (xb_min, yb_min), (xb_mbx, yb_mbx) = b + + x_overlap = not (xa_max < xb_min or xb_max < xa_min) + y_overlap = not (ya_max < yb_min or yb_max < ya_min) + + return x_overlap and y_overlap + |