From ff00c4ecb69ef574bb0a19c0bcfe730bd92408ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 15 Dec 2020 13:32:30 +0100 Subject: e8 comments --- labb7/src/fast.cpp | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'labb7/src/fast.cpp') 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 bool vec_contains_vec(const vector& v1, const vector& 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& v1, const vector& 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 bool contained_in_before(const vector>& 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> lines; // all lines we want to draw - vector> angles; // for each point, the angle to every other point + // find the corresponding point with points.at(int) + vector> lines; + vector> 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(end - begin).count() + << " milliseconds." << endl; + + /////////// + // tests // + /////////// + vector v1 = {1, 2, 3}; vector v2 = {2, 3}; vector v3 = {3}; vector 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> 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(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 -- cgit v1.2.1