diff --git a/kandinsky/include/kandinsky/context.h b/kandinsky/include/kandinsky/context.h index 09a1d73ec..472f0b47b 100644 --- a/kandinsky/include/kandinsky/context.h +++ b/kandinsky/include/kandinsky/context.h @@ -42,7 +42,6 @@ public: virtual void pullRect(KDRect rect, KDColor * pixels) = 0; //Polygon - static const int k_polygonMaxNumberOfPoints = 32; void fillPolygon(KDCoordinate pointsX[], KDCoordinate pointsY[], int numberOfPoints, KDColor color); protected: KDContext(KDPoint origin, KDRect clippingRect); diff --git a/kandinsky/src/context_polygon.cpp b/kandinsky/src/context_polygon.cpp index 7dafd3cbe..dc97ada5a 100644 --- a/kandinsky/src/context_polygon.cpp +++ b/kandinsky/src/context_polygon.cpp @@ -11,6 +11,7 @@ void KDContext::fillPolygon(KDCoordinate pointsX[], KDCoordinate pointsY[], int KDCoordinate right = m_clippingRect.width(); KDCoordinate left = 0; + // We find top and bottom of the polygon for (int i = 0; i < numberOfPoints; i++) { if (pointsY[i] < top) { top = pointsY[i]; @@ -20,6 +21,7 @@ void KDContext::fillPolygon(KDCoordinate pointsX[], KDCoordinate pointsY[], int } } + // We update them if needed if (top < 0) { top = 0; } @@ -29,13 +31,13 @@ void KDContext::fillPolygon(KDCoordinate pointsX[], KDCoordinate pointsY[], int for (int y=top; y<=bottom; y++) { - int switches=0; - KDCoordinate switchesX[KDContext::k_polygonMaxNumberOfPoints]; + KDCoordinate switchesX[numberOfPoints]; int lastPointIndex = numberOfPoints-1; for (int i=0; i=y) || (pointsY[lastPointIndex]<= y && pointsY[i]>=y)) && pointsY[i] != pointsY[lastPointIndex]) { + if (((pointsY[i]=y) || (pointsY[lastPointIndex]=y)) && + pointsY[i] != pointsY[lastPointIndex]) { switchesX[switches++] = (int) round(pointsX[i]+1.0*(y-pointsY[i])/(pointsY[lastPointIndex]-pointsY[i])*(pointsX[lastPointIndex]-pointsX[i])); } lastPointIndex=i; @@ -60,7 +62,7 @@ void KDContext::fillPolygon(KDCoordinate pointsX[], KDCoordinate pointsY[], int break; } if (switchesX[i+1]>left) { - fillRect( KDRect( switchesX[ i ] , y, switchesX[ i+1 ] - switchesX[ i ], 1 ), color ) ; + fillRect( KDRect(switchesX[ i ], y, switchesX[ i+1 ] - switchesX[ i ], 1 ), color ) ; } } } diff --git a/python/port/mod/kandinsky/modkandinsky.cpp b/python/port/mod/kandinsky/modkandinsky.cpp index 8053979f8..90568a4e1 100644 --- a/python/port/mod/kandinsky/modkandinsky.cpp +++ b/python/port/mod/kandinsky/modkandinsky.cpp @@ -132,23 +132,19 @@ mp_obj_t modkandinsky_fill_circle(size_t n_args, const mp_obj_t * args) { } mp_obj_t modkandinsky_fill_polygon(size_t n_args, const mp_obj_t * args) { - KDCoordinate pointsX[KDContext::k_polygonMaxNumberOfPoints]; - KDCoordinate pointsY[KDContext::k_polygonMaxNumberOfPoints]; - size_t itemLength; mp_obj_t * items; mp_obj_get_array(args[0], &itemLength, &items); + KDCoordinate pointsX[itemLength]; + KDCoordinate pointsY[itemLength]; + if (itemLength < 3) { mp_raise_ValueError("polygon must have at least 3 points"); } - else if (itemLength > KDContext::k_polygonMaxNumberOfPoints) { - mp_raise_ValueError("polygon is defined by too many points"); - } - for(unsigned int i=0; i