Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/curves_geometry_test.cc
| Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | curves.curve_types_for_write().copy_from({ | ||||
| CURVE_TYPE_NURBS, | CURVE_TYPE_NURBS, | ||||
| CURVE_TYPE_CATMULL_ROM, | CURVE_TYPE_CATMULL_ROM, | ||||
| CURVE_TYPE_CATMULL_ROM, | CURVE_TYPE_CATMULL_ROM, | ||||
| CURVE_TYPE_CATMULL_ROM, | CURVE_TYPE_CATMULL_ROM, | ||||
| CURVE_TYPE_POLY, | CURVE_TYPE_POLY, | ||||
| CURVE_TYPE_POLY, | CURVE_TYPE_POLY, | ||||
| CURVE_TYPE_POLY, | CURVE_TYPE_POLY, | ||||
| }); | }); | ||||
| std::array<int, CURVE_TYPES_NUM> counts = curves.count_curve_types(); | curves.update_curve_types(); | ||||
| const std::array<int, CURVE_TYPES_NUM> &counts = curves.curve_type_counts(); | |||||
| EXPECT_EQ(counts[CURVE_TYPE_CATMULL_ROM], 3); | EXPECT_EQ(counts[CURVE_TYPE_CATMULL_ROM], 3); | ||||
| EXPECT_EQ(counts[CURVE_TYPE_POLY], 3); | EXPECT_EQ(counts[CURVE_TYPE_POLY], 3); | ||||
| EXPECT_EQ(counts[CURVE_TYPE_BEZIER], 1); | EXPECT_EQ(counts[CURVE_TYPE_BEZIER], 1); | ||||
| EXPECT_EQ(counts[CURVE_TYPE_NURBS], 3); | EXPECT_EQ(counts[CURVE_TYPE_NURBS], 3); | ||||
| } | } | ||||
| TEST(curves_geometry, CatmullRomEvaluation) | TEST(curves_geometry, CatmullRomEvaluation) | ||||
| { | { | ||||
| CurvesGeometry curves(4, 1); | CurvesGeometry curves(4, 1); | ||||
| curves.curve_types_for_write().fill(CURVE_TYPE_CATMULL_ROM); | curves.fill_curve_types(CURVE_TYPE_CATMULL_ROM); | ||||
| curves.resolution_for_write().fill(12); | curves.resolution_for_write().fill(12); | ||||
| curves.offsets_for_write().last() = 4; | curves.offsets_for_write().last() = 4; | ||||
| curves.cyclic_for_write().fill(false); | curves.cyclic_for_write().fill(false); | ||||
| MutableSpan<float3> positions = curves.positions_for_write(); | MutableSpan<float3> positions = curves.positions_for_write(); | ||||
| positions[0] = {1, 1, 0}; | positions[0] = {1, 1, 0}; | ||||
| positions[1] = {0, 1, 0}; | positions[1] = {0, 1, 0}; | ||||
| positions[2] = {0, 0, 0}; | positions[2] = {0, 0, 0}; | ||||
| ▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | TEST(curves_geometry, CatmullRomEvaluation) | ||||
| for (const int i : evaluated_positions.index_range()) { | for (const int i : evaluated_positions.index_range()) { | ||||
| EXPECT_V3_NEAR(evaluated_positions[i], result_2[i], 1e-5f); | EXPECT_V3_NEAR(evaluated_positions[i], result_2[i], 1e-5f); | ||||
| } | } | ||||
| } | } | ||||
| TEST(curves_geometry, CatmullRomTwoPointCyclic) | TEST(curves_geometry, CatmullRomTwoPointCyclic) | ||||
| { | { | ||||
| CurvesGeometry curves(2, 1); | CurvesGeometry curves(2, 1); | ||||
| curves.curve_types_for_write().fill(CURVE_TYPE_CATMULL_ROM); | curves.fill_curve_types(CURVE_TYPE_CATMULL_ROM); | ||||
| curves.resolution_for_write().fill(12); | curves.resolution_for_write().fill(12); | ||||
| curves.offsets_for_write().last() = 2; | curves.offsets_for_write().last() = 2; | ||||
| curves.cyclic_for_write().fill(true); | curves.cyclic_for_write().fill(true); | ||||
| /* The curve should still be cyclic when there are only two control points. */ | /* The curve should still be cyclic when there are only two control points. */ | ||||
| EXPECT_EQ(curves.evaluated_points_num(), 24); | EXPECT_EQ(curves.evaluated_points_num(), 24); | ||||
| } | } | ||||
| TEST(curves_geometry, BezierPositionEvaluation) | TEST(curves_geometry, BezierPositionEvaluation) | ||||
| { | { | ||||
| CurvesGeometry curves(2, 1); | CurvesGeometry curves(2, 1); | ||||
| curves.curve_types_for_write().fill(CURVE_TYPE_BEZIER); | curves.fill_curve_types(CURVE_TYPE_BEZIER); | ||||
| curves.resolution_for_write().fill(12); | curves.resolution_for_write().fill(12); | ||||
| curves.offsets_for_write().last() = 2; | curves.offsets_for_write().last() = 2; | ||||
| MutableSpan<float3> handles_left = curves.handle_positions_left_for_write(); | MutableSpan<float3> handles_left = curves.handle_positions_left_for_write(); | ||||
| MutableSpan<float3> handles_right = curves.handle_positions_right_for_write(); | MutableSpan<float3> handles_right = curves.handle_positions_right_for_write(); | ||||
| MutableSpan<float3> positions = curves.positions_for_write(); | MutableSpan<float3> positions = curves.positions_for_write(); | ||||
| positions.first() = {-1, 0, 0}; | positions.first() = {-1, 0, 0}; | ||||
| positions.last() = {1, 0, 0}; | positions.last() = {1, 0, 0}; | ||||
| Show All 20 Lines | static const Array<float3> result_1{{ | ||||
| {0.760127, 0.00954859, 0}, | {0.760127, 0.00954859, 0}, | ||||
| {1, 0, 0}, | {1, 0, 0}, | ||||
| }}; | }}; | ||||
| for (const int i : evaluated_positions.index_range()) { | for (const int i : evaluated_positions.index_range()) { | ||||
| EXPECT_V3_NEAR(evaluated_positions[i], result_1[i], 1e-5f); | EXPECT_V3_NEAR(evaluated_positions[i], result_1[i], 1e-5f); | ||||
| } | } | ||||
| curves.resize(4, 2); | curves.resize(4, 2); | ||||
| curves.curve_types_for_write().fill(CURVE_TYPE_BEZIER); | curves.fill_curve_types(CURVE_TYPE_BEZIER); | ||||
| curves.resolution_for_write().fill(9); | curves.resolution_for_write().fill(9); | ||||
| curves.offsets_for_write().last() = 4; | curves.offsets_for_write().last() = 4; | ||||
| handles_left = curves.handle_positions_left_for_write(); | handles_left = curves.handle_positions_left_for_write(); | ||||
| handles_right = curves.handle_positions_right_for_write(); | handles_right = curves.handle_positions_right_for_write(); | ||||
| positions = curves.positions_for_write(); | positions = curves.positions_for_write(); | ||||
| positions[2] = {-1, 1, 0}; | positions[2] = {-1, 1, 0}; | ||||
| positions[3] = {1, 1, 0}; | positions[3] = {1, 1, 0}; | ||||
| handles_right[2] = {-0.5f, 1.5f, 0.0f}; | handles_right[2] = {-0.5f, 1.5f, 0.0f}; | ||||
| Show All 30 Lines | TEST(curves_geometry, BezierPositionEvaluation) | ||||
| for (const int i : evaluated_positions.index_range()) { | for (const int i : evaluated_positions.index_range()) { | ||||
| EXPECT_V3_NEAR(evaluated_positions[i], result_2[i], 1e-5f); | EXPECT_V3_NEAR(evaluated_positions[i], result_2[i], 1e-5f); | ||||
| } | } | ||||
| } | } | ||||
| TEST(curves_geometry, NURBSEvaluation) | TEST(curves_geometry, NURBSEvaluation) | ||||
| { | { | ||||
| CurvesGeometry curves(4, 1); | CurvesGeometry curves(4, 1); | ||||
| curves.curve_types_for_write().fill(CURVE_TYPE_NURBS); | curves.fill_curve_types(CURVE_TYPE_NURBS); | ||||
| curves.resolution_for_write().fill(10); | curves.resolution_for_write().fill(10); | ||||
| curves.offsets_for_write().last() = 4; | curves.offsets_for_write().last() = 4; | ||||
| MutableSpan<float3> positions = curves.positions_for_write(); | MutableSpan<float3> positions = curves.positions_for_write(); | ||||
| positions[0] = {1, 1, 0}; | positions[0] = {1, 1, 0}; | ||||
| positions[1] = {0, 1, 0}; | positions[1] = {0, 1, 0}; | ||||
| positions[2] = {0, 0, 0}; | positions[2] = {0, 0, 0}; | ||||
| positions[3] = {-1, 0, 0}; | positions[3] = {-1, 0, 0}; | ||||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | TEST(curves_geometry, NURBSEvaluation) | ||||
| for (const int i : evaluated_positions.index_range()) { | for (const int i : evaluated_positions.index_range()) { | ||||
| EXPECT_V3_NEAR(evaluated_positions[i], result_3[i], 1e-5f); | EXPECT_V3_NEAR(evaluated_positions[i], result_3[i], 1e-5f); | ||||
| } | } | ||||
| } | } | ||||
| TEST(curves_geometry, BezierGenericEvaluation) | TEST(curves_geometry, BezierGenericEvaluation) | ||||
| { | { | ||||
| CurvesGeometry curves(3, 1); | CurvesGeometry curves(3, 1); | ||||
| curves.curve_types_for_write().fill(CURVE_TYPE_BEZIER); | curves.fill_curve_types(CURVE_TYPE_BEZIER); | ||||
| curves.resolution_for_write().fill(8); | curves.resolution_for_write().fill(8); | ||||
| curves.offsets_for_write().last() = 3; | curves.offsets_for_write().last() = 3; | ||||
| MutableSpan<float3> handles_left = curves.handle_positions_left_for_write(); | MutableSpan<float3> handles_left = curves.handle_positions_left_for_write(); | ||||
| MutableSpan<float3> handles_right = curves.handle_positions_right_for_write(); | MutableSpan<float3> handles_right = curves.handle_positions_right_for_write(); | ||||
| MutableSpan<float3> positions = curves.positions_for_write(); | MutableSpan<float3> positions = curves.positions_for_write(); | ||||
| positions.first() = {-1, 0, 0}; | positions.first() = {-1, 0, 0}; | ||||
| handles_right.first() = {-1, 1, 0}; | handles_right.first() = {-1, 1, 0}; | ||||
| ▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines | |||||