Skip to content

Commit fd3e720

Browse files
committed
Library structure (headers only) and new cmake
Files and folder rearrangement 2 New library structure.
1 parent ccc7020 commit fd3e720

File tree

14 files changed

+592
-686
lines changed

14 files changed

+592
-686
lines changed

CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Please modify this file freely to adapt to the production of other
2+
## executables than convexhull and testrun
3+
14
# Recent version of CMake required
25
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
36

@@ -42,18 +45,23 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wshadow")
4245
# Might need to be fixed for retrocompatibility or temporary
4346
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++0x-compat -Wno-unused")
4447

45-
#Bring the headers into the project
46-
include_directories(${PROJECT_SOURCE_DIR}/include)
47-
48-
#Bring the sources
49-
file(GLOB SOURCES "src/*.cpp")
48+
#Bring the headers of the header-only CompressedStack library into the project
49+
include_directories(
50+
${PROJECT_SOURCE_DIR}/include
51+
${PROJECT_SOURCE_DIR}/examples/convexhull/include ${PROJECT_SOURCE_DIR}/examples/testrun/include
52+
)
5053

5154
# Test directories
5255
get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
5356
message("inc_dirs = ${inc_dirs}")
5457

55-
# Executable
56-
add_executable(smartstack ${SOURCES})
58+
# Convex Hull
59+
file(GLOB SOURCES "examples/convexhull/*.cpp")
60+
add_executable(convexhull ${SOURCES})
61+
62+
# Test Run
63+
file(GLOB SOURCES "examples/testrun/*.cpp")
64+
add_executable(testrun ${SOURCES})
5765

5866

5967
# Description of the different builds

examples/convexhull/convexHull.cpp

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
// ConvexHull : Implementation
2+
3+
/*==============================================================================
4+
Includes
5+
==============================================================================*/
6+
#include "include/convexHull.hpp"
7+
8+
/*==============================================================================
9+
Stack functions to define the Convex Hull algorithm with Compressed Stack
10+
* readInput
11+
* initStack
12+
* popCondition
13+
* prePop
14+
* postPop
15+
* noPop
16+
* pushCondition
17+
* prePush
18+
* postPush
19+
* noPush
20+
* reportStack
21+
==============================================================================*/
22+
Point2D ConvexHull::readInput(std::vector<std::string> line) {
23+
double x = std::stof(line[0]);
24+
double y = std::stof(line[1]);
25+
26+
Point2D p(x, y);
27+
28+
std::cout << "I JUST READ " << p << std::endl;
29+
return p;
30+
}
31+
32+
std::shared_ptr<emptyContext> ConvexHull::initStack() {
33+
34+
std::cout << "going to read two values " << std::endl;
35+
36+
// first, read and push two values
37+
readPush(2);
38+
39+
std::cout << "done reading two values " << std::endl;
40+
41+
// then initialize context (which in this case is NULL everything
42+
std::shared_ptr<emptyContext> context;
43+
return context;
44+
}
45+
46+
bool ConvexHull::popCondition(Point2D last) {
47+
Point2D minus1, minus2;
48+
49+
std::cout << last << " <<<< pop condition enter " << std::endl;
50+
51+
// read the two previous elements
52+
minus1 = top(1).getData();
53+
minus2 = top(2).getData();
54+
55+
std::cout << last << " <<<< pop condition read two before " << minus1
56+
<< minus2 << std::endl;
57+
58+
if (Point2D::orientation(minus2, minus1, last) == 2) {
59+
std::cout << last << " <<<< pop condition returning true " << std::endl;
60+
61+
return true;
62+
}
63+
std::cout << last << " <<<< pop condition returning false " << std::endl;
64+
65+
return false;
66+
}
67+
void ConvexHull::prePop(Point2D data) {}
68+
void ConvexHull::postPop(Point2D data, Data<emptyContext, Point2D> elt) {
69+
std::cout << elt.getData() << " <<<< Pop!" << std::endl;
70+
}
71+
void ConvexHull::noPop(Point2D data) {}
72+
73+
bool ConvexHull::pushCondition(Point2D data) {
74+
std::cout << data << " <<<< push condition returning true " << std::endl;
75+
return true;
76+
}
77+
void ConvexHull::prePush(Data<emptyContext, Point2D> elt) {}
78+
void ConvexHull::postPush(Data<emptyContext, Point2D> elt) {
79+
std::cout << "ConvexHullStackAlgo::pushAction Nothing to see here "
80+
<< elt.getData() << std::endl;
81+
}
82+
void ConvexHull::noPush(Point2D data) {}
83+
84+
void ConvexHull::reportStack() {}
85+
86+
/*==============================================================================
87+
Stack functions to define the Convex Hull algorithm with Stack comparison
88+
* readInput
89+
* initStack
90+
* popCondition
91+
* prePop
92+
* postPop
93+
* noPop
94+
* pushCondition
95+
* prePush
96+
* postPush
97+
* noPush
98+
* reportStack
99+
==============================================================================*/
100+
Point2D ComparisonConvexHull::readInput(std::vector<std::string> line) {
101+
double x = std::stof(line[0]);
102+
double y = std::stof(line[1]);
103+
104+
Point2D p(x, y);
105+
106+
std::cout << "I JUST READ " << p << std::endl;
107+
108+
return p;
109+
}
110+
111+
std::shared_ptr<emptyContext> ComparisonConvexHull::initStack() {
112+
std::cout << "going to read two values " << std::endl;
113+
114+
// first, read and push two values
115+
readPush(2);
116+
117+
printCompare();
118+
119+
std::cout << "done reading two values " << std::endl;
120+
// then initialize context (which in this case is NULL everything
121+
std::shared_ptr<emptyContext> context;
122+
return context;
123+
}
124+
125+
bool ComparisonConvexHull::popCondition(Point2D last) {
126+
Point2D minus1, minus2;
127+
128+
std::cout << last << " <<<< pop condition enter " << std::endl;
129+
130+
// read the two previous elements
131+
minus1 = top(1).getData();
132+
minus2 = top(2).getData();
133+
134+
std::cout << last << " <<<< pop condition read two before " << minus1
135+
<< minus2 << std::endl;
136+
137+
if (Point2D::orientation(minus2, minus1, last) == 2) {
138+
std::cout << last << " <<<< pop condition returning true " << std::endl;
139+
140+
return true;
141+
}
142+
std::cout << last << " <<<< pop condition returning false " << std::endl;
143+
144+
return false;
145+
}
146+
void ComparisonConvexHull::prePop(Point2D data) {}
147+
void ComparisonConvexHull::postPop(Point2D data,
148+
Data<emptyContext, Point2D> elt) {
149+
std::cout << elt.getData() << " <<<< Pop!" << std::endl;
150+
}
151+
void ComparisonConvexHull::noPop(Point2D data) {}
152+
153+
bool ComparisonConvexHull::pushCondition(Point2D data) {
154+
std::cout << data << " <<<< push condition returning true " << std::endl;
155+
return true;
156+
}
157+
void ComparisonConvexHull::prePush(Data<emptyContext, Point2D> elt) {}
158+
void ComparisonConvexHull::postPush(Data<emptyContext, Point2D> elt) {
159+
std::cout << "ConvexHullStackAlgo::pushAction Nothing to see here "
160+
<< elt.getData() << std::endl;
161+
}
162+
void ComparisonConvexHull::noPush(Point2D data) {}
163+
164+
void ComparisonConvexHull::reportStack() {}
165+
166+
/*==============================================================================
167+
How to use
168+
* argv[1] is the file name
169+
* argv[2] is the code of what is to be done (is no space provided -> 0)
170+
* 0 is a convex hull problem with a classical stack
171+
* 1 is a convex hull problem with a compressed stack
172+
* 2 is a convex hull problem with both stacks comparison (check errors)
173+
==============================================================================*/
174+
int main(int argc, char *argv[]) {
175+
// Getting the path of the instance to test
176+
std::string filepath = argv[1];
177+
178+
switch (atoi(argv[2])) {
179+
case 0: {
180+
ConvexHull stack(filepath, true);
181+
stack.run();
182+
stack.println();
183+
break;
184+
}
185+
case 1: {
186+
ConvexHull stack(filepath);
187+
stack.run();
188+
stack.println();
189+
break;
190+
}
191+
default: {
192+
ComparisonConvexHull stack(filepath);
193+
stack.runCompare();
194+
stack.println();
195+
break;
196+
}
197+
}
198+
return 0;
199+
}

include/convexHull.hpp renamed to examples/convexhull/include/convexHull.hpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
#include "compare.hpp"
1+
// ConvexHull : Definition
2+
#ifndef CONVEXHULL
3+
#define CONVEXHULL
4+
5+
/*==============================================================================
6+
Includes
7+
==============================================================================*/
8+
//#include "../../../include/stackAlgo.hpp" // Not necessary with compare.hpp
9+
#include "../../../include/compare.hpp"
210
#include "point2D.hpp"
3-
#include "stackAlgo.hpp"
411

512
/*==============================================================================
613
Empty type for the context (empty for the Convex Hull problem)
@@ -10,10 +17,10 @@ class emptyContext {};
1017
/*==============================================================================
1118
Instantiation of a problem
1219
==============================================================================*/
13-
class convexHull : public StackAlgo<emptyContext, Point2D> {
20+
class ConvexHull : public StackAlgo<emptyContext, Point2D> {
1421
public:
15-
convexHull(std::string filePath)
16-
: StackAlgo<emptyContext, Point2D>(filePath) {}
22+
ConvexHull(std::string filePath, bool useclassic = false)
23+
: StackAlgo<emptyContext, Point2D>(filePath, useclassic) {}
1724

1825
private:
1926
// Functions to run the stack
@@ -37,9 +44,9 @@ class convexHull : public StackAlgo<emptyContext, Point2D> {
3744
Instantiation of a comparison
3845
==============================================================================*/
3946

40-
class comparisonConvexHull : public CompareStacks<emptyContext, Point2D> {
47+
class ComparisonConvexHull : public CompareStacks<emptyContext, Point2D> {
4148
public:
42-
comparisonConvexHull(std::string filePath)
49+
ComparisonConvexHull(std::string filePath)
4350
: CompareStacks<emptyContext, Point2D>(filePath) {}
4451

4552
private:
@@ -59,3 +66,5 @@ class comparisonConvexHull : public CompareStacks<emptyContext, Point2D> {
5966

6067
void reportStack();
6168
};
69+
70+
#endif // CONVEXHULL

0 commit comments

Comments
 (0)