88#include " ../../../include/stackAlgo.hpp"
99#include " point2D.hpp"
1010
11-
12- double pops=0 ;
13- double total=0 ;
11+ double pops = 0 ;
12+ double total = 0 ;
1413
1514/* ==============================================================================
1615 Empty type for the context (empty for the Convex Hull problem)
@@ -65,7 +64,7 @@ Point2D ConvexHull<I>::readInput(std::vector<std::string> line) {
6564
6665 Point2D p (x, y);
6766
68- // std::cout << "I JUST READ " << p << std::endl;
67+ // std::cout << "I JUST READ " << p << std::endl;
6968 return p;
7069}
7170
@@ -74,8 +73,7 @@ template <class I> std::shared_ptr<emptyContext> ConvexHull<I>::initStack() {
7473 std::cout << " going to read two values " << std::endl;
7574
7675 // first, read and push two values
77- StackAlgo<emptyContext, Point2D, I>::readPush (1 );
78- StackAlgo<emptyContext, Point2D, I>::readPush (1 );
76+ StackAlgo<emptyContext, Point2D, I>::readPush (2 );
7977
8078 std::cout << " done reading two values " << std::endl;
8179
@@ -86,31 +84,40 @@ template <class I> std::shared_ptr<emptyContext> ConvexHull<I>::initStack() {
8684
8785template <class I > bool ConvexHull<I>::popCondition(Point2D last) {
8886 Point2D minus1, minus2;
89- total++;
90- std::cout << last << " <<<< pop condition enter " << std::endl;
87+ total++;
88+ std::cout << std::endl << last << " <<<< pop condition enter " << std::endl;
9189 StackAlgo<emptyContext, Point2D, I>::println ();
9290
9391 // read the two previous elements
9492 minus1 = StackAlgo<emptyContext, Point2D, I>::top (1 ).getData ();
93+ if (StackAlgo<emptyContext, Point2D, I>::mStack ->getBufferLength () < 2 ) {
94+ return true ;
95+ }
96+
9597 minus2 = StackAlgo<emptyContext, Point2D, I>::top (2 ).getData ();
9698
97- std::cout << last << " <<<< pop condition read two before " << minus2<< minus1 << std::endl;
99+ std::cout << last << " <<<< pop condition read two before " << minus2
100+ << minus1 << std::endl;
98101
99102 if (Point2D::orientation (minus2, minus1, last) == 1 ) {
100103 pops++;
101- std::cout << last << " <<<< pop condition returning true " <<pops/total<<" tot " <<total << std::endl;
104+ std::cout << last
105+ << " <<<< "
106+ " pop condition returning true "
107+ << pops / total << " tot " << total << std::endl;
102108
103109 return true ;
104110 }
105- std::cout << last << " <<<< pop condition returning false " <<pops/total<<" tot " <<total << std::endl;
106-
111+ std::cout << last << " "
112+ " <<<< pop condition returning false "
113+ << pops / total << " tot " << total << std::endl;
107114
108115 return false ;
109116}
110117template <class I > void ConvexHull<I>::prePop(Point2D data) {}
111118template <class I >
112119void ConvexHull<I>::postPop(Point2D data, Data<emptyContext, Point2D, I> elt) {
113- std::cout << elt.getData () << " <<<< Pop!" << std::endl;
120+ std::cout << elt.getData () << " <<<< (post-) Pop!" << std::endl;
114121}
115122template <class I > void ConvexHull<I>::noPop(Point2D data) {}
116123
@@ -122,7 +129,8 @@ template <class I>
122129void ConvexHull<I>::prePush(Data<emptyContext, Point2D, I> elt) {}
123130template <class I >
124131void ConvexHull<I>::postPush(Data<emptyContext, Point2D, I> elt) {
125- std::cout << " ConvexHullStackAlgo::pushAction Nothing to see here " << elt.getData () << std::endl;
132+ std::cout << " ConvexHullStackAlgo::pushAction Nothing to see here "
133+ << elt.getData () << std::endl;
126134}
127135template <class I > void ConvexHull<I>::noPush(Point2D data) {}
128136
0 commit comments