Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • shlomist/unionized-triangles
  • blaicheo/unionized-triangles-2
2 results
Show changes
Showing
with 539 additions and 163 deletions
#include "triangulation.h"
#include <list>
#include <point.h>
#include <triangle.h>
#include <optional>
#include <pointList.h>
bool isAnEar(Triangle triangle, const std::vector<Point> &points) {
for (const Point &p: points) {
if (triangle.pointInTriangle(p)) {
return false;
}
}
return true;
}
int mod(int a, int b) {
return (a + b) % b;
}
std::optional<Triangle> removeEar(int &index, PointList &pointList, const std::vector<Point> &allPoints) {
PointNode &p = pointList.points[index];
const int next = pointList.next(p);
const int prev = pointList.prev(p);
const PointNode &nextNode = pointList.points[next];
const PointNode &prevNode = pointList.points[prev];
/*
Triangle candidate;
if (index > next_index && next_index < previous_index) {
candidate = Triangle{points[index], points[next_index], points[previous_index], 0};
}
if (index < next_index) {
candidate = Triangle{points[index], points[next_index], points[previous_index], 0};
}
*/
Triangle candidate = Triangle{p.p, nextNode.p, prevNode.p, 0};
if (isAnEar(candidate, allPoints)) {
index = pointList.next(nextNode);
pointList.remove(index);
return candidate;
}
index = prev;
return {};
}
std::vector<Triangle> triangulate(std::vector<Point> points) {
std::vector<Triangle> result;
PointList polygon = PointList(points);
int i = 0;
while (!polygon.empty()) {
std::optional<Triangle> t = removeEar(i, polygon, points);
if (t.has_value()) {
result.push_back(t.value());
}
}
return result;
}
\ No newline at end of file
#include <gtest/gtest.h>
#include <union.h>
#include <triangle.h>
#include <orientation.h>
#include "union_tests.h"
INSTANTIATE_TEST_SUITE_P(EdgeUnionTests, InstantiateUnionTests, testing::Values(
// Point on top of triangle
UnionParams{Triangle({0, 0, 4}, {5, 0, 4}, {2, 3, 4}, 1), Triangle({1, 1, 0}, {1, 1, 0}, {1, 1, 0}, 2), {Triangle({0, 0, 4}, {5, 0, 4}, {2, 3, 4}, 1), Triangle({1, 1, 0}, {1, 1, 0}, {1, 1, 0}, 2)}},
// Point on edge of triangle
UnionParams{Triangle({0, 0, 6}, {5, 0, 6}, {2, 3, 6}, 1), Triangle({0, 2, 3}, {0, 2, 3}, {0, 2, 3}, 2), {Triangle({0, 0, 6}, {5, 0, 6}, {2, 3, 6}, 1), Triangle({0, 2, 3}, {0, 2, 3}, {0, 2, 3}, 2)}},
// Point on vertex of triangle
UnionParams{Triangle({0, 0, 2}, {5,0,2}, {2,3,2}, 1), Triangle({0,0,0}, {0,0,0}, {0,0,0}, 2), {Triangle({0, 0, 2}, {5,0,2}, {2,3,2}, 1), Triangle({0,0,0}, {0,0,0}, {0,0,0}, 2)}},
// Line and Triangle
UnionParams{Triangle({0,0,5}, {5,0,5}, {2,3,5}, 1), Triangle({0,0,0}, {1,1,0}, {6,6,0}, 2), {Triangle({0,0,5}, {5,0,5}, {2,3,5}, 1), Triangle({0,0,0}, {1,1,0}, {6,6,0}, 2)}}
));
TEST(UnionEdgeTests, TriangleVertexOnEdge)
{
Triangle t1 = Triangle({}, {}, {}, 1);
Triangle t2 = Triangle({}, {}, {}, 2);
auto result = unionize(t1, t2);
}
TEST(UnionEdgeTests, TriangleIsPoint)
{
Triangle t1 = Triangle({1, 1, 2}, {2, 2, 2}, {3, 3, 2}, 1);
Triangle t2 = Triangle({2, 2, 1}, {2, 2, 1}, {2, 2, 1}, 2);
auto results = unionize(t1, t2);
std::vector<Triangle> expected = {
Triangle({1, 1, 2}, {2, 2, 2}, {3, 3, 2}, 1),
Triangle({2, 2, 1}, {2, 2, 1}, {2, 2, 1}, 2)};
EXPECT_EQ(results, expected);
}
TEST(UnionEdgeTests, TriangleOnSide)
{
Triangle t1 = Triangle({0, 0, 1}, {0, 5, 1}, {2, 3, 1}, 1);
Triangle t2 = Triangle({0, 1}, {1, 1}, {0, 3}, 2);
auto results = unionize(t1, t2);
std::vector<Triangle> expected = {
Triangle({0,0,1}, {0.666667,1,1}, {0,1,1}, 1),
Triangle({0,5,1}, {0,3,1}, {0.857143,1.28571,1}, 1),
Triangle({0,5,1}, {0.857143,1.28571,1}, {2,3,1}, 1),
Triangle({0,1,0}, {1,1,0}, {0,3,0}, 2)
};
EXPECT_EQ(results, expected);
}
#include <gtest/gtest.h>
#include <quad_tree.h>
TEST(QuadTreeTests, SimplePointQueryTest) {
QuadTree q({{10,10}, {0,0}});
Triangle t({0,0}, {5,0}, {2,3}, 42);
q.addTriangle(t);
Point p{1,1};
int id = q.pointIntersection(p);
EXPECT_EQ(id, t.mainTriangleId);
}
TEST (QuadTreeTests, NotInQueryPointTest) {
QuadTree q({{10,10}, {0,0}});
Triangle t({0,0}, {5,0}, {2,3});
Point p{9,9};
int id = q.pointIntersection(p);
EXPECT_EQ(id, POINT_NOT_IN_QUADTREE);
}
TEST (QuadTreeTests, OverlapTest) {
QuadTree q({{10,10}, {0,0}});
Triangle t1({0, 0, 0}, {5, 0, 0}, {2, 3, 0}, 1);
Triangle t2({3, 1, 1}, {6, 1, 1}, {4, 3, 1}, 2);
q.addTriangle(t1);
q.addTriangle(t2);
Point p{1,1};
int id = q.pointIntersection(p);
EXPECT_EQ(id, t1.mainTriangleId);
}
TEST (QuadTreeTests, NonOverlappingTest) {
QuadTree q({{10,10}, {0,0}});
Triangle t1({0, 0, 0}, {5, 0, 0}, {2, 3, 0}, 1);
Triangle t2{{6, 0, 1}, {10, 0, 1}, {7, 5, 1}, 2};
q.addTriangle(t1);
q.addTriangle(t2);
}
TEST (QuadTreeTests, VisibleSurfaceTestNonOverlapping) {
QuadTree q({{10,10}, {0,0}});
Triangle t1({0, 0, 0}, {5, 0, 0}, {2, 3, 0}, 1);
Triangle t2{{6, 0, 1}, {10, 0, 1}, {7, 5, 1}, 2};
q.addTriangle(t1);
q.addTriangle(t2);
auto surface = q.visibleSurface();
std::vector<Triangle> expected_surface {{{6,0,1}, {10, 0, 1}, {7, 5, 1}, 2}, {{0,0,0}, {5,0,0},{2,3,0}, 1}};
EXPECT_EQ(surface, expected_surface);
}
TEST (QuadTreeTests, NoVisibleSurfaceTest) {
QuadTree q({{1,1}, {0,0}});
auto surface = q.visibleSurface();
EXPECT_EQ(surface, std::vector<Triangle>{});
}
TEST (QuadTreeTests, FiveTrianglesTest) {
QuadTree q({{1,1}, {0,0}});
Triangle t1{{0,0,0}, {0,0,0}, {0,0,0}, 1};
Triangle t2{{0,0,0}, {0,0,0}, {0,0,0}, 1};
Triangle t3{{0,0,0}, {0,0,0}, {0,0,0}, 1};
Triangle t4{{0,0,0}, {0,0,0}, {0,0,0}, 1};
}
TEST (QuadTreeTests, DegenerateTrianglesTest) {
QuadTree q({{1,1}, {0,0}});
Triangle t1{{0,0,0}, {0,0,0}, {0,0,0}, 1};
Triangle t2{{0.2, 0.1, 1}, {0.2, 0.1, 1}, {0.3, 0.2, 1}, 2};
Triangle t3{{1,0,0}, {1,0,0}, {0,0,0}, 3};
q.addTriangle(t3);
q.addTriangle(t2);
q.addTriangle(t1);
auto surface = q.visibleSurface();
std::vector<Triangle> expected_surface {t1, t3, t2};
EXPECT_EQ(surface, expected_surface);
}
TEST (QuadTreeTests, StackingPointsTest) {
}
TEST (QuadTreeTests, TriangleCompletelyCoversOthers) {
QuadTree q({{1,1}, {0,0}});
Triangle t1{{0,0.1,10}, {0.234, 0.3, 9}, {0.1, 0.5, 9}, 1};
Triangle cover{{-100,-100,0}, {100,-1000,0}, {25, 50,0}, 100};
q.addTriangle(t1);
q.addTriangle(cover);
std::vector<Triangle> expected {cover};
EXPECT_EQ(q.visibleSurface(), expected);
}
\ No newline at end of file
#include <gtest/gtest.h>
#include <triangle.h>
#include <union.h>
TEST (UnionNeighbourTests, NeighbourTest) {
Triangle t1 = Triangle({}, {}, {}, 1, {2});
Triangle t2 = Triangle({}, {}, {}, 2, {1});
auto results = unionize(t1, t2);
std::vector<Triangle> expected ={t1, t2} ;
EXPECT_EQ(results, expected);
}
#include "gtest/gtest.h"
#include <union.h>
#include<triangle.h>
#include <triangle.h>
#include <orientation.h>
#include <shift_triangle.h>
#include "union_tests.h"
TEST (UnionTrivialTests, NotTouching) {
Triangle t1 = Triangle{{0,0}, {5,0}, {2,3}, 0};
Triangle t2 = Triangle{{6,0}, {10,0}, {7,5}, 0};
std::ostream &operator<<(std::ostream &os, const UnionParams &u) {
os << u.t1 << "|" << u.t2;
return os;
}
TEST(UnionTrivialTests, NotTouching)
{
Triangle t1 = Triangle{{0, 0}, {5, 0}, {2, 3}, 0};
Triangle t2 = Triangle{{6, 0}, {10, 0}, {7, 5}, 0};
auto ts = unionize(t1, t2);
EXPECT_TRUE(ts.size() == 2);
}
TEST(UnionTests, TwoIntersections)
{
TEST (UnionTests, TwoIntersections) {
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, 0}, Point{5, 0, 0}, Point{2, 3, 0}, 1);
auto t2 = Triangle(Point{3, 1, 1}, Point{6, 1, 1}, Point{4, 3, 1}, 2);
auto ts = unionize(t1, t2);
EXPECT_TRUE(ts.size() > 0);
}
\ No newline at end of file
EXPECT_TRUE(ts.size() == 3);
std::vector<Triangle> expected{
Triangle({6,1,1}, {4,3,1}, {3.333333,1.66666,1}, 2),
Triangle({6,1,1}, {3.33333,1.66667,1}, {4,1,1},2),
Triangle({0,0}, {5,0}, {2,3}, 1)};
EXPECT_EQ(ts, expected);
}
// Edge Case
TEST(UnionTests, SharesPointTest)
{
// Case 1 t1 covers t2
Triangle top = Triangle({0, 5}, {3, 2}, {5, 3}, 1);
Triangle bottom = Triangle({0.1, 7, 5}, {5, 3,5}, {3.2, 9,5}, 2);
auto results = unionize(bottom, top);
std::vector<Triangle> expected_results_1 = {
Triangle({0.1, 7, 5}, {5, 3,5}, {3.2, 9,5}, 2),
Triangle({0, 5}, {3, 2}, {5, 3}, 1)
};
EXPECT_EQ(results, expected_results_1);
// Case 2 t2 covers t1
shiftZ(top, 10);
results = unionize(bottom, top);
std::vector<Triangle> expected_results_2 {
Triangle({0, 5, 10}, {3, 2, 10}, {5, 3, 10}, 1),
Triangle({0.1, 7, 5}, {5, 3,5}, {3.2, 9,5}, 2)
};
EXPECT_EQ(results, expected_results_2);
}
TEST(UnionTests, FoldTriangleTest)
{
Triangle top = Triangle({0, 5}, {3, 2}, {5, 3}, 1);
Triangle bottom = Triangle({0.1, 9,1}, {2, 4,1}, {5,5,1}, 2);
auto results = unionize(bottom, top);
std::vector<Triangle> expected_results_1 = {
Triangle({0.1,9,1}, {1.91038,4.23585,1}, {2.27273,4.09091,1}, 2),
Triangle({0.1,9,1}, {2.27273,4.09091,1}, {5,5,1}, 2),
Triangle({0,5,0}, {3,2,0}, {5,3,0}, 1)
};
EXPECT_EQ(results, expected_results_1);
shiftZ(top, 3);
results = unionize(bottom, top);
std::vector<Triangle> expected_results_2 = {
Triangle({0,5,3}, {2.6129,2.3871,3}, {1.91038,4.23585,3}, 1),
Triangle({3,2,3}, {5,3,3}, {2.27273,4.09091,3}, 1),
Triangle({3,2,3}, {2.27273,4.09091,3}, {2.6129,2.3871,3}, 1),
Triangle({2.6129,2.3871,3}, {2.27273,4.09091,3}, {2,4,3}, 1),
Triangle({0.1,9,1}, {2,4,1}, {5,5,1}, 2)
};
EXPECT_EQ(results, expected_results_2);
}
TEST(UnionTests, StarTest)
{
Triangle top = Triangle({0, 3,0}, {5, 3,0}, {2.5, 6,0}, 1);
Triangle bot = Triangle({0, 5, 1}, {2, 0, 1}, {5, 5, 1}, 2);
ASSERT_EQ(orientation(top.points[0], top.points[1], top.points[2]), Counterclockwise);
ASSERT_EQ(orientation(bot.points[0], bot.points[1], bot.points[2]), Counterclockwise);
auto results = unionize(top, bot);
std::vector<Triangle> expected_results_1 = {
Triangle({2,0,1}, {3.8, 3,1}, {0.8, 3, 1}, 2),
Triangle({5,5,1}, {3.33333, 5, 1}, {4.30233, 3.83721, 1}, 2),
Triangle({0,5,1}, {0.540541, 3.64865, 1}, {1.66667, 5, 1}, 2),
Triangle({0, 3}, {5, 3}, {2.5, 6}, 1)
};
EXPECT_EQ(results, expected_results_1);
shiftZ(top, 3);
results = unionize(top, bot);
std::vector<Triangle> expected_results_2 = {
Triangle({0,3,3}, {0.8,3,3}, {0.540541,3.64865,3}, 1),
Triangle({5,3,3}, {4.30233,3.83721,3}, {3.8,3,3}, 1),
Triangle({2.5,6,3}, {1.66667,5,3}, {3.33333,5,3}, 1),
Triangle({0,5, 1}, {2,0,1}, {5,5,1}, 2)
};
EXPECT_EQ(results, expected_results_2);
}
TEST_P(InstantiateUnionTests, UnionTest)
{
const Triangle &t1 = GetParam().t1;
const Triangle &t2 = GetParam().t2;
auto expected = GetParam().expected;
ASSERT_NE(orientation(t1), Clockwise);
ASSERT_NE(orientation(t2), Clockwise);
auto result = unionize(t1, t2);
EXPECT_EQ(result, expected);
}
INSTANTIATE_TEST_SUITE_P(ParameterizedUnionTests, InstantiateUnionTests, testing::Values(
UnionParams{Triangle({0, 0, 0}, {5, 0, 0}, {2, 3, 0}, 1), Triangle(Point{3, 1, 10}, Point{6, 1, 2}, Point{4, 3, 1}, 2),
{Triangle({6,1,2}, {4,3,1}, {3.333333,1.66666,7.23542}, 2),
Triangle({6,1,2}, {3.33333,1.66667,7.23542}, {4,1,7.3680},2),
Triangle({0,0}, {5,0}, {2,3}, 1)}}, UnionParams{Triangle({0,0.1,10}, {0.234, 0.3, 9}, {0.1, 0.5, 9}, 1), Triangle({-100, -100, 0}, {100, -100, 0}, {25, 50, 0}, 2), {Triangle({-100, -100}, {100, -100}, {25, 50}, 2)}}
));
\ No newline at end of file
#pragma once
#include <triangle.h>
struct UnionParams
{
Triangle t1;
Triangle t2;
std::vector<Triangle> expected;
};
class InstantiateUnionTests : public testing::TestWithParam<UnionParams>{};
std::ostream &operator<<(std::ostream &os, const UnionParams &u);
......@@ -3,38 +3,36 @@
#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);
TEST(ContourizeTest, Simple) {
std::vector<Point> points{{0,0}, {5,0}, {2, 3}};
auto newIntersections = intersections(t1, t2);
auto result = contourize(points);
auto contour = contourize(t1, t2, newIntersections);
EXPECT_TRUE(contour.size() > 0);
std::vector<Point> expectedContour {Point{0,0},
Point{5,0},
Point{4, 1},
Point{6,1},
Point{4,3},
Point{3.33333325, 1.66666675},
Point{2,3}};
EXPECT_EQ(contour, expectedContour);
std::vector<Point> expected{{0,0}, {5,0}, {2, 3}};
EXPECT_EQ(result, expected);
}
TEST (ContourizeTest, Collinear) {
std::vector<Point> points {{2,3,5}, {0,0,5}, {2.5,2.5,5}, {-0,0,5}};
auto result = contourize(points);
}
TEST (ContourizeTests, TriangleSingleDipTest) {
auto t1 = Triangle({0,0}, {5,0}, {2,6}, 0);
auto t2 = Triangle({1,1}, {7,3}, {8,6}, 0);
TEST(ContourizeTest, Triangle) {
std::vector<Point> points{{3,1}, {4,1}, {3.33333, 1.6666}};
auto result = contourize(points);
std::vector<Point> expected{{3,1}, {4,1}, {3.33333, 1.6666}};
EXPECT_EQ(result, expected);
}
auto newIntersections = intersections(t1, t2);
/*
TEST(ContourizeTest, TestCase3) {
auto contour = contourize(t1, t2, newIntersections);
std::vector<Point> points{{0.100000001,9}, {5,5}, {1.91037738, 4.2358489}, {2.27272725, 4.090909}, {9.80392265, 1.07843113}};
auto result = contourize(points);
std::vector<Point> expectedContour{
{0,0}, {5,0}, {5,2}, {7,3}, {8,6}, {4,3}, {2,6}
};
EXPECT_EQ(contour, expectedContour);
}
\ No newline at end of file
std::vector<Point> expected{{3,1}, {4,1}, {3.33333, 1.6666}};
EXPECT_EQ(result, expected);
}*/
#include <gtest/gtest.h>
#include <convex_triangulation.h>
#include <vector>
TEST(ConvexTriangulationTests, Simple) {
Point p1{1,3};
Point p2{2,2};
Point p3{3,2.1};
Point p4{4,3.2};
Point p5{2.1,4};
std::vector<Point> points = {
p1, p2, p3, p4, p5
};
auto results = convexTriangulation(points, 2, std::make_shared<std::vector<int>>());
std::vector<Triangle> expected_result {
Triangle(p1, p2, p3, 2),
Triangle(p1, p3, p5, 2),
Triangle(p5, p3, p4, 2)
};
EXPECT_EQ(results, expected_result);
}
TEST(ConvexTriangulationTests, TrivialTriangle) {
std::vector<Point> points = {
{0,0},
{2,0},
{1.5, 2}
};
auto results = convexTriangulation(points, 1, std::make_shared<std::vector<int>>());
Triangle expected_triangle = Triangle({0,0}, {2,0}, {1.5, 2}, 1);
EXPECT_EQ(results.size(), 1);
EXPECT_EQ(results[0], expected_triangle);
}
#include <gtest/gtest.h>
#include <triangulation.h>
#include <vector>
#include <point.h>
#include <pointList.h>
TEST(EarRemovalTests, SingleEarRemoval) {
std::vector<Point> polygon = {
{3,48}, {52, 8}, {99,50}, {138,25},
{175, 77}, {131, 72}, {111, 113},
{72, 43}, {26, 55}, {29, 100}};
PointList pointList = PointList(polygon);
int index = 0;
auto t = removeEar(index, pointList, polygon);
EXPECT_FALSE(t.has_value());
EXPECT_TRUE(true);
auto t2 = removeEar(index, pointList, polygon);
auto t3 = removeEar(index, pointList, polygon);
}
\ No newline at end of file
#include <gtest/gtest.h>
#include <interpolate_z.h>
#include <point.h>
#include <edge.h>
struct InterpolateParams {
Edge e;
Point point;
float expected_z;
};
std::ostream &operator<<(std::ostream & out, const Edge &e) {
return out << e.p1 << ", " << e.p2;
}
std::ostream &operator<<(std::ostream & out, const InterpolateParams &p) {
return out << "Edge: " << p.e << "Point: " << p.point;
}
class InstantiateInterpolateZTests : public testing::TestWithParam<InterpolateParams>{
};
TEST_P (InstantiateInterpolateZTests, Interpolate) {
Edge e = GetParam().e;
Point point = GetParam().point;
float z = interpolateZ(e, point);
EXPECT_EQ(z,GetParam().expected_z);
}
INSTANTIATE_TEST_SUITE_P(Interpolation, InstantiateInterpolateZTests, testing::Values(
InterpolateParams{{{1,1,3}, {2,2,3}}, {1.5,1.5},3},
InterpolateParams{{{1,1,5}, {1,1,5}}, {1,1},5},
InterpolateParams{{{1,1,10}, {2,3,15}}, {2,3},15},
InterpolateParams{{{1,1,10}, {2,2,0}}, {1,1},10},
InterpolateParams{{{1,1,10}, {2,2,0}}, {2,2},0},
InterpolateParams{{{5, 3,3}, {2.5, 6,3}}, {0.540541,3.64865},3}
));
#include <intersections.h>
#include <gtest/gtest.h>
#include <edge.h>
TEST (IntersectionTests, EdgeToEdgeTest) {
Edge e1 {{5,0}, {2,6}};
Edge e2 {{1,1}, {4,2}};
auto p = intersectionWithinEdge(e1, e2);
Point actual_point = p.value();
Point expected_point = Point{4,2};
EXPECT_TRUE(actual_point == expected_point);
}
TEST (IntersectionTests, EdgeTest) {
Edge e1{{0.8, 3}, {5,3}};
Edge e2{{2,0}, {5,5}};
auto p = intersectionFirstSide(e1,e2);
EXPECT_TRUE(p.has_value());
}
\ No newline at end of file
......@@ -2,23 +2,25 @@
#include <orientation.h>
#include <point.h>
TEST (OrientationTests, CounterClockwiseTest) {
EXPECT_EQ(orientation(Point{0,0}, Point{1,0}, Point{0.5, 0.5}), Counterclockwise);
TEST(OrientationTests, Collinear)
{
EXPECT_EQ(orientation(Point{0, 0}, Point{1, 0}, Point{2, 0}), Collinear);
}
TEST (OrientationTests, Clockwise) {
EXPECT_EQ(orientation(Point{0,0}, Point{0.5, 0.5}, Point{1,0}), Clockwise);
TEST(OrientationTests, ExampleCounterClockwiseTest)
{
EXPECT_EQ(orientation(Point{0, 0}, Point{4, 4}, Point{1, 2}), Counterclockwise);
}
TEST (OrientationTests, Collinear) {
EXPECT_EQ(orientation(Point{0,0}, Point{1,0}, Point{2,0}), Collinear);
TEST (OrientationTests, Counterclockwise) {
EXPECT_EQ(orientation({0,0}, {5,0}, {2,3}), Counterclockwise);
}
TEST (OrientationTests, ExampleCounterClockwiseTest) {
EXPECT_EQ(orientation(Point{0,0}, Point{4,4}, Point{1,2}), Counterclockwise);
}
/*TEST (OrientationTests, Counterclockwise2Test) {
EXPECT_EQ(orientation({}, {}, {}), Counterclockwise);
}*/
\ No newline at end of file
TEST(OrientationTests, TestAll)
{
Point p1 = {3, 1};
Point p2 = {4, 1};
Point p3 = {3.333, 1.666};
EXPECT_EQ(orientation(p1, p2, p3), Counterclockwise);
EXPECT_EQ(orientation(p2, p1, p3), Clockwise);
}
\ No newline at end of file
#include <gtest/gtest.h>
#include <split_triangle.h>
#include <triangle.h>
#include <edge.h>
TEST(SplitTriangleTests, NormalCase2) {
std::vector<Point> t {{0.1, 9}, {2,4}, {5,5}};
Edge e{{5,3}, {0,5}};
auto results = splitShape(t, e);
auto pos = results[0];
EXPECT_TRUE(pos.size() > 1);
}
TEST(SplitTriangleTests, InvisibleIntersection) {
Edge e {{0.1,9}, {2,4}};
std::vector<Point> t{{0,5}, {3,2}, {5,5}};
auto results = splitShape(t,e);
EXPECT_TRUE(results[1].size() > 2);
}
TEST (SplitTriangleTests, Quadric) {
Edge e {{2,4}, {5,5}};
std::vector<Point> p{{3,2}, {5,3}, {1.91037738, 4.2358489}, {2.61290312,2.38709688}};
auto results = splitShape(p,e);
EXPECT_TRUE(results[0].size() > 2);
}
TEST(SplitTriangleTests, OnEdge1) {
std::vector<Point> t {{0,0}, {0,5}, {2,3}};
Edge e = Edge{{1,1}, {0,1}};
auto results = splitShape(t, e);
EXPECT_EQ(results[0].size(), 4);
EXPECT_EQ(results[1].size(), 3);
}
TEST(SplitTriangleTests, OnEdge2) {
std::vector<Point> t {{0,0}, {0,5}, {2,3}};
Edge e {{1,1}, {0,3}};
auto results = splitShape(t,e);
EXPECT_EQ(results[0].size(), 4);
}
#include "gtest/gtest.h"
#include <point.h>
#include <triangulation.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}};
auto t = triangulate(polygon);
EXPECT_TRUE(t.size() > 0);
}
\ No newline at end of file