Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
24 changes: 15 additions & 9 deletions ink/strokes/internal/stroke_vertex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,13 @@ MeshFormat MakeValidatedFullFormat() {
return *format;
}

const MeshFormat kFullFormat = MakeValidatedFullFormat();

} // namespace

MeshFormat StrokeVertex::FullMeshFormat() {
// `MeshFormat` is relatively small, so we return by value to prevent any
// future issues in case, for example, the type stops being trivially
// destructible.
static const MeshFormat kFullFormat = MakeValidatedFullFormat();
return kFullFormat;
}

Expand Down Expand Up @@ -243,7 +242,8 @@ StrokeVertex::FormatAttributeIndices StrokeVertex::FindAttributeIndices(

StrokeVertex StrokeVertex::GetFromMesh(const MutableMesh& mesh,
uint32_t index) {
ABSL_DCHECK(MeshFormat::IsUnpackedEquivalent(mesh.Format(), kFullFormat));
ABSL_DCHECK(
MeshFormat::IsUnpackedEquivalent(mesh.Format(), FullMeshFormat()));
StrokeVertex vertex;
std::memcpy(&vertex, &mesh.RawVertexData()[index * sizeof(StrokeVertex)],
sizeof(StrokeVertex));
Expand Down Expand Up @@ -305,46 +305,52 @@ void SetNonPositionAttributes(
} // namespace

void StrokeVertex::AppendToMesh(MutableMesh& mesh, const StrokeVertex& vertex) {
ABSL_DCHECK(MeshFormat::IsUnpackedEquivalent(mesh.Format(), kFullFormat));
ABSL_DCHECK(
MeshFormat::IsUnpackedEquivalent(mesh.Format(), FullMeshFormat()));
mesh.AppendVertex(vertex.position);
SetNonPositionAttributes(mesh, mesh.VertexCount() - 1,
vertex.non_position_attributes);
}

void StrokeVertex::SetInMesh(MutableMesh& mesh, uint32_t index,
const StrokeVertex& vertex) {
ABSL_DCHECK(MeshFormat::IsUnpackedEquivalent(mesh.Format(), kFullFormat));
ABSL_DCHECK(
MeshFormat::IsUnpackedEquivalent(mesh.Format(), FullMeshFormat()));
mesh.SetVertexPosition(index, vertex.position);
SetNonPositionAttributes(mesh, index, vertex.non_position_attributes);
}

void StrokeVertex::SetSideDerivativeInMesh(MutableMesh& mesh, uint32_t index,
Vec derivative) {
ABSL_DCHECK(MeshFormat::IsUnpackedEquivalent(mesh.Format(), kFullFormat));
ABSL_DCHECK(
MeshFormat::IsUnpackedEquivalent(mesh.Format(), FullMeshFormat()));
mesh.SetFloatVertexAttribute(
index, StrokeVertex::kFullFormatAttributeIndices.side_derivative,
{derivative.x, derivative.y});
}

void StrokeVertex::SetForwardDerivativeInMesh(MutableMesh& mesh, uint32_t index,
Vec derivative) {
ABSL_DCHECK(MeshFormat::IsUnpackedEquivalent(mesh.Format(), kFullFormat));
ABSL_DCHECK(
MeshFormat::IsUnpackedEquivalent(mesh.Format(), FullMeshFormat()));
mesh.SetFloatVertexAttribute(
index, StrokeVertex::kFullFormatAttributeIndices.forward_derivative,
{derivative.x, derivative.y});
}

void StrokeVertex::SetSideLabelInMesh(MutableMesh& mesh, uint32_t index,
Label label) {
ABSL_DCHECK(MeshFormat::IsUnpackedEquivalent(mesh.Format(), kFullFormat));
ABSL_DCHECK(
MeshFormat::IsUnpackedEquivalent(mesh.Format(), FullMeshFormat()));
mesh.SetFloatVertexAttribute(
index, StrokeVertex::kFullFormatAttributeIndices.side_label,
{label.encoded_value});
}

void StrokeVertex::SetForwardLabelInMesh(MutableMesh& mesh, uint32_t index,
Label label) {
ABSL_DCHECK(MeshFormat::IsUnpackedEquivalent(mesh.Format(), kFullFormat));
ABSL_DCHECK(
MeshFormat::IsUnpackedEquivalent(mesh.Format(), FullMeshFormat()));
mesh.SetFloatVertexAttribute(
index, StrokeVertex::kFullFormatAttributeIndices.forward_label,
{label.encoded_value});
Expand Down