-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.cpp
67 lines (60 loc) · 1.53 KB
/
io.cpp
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
#include "io.h"
void readPositions(std::string nameFile, std::vector<Particle> *particles){
double x,y;
Particle p;
std::ifstream positionsFile(nameFile);
int I = 0;
while(positionsFile >> x >> y){
p.setPosition(x,y);
p.setIndex(I);
particles->push_back(p);
I++;
}
positionsFile.close();
};
void readFixedParticles(std::string nameFile, std::vector<Particle> *particles){
double x,y;
Particle p;
std::ifstream positionsFile(nameFile);
int I = 0;
while(positionsFile >> x >> y){
p.setPosition(x,y);
p.setIndex(I);
p.setFixed();
particles->push_back(p);
I--;
}
positionsFile.close();
};
void readRadii(std::string nameFile, std::vector<Particle> particles){
double R;
std::ifstream radiiFile(nameFile);
for(auto &p: particles){
radiiFile >> R;
p.setRadius(R);
}
radiiFile.close();
};
void readMasses(std::string nameFile, std::vector<Particle> particles){
double mass;
std::ifstream massFile(nameFile);
for(auto &p: particles){
massFile >> mass;
p.setMass(mass);
}
massFile.close();
};
void readWalls(std::string nameFile, std::vector<Wall> *walls){
double x1, x2, y1, y2, n1, n2;
std::ifstream wallFile(nameFile);
int I = -1;
while(wallFile >> x1 >> x2 >> y1 >> y2 >> n1 >> n2)
{
Wall w(x1, x2, y1, y2);
w.setNormal(Vec2D(n1, n2));
w.setIndex(I);
walls->push_back(w);
I--;
}
wallFile.close();
};