From 8414295b4670b1fdae03879c4427ca674412d2ce Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 2 Oct 2015 11:33:24 +0700 Subject: [PATCH] Expand check on combining parentheses --- openmc/region.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/openmc/region.py b/openmc/region.py index f1926cdc2a..26da5355dd 100644 --- a/openmc/region.py +++ b/openmc/region.py @@ -83,16 +83,19 @@ class Region(object): else: tokens.append(surfaces[abs(j)].positive) - # This function is used below to apply an operator to operands on the + # The functions below are used to apply an operator to operands on the # output queue during the shunting yard algorithm. + def can_be_combined(region): + return isinstance(region, Complement) or hasattr(region, 'surface') + def apply_operator(output, operator): r2 = output.pop() if operator == ' ': r1 = output.pop() - if isinstance(r1, Intersection) and hasattr(r2, 'surface'): + if isinstance(r1, Intersection) and can_be_combined(r2): r1.nodes.append(r2) output.append(r1) - elif isinstance(r2, Intersection) and hasattr(r1, 'surface'): + elif isinstance(r2, Intersection) and can_be_combined(r1): r2.nodes.insert(0, r1) output.append(r2) elif isinstance(r1, Intersection) and isinstance(r2, Intersection): @@ -102,10 +105,10 @@ class Region(object): output.append(Intersection(r1, r2)) elif operator == '^': r1 = output.pop() - if isinstance(r1, Union) and hasattr(r2, 'surface'): + if isinstance(r1, Union) and can_be_combined(r2): r1.nodes.append(r2) output.append(r1) - elif isinstance(r2, Union) and hasattr(r1, 'surface'): + elif isinstance(r2, Union) and can_be_combined(r1): r2.nodes.insert(0, r1) output.append(r2) elif isinstance(r1, Union) and isinstance(r2, Union):