Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nik karasyov exam 7 #8

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build/
drawer/testing_ground.cpp
drawer/build
drawer/glfw
drawer/shader_utils.cpp
drawer/shader_utils.h
drawer/main
2 changes: 2 additions & 0 deletions drawer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
tests.cpp
29 changes: 29 additions & 0 deletions drawer/2dDecart.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "second_dim_drawer.h"
#include <vector>
#include <boost/tuple/tuple.hpp>
#include "gnuplot-iostream.h"
#include "utility"
#include <string>
SecondDimensionDecartDrawer::SecondDimensionDecartDrawer(auto *f, double &scale, std::pair<int, int> &size) : size(size), scale(scale){
}

Gnuplot SecondDimensionDecartDrawer::Drawer(){
Gnuplot gp;

std::vector<boost::tuple<double, double> > graph;
double left_border = this->size.first * -1 / 2;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

писать this-> не нужно

double right_border = this->size.first / 2;
double bottom_border = this->size.first * -1 / 2;
double upper_border = this->size.first / 2;
for(size_t i = left_border; i != right_border; i += 0.001){
if (i * this->scale > upper_border || i * this->scale < bottom_border) continue;
graph.push_back(boost::make_tuple(
i * this->scale,
f(i) * this->scale
));
}
gp << "set xrange[" + std::string((-1) * this->size.first / 2 * scale) + ":" + std::string(* this->size.first / 2) + "]\nset yrange [" + std::string((-1) * this->size.second / 2 * scale) + ":" + std::string(* this->size.second / 2) + "\n";
return gp(graph);
}


13 changes: 13 additions & 0 deletions drawer/2dDecart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "second_dim_drawer.h"
#include "gnuplot-iostream.h"

#pragma once
class SecondDimensionDecartDrawer: SecondDimensionDrawer{
private:
double &scale;
std::pair<int, int> &size;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

храните по значению, не такая большая структура

public:
SecondDimensionDecartDrawer(auto *f, double &scale, std::pair<int, int> &size);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вы шаблонный конструктор объявили, может f можно как-то ограничить

Gnuplot Drawer();
~SecondDimensionDecartDrawer();
};
Empty file added drawer/3dDecart.cpp
Empty file.
9 changes: 9 additions & 0 deletions drawer/3dDecart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "third_dim_drawer.h"
#pragma once
class ThirdDimensionDecartDrawer: ThirdDimenstionDrawer{
private:
double **values;
public:
ThirdDimensionDecartDrawer(double **parsed_data);
~ThirdDimensionDecartDrawer();
};
33 changes: 33 additions & 0 deletions drawer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.0.0)
project(drawer VERSION 0.1.0)

include(CTest)
enable_testing()

SET(SOURCES
2dDecart.cpp
3dDecart.cpp
cylinder.cpp
drawer.cpp
polar.cpp
second_dim_drawer.cpp
spherical.cpp
third_dim_drawer.cpp
)

SET(HEADERS
2dDecart.h
3dDecart.h
cylinder.h
drawer.h
polar.h
second_dim_drawer.h
spherical.h
third_dim_drawer.h
)

add_library(drawer main.cpp)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
Empty file added drawer/cylinder.cpp
Empty file.
9 changes: 9 additions & 0 deletions drawer/cylinder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "third_dim_drawer.h"
#pragma once
class CylinderDrawer: ThirdDimensionDrawer{
private:
double **values;
public:
CylinderDrawer(double **parsed_data);
~CylinderDrawer();
};
8 changes: 8 additions & 0 deletions drawer/drawer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once
class Drawer{
private:
double **values;
public:
virtual Drawer(double **parsed_data);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

виртуальный конструктор не имеет смысла. У вас в любом случае при создании объекта вызывается его конструктор, затем все конструкторы всех родителей

virtual ~Drawer();
};
52 changes: 52 additions & 0 deletions drawer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@


// Demo of vector plot.
// Compile it with:
// g++ -o example-vector example-vector.cc -lboost_iostreams -lboost_system -lboost_filesystem

#include <vector>
#include <cmath>
#include <boost/tuple/tuple.hpp>

#include "gnuplot-iostream.h"

