summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/aperture_macros/expression.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2021-12-29 19:58:20 +0100
committerjaseg <git@jaseg.de>2021-12-29 19:58:20 +0100
commit3fb26e6940b5ae752308d8a33f2608d266795153 (patch)
treea563b0cf512e5661b2a450ebf73eafe655ac18b2 /gerbonara/gerber/aperture_macros/expression.py
parent30dabef9ee83021067957854187b9bbf245c14cf (diff)
downloadgerbonara-3fb26e6940b5ae752308d8a33f2608d266795153.tar.gz
gerbonara-3fb26e6940b5ae752308d8a33f2608d266795153.tar.bz2
gerbonara-3fb26e6940b5ae752308d8a33f2608d266795153.zip
Basic round-trip works
Diffstat (limited to 'gerbonara/gerber/aperture_macros/expression.py')
-rw-r--r--gerbonara/gerber/aperture_macros/expression.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/gerbonara/gerber/aperture_macros/expression.py b/gerbonara/gerber/aperture_macros/expression.py
index ddd8d53..73a2a36 100644
--- a/gerbonara/gerber/aperture_macros/expression.py
+++ b/gerbonara/gerber/aperture_macros/expression.py
@@ -8,15 +8,14 @@ import re
import ast
+MILLIMETERS_PER_INCH = 25.4
+
+
def expr(obj):
return obj if isinstance(obj, Expression) else ConstantExpression(obj)
-class Expression(object):
- @property
- def value(self):
- return self
-
+class Expression:
def optimized(self, variable_binding={}):
return self
@@ -79,17 +78,17 @@ class UnitExpression(Expression):
return f'<{self._expr.to_gerber()} {self.unit}>'
def converted(self, unit):
- if unit is None or self.unit == unit:
+ if self.unit is None or unit is None or self.unit == unit:
return self._expr
elif unit == 'mm':
return self._expr * MILLIMETERS_PER_INCH
elif unit == 'inch':
- return self._expr / MILLIMETERS_PER_INCH)
+ return self._expr / MILLIMETERS_PER_INCH
else:
- raise ValueError('invalid unit, must be "inch" or "mm".')
+ raise ValueError(f'invalid unit {unit}, must be "inch" or "mm".')
class ConstantExpression(Expression):