[graphics] ENoJoin on Solid and Stripple Path, EBevelJoin for StripplePath + test update

This commit is contained in:
Darafei Praliaskouski 2013-01-12 19:06:12 +03:00 committed by Alex Zolotarev
parent 30f4b3b641
commit 382d789c51
3 changed files with 45 additions and 7 deletions

View file

@ -78,7 +78,7 @@ namespace
m_axisPattern.push_back(2);
m_axisPattern.push_back(2);
m_axisPenInfo = graphics::Pen::Info(graphics::Color(0xFF, 0, 0, 0xFF), 2, &m_axisPattern[0], m_axisPattern.size(), 0);
m_axisPenInfo = graphics::Pen::Info(graphics::Color(0xFF, 0, 0, 0xFF), 2, &m_axisPattern[0], m_axisPattern.size(), 0, 0, 0, graphics::Pen::Info::ENoJoin, graphics::Pen::Info::EButtCap);
}
void AddTest(std::vector<m2::PointD> const & points,
@ -606,6 +606,35 @@ namespace
testPoints.push_back(m2::PointD(dx + 220, dy + 170));
AddTest(testPoints, testPattern, graphics::Color(0, 255, 0, 255), width, 0, 0, 0, graphics::Pen::Info::ERoundCap, graphics::Pen::Info::EBevelJoin);
dy = 0;
dx += 200;
testPoints.clear();
testPoints.push_back(m2::PointD(dx + 20, dy + 100));
testPoints.push_back(m2::PointD(dx + 80, dy + 40));
testPoints.push_back(m2::PointD(dx + 120, dy + 169));
testPoints.push_back(m2::PointD(dx + 220, dy + 170));
AddTest(testPoints, testPattern, graphics::Color(0, 255, 0, 255), width, 0, 0, 0, graphics::Pen::Info::EButtCap, graphics::Pen::Info::ENoJoin);
dy += 130;
testPoints.clear();
testPoints.push_back(m2::PointD(dx + 20, dy + 100));
testPoints.push_back(m2::PointD(dx + 80, dy + 40));
testPoints.push_back(m2::PointD(dx + 120, dy + 169));
testPoints.push_back(m2::PointD(dx + 220, dy + 170));
AddTest(testPoints, testPattern, graphics::Color(0, 255, 0, 255), width, 0, 0, 0, graphics::Pen::Info::ESquareCap, graphics::Pen::Info::ENoJoin);
dy += 130;
testPoints.clear();
testPoints.push_back(m2::PointD(dx + 20, dy + 100));
testPoints.push_back(m2::PointD(dx + 80, dy + 40));
testPoints.push_back(m2::PointD(dx + 120, dy + 169));
testPoints.push_back(m2::PointD(dx + 220, dy + 170));
AddTest(testPoints, testPattern, graphics::Color(0, 255, 0, 255), width, 0, 0, 0, graphics::Pen::Info::ERoundCap, graphics::Pen::Info::ENoJoin);
testPattern.push_back(20);
testPattern.push_back(20);
testPattern.push_back(20);

View file

@ -59,6 +59,10 @@ namespace graphics
void PathRenderer::drawStipplePath(m2::PointD const * points, size_t pointsCount, double offset, Pen const * pen, double depth)
{
bool const hasRoundJoin = (pen->m_info.m_join == pen->m_info.ERoundJoin);
bool const hasBevelJoin = (pen->m_info.m_join == pen->m_info.EBevelJoin);
bool const hasJoin = (pen->m_info.m_join != pen->m_info.ENoJoin);
float rawTileStartLen = 0;
float rawTileLen = (float)pen->rawTileLen();
@ -174,10 +178,10 @@ namespace graphics
rawTileStartPt = rawTileEndPt;
}
bool isColorJoin = pen->m_isSolid ? true : pen->m_info.atDashOffset(rawTileLen);
bool isColorJoin = hasJoin && pen->m_info.atDashOffset(rawTileLen);
/// Adding geometry for a line join between previous and current segment.
if ((i != pointsCount - 2) && (isColorJoin))
if ((i != pointsCount - 2) && isColorJoin)
{
m2::PointD nextDir = points[i + 2] - points[i + 1];
nextDir *= 1.0 / nextDir.Length(m2::PointD(0, 0));
@ -187,19 +191,23 @@ namespace graphics
double alphaSin = dir.x * nextDir.y - dir.y * nextDir.x;
double alphaCos = dir.x * nextDir.x + dir.y * nextDir.y;
double alpha = atan2(alphaSin, alphaCos);
int angleSegCount = int(ceil(fabs(alpha) / (math::pi / 6)));
int angleSegCount = 1; // bevel join - 1 segment
if (hasRoundJoin)
angleSegCount= int(ceil(fabs(alpha) / (math::pi / 6)));
double angleStep = alpha / angleSegCount;
m2::PointD startVec;
if (alpha > 0)
{
/// The outer site is on the prevNorm direction.
/// The outer side is on the prevNorm direction.
startVec = -norm;
}
else
{
/// The outer site is on the -prevNorm direction
/// The outer side is on the -prevNorm direction
startVec = norm;
}

View file

@ -18,7 +18,8 @@ namespace graphics
enum ELineJoin
{
ERoundJoin,
EBevelJoin
EBevelJoin,
ENoJoin
};
enum ELineCap