int main() {
Gnuplot gp;

std::vector<boost::tuple<double, double, double, double> > pts_A;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tuple есть в std


std::vector<double> pts_B_x;
std::vector<double> pts_B_y;
std::vector<double> pts_B_dx;
std::vector<double> pts_B_dy;

for(double alpha=0; alpha<1; alpha+=1.0/24.0) {
double theta = alpha*2.0*3.14159;
pts_A.push_back(boost::make_tuple(
cos(theta),
sin(theta),
-cos(theta)*0.1,
-sin(theta)*0.1
));

pts_B_x .push_back( cos(theta)*0.8);
pts_B_y .push_back( sin(theta)*0.8);
pts_B_dx.push_back( sin(theta)*0.1);
pts_B_dy.push_back(-cos(theta)*0.1);
}

// Don't forget to put "\n" at the end of each line!
gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
// '-' means read from stdin. The send1d() function sends data to gnuplot's stdin.
gp << "plot '-' with vectors title 'pts_A', '-' with vectors title 'pts_B'\n";
gp.send1d(pts_A);
gp.send1d(boost::make_tuple(pts_B_x, pts_B_y, pts_B_dx, pts_B_dy));

#ifdef _WIN32
// For Windows, prompt for a keystroke before the Gnuplot object goes out of scope so that
// the gnuplot window doesn't get closed.
std::cout << "Press enter to exit." << std::endl;
std::cin.get();
#endif
}

Empty file added drawer/polar.cpp
Empty file.
9 changes: 9 additions & 0 deletions drawer/polar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "second_dim_drawer.h"
#pragma once
class PolarDrawer: SecondDimensionDrawer{
private:
double **values;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::vector

public:
PolarDrawer(double **parsed_data);
~PolarDrawer();
};
Empty file added drawer/second_dim_drawer.cpp
Empty file.
8 changes: 8 additions & 0 deletions drawer/second_dim_drawer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "drawer.h"
#pragma once
class SecondDimensionDrawer: Drawer{
protected:
public:
virtual SecondDimensionDrawer(double **parsed_data);
virtual ~SecondDimensionDrawer();
};
Empty file added drawer/spherical.cpp
Empty file.
9 changes: 9 additions & 0 deletions drawer/spherical.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "third_dim_drawer.h"
#pragma once
class SphericalDrawer: ThirdDimensionDrawer{
private:
double **values;
public:
SphericalDrawer(double **parsed_data);
~SphericalDrawer();
};
67 changes: 67 additions & 0 deletions drawer/tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <gtest/gtest.h>
#include <iostream>

#include "polar.h"
#include "spherical.h"
#include "2dDecart.h"
#include "3dDecart.h"
#include "cylinder.h"

TEST(BINARY_TEST_1, binary_search_test) {
double a = -1;
double b = 1;
int dpi = 100;

EXPECT_EQ((abs(binary_search(a, b, dpi, f) - (-0.541)) < (b-a) / dpi) ? 0: -1, 0);
}

TEST(CALC_COUNT_TEST_1, clac_count_test) {
int n = 2;
double a = -1;
double b = 1;
int dpi = 100;
string mode = "count";
double ** values = new double*[n];
for (int i = 0; i < n; ++i){
values[i] = new double[1];
}
Calculation calculation(a, b, dpi, f, mode);
calculation.calc();
calculation.get_table(values);

EXPECT_EQ((abs(values[0][0]- (-0.541)) < (b-a) / dpi) ? 0: -1, 0);
EXPECT_EQ(values[0][1], 0);

for (int i = 0; i < n; ++i){
delete [] values[i];
}
delete[] values;
}

TEST(CALC_SIMPLE_TEST_1, clac_simple_test) {
int n = 2;
double a = -1;
double b = 1;
int dpi = 100;
string mode = "count";
double ** values = new double*[n];
for (int i = 0; i < n; ++i){
values[i] = new double[1];
}
Calculation calculation(a, b, dpi, f, mode);
calculation.calc();
calculation.get_table(values);

EXPECT_EQ((abs(values[0][0]- (-0.541)) < (b-a) / dpi) ? 0: -1, 0);
EXPECT_EQ(values[0][1], 0);

for (int i = 0; i < n; ++i){
delete [] values[i];
}
delete[] values;
}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Empty file added drawer/third_dim_drawer.cpp
Empty file.
9 changes: 9 additions & 0 deletions drawer/third_dim_drawer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "drawer.h"
#pragma once
class ThirdDimensionDrawer: Drawer{
private:
double **values;
public:
virtual ThirdDimensionDrawer(double **parsed_data);
virtual ~ThirdDimensionDrawer();
};
Empty file added testing_ground.cpp
Empty file.
Binary file added umls-Main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.