Blender
V5.3
source
blender
geometry
tests
GEO_merge_curves_test.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2024 Blender Authors
2
*
3
* SPDX-License-Identifier: Apache-2.0 */
4
5
#include "
BKE_attribute.hh
"
6
#include "
BKE_curves.hh
"
7
#include "
BKE_gtest_base.hh
"
8
9
#include "
BLI_array_utils.hh
"
10
11
#include "
GEO_merge_curves.hh
"
12
13
#include "testing/testing.h"
14
15
namespace
blender
{
16
17
using namespace
blender::bke;
18
19
namespace
geometry::tests
{
20
21
class
MergeCurvesTest
:
public
bke::BlenderGTestBase
{};
22
23
static
bke::CurvesGeometry
create_test_curves
(
Span<int>
offsets,
Span<bool>
cyclic)
24
{
25
BLI_assert
(!offsets.
is_empty
());
26
const
int
curves_num = offsets.
size
() - 1;
27
BLI_assert
(cyclic.
size
() == curves_num);
28
const
int
points_num = offsets.
last
();
29
30
bke::CurvesGeometry
curves
(points_num, curves_num);
31
curves
.offsets_for_write().copy_from(offsets);
32
curves
.cyclic_for_write().copy_from(cyclic);
33
34
/* Attribute storing original indices to test point remapping. */
35
SpanAttributeWriter<int>
test_indices_writer =
36
curves
.attributes_for_write().lookup_or_add_for_write_span<
int
>(
37
"test_index"
,
bke::AttrDomain::Point
,
bke::AttributeInitConstruct
());
38
array_utils::fill_index_range
(test_indices_writer.
span
);
39
test_indices_writer.
finish
();
40
41
return
curves
;
42
}
43
44
TEST_F
(
MergeCurvesTest
, NoConnections)
45
{
46
bke::CurvesGeometry
src_curves =
create_test_curves
({0, 3, 6, 9, 12},
47
{
false
,
true
,
true
,
false
});
48
49
Array<int>
connect_to_curve(4, -1);
50
Array<bool>
flip_direction(4,
false
);
51
52
bke::CurvesGeometry
dst_curves =
geometry::curves_merge_endpoints
(
53
src_curves, connect_to_curve, flip_direction, {});
54
const
VArraySpan<bool>
cyclic = dst_curves.
cyclic
();
55
56
EXPECT_EQ
(dst_curves.
points_num
(), 12);
57
EXPECT_EQ
(dst_curves.
curves_num
(), 4);
58
EXPECT_EQ_SPAN(
Span
({0, 3, 6, 9, 12}), dst_curves.
offsets
());
59
EXPECT_EQ_SPAN(
Span
({
false
,
true
,
true
,
false
}), cyclic);
60
}
61
62
TEST_F
(
MergeCurvesTest
, ConnectSingleCurve)
63
{
64
bke::CurvesGeometry
src_curves =
create_test_curves
({0, 3, 6, 9, 12},
65
{
false
,
true
,
true
,
false
});
66
67
Array<int>
connect_to_curve = {-1, -1, -1, 1};
68
Array<bool>
flip_direction(4,
false
);
69
70
bke::CurvesGeometry
dst_curves =
geometry::curves_merge_endpoints
(
71
src_curves, connect_to_curve, flip_direction, {});
72
const
VArraySpan<bool>
cyclic = dst_curves.
cyclic
();
73
const
VArraySpan<int>
dst_indices = *dst_curves.
attributes
().
lookup
<
int
>(
"test_index"
);
74
75
EXPECT_EQ
(dst_curves.
points_num
(), 12);
76
EXPECT_EQ
(dst_curves.
curves_num
(), 3);
77
EXPECT_EQ_SPAN(
Span
({0, 3, 6, 12}), dst_curves.
offsets
());
78
EXPECT_EQ_SPAN(
Span
({
false
,
true
,
false
}), cyclic);
79
EXPECT_EQ_SPAN(
Span
({0, 1, 2, 6, 7, 8, 9, 10, 11, 3, 4, 5}), dst_indices);
80
}
81
82
TEST_F
(
MergeCurvesTest
, ReverseCurves)
83
{
84
bke::CurvesGeometry
src_curves =
create_test_curves
({0, 3, 6, 9, 12},
85
{
false
,
true
,
true
,
false
});
86
87
Array<int>
connect_to_curve = {-1, -1, -1, -1};
88
Array<bool>
flip_direction = {
false
,
true
,
false
,
true
};
89
90
bke::CurvesGeometry
dst_curves =
geometry::curves_merge_endpoints
(
91
src_curves, connect_to_curve, flip_direction, {});
92
const
VArraySpan<bool>
cyclic = dst_curves.
cyclic
();
93
const
VArraySpan<int>
dst_indices = *dst_curves.
attributes
().
lookup
<
int
>(
"test_index"
);
94
95
EXPECT_EQ
(dst_curves.
points_num
(), 12);
96
EXPECT_EQ
(dst_curves.
curves_num
(), 4);
97
EXPECT_EQ_SPAN(
Span
({0, 3, 6, 9, 12}), dst_curves.
offsets
());
98
EXPECT_EQ_SPAN(
Span
({
false
,
true
,
true
,
false
}), cyclic);
99
EXPECT_EQ_SPAN(
Span
({0, 1, 2, 5, 4, 3, 6, 7, 8, 11, 10, 9}), dst_indices);
100
}
101
102
TEST_F
(
MergeCurvesTest
, ConnectAndReverseCurves)
103
{
104
bke::CurvesGeometry
src_curves =
create_test_curves
({0, 3, 6, 9, 12},
105
{
false
,
true
,
true
,
false
});
106
107
Array<int>
connect_to_curve = {3, 0, -1, -1};
108
Array<bool>
flip_direction = {
true
,
false
,
true
,
false
};
109
110
bke::CurvesGeometry
dst_curves =
geometry::curves_merge_endpoints
(
111
src_curves, connect_to_curve, flip_direction, {});
112
const
VArraySpan<bool>
cyclic = dst_curves.
cyclic
();
113
const
VArraySpan<int>
dst_indices = *dst_curves.
attributes
().
lookup
<
int
>(
"test_index"
);
114
115
EXPECT_EQ
(dst_curves.
points_num
(), 12);
116
EXPECT_EQ
(dst_curves.
curves_num
(), 2);
117
EXPECT_EQ_SPAN(
Span
({0, 9, 12}), dst_curves.
offsets
());
118
EXPECT_EQ_SPAN(
Span
({
false
,
true
}), cyclic);
119
EXPECT_EQ_SPAN(
Span
({3, 4, 5, 2, 1, 0, 9, 10, 11, 8, 7, 6}), dst_indices);
120
}
121
122
TEST_F
(
MergeCurvesTest
, CyclicConnection)
123
{
124
bke::CurvesGeometry
src_curves =
create_test_curves
({0, 3, 6, 9, 12},
125
{
false
,
true
,
true
,
false
});
126
127
Array<int>
connect_to_curve = {-1, 3, -1, 1};
128
Array<bool>
flip_direction(4,
false
);
129
130
bke::CurvesGeometry
dst_curves =
geometry::curves_merge_endpoints
(
131
src_curves, connect_to_curve, flip_direction, {});
132
const
VArraySpan<bool>
cyclic = dst_curves.
cyclic
();
133
const
VArraySpan<int>
dst_indices = *dst_curves.
attributes
().
lookup
<
int
>(
"test_index"
);
134
135
EXPECT_EQ
(dst_curves.
points_num
(), 12);
136
EXPECT_EQ
(dst_curves.
curves_num
(), 3);
137
EXPECT_EQ_SPAN(
Span
({0, 3, 9, 12}), dst_curves.
offsets
());
138
EXPECT_EQ_SPAN(
Span
({
false
,
true
,
true
}), cyclic);
139
EXPECT_EQ_SPAN(
Span
({0, 1, 2, 3, 4, 5, 9, 10, 11, 6, 7, 8}), dst_indices);
140
}
141
142
TEST_F
(
MergeCurvesTest
, SelfConnectCurve)
143
{
144
bke::CurvesGeometry
src_curves =
create_test_curves
({0, 3, 6, 9, 12},
145
{
false
,
false
,
false
,
false
});
146
147
Array<int>
connect_to_curve = {-1, 1, 2, -1};
148
Array<bool>
flip_direction(4,
false
);
149
150
bke::CurvesGeometry
dst_curves =
geometry::curves_merge_endpoints
(
151
src_curves, connect_to_curve, flip_direction, {});
152
const
VArraySpan<bool>
cyclic = dst_curves.
cyclic
();
153
const
VArraySpan<int>
dst_indices = *dst_curves.
attributes
().
lookup
<
int
>(
"test_index"
);
154
155
EXPECT_EQ
(dst_curves.
points_num
(), 12);
156
EXPECT_EQ
(dst_curves.
curves_num
(), 4);
157
EXPECT_EQ_SPAN(
Span
({0, 3, 6, 9, 12}), dst_curves.
offsets
());
158
EXPECT_EQ_SPAN(
Span
({
false
,
true
,
true
,
false
}), cyclic);
159
EXPECT_EQ_SPAN(
Span
({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}), dst_indices);
160
}
161
162
TEST_F
(
MergeCurvesTest
, MergeAll)
163
{
164
bke::CurvesGeometry
src_curves =
create_test_curves
({0, 3, 6, 9, 12},
165
{
false
,
true
,
true
,
false
});
166
167
Array<int>
connect_to_curve = {2, 0, 3, 1};
168
Array<bool>
flip_direction(4,
false
);
169
170
bke::CurvesGeometry
dst_curves =
geometry::curves_merge_endpoints
(
171
src_curves, connect_to_curve, flip_direction, {});
172
const
VArraySpan<bool>
cyclic = dst_curves.
cyclic
();
173
const
VArraySpan<int>
dst_indices = *dst_curves.
attributes
().
lookup
<
int
>(
"test_index"
);
174
175
EXPECT_EQ
(dst_curves.
points_num
(), 12);
176
EXPECT_EQ
(dst_curves.
curves_num
(), 1);
177
EXPECT_EQ_SPAN(
Span
({0, 12}), dst_curves.
offsets
());
178
EXPECT_EQ_SPAN(
Span
({
true
}), cyclic);
179
EXPECT_EQ_SPAN(
Span
({0, 1, 2, 6, 7, 8, 9, 10, 11, 3, 4, 5}), dst_indices);
180
}
181
182
TEST_F
(
MergeCurvesTest
, Branching)
183
{
184
bke::CurvesGeometry
src_curves =
create_test_curves
({0, 3, 6, 9, 12},
185
{
false
,
true
,
true
,
false
});
186
187
/* Multiple curves connect to curve 2, one connection is ignored. */
188
Array<int>
connect_to_curve = {2, 2, -1, -1};
189
Array<bool>
flip_direction(4,
false
);
190
191
bke::CurvesGeometry
dst_curves =
geometry::curves_merge_endpoints
(
192
src_curves, connect_to_curve, flip_direction, {});
193
const
VArraySpan<bool>
cyclic = dst_curves.
cyclic
();
194
const
VArraySpan<int>
dst_indices = *dst_curves.
attributes
().
lookup
<
int
>(
"test_index"
);
195
196
EXPECT_EQ
(dst_curves.
points_num
(), 12);
197
EXPECT_EQ
(dst_curves.
curves_num
(), 3);
198
EXPECT_EQ_SPAN(
Span
({0, 6, 9, 12}), dst_curves.
offsets
());
199
EXPECT_EQ_SPAN(
Span
({
false
,
false
,
false
}), cyclic);
200
EXPECT_EQ_SPAN(
Span
({0, 1, 2, 6, 7, 8, 3, 4, 5, 9, 10, 11}), dst_indices);
201
}
202
203
}
// namespace geometry::tests
204
}
// namespace blender
BKE_attribute.hh
BKE_curves.hh
Low-level operations for curves.
BKE_gtest_base.hh
BLI_array_utils.hh
GEO_merge_curves.hh
blender::Array
Definition
BLI_array.hh:50
blender::Span
Definition
BLI_span.hh:74
blender::Span::Span
constexpr Span()=default
blender::Span::size
constexpr int64_t size() const
Definition
BLI_span.hh:256
blender::Span::last
constexpr const T & last(const int64_t n=0) const
Definition
BLI_span.hh:329
blender::Span::is_empty
constexpr bool is_empty() const
Definition
BLI_span.hh:264
blender::VArraySpan
Definition
BLI_virtual_array.hh:956
blender::bke::AttributeAccessor::lookup
GAttributeReader lookup(const StringRef name) const
Definition
BKE_attribute.hh:585
blender::bke::BlenderGTestBase
Definition
BKE_gtest_base.hh:17
blender::bke::CurvesGeometry
Definition
BKE_curves.hh:156
blender::bke::CurvesGeometry::cyclic
VArray< bool > cyclic() const
Definition
curves_geometry.cc:405
blender::bke::CurvesGeometry::attributes
AttributeAccessor attributes() const
Definition
curves_geometry.cc:1951
blender::bke::CurvesGeometry::points_num
int points_num() const
Definition
BKE_curves.hh:1001
blender::bke::CurvesGeometry::curves_num
int curves_num() const
Definition
BKE_curves.hh:1005
blender::bke::CurvesGeometry::offsets
Span< int > offsets() const
Definition
curves_geometry.cc:388
blender::geometry::tests::MergeCurvesTest
Definition
GEO_merge_curves_test.cc:21
blender::array_utils::fill_index_range
void fill_index_range(MutableSpan< T > span, const T start=0)
Definition
BLI_array_utils.hh:434
blender::bke::AttrDomain::Point
@ Point
Definition
BKE_attribute_enums.hh:42
blender::geometry::tests
Definition
GEO_merge_curves_test.cc:19
blender::geometry::tests::TEST_F
TEST_F(MergeCurvesTest, NoConnections)
Definition
GEO_merge_curves_test.cc:44
blender::geometry::tests::create_test_curves
static bke::CurvesGeometry create_test_curves(Span< int > offsets, Span< bool > cyclic)
Definition
GEO_merge_curves_test.cc:23
blender::geometry::curves_merge_endpoints
bke::CurvesGeometry curves_merge_endpoints(const bke::CurvesGeometry &src_curves, Span< int > connect_to_curve, Span< bool > flip_direction, const bke::AttributeFilter &attribute_filter)
Definition
merge_curves.cc:298
blender
BMesh Iterators.
Definition
ANIM_action.hh:30
blender::BLI_assert
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
blender::EXPECT_EQ
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
curves
Definition
draw_curves_interpolation.bsl.hh:22
blender::bke::AttributeInitConstruct
Definition
BKE_attribute.hh:89
blender::bke::SpanAttributeWriter
Definition
BKE_attribute.hh:246
blender::bke::SpanAttributeWriter::finish
void finish()
Definition
BKE_attribute.hh:279
blender::bke::SpanAttributeWriter::span
MutableVArraySpan< T > span
Definition
BKE_attribute.hh:250
Generated on
for Blender by
doxygen
1.18.0