Clipping algo is now OK ==> I will create a generic code and optimise it...
This commit is contained in:
parent
40f82d2f77
commit
1cabc7310b
@ -89,6 +89,7 @@ void generatePolyGone(etk::VectorType<coord2D_ts> & input, etk::VectorType<coord
|
|||||||
output.PushBack(input[iii]);
|
output.PushBack(input[iii]);
|
||||||
output.PushBack(input[iii+1]);
|
output.PushBack(input[iii+1]);
|
||||||
}
|
}
|
||||||
|
//EWOL_DEBUG("generate Plygone : " << input.Size() << " ==> " << output.Size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SutherlandHodgman(etk::VectorType<coord2D_ts> & input, etk::VectorType<coord2D_ts> & output, float sx, float sy, float ex, float ey)
|
void SutherlandHodgman(etk::VectorType<coord2D_ts> & input, etk::VectorType<coord2D_ts> & output, float sx, float sy, float ex, float ey)
|
||||||
@ -97,28 +98,25 @@ void SutherlandHodgman(etk::VectorType<coord2D_ts> & input, etk::VectorType<coor
|
|||||||
if (input.Size() <0) {
|
if (input.Size() <0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
int32_t sizeInit=input.Size();
|
||||||
// last element :
|
// last element :
|
||||||
coord2D_ts destPoint;
|
coord2D_ts destPoint;
|
||||||
coord2D_ts lastElement = input[input.Size()-1];
|
coord2D_ts lastElement = input[input.Size()-1];
|
||||||
bool inside = true;
|
bool inside = true;
|
||||||
if (lastElement.x < 0) {
|
if (lastElement.x < sx) {
|
||||||
inside = false;
|
inside = false;
|
||||||
}
|
}
|
||||||
EWOL_DEBUG("generate an crop : ");
|
//EWOL_DEBUG("generate an crop : ");
|
||||||
for(int32_t iii=0; iii<input.Size(); iii++) {
|
for(int32_t iii=0; iii<input.Size(); iii++) {
|
||||||
if(input[iii].x < 0) {
|
if(input[iii].x < sx) {
|
||||||
if(true == inside) {
|
if(true == inside) {
|
||||||
//EWOL_DEBUG("element IN ==> OUT ");
|
//EWOL_DEBUG("element IN ==> OUT ");
|
||||||
//new point intersection ...
|
//new point intersection ...
|
||||||
//y=aaax+bbb
|
//y=aaax+bbb
|
||||||
//EWOL_DEBUG(" A (" << lastElement.x << "," << lastElement.y << ") A(" << input[iii].x << "," << input[iii].y << ")");
|
|
||||||
float aaa = (lastElement.y-input[iii].y) / (lastElement.x-input[iii].x);
|
float aaa = (lastElement.y-input[iii].y) / (lastElement.x-input[iii].x);
|
||||||
float bbb = lastElement.y - (aaa*lastElement.x);
|
float bbb = lastElement.y - (aaa*lastElement.x);
|
||||||
//EWOL_DEBUG(" y=" << aaa << "*x + " << bbb << ";");
|
destPoint.y = aaa*sx + bbb;
|
||||||
//==> intersection en x=0 :
|
destPoint.x = sx;
|
||||||
destPoint.y = bbb;
|
|
||||||
destPoint.x = 0;
|
|
||||||
//EWOL_DEBUG(" ADD (" << destPoint.x << "," << destPoint.y << ")");
|
|
||||||
output.PushBack(destPoint);
|
output.PushBack(destPoint);
|
||||||
} else {
|
} else {
|
||||||
//EWOL_DEBUG("element OUT ==> OUT ");
|
//EWOL_DEBUG("element OUT ==> OUT ");
|
||||||
@ -127,22 +125,16 @@ void SutherlandHodgman(etk::VectorType<coord2D_ts> & input, etk::VectorType<coor
|
|||||||
} else {
|
} else {
|
||||||
if(true == inside) {
|
if(true == inside) {
|
||||||
//EWOL_DEBUG("element IN ==> IN ");
|
//EWOL_DEBUG("element IN ==> IN ");
|
||||||
//EWOL_DEBUG(" ADD (" << input[iii].x << "," << input[iii].y << ")");
|
|
||||||
output.PushBack(input[iii]);
|
output.PushBack(input[iii]);
|
||||||
} else {
|
} else {
|
||||||
//EWOL_DEBUG("element OUT ==> IN ");
|
//EWOL_DEBUG("element OUT ==> IN ");
|
||||||
//new point intersection ...
|
//new point intersection ...
|
||||||
//y=aaax+bbb
|
//y=aaax+bbb
|
||||||
//EWOL_DEBUG(" A (" << lastElement.x << "," << lastElement.y << ") A(" << input[iii].x << "," << input[iii].y << ")");
|
|
||||||
float aaa = (lastElement.y-input[iii].y) / (lastElement.x-input[iii].x);
|
float aaa = (lastElement.y-input[iii].y) / (lastElement.x-input[iii].x);
|
||||||
float bbb = lastElement.y - (aaa*lastElement.x);
|
float bbb = lastElement.y - (aaa*lastElement.x);
|
||||||
//EWOL_DEBUG(" y=" << aaa << "*x + " << bbb << ";");
|
destPoint.y = aaa*sx + bbb;
|
||||||
//==> intersection en x=0 :
|
destPoint.x = sx;
|
||||||
destPoint.y = bbb;
|
|
||||||
destPoint.x = 0;
|
|
||||||
//EWOL_DEBUG(" ADD (" << destPoint.x << "," << destPoint.y << ")");
|
|
||||||
output.PushBack(destPoint);
|
output.PushBack(destPoint);
|
||||||
//EWOL_DEBUG(" ADD (" << input[iii].x << "," << input[iii].y << ")");
|
|
||||||
output.PushBack(input[iii]);
|
output.PushBack(input[iii]);
|
||||||
}
|
}
|
||||||
inside = true;
|
inside = true;
|
||||||
@ -151,7 +143,143 @@ void SutherlandHodgman(etk::VectorType<coord2D_ts> & input, etk::VectorType<coor
|
|||||||
lastElement.x = input[iii].x;
|
lastElement.x = input[iii].x;
|
||||||
lastElement.y = input[iii].y;
|
lastElement.y = input[iii].y;
|
||||||
}
|
}
|
||||||
EWOL_DEBUG("generate an crop on element : " << input.Size()<< " ==> " << output.Size() );
|
|
||||||
|
//EWOL_DEBUG("generate an crop on element : " << sizeInit << " ==> " << output.Size() << "intermediate (1)");
|
||||||
|
input = output;
|
||||||
|
output.Clear();
|
||||||
|
lastElement = input[input.Size()-1];
|
||||||
|
inside = true;
|
||||||
|
if (lastElement.y < sy) {
|
||||||
|
inside = false;
|
||||||
|
}
|
||||||
|
for(int32_t iii=0; iii<input.Size(); iii++) {
|
||||||
|
if(input[iii].y < sy) {
|
||||||
|
if(true == inside) {
|
||||||
|
//EWOL_DEBUG("element IN ==> OUT ");
|
||||||
|
//new point intersection ...
|
||||||
|
//x=aaay+bbb
|
||||||
|
float aaa = (lastElement.x-input[iii].x) / (lastElement.y-input[iii].y);
|
||||||
|
float bbb = lastElement.x - (aaa*lastElement.y);
|
||||||
|
destPoint.y = sy;
|
||||||
|
destPoint.x = sy*aaa + bbb;
|
||||||
|
output.PushBack(destPoint);
|
||||||
|
} else {
|
||||||
|
//EWOL_DEBUG("element OUT ==> OUT ");
|
||||||
|
}
|
||||||
|
inside = false;
|
||||||
|
} else {
|
||||||
|
if(true == inside) {
|
||||||
|
//EWOL_DEBUG("element IN ==> IN ");
|
||||||
|
output.PushBack(input[iii]);
|
||||||
|
} else {
|
||||||
|
//EWOL_DEBUG("element OUT ==> IN ");
|
||||||
|
//new point intersection ...
|
||||||
|
//y=aaax+bbb
|
||||||
|
float aaa = (lastElement.x-input[iii].x) / (lastElement.y-input[iii].y);
|
||||||
|
float bbb = lastElement.x - (aaa*lastElement.y);
|
||||||
|
destPoint.y = sy;
|
||||||
|
destPoint.x = sy*aaa + bbb;
|
||||||
|
output.PushBack(destPoint);
|
||||||
|
output.PushBack(input[iii]);
|
||||||
|
}
|
||||||
|
inside = true;
|
||||||
|
}
|
||||||
|
// update the last point position :
|
||||||
|
lastElement.x = input[iii].x;
|
||||||
|
lastElement.y = input[iii].y;
|
||||||
|
}
|
||||||
|
|
||||||
|
input = output;
|
||||||
|
output.Clear();
|
||||||
|
lastElement = input[input.Size()-1];
|
||||||
|
inside = true;
|
||||||
|
if (lastElement.x > ex) {
|
||||||
|
inside = false;
|
||||||
|
}
|
||||||
|
//EWOL_DEBUG("generate an crop : ");
|
||||||
|
for(int32_t iii=0; iii<input.Size(); iii++) {
|
||||||
|
if(input[iii].x > ex) {
|
||||||
|
if(true == inside) {
|
||||||
|
//EWOL_DEBUG("element IN ==> OUT ");
|
||||||
|
//new point intersection ...
|
||||||
|
//y=aaax+bbb
|
||||||
|
float aaa = (lastElement.y-input[iii].y) / (lastElement.x-input[iii].x);
|
||||||
|
float bbb = lastElement.y - (aaa*lastElement.x);
|
||||||
|
destPoint.y = aaa*ex + bbb;
|
||||||
|
destPoint.x = ex;
|
||||||
|
output.PushBack(destPoint);
|
||||||
|
} else {
|
||||||
|
//EWOL_DEBUG("element OUT ==> OUT ");
|
||||||
|
}
|
||||||
|
inside = false;
|
||||||
|
} else {
|
||||||
|
if(true == inside) {
|
||||||
|
//EWOL_DEBUG("element IN ==> IN ");
|
||||||
|
output.PushBack(input[iii]);
|
||||||
|
} else {
|
||||||
|
//EWOL_DEBUG("element OUT ==> IN ");
|
||||||
|
//new point intersection ...
|
||||||
|
//y=aaax+bbb
|
||||||
|
float aaa = (lastElement.y-input[iii].y) / (lastElement.x-input[iii].x);
|
||||||
|
float bbb = lastElement.y - (aaa*lastElement.x);
|
||||||
|
destPoint.y = aaa*ex + bbb;
|
||||||
|
destPoint.x = ex;
|
||||||
|
output.PushBack(destPoint);
|
||||||
|
output.PushBack(input[iii]);
|
||||||
|
}
|
||||||
|
inside = true;
|
||||||
|
}
|
||||||
|
// update the last point position :
|
||||||
|
lastElement.x = input[iii].x;
|
||||||
|
lastElement.y = input[iii].y;
|
||||||
|
}
|
||||||
|
|
||||||
|
input = output;
|
||||||
|
output.Clear();
|
||||||
|
lastElement = input[input.Size()-1];
|
||||||
|
inside = true;
|
||||||
|
if (lastElement.y > ey) {
|
||||||
|
inside = false;
|
||||||
|
}
|
||||||
|
for(int32_t iii=0; iii<input.Size(); iii++) {
|
||||||
|
if(input[iii].y > ey) {
|
||||||
|
if(true == inside) {
|
||||||
|
//EWOL_DEBUG("element IN ==> OUT ");
|
||||||
|
//new point intersection ...
|
||||||
|
//x=aaay+bbb
|
||||||
|
float aaa = (lastElement.x-input[iii].x) / (lastElement.y-input[iii].y);
|
||||||
|
float bbb = lastElement.x - (aaa*lastElement.y);
|
||||||
|
destPoint.y = ey;
|
||||||
|
destPoint.x = ey*aaa + bbb;
|
||||||
|
output.PushBack(destPoint);
|
||||||
|
} else {
|
||||||
|
//EWOL_DEBUG("element OUT ==> OUT ");
|
||||||
|
}
|
||||||
|
inside = false;
|
||||||
|
} else {
|
||||||
|
if(true == inside) {
|
||||||
|
//EWOL_DEBUG("element IN ==> IN ");
|
||||||
|
output.PushBack(input[iii]);
|
||||||
|
} else {
|
||||||
|
//EWOL_DEBUG("element OUT ==> IN ");
|
||||||
|
//new point intersection ...
|
||||||
|
//y=aaax+bbb
|
||||||
|
float aaa = (lastElement.x-input[iii].x) / (lastElement.y-input[iii].y);
|
||||||
|
float bbb = lastElement.x - (aaa*lastElement.y);
|
||||||
|
destPoint.y = ey;
|
||||||
|
destPoint.x = ey*aaa + bbb;
|
||||||
|
output.PushBack(destPoint);
|
||||||
|
output.PushBack(input[iii]);
|
||||||
|
}
|
||||||
|
inside = true;
|
||||||
|
}
|
||||||
|
// update the last point position :
|
||||||
|
lastElement.x = input[iii].x;
|
||||||
|
lastElement.y = input[iii].y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//EWOL_DEBUG("generate an crop on element : " << sizeInit << " ==> " << output.Size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -331,7 +459,7 @@ void ewol::OObject2DColored::Circle(float x, float y, float radius, float thickn
|
|||||||
if (radius < thickness/2) {
|
if (radius < thickness/2) {
|
||||||
Disc(x, y, thickness/2 + radius);
|
Disc(x, y, thickness/2 + radius);
|
||||||
}
|
}
|
||||||
int32_t nbOcurence = radius*2;
|
int32_t nbOcurence = radius;
|
||||||
if (nbOcurence < 10)
|
if (nbOcurence < 10)
|
||||||
{
|
{
|
||||||
nbOcurence = 10;
|
nbOcurence = 10;
|
||||||
@ -366,10 +494,10 @@ void ewol::OObject2DColored::Disc(float x, float y, float radius)
|
|||||||
if (radius<0) {
|
if (radius<0) {
|
||||||
radius *= -1;
|
radius *= -1;
|
||||||
}
|
}
|
||||||
int32_t nbOcurence = radius*2;
|
int32_t nbOcurence = radius*0.50;
|
||||||
if (nbOcurence < 10)
|
if (nbOcurence < 15)
|
||||||
{
|
{
|
||||||
nbOcurence = 10;
|
nbOcurence = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t iii=0; iii<nbOcurence; iii++) {
|
for (int32_t iii=0; iii<nbOcurence; iii++) {
|
||||||
|
@ -148,7 +148,7 @@ bool ewol::Widget::AddEventArea(coord origin, coord size, uint64_t flags, const
|
|||||||
newEvent.area.size = size;
|
newEvent.area.size = size;
|
||||||
newEvent.area.flags = flags;
|
newEvent.area.flags = flags;
|
||||||
m_inputEvent.PushBack(newEvent);
|
m_inputEvent.PushBack(newEvent);
|
||||||
EWOL_DEBUG("Add an area event...");
|
//EWOL_DEBUG("Add an area event...");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ ewol::SizerHori::~SizerHori(void)
|
|||||||
|
|
||||||
bool ewol::SizerHori::CalculateSize(double availlableX, double availlableY)
|
bool ewol::SizerHori::CalculateSize(double availlableX, double availlableY)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("Update Size");
|
//EWOL_DEBUG("Update Size");
|
||||||
m_size.x = availlableX;
|
m_size.x = availlableX;
|
||||||
m_size.y = availlableY;
|
m_size.y = availlableY;
|
||||||
// calculate unExpendable Size :
|
// calculate unExpendable Size :
|
||||||
@ -76,7 +76,7 @@ bool ewol::SizerHori::CalculateSize(double availlableX, double availlableY)
|
|||||||
if (NULL != m_subWidget[iii]) {
|
if (NULL != m_subWidget[iii]) {
|
||||||
coord tmpSize = m_subWidget[iii]->GetMinSize();
|
coord tmpSize = m_subWidget[iii]->GetMinSize();
|
||||||
// Set the origin :
|
// Set the origin :
|
||||||
EWOL_DEBUG("Set ORIGIN : " << tmpOrigin.x << "," << tmpOrigin.y << ")");
|
//EWOL_DEBUG("Set ORIGIN : " << tmpOrigin.x << "," << tmpOrigin.y << ")");
|
||||||
m_subWidget[iii]->SetOrigin(tmpOrigin.x, tmpOrigin.y);
|
m_subWidget[iii]->SetOrigin(tmpOrigin.x, tmpOrigin.y);
|
||||||
// Now Update his Size his size in X and the curent sizer size in Y:
|
// Now Update his Size his size in X and the curent sizer size in Y:
|
||||||
if (true == m_subWidget[iii]->CanExpentX()) {
|
if (true == m_subWidget[iii]->CanExpentX()) {
|
||||||
@ -94,7 +94,7 @@ bool ewol::SizerHori::CalculateSize(double availlableX, double availlableY)
|
|||||||
|
|
||||||
bool ewol::SizerHori::CalculateMinSize(void)
|
bool ewol::SizerHori::CalculateMinSize(void)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("Update minimum Size");
|
//EWOL_DEBUG("Update minimum Size");
|
||||||
m_userExpendX=false;
|
m_userExpendX=false;
|
||||||
m_userExpendY=false;
|
m_userExpendY=false;
|
||||||
m_minSize.x = 0.0;
|
m_minSize.x = 0.0;
|
||||||
@ -115,8 +115,8 @@ bool ewol::SizerHori::CalculateMinSize(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EWOL_DEBUG("Result : expend X="<< m_userExpendX << " Y=" << m_userExpendY);
|
//EWOL_DEBUG("Result : expend X="<< m_userExpendX << " Y=" << m_userExpendY);
|
||||||
EWOL_DEBUG(" minSize ("<< m_minSize.x << "," << m_minSize.y << ")");
|
//EWOL_DEBUG(" minSize ("<< m_minSize.x << "," << m_minSize.y << ")");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ ewol::SizerVert::~SizerVert(void)
|
|||||||
|
|
||||||
bool ewol::SizerVert::CalculateSize(double availlableX, double availlableY)
|
bool ewol::SizerVert::CalculateSize(double availlableX, double availlableY)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("Update Size");
|
//EWOL_DEBUG("Update Size");
|
||||||
m_size.x = availlableX;
|
m_size.x = availlableX;
|
||||||
m_size.y = availlableY;
|
m_size.y = availlableY;
|
||||||
// calculate unExpendable Size :
|
// calculate unExpendable Size :
|
||||||
@ -78,7 +78,7 @@ bool ewol::SizerVert::CalculateSize(double availlableX, double availlableY)
|
|||||||
if (NULL != m_subWidget[iii]) {
|
if (NULL != m_subWidget[iii]) {
|
||||||
coord tmpSize = m_subWidget[iii]->GetMinSize();
|
coord tmpSize = m_subWidget[iii]->GetMinSize();
|
||||||
// Set the origin :
|
// Set the origin :
|
||||||
EWOL_DEBUG("Set ORIGIN : " << tmpOrigin.x << "," << tmpOrigin.y << ")");
|
//EWOL_DEBUG("Set ORIGIN : " << tmpOrigin.x << "," << tmpOrigin.y << ")");
|
||||||
m_subWidget[iii]->SetOrigin(tmpOrigin.x, tmpOrigin.y);
|
m_subWidget[iii]->SetOrigin(tmpOrigin.x, tmpOrigin.y);
|
||||||
// Now Update his Size his size in X and the curent sizer size in Y:
|
// Now Update his Size his size in X and the curent sizer size in Y:
|
||||||
if (true == m_subWidget[iii]->CanExpentY()) {
|
if (true == m_subWidget[iii]->CanExpentY()) {
|
||||||
@ -96,7 +96,7 @@ bool ewol::SizerVert::CalculateSize(double availlableX, double availlableY)
|
|||||||
|
|
||||||
bool ewol::SizerVert::CalculateMinSize(void)
|
bool ewol::SizerVert::CalculateMinSize(void)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("Update minimum Size");
|
//EWOL_DEBUG("Update minimum Size");
|
||||||
m_userExpendX=false;
|
m_userExpendX=false;
|
||||||
m_userExpendY=false;
|
m_userExpendY=false;
|
||||||
m_minSize.x = 0.0;
|
m_minSize.x = 0.0;
|
||||||
@ -117,8 +117,8 @@ bool ewol::SizerVert::CalculateMinSize(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EWOL_DEBUG("Result : expend X="<< m_userExpendX << " Y=" << m_userExpendY);
|
//EWOL_DEBUG("Result : expend X="<< m_userExpendX << " Y=" << m_userExpendY);
|
||||||
EWOL_DEBUG(" minSize ("<< m_minSize.x << "," << m_minSize.y << ")");
|
//EWOL_DEBUG(" minSize ("<< m_minSize.x << "," << m_minSize.y << ")");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +148,7 @@ void ewol::Test::OnRegenerateDisplay(void)
|
|||||||
AddEventArea(origin, size, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventTestPressed);
|
AddEventArea(origin, size, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventTestPressed);
|
||||||
|
|
||||||
//tmpOObjects->SetColor(1.0, 0.0, 0.0, 1.0);
|
//tmpOObjects->SetColor(1.0, 0.0, 0.0, 1.0);
|
||||||
|
//tmpOObjects->Circle(100, 100, 100, 35);
|
||||||
/*
|
/*
|
||||||
tmpOObjects->SetPoint(-20, -20);
|
tmpOObjects->SetPoint(-20, -20);
|
||||||
tmpOObjects->SetPoint(50, 50);
|
tmpOObjects->SetPoint(50, 50);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user