From 07cacc4941275048587ddafbba0cf412dbaacbb4 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 6 Apr 2011 22:31:53 +0300 Subject: [PATCH] Fix ShapeRenderer::approximateArc. Fix GlyphCacheTest_Main. --- yg/shape_renderer.cpp | 25 +++++++++++-------------- yg/shape_renderer.hpp | 2 +- yg/yg_tests/glyph_cache_test.cpp | 11 +++++++++-- yg/yg_tests/shape_renderer_test.cpp | 14 +++++--------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/yg/shape_renderer.cpp b/yg/shape_renderer.cpp index cb2ecb5f24..626ce42eb1 100644 --- a/yg/shape_renderer.cpp +++ b/yg/shape_renderer.cpp @@ -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 pts; + vector pts; approximateArc(center, startA, endA, r, pts); - vector 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 & pts) + void ShapeRenderer::approximateArc(m2::PointD const & center, double startA, double endA, double r, vector & 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 pts; + vector pts; pts.push_back(center); approximateArc(center, startA, endA, r, pts); pts.push_back(center); - vector 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 arcPts; + vector 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 sectorPts; diff --git a/yg/shape_renderer.hpp b/yg/shape_renderer.hpp index 49aaaca5cd..3a45ac8e89 100644 --- a/yg/shape_renderer.hpp +++ b/yg/shape_renderer.hpp @@ -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 & pts); + static void approximateArc(m2::PointD const & center, double startA, double endA, double r, vector & 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); diff --git a/yg/yg_tests/glyph_cache_test.cpp b/yg/yg_tests/glyph_cache_test.cpp index f23fd8428e..3d75f684c4 100644 --- a/yg/yg_tests/glyph_cache_test.cpp +++ b/yg/yg_tests/glyph_cache_test.cpp @@ -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 g1 = cache.getGlyph(yg::GlyphKey('#', 40, true, yg::Color(255, 255, 255, 255))); // g1->dump(GetPlatform().WritablePathForFile("#_mask.png").c_str()); shared_ptr g2 = cache.getGlyph(yg::GlyphKey('#', 40, false, yg::Color(0, 0, 0, 0))); diff --git a/yg/yg_tests/shape_renderer_test.cpp b/yg/yg_tests/shape_renderer_test.cpp index e926d72323..1eb4bd4108 100644 --- a/yg/yg_tests/shape_renderer_test.cpp +++ b/yg/yg_tests/shape_renderer_test.cpp @@ -6,24 +6,20 @@ using namespace yg::gl; namespace { - void TestPoints(m2::PointF const & center, float r, vector const & points) + void TestPoints(m2::PointD const & center, float r, vector 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(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 points; + vector 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 points; + vector points; ShapeRenderer::approximateArc(center, startA, endA, r, points); TestPoints(center, r, points); }