| Total Complexity | 3 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # Author: Simon Blanke |
||
| 2 | # Email: [email protected] |
||
| 3 | # License: MIT License |
||
| 4 | |||
| 5 | |||
| 6 | class Direction: |
||
| 7 | def __init__(self, position_1, position_2) -> None: |
||
| 8 | """ |
||
| 9 | Parameters: |
||
| 10 | - position_1: dict, starting point in the search-space |
||
| 11 | - position_2: dict, end point in the search-space |
||
| 12 | """ |
||
| 13 | |||
| 14 | self.position_1 = position_1 |
||
| 15 | self.position_2 = position_2 |
||
| 16 | |||
| 17 | def get_new_position(self, t): |
||
| 18 | """ |
||
| 19 | Calculate a position on the line (vector) between two positions using parameter t. |
||
| 20 | |||
| 21 | Parameters: |
||
| 22 | - t: float, parameter indicating the position along the line (0 <= t <= 1 for within the line segment) |
||
| 23 | |||
| 24 | Returns: |
||
| 25 | - dict representing the new position in the search-space coordinate system |
||
| 26 | """ |
||
| 27 | new_position = {} |
||
| 28 | for dim in self.position_1: |
||
| 29 | # Calculate the position along the line in each dimension |
||
| 30 | new_position[dim] = self.position_1[dim] + t * ( |
||
| 31 | self.position_2[dim] - self.position_1[dim] |
||
| 32 | ) |
||
| 33 | return new_position |
||
| 34 |