-
Notifications
You must be signed in to change notification settings - Fork 0
/
body_utils.h
196 lines (179 loc) · 6.39 KB
/
body_utils.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
* Utility functions to create Bodys and sets of Bodys for testing.
*/
#include "Body.h"
#include <string>
using namespace A6;
using std::string;
constexpr double PI_4 = 3.14159265358979323846 / 4.0;
Body createSquareBody(double x, double y, double sidelength)
{
double h = sidelength / sqrt(2.);
PolarVec p1{PI_4, h};
PolarVec p2{3*PI_4, h};
PolarVec p3{5*PI_4, h};
PolarVec p4{7*PI_4, h};
PolarVec vertexArray[]{ p1, p2, p3, p4, p1 };
TriFan* tf = new TriFan{vertexArray, 5};
return Body{CartVec{x,y}, CartVec{0,0}, 0, 0, tf, Colour::Black};
}
vector<Body> createSquaresOnGrid(int nHorz, double horzSpacing, int nVert, double vertSpacing, double sidelength)
{
vector<Body> squares;
for (int ny=0; ny < nVert; ++ny) {
double y = (ny + 1) * vertSpacing;
for (int nx=0; nx < nHorz; ++nx) {
double x = (nx + 1) * horzSpacing;
squares.push_back( createSquareBody(x, y, sidelength) );
}
}
return squares;
}
//
// We define a set of different configurations for testing.
//
struct Config {
vector<Body> aBodies;
vector<Body> bBodies;
};
vector<Config> allConfigs()
{
vector<Config> configs{
//
// Configs 0 - 7 have a single square in aBodies and a grid of 25x25
// squares in bBodies. The single square grows and shifts in x.
//
// 0
Config{
vector<Body>{ createSquareBody(400, 300, 10) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 1
, Config{
vector<Body>{ createSquareBody(450, 300, 10) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 2
, Config{
vector<Body>{ createSquareBody(400, 300, 100) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 3
, Config{
vector<Body>{ createSquareBody(450, 300, 100) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 4
, Config{
vector<Body>{ createSquareBody(400, 300, 200) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 5
, Config{
vector<Body>{ createSquareBody(450, 300, 200) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 6
, Config{
vector<Body>{ createSquareBody(400, 300, 300) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 7
, Config{
vector<Body>{ createSquareBody(450, 300, 300) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
//
// Configs 8 - 15 have a two squares in aBodies and a grid of 25x25
// squares in bBodies. The left square is constant, but the right
// square grows and shifts in x. The left square intersects with nothing.
//
// 8
, Config{
vector<Body>{ createSquareBody(50, 50, 10), createSquareBody(400, 300, 10) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 9
, Config{
vector<Body>{ createSquareBody(50, 50, 10), createSquareBody(450, 300, 10) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 10
, Config{
vector<Body>{ createSquareBody(50, 50, 10), createSquareBody(400, 300, 100) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 11
, Config{
vector<Body>{ createSquareBody(50, 50, 10), createSquareBody(450, 300, 100) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 12
, Config{
vector<Body>{ createSquareBody(50, 50, 10), createSquareBody(400, 300, 200) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 13
, Config{
vector<Body>{ createSquareBody(50, 50, 10), createSquareBody(450, 300, 200) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 14
, Config{
vector<Body>{ createSquareBody(50, 50, 10), createSquareBody(400, 300, 300) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 15
, Config{
vector<Body>{ createSquareBody(50, 50, 10), createSquareBody(450, 300, 300) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
//
// Configs 16 - 23 have two squares in aBodies and a grid of 25x25
// squares in bBodies. The left square is constant, but the right
// square grows and shifts in x. Here the left square always intersects
// with one body in the grid.
//
// 16
, Config{
vector<Body>{ createSquareBody(50, 50, 100), createSquareBody(400, 300, 10) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 17
, Config{
vector<Body>{ createSquareBody(50, 50, 100), createSquareBody(450, 300, 10) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 18
, Config{
vector<Body>{ createSquareBody(50, 50, 100), createSquareBody(400, 300, 100) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 19
, Config{
vector<Body>{ createSquareBody(50, 50, 100), createSquareBody(450, 300, 100) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 20
, Config{
vector<Body>{ createSquareBody(50, 50, 100), createSquareBody(400, 300, 200) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 21
, Config{
vector<Body>{ createSquareBody(50, 50, 100), createSquareBody(450, 300, 200) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 22
, Config{
vector<Body>{ createSquareBody(50, 50, 100), createSquareBody(400, 300, 300) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
// 23
, Config{
vector<Body>{ createSquareBody(50, 50, 100), createSquareBody(450, 300, 300) },
vector<Body>{ createSquaresOnGrid(5, 100, 5, 100, 20) }
}
};
return configs;
}