diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-12-15 13:32:30 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-12-15 13:34:36 +0100 |
| commit | ff00c4ecb69ef574bb0a19c0bcfe730bd92408ea (patch) | |
| tree | 5810dc1c73401dbd851807ed67722be97c7b5c31 | |
| parent | fa32f97c3617381eec9d9f4736ae94dd284d1617 (diff) | |
| download | tddd86-ff00c4ecb69ef574bb0a19c0bcfe730bd92408ea.tar.gz | |
e8 commentse8
| -rw-r--r-- | labb7/src/fast.cpp | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/labb7/src/fast.cpp b/labb7/src/fast.cpp index e01af2d..edce769 100644 --- a/labb7/src/fast.cpp +++ b/labb7/src/fast.cpp @@ -30,6 +30,7 @@ void render_line(QGraphicsScene* scene, const Point& p1, const Point& p2) { template <typename T> bool vec_contains_vec(const vector<T>& v1, const vector<T>& v2) { if (v2.size() == 0) { + // every vector contains the empty vector return true; } int i1 = 0; @@ -49,7 +50,7 @@ bool vec_contains_vec(const vector<T>& v1, const vector<T>& v2) { } /* - * Return whether inner is contained in some vector before itself in outer. + * Return whether some vector is contained in some other vector before itself. */ template <typename T> bool contained_in_before(const vector<vector<T>>& outer, int index) { @@ -100,8 +101,9 @@ int main(int argc, char *argv[]) { auto begin = chrono::high_resolution_clock::now(); // these contain indexes since points can't be compared - vector<vector<int>> lines; // all lines we want to draw - vector<pair<double, int>> angles; // for each point, the angle to every other point + // find the corresponding point with points.at(int) + vector<vector<int>> lines; + vector<pair<double, int>> angles; for (int p1 = 0; p1 < N-1; p1++) { angles.clear(); @@ -114,8 +116,10 @@ int main(int argc, char *argv[]) { for (int i = 2; i < angles.size(); i++) { double prev_angle = angles[i - 1].first; if (angles[i].first == prev_angle) { + // start of potential line line.push_back(angles[i].second); } else { + // end of potential line if (line.size() >= 4) { lines.push_back(line); } @@ -131,7 +135,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < lines.size();) { if (contained_in_before(lines, i)) { - lines.erase(lines.begin() + i); + lines.erase(lines.begin() + i); //NOTE should check before inserting instead } else { i++; } @@ -142,24 +146,28 @@ int main(int argc, char *argv[]) { } cout << lines.size() << " draws" << endl; + auto end = chrono::high_resolution_clock::now(); + cout << "Computing line segments took " + << std::chrono::duration_cast<chrono::milliseconds>(end - begin).count() + << " milliseconds." << endl; + + /////////// + // tests // + /////////// + vector<int> v1 = {1, 2, 3}; vector<int> v2 = {2, 3}; vector<int> v3 = {3}; vector<int> v4 = {2, 3, 4}; - cout << vec_contains_vec(v1, v2) << " " - << vec_contains_vec(v2, v1) << " " - << vec_contains_vec(v1, v3) << " " - << vec_contains_vec(v1, v4) << endl; + cout << vec_contains_vec(v1, v2) << " " // expect true + << vec_contains_vec(v2, v1) << " " // expect false + << vec_contains_vec(v1, v3) << " " // expect true + << vec_contains_vec(v1, v4) << endl; // expect false vector<vector<int>> outer = {{1,2,3}, {2,3}, {3,4}}; - cout << contained_in_before(outer, 0) << " " - << contained_in_before(outer, 1) << " " - << contained_in_before(outer, 2) << endl; - - auto end = chrono::high_resolution_clock::now(); - cout << "Computing line segments took " - << std::chrono::duration_cast<chrono::milliseconds>(end - begin).count() - << " milliseconds." << endl; + cout << contained_in_before(outer, 0) << " " // expect false + << contained_in_before(outer, 1) << " " // expect true + << contained_in_before(outer, 2) << endl; // expect false view->show(); return a.exec(); // start Qt event loop |
