diff options
author | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-03-05 22:42:42 -0500 |
---|---|---|
committer | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-03-05 22:42:42 -0500 |
commit | 68619d4d5a7beb38dc81d953b43bf4196ca1d3a6 (patch) | |
tree | dbc6a5ebe7403c95d9c37b0ef338d4eb60e4980a /gerber/utils.py | |
parent | c40683b6a216f29fe473c31680ade7ab294002cd (diff) | |
download | gerbonara-68619d4d5a7beb38dc81d953b43bf4196ca1d3a6.tar.gz gerbonara-68619d4d5a7beb38dc81d953b43bf4196ca1d3a6.tar.bz2 gerbonara-68619d4d5a7beb38dc81d953b43bf4196ca1d3a6.zip |
Fix parsing for multiline ipc-d-356 records
Diffstat (limited to 'gerber/utils.py')
-rw-r--r-- | gerber/utils.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/gerber/utils.py b/gerber/utils.py index 8cd4965..1c43550 100644 --- a/gerber/utils.py +++ b/gerber/utils.py @@ -26,6 +26,9 @@ files. # Author: Hamilton Kibbe <ham@hamiltonkib.be> # License: +from math import radians, sin, cos +from operator import sub + MILLIMETERS_PER_INCH = 25.4 def parse_gerber_value(value, format=(2, 5), zero_suppression='trailing'): @@ -238,7 +241,57 @@ def validate_coordinates(position): def metric(value): + """ Convert inch value to millimeters + + Parameters + ---------- + value : float + A value in inches. + + Returns + ------- + value : float + The equivalent value expressed in millimeters. + """ return value * MILLIMETERS_PER_INCH def inch(value): + """ Convert millimeter value to inches + + Parameters + ---------- + value : float + A value in millimeters. + + Returns + ------- + value : float + The equivalent value expressed in inches. + """ return value / MILLIMETERS_PER_INCH + + +def rotate_point(point, angle, center=(0.0, 0.0)): + """ Rotate a point about another point. + + Parameters + ----------- + point : tuple(<float>, <float>) + Point to rotate about origin or center point + + angle : float + Angle to rotate the point [degrees] + + center : tuple(<float>, <float>) + Coordinates about which the point is rotated. Defaults to the origin. + + Returns + ------- + rotated_point : tuple(<float>, <float>) + `point` rotated about `center` by `angle` degrees. + """ + angle = radians(angle) + xdelta, ydelta = tuple(map(sub, point, center)) + x = center[0] + (cos(angle) * xdelta) - (sin(angle) * ydelta) + y = center[1] + (sin(angle) * xdelta) - (cos(angle) * ydelta) + return (x, y) |