Skip to content

Conversation

@wouterpeere
Copy link
Contributor

Hi @MassimoCimmino ,

I thought it would be useful to have a function to add different borefields together.

Best,
Wouter

@MassimoCimmino
Copy link
Owner

Thanks. This was also on my to-do list.

We might want to implement also __radd__ for the case borehole + borefield. One thing that delayed me on this feature is how to do the operation borehole1 + borehole2. Perhaps you have an idea there.

Following this, we could explore adding methods to the borefield class such as .translate and .rotate to have composable borefields.

@wouterpeere
Copy link
Contributor Author

Hi @MassimoCimmino ,

The code I wrote for __add__ can handle borefield + borehole as well as borefield + borefield where the borefield can be both the Borefield object or a list of Borehole objects.

Since every borehole has an (x,y) coordinate, I think we just can create a addition that returns a Borefield object.
I added this also to the code.

@MassimoCimmino
Copy link
Owner

Thanks @wouterpeere.

Your implementation of Borehole.__add__(Borefield) always put the borehole at the end of the borefield. Calling borehole + field would have the expected result of putting the borehole at the start of the borefield.

I fixed it by implementing both Borehole.__radd__ and Borefield.__radd__. This as the added bonus of also handling the cases list + borehole and list + field.

Could you doublecheck the implementation before I merge?

@wouterpeere
Copy link
Contributor Author

@MassimoCimmino , everything looks good to me!

(I tried if the rand was really needed, since I'm not that familiar with it, but everything is fine!)

@MassimoCimmino
Copy link
Owner

In summary, when executing a + b, Python first tries a.__add__(b) and if that is not supported it tries b.__radd__(a). In the present case, this allows us to enable the use of + when a is a list without coding the behavior into the built-in list type.

@MassimoCimmino MassimoCimmino merged commit 8151179 into MassimoCimmino:master Jul 15, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants