From 1cfcd25c369e8ec4ea66bd2acb3a5368801bf89e Mon Sep 17 00:00:00 2001 From: Jacob1 Date: Wed, 14 Mar 2012 18:49:19 -0400 Subject: [PATCH] Increase drawing speed --- src/powder.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/powder.c b/src/powder.c index 91a478dfd..4c3d65df9 100644 --- a/src/powder.c +++ b/src/powder.c @@ -3167,22 +3167,33 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags) f = 1; } else - for (j=-ry; j<=ry; j++) - for (i=-rx; i<=rx; i++) - if (InCurrentBrush(i ,j ,rx ,ry)) - if (create_part_add_props(-2, x+i, y+j, c, rx, ry)==-1) - f = 1; + { + int tempy = y, i, j; + for (i = x - rx; i <= x; i++) { + while (InCurrentBrush(i-x,tempy-y,rx,ry)) { + tempy = tempy - 1; + } + tempy = tempy + 1; + for (j = tempy; j <= 2 * y - tempy; j++) { + if (create_part_add_props(-2, i, j, c, rx, ry)==-1) + f = 1; + if (create_part_add_props(-2, 2*x-i, j, c, rx, ry)==-1) + f = 1; + } + } + } return !f; } + int InCurrentBrush(int i, int j, int rx, int ry) { switch(CURRENT_BRUSH) { case CIRCLE_BRUSH: - return (pow(i,2)*pow(ry,2)+pow(j,2)*pow(rx,2)<=pow(rx,2)*pow(ry,2)); + return (pow((double)i,2)*pow((double)ry,2)+pow((double)j,2)*pow((double)rx,2)<=pow((double)rx,2)*pow((double)ry,2)); break; case SQUARE_BRUSH: - return (i*j<=ry*rx); + return (abs(i) <= rx && abs(j) <= ry); break; case TRI_BRUSH: return (j <= ry ) && ( j >= (((-2.0*ry)/rx)*i) -ry) && ( j >= (((-2.0*ry)/(-rx))*i)-ry ) ;