Fix ShapeRenderer::approximateArc.

Fix GlyphCacheTest_Main.
This commit is contained in:
vng 2011-04-06 22:31:53 +03:00 committed by Alex Zolotarev
parent 911cfcc587
commit 07cacc4941
4 changed files with 26 additions and 26 deletions

View file

@ -14,45 +14,42 @@ namespace yg
void ShapeRenderer::drawArc(m2::PointD const & center, double startA, double endA, double r, yg::Color const & c, double depth)
{
vector<m2::PointF> pts;
vector<m2::PointD> pts;
approximateArc(center, startA, endA, r, pts);
vector<m2::PointD> ptsD;
copy(pts.begin(), pts.end(), back_inserter(ptsD));
drawPath(&ptsD[0], ptsD.size(), skin()->mapPenInfo(yg::PenInfo(c, 3, 0, 0, 0)), depth);
drawPath(&pts[0], pts.size(), skin()->mapPenInfo(yg::PenInfo(c, 3, 0, 0, 0)), depth);
}
void ShapeRenderer::approximateArc(m2::PointF const & center, double startA, double endA, double r, vector<m2::PointF> & pts)
void ShapeRenderer::approximateArc(m2::PointD const & center, double startA, double endA, double r, vector<m2::PointD> & pts)
{
double sectorA = math::pi / 180.0;
unsigned sectorsCount = floor((endA - startA) / sectorA);
size_t const sectorsCount = floor(fabs(endA - startA) / sectorA);
sectorA = (endA - startA) / sectorsCount;
for (unsigned i = 0; i <= sectorsCount; ++i)
for (size_t i = 0; i <= sectorsCount; ++i)
pts.push_back(m2::Shift(m2::Rotate(m2::PointD(r, 0), startA + i * sectorA), center));
}
void ShapeRenderer::drawSector(m2::PointD const & center, double startA, double endA, double r, yg::Color const & c, double depth)
{
vector<m2::PointF> pts;
vector<m2::PointD> pts;
pts.push_back(center);
approximateArc(center, startA, endA, r, pts);
pts.push_back(center);
vector<m2::PointD> ptsD;
copy(pts.begin(), pts.end(), back_inserter(ptsD));
drawPath(&ptsD[0], ptsD.size(), skin()->mapPenInfo(yg::PenInfo(c, 2, 0, 0, 0)), depth);
drawPath(&pts[0], pts.size(), skin()->mapPenInfo(yg::PenInfo(c, 2, 0, 0, 0)), depth);
}
void ShapeRenderer::fillSector(m2::PointD const & center, double startA, double endA, double r, yg::Color const & c, double depth)
{
vector<m2::PointF> arcPts;
vector<m2::PointD> arcPts;
arcPts.push_back(center);
approximateArc(center, startA, endA, r, arcPts);
m2::PointF pt0 = arcPts[0];
m2::PointF pt1 = arcPts[1];
m2::PointD pt0 = arcPts[0];
m2::PointD pt1 = arcPts[1];
vector<m2::PointD> sectorPts;

View file

@ -14,7 +14,7 @@ namespace yg
ShapeRenderer(base_t::Params const & params);
static void approximateArc(m2::PointF const & center, double startA, double endA, double r, vector<m2::PointF> & pts);
static void approximateArc(m2::PointD const & center, double startA, double endA, double r, vector<m2::PointD> & pts);
void drawArc(m2::PointD const & center, double startA, double endA, double r, yg::Color const & c, double depth);
void drawSector(m2::PointD const & center, double startA, double endA, double r, yg::Color const & c, double depth);
void fillSector(m2::PointD const & center, double startA, double endA, double r, yg::Color const & c, double depth);

View file

@ -5,8 +5,15 @@
UNIT_TEST(GlyphCacheTest_Main)
{
yg::GlyphCache cache(yg::GlyphCache::Params("", "", "", 200000));
cache.addFont(GetPlatform().ReadPathForFile("dejavusans.ttf").c_str());
string const path = GetPlatform().WritableDir();
yg::GlyphCache cache(yg::GlyphCache::Params(
(path + "unicode_blocks.txt").c_str(),
(path + "fonts_whitelist.txt").c_str(),
(path + "fonts_blacklist.txt").c_str(),
200000));
cache.addFont((path + "01_dejavusans.ttf").c_str());
shared_ptr<yg::GlyphInfo> g1 = cache.getGlyph(yg::GlyphKey('#', 40, true, yg::Color(255, 255, 255, 255)));
// g1->dump(GetPlatform().WritablePathForFile("#_mask.png").c_str());
shared_ptr<yg::GlyphInfo> g2 = cache.getGlyph(yg::GlyphKey('#', 40, false, yg::Color(0, 0, 0, 0)));

View file

@ -6,24 +6,20 @@ using namespace yg::gl;
namespace
{
void TestPoints(m2::PointF const & center, float r, vector<m2::PointF> const & points)
void TestPoints(m2::PointD const & center, float r, vector<m2::PointD> const & points)
{
for (size_t i = 0; i < points.size(); ++i)
{
TEST_LESS(fabs(center.Length(points[i]) - r), 0.0001, ());
/*
TEST(my::AlmostEqual(center.Length(points[i]), static_cast<double>(r), 1024),
(center.Length(points[i]), r));
*/
TEST_LESS(fabs(center.Length(points[i]) - r), 0.0001, (points[i]));
}
}
}
UNIT_TEST(ApproximateArc_Smoke)
{
m2::PointF const center(1, 2);
m2::PointD const center(1, 2);
float r = 10;
vector<m2::PointF> points;
vector<m2::PointD> points;
ShapeRenderer::approximateArc(center, 0, math::pi / 4, r, points);
TestPoints(center, r, points);
}
@ -36,7 +32,7 @@ UNIT_TEST(ApproximateArc_Crash)
double const startA = -1.5707963267948966;
double const endA = -1.6057029118347832;
double const r = 127.99998027132824;
vector<m2::PointF> points;
vector<m2::PointD> points;
ShapeRenderer::approximateArc(center, startA, endA, r, points);
TestPoints(center, r, points);
}