diff --git a/build/CMakeFiles/HLlib.dir/src/HiddenLines.cpp.o b/build/CMakeFiles/HLlib.dir/src/HiddenLines.cpp.o index 5580055..7272f45 100644 Binary files a/build/CMakeFiles/HLlib.dir/src/HiddenLines.cpp.o and b/build/CMakeFiles/HLlib.dir/src/HiddenLines.cpp.o differ diff --git a/build/libHLlib.a b/build/libHLlib.a index a9e4174..8f362f8 100644 Binary files a/build/libHLlib.a and b/build/libHLlib.a differ diff --git a/build/main b/build/main index 7077f43..683145c 100755 Binary files a/build/main and b/build/main differ diff --git a/src/HiddenLines.cpp b/src/HiddenLines.cpp index 3c42bf1..891cff0 100644 --- a/src/HiddenLines.cpp +++ b/src/HiddenLines.cpp @@ -11,6 +11,7 @@ HL::HL() { + //Read from CSV and construct the problem from the given lines lines = construct_HWprob(); } @@ -19,10 +20,12 @@ void HL::print_sol() std::cout << "Not yet implemented" << std::endl; } +//Divide and Conquer Strategy using recursive call to divide ls and merge using merge() std::set HL::gen_sol(std::set& ls){ if (ls.size() > 2){ HL inst = *this; + //Create left and right half sets int split = ceil(ls.size()/2); std::set lh; std::set rh; @@ -39,33 +42,45 @@ std::set HL::gen_sol(std::set& ls){ rh.insert(*itr); } + //Recursive call return merge(inst.gen_sol(lh), inst.gen_sol(rh)); } + //Set with 2 lines is a base case: both are visible at +-inf respectively, and intersection is where they change + //visibility else if (ls.size() == 2){ auto l1 = *(ls.begin()); auto l2 = *(ls.end()); double isec = (l2.get_ycept() - l1.get_ycept())/(l1.get_slope() - l2.get_slope()); - l1.set_vis_start(-std::numeric_limits::infinity()); - l1.set_vis_end(isec); - l2.set_vis_start(isec); - l2.set_vis_end(std::numeric_limits::infinity()); + + //Smaller Slope: vis from isec to inf + l1.set_vis_start(isec); + l1.set_vis_end(std::numeric_limits::infinity()); + + + //Greater Slope: vis from -inf to isec + l2.set_vis_start(-std::numeric_limits::infinity()); + l2.set_vis_end(isec); return ls; } + //Set with 1 line: vis at +-inf else{ auto l1 = *(ls.begin()); l1.set_vis_start(-std::numeric_limits::infinity()); l1.set_vis_end(std::numeric_limits::infinity()); + + return ls; } return sol; } std::set HL::construct_HWprob(){ - //Vector to hold all our Lines + //Set to hold all our Lines std::set lines; + //Hold our doubles from each line std::vector tmp_data; @@ -81,7 +96,7 @@ std::set HL::construct_HWprob(){ } } } - + //Close file data.close(); while(!tmp_data.empty()){ @@ -113,6 +128,15 @@ std::set merge(std::set lh, std::set rh){ while(litr != lh.end() && ritr != rh.end()){ Line l1 = *litr; Line l2 = *ritr; + + if(l1.get_slope() < l2.get_slope()){ + litr++; + continue; + } + else{ + + } + } } diff --git a/src/HiddenLines.h b/src/HiddenLines.h index 946662d..387ff33 100644 --- a/src/HiddenLines.h +++ b/src/HiddenLines.h @@ -16,13 +16,10 @@ class HL std::set get_lines(); std::set get_sol(); - private: std::set sol; std::set lines; std::set> isec; - - }; std::set merge(std::set lh, std::set rh);