From a33196731c2713e7c4550d162131297d75ae678d Mon Sep 17 00:00:00 2001 From: Julian Lamb Date: Wed, 28 Jul 2010 12:53:18 -0400 Subject: [PATCH] recalculate the bounding boxes when drawing primatives via the libgerbv API --- src/gerb_image.c | 34 +++++++++++++++++++++++++++++++++- src/gerber.c | 30 +++++++++++++++--------------- src/gerber.h | 7 +++++++ 3 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/gerb_image.c b/src/gerb_image.c index 9ae3f27..f027325 100644 --- a/src/gerb_image.c +++ b/src/gerb_image.c @@ -681,24 +681,36 @@ gerbv_image_create_rectangle_object (gerbv_image_t *image, gdouble coordinateX, currentNet->start_y = coordinateY; currentNet->stop_x = coordinateX + width; currentNet->stop_y = coordinateY; - + gerber_update_min_and_max (¤tNet->boundingBox,currentNet->stop_x,currentNet->stop_y, + 0,0,0,0); + gerber_update_image_min_max (¤tNet->boundingBox, 0, 0, image); + currentNet = gerber_create_new_net (currentNet, NULL, NULL); currentNet->interpolation = GERBV_INTERPOLATION_LINEARx1; currentNet->aperture_state = GERBV_APERTURE_STATE_ON; currentNet->stop_x = coordinateX + width; currentNet->stop_y = coordinateY + height; + gerber_update_min_and_max (¤tNet->boundingBox,currentNet->stop_x,currentNet->stop_y, + 0,0,0,0); + gerber_update_image_min_max (¤tNet->boundingBox, 0, 0, image); currentNet = gerber_create_new_net (currentNet, NULL, NULL); currentNet->interpolation = GERBV_INTERPOLATION_LINEARx1; currentNet->aperture_state = GERBV_APERTURE_STATE_ON; currentNet->stop_x = coordinateX; currentNet->stop_y = coordinateY + height; + gerber_update_min_and_max (¤tNet->boundingBox,currentNet->stop_x,currentNet->stop_y, + 0,0,0,0); + gerber_update_image_min_max (¤tNet->boundingBox, 0, 0, image); currentNet = gerber_create_new_net (currentNet, NULL, NULL); currentNet->interpolation = GERBV_INTERPOLATION_LINEARx1; currentNet->aperture_state = GERBV_APERTURE_STATE_ON; currentNet->stop_x = coordinateX; currentNet->stop_y = coordinateY; + gerber_update_min_and_max (¤tNet->boundingBox,currentNet->stop_x,currentNet->stop_y, + 0,0,0,0); + gerber_update_image_min_max (¤tNet->boundingBox, 0, 0, image); /* create the polygon end node */ currentNet = gerber_create_new_net (currentNet, NULL, NULL); @@ -764,6 +776,21 @@ gerbv_image_create_arc_object (gerbv_image_t *image, gdouble centerX, gdouble ce currentNet->cirseg = g_new0 (gerbv_cirseg_t,1); *(currentNet->cirseg) = cirSeg; + gdouble angleDiff = currentNet->cirseg->angle2 - currentNet->cirseg->angle1; + gint i, steps = abs(angleDiff); + for (i=0; i<=steps; i++){ + gdouble tempX = currentNet->cirseg->cp_x + currentNet->cirseg->width / 2.0 * + cos ((currentNet->cirseg->angle1 + + (angleDiff * i) / steps)*M_PI/180); + gdouble tempY = currentNet->cirseg->cp_y + currentNet->cirseg->width / 2.0 * + sin ((currentNet->cirseg->angle1 + + (angleDiff * i) / steps)*M_PI/180); + gerber_update_min_and_max (¤tNet->boundingBox, + tempX, tempY, + lineWidth/2,lineWidth/2, + lineWidth/2,lineWidth/2); + } + gerber_update_image_min_max (¤tNet->boundingBox, 0, 0, image); return; } @@ -793,6 +820,11 @@ gerbv_image_create_line_object (gerbv_image_t *image, gdouble startX, gdouble st currentNet->stop_x = endX; currentNet->stop_y = endY; + gerber_update_min_and_max (¤tNet->boundingBox,currentNet->stop_x,currentNet->stop_y, + lineWidth/2,lineWidth/2,lineWidth/2,lineWidth/2); + gerber_update_min_and_max (¤tNet->boundingBox,currentNet->start_x,currentNet->start_y, + lineWidth/2,lineWidth/2,lineWidth/2,lineWidth/2); + gerber_update_image_min_max (¤tNet->boundingBox, 0, 0, image); return; } diff --git a/src/gerber.c b/src/gerber.c index 175d689..ac63a8a 100644 --- a/src/gerber.c +++ b/src/gerber.c @@ -75,12 +75,6 @@ static void calc_cirseg_sq(struct gerbv_net *net, int cw, static void calc_cirseg_mq(struct gerbv_net *net, int cw, double delta_cp_x, double delta_cp_y); -static void -gerber_update_min_and_max(gerbv_render_size_t *boundingBox, - gdouble x, gdouble y, gdouble apertureSizeX1, - gdouble apertureSizeX2,gdouble apertureSizeY1, - gdouble apertureSizeY2); - static void gerber_update_any_running_knockout_measurements(gerbv_image_t *image); @@ -691,14 +685,8 @@ gerber_parse_file_segment (gint levelOfRecursion, gerbv_image_t *image, } /* update the info bounding box with this latest bounding box */ - if (boundingBox.left < image->info->min_x) - image->info->min_x = boundingBox.left; - if (boundingBox.right+repeat_off_X > image->info->max_x) - image->info->max_x = boundingBox.right+repeat_off_X; - if (boundingBox.bottom < image->info->min_y) - image->info->min_y = boundingBox.bottom; - if (boundingBox.top+repeat_off_Y > image->info->max_y) - image->info->max_y = boundingBox.top+repeat_off_Y; + gerber_update_image_min_max(&boundingBox, repeat_off_X, repeat_off_Y, image); + /* optionally update the knockout measurement box */ if (knockoutMeasure) { if (boundingBox.left < knockoutLimitXmin) @@ -2671,7 +2659,19 @@ gerber_calculate_final_justify_effects(gerbv_image_t *image) } /* gerber_calculate_final_justify_effects */ -static void +void gerber_update_image_min_max (gerbv_render_size_t *boundingBox, double repeat_off_X, + double repeat_off_Y, gerbv_image_t* image) { + if (boundingBox->left < image->info->min_x) + image->info->min_x = boundingBox->left; + if (boundingBox->right+repeat_off_X > image->info->max_x) + image->info->max_x = boundingBox->right+repeat_off_X; + if (boundingBox->bottom < image->info->min_y) + image->info->min_y = boundingBox->bottom; + if (boundingBox->top+repeat_off_Y > image->info->max_y) + image->info->max_y = boundingBox->top+repeat_off_Y; +} + +void gerber_update_min_and_max(gerbv_render_size_t *boundingBox, gdouble x, gdouble y, gdouble apertureSizeX1, gdouble apertureSizeX2,gdouble apertureSizeY1, diff --git a/src/gerber.h b/src/gerber.h index 98f9ec8..b30510f 100644 --- a/src/gerber.h +++ b/src/gerber.h @@ -69,6 +69,13 @@ gerber_create_new_net (gerbv_net_t *currentNet, gerbv_layer_t *layer, gerbv_nets gboolean gerber_create_new_aperture (gerbv_image_t *image, int *indexNumber, gerbv_aperture_type_t apertureType, gdouble parameter1, gdouble parameter2); + +void gerber_update_image_min_max (gerbv_render_size_t *boundingBox, double repeat_off_X, + double repeat_off_Y, gerbv_image_t* image); +void gerber_update_min_and_max(gerbv_render_size_t *boundingBox, + gdouble x, gdouble y, gdouble apertureSizeX1, + gdouble apertureSizeX2,gdouble apertureSizeY1, + gdouble apertureSizeY2); #ifdef __cplusplus } #endif -- 2.11.4.GIT