aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi Murayama <opiopan@gmail.com>2019-08-18 18:33:41 +0900
committerHiroshi Murayama <opiopan@gmail.com>2019-08-18 18:33:41 +0900
commitf8fe16708502e0588d9d0be42d097a933d6f12d3 (patch)
tree4b489aa4ba99d96f5f16085d17874e8c4da8b001
parent02258202793e9c70f212171fe4a92f6bab3a6f72 (diff)
downloadpcb-tools-extension-f8fe16708502e0588d9d0be42d097a933d6f12d3.tar.gz
pcb-tools-extension-f8fe16708502e0588d9d0be42d097a933d6f12d3.tar.bz2
pcb-tools-extension-f8fe16708502e0588d9d0be42d097a933d6f12d3.zip
zero supressing in aperture macro definition
-rw-r--r--gerberex/am_expression.py3
-rw-r--r--tests/expects/RS2724x_offset.gtl14
-rw-r--r--tests/expects/RS2724x_rotate.gtl38
-rw-r--r--tests/expects/RS2724x_save.gtl14
-rw-r--r--tests/expects/RS2724x_to_inch.gtl14
-rw-r--r--tests/expects/RS2724x_to_metric.gtl14
-rw-r--r--tests/test_am_expression.py50
7 files changed, 74 insertions, 73 deletions
diff --git a/gerberex/am_expression.py b/gerberex/am_expression.py
index 4bb1d78..5400130 100644
--- a/gerberex/am_expression.py
+++ b/gerberex/am_expression.py
@@ -49,7 +49,8 @@ class AMConstantExpression(AMExpression):
return self
def to_gerber(self, settings=None):
- return '%.6f' % self._value
+ gerber = '%.6g' % self._value
+ return '%.6f' % self._value if 'e' in gerber else gerber
def to_instructions(self):
return [(OpCode.PUSH, self._value)]
diff --git a/tests/expects/RS2724x_offset.gtl b/tests/expects/RS2724x_offset.gtl
index f54e85b..9f15f4c 100644
--- a/tests/expects/RS2724x_offset.gtl
+++ b/tests/expects/RS2724x_offset.gtl
@@ -3,13 +3,13 @@
%INTop Layer*%
%IPPOS*%
%AMCOMP*
-20,1,0.200000,0.000000,0.100000,0.400000,0.100000,$1*
-21,1,0.400000,0.200000,-0.200000,-0.100000,$1*
-1,1,0.400000,-1.200000,0.000000,$1*
-4,1,4,1.200000,0.000000,1.400000,-0.200000,1.200000,-0.400000,1.000000,-0.200000,1.200000,0.000000,$1*
-5,1,6.000000,1.200000,0.200000,0.400000,$1*
-6,-0.700000,0.000000,0.500000,0.050000,0.150000,2.000000,0.050000,0.600000,$1*
-7,0.700000,0.000000,0.600000,0.500000,0.150000,$1*%
+20,1,0.2,0,0.1,0.4,0.1,$1*
+21,1,0.4,0.2,-0.2,-0.1,$1*
+1,1,0.4,-1.2,0,$1*
+4,1,4,1.2,0,1.4,-0.2,1.2,-0.4,1,-0.2,1.2,0,$1*
+5,1,6,1.2,0.2,0.4,$1*
+6,-0.7,0,0.5,0.05,0.15,2,0.05,0.6,$1*
+7,0.7,0,0.6,0.5,0.15,$1*%
%ADD10C,0.01*%
%ADD11C,1X0.4*%
%ADD12R,1X0.5X0.2*%
diff --git a/tests/expects/RS2724x_rotate.gtl b/tests/expects/RS2724x_rotate.gtl
index 9401fa7..0a2d1aa 100644
--- a/tests/expects/RS2724x_rotate.gtl
+++ b/tests/expects/RS2724x_rotate.gtl
@@ -3,33 +3,33 @@
%INTop Layer*%
%IPPOS*%
%AMCOMP*
-20,1,0.200000,0.000000,0.100000,0.400000,0.100000,($1)+(20.000000)*
-21,1,0.400000,0.200000,-0.200000,-0.100000,($1)+(20.000000)*
-1,1,0.400000,-1.200000,0.000000,($1)+(20.000000)*
-4,1,4,1.200000,0.000000,1.400000,-0.200000,1.200000,-0.400000,1.000000,-0.200000,1.200000,0.000000,($1)+(20.000000)*
-5,1,6.000000,1.200000,0.200000,0.400000,($1)+(20.000000)*
-6,-0.700000,0.000000,0.500000,0.050000,0.150000,2.000000,0.050000,0.600000,($1)+(20.000000)*
-7,0.700000,0.000000,0.600000,0.500000,0.150000,($1)+(20.000000)*%
+20,1,0.2,0,0.1,0.4,0.1,($1)+(20)*
+21,1,0.4,0.2,-0.2,-0.1,($1)+(20)*
+1,1,0.4,-1.2,0,($1)+(20)*
+4,1,4,1.2,0,1.4,-0.2,1.2,-0.4,1,-0.2,1.2,0,($1)+(20)*
+5,1,6,1.2,0.2,0.4,($1)+(20)*
+6,-0.7,0,0.5,0.05,0.15,2,0.05,0.6,($1)+(20)*
+7,0.7,0,0.6,0.5,0.15,($1)+(20)*%
%AMMACP*
-5,1,$2,0.000000,0.000000,$1,($3)+(20.000000)*
-1,0,$4,0.000000,0.000000,20.000000*%
+5,1,$2,0,0,$1,($3)+(20)*
+1,0,$4,0,0,20*%
%AMMACPO*
$4=($2)-($1)*
$5=($2)-($4)*
-21,1,$1,$5,0.000000,0.000000,20.000000*
-1,1,$4,0.000000,($4)/(2.000000),20.000000*
-1,1,$4,0.000000,($4)/(-2.000000),20.000000*
-1,0,$3,0.000000,0.000000,20.000000*%
+21,1,$1,$5,0,0,20*
+1,1,$4,0,($4)/(2),20*
+1,1,$4,0,($4)/(-2),20*
+1,0,$3,0,0,20*%
%AMMACLO*
$4=($1)-($2)*
$5=($1)-($4)*
-21,1,$5,$2,0.000000,0.000000,20.000000*
-1,1,$4,($4)/(2.000000),0.000000,20.000000*
-1,1,$4,($4)/(-2.000000),0.000000,20.000000*
-1,0,$3,0.000000,0.000000,20.000000*%
+21,1,$5,$2,0,0,20*
+1,1,$4,($4)/(2),0,20*
+1,1,$4,($4)/(-2),0,20*
+1,0,$3,0,0,20*%
%AMMACR*
-21,1,$1,$2,0.000000,0.000000,20.000000*
-1,0,$3,0.000000,0.000000,20.000000*%
+21,1,$1,$2,0,0,20*
+1,0,$3,0,0,20*%
%ADD10C,0.01*%
%ADD11C,1X0.4*%
%ADD12MACR,1X0.5X0.2*%
diff --git a/tests/expects/RS2724x_save.gtl b/tests/expects/RS2724x_save.gtl
index 45841e8..02dbaa8 100644
--- a/tests/expects/RS2724x_save.gtl
+++ b/tests/expects/RS2724x_save.gtl
@@ -3,13 +3,13 @@
%INTop Layer*%
%IPPOS*%
%AMCOMP*
-20,1,0.200000,0.000000,0.100000,0.400000,0.100000,$1*
-21,1,0.400000,0.200000,-0.200000,-0.100000,$1*
-1,1,0.400000,-1.200000,0.000000,$1*
-4,1,4,1.200000,0.000000,1.400000,-0.200000,1.200000,-0.400000,1.000000,-0.200000,1.200000,0.000000,$1*
-5,1,6.000000,1.200000,0.200000,0.400000,$1*
-6,-0.700000,0.000000,0.500000,0.050000,0.150000,2.000000,0.050000,0.600000,$1*
-7,0.700000,0.000000,0.600000,0.500000,0.150000,$1*%
+20,1,0.2,0,0.1,0.4,0.1,$1*
+21,1,0.4,0.2,-0.2,-0.1,$1*
+1,1,0.4,-1.2,0,$1*
+4,1,4,1.2,0,1.4,-0.2,1.2,-0.4,1,-0.2,1.2,0,$1*
+5,1,6,1.2,0.2,0.4,$1*
+6,-0.7,0,0.5,0.05,0.15,2,0.05,0.6,$1*
+7,0.7,0,0.6,0.5,0.15,$1*%
%ADD10C,0.01*%
%ADD11C,1X0.4*%
%ADD12R,1X0.5X0.2*%
diff --git a/tests/expects/RS2724x_to_inch.gtl b/tests/expects/RS2724x_to_inch.gtl
index 36bc604..3ec60d8 100644
--- a/tests/expects/RS2724x_to_inch.gtl
+++ b/tests/expects/RS2724x_to_inch.gtl
@@ -3,13 +3,13 @@
%INTop Layer*%
%IPPOS*%
%AMCOMP*
-20,1,0.007874,0.000000,0.003937,0.015748,0.003937,$1*
-21,1,0.015748,0.007874,-0.007874,-0.003937,$1*
-1,1,0.015748,-0.047244,0.000000,$1*
-4,1,4,0.047244,0.000000,0.055118,-0.007874,0.047244,-0.015748,0.039370,-0.007874,0.047244,0.000000,$1*
-5,1,6.000000,0.047244,0.007874,0.015748,$1*
-6,-0.027559,0.000000,0.019685,0.001969,0.005906,2.000000,0.001969,0.023622,$1*
-7,0.027559,0.000000,0.023622,0.019685,0.005906,$1*%
+20,1,0.00787402,0,0.00393701,0.015748,0.00393701,$1*
+21,1,0.015748,0.00787402,-0.00787402,-0.00393701,$1*
+1,1,0.015748,-0.0472441,0,$1*
+4,1,4,0.0472441,0,0.0551181,-0.00787402,0.0472441,-0.015748,0.0393701,-0.00787402,0.0472441,0,$1*
+5,1,6,0.0472441,0.00787402,0.015748,$1*
+6,-0.0275591,0,0.019685,0.0019685,0.00590551,2,0.0019685,0.023622,$1*
+7,0.0275591,0,0.023622,0.019685,0.00590551,$1*%
%ADD10C,0.0003937*%
%ADD11C,0.03937X0.01575*%
%ADD12R,0.03937X0.01969X0.007874*%
diff --git a/tests/expects/RS2724x_to_metric.gtl b/tests/expects/RS2724x_to_metric.gtl
index 72464f3..93adfc1 100644
--- a/tests/expects/RS2724x_to_metric.gtl
+++ b/tests/expects/RS2724x_to_metric.gtl
@@ -3,13 +3,13 @@
%INTop Layer*%
%IPPOS*%
%AMCOMP*
-20,1,0.200000,0.000000,0.100000,0.399999,0.100000,$1*
-21,1,0.399999,0.200000,-0.200000,-0.100000,$1*
-1,1,0.399999,-1.200000,0.000000,$1*
-4,1,4,1.200000,0.000000,1.400000,-0.200000,1.200000,-0.399999,1.000001,-0.200000,1.200000,0.000000,$1*
-5,1,6.000000,1.200000,0.200000,0.399999,$1*
-6,-0.700001,0.000000,0.499999,0.050000,0.150000,2.000000,0.050000,0.599999,$1*
-7,0.700001,0.000000,0.599999,0.499999,0.150000,$1*%
+20,1,0.2,0,0.1,0.399999,0.1,$1*
+21,1,0.399999,0.2,-0.2,-0.1,$1*
+1,1,0.399999,-1.2,0,$1*
+4,1,4,1.2,0,1.4,-0.2,1.2,-0.399999,1,-0.2,1.2,0,$1*
+5,1,6,1.2,0.2,0.399999,$1*
+6,-0.700001,0,0.499999,0.0499999,0.15,2,0.0499999,0.599999,$1*
+7,0.700001,0,0.599999,0.499999,0.15,$1*%
%ADD10C,0.01*%
%ADD11C,1X0.4*%
%ADD12R,1X0.5001X0.2*%
diff --git a/tests/test_am_expression.py b/tests/test_am_expression.py
index 0f064e6..7490284 100644
--- a/tests/test_am_expression.py
+++ b/tests/test_am_expression.py
@@ -27,8 +27,8 @@ class TestAMConstantExpression(unittest.TestCase):
self.assertEqual(ov.value, self.const_float_value)
def test_to_gerber(self):
- self.assertEqual(self.const_int.to_gerber(), '7.000000')
- self.assertEqual(self.const_float.to_gerber(), '1.234500')
+ self.assertEqual(self.const_int.to_gerber(), '7')
+ self.assertEqual(self.const_float.to_gerber(), '1.2345')
def test_to_instructions(self):
self.const_int.to_instructions()
@@ -120,15 +120,15 @@ class TestAMOperatorExpression(unittest.TestCase):
def test_to_gerber(self):
for op, expression in self.cc_exps:
self.assertEqual(expression.to_gerber(),
- '(%.6f)%s(%.6f)' % (self.c1, op, self.c2))
+ '({0}){1}({2})'.format(self.c1, op, self.c2))
for op, expression in self.cv_exps:
self.assertEqual(expression.to_gerber(),
- '(%.6f)%s($%d)' % (self.c1, op, self.v2))
+ '({0}){1}(${2})'.format(self.c1, op, self.v2))
for op, expression in self.vc_exps:
self.assertEqual(expression.to_gerber(),
- '($%d)%s(%.6f)' % (self.v1, op, self.c2))
+ '(${0}){1}({2})'.format(self.v1, op, self.c2))
self.assertEqual(self.composition.to_gerber(),
- '((%.6f)+(%.6f))+((%.6f)+(%.6f))' % (
+ '(({0})+({1}))+(({2})+({3}))'.format(
self.c1, self.c2, self.c1, self.c2
))
@@ -168,29 +168,29 @@ class TestAMExpression(unittest.TestCase):
class TestEvalMacro(unittest.TestCase):
def test_eval_macro(self):
macros = [
- ('$1=5.5*', '$1=5.500000*'),
- ('$1=0.0000001*', '$1=0.000000*'),
- ('$2=$3*', '$2=$3*'),
- ('$3=(1.23)+(4.56)*', '$3=(1.230000)+(4.560000)*'),
- ('$3=(1.23)-(4.56)*', '$3=(1.230000)-(4.560000)*'),
- ('$3=(1.23)X(4.56)*', '$3=(1.230000)X(4.560000)*'),
- ('$3=(1.23)/(4.56)*', '$3=(1.230000)/(4.560000)*'),
- ('$3=(10.2)X($2)*', '$3=(10.200000)X($2)*'),
- ('1,1.2*', '1,1.200000*'),
- ('1,$2*', '1,$2*'),
- ('1,($2)+($3)*', '1,($2)+($3)*'),
- #('1,(2.0)-($3)*', '1,(2.0)-($3)*'), # This doesn't pass due to pcb-tools bug
- ('1,($2)X($3)*', '1,($2)X($3)*'),
- ('1,($2)/($3)*', '1,($2)/($3)*'),
- ('1,2.1,3.2*2,(3.1)/($1),$2*', '1,2.100000,3.200000*2,(3.100000)/($1),$2*'),
+ '$1=5.5*',
+ '$1=0.000001*'
+ '$2=$3*',
+ '$3=(1.23)+(4.56)*',
+ '$3=(1.23)-(4.56)*',
+ '$3=(1.23)X(4.56)*',
+ '$3=(1.23)/(4.56)*',
+ '$3=(10.2)X($2)*',
+ '1,1.2*',
+ '1,$2*',
+ '1,($2)+($3)*',
+ #'1,(2.0)-($3)*', # This doesn't pass due to pcb-tools bug
+ '1,($2)X($3)*',
+ '1,($2)/($3)*',
+ '1,2.1,3.2*2,(3.1)/($1),$2*'
]
- for macro, expected in macros:
- self._eval_macro_string(macro, expected)
+ for macro in macros:
+ self._eval_macro_string(macro)
- def _eval_macro_string(self, macro, expected):
+ def _eval_macro_string(self, macro):
expressions = eval_macro(read_macro(macro))
gerber = self._to_gerber(expressions)
- self.assertEqual(gerber, expected)
+ self.assertEqual(macro, gerber)
def _to_gerber(self, expressions_list):
gerber = ''