|
1 | 1 | # -*- coding: utf-8 -*- |
| 2 | +from typing import Union |
2 | 3 | import warnings |
3 | 4 |
|
4 | 5 | import numpy as np |
5 | 6 | from scipy.spatial.distance import pdist |
| 7 | +from typing_extensions import Self # for compatibility with Python <= 3.10 |
6 | 8 |
|
7 | 9 | from .utilities import _initialize_figure, _format_axes, _format_axes_3d |
8 | 10 |
|
@@ -54,6 +56,56 @@ def __repr__(self): |
54 | 56 | f' orientation={self.orientation})') |
55 | 57 | return s |
56 | 58 |
|
| 59 | + def __add__(self, other: Union[Self, list]): |
| 60 | + """ |
| 61 | + Adds two boreholes together to form a borefield |
| 62 | + """ |
| 63 | + if not isinstance(other, (self.__class__, list)): |
| 64 | + # Check if other is a borefield and try the operation using |
| 65 | + # other.__radd__ |
| 66 | + try: |
| 67 | + field = other.__radd__(self) |
| 68 | + except: |
| 69 | + # Invalid input |
| 70 | + raise TypeError( |
| 71 | + f'Expected Borefield, list or Borehole input;' |
| 72 | + f' got {other}' |
| 73 | + ) |
| 74 | + elif isinstance(other, list): |
| 75 | + # Create a borefield from the borehole and a list |
| 76 | + from .borefield import Borefield |
| 77 | + field = Borefield.from_boreholes([self] + other) |
| 78 | + else: |
| 79 | + # Create a borefield from the two boreholes |
| 80 | + from .borefield import Borefield |
| 81 | + field = Borefield.from_boreholes([self, other]) |
| 82 | + return field |
| 83 | + |
| 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 |
| 108 | + |
57 | 109 | def distance(self, target): |
58 | 110 | """ |
59 | 111 | Evaluate the distance between the current borehole and a target |
|
0 commit comments