diff --git a/src/union.cpp b/src/union.cpp index 62c82b90717f8e6b65ddef67a9c5123c3ff575d6..8047ba5ce94f0176bea9afddd2d2d973da8530c9 100644 --- a/src/union.cpp +++ b/src/union.cpp @@ -1,77 +1,34 @@ -#include <vector> +#include <union.h> +#include <contourize.h> #include <triangle.h> +#include <constants.h> +#include <list> #include <triangle_edges.h> #include <intersections.h> -#include <contourize.h> -#include <convex_triangulation.h> -std::vector<Point> getPointsOnSide(const Edge &e, const std::vector<Point> intr, const Triangle &bottom) -{ - std::vector<Point> result; - for (int i = 0; i < NB_TRIANGLE_SIDES; i++) - { - if (e.positiveSide(bottom.points[i])) - { - result.push_back(bottom.points[i]); - } - } - - for (const auto &p : intr) - { - if (e.positiveSide(p)) - { - result.push_back(p); - } - } - return result; -} +std::vector<Triangle> unionizeTopAndBottom(const Triangle &top, const Triangle &bot) { + std::vector<Triangle> result; -std::vector<Triangle> unionizeTopAndBottom(const Triangle &top, const Triangle &bottom) -{ + std::list<Point> intr; + TriangleEdges topEdges = TriangleEdges(top); - std::vector<Triangle> result; - TriangleEdges topEdges = TriangleEdges(top); - TriangleEdges botEdges = TriangleEdges(bottom); + // keep track of relevant triangles + + for (int i = 0; i < NB_TRIANGLE_SIDES; i++) { + const Edge &e = topEdges.edges[i]; + auto newIntr = intersections(e, bot); + // split triangle if exists + // currently relevant triangles + // add these to result + + // future relevant triangles + // use to - std::vector<Point> intrPoints; + // filter using previous edges - for (int i = 0; i < NB_TRIANGLE_SIDES; i++) - { - for (int j = 0; j < NB_TRIANGLE_SIDES; j++) - { - auto cand = intersectionWithinEdgeDirection(topEdges.edges[i], botEdges.edges[j]); - if (cand.has_value()) - { - intrPoints.push_back(cand.value()); - } - } - } - - for (int i = 0; i < NB_TRIANGLE_SIDES; i++) - { - std::vector<Point> currentShape = getPointsOnSide(topEdges.edges[i], intrPoints, bottom); - if (currentShape.empty()) { - continue; + // create shape if points exists + contourize(); } - std::vector<Point> orderedPoints = contourize(currentShape); - std::vector<Triangle> newTriangles = convexTriangulation(orderedPoints, bottom.depth, bottom.id); - result.insert(result.begin(), newTriangles.begin(), newTriangles.end()); - } - - // add top triangle - result.push_back(top); - return result; -} + return result; -std::vector<Triangle> unionize(const Triangle &t1, const Triangle &t2) -{ - if (intersections(t1, t2).empty()) - { - return {t1, t2}; - } - if (t1.depth < t2.depth) - { - return unionizeTopAndBottom(t1, t2); - } - return unionizeTopAndBottom(t2, t1); }