-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Changes from all commits
74645ca
08808ac
2246109
c0b827f
ffc5437
cf06cf5
4ca95f2
a64fe8d
c5e5186
612ff53
4836b4c
7fb0ec5
ccf0bbf
23ec881
2c59f8a
392687b
3bf4541
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build/ | ||
tests.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; | ||
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); | ||
} | ||
|
||
|
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. храните по значению, не такая большая структура |
||
public: | ||
SecondDimensionDecartDrawer(auto *f, double &scale, std::pair<int, int> &size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вы шаблонный конструктор объявили, может f можно как-то ограничить |
||
Gnuplot Drawer(); | ||
~SecondDimensionDecartDrawer(); | ||
}; |
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(); | ||
}; |
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) |
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(); | ||
}; |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. виртуальный конструктор не имеет смысла. У вас в любом случае при создании объекта вызывается его конструктор, затем все конструкторы всех родителей |
||
virtual ~Drawer(); | ||
}; |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. std::vector |
||
public: | ||
PolarDrawer(double **parsed_data); | ||
~PolarDrawer(); | ||
}; |
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(); | ||
}; |
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(); | ||
}; |
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(); | ||
} |
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(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
писать this-> не нужно