[DEV] try to implement curve path models ... (not work at all) and add test assiciated

This commit is contained in:
Edouard DUPIN 2015-11-24 22:20:12 +01:00
parent 3ddc118c4c
commit 4ccad4aaed
4 changed files with 136 additions and 21 deletions

View File

@ -203,7 +203,9 @@ bool esvg::Path::parse(const std::shared_ptr<exml::Element>& _element, mat2& _pa
break;
}
for(int32_t iii=0; iii<listDot.size(); iii+=4) {
m_listElement.smoothCurveTo(relative, vec2(listDot[iii],listDot[iii+1]), vec2(listDot[iii+2],listDot[iii+3]));
m_listElement.smoothCurveTo(relative,
vec2(listDot[iii],listDot[iii+1]),
vec2(listDot[iii+2],listDot[iii+3]));
}
break;

View File

@ -102,7 +102,7 @@ void esvg::Document::generateAnImage(const ivec2& _size, const std::string& _fil
SVG_ERROR("SizeY == 0 ==> set 64");
sizeY = 64;
}
SVG_INFO("Generate size (" << sizeX << "," << sizeY << ")");
SVG_DEBUG("Generate size (" << sizeX << "," << sizeY << ")");
delete(m_renderedElement);
m_renderedElement = nullptr;

View File

@ -232,29 +232,83 @@ esvg::render::PointList esvg::render::Path::generateListPoints(int32_t _level, i
}
break;
case esvg::render::path_smoothCurveTo:
/*
path.curve4SmoothTo(it->getRelative(),
vec2(it->m_element[0],
it->m_element[1]),
vec2(it->m_element[2],
it->m_element[3]) );
*/
// If no previous point, we need to create the last point has start ...
if (tmpListPoint.size() == 0) {
tmpListPoint.push_back(esvg::render::Point(lastPosition, esvg::render::Point::type_join));
}
{
vec2 lastPosStore(lastPosition);
if (it->getRelative() == false) {
lastPosition = vec2(0.0f, 0.0f);
}
vec2 pos2 = lastPosition + it->getPos2();
vec2 pos = lastPosition + it->getPos();
// generate Pos 1
vec2 pos1 = pos*2.0f - pos2;
interpolateCubicBezier(tmpListPoint,
_recurtionMax,
_threshold,
lastPosStore,
pos1,
pos2,
pos,
0,
esvg::render::Point::type_join);
lastPosition = pos;
}
break;
case esvg::render::path_bezierCurveTo:
/*
path.curve3To(it->getRelative(),
vec2(it->m_element[0],
it->m_element[1]),
vec2(it->m_element[2],
it->m_element[3]) );
*/
// If no previous point, we need to create the last point has start ...
if (tmpListPoint.size() == 0) {
tmpListPoint.push_back(esvg::render::Point(lastPosition, esvg::render::Point::type_join));
}
{
vec2 lastPosStore(lastPosition);
if (it->getRelative() == false) {
lastPosition = vec2(0.0f, 0.0f);
}
vec2 pos = lastPosition + it->getPos();
// generate pos1 and pos2
vec2 pos1 = lastPosStore + (it->getPos1() - lastPosStore)*0.666666666f;
vec2 pos2 = pos + (it->getPos1() - pos)*0.666666666f;
interpolateCubicBezier(tmpListPoint,
_recurtionMax,
_threshold,
lastPosStore,
pos1,
pos2,
pos,
0,
esvg::render::Point::type_join);
lastPosition = pos;
}
break;
case esvg::render::path_bezierSmoothCurveTo:
/*
path.curve3SmoothTo(it->getRelative(),
vec2(it->m_element[0],
it->m_element[1]) );
*/
// If no previous point, we need to create the last point has start ...
if (tmpListPoint.size() == 0) {
tmpListPoint.push_back(esvg::render::Point(lastPosition, esvg::render::Point::type_join));
}
{
vec2 lastPosStore(lastPosition);
if (it->getRelative() == false) {
lastPosition = vec2(0.0f, 0.0f);
}
vec2 pos = lastPosition + it->getPos();
vec2 delta = lastPosStore*2.0f - pos;
// generate pos1 and pos2
vec2 pos1 = lastPosStore + (delta - lastPosStore)*0.666666666f;
vec2 pos2 = pos + (delta - pos)*0.66666666f;
interpolateCubicBezier(tmpListPoint,
_recurtionMax,
_threshold,
lastPosStore,
pos1,
pos2,
pos,
0,
esvg::render::Point::type_join);
lastPosition = pos;
}
break;
case esvg::render::path_elliptic:
/*

View File

@ -48,3 +48,62 @@ TEST(TestPath, fill_and_stroke) {
etk::FSNodeWriteAllData("TestPath_fill_and_stroke.svg", data);
doc.generateAnImage(ivec2(100, 100), "TestPath_fill_and_stroke.bmp", g_visualDebug);
}
TEST(TestPath, curveTo) {
std::string data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>"
"<svg height='100' width='100'>"
" <path d='m 50,50 c -30,0 -30,1 -20,20 z'"
" fill='red' />"
"</svg>");
esvg::Document doc;
doc.parse(data);
etk::FSNodeWriteAllData("TestPath_curveTo.svg", data);
doc.generateAnImage(ivec2(100, 100), "TestPath_curveTo.bmp", g_visualDebug);
}
TEST(TestPath, smoothCurveTo) {
std::string data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>"
"<svg height='100' width='100'>"
" <path d='m 50,50 s -30,0 -20,20 z'"
" fill='red' />"
"</svg>");
esvg::Document doc;
doc.parse(data);
etk::FSNodeWriteAllData("TestPath_smoothCurveTo.svg", data);
doc.generateAnImage(ivec2(100, 100), "TestPath_smoothCurveTo.bmp", g_visualDebug);
}
TEST(TestPath, bezierCurveTo) {
std::string data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>"
"<svg height='100' width='100'>"
" <path d='m 50,50 q -30,1 -20,20 z'"
" fill='red' />"
"</svg>");
esvg::Document doc;
doc.parse(data);
etk::FSNodeWriteAllData("TestPath_bezierCurveTo.svg", data);
doc.generateAnImage(ivec2(100, 100), "TestPath_bezierCurveTo.bmp", g_visualDebug);
}
TEST(TestPath, bezierSmoothCurveTo) {
std::string data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>"
"<svg height='100' width='100'>"
" <path d='m 50,50 t -20,20 z'"
" fill='red' />"
"</svg>");
esvg::Document doc;
doc.parse(data);
etk::FSNodeWriteAllData("TestPath_bezierSmoothCurveTo.svg", data);
doc.generateAnImage(ivec2(100, 100), "TestPath_bezierSmoothCurveTo.bmp", g_visualDebug);
}
TEST(TestPath, arc) {
// TODO : ...
EXPECT_EQ(1, 2);
}