Skip to content
Snippets Groups Projects
Commit 473f3076 authored by Brandon Lai-Cheong's avatar Brandon Lai-Cheong
Browse files

Added neighbour property

parent 278ad311
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,7 @@ add_executable(
src/debug_utilities/print_triangles.cpp
src/utilities/split_triangle.cpp
tests/unit_tests/orientation_tests.cpp
tests/union_neighbours_tests.cpp
)
include_directories(include)
......
#pragma once
#include "point.h"
#include "print_triangle.h"
#include <vector>
// points specified counterclockwise
struct Triangle
......@@ -8,8 +9,10 @@ struct Triangle
Point points[3];
int depth;
int id;
bool neighbours(const Triangle &other) const;
Triangle(const Point &p1, const Point &p2, const Point &p3, int depth = 0, int id = 0);
std::vector<int> neighbours;
Triangle(const Point &p1, const Point &p2, const Point &p3, int depth = 0, int id = 0, const std::vector<int> neighbours = {});
bool pointInTriangle(const Point &p) const;
Point nextPoint(int pointIndex) const;
bool operator==(const Triangle &other) const;
......
......@@ -2,13 +2,7 @@
#include "triangle_edges.h"
#include "edge.h"
bool Triangle::neighbours(const Triangle &other) const {
return false;
}
Triangle::Triangle(const Point &p1, const Point &p2, const Point &p3, int depth, int id) : points{p1,p2,p3}, depth{depth}, id{id} {}
Triangle::Triangle(const Point &p1, const Point &p2, const Point &p3, int depth, int id, std::vector<int> neighbours) : points{p1,p2,p3}, depth{depth}, id{id}, neighbours{neighbours} {}
bool Triangle::pointInTriangle(const Point &p) const {
// all tests must be positive
......
......@@ -40,6 +40,9 @@ std::vector<Triangle> unionizeTopAndBottom(const Triangle &top, const Triangle &
std::vector<Triangle> unionize(const Triangle &t1, const Triangle &t2)
{
if (std::find(t1.neighbours.begin(), t1.neighbours.end(), t2.id) != t1.neighbours.end()) {
return {t1, t2};
}
if (intersections(t1, t2).empty())
{
return {t1, t2};
......@@ -49,4 +52,4 @@ std::vector<Triangle> unionize(const Triangle &t1, const Triangle &t2)
return unionizeTopAndBottom(t1, t2);
}
return unionizeTopAndBottom(t2, t1);
}
\ No newline at end of file
}
......@@ -14,3 +14,8 @@ TEST(UnionEdgeTests, TriangleEdgeLength0) {
Triangle t1 = Triangle({1,1}, {2,2}, {3,3}, 1, 1);
Triangle t2 = Triangle({}, {}, {}, 2, 2);
}
TEST(UnionEdgeTests, TriangleOnSide) {
Triangle t1 = Triangle({}, {}, {}, 1, 1);
Triangle t2 = Triangle({}, {}, {}, 2, 2);
}
#include <gtest/gtest.h>
#include <triangle.h>
#include <union.h>
TEST (UnionNeighbourTests, NeighbourTest) {
Triangle t1 = Triangle({}, {}, {}, 1, 1, {2});
Triangle t2 = Triangle({}, {}, {}, 2, 2, {1});
auto results = unionize(t1, t2);
std::vector<Triangle> expected ={t1, t2} ;
EXPECT_EQ(results, expected);
}
......@@ -128,9 +128,9 @@ TEST(UnionTests, StarTest)
results = unionize(bottom, top);
std::vector<Triangle> expected_results_2 = {
Triangle({0,3}, {0.8,3}, {0.540541,3.64865}, 1, 3),
Triangle({5,3}, {4.30233,3.83721}, {3.8,3}, 1, 3),
Triangle({2.5,6}, {1.66667,5}, {3.33333,5}, 1, 3),
Triangle({0,3}, {0.8,3}, {0.540541,3.64865}, 3, 1),
Triangle({5,3}, {4.30233,3.83721}, {3.8,3}, 3, 1),
Triangle({2.5,6}, {1.66667,5}, {3.33333,5}, 3, 1),
Triangle({0,5}, {2,0}, {5,5}, 2, 2)
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment