-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitPoints.h
88 lines (61 loc) · 2.3 KB
/
InitPoints.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include <random>
#include "Instrumentor.h"
std::pair<int, std::string> InitializeRandomPointsFile(int numOfPoints, int boundaries)
{
PROFILE_FUNCTION();
std::random_device rd;
std::mt19937 g(rd());
std::uniform_real_distribution<double> distribution(-boundaries, boundaries);
std::ofstream outFile;
std::string fileName("test_points/Init_Test_Points_" + std::to_string(numOfPoints) + ".txt");
outFile.open(fileName);
outFile << std::fixed << std::setprecision(11);
if (outFile) {
for (int i = 0; i < numOfPoints - 1; ++i) {
outFile << "(" << 0.0 + distribution(g) << "," << 1.0 * distribution(g) << "), \n";
}
outFile << "(" << 0.0 + distribution(g) << "," << 1.0 * distribution(g) << ")" << std::endl;
outFile.close();
return std::pair< int, std::string>(numOfPoints, fileName);
}
else {
std::cerr << "Could not open File!" << std::endl;
return std::pair<int, std::string>();
}
}
std::pair<int, std::string> InitializeRandomPointsCircleFile(int numOfPoints, int boundaries)
{
PROFILE_FUNCTION();
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 rngAngle(seed);
seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 rngRadius(seed);
std::uniform_real_distribution<double> angleDistribution(0, 360);
std::uniform_real_distribution<double> radiusDistribution(0, boundaries);
double angle, radius, x, y;
std::string fileName("test_points/Circle_Test_Points_" + std::to_string(numOfPoints) + ".txt");
std::ofstream outFile;
outFile.open(fileName);
outFile << std::fixed << std::setprecision(9);
if (outFile) {
for (int i = 0; i < numOfPoints - 1; i++) {
angle = angleDistribution(rngAngle);
radius = radiusDistribution(rngRadius);
x = radius * sin(angle);
y = radius * cos(angle);
outFile << "(" << x << ", " << y << "), \n";
}
angle = angleDistribution(rngAngle);
radius = radiusDistribution(rngRadius);
x = radius * sin(angle);
y = radius * cos(angle);
outFile << "(" << x << ", " << y << ")" << std::endl;
outFile.close();
return std::pair< int, std::string>(numOfPoints, fileName);
}
else {
std::cerr << "Could not open File!" << std::endl;
return std::pair<int, std::string>();
}
}