Skip to content

Commit 1cbf556

Browse files
committed
add __rand__ back
1 parent 22c1aa0 commit 1cbf556

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

pygfunction/boreholes.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,30 @@ def __add__(self, other: Union[Self, list]):
8181
field = Borefield.from_boreholes([self, other])
8282
return field
8383

84-
84+
def __radd__(self, other: Union[Self, list]):
85+
"""
86+
Adds two boreholes together to form a borefield
87+
"""
88+
if not isinstance(other, (self.__class__, list)):
89+
# Check if other is a borefield and try the operation using
90+
# other.__radd__
91+
try:
92+
field = other.__add__(self)
93+
except:
94+
# Invalid input
95+
raise TypeError(
96+
f'Expected Borefield, list or Borehole input;'
97+
f' got {other}'
98+
)
99+
elif isinstance(other, list):
100+
# Create a borefield from the borehole and a list
101+
from .borefield import Borefield
102+
field = Borefield.from_boreholes(other + [self])
103+
else:
104+
# Create a borefield from the two boreholes
105+
from .borefield import Borefield
106+
field = Borefield.from_boreholes([other, self])
107+
return field
85108

86109
def distance(self, target):
87110
"""

0 commit comments

Comments
 (0)