Initial Grease Pencil 3.0 stage #106848

Merged
Falk David merged 224 commits from filedescriptor/blender:grease-pencil-v3 into main 2023-05-30 11:14:22 +02:00
2 changed files with 7 additions and 9 deletions
Showing only changes of commit af5f43651f - Show all commits

View File

@ -50,7 +50,7 @@ class TreeNode : public ::GreasePencilLayerTreeNode {
}

Is defining these as constexpr helpful? I sort of doubt any real computation is done on these nodes at compile time. But maybe?

Is defining these as `constexpr` helpful? I sort of doubt any real computation is done on these nodes at compile time. But maybe?

The const in the const bool return type means nothing here

The `const` in the `const bool` return type means nothing here
TreeNode &operator=(const TreeNode &other) = delete;
TreeNode &operator=(TreeNode &&other) = delete;
~TreeNode()
virtual ~TreeNode()
{
if (this->name) {
MEM_freeN(this->name);
@ -219,6 +219,9 @@ class Layer : public TreeNode, ::GreasePencilLayer {
}
return *this;
}
~Layer()

Returning an element added to a vector by reference is quite dangerous since they're invalidated by further additions, we usually don't do that. Either returning an index or not having these wrapper functions seems like the best choices IMO

Returning an element added to a vector by reference is quite dangerous since they're invalidated by further additions, we usually don't do that. Either returning an index or not having these wrapper functions seems like the best choices IMO

From quick look it seems that it should actually be emplace_layer() or something like this.
And for that it is typically very handy to return reference. And not only that, since C++17 it is expected behavior for vector type containers as well.

From quick look it seems that it should actually be `emplace_layer()` or something like this. And for that it is typically very handy to return reference. And not only that, since C++17 it is expected behavior for vector type containers as well.

I think emplace_layer would be a better name indeed.

I think `emplace_layer` would be a better name indeed.
{
}
bool operator==(const Layer &other) const
{
@ -228,11 +231,6 @@ class Layer : public TreeNode, ::GreasePencilLayer {
{
return this != &other;
}
Layer &as_layer()
{
return *this;
}
};
class LayerGroup : public TreeNode {

View File

@ -14,11 +14,11 @@ TEST(gpencil, build_layer_tree)
LayerGroup root{};
LayerGroup group("Group1");
group.add_layer(Layer("Child1"));
group.add_layer(Layer("Child2"));
group.add_layer(Layer("Layer1"));
group.add_layer(Layer("Layer2"));
Use text fixtures: http://google.github.io/googletest/primer.html#same-data-multiple-tests

I used fixtures before, but decided to use this approach instead, because all the tests are then under the same greasepencil namespace. I didn't find a way to do this with fixtures, unless I name the class literally greasepencil.

I used fixtures before, but decided to use this approach instead, because all the tests are then under the same `greasepencil` namespace. I didn't find a way to do this with fixtures, unless I name the class literally `greasepencil`.

You can't do that either. It is at a very least discouraged to use the same name for fixture and "regular" test.

Typically the "namespace" defines context you're testing, and it is perfectly fine to have multiple of such contexts per file (euclidean_resection_test.cc). But with the monolithic nature of BKE/BLI tests there is no good way to achieve the same behavior.

I would love to improve the monolithic state of tests at some point (as it is really in a way every time I work on test), but that is outside of the scope of this patch.

Would be nice to add a comment on top of the GreasePencilIDTestContext which briefly summarizes your choice of this approach. Basically, so if someone else stumbles on this code and winders "why not fixtures" they have an answer.

You can't do that either. It is at a very least discouraged to use the same name for fixture and "regular" test. Typically the "namespace" defines context you're testing, and it is perfectly fine to have multiple of such contexts per file (`euclidean_resection_test.cc`). But with the monolithic nature of BKE/BLI tests there is no good way to achieve the same behavior. I would love to improve the monolithic state of tests at some point (as it is really in a way every time I work on test), but that is outside of the scope of this patch. Would be nice to add a comment on top of the `GreasePencilIDTestContext` which briefly summarizes your choice of this approach. Basically, so if someone else stumbles on this code and winders "why not fixtures" they have an answer.
root.add_group(std::move(group));
root.add_layer(Layer("Group2"));
root.add_layer(Layer("Layer3"));
root.foreach_children_pre_order([](TreeNode &child) { std::cout << child.name << std::endl; });
}