Changeset View
Changeset View
Standalone View
Standalone View
tests/gtests/blenlib/BLI_math_geom_test.cc
| Context not available. | |||||
| float distance = dist_to_line_segment_v2(p, a, b); | float distance = dist_to_line_segment_v2(p, a, b); | ||||
| EXPECT_NEAR(sqrtf(2.0f), distance, 1e-6); | EXPECT_NEAR(sqrtf(2.0f), distance, 1e-6); | ||||
| } | } | ||||
| TEST(math_geom, IsectPointPoly2DSimpleSquare) | |||||
| { | |||||
| float square[][2] = {{0.0f, 1.0f}, {-1.0f, 0.0f}, {0.0f, -1.0f}, {1.0f, 0.0f}}; | |||||
| p_inside[1][2] = {{0.0f, 0.0f}}; | |||||
| p_outside[4][2] = {{-2.0f, 0.0f}, {2.0f, 0.0f}, {0.0f, -2.0f}, {0.0f, 2.0f}}; | |||||
| int square_vertices_quantity = 4; | |||||
| bool holes_in_square = false; /* currently unused */ | |||||
| for (int i = 0; i<1; i++) EXPECT_TRUE(isect_point_poly_v2(p_inside[i], square, square_vertices_quantity, holes_in_square)); | |||||
| for (int i = 0; i<4; i++) EXPECT_FALSE(isect_point_poly_v2(p_outside[i], square, square_vertices_quantity, holes_in_square)); | |||||
| } | |||||
| TEST(math_geom, IsectPointPoly2DConvex) | |||||
| { | |||||
| float potato[][2] = {{1.0f, 1.0f}, {2.5f, 0.5f}, {3.75f, 1.0f}, {4.0f, 2.5f}, {1.5f, 5.0f}, {0.5f, 3.5f}, {0.5f, 2.5f}}, | |||||
| p_inside[3][2] = {{1.000001f, 1.000001f}, {2.0f, 2.5f}, {0.5000001f, 3.0f}}, | |||||
| p_outside[5][2] = {{0.999999f, 0.999999f}, {5.0f, 2.5f}, {0.499999f, 3.0f}}; | |||||
| int potato_vertices_quantity = 7; | |||||
| bool holes_in_potato = false; /* currently unused */ | |||||
| for(int i = 0; i<1; i++) EXPECT_TRUE(isect_point_poly_v2(p_inside[i], potato, potato_vertices_quantity, holes_in_potato)); | |||||
| for(int i = 0; i<4; i++) EXPECT_FALSE(isect_point_poly_v2(p_outside[i], potato, potato_vertices_quantity, holes_in_potato)); | |||||
| } | |||||
| TEST(math_geom, IsectPointPoly2DDoubleSquare) | |||||
| { | |||||
| float square[][2] = {{0.0f, 1.0f}, {-1.0f, 0.0f}, {0.0f, -1.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}, | |||||
| {0.0f, 0.5f}, {0.5f, 0.0f}, {0.0f, -0.5f}, {-0.5f, 0.0f}, {0.0f, 0.5f}}, | |||||
| p_inside[4][2] = {{0.75f, 0.0f}, {-0.75f, 0.0f}, {0.0f, -0.75f}, {0.0f, 0.75f}}, | |||||
| p_outside[5][2] = {{0.0f, 0.0f}, {-2.0f, 0.0f}, {2.0f, 0.0f}, {0.0f, -2.0f}, {0.0f, 2.0f}}; | |||||
| int square_vertices_quantity = 10; | |||||
| bool holes_in_square = false; /* currently unused */ | |||||
| for(int i = 0; i<1; i++) EXPECT_TRUE(isect_point_poly_v2(p_inside[i], square, square_vertices_quantity, holes_in_square)); | |||||
| for(int i = 0; i<4; i++) EXPECT_FALSE(isect_point_poly_v2(p_outside[i], square, square_vertices_quantity, holes_in_square)); | |||||
| } | |||||
| TEST(math_geom, IsectPointQuad2DSimpleSquare) | |||||
| { | |||||
| float square[][2] = {{0.0f, 1.0f}, {-1.0f, 0.0f}, {0.0f, -1.0f}, {1.0f, 0.0f}}, | |||||
| p_inside[1][2] = {{0.0f, 0.0f}}; | |||||
| for(int i = 0; i<1; i++) EXPECT_TRUE(isect_point_quad_v2(p_inside[i], square[0], square[1], square[2], square[3])); | |||||
| } | |||||
| TEST(math_geom, IsectPointQuad2DSimpleSquareOutside) | |||||
| { | |||||
| float square[][2] = {{0.0f, 1.0f}, {-1.0f, 0.0f}, {0.0f, -1.0f}, {1.0f, 0.0f}}, | |||||
| p_outside[4][2] = {{-2.0f, 0.0f}, {2.0f, 0.0f}, {0.0f, -2.0f}, {0.0f, 2.0f}}; | |||||
| for(int i = 0; i<4; i++) EXPECT_FALSE(isect_point_quad_v2(p_outside[i], square[0], square[1], square[2], square[3])); | |||||
| } | |||||
| TEST(math_geom, IsectPointTri2DSimpleTriangle) | |||||
| { | |||||
| float triangle[3][2] = {{-1.0f, -1.0f}, {1.0f, -1.0f}, {0.0f, 1.0f}}, | |||||
| p[2] = {0.0f, 0.0f}; | |||||
| EXPECT_EQ(1,isect_point_tri_v2(p, triangle[0], triangle[1], triangle[2])); | |||||
| } | |||||
| TEST(math_geom, IsectPointTri2DSimpleTriangleOutside) | |||||
| { | |||||
| float triangle[3][2] = {{-1.0f, -1.0f}, {0.0f, 1.0f}, {1.0f, -1.0f}}, | |||||
| p[2] = {2.0f, 2.0f}; | |||||
| EXPECT_EQ(0,isect_point_tri_v2(p, triangle[0], triangle[1], triangle[2])); | |||||
| } | |||||
| TEST(math_geom, IsectPointTri2DSimpleTriangleReversed) | |||||
| { | |||||
| float triangle[3][2] = {{-1.0f, -1.0f}, {0.0f, 1.0f}, {1.0f, -1.0f}}, | |||||
| p[2] = {0.0f, 0.0f}; | |||||
| EXPECT_EQ(-1,isect_point_tri_v2(p, triangle[0], triangle[1], triangle[2])); | |||||
| } | |||||
| TEST(math_geom, IsectPointTri2DManyTriangles) | |||||
| { | |||||
| for(float x1 = 4.001f; x1 <= 12.0f; x1 += 2.71828f) for(float y1 = 0.001f; y1 <= 10.0f; y1 += 2.71828f) | |||||
| for(float x2 = x1 + 0.001f; x2 <= 15.02f; x2 += 2.71828f) for(float y2 = 0.001f; y2 <= y2 - 3.1f; y2 += 2.71828f) | |||||
| for(float w1 = 0.01f; w1 <= 0.999f; w1 += 0.113f) for(float w2 = 0.001f; w2 <= 1.0f - w1 - 0.0012; w2 += 0.1212f) | |||||
| { | |||||
| float a[2] = {0.0f, 0.0f}, | |||||
| b[2] = {x1, y1}, | |||||
| c[2] = {x2, y2}, | |||||
| p[2] = {w1*x1 + w2*x2, w1*y1 + w2*y2}; | |||||
| EXPECT_EQ(1,isect_point_tri_v2(p, a, b, c)); | |||||
| } | |||||
| } | |||||
| TEST(math_geom, IsectPointTri2DManyTrianglesReversed) | |||||
| { | |||||
| for(float x1 = 4.001f; x1 <= 12.0f; x1 += 2.71828f) for(float y1 = 0.001f; y1 <= 10.0f; y1 += 2.71828f) | |||||
| for(float x2 = x1 + 0.001f; x2 <= 15.02f; x2 += 2.71828f) for(float y2 = 0.001f; y2 <= y2 - 3.1f; y2 += 2.71828f) | |||||
| for(float w1 = 0.01f; w1 <= 0.999f; w1 += 0.113f) for(float w2 = 0.001f; w2 <= 1.0f - w1 - 0.0012; w2 += 0.1212f) | |||||
| { | |||||
| float a[2] = {0.0f, 0.0f}, | |||||
| b[2] = {x2, y2}, | |||||
| c[2] = {x1, y1}, | |||||
| p[2] = {w1*x1 + w2*x2, w1*y1 + w2*y2}; | |||||
| EXPECT_EQ(-1,isect_point_tri_v2(p, a, b, c)); | |||||
| } | |||||
| } | |||||
| TEST(math_geom, IsectPointTri2DManyTrianglesOutside) { | |||||
| for(float x1 = 4.001f; x1 <= 12.0f; x1 += 2.71828f) for(float y1 = 0.001f; y1 <= 10.0f; y1 += 2.71828f) | |||||
| for(float x2 = x1 + 0.001f; x2 <= 15.02f; x2 += 2.71828f) for(float y2 = 0.001f; y2 <= y2 - 3.1f; y2 += 2.71828f) | |||||
| for(float w1 = 0.01f; w1 <= 0.999f; w1 += 0.113f) for(float w2 = 0.001f; w2 <= 1.0f - w1 - 0.0012; w2 += 0.1212f) | |||||
| { | |||||
| float a[2] = {0.0f, 0.0f}, | |||||
| b[2] = {x1, y1}, | |||||
| c[2] = {x2, y2}, | |||||
| p[2] = {-0.01f, -0.01f}; | |||||
| EXPECT_EQ(0,isect_point_tri_v2(p, a, b, c)); | |||||
| } | |||||
| } | |||||
| Context not available. | |||||