Skip to content

Commit

Permalink
code beautify
Browse files Browse the repository at this point in the history
  • Loading branch information
UmbrellaLeaf5 committed May 13, 2024
1 parent 85e11eb commit 68a10f6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
5 changes: 4 additions & 1 deletion data_tools/plot_area/check_errors.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "math/optimal_way/helpers_functions.h"
// header file:
#include "plot_area.h"

// our code libs:
#include "math/optimal_way/helpers_functions.h"

namespace data_tools {

bool IsPointInsideHill(lib::Point point, std::vector<lib::Point> vertices) {
Expand Down
1 change: 0 additions & 1 deletion gui/_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "airport.h"
#include "flying_robot.h"
#include "hill.h"
#include "target.h"
#include "trajectory.h"
#include "trappy_circle.h"
#include "trappy_line.h"
32 changes: 25 additions & 7 deletions gui/flying_robot.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
// header file:
#include "flying_robot.h"

void gui::FlyingRobot::SetNewPositionOnLine() {
namespace gui {

void FlyingRobot::SetTrajectory(Trajectory* trj) {
trajectory_ = trj;
if (!trajectory_) return;

curr_point_ = trj->Segments()[0].Start();
index_of_segment_ = 0;

if (trajectory_->Segments()[0].IsArc())
UpdateCircleFields();
else
UpdateLineFields();
}

void FlyingRobot::SetNewPositionOnLine() {
if (count_of_partitions_ == 0) {
UpdateSegment();
} else {
Expand All @@ -13,7 +29,7 @@ void gui::FlyingRobot::SetNewPositionOnLine() {
}
}

void gui::FlyingRobot::SetNewPositionOnCircle() {
void FlyingRobot::SetNewPositionOnCircle() {
if (count_of_partitions_ == 0)
UpdateSegment();
else {
Expand All @@ -33,7 +49,7 @@ void gui::FlyingRobot::SetNewPositionOnCircle() {
}
}

void gui::FlyingRobot::UpdateSegment() {
void FlyingRobot::UpdateSegment() {
index_of_segment_++;

if (index_of_segment_ == trajectory_->Segments().size())
Expand All @@ -47,7 +63,7 @@ void gui::FlyingRobot::UpdateSegment() {
UpdateLineFields();
}

void gui::FlyingRobot::UpdateLineFields() {
void FlyingRobot::UpdateLineFields() {
lib::Point p = trajectory_->Segments()[index_of_segment_].End() -
trajectory_->Segments()[index_of_segment_].Start();
double R = sqrt(p.x * p.x + p.y * p.y);
Expand Down Expand Up @@ -76,7 +92,7 @@ void gui::FlyingRobot::UpdateLineFields() {
sin_of_line_ = p.y / R;
}

void gui::FlyingRobot::UpdateCircleFields() {
void FlyingRobot::UpdateCircleFields() {
auto angles = trajectory_->Segments()[index_of_segment_].ToAnglesOnCircle();

double len_sector = trajectory_->Segments()[index_of_segment_].Radius() *
Expand Down Expand Up @@ -107,7 +123,7 @@ void gui::FlyingRobot::UpdateCircleFields() {
clockwise_ = false;
}

void gui::FlyingRobot::Draw(QCustomPlot* plot) {
void FlyingRobot::Draw(QCustomPlot* plot) {
if (!trajectory_) throw std::invalid_argument("The trajectory is not built!");

graph_ = plot->addGraph(plot->xAxis, plot->yAxis);
Expand All @@ -119,7 +135,7 @@ void gui::FlyingRobot::Draw(QCustomPlot* plot) {
graph_->setData({curr_point_.x}, {curr_point_.y});
}

void gui::FlyingRobot::ReDraw(QCustomPlot* plot) {
void FlyingRobot::ReDraw(QCustomPlot* plot) {
if (trajectory_->Segments()[index_of_segment_].IsArc())
SetNewPositionOnCircle();
else
Expand All @@ -129,3 +145,5 @@ void gui::FlyingRobot::ReDraw(QCustomPlot* plot) {

plot->replot();
}

} // namespace gui
17 changes: 2 additions & 15 deletions gui/flying_robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FlyingRobot : public Drawable {

/**
* @brief Инициализирует новый экземпляр FlyingRobot
* @param gui::Trajectory: траетория
* @param gui::Trajectory: траектория
*/
FlyingRobot(gui::Trajectory* trj)
: trajectory_{trj}, curr_point_{trj->Segments()[0].Start()} {
Expand All @@ -34,27 +34,14 @@ class FlyingRobot : public Drawable {
*/
void Draw(QCustomPlot* plot) override;

void UnDraw(QCustomPlot* plot);

/**
* @brief Эта функция нужна для того, чтобы обновлять позицию картинки на
* полотне
* @param plot: указатель на полотно
*/
void ReDraw(QCustomPlot* plot);

void SetTrajectory(gui::Trajectory* trj) {
trajectory_ = trj;
if (!trajectory_) return;

curr_point_ = trj->Segments()[0].Start();
index_of_segment_ = 0;

if (trajectory_->Segments()[0].IsArc())
UpdateCircleFields();
else
UpdateLineFields();
}
void SetTrajectory(gui::Trajectory* trj);

gui::Trajectory* GetTrajectory() const { return trajectory_; }

Expand Down
3 changes: 2 additions & 1 deletion math/optimal_way/helpers_functions.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// header file:
#include "helpers_functions.h"

#include <QDebug>
// std libs:
#include <algorithm>

namespace math {
Expand Down

0 comments on commit 68a10f6

Please sign in to comment.