Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ink/strokes/internal/stroke_subtraction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,16 @@ void AddVertex(MutableMesh& mutable_mesh, Point position,
const std::array<double, 3>& weights) {
uint32_t new_index = mutable_mesh.VertexCount();
mutable_mesh.AppendVertex(position);
const auto& format = mutable_mesh.Format();
for (uint32_t attr = 0; attr < triangle_attrs.size(); ++attr) {
auto id = format.Attributes()[attr].id;
// Set derivatives to 1.0 to avoid divisions-by-zero in the shader.
if (id == MeshFormat::AttributeId::kSideDerivative ||
id == MeshFormat::AttributeId::kForwardDerivative) {
mutable_mesh.SetFloatVertexAttribute(new_index, attr, {1.0f, 1.0f});
continue;
}

const auto& vals = triangle_attrs[attr];
if (vals[0].Size() == 0) continue;
uint8_t count = vals[0].Size();
Expand Down
2 changes: 1 addition & 1 deletion ink/strokes/internal/stroke_subtraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace ink::strokes_internal {
// input mesh. The attributes of vertices in the returned mesh are obtained
// by linearly interpolating the attributes of the input mesh, except for
// anti-aliasing attributes (kSideLabel, kSideDerivative, kForwardLabel,
// kForwardDerivative), which are set to zero.
// kForwardDerivative), which are set to default values.
absl::StatusOr<PartitionedMesh> Subtract(const PartitionedMesh& mesh_a,
const AffineTransform& transform_a,
const PartitionedMesh& mesh_b,
Expand Down
8 changes: 4 additions & 4 deletions ink/strokes/internal/stroke_subtraction_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ TEST(StrokeSubtractionTest, TriangleMinusTriangle) {
result_mesh.FloatVertexAttribute(*index_X1, 2).Values(),
ElementsAre(FloatEq(0.5f), FloatEq(0.5f), FloatEq(0.0f), FloatEq(1.0f)));
EXPECT_THAT(result_mesh.FloatVertexAttribute(*index_X1, 3).Values(),
ElementsAre(FloatEq(0.0f), FloatEq(0.0f)));
ElementsAre(FloatEq(1.0f), FloatEq(1.0f)));
EXPECT_THAT(result_mesh.FloatVertexAttribute(*index_X1, 4).Values(),
ElementsAre(FloatEq(0.0f), FloatEq(0.0f)));
ElementsAre(FloatEq(1.0f), FloatEq(1.0f)));

std::optional<uint32_t> index_X2 = FindVertexIndex(result_mesh, X2);
ASSERT_TRUE(index_X2.has_value());
Expand All @@ -231,9 +231,9 @@ TEST(StrokeSubtractionTest, TriangleMinusTriangle) {
result_mesh.FloatVertexAttribute(*index_X2, 2).Values(),
ElementsAre(FloatEq(0.0f), FloatEq(0.5f), FloatEq(0.5f), FloatEq(1.0f)));
EXPECT_THAT(result_mesh.FloatVertexAttribute(*index_X2, 3).Values(),
ElementsAre(FloatEq(0.0f), FloatEq(0.0f)));
ElementsAre(FloatEq(1.0f), FloatEq(1.0f)));
EXPECT_THAT(result_mesh.FloatVertexAttribute(*index_X2, 4).Values(),
ElementsAre(FloatEq(0.0f), FloatEq(0.0f)));
ElementsAre(FloatEq(1.0f), FloatEq(1.0f)));
}

TEST(StrokeSubtractionTest, AttributeInterpolation) {
Expand Down
Loading