Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-03-25 17:03:35 +0300
committerHans Goudey <h.goudey@me.com>2022-03-25 17:03:35 +0300
commitcea51c1bb500eb2cfca425e1cae5dcc419dda2ce (patch)
treea7074ea2c67c0c8a40d27faac5ebfa1793390656 /source/blender/blenkernel/intern/curves_geometry_test.cc
parentc0016d85b2a62858229d31bd97399fbe2608f99d (diff)
Curves: Bezier and general interpolate to evaluated utility
This commit implements generic evaluation for Bezier curves (which is really just linear interpolation, since attributes are not stored on Bezier handles). For complete parity with the old curve type, we would have to add options for this (RNA: `Spline.radius_interpolation`), but it's not clear that we want to do that. This also adds a generic `interpolate_to_evaluate` utility on curves that hides the implementation details. Though there is theoretically a performance cost to that, without some abstraction calling code would usually be too complex. Differential Revision: https://developer.blender.org/D14447
Diffstat (limited to 'source/blender/blenkernel/intern/curves_geometry_test.cc')
-rw-r--r--source/blender/blenkernel/intern/curves_geometry_test.cc73
1 files changed, 73 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/curves_geometry_test.cc b/source/blender/blenkernel/intern/curves_geometry_test.cc
index 574f90f2e51..e4dc9eead60 100644
--- a/source/blender/blenkernel/intern/curves_geometry_test.cc
+++ b/source/blender/blenkernel/intern/curves_geometry_test.cc
@@ -405,4 +405,77 @@ TEST(curves_geometry, NURBSEvaluation)
}
}
+TEST(curves_geometry, BezierGenericEvaluation)
+{
+ CurvesGeometry curves(3, 1);
+ curves.curve_types().fill(CURVE_TYPE_BEZIER);
+ curves.resolution().fill(8);
+ curves.offsets().last() = 3;
+
+ MutableSpan<float3> handles_left = curves.handle_positions_left();
+ MutableSpan<float3> handles_right = curves.handle_positions_right();
+ MutableSpan<float3> positions = curves.positions();
+ positions.first() = {-1, 0, 0};
+ handles_right.first() = {-1, 1, 0};
+ handles_left[1] = {0, 0, 0};
+ positions[1] = {1, 0, 0};
+ handles_right[1] = {2, 0, 0};
+ handles_left.last() = {1, 1, 0};
+ positions.last() = {2, 1, 0};
+
+ /* Dangling handles shouldn't be used in a non-cyclic curve. */
+ handles_left.first() = {100, 100, 100};
+ handles_right.last() = {100, 100, 100};
+
+ Span<float3> evaluated_positions = curves.evaluated_positions();
+ static const Array<float3> result_1{{
+ {-1.0f, 0.0f, 0.0f},
+ {-0.955078f, 0.287109f, 0.0f},
+ {-0.828125f, 0.421875f, 0.0f},
+ {-0.630859f, 0.439453f, 0.0f},
+ {-0.375f, 0.375f, 0.0f},
+ {-0.0722656f, 0.263672f, 0.0f},
+ {0.265625f, 0.140625f, 0.0f},
+ {0.626953f, 0.0410156f, 0.0f},
+ {1.0f, 0.0f, 0.0f},
+ {1.28906f, 0.0429688f, 0.0f},
+ {1.4375f, 0.15625f, 0.0f},
+ {1.49219f, 0.316406f, 0.0f},
+ {1.5f, 0.5f, 0.0f},
+ {1.50781f, 0.683594f, 0.0f},
+ {1.5625f, 0.84375f, 0.0f},
+ {1.71094f, 0.957031f, 0.0f},
+ {2.0f, 1.0f, 0.0f},
+ }};
+ for (const int i : evaluated_positions.index_range()) {
+ EXPECT_V3_NEAR(evaluated_positions[i], result_1[i], 1e-5f);
+ }
+
+ Array<float> radii{{0.0f, 1.0f, 2.0f}};
+ Array<float> evaluated_radii(17);
+ curves.interpolate_to_evaluated(0, radii.as_span(), evaluated_radii.as_mutable_span());
+ static const Array<float> result_2{{
+ 0.0f,
+ 0.125f,
+ 0.25f,
+ 0.375f,
+ 0.5f,
+ 0.625f,
+ 0.75f,
+ 0.875f,
+ 1.0f,
+ 1.125f,
+ 1.25f,
+ 1.375f,
+ 1.5f,
+ 1.625f,
+ 1.75f,
+ 1.875f,
+ 2.0f,
+ }};
+ for (const int i : evaluated_radii.index_range()) {
+ EXPECT_NEAR(evaluated_radii[i], result_2[i], 1e-6f);
+ }
+}
+
} // namespace blender::bke::tests