Cleanup: Adjust naming in new curves code

Rename "size" variables and functions to use "num" instead,
based on T85728 (though this doesn't apply to simple C++
containers, it applies here). Rename "range" to "points" in
some functions, so be more specific.

Differential Revision: https://developer.blender.org/D14431
This commit is contained in:
Hans Goudey 2022-03-23 23:01:02 -05:00
parent a1598d6835
commit e253f9f66d
Notes: blender-bot 2023-02-14 06:00:45 +01:00
Referenced by commit 6e72e3fdb2, Cleanup: Further renaming in new curves code
22 changed files with 146 additions and 146 deletions

View File

@ -122,14 +122,14 @@ class CurvesGeometry : public ::CurvesGeometry {
* Accessors.
*/
int points_size() const;
int curves_size() const;
int num_points() const;
int num_curves() const;
IndexRange points_range() const;
IndexRange curves_range() const;
/**
* The index of the first point in every curve. The size of this span is one larger than the
* number of curves. Consider using #range_for_curve rather than using the offsets directly.
* number of curves. Consider using #points_for_curve rather than using the offsets directly.
*/
Span<int> offsets() const;
MutableSpan<int> offsets();
@ -137,8 +137,8 @@ class CurvesGeometry : public ::CurvesGeometry {
/**
* Access a range of indices of point data for a specific curve.
*/
IndexRange range_for_curve(int index) const;
IndexRange range_for_curves(IndexRange curves) const;
IndexRange points_for_curve(int index) const;
IndexRange points_for_curves(IndexRange curves) const;
/** The type (#CurveType) of each curve, or potentially a single if all are the same type. */
VArray<int8_t> curve_types() const;
@ -249,11 +249,11 @@ class CurvesGeometry : public ::CurvesGeometry {
* Access a range of indices of point data for a specific curve.
* Call #evaluated_offsets() first to ensure that the evaluated offsets cache is current.
*/
IndexRange evaluated_range_for_curve(int index) const;
IndexRange evaluated_points_for_curve(int index) const;
/**
* The index of the first evaluated point for every curve. The size of this span is one larger
* than the number of curves. Consider using #evaluated_range_for_curve rather than using the
* than the number of curves. Consider using #evaluated_points_for_curve rather than using the
* offsets directly.
*/
Span<int> evaluated_offsets() const;
@ -275,7 +275,7 @@ class CurvesGeometry : public ::CurvesGeometry {
* Change the number of elements. New values for existing attributes should be properly
* initialized afterwards.
*/
void resize(int point_size, int curve_size);
void resize(int num_points, int num_curves);
/** Call after deforming the position attribute. */
void tag_positions_changed();
@ -314,9 +314,9 @@ namespace curves {
* and the fact that curves with two points cannot be cyclic. The logic is simple, but this
* function should be used to make intentions clearer.
*/
inline int curve_segment_size(const int size, const bool cyclic)
inline int curve_segment_size(const int num_points, const bool cyclic)
{
return (cyclic && size > 2) ? size : size - 1;
return (cyclic && num_points > 2) ? num_points : num_points - 1;
}
namespace bezier {
@ -381,10 +381,10 @@ namespace catmull_rom {
/**
* Calculate the number of evaluated points that #interpolate_to_evaluated is expected to produce.
* \param size: The number of points in the curve.
* \param num_points: The number of points in the curve.
* \param resolution: The resolution for each segment.
*/
int calculate_evaluated_size(int size, bool cyclic, int resolution);
int calculate_evaluated_size(int num_points, bool cyclic, int resolution);
/**
* Evaluate the Catmull Rom curve. The length of the #dst span should be calculated with
@ -399,7 +399,7 @@ namespace nurbs {
/**
* Checks the conditions that a NURBS curve needs to evaluate.
*/
bool check_valid_size_and_order(int size, int8_t order, bool cyclic, KnotsMode knots_mode);
bool check_valid_size_and_order(int num_points, int8_t order, bool cyclic, KnotsMode knots_mode);
/**
* Calculate the standard evaluated size for a NURBS curve, using the standard that
@ -410,14 +410,14 @@ bool check_valid_size_and_order(int size, int8_t order, bool cyclic, KnotsMode k
* shared.
*/
int calculate_evaluated_size(
int size, int8_t order, bool cyclic, int resolution, KnotsMode knots_mode);
int num_points, int8_t order, bool cyclic, int resolution, KnotsMode knots_mode);
/**
* Calculate the length of the knot vector for a NURBS curve with the given properties.
* The knots must be longer for a cyclic curve, for example, in order to provide weights for the
* last evaluated points that are also influenced by the first control points.
*/
int knots_size(int size, int8_t order, bool cyclic);
int knots_size(int num_points, int8_t order, bool cyclic);
/**
* Calculate the knots for a spline given its properties, based on built-in standards defined by
@ -428,7 +428,7 @@ int knots_size(int size, int8_t order, bool cyclic);
* changes, and is generally more intuitive than defining the knot vector manually.
*/
void calculate_knots(
int size, KnotsMode mode, int8_t order, bool cyclic, MutableSpan<float> knots);
int num_points, KnotsMode mode, int8_t order, bool cyclic, MutableSpan<float> knots);
/**
* Based on the knots, the order, and other properties of a NURBS curve, calculate a cache that can
@ -436,7 +436,7 @@ void calculate_knots(
* two pieces of information for every evaluated point: the first control point that influences it,
* and a weight for each control point.
*/
void calculate_basis_cache(int size,
void calculate_basis_cache(int num_points,
int evaluated_size,
int8_t order,
bool cyclic,
@ -461,11 +461,11 @@ void interpolate_to_evaluated(const BasisCache &basis_cache,
} // namespace curves
Curves *curves_new_nomain(int point_size, int curves_size);
Curves *curves_new_nomain(int num_points, int num_curves);
/**
* Create a new curves data-block containing a single curve with the given length and type.
*/
Curves *curves_new_nomain_single(int point_size, CurveType type);
Curves *curves_new_nomain_single(int num_points, CurveType type);
} // namespace blender::bke

View File

@ -9,11 +9,11 @@
namespace blender::bke::curves::catmull_rom {
int calculate_evaluated_size(const int size, const bool cyclic, const int resolution)
int calculate_evaluated_size(const int num_points, const bool cyclic, const int resolution)
{
const int eval_size = resolution * curve_segment_size(size, cyclic);
const int eval_size = resolution * curve_segment_size(num_points, cyclic);
/* If the curve isn't cyclic, one last point is added to the final point. */
return (cyclic && size > 2) ? eval_size : eval_size + 1;
return (cyclic && num_points > 2) ? eval_size : eval_size + 1;
}
/* Adapted from Cycles #catmull_rom_basis_eval function. */

View File

@ -398,7 +398,7 @@ std::unique_ptr<CurveEval> curves_to_curve_eval(const Curves &curves)
VArray<int8_t> curve_types = geometry.curve_types();
std::unique_ptr<CurveEval> curve_eval = std::make_unique<CurveEval>();
for (const int curve_index : curve_types.index_range()) {
const IndexRange point_range = geometry.range_for_curve(curve_index);
const IndexRange point_range = geometry.points_for_curve(curve_index);
std::unique_ptr<Spline> spline;
switch (curve_types[curve_index]) {
@ -489,7 +489,7 @@ Curves *curve_eval_to_curves(const CurveEval &curve_eval)
const Spline &spline = *curve_eval.splines()[curve_index];
curve_types[curve_index] = curve_eval.splines()[curve_index]->type();
const IndexRange point_range = geometry.range_for_curve(curve_index);
const IndexRange point_range = geometry.points_for_curve(curve_index);
switch (spline.type()) {
case CURVE_TYPE_POLY:

View File

@ -10,53 +10,53 @@
namespace blender::bke::curves::nurbs {
bool check_valid_size_and_order(const int size,
bool check_valid_size_and_order(const int num_points,
const int8_t order,
const bool cyclic,
const KnotsMode knots_mode)
{
if (size < order) {
if (num_points < order) {
return false;
}
if (ELEM(knots_mode, NURBS_KNOT_MODE_BEZIER, NURBS_KNOT_MODE_ENDPOINT_BEZIER)) {
if (knots_mode == NURBS_KNOT_MODE_BEZIER && size <= order) {
if (knots_mode == NURBS_KNOT_MODE_BEZIER && num_points <= order) {
return false;
}
return (!cyclic || size % (order - 1) == 0);
return (!cyclic || num_points % (order - 1) == 0);
}
return true;
}
int calculate_evaluated_size(const int size,
int calculate_evaluated_size(const int num_points,
const int8_t order,
const bool cyclic,
const int resolution,
const KnotsMode knots_mode)
{
if (!check_valid_size_and_order(size, order, cyclic, knots_mode)) {
if (!check_valid_size_and_order(num_points, order, cyclic, knots_mode)) {
return 0;
}
return resolution * curve_segment_size(size, cyclic);
return resolution * curve_segment_size(num_points, cyclic);
}
int knots_size(const int size, const int8_t order, const bool cyclic)
int knots_size(const int num_points, const int8_t order, const bool cyclic)
{
if (cyclic) {
return size + order * 2 - 1;
return num_points + order * 2 - 1;
}
return size + order;
return num_points + order;
}
void calculate_knots(const int size,
void calculate_knots(const int num_points,
const KnotsMode mode,
const int8_t order,
const bool cyclic,
MutableSpan<float> knots)
{
BLI_assert(knots.size() == knots_size(size, order, cyclic));
UNUSED_VARS_NDEBUG(size);
BLI_assert(knots.size() == knots_size(num_points, order, cyclic));
UNUSED_VARS_NDEBUG(num_points);
const bool is_bezier = ELEM(mode, NURBS_KNOT_MODE_BEZIER, NURBS_KNOT_MODE_ENDPOINT_BEZIER);
const bool is_end_point = ELEM(mode, NURBS_KNOT_MODE_ENDPOINT, NURBS_KNOT_MODE_ENDPOINT_BEZIER);
@ -94,7 +94,7 @@ void calculate_knots(const int size,
}
static void calculate_basis_for_point(const float parameter,
const int size,
const int num_points,
const int degree,
const Span<float> knots,
MutableSpan<float> r_weights,
@ -104,7 +104,7 @@ static void calculate_basis_for_point(const float parameter,
int start = 0;
int end = 0;
for (const int i : IndexRange(size + degree)) {
for (const int i : IndexRange(num_points + degree)) {
const bool knots_equal = knots[i] == knots[i + 1];
if (knots_equal || parameter < knots[i] || parameter > knots[i + 1]) {
continue;
@ -121,7 +121,7 @@ static void calculate_basis_for_point(const float parameter,
for (const int i_order : IndexRange(2, degree)) {
if (end + i_order >= knots.size()) {
end = size + degree - i_order;
end = num_points + degree - i_order;
}
for (const int i : IndexRange(end - start + 1)) {
const int knot_index = start + i;
@ -146,14 +146,14 @@ static void calculate_basis_for_point(const float parameter,
r_start_index = start;
}
void calculate_basis_cache(const int size,
void calculate_basis_cache(const int num_points,
const int evaluated_size,
const int8_t order,
const bool cyclic,
const Span<float> knots,
BasisCache &basis_cache)
{
BLI_assert(size > 0);
BLI_assert(num_points > 0);
BLI_assert(evaluated_size > 0);
const int8_t degree = order - 1;
@ -168,7 +168,7 @@ void calculate_basis_cache(const int size,
MutableSpan<float> basis_weights(basis_cache.weights);
MutableSpan<int> basis_start_indices(basis_cache.start_indices);
const int last_control_point_index = cyclic ? size + degree : size;
const int last_control_point_index = cyclic ? num_points + degree : num_points;
const int evaluated_segment_size = curve_segment_size(evaluated_size, cyclic);
const float start = knots[degree];
@ -176,7 +176,7 @@ void calculate_basis_cache(const int size,
const float step = (end - start) / evaluated_segment_size;
for (const int i : IndexRange(evaluated_size)) {
/* Clamp parameter due to floating point inaccuracy. */
const float parameter = std::clamp(start + step * i, knots[0], knots[size + degree]);
const float parameter = std::clamp(start + step * i, knots[0], knots[num_points + degree]);
MutableSpan<float> point_weights = basis_weights.slice(i * order, order);

View File

@ -366,19 +366,19 @@ void BKE_curves_batch_cache_free(Curves *curves)
namespace blender::bke {
Curves *curves_new_nomain(const int point_size, const int curves_size)
Curves *curves_new_nomain(const int num_points, const int num_curves)
{
Curves *curves = static_cast<Curves *>(BKE_id_new_nomain(ID_CV, nullptr));
CurvesGeometry &geometry = CurvesGeometry::wrap(curves->geometry);
geometry.resize(point_size, curves_size);
geometry.resize(num_points, num_curves);
return curves;
}
Curves *curves_new_nomain_single(const int point_size, const CurveType type)
Curves *curves_new_nomain_single(const int num_points, const CurveType type)
{
Curves *curves = curves_new_nomain(point_size, 1);
Curves *curves = curves_new_nomain(num_points, 1);
CurvesGeometry &geometry = CurvesGeometry::wrap(curves->geometry);
geometry.offsets().last() = point_size;
geometry.offsets().last() = num_points;
geometry.curve_types().first() = type;
return curves;
}

View File

@ -149,24 +149,24 @@ CurvesGeometry::~CurvesGeometry()
/** \name Accessors
* \{ */
int CurvesGeometry::points_size() const
int CurvesGeometry::num_points() const
{
return this->point_size;
}
int CurvesGeometry::curves_size() const
int CurvesGeometry::num_curves() const
{
return this->curve_size;
}
IndexRange CurvesGeometry::points_range() const
{
return IndexRange(this->points_size());
return IndexRange(this->num_points());
}
IndexRange CurvesGeometry::curves_range() const
{
return IndexRange(this->curves_size());
return IndexRange(this->num_curves());
}
IndexRange CurvesGeometry::range_for_curve(const int index) const
IndexRange CurvesGeometry::points_for_curve(const int index) const
{
BLI_assert(this->curve_size > 0);
BLI_assert(this->curve_offsets != nullptr);
@ -175,7 +175,7 @@ IndexRange CurvesGeometry::range_for_curve(const int index) const
return {offset, offset_next - offset};
}
IndexRange CurvesGeometry::range_for_curves(const IndexRange curves) const
IndexRange CurvesGeometry::points_for_curves(const IndexRange curves) const
{
BLI_assert(this->curve_size > 0);
BLI_assert(this->curve_offsets != nullptr);
@ -186,7 +186,7 @@ IndexRange CurvesGeometry::range_for_curves(const IndexRange curves) const
static int domain_size(const CurvesGeometry &curves, const AttributeDomain domain)
{
return domain == ATTR_DOMAIN_POINT ? curves.points_size() : curves.curves_size();
return domain == ATTR_DOMAIN_POINT ? curves.num_points() : curves.num_curves();
}
static CustomData &domain_custom_data(CurvesGeometry &curves, const AttributeDomain domain)
@ -431,7 +431,7 @@ static void calculate_evaluated_offsets(const CurvesGeometry &curves,
VArray<int8_t> nurbs_knots_modes = curves.nurbs_knots_modes();
build_offsets(offsets, [&](const int curve_index) -> int {
const IndexRange points = curves.range_for_curve(curve_index);
const IndexRange points = curves.points_for_curve(curve_index);
switch (types[curve_index]) {
case CURVE_TYPE_CATMULL_ROM:
return curves::catmull_rom::calculate_evaluated_size(
@ -463,7 +463,7 @@ int CurvesGeometry::evaluated_points_size() const
return this->evaluated_offsets().last();
}
IndexRange CurvesGeometry::evaluated_range_for_curve(int index) const
IndexRange CurvesGeometry::evaluated_points_for_curve(int index) const
{
BLI_assert(!this->runtime->offsets_cache_dirty);
return offsets_to_range(this->runtime->evaluated_offsets_cache.as_span(), index);
@ -482,10 +482,10 @@ Span<int> CurvesGeometry::evaluated_offsets() const
}
threading::isolate_task([&]() {
this->runtime->evaluated_offsets_cache.resize(this->curves_size() + 1);
this->runtime->evaluated_offsets_cache.resize(this->num_curves() + 1);
if (this->has_curve_with_type(CURVE_TYPE_BEZIER)) {
this->runtime->bezier_evaluated_offsets.resize(this->points_size());
this->runtime->bezier_evaluated_offsets.resize(this->num_points());
}
else {
this->runtime->bezier_evaluated_offsets.clear_and_make_inline();
@ -536,7 +536,7 @@ void CurvesGeometry::ensure_nurbs_basis_cache() const
return;
}
this->runtime->nurbs_basis_cache.resize(this->curves_size());
this->runtime->nurbs_basis_cache.resize(this->num_curves());
MutableSpan<curves::nurbs::BasisCache> basis_caches(this->runtime->nurbs_basis_cache);
VArray<bool> cyclic = this->cyclic();
@ -545,8 +545,8 @@ void CurvesGeometry::ensure_nurbs_basis_cache() const
threading::parallel_for(nurbs_mask.index_range(), 64, [&](const IndexRange range) {
for (const int curve_index : nurbs_mask.slice(range)) {
const IndexRange points = this->range_for_curve(curve_index);
const IndexRange evaluated_points = this->evaluated_range_for_curve(curve_index);
const IndexRange points = this->points_for_curve(curve_index);
const IndexRange evaluated_points = this->evaluated_points_for_curve(curve_index);
const int8_t order = orders[curve_index];
const bool is_cyclic = cyclic[curve_index];
@ -598,8 +598,8 @@ Span<float3> CurvesGeometry::evaluated_positions() const
threading::parallel_for(this->curves_range(), 128, [&](IndexRange curves_range) {
for (const int curve_index : curves_range) {
const IndexRange points = this->range_for_curve(curve_index);
const IndexRange evaluated_points = this->evaluated_range_for_curve(curve_index);
const IndexRange points = this->points_for_curve(curve_index);
const IndexRange evaluated_points = this->evaluated_points_for_curve(curve_index);
switch (types[curve_index]) {
case CURVE_TYPE_CATMULL_ROM:
@ -645,16 +645,16 @@ Span<float3> CurvesGeometry::evaluated_positions() const
/** \name Operations
* \{ */
void CurvesGeometry::resize(const int point_size, const int curve_size)
void CurvesGeometry::resize(const int num_points, const int num_curves)
{
if (point_size != this->point_size) {
CustomData_realloc(&this->point_data, point_size);
this->point_size = point_size;
if (num_points != this->point_size) {
CustomData_realloc(&this->point_data, num_points);
this->point_size = num_points;
}
if (curve_size != this->curve_size) {
CustomData_realloc(&this->curve_data, curve_size);
this->curve_size = curve_size;
this->curve_offsets = (int *)MEM_reallocN(this->curve_offsets, sizeof(int) * (curve_size + 1));
if (num_curves != this->curve_size) {
CustomData_realloc(&this->curve_data, num_curves);
this->curve_size = num_curves;
this->curve_offsets = (int *)MEM_reallocN(this->curve_offsets, sizeof(int) * (num_curves + 1));
}
this->tag_topology_changed();
this->update_customdata_pointers();
@ -727,7 +727,7 @@ static std::optional<bounds::MinMaxResult<float3>> curves_bounds(const CurvesGeo
{
Span<float3> positions = curves.positions();
if (curves.radius) {
Span<float> radii{curves.radius, curves.points_size()};
Span<float> radii{curves.radius, curves.num_points()};
return bounds::min_max_with_radii(positions, radii);
}
return bounds::min_max(positions);
@ -784,7 +784,7 @@ static CurvesGeometry copy_with_removed_curves(const CurvesGeometry &curves,
new_curve_ranges.append(IndexRange(new_tot_curves, curve_range.size()));
new_tot_curves += curve_range.size();
const IndexRange old_point_range = curves.range_for_curves(curve_range);
const IndexRange old_point_range = curves.points_for_curves(curve_range);
old_point_ranges.append(old_point_range);
new_point_ranges.append(IndexRange(new_tot_points, old_point_range.size()));
new_tot_points += old_point_range.size();
@ -889,7 +889,7 @@ static void reverse_curve_point_data(const CurvesGeometry &curves,
{
threading::parallel_for(curve_selection.index_range(), 256, [&](IndexRange range) {
for (const int curve_i : curve_selection.slice(range)) {
data.slice(curves.range_for_curve(curve_i)).reverse();
data.slice(curves.points_for_curve(curve_i)).reverse();
}
});
}
@ -902,7 +902,7 @@ static void reverse_swap_curve_point_data(const CurvesGeometry &curves,
{
threading::parallel_for(curve_selection.index_range(), 256, [&](IndexRange range) {
for (const int curve_i : curve_selection.slice(range)) {
const IndexRange points = curves.range_for_curve(curve_i);
const IndexRange points = curves.points_for_curve(curve_i);
MutableSpan<T> a = data_a.slice(points);
MutableSpan<T> b = data_b.slice(points);
for (const int i : IndexRange(points.size() / 2)) {
@ -926,7 +926,7 @@ static bool layer_matches_name_and_type(const CustomDataLayer &layer,
void CurvesGeometry::reverse_curves(const IndexMask curves_to_reverse)
{
CustomData_duplicate_referenced_layers(&this->point_data, this->points_size());
CustomData_duplicate_referenced_layers(&this->point_data, this->num_points());
/* Collect the Bezier handle attributes while iterating through the point custom data layers;
* they need special treatment later. */
@ -940,22 +940,22 @@ void CurvesGeometry::reverse_curves(const IndexMask curves_to_reverse)
if (positions_left.is_empty() &&
layer_matches_name_and_type(layer, ATTR_HANDLE_POSITION_LEFT, CD_PROP_FLOAT3)) {
positions_left = {static_cast<float3 *>(layer.data), this->points_size()};
positions_left = {static_cast<float3 *>(layer.data), this->num_points()};
continue;
}
if (positions_right.is_empty() &&
layer_matches_name_and_type(layer, ATTR_HANDLE_POSITION_RIGHT, CD_PROP_FLOAT3)) {
positions_right = {static_cast<float3 *>(layer.data), this->points_size()};
positions_right = {static_cast<float3 *>(layer.data), this->num_points()};
continue;
}
if (types_left.is_empty() &&
layer_matches_name_and_type(layer, ATTR_HANDLE_TYPE_LEFT, CD_PROP_INT8)) {
types_left = {static_cast<int8_t *>(layer.data), this->points_size()};
types_left = {static_cast<int8_t *>(layer.data), this->num_points()};
continue;
}
if (types_right.is_empty() &&
layer_matches_name_and_type(layer, ATTR_HANDLE_TYPE_RIGHT, CD_PROP_INT8)) {
types_right = {static_cast<int8_t *>(layer.data), this->points_size()};
types_right = {static_cast<int8_t *>(layer.data), this->num_points()};
continue;
}
@ -963,7 +963,7 @@ void CurvesGeometry::reverse_curves(const IndexMask curves_to_reverse)
attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
using T = decltype(dummy);
reverse_curve_point_data<T>(
*this, curves_to_reverse, {static_cast<T *>(layer.data), this->points_size()});
*this, curves_to_reverse, {static_cast<T *>(layer.data), this->num_points()});
});
}
@ -1001,8 +1001,8 @@ static void adapt_curve_domain_point_to_curve_impl(const CurvesGeometry &curves,
MutableSpan<T> r_values)
{
attribute_math::DefaultMixer<T> mixer(r_values);
for (const int i_curve : IndexRange(curves.curves_size())) {
for (const int i_point : curves.range_for_curve(i_curve)) {
for (const int i_curve : IndexRange(curves.num_curves())) {
for (const int i_point : curves.points_for_curve(i_curve)) {
mixer.mix_in(i_curve, old_values[i_point]);
}
}
@ -1022,8 +1022,8 @@ void adapt_curve_domain_point_to_curve_impl(const CurvesGeometry &curves,
MutableSpan<bool> r_values)
{
r_values.fill(true);
for (const int i_curve : IndexRange(curves.curves_size())) {
for (const int i_point : curves.range_for_curve(i_curve)) {
for (const int i_curve : IndexRange(curves.num_curves())) {
for (const int i_point : curves.points_for_curve(i_curve)) {
if (!old_values[i_point]) {
r_values[i_curve] = false;
break;
@ -1039,7 +1039,7 @@ static GVArray adapt_curve_domain_point_to_curve(const CurvesGeometry &curves,
attribute_math::convert_to_static_type(varray.type(), [&](auto dummy) {
using T = decltype(dummy);
if constexpr (!std::is_void_v<attribute_math::DefaultMixer<T>>) {
Array<T> values(curves.curves_size());
Array<T> values(curves.num_curves());
adapt_curve_domain_point_to_curve_impl<T>(curves, varray.typed<T>(), values);
new_varray = VArray<T>::ForContainer(std::move(values));
}
@ -1059,8 +1059,8 @@ static void adapt_curve_domain_curve_to_point_impl(const CurvesGeometry &curves,
const VArray<T> &old_values,
MutableSpan<T> r_values)
{
for (const int i_curve : IndexRange(curves.curves_size())) {
r_values.slice(curves.range_for_curve(i_curve)).fill(old_values[i_curve]);
for (const int i_curve : IndexRange(curves.num_curves())) {
r_values.slice(curves.points_for_curve(i_curve)).fill(old_values[i_curve]);
}
}
@ -1070,7 +1070,7 @@ static GVArray adapt_curve_domain_curve_to_point(const CurvesGeometry &curves,
GVArray new_varray;
attribute_math::convert_to_static_type(varray.type(), [&](auto dummy) {
using T = decltype(dummy);
Array<T> values(curves.points_size());
Array<T> values(curves.num_points());
adapt_curve_domain_curve_to_point_impl<T>(curves, varray.typed<T>(), values);
new_varray = VArray<T>::ForContainer(std::move(values));
});

View File

@ -46,7 +46,7 @@ TEST(curves_geometry, Move)
CurvesGeometry other = std::move(curves);
/* The old curves should be empty, and the offsets are expected to be null. */
EXPECT_EQ(curves.points_size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(curves.num_points(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(curves.curve_offsets, nullptr); /* NOLINT: bugprone-use-after-move */
/* Just a basic check that the new curves work okay. */

View File

@ -236,10 +236,10 @@ int CurveComponent::attribute_domain_size(const AttributeDomain domain) const
const blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(
curves_->geometry);
if (domain == ATTR_DOMAIN_POINT) {
return geometry.points_size();
return geometry.num_points();
}
if (domain == ATTR_DOMAIN_CURVE) {
return geometry.curves_size();
return geometry.num_curves();
}
return 0;
}

View File

@ -138,7 +138,7 @@ static void curves_batch_cache_fill_segments_proc_pos(Curves *curves,
Span<float3> positions = geometry.positions();
for (const int i : IndexRange(curve_size)) {
const IndexRange curve_range = geometry.range_for_curve(i);
const IndexRange curve_range = geometry.points_for_curve(i);
Span<float3> curve_positions = positions.slice(curve_range);
float total_len = 0.0f;
@ -218,8 +218,8 @@ static void curves_batch_cache_fill_strands_data(Curves *curves,
const blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(
curves->geometry);
for (const int i : IndexRange(geometry.curves_size())) {
const IndexRange curve_range = geometry.range_for_curve(i);
for (const int i : IndexRange(geometry.num_curves())) {
const IndexRange curve_range = geometry.points_for_curve(i);
*(uint *)GPU_vertbuf_raw_step(data_step) = curve_range.start();
*(ushort *)GPU_vertbuf_raw_step(seg_step) = curve_range.size() - 1;

View File

@ -21,7 +21,7 @@ bke::CurvesGeometry primitive_random_sphere(const int curves_size, const int poi
float *radius_data = (float *)CustomData_add_layer_named(
&curves.point_data, CD_PROP_FLOAT, CD_DEFAULT, nullptr, curves.point_size, "radius");
MutableSpan<float> radii{radius_data, curves.points_size()};
MutableSpan<float> radii{radius_data, curves.num_points()};
for (const int i : offsets.index_range()) {
offsets[i] = points_per_curve * i;
@ -30,7 +30,7 @@ bke::CurvesGeometry primitive_random_sphere(const int curves_size, const int poi
RandomNumberGenerator rng;
for (const int i : curves.curves_range()) {
const IndexRange curve_range = curves.range_for_curve(i);
const IndexRange curve_range = curves.points_for_curve(i);
MutableSpan<float3> curve_positions = positions.slice(curve_range);
MutableSpan<float> curve_radii = radii.slice(curve_range);

View File

@ -93,7 +93,7 @@ static std::optional<float3> find_curves_brush_position(const CurvesGeometry &cu
BrushPositionCandidate best_candidate = init;
for (const int curve_i : curves_range) {
const IndexRange points = curves.range_for_curve(curve_i);
const IndexRange points = curves.points_for_curve(curve_i);
const int tot_segments = points.size() - 1;
for (const int segment_i : IndexRange(tot_segments)) {

View File

@ -174,8 +174,8 @@ struct AddOperationExecutor {
use_interpolation_ = interpolate_length_ || interpolate_shape_;
new_curve_length_ = curves_sculpt_->curve_length;
tot_old_curves_ = curves_->curves_size();
tot_old_points_ = curves_->points_size();
tot_old_curves_ = curves_->num_curves();
tot_old_points_ = curves_->num_points();
if (add_amount_ == 0) {
return;
@ -216,8 +216,8 @@ struct AddOperationExecutor {
const int tot_added_curves = added_points.bary_coords.size();
const int tot_added_points = tot_added_curves * points_per_curve_;
curves_->resize(curves_->points_size() + tot_added_points,
curves_->curves_size() + tot_added_curves);
curves_->resize(curves_->num_points() + tot_added_points,
curves_->num_curves() + tot_added_curves);
threading::parallel_invoke([&]() { this->initialize_curve_offsets(tot_added_curves); },
[&]() { this->initialize_attributes(added_points); });
@ -515,7 +515,7 @@ struct AddOperationExecutor {
void ensure_curve_roots_kdtree()
{
if (self_->curve_roots_kdtree_ == nullptr) {
self_->curve_roots_kdtree_ = BLI_kdtree_3d_new(curves_->curves_size());
self_->curve_roots_kdtree_ = BLI_kdtree_3d_new(curves_->num_curves());
for (const int curve_i : curves_->curves_range()) {
const int root_point_i = curves_->offsets()[curve_i];
const float3 &root_pos_cu = curves_->positions()[root_point_i];
@ -609,7 +609,7 @@ struct AddOperationExecutor {
const Span<NeighborInfo> neighbors = neighbors_per_curve[added_curve_i];
float length_sum = 0.0f;
for (const NeighborInfo &neighbor : neighbors) {
const IndexRange neighbor_points = curves_->range_for_curve(neighbor.index);
const IndexRange neighbor_points = curves_->points_for_curve(neighbor.index);
float neighbor_length = 0.0f;
const int tot_segments = neighbor_points.size() - 1;
for (const int segment_i : IndexRange(tot_segments)) {
@ -744,7 +744,7 @@ struct AddOperationExecutor {
float normal_rotation_cu[3][3];
rotation_between_vecs_to_mat3(normal_rotation_cu, neighbor_normal_cu, normal_cu);
const IndexRange neighbor_points = curves_->range_for_curve(neighbor_curve_i);
const IndexRange neighbor_points = curves_->points_for_curve(neighbor_curve_i);
const float3 &neighbor_root_cu = positions_cu[neighbor_points[0]];
/* Use a temporary #PolySpline, because that's the easiest way to resample an

View File

@ -202,7 +202,7 @@ struct CombOperationExecutor {
Vector<int> &local_changed_curves = r_changed_curves.local();
for (const int curve_i : curves_range) {
bool curve_changed = false;
const IndexRange points = curves_->range_for_curve(curve_i);
const IndexRange points = curves_->points_for_curve(curve_i);
for (const int point_i : points.drop_front(1)) {
const float3 old_pos_cu = positions_cu[point_i];
@ -274,7 +274,7 @@ struct CombOperationExecutor {
Vector<int> &local_changed_curves = r_changed_curves.local();
for (const int curve_i : curves_range) {
bool curve_changed = false;
const IndexRange points = curves_->range_for_curve(curve_i);
const IndexRange points = curves_->points_for_curve(curve_i);
for (const int point_i : points.drop_front(1)) {
const float3 pos_old_cu = positions_cu[point_i];
@ -324,10 +324,10 @@ struct CombOperationExecutor {
void initialize_segment_lengths()
{
const Span<float3> positions_cu = curves_->positions();
self_->segment_lengths_cu_.reinitialize(curves_->points_size());
self_->segment_lengths_cu_.reinitialize(curves_->num_points());
threading::parallel_for(curves_->curves_range(), 128, [&](const IndexRange range) {
for (const int curve_i : range) {
const IndexRange points = curves_->range_for_curve(curve_i);
const IndexRange points = curves_->points_for_curve(curve_i);
for (const int point_i : points.drop_back(1)) {
const float3 &p1_cu = positions_cu[point_i];
const float3 &p2_cu = positions_cu[point_i + 1];
@ -349,7 +349,7 @@ struct CombOperationExecutor {
threading::parallel_for_each(changed_curves, [&](const Vector<int> &changed_curves) {
threading::parallel_for(changed_curves.index_range(), 256, [&](const IndexRange range) {
for (const int curve_i : changed_curves.as_span().slice(range)) {
const IndexRange points = curves_->range_for_curve(curve_i);
const IndexRange points = curves_->points_for_curve(curve_i);
for (const int segment_i : IndexRange(points.size() - 1)) {
const float3 &p1_cu = positions_cu[points[segment_i]];
float3 &p2_cu = positions_cu[points[segment_i] + 1];

View File

@ -70,7 +70,7 @@ class DeleteOperation : public CurvesSculptStrokeOperation {
Vector<int64_t> indices;
const IndexMask curves_to_remove = index_mask_ops::find_indices_based_on_predicate(
curves.curves_range(), 512, indices, [&](const int curve_i) {
const IndexRange point_range = curves.range_for_curve(curve_i);
const IndexRange point_range = curves.points_for_curve(curve_i);
for (const int segment_i : IndexRange(point_range.size() - 1)) {
const float3 pos1 = positions[point_range[segment_i]];
const float3 pos2 = positions[point_range[segment_i + 1]];

View File

@ -117,7 +117,7 @@ class ShrinkOperation : public CurvesSculptStrokeOperation {
threading::parallel_for(curves.curves_range(), 256, [&](const IndexRange curves_range) {
for (const int curve_i : curves_range) {
const IndexRange curve_points = curves.range_for_curve(curve_i);
const IndexRange curve_points = curves.points_for_curve(curve_i);
const int last_point_i = curve_points.last();
const float3 old_tip_position = positions[last_point_i];
@ -304,7 +304,7 @@ class DensityAddOperation : public CurvesSculptStrokeOperation {
if (old_kdtree_ == nullptr && minimum_distance > 0.0f) {
old_kdtree_ = this->kdtree_from_curve_roots_and_positions(curves, curves.curves_range(), {});
old_kdtree_size_ = curves.curves_size();
old_kdtree_size_ = curves.num_curves();
}
float density;
@ -525,7 +525,7 @@ class DensityAddOperation : public CurvesSculptStrokeOperation {
{
Array<bool> elimination_mask(points.positions.size(), false);
const int curves_added_previously = curves.curves_size() - old_kdtree_size_;
const int curves_added_previously = curves.num_curves() - old_kdtree_size_;
KDTree_3d *new_points_kdtree = this->kdtree_from_curve_roots_and_positions(
curves, IndexRange(old_kdtree_size_, curves_added_previously), points.positions);
@ -589,14 +589,14 @@ class DensityAddOperation : public CurvesSculptStrokeOperation {
const int tot_new_curves = new_points.positions.size();
const int points_per_curve = 8;
curves.resize(curves.points_size() + tot_new_curves * points_per_curve,
curves.curves_size() + tot_new_curves);
curves.resize(curves.num_points() + tot_new_curves * points_per_curve,
curves.num_curves() + tot_new_curves);
MutableSpan<int> offsets = curves.offsets();
MutableSpan<float3> positions = curves.positions();
for (const int i : IndexRange(tot_new_curves)) {
const int curve_i = curves.curves_size() - tot_new_curves + i;
const int curve_i = curves.num_curves() - tot_new_curves + i;
const int first_point_i = offsets[curve_i];
offsets[curve_i + 1] = offsets[curve_i] + points_per_curve;

View File

@ -83,7 +83,7 @@ class SnakeHookOperation : public CurvesSculptStrokeOperation {
threading::parallel_for(curves.curves_range(), 256, [&](const IndexRange curves_range) {
for (const int curve_i : curves_range) {
const IndexRange curve_points = curves.range_for_curve(curve_i);
const IndexRange curve_points = curves.points_for_curve(curve_i);
const int last_point_i = curve_points.last();
const float3 old_position = positions[last_point_i];

View File

@ -1139,8 +1139,8 @@ static void execute_realize_curve_task(const RealizeInstancesOptions &options,
const Curves &curves_id = *curves_info.curves;
const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
const IndexRange dst_point_range{task.start_indices.point, curves.points_size()};
const IndexRange dst_curve_range{task.start_indices.curve, curves.curves_size()};
const IndexRange dst_point_range{task.start_indices.point, curves.num_points()};
const IndexRange dst_curve_range{task.start_indices.curve, curves.num_curves()};
copy_transformed_positions(
curves.positions(), task.transform, dst_curves.positions().slice(dst_point_range));
@ -1194,9 +1194,9 @@ static void execute_realize_curve_task(const RealizeInstancesOptions &options,
[&](const AttributeDomain domain) {
switch (domain) {
case ATTR_DOMAIN_POINT:
return IndexRange(task.start_indices.point, curves.points_size());
return IndexRange(task.start_indices.point, curves.num_points());
case ATTR_DOMAIN_CURVE:
return IndexRange(task.start_indices.curve, curves.curves_size());
return IndexRange(task.start_indices.curve, curves.num_curves());
default:
BLI_assert_unreachable();
return IndexRange();

View File

@ -55,24 +55,24 @@ class EndpointFieldInput final : public GeometryFieldInput {
const Curves &curves_id = *curve_component.get_for_read();
const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
if (curves.points_size() == 0) {
if (curves.num_points() == 0) {
return nullptr;
}
GeometryComponentFieldContext size_context{curve_component, ATTR_DOMAIN_CURVE};
fn::FieldEvaluator evaluator{size_context, curves.curves_size()};
fn::FieldEvaluator evaluator{size_context, curves.num_curves()};
evaluator.add(start_size_);
evaluator.add(end_size_);
evaluator.evaluate();
const VArray<int> &start_size = evaluator.get_evaluated<int>(0);
const VArray<int> &end_size = evaluator.get_evaluated<int>(1);
Array<bool> selection(curves.points_size(), false);
Array<bool> selection(curves.num_points(), false);
MutableSpan<bool> selection_span = selection.as_mutable_span();
devirtualize_varray2(start_size, end_size, [&](const auto &start_size, const auto &end_size) {
threading::parallel_for(curves.curves_range(), 1024, [&](IndexRange curves_range) {
for (const int i : curves_range) {
const IndexRange range = curves.range_for_curve(i);
const IndexRange range = curves.points_for_curve(i);
const int start = std::max(start_size[i], 0);
const int end = std::max(end_size[i], 0);

View File

@ -46,13 +46,13 @@ static meshintersect::CDT_result<double> do_cdt(const bke::CurvesGeometry &curve
meshintersect::CDT_input<double> input;
input.need_ids = false;
input.vert.reinitialize(curves.evaluated_points_size());
input.face.reinitialize(curves.curves_size());
input.face.reinitialize(curves.num_curves());
VArray<bool> cyclic = curves.cyclic();
Span<float3> positions = curves.evaluated_positions();
for (const int i_curve : curves.curves_range()) {
const IndexRange points = curves.evaluated_range_for_curve(i_curve);
const IndexRange points = curves.evaluated_points_for_curve(i_curve);
const int segment_size = bke::curves::curve_segment_size(points.size(), cyclic[i_curve]);
for (const int i : points) {
@ -118,7 +118,7 @@ static void curve_fill_calculate(GeometrySet &geometry_set, const GeometryNodeCu
const Curves &curves_id = *geometry_set.get_curves_for_read();
const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
if (curves.curves_size() == 0) {
if (curves.num_curves() == 0) {
geometry_set.replace_curves(nullptr);
return;
}

View File

@ -57,7 +57,7 @@ static void select_by_handle_type(const bke::CurvesGeometry &curves,
VArray<int8_t> right = curves.handle_types_right();
for (const int i_curve : curves.curves_range()) {
const IndexRange points = curves.range_for_curve(i_curve);
const IndexRange points = curves.points_for_curve(i_curve);
if (curve_types[i_curve] != CURVE_TYPE_BEZIER) {
r_selection.slice(points).fill(false);
}

View File

@ -273,9 +273,9 @@ static void copy_curve_attributes_without_id(const GeometrySet &geometry_set,
threading::parallel_for(selection.index_range(), 512, [&](IndexRange range) {
for (const int i_selection : range) {
const int i_src_curve = selection[i_selection];
const Span<T> curve_src = src.slice(src_curves.range_for_curve(i_src_curve));
const Span<T> curve_src = src.slice(src_curves.points_for_curve(i_src_curve));
for (const int i_dst_curve : range_for_offsets_index(curve_offsets, i_selection)) {
dst.slice(dst_curves.range_for_curve(i_dst_curve)).copy_from(curve_src);
dst.slice(dst_curves.points_for_curve(i_dst_curve)).copy_from(curve_src);
}
}
});
@ -317,12 +317,12 @@ static void copy_stable_id_curves(const bke::CurvesGeometry &src_curves,
threading::parallel_for(selection.index_range(), 512, [&](IndexRange range) {
for (const int i_selection : range) {
const int i_src_curve = selection[i_selection];
const Span<int> curve_src = src.slice(src_curves.range_for_curve(i_src_curve));
const Span<int> curve_src = src.slice(src_curves.points_for_curve(i_src_curve));
const IndexRange duplicates_range = range_for_offsets_index(curve_offsets, i_selection);
for (const int i_duplicate : IndexRange(duplicates_range.size()).drop_front(1)) {
const int i_dst_curve = duplicates_range[i_duplicate];
copy_hashed_ids(
curve_src, i_duplicate, dst.slice(dst_curves.range_for_curve(i_dst_curve)));
curve_src, i_duplicate, dst.slice(dst_curves.points_for_curve(i_dst_curve)));
}
}
});
@ -345,7 +345,7 @@ static void duplicate_curves(GeometrySet &geometry_set,
const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
GeometryComponentFieldContext field_context{src_component, ATTR_DOMAIN_CURVE};
FieldEvaluator evaluator{field_context, curves.curves_size()};
FieldEvaluator evaluator{field_context, curves.num_curves()};
evaluator.add(count_field);
evaluator.set_selection(selection_field);
evaluator.evaluate();
@ -363,7 +363,7 @@ static void duplicate_curves(GeometrySet &geometry_set,
curve_offsets[i_curve] = dst_curves_size;
point_offsets[i_curve] = dst_points_size;
dst_curves_size += count;
dst_points_size += count * curves.range_for_curve(selection[i_curve]).size();
dst_points_size += count * curves.points_for_curve(selection[i_curve]).size();
}
curve_offsets.last() = dst_curves_size;
point_offsets.last() = dst_points_size;
@ -375,7 +375,7 @@ static void duplicate_curves(GeometrySet &geometry_set,
threading::parallel_for(selection.index_range(), 512, [&](IndexRange range) {
for (const int i_selection : range) {
const int i_src_curve = selection[i_selection];
const IndexRange src_curve_range = curves.range_for_curve(i_src_curve);
const IndexRange src_curve_range = curves.points_for_curve(i_src_curve);
const IndexRange dst_curves_range = range_for_offsets_index(curve_offsets, i_selection);
MutableSpan<int> dst_offsets = all_dst_offsets.slice(dst_curves_range);
for (const int i_duplicate : IndexRange(dst_curves_range.size())) {
@ -800,12 +800,12 @@ static void duplicate_points_curve(GeometrySet &geometry_set,
const CurveComponent &src_component = *geometry_set.get_component_for_read<CurveComponent>();
const Curves &src_curves_id = *src_component.get_for_read();
const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(src_curves_id.geometry);
if (src_curves.points_size() == 0) {
if (src_curves.num_points() == 0) {
return;
}
GeometryComponentFieldContext field_context{src_component, ATTR_DOMAIN_POINT};
FieldEvaluator evaluator{field_context, src_curves.points_size()};
FieldEvaluator evaluator{field_context, src_curves.num_points()};
evaluator.add(count_field);
evaluator.set_selection(selection_field);
evaluator.evaluate();
@ -815,10 +815,10 @@ static void duplicate_points_curve(GeometrySet &geometry_set,
Array<int> offsets = accumulate_counts_to_offsets(selection, counts);
const int dst_size = offsets.last();
Array<int> point_to_curve_map(src_curves.points_size());
Array<int> point_to_curve_map(src_curves.num_points());
threading::parallel_for(src_curves.curves_range(), 1024, [&](const IndexRange range) {
for (const int i_curve : range) {
const IndexRange point_range = src_curves.range_for_curve(i_curve);
const IndexRange point_range = src_curves.points_for_curve(i_curve);
point_to_curve_map.as_mutable_span().slice(point_range).fill(i_curve);
}
});

View File

@ -86,13 +86,13 @@ static VArray<int> construct_spline_count_gvarray(const CurveComponent &componen
const Curves &curves_id = *component.get_for_read();
const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
auto count_fn = [curves](int64_t i) { return curves.range_for_curve(i).size(); };
auto count_fn = [curves](int64_t i) { return curves.points_for_curve(i).size(); };
if (domain == ATTR_DOMAIN_CURVE) {
return VArray<int>::ForFunc(curves.curves_size(), count_fn);
return VArray<int>::ForFunc(curves.num_curves(), count_fn);
}
if (domain == ATTR_DOMAIN_POINT) {
VArray<int> count = VArray<int>::ForFunc(curves.curves_size(), count_fn);
VArray<int> count = VArray<int>::ForFunc(curves.num_curves(), count_fn);
return component.attribute_try_adapt_domain<int>(
std::move(count), ATTR_DOMAIN_CURVE, ATTR_DOMAIN_POINT);
}