Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
utils.cpp File Reference
#include "utils.hpp"
Include dependency graph for utils.cpp:

Go to the source code of this file.

Functions

std::ifstream open_read_file (const std::string &filename)
 Opens a file for reading.
 
std::vector< common_lib::structures::Conecone_vector_from_file (const std::string &path)
 Retrieves a cone vector from a file.
 
std::pair< std::vector< common_lib::structures::Cone >, std::vector< common_lib::structures::Cone > > track_from_file (const std::string &path)
 Retrieves a track (a pair of colored cone vectors from each side) from a file.
 
std::vector< common_lib::structures::PathPointpath_from_file (const std::string &path)
 Retrieves a path point vector from a file.
 
void extract_info (const std::string_view &filename_view, int &size, int &n_outliers)
 Extracts the size and number of outliers from a filename.
 
float consecutive_max_distance (const std::vector< common_lib::structures::Cone > &cones)
 Retrieves the max consecutive distance between adjacent cones in a vector.
 
std::vector< std::pair< double, double > > order_vector_of_pairs (const std::vector< std::pair< double, double > > &vec)
 orders a vector of pairs to make it easier to compare them
 
std::string get_current_date_time_as_string ()
 Get current date and time as a string.
 
float round_n (float num, int decimal_places)
 rounds float to n decimal places
 

Function Documentation

◆ cone_vector_from_file()

std::vector< common_lib::structures::Cone > cone_vector_from_file ( const std::string &  path)

Retrieves a cone vector from a file.

Parameters
filenameThe filename to be open

Definition at line 19 of file utils.cpp.

Here is the call graph for this function:

◆ consecutive_max_distance()

float consecutive_max_distance ( const std::vector< common_lib::structures::Cone > &  cones)

Retrieves the max consecutive distance between adjacent cones in a vector.

Parameters
filenameThe filename to be open

Definition at line 107 of file utils.cpp.

◆ extract_info()

void extract_info ( const std::string_view &  filename_view,
int &  size,
int &  n_outliers 
)

Extracts the size and number of outliers from a filename.

Parameters
filenameThe filename containing size and number of outliers information.
sizeOutput parameter to store the extracted size.
n_outliersOutput parameter to store the extracted number of outliers.

The filename should be in the format "map_{size}_{n_outliers}.txt", where:

  • "size" is an integer representing the size.
  • "n_outliers" is an integer representing the number of outliers.

Example: If filename is "map_100_5.txt", size will be set to 100 and n_outliers to 5.

Definition at line 96 of file utils.cpp.

◆ get_current_date_time_as_string()

std::string get_current_date_time_as_string ( )

Get current date and time as a string.

Returns
Current date and time as a string in "YYYY-MM-DD-HH:MM" format.

Definition at line 125 of file utils.cpp.

Here is the caller graph for this function:

◆ open_read_file()

std::ifstream open_read_file ( const std::string &  filename)

Opens a file for reading.

Parameters
filenameThe filename to be open
Returns
returns the input ifstream buffer

Definition at line 3 of file utils.cpp.

Here is the caller graph for this function:

◆ order_vector_of_pairs()

std::vector< std::pair< double, double > > order_vector_of_pairs ( const std::vector< std::pair< double, double > > &  vec)

orders a vector of pairs to make it easier to compare them

Parameters
vecvector of pairs to be ordered
Returns
ordered vector of pairs

Definition at line 118 of file utils.cpp.

◆ path_from_file()

std::vector< common_lib::structures::PathPoint > path_from_file ( const std::string &  path)

Retrieves a path point vector from a file.

Parameters
filenameThe filename to be open

Definition at line 76 of file utils.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ round_n()

float round_n ( float  num,
int  decimal_places 
)

rounds float to n decimal places

Parameters
numnumber to be rounded
decimal_placesnumber of decimal places
Returns
rounded number

Definition at line 136 of file utils.cpp.

Here is the call graph for this function:

◆ track_from_file()

std::pair< std::vector< common_lib::structures::Cone >, std::vector< common_lib::structures::Cone > > track_from_file ( const std::string &  path)

Retrieves a track (a pair of colored cone vectors from each side) from a file.

Parameters
filenameThe filename to be open

Definition at line 51 of file utils.cpp.

Here is the call graph for this function: