From 1cabc7310b27fb6bd238ce45f0eb2bfc19e444fc Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Thu, 10 Nov 2011 17:54:28 +0100 Subject: [PATCH] Clipping algo is now OK ==> I will create a generic code and optimise it... --- Sources/ewolOObject2DColored.cpp | 172 +++++++++++++++++++++++++++---- Sources/ewolWidget.cpp | 2 +- Sources/widget/ewolSizerHori.cpp | 10 +- Sources/widget/ewolSizerVert.cpp | 10 +- Sources/widget/ewolTest.cpp | 3 +- 5 files changed, 163 insertions(+), 34 deletions(-) diff --git a/Sources/ewolOObject2DColored.cpp b/Sources/ewolOObject2DColored.cpp index 6b9ec356..b898ba50 100644 --- a/Sources/ewolOObject2DColored.cpp +++ b/Sources/ewolOObject2DColored.cpp @@ -89,6 +89,7 @@ void generatePolyGone(etk::VectorType & input, etk::VectorType " << output.Size() ); } void SutherlandHodgman(etk::VectorType & input, etk::VectorType & output, float sx, float sy, float ex, float ey) @@ -97,28 +98,25 @@ void SutherlandHodgman(etk::VectorType & input, etk::VectorType OUT "); //new point intersection ... //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 bbb = lastElement.y - (aaa*lastElement.x); - //EWOL_DEBUG(" y=" << aaa << "*x + " << bbb << ";"); - //==> intersection en x=0 : - destPoint.y = bbb; - destPoint.x = 0; - //EWOL_DEBUG(" ADD (" << destPoint.x << "," << destPoint.y << ")"); + destPoint.y = aaa*sx + bbb; + destPoint.x = sx; output.PushBack(destPoint); } else { //EWOL_DEBUG("element OUT ==> OUT "); @@ -127,22 +125,16 @@ void SutherlandHodgman(etk::VectorType & input, etk::VectorType IN "); - //EWOL_DEBUG(" ADD (" << input[iii].x << "," << input[iii].y << ")"); output.PushBack(input[iii]); } else { //EWOL_DEBUG("element OUT ==> IN "); //new point intersection ... //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 bbb = lastElement.y - (aaa*lastElement.x); - //EWOL_DEBUG(" y=" << aaa << "*x + " << bbb << ";"); - //==> intersection en x=0 : - destPoint.y = bbb; - destPoint.x = 0; - //EWOL_DEBUG(" ADD (" << destPoint.x << "," << destPoint.y << ")"); + destPoint.y = aaa*sx + bbb; + destPoint.x = sx; output.PushBack(destPoint); - //EWOL_DEBUG(" ADD (" << input[iii].x << "," << input[iii].y << ")"); output.PushBack(input[iii]); } inside = true; @@ -151,7 +143,143 @@ void SutherlandHodgman(etk::VectorType & input, etk::VectorType " << 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 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 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 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) { Disc(x, y, thickness/2 + radius); } - int32_t nbOcurence = radius*2; + int32_t nbOcurence = radius; if (nbOcurence < 10) { nbOcurence = 10; @@ -366,10 +494,10 @@ void ewol::OObject2DColored::Disc(float x, float y, float radius) if (radius<0) { radius *= -1; } - int32_t nbOcurence = radius*2; - if (nbOcurence < 10) + int32_t nbOcurence = radius*0.50; + if (nbOcurence < 15) { - nbOcurence = 10; + nbOcurence = 15; } for (int32_t iii=0; iiiGetMinSize(); // 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); // Now Update his Size his size in X and the curent sizer size in Y: if (true == m_subWidget[iii]->CanExpentX()) { @@ -94,7 +94,7 @@ bool ewol::SizerHori::CalculateSize(double availlableX, double availlableY) bool ewol::SizerHori::CalculateMinSize(void) { - EWOL_DEBUG("Update minimum Size"); + //EWOL_DEBUG("Update minimum Size"); m_userExpendX=false; m_userExpendY=false; 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(" minSize ("<< m_minSize.x << "," << m_minSize.y << ")"); + //EWOL_DEBUG("Result : expend X="<< m_userExpendX << " Y=" << m_userExpendY); + //EWOL_DEBUG(" minSize ("<< m_minSize.x << "," << m_minSize.y << ")"); return true; } diff --git a/Sources/widget/ewolSizerVert.cpp b/Sources/widget/ewolSizerVert.cpp index 386e4de8..022a3755 100644 --- a/Sources/widget/ewolSizerVert.cpp +++ b/Sources/widget/ewolSizerVert.cpp @@ -44,7 +44,7 @@ ewol::SizerVert::~SizerVert(void) bool ewol::SizerVert::CalculateSize(double availlableX, double availlableY) { - EWOL_DEBUG("Update Size"); + //EWOL_DEBUG("Update Size"); m_size.x = availlableX; m_size.y = availlableY; // calculate unExpendable Size : @@ -78,7 +78,7 @@ bool ewol::SizerVert::CalculateSize(double availlableX, double availlableY) if (NULL != m_subWidget[iii]) { coord tmpSize = m_subWidget[iii]->GetMinSize(); // 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); // Now Update his Size his size in X and the curent sizer size in Y: if (true == m_subWidget[iii]->CanExpentY()) { @@ -96,7 +96,7 @@ bool ewol::SizerVert::CalculateSize(double availlableX, double availlableY) bool ewol::SizerVert::CalculateMinSize(void) { - EWOL_DEBUG("Update minimum Size"); + //EWOL_DEBUG("Update minimum Size"); m_userExpendX=false; m_userExpendY=false; 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(" minSize ("<< m_minSize.x << "," << m_minSize.y << ")"); + //EWOL_DEBUG("Result : expend X="<< m_userExpendX << " Y=" << m_userExpendY); + //EWOL_DEBUG(" minSize ("<< m_minSize.x << "," << m_minSize.y << ")"); return true; } diff --git a/Sources/widget/ewolTest.cpp b/Sources/widget/ewolTest.cpp index 8d129b4c..1f6dc5fc 100644 --- a/Sources/widget/ewolTest.cpp +++ b/Sources/widget/ewolTest.cpp @@ -146,8 +146,9 @@ void ewol::Test::OnRegenerateDisplay(void) size.x = m_size.x-6; size.y = m_size.y-6; AddEventArea(origin, size, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventTestPressed); - + //tmpOObjects->SetColor(1.0, 0.0, 0.0, 1.0); + //tmpOObjects->Circle(100, 100, 100, 35); /* tmpOObjects->SetPoint(-20, -20); tmpOObjects->SetPoint(50, 50);