Passed
Push — master ( 7ebd63...8bd9a3 )
by Simon
06:11
created

Direction.get_new_position()   A

Complexity

Conditions 2

Size

Total Lines 17
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 17
rs 10
c 0
b 0
f 0
cc 2
nop 2
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