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
#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, 0,0);
EXPECT_FALSE(t.has_value());
EXPECT_TRUE(true);
auto t2 = removeEar(index, pointList, polygon,0,0);
auto t3 = removeEar(index, pointList, polygon,0,0);
}
\ No newline at end of file
#include <intersections.h>
#include <gtest/gtest.h>
#include <edge.h>
TEST(EdgeDirectionIntersectionTests, BasicTests) {
Edge e1{ {5,0}, {2,3}};
Edge e2{{3,1}, {6,1}};
auto result = intersectionWithinEdgeDirection(e1, e2);
ASSERT_TRUE(result.has_value());
Point expected = Point{4,1};
EXPECT_EQ(result.value(), expected);
Edge e3{{4,3}, {3,1}};
auto result2 = intersectionWithinEdgeDirection(e3, e1);
ASSERT_TRUE(result2.has_value());
Point expected2 = Point{3.33333,1.66667};
EXPECT_EQ(result2.value(), expected2);
Edge e4{{3,1}, {4,3}};
Edge e5{{0,0}, {5,0}};
auto result3 = intersectionWithinEdgeDirection(e4, e5);
EXPECT_FALSE(result3.has_value()) << result3.value();
}
#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}
));
......@@ -12,6 +12,10 @@ TEST(OrientationTests, ExampleCounterClockwiseTest)
EXPECT_EQ(orientation(Point{0, 0}, Point{4, 4}, Point{1, 2}), Counterclockwise);
}
TEST (OrientationTests, Counterclockwise) {
EXPECT_EQ(orientation({0,0}, {5,0}, {2,3}), Counterclockwise);
}
TEST(OrientationTests, TestAll)
{
Point p1 = {3, 1};
......
......@@ -3,22 +3,6 @@
#include <triangle.h>
#include <edge.h>
TEST(SplitTriangleTests, NormalCase) {
Triangle t = Triangle({0,0}, {5,0}, {2,3}, 1, 1);
Edge e{{4,3}, {3,1}};
auto results = splitShape(std::vector<Point>{t.points[0], t.points[1], t.points[2]}, e);
ASSERT_EQ(results.size(), 2);
auto pos = results[0];
auto neg = results[1];
std::vector<Point> expected_pos = {{0,0}, {2,3}};
std::vector<Point> expected_neg = {{5,0}};
EXPECT_EQ(pos, expected_pos);
EXPECT_EQ(neg, expected_neg);
}
TEST(SplitTriangleTests, NormalCase2) {
std::vector<Point> t {{0.1, 9}, {2,4}, {5,5}};
......@@ -46,4 +30,24 @@ TEST (SplitTriangleTests, Quadric) {
auto results = splitShape(p,e);
EXPECT_TRUE(results[0].size() > 2);
}
\ No newline at end of file
}
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, 0, 0);
EXPECT_TRUE(t.size() > 0);
}
\ No newline at end of file