[DEBUG] correct the display of partial axis in lenear gradient
This commit is contained in:
parent
0ecf356a17
commit
d9f689ebc6
@ -55,32 +55,44 @@ etk::Color<float,4> esvg::render::DynamicColorLinear::getColor(const ivec2& _pos
|
|||||||
vec2 intersec = getIntersect(m_pos1, vectorBase,
|
vec2 intersec = getIntersect(m_pos1, vectorBase,
|
||||||
vec2(_pos.x(), _pos.y()), vectorOrtho);
|
vec2(_pos.x(), _pos.y()), vectorOrtho);
|
||||||
float baseSize = vectorBase.length();
|
float baseSize = vectorBase.length();
|
||||||
float baseDraw = (m_pos1 - intersec).length();
|
vec2 vectorBaseDraw = intersec - m_pos1;
|
||||||
|
float baseDraw = vectorBaseDraw.length();
|
||||||
ratio = baseDraw / baseSize;
|
ratio = baseDraw / baseSize;
|
||||||
|
//ratio -= float(int32_t(ratio));
|
||||||
|
if (vectorBase.dot(vectorBaseDraw) < 0) {
|
||||||
|
ratio *= -1.0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// in the basic vertion of the gradient the color is calculated with the ration in X and Y in the bonding box associated (it is rotate with the object..
|
// in the basic vertion of the gradient the color is calculated with the ration in X and Y in the bonding box associated (it is rotate with the object..
|
||||||
vec2 intersecX = getIntersect(m_pos1, m_axeX,
|
vec2 intersecX = getIntersect(m_pos1, m_axeX,
|
||||||
vec2(_pos.x(), _pos.y()), m_axeY);
|
vec2(_pos.x(), _pos.y()), m_axeY);
|
||||||
vec2 intersecY = getIntersect(m_pos1, m_axeY,
|
vec2 intersecY = getIntersect(m_pos1, m_axeY,
|
||||||
vec2(_pos.x(), _pos.y()), m_axeX);
|
vec2(_pos.x(), _pos.y()), m_axeX);
|
||||||
float baseDrawX = (m_pos1 - intersecX).length();
|
vec2 vectorBaseDrawX = intersecX - m_pos1;
|
||||||
float baseDrawY = (m_pos1 - intersecY).length();
|
vec2 vectorBaseDrawY = intersecY - m_pos1;
|
||||||
|
float baseDrawX = vectorBaseDrawX.length();
|
||||||
|
float baseDrawY = vectorBaseDrawY.length();
|
||||||
if (m_baseSize.x() != 0.0f) {
|
if (m_baseSize.x() != 0.0f) {
|
||||||
if (m_baseSize.y() != 0.0f) {
|
float val = baseDrawX/m_baseSize.x();
|
||||||
ratio += baseDrawX/m_baseSize.x() * 0.5f;
|
if (m_axeX.dot(vectorBaseDrawX) < 0) {
|
||||||
} else {
|
val *= -1.0;
|
||||||
ratio += baseDrawX/m_baseSize.x();
|
|
||||||
}
|
}
|
||||||
|
if (m_baseSize.y() == 0.0f) {
|
||||||
|
val *= 0.5f;
|
||||||
|
}
|
||||||
|
ratio += val;
|
||||||
}
|
}
|
||||||
if (m_baseSize.y() != 0.0f) {
|
if (m_baseSize.y() != 0.0f) {
|
||||||
if (m_baseSize.x() != 0.0f) {
|
float val = baseDrawY/m_baseSize.y();
|
||||||
ratio += baseDrawY/m_baseSize.y() * 0.5f;
|
if (m_axeY.dot(vectorBaseDrawY) < 0) {
|
||||||
} else {
|
val *= -1.0;
|
||||||
ratio += baseDrawY/m_baseSize.y();
|
|
||||||
}
|
}
|
||||||
|
if (m_baseSize.x() == 0.0f) {
|
||||||
|
val *= 0.5f;
|
||||||
|
}
|
||||||
|
ratio += val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//ESVG_DEBUG("plop " << ratio);
|
|
||||||
if (ratio <= m_data[0].first*0.01f) {
|
if (ratio <= m_data[0].first*0.01f) {
|
||||||
return m_data[0].second;
|
return m_data[0].second;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,23 @@ TEST(TestGradientLinear, diag1) {
|
|||||||
doc.generateAnImage(ivec2(100, 100), "TestGradientLinear_diag1.bmp", g_visualDebug);
|
doc.generateAnImage(ivec2(100, 100), "TestGradientLinear_diag1.bmp", g_visualDebug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(TestGradientLinear, diag1Partiel) {
|
||||||
|
std::string data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
|
||||||
|
"<svg height='100' width='100'>\n"
|
||||||
|
" <defs>\n"
|
||||||
|
" <linearGradient id='grad2' x1='40%' y1='40%' x2='70%' y2='70%'>\n"
|
||||||
|
" <stop offset='0%' style='stop-color:rgb(0,255,0);stop-opacity:1' />\n"
|
||||||
|
" <stop offset='100%' style='stop-color:rgb(0,0,255);stop-opacity:1' />\n"
|
||||||
|
" </linearGradient>\n"
|
||||||
|
" </defs>\n"
|
||||||
|
" <ellipse cx='50' cy='50' rx='50' ry='20' fill='url(#grad2)' />\n"
|
||||||
|
"</svg>\n");
|
||||||
|
esvg::Document doc;
|
||||||
|
doc.parse(data);
|
||||||
|
etk::FSNodeWriteAllData("TestGradientLinear_diag1Partiel.svg", data);
|
||||||
|
doc.generateAnImage(ivec2(100, 100), "TestGradientLinear_diag1Partiel.bmp", g_visualDebug);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(TestGradientLinear, diag2) {
|
TEST(TestGradientLinear, diag2) {
|
||||||
std::string data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
|
std::string data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
|
||||||
"<svg height='100' width='100'>\n"
|
"<svg height='100' width='100'>\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user