Index: trunk/src/intersect.c =================================================================== --- trunk/src/intersect.c (revision 34504) +++ trunk/src/intersect.c (revision 34505) @@ -67,19 +67,19 @@ } LocationList; /* --------------------------------------------------------------------------- - * Create a sorted list of unique y coords from a BoxList. + * Create a sorted list of unique y coords from an array of boxes. */ -static LocationList createSortedYList(rnd_box_list_t *boxlist) +static LocationList createSortedYList(rnd_box_t *boxes, long len) { LocationList yCoords; rnd_coord_t last; int i, n; /* create sorted list of Y coordinates */ - yCoords.size = 2 * boxlist->BoxN; + yCoords.size = 2 * len; yCoords.p = (rnd_coord_t *) calloc(yCoords.size, sizeof(*yCoords.p)); - for (i = 0; i < boxlist->BoxN; i++) { - yCoords.p[2 * i] = boxlist->Box[i].Y1; - yCoords.p[2 * i + 1] = boxlist->Box[i].Y2; + for (i = 0; i < len; i++) { + yCoords.p[2 * i] = boxes[i].Y1; + yCoords.p[2 * i + 1] = boxes[i].Y2; } qsort(yCoords.p, yCoords.size, sizeof(*yCoords.p), comparepos); /* count uniq y coords */ @@ -164,15 +164,15 @@ * etc.). * Runs in O(N ln N) time. */ -double pcb_intersect_box_box(rnd_box_list_t *boxlist) +double pcb_intersect_box_box(rnd_box_t *boxes, long len) { rnd_cardinal_t i; double area = 0.0; /* first get the aggregate area. */ - for (i = 0; i < boxlist->BoxN; i++) - area += (double) (boxlist->Box[i].X2 - boxlist->Box[i].X1) * (double) (boxlist->Box[i].Y2 - boxlist->Box[i].Y1); + for (i = 0; i < len; i++) + area += (double)(boxes[i].X2 - boxes[i].X1) * (double)(boxes[i].Y2 - boxes[i].Y1); /* intersection area is aggregate - union. */ - return area * 0.0001 - pcb_union_box_box(boxlist); + return area * 0.0001 - pcb_union_box_box(boxes, len); } /* --------------------------------------------------------------------------- @@ -179,7 +179,7 @@ * Compute the area of the union of the given rectangles. * O(N ln N) time. */ -double pcb_union_box_box(rnd_box_list_t *boxlist) +double pcb_union_box_box(rnd_box_t *boxes, long len) { rnd_box_t **rectLeft, **rectRight; rnd_cardinal_t i, j; @@ -188,30 +188,30 @@ rnd_coord_t lastX; double area = 0.0; - if (boxlist->BoxN == 0) + if (len == 0) return 0.0; /* create sorted list of Y coordinates */ - yCoords = createSortedYList(boxlist); + yCoords = createSortedYList(boxes, len); /* now create empty segment tree */ segtree = createSegmentTree(yCoords.p, yCoords.size); free(yCoords.p); /* create sorted list of left and right X coordinates of rectangles */ - rectLeft = (rnd_box_t **) calloc(boxlist->BoxN, sizeof(*rectLeft)); - rectRight = (rnd_box_t **) calloc(boxlist->BoxN, sizeof(*rectRight)); - for (i = 0; i < boxlist->BoxN; i++) { - assert(boxlist->Box[i].X1 <= boxlist->Box[i].X2); - assert(boxlist->Box[i].Y1 <= boxlist->Box[i].Y2); - rectLeft[i] = rectRight[i] = &boxlist->Box[i]; + rectLeft = (rnd_box_t **) calloc(len, sizeof(*rectLeft)); + rectRight = (rnd_box_t **) calloc(len, sizeof(*rectRight)); + for (i = 0; i < len; i++) { + assert(boxes[i].X1 <= boxes[i].X2); + assert(boxes[i].Y1 <= boxes[i].Y2); + rectLeft[i] = rectRight[i] = &boxes[i]; } - qsort(rectLeft, boxlist->BoxN, sizeof(*rectLeft), compareleft); - qsort(rectRight, boxlist->BoxN, sizeof(*rectRight), compareright); + qsort(rectLeft, len, sizeof(*rectLeft), compareleft); + qsort(rectRight, len, sizeof(*rectRight), compareright); /* sweep through x segments from left to right */ i = j = 0; lastX = rectLeft[0]->X1; - while (j < boxlist->BoxN) { - assert(i <= boxlist->BoxN); + while (j < len) { + assert(i <= len); /* i will step through rectLeft, j will through rectRight */ - if (i == boxlist->BoxN || rectRight[j]->X2 < rectLeft[i]->X1) { + if (i == len || rectRight[j]->X2 < rectLeft[i]->X1) { /* right edge of rectangle */ rnd_box_t *b = rectRight[j++]; /* check lastX */ Index: trunk/src/intersect.h =================================================================== --- trunk/src/intersect.h (revision 34504) +++ trunk/src/intersect.h (revision 34505) @@ -43,7 +43,7 @@ #include -double pcb_intersect_box_box(rnd_box_list_t *boxlist); /* will sort boxlist */ -double pcb_union_box_box(rnd_box_list_t *boxlist); +double pcb_intersect_box_box(rnd_box_t *boxes, long len); /* will sort boxlist */ +double pcb_union_box_box(rnd_box_t *boxes, long len); #endif Index: trunk/src_plugins/autoplace/autoplace.c =================================================================== --- trunk/src_plugins/autoplace/autoplace.c (revision 34504) +++ trunk/src_plugins/autoplace/autoplace.c (revision 34505) @@ -371,9 +371,9 @@ /* now compute penalty function Wc which is proportional to * amount of overlap and congestion. */ /* delta1 is congestion penalty function */ - delta1 = CostParameter.congestion_penalty * sqrt(fabs(pcb_intersect_box_box(&bounds))); + delta1 = CostParameter.congestion_penalty * sqrt(fabs(pcb_intersect_box_box(bounds.Box, bounds.BoxN))); #if 0 - printf("Wire Congestion Area: %f\n", pcb_intersect_box_box(&bounds)); + printf("Wire Congestion Area: %f\n", pcb_intersect_box_box(bounds.Box, bounds.BoxN)); #endif /* free bounding rectangles */ pcb_box_free(&bounds); @@ -437,10 +437,10 @@ PCB_END_LOOP; /* compute intersection area of module areas box list */ - delta2 = sqrt(fabs(pcb_intersect_box_box(&solderside) + pcb_intersect_box_box(&componentside))) * (CostParameter.overlap_penalty_min + (1 - (T / T0)) * CostParameter.overlap_penalty_max); + delta2 = sqrt(fabs(pcb_intersect_box_box(solderside.Box, solderside.BoxN) + pcb_intersect_box_box(componentside.Box, componentside.BoxN))) * (CostParameter.overlap_penalty_min + (1 - (T / T0)) * CostParameter.overlap_penalty_max); #if 0 - printf("Module Overlap Area (solder): %f\n", pcb_intersect_box_box(&solderside)); - printf("Module Overlap Area (component): %f\n", pcb_intersect_box_box(&componentside)); + printf("Module Overlap Area (solder): %f\n", pcb_intersect_box_box(solderside.Box, solderside.BoxN)); + printf("Module Overlap Area (component): %f\n", pcb_intersect_box_box(componentside.Box, componentside.BoxN)); #endif pcb_box_free(&solderside); pcb_box_free(&componentside);