diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..afcc6ece13429635727745fb7d84fd8e2a48f629 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,68 @@ +{ + "files.associations": { + "any": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp", + "variant": "cpp" + } +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 01ff39dbe3f11ba0f5ec07c12f8d79a3b3ed1b19..d1a3823c306c5e8f0f3a8fd4e5b01cae727e50b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,18 +22,19 @@ add_executable( tests tests/unit_tests/simple_triangle_tests.cpp tests/unit_tests/contourize_tests.cpp - src/intersections/intersections.cpp + tests/unit_tests/point_in_triangle_tests.cpp + src/utilities/intersections.cpp src/shapes/triangle.cpp src/shapes/triangle_edges.cpp - src/contourize/contourize.cpp + src/utilities/contourize.cpp src/shapes/edge.cpp - src/orientation/orientation.cpp + src/utilities/orientation.cpp src/shapes/point.cpp src/union.cpp - src/triangulation/triangulation.cpp + src/utilities/triangulation.cpp ) -include_directories(src) +include_directories(include) target_link_libraries( tests diff --git a/src/contourize/contourize.h b/include/contourize.h similarity index 100% rename from src/contourize/contourize.h rename to include/contourize.h diff --git a/src/shapes/edge.h b/include/edge.h similarity index 100% rename from src/shapes/edge.h rename to include/edge.h diff --git a/src/intersections/intersections.h b/include/intersections.h similarity index 72% rename from src/intersections/intersections.h rename to include/intersections.h index ca089a03a1e43d3277efffe481da7c664e926cc7..952d64f0bb1864b5f61bbd18cd524304eb97b866 100644 --- a/src/intersections/intersections.h +++ b/include/intersections.h @@ -1,7 +1,6 @@ #pragma once #include <vector> -#include "../shapes/point.h" -#include "../shapes/triangle.h" +#include <triangle.h> struct TrigTrigInterResults { std::vector<Point> results; diff --git a/src/orientation/orientation.h b/include/orientation.h similarity index 100% rename from src/orientation/orientation.h rename to include/orientation.h diff --git a/src/shapes/point.h b/include/point.h similarity index 100% rename from src/shapes/point.h rename to include/point.h diff --git a/src/static_vector/static_vector.h b/include/static_vector.h similarity index 100% rename from src/static_vector/static_vector.h rename to include/static_vector.h diff --git a/src/shapes/triangle.h b/include/triangle.h similarity index 86% rename from src/shapes/triangle.h rename to include/triangle.h index 32b2315f710200844d8b71674dbfde0449568bdb..f95e6070fcd30bf491edb1a93d707c636e6daf2b 100644 --- a/src/shapes/triangle.h +++ b/include/triangle.h @@ -1,7 +1,7 @@ #pragma once #include "point.h" -// points specified clockwise +// points specified counterclockwise struct Triangle { Point points[3]; int depth; diff --git a/src/shapes/triangle_edges.h b/include/triangle_edges.h similarity index 100% rename from src/shapes/triangle_edges.h rename to include/triangle_edges.h diff --git a/include/triangulation.h b/include/triangulation.h new file mode 100644 index 0000000000000000000000000000000000000000..299914a58d4cb7707fdf3057c9beda955796ca40 --- /dev/null +++ b/include/triangulation.h @@ -0,0 +1,9 @@ +#pragma once +#include <vector> + +struct Triangle; +struct Point; + + +std::vector<Triangle> triangulate(std::vector<Point> points); + diff --git a/src/union.h b/include/union.h similarity index 85% rename from src/union.h rename to include/union.h index c6bca294f6b9d86e47c24060250b088da177ff59..3aeaae906cfbc8a4c1c3ca299d799711dff68c98 100644 --- a/src/union.h +++ b/include/union.h @@ -1,5 +1,6 @@ #pragma once #include <vector> +struct Triangle; std::vector<Triangle> unionize(const Triangle &t1, const Triangle &t2); \ No newline at end of file diff --git a/src/shapes/triangle.cpp b/src/shapes/triangle.cpp index 10229a50976e495b824f04ee961cc9a2e37826cf..c07c9a43df9cf59f0f15e5343aeb38893ac19dd5 100644 --- a/src/shapes/triangle.cpp +++ b/src/shapes/triangle.cpp @@ -12,7 +12,7 @@ bool Triangle::pointInTriangle(const Point &p) const { // all tests must be positive auto edges = TriangleEdges(*this); - return edges.e1.positiveSide(p) && - edges.e2.positiveSide(p) && - edges.e3.positiveSide(p); + return !edges.e1.positiveSide(p) && + !edges.e2.positiveSide(p) && + !edges.e3.positiveSide(p); } \ No newline at end of file diff --git a/src/triangulation/triangulation.cpp b/src/triangulation/triangulation.cpp deleted file mode 100644 index bbd45b7ac106dade9d3418637f5e72a0996c0b9e..0000000000000000000000000000000000000000 --- a/src/triangulation/triangulation.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "triangulation.h" - -std::vector<Triangle> monotoneTriangulate(std::vector<Point> &points) { - -} \ No newline at end of file diff --git a/src/triangulation/triangulation.h b/src/triangulation/triangulation.h deleted file mode 100644 index 30317cb0ed0b6e6b1d7bad0325d3b31afdbbef0b..0000000000000000000000000000000000000000 --- a/src/triangulation/triangulation.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include <vector> - -struct Triangle; -struct Point; - -std::vector<Triangle> monotoneTriangulate(std::vector<Point> &points); \ No newline at end of file diff --git a/src/union.cpp b/src/union.cpp index 09d7fb6b5d15c643717b256da4da64186a479ab7..54a9e90c4338f50d4c5e251db88d9cc0ff49883e 100644 --- a/src/union.cpp +++ b/src/union.cpp @@ -1,10 +1,9 @@ -#include "shapes/triangle.h" #include <vector> #include <optional> -#include <intersections/intersections.h> -#include <contourize/contourize.h> -#include <triangulation/triangulation.h> #include <union.h> +#include <contourize.h> +#include <intersections.h> +#include <triangulation.h> std::vector<Triangle> unionize(const Triangle &t1, const Triangle &t2) { @@ -23,7 +22,7 @@ std::vector<Triangle> unionize(const Triangle &t1, const Triangle &t2) { std::vector<Point> contour = contourize(t1, t2, newIntersections); - return monotoneTriangulate(contour); + return triangulate(contour); } void unionize(Triangle soup) { diff --git a/src/contourize/contourize.cpp b/src/utilities/contourize.cpp similarity index 96% rename from src/contourize/contourize.cpp rename to src/utilities/contourize.cpp index e33f59d61fd54ccd2fc1f076779c88e65b6c7d64..668b70ec775f164d337f981c9dbb76af5e80d895 100644 --- a/src/contourize/contourize.cpp +++ b/src/utilities/contourize.cpp @@ -1,7 +1,6 @@ -#include <shapes/triangle.h> #include <vector> -#include "contourize.h" -#include <orientation/orientation.h> +#include <triangle.h> +#include <orientation.h> Triangle clockwiseToCounterclockwise(const Triangle &t) { return Triangle(t.points[0], t.points[2], t.points[1], t.depth); diff --git a/src/intersections/intersections.cpp b/src/utilities/intersections.cpp similarity index 95% rename from src/intersections/intersections.cpp rename to src/utilities/intersections.cpp index c6b1ec18d7c668d106df70f6f12b16a74f804f24..8b299f4ce682b917823c375b3723ba9fa83d58ea 100644 --- a/src/intersections/intersections.cpp +++ b/src/utilities/intersections.cpp @@ -1,8 +1,7 @@ #include "intersections.h" -#include <shapes/edge.h> -#include <shapes/triangle_edges.h> -#include <shapes/point.h> #include <optional> +#include <edge.h> +#include <triangle_edges.h> diff --git a/src/orientation/orientation.cpp b/src/utilities/orientation.cpp similarity index 91% rename from src/orientation/orientation.cpp rename to src/utilities/orientation.cpp index ee414a801b0c335b2531ec0372ff92441365da08..14817eb038df3f13cb63b9a16571aa6bd12f5844 100644 --- a/src/orientation/orientation.cpp +++ b/src/utilities/orientation.cpp @@ -1,5 +1,5 @@ #include "orientation.h" -#include <shapes/point.h> +#include <point.h> Orientation orientation(const Point &p1, const Point &p2, const Point &p3) { int val = (p2.y - p1.y) * (p3.x - p2.x) - (p2.x - p1.x) * (p3.y - p2.y); diff --git a/src/utilities/triangulation.cpp b/src/utilities/triangulation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..186976e81e96f0af04cf2fd739f880cbce09c51e --- /dev/null +++ b/src/utilities/triangulation.cpp @@ -0,0 +1,21 @@ +#include "triangulation.h" +#include <list> +#include <point.h> +#include <triangle.h> +/* +bool isAnEar(Point point, Triangle triangle, Point start[], Point end[]) { + +} +*/ + +std::vector<Triangle> triangulate(std::vector<Point> points) { + //std::list<Point> polygon = std::list(points); + std::vector<Triangle> result; + + for (int i = 0; i < points.size(); i++) { + + } + + return result; + +} \ No newline at end of file diff --git a/tests/unit_tests/contourize_tests.cpp b/tests/unit_tests/contourize_tests.cpp index 27e318d41095b9147574d4f075a39859315a7a25..93bda8d73bb452f1d2b12bfb3a59231048027f4f 100644 --- a/tests/unit_tests/contourize_tests.cpp +++ b/tests/unit_tests/contourize_tests.cpp @@ -1,10 +1,11 @@ -#include "gtest/gtest.h" -#include <contourize/contourize.h> -#include <intersections/intersections.h> +#include <gtest/gtest.h> +#include <contourize.h> +#include <triangle.h> +#include <intersections.h> TEST(ContourizeTest, TwoTriangles) { - auto t1 = Triangle(Point(0,0), Point(5,0), Point(2,3), 0); - auto t2 = Triangle(Point(3,1), Point(6,1), Point(4,3), 0); + auto t1 = Triangle(Point{0,0}, Point{5,0}, Point{2,3}, 0); + auto t2 = Triangle(Point{3,1}, Point{6,1}, Point{4,3}, 0); auto newIntersections = intersections(t1, t2); diff --git a/tests/unit_tests/point_in_triangle_tests.cpp b/tests/unit_tests/point_in_triangle_tests.cpp new file mode 100644 index 0000000000000000000000000000000000000000..00811dbf0d74f24cf2f8fc4b782e55a9668e8002 --- /dev/null +++ b/tests/unit_tests/point_in_triangle_tests.cpp @@ -0,0 +1,10 @@ +#include <gtest/gtest.h> +#include <triangle.h> + +TEST(PointInTriangleTests, PointInTriangle) { + Triangle t = Triangle({1, 0.5}, {3, 0.2}, {2, 1}, 0); + EXPECT_TRUE(t.pointInTriangle({1.96, 0.467})); + EXPECT_FALSE(t.pointInTriangle({1.107,0.834})); + EXPECT_FALSE(t.pointInTriangle({2.553, 0.823})); + EXPECT_FALSE(t.pointInTriangle({1.63, 0.13})); +} \ No newline at end of file diff --git a/tests/unit_tests/simple_triangle_tests.cpp b/tests/unit_tests/simple_triangle_tests.cpp index 01e759f272b06caffeb584732990f8ebb425b016..f3d4783606aeb88273b7f4b559a8c84b2ddd3bf9 100644 --- a/tests/unit_tests/simple_triangle_tests.cpp +++ b/tests/unit_tests/simple_triangle_tests.cpp @@ -1,10 +1,10 @@ -#include "gtest/gtest.h" -#include "../../src/shapes/triangle.h" -#include "../../src/intersections/intersections.h" +#include <gtest/gtest.h> +#include <triangle.h> +#include <intersections.h> TEST (TriangleIntersectionTests, TriangleIntersection) { - auto t1 = Triangle(Point(0,0), Point(2,3), Point(5,0), 0); - auto t2 = Triangle(Point(3,1), Point(4,3), Point(6,1), 0); + auto t1 = Triangle(Point{0,0}, Point{2,3}, Point{5,0}, 0); + auto t2 = Triangle(Point{3,1}, Point{4,3}, Point{6,1}, 0); std::vector<Point> results = intersections(t1, t2); diff --git a/tests/unit_tests/triangulation_tests.cpp b/tests/unit_tests/triangulation_tests.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a69bf5103016a65d90be1240e1973364620633b0 --- /dev/null +++ b/tests/unit_tests/triangulation_tests.cpp @@ -0,0 +1,12 @@ +#include "gtest/gtest.h" +#include <shapes/point.h> + + +TEST(TriangulationTests, Page3Example) { + std::vector<Point> polygon = { + {3,48}, {52, 8}, {99,50}, {138,25}, + {175, 77}, {131, 72}, {111, 113}, + {72, 43}, {26, 55}, {29, 100}}; + + +} \ No newline at end of file