flatland.core.grid.grid_utils module¶
-
class
flatland.core.grid.grid_utils.
Vec2dOperations
[source]¶ Bases:
object
-
static
add
(node_a:Tuple[float, float], node_b:Tuple[float, float]) → Tuple[float, float][source]¶ vector operation : node_a + node_b
Parameters: - node_a – tuple with coordinate (x,y) or 2d vector
- node_b – tuple with coordinate (x,y) or 2d vector
Returns: tuple with coordinate (x,y) or 2d vector
-
static
bound
(node:Tuple[float, float], min_value:float, max_value:float) → Tuple[float, float][source]¶ force the values x and y to be between min_value and max_value
Parameters: - node – tuple with coordinate (x,y) or 2d vector
- min_value – scalar value
- max_value – scalar value
Returns: tuple with coordinate (x,y) or 2d vector
-
static
ceil
(node:Tuple[float, float]) → Tuple[int, int][source]¶ ceiling the x and y coordinate and convert them to an integer values
Parameters: node – tuple with coordinate (x,y) or 2d vector Returns: tuple with coordinate (x,y) or 2d vector
-
static
floor
(node:Tuple[float, float]) → Tuple[int, int][source]¶ floor the x and y coordinate and convert them to an integer values
Parameters: node – tuple with coordinate (x,y) or 2d vector Returns: tuple with coordinate (x,y) or 2d vector
-
static
get_chebyshev_distance
(node_a:Tuple[float, float], node_b:Tuple[float, float]) → float[source]¶ calculates the chebyshev norm of the 2d vector [see: https://lyfat.wordpress.com/2012/05/22/euclidean-vs-chebyshev-vs-manhattan-distance/]
Parameters: - node_a
tuple with coordinate (x,y) or 2d vector
- node_b
tuple with coordinate (x,y) or 2d vector
Returns: - float
the chebyshev distance
-
static
get_euclidean_distance
(node_a:Tuple[float, float], node_b:Tuple[float, float]) → float[source]¶ calculates the euclidean norm of the 2d vector
Parameters: - node_a
tuple with coordinate (x,y) or 2d vector
- node_b
tuple with coordinate (x,y) or 2d vector
Returns: - float
Euclidean distance
-
static
get_manhattan_distance
(node_a:Tuple[float, float], node_b:Tuple[float, float]) → float[source]¶ calculates the manhattan distance of the 2d vector [see: https://lyfat.wordpress.com/2012/05/22/euclidean-vs-chebyshev-vs-manhattan-distance/]
Parameters: - node_a
tuple with coordinate (x,y) or 2d vector
- node_b
tuple with coordinate (x,y) or 2d vector
Returns: - float
Mahnhattan distance
-
static
get_norm
(node:Tuple[float, float]) → float[source]¶ calculates the euclidean norm of the 2d vector [see: https://lyfat.wordpress.com/2012/05/22/euclidean-vs-chebyshev-vs-manhattan-distance/]
Parameters: node – tuple with coordinate (x,y) or 2d vector Returns: tuple with coordinate (x,y) or 2d vector
-
static
is_equal
(node_a:Tuple[float, float], node_b:Tuple[float, float]) → bool[source]¶ vector operation : node_a + node_b
Parameters: - node_a – tuple with coordinate (x,y) or 2d vector
- node_b – tuple with coordinate (x,y) or 2d vector
Returns: check if node_a and nobe_b are equal
-
static
make_orthogonal
(node:Tuple[float, float]) → Tuple[float, float][source]¶ vector operation : rotates the 2D vector +90°
Parameters: node – tuple with coordinate (x,y) or 2d vector Returns: tuple with coordinate (x,y) or 2d vector
-
static
normalize
(node:Tuple[float, float]) → Tuple[float, float][source]¶ normalize the 2d vector = v/|v|
Parameters: node – tuple with coordinate (x,y) or 2d vector Returns: tuple with coordinate (x,y) or 2d vector
-
static
rotate
(node:Tuple[float, float], rot_in_degree:float) → Tuple[float, float][source]¶ rotate the 2d vector with given angle in degree
Parameters: - node – tuple with coordinate (x,y) or 2d vector
- rot_in_degree – angle in degree
Returns: tuple with coordinate (x,y) or 2d vector
-
static
round
(node:Tuple[float, float]) → Tuple[int, int][source]¶ rounds the x and y coordinate and convert them to an integer values
Parameters: node – tuple with coordinate (x,y) or 2d vector Returns: tuple with coordinate (x,y) or 2d vector
-
static
-
flatland.core.grid.grid_utils.
coordinate_to_position
(depth, coords)[source]¶ Converts positions to coordinates:
[ 0 d .. (w-1)*d 1 d+1 ... d-1 2d-1 w*d-1 ] --> [ (0,0) (0,1) .. (0,w-1) (1,0) (1,1) (1,w-1) ... (d-1,0) (d-1,1) (d-1,w-1) ]
Parameters: - depth –
- coords –
Returns:
-
flatland.core.grid.grid_utils.
position_to_coordinate
(depth:int, positions:List[int])[source]¶ Converts coordinates to positions:
[ (0,0) (0,1) .. (0,w-1) (1,0) (1,1) (1,w-1) ... (d-1,0) (d-1,1) (d-1,w-1) ] --> [ 0 d .. (w-1)*d 1 d+1 ... d-1 2d-1 w*d-1 ]
Parameters: - depth : int
- positions : List[Tuple[int,int]]