Skip to content
Snippets Groups Projects
Commit d8d2d6de authored by David C. Lonie's avatar David C. Lonie
Browse files

Fix TestContext2D to handle new alignment behavior.

Text alignment in the Context2D::ComputeJustifiedStringBounds now
aligns the text using the information provided by
vtkTextRenderer::ComputeBoundingBox. This differs from the previous
implementation since we now align to the actual drawn text instead of
the texture image data, which may contain padding. We also now properly
handle rotations that aren't multiples of 90 degrees.
parent 8d0b0e2e
No related branches found
No related tags found
No related merge requests found
......@@ -49,21 +49,30 @@ vtkStandardNewMacro(ContextItem);
//----------------------------------------------------------------------------
bool IsVector4Same(float expected[4], float computed[4])
{
double eps = 1e-6;
bool same = (fabs(expected[0] - computed[0]) < eps &&
fabs(expected[1] - computed[1]) < eps &&
fabs(expected[2] - computed[2]) < eps &&
fabs(expected[3] - computed[3]) < eps);
if (!same)
// The origin should be with 3 px of the expected value. This is because we
// align to the text data (ie. actual drawn pixels), not the texture image
// size, which may include a degree of padding.
const float originEps = 3.f;
const bool closeOrigin = (fabs(expected[0] - computed[0]) <= originEps &&
fabs(expected[1] - computed[1]) <= originEps);
// The width / height should be the same:
const float sizeEps = 1e-6f;
const bool sameSize = (fabs(expected[2] - computed[2]) <= sizeEps &&
fabs(expected[3] - computed[3]) <= sizeEps);
if (!sameSize || !closeOrigin)
{
std::cout << "Not the same!\n";
std::cout << "Expected: (" << expected[0] << ", " << expected[1] << ", "
<< expected[2] << ", " << expected[3] << ")\n";
std::cout << "Computed: (" << computed[0] << ", " << computed[1] << ", "
<< computed[2] << ", " << computed[3] << ")\n";
return false;
}
return same;
return true;
}
//----------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment