int main(){ printf("Please enter the number of guests: "); scanf("%i", &num_guests); //find the number needed of each pizza size num_large = num_guests/largePizza.people; num_medium = (num_guests % largePizza.people) / mediumPizza.people; num_small = ((num_guests % largePizza.people) % mediumPizza.people); printf("\t\tNumber of pizzas\n" "Large:\t%i\tMedium:\t%i\tSmall:\t%i\n", num_large, num_medium, num_small); //get individual pizza areas large_area = get_area(largePizza.diameter/2); medium_area = get_area(mediumPizza.diameter/2); small_area = get_area(smallPizza.diameter/2); //calculate total area and area per guest total_area = (num_large*large_area) + (num_medium*medium_area) + (num_small*small_area); area_per_guest = total_area/num_guests; printf("Total Area:\t%f (in^2)\tArea per guest:\t%f (in^2)\n", total_area, area_per_guest); int in_tip_percent; printf("Please enter the percent of total price" " to be paid as a tip: "); scanf("%i", &in_tip_percent); //get total cost with no tip double total_cost_notip = (num_large*largePizza.price) + (num_medium*mediumPizza.price) + (num_small*smallPizza.price); //calculate total cost with tip total_cost = total_cost_notip + (total_cost_notip * (in_tip_percent*0.01)); printf("Total Cost:\t$%i\n", (int)round(total_cost)); return 0; }
static gint is_inside(GtsPoint *v1, GtsPoint *v2, GtsPoint *v3, GtsPoint *p) { gdouble a_all, a1, a2, a3; a_all = get_area(v1, v2, v3); a1 = get_area(p, v2, v3); a2 = get_area(v1, p, v3); a3 = get_area(v1, v2, p); return (a_all >= a1 + a2 + a3); }
int SkRTree::chooseSubtree(Node* root, Branch* branch) { SkASSERT(!root->isLeaf()); if (1 < root->fLevel) { // root's child pointers do not point to leaves, so minimize area increase int32_t minAreaIncrease = SK_MaxS32; int32_t minArea = SK_MaxS32; int32_t bestSubtree = -1; for (int i = 0; i < root->fNumChildren; ++i) { const SkIRect& subtreeBounds = root->child(i)->fBounds; int32_t areaIncrease = get_area_increase(subtreeBounds, branch->fBounds); // break ties in favor of subtree with smallest area if (areaIncrease < minAreaIncrease || (areaIncrease == minAreaIncrease && static_cast<int32_t>(get_area(subtreeBounds)) < minArea)) { minAreaIncrease = areaIncrease; minArea = get_area(subtreeBounds); bestSubtree = i; } } SkASSERT(-1 != bestSubtree); return bestSubtree; } else if (1 == root->fLevel) { // root's child pointers do point to leaves, so minimize overlap increase int32_t minOverlapIncrease = SK_MaxS32; int32_t minAreaIncrease = SK_MaxS32; int32_t bestSubtree = -1; for (int32_t i = 0; i < root->fNumChildren; ++i) { const SkIRect& subtreeBounds = root->child(i)->fBounds; SkIRect expandedBounds = subtreeBounds; join_no_empty_check(branch->fBounds, &expandedBounds); int32_t overlap = 0; for (int32_t j = 0; j < root->fNumChildren; ++j) { if (j == i) continue; // Note: this would be more correct if we subtracted the original pre-expanded // overlap, but computing overlaps is expensive and omitting it doesn't seem to // hurt query performance. See get_overlap_increase() overlap += get_overlap(expandedBounds, root->child(j)->fBounds); } // break ties with lowest area increase if (overlap < minOverlapIncrease || (overlap == minOverlapIncrease && static_cast<int32_t>(get_area_increase(branch->fBounds, subtreeBounds)) < minAreaIncrease)) { minOverlapIncrease = overlap; minAreaIncrease = get_area_increase(branch->fBounds, subtreeBounds); bestSubtree = i; } } return bestSubtree; } else { SkASSERT(false); return 0; } }
void Export_Dialog::reset_size() { height_spin->blockSignals(true); width_spin->blockSignals(true); width_spin->setValue(get_area().width()); height_spin->setValue(get_area().height()); height_spin->blockSignals(false); width_spin->blockSignals(false); ratio = double ( height_spin->value() ) / width_spin->value(); }
//*****************LIC10()********************* void LIC_10() { CMV[10]=FALSE; if(NUMPOINTS < 5) return; int i; for(i=0;(i+PARAMETERS.E_PTS+PARAMETERS.F_PTS+1+1< NUMPOINTS);i++) { double x1 = X[i]; double x2 = X[i+PARAMETERS.E_PTS+1]; double x3 = X[i+PARAMETERS.E_PTS+1+PARAMETERS.F_PTS+1]; double y1 = Y[i]; double y2 = Y[i+PARAMETERS.E_PTS+1]; double y3 = Y[i+PARAMETERS.E_PTS+1+PARAMETERS.F_PTS+1]; //double l12 = get_distance(x1,x2,y1,y2); //double l13 = get_distance(x1,x3,y1,y3); //double l23 = get_distance(x2,x3,y2,y3); //double hp = (l12+l13+l23)/2; // calculating half-perimeter //double result = hp*(hp-l12)*(hp-l13)*(hp-l23); //if (DOUBLECOMPARE(result,0)==LT) // result = 0; //double area = sqrt(result); double area = get_area(x1,y1,x2,y2,x3,y3); if(DOUBLECOMPARE(area,PARAMETERS.AREA1)==GT) { CMV[10]=TRUE; return; } } }//End of LIC_10
void LIC_3() { CMV[3] = FALSE; int i; // Loop through X and Y for (i=0;i<NUMPOINTS-2;++i) { // Get the coordinates for the three points double x1 = X[i]; double x2 = X[i+1]; double x3 = X[i+2]; double y1 = Y[i]; double y2 = Y[i+1]; double y3 = Y[i+2]; double area = get_area(x1,y1,x2,y2,x3,y3); //double l12 = get_distance(x1,x2,y1,y2); //double l13 = get_distance(x1,x3,y1,y3); //double l23 = get_distance(x2,x3,y2,y3); //double hp = (l12+l13+l23)/2; // calculating half-perimeter //double result = hp*(hp-l12)*(hp-l13)*(hp-l23); //if (DOUBLECOMPARE(result,0)==LT) // result = 0; //double area = sqrt(result); if (DOUBLECOMPARE(area,PARAMETERS.AREA1)==GT) { CMV[3] = TRUE; return; } }//closes for loop }// end of LIC3 functions LIC3 function
void floodfill() { int i; cell_t p, p1; grid[0][0][0] = -1; p.x = p.y = p.z = 0; q.push(p); while(!q.empty()) { p = q.front(), q.pop(); vol += get_vol(p.x, p.y, p.z); for(i = 0; i < 6; ++i) { p1.x = p.x+D[i][0], p1.y = p.y+D[i][1], p1.z = p.z+D[i][2]; if(p1.x < 0 || p1.x >= mx || p1.y < 0 || p1.y >= my || p1.z < 0 || p1.z >= mz) continue; if(grid[p1.x][p1.y][p1.z] == 0) { grid[p1.x][p1.y][p1.z] = -1; q.push(p1); } else if(grid[p1.x][p1.y][p1.z] == 1) { area += get_area(p1.x, p1.y, p1.z, i); } } } }
int digitize(FILE * fd) { int any; struct Categories labels; G_init_cats((CELL) 0, "", &labels); any = 0; for (;;) { switch (get_type()) { case 'A': /* area */ if (get_area(fd, &labels)) any = 1; break; case 'C': /* circle */ if (get_circle(fd, &labels)) any = 1; break; case 'L': /* line */ if (get_line(fd, &labels)) any = 1; break; case 'X': /* done */ return any; case 'Q': /* exit without saving */ if (G_yes(_("Quit without creating a map?? "), 0)) return 0; } } }
void text_entry::render(const window_render_params& params) { if (_is_dragging_selection) { _caret_pos = get_cursor_caret_pos(params._cursor_pos); make_caret_visible(); } refresh_render_text_parts(); auto& renderer = params._window_renderer; renderer.begin_brush_rendering(); renderer.render_brush(*this, _style->_underlay); if (_render_text_parts._selection._area.get_width() > 0.f) { renderer.render_brush(*this, _style->_selection_underlay, brush_render_mode::STRETCHED, rectf_to_rect(_render_text_parts._selection._area)); } renderer.end_brush_rendering(); renderer.begin_font_rendering(); renderer.render_font(*this, _style->_font, _render_text_parts._pre_selection._clipped_text.c_str(), rectf_to_rect(_render_text_parts._pre_selection._area)); renderer.render_font(*this, _style->_font, _render_text_parts._selection._clipped_text.c_str(), rectf_to_rect(_render_text_parts._selection._area)); renderer.render_font(*this, _style->_font, _render_text_parts._post_selection._clipped_text.c_str(), rectf_to_rect(_render_text_parts._post_selection._area)); renderer.end_font_rendering(); renderer.get_prim2d().begin_rendering(get_area()); renderer.get_prim2d().render_rect(get_caret_area(), get_caret_color()); renderer.get_prim2d().end_rendering(); }
static float get_volume(stl_file *stl) { long i; stl_vertex p0; stl_vertex p; stl_normal n; float height; float area; float volume = 0.0; /* Choose a point, any point as the reference */ p0.x = stl->facet_start[0].vertex[0].x; p0.y = stl->facet_start[0].vertex[0].y; p0.z = stl->facet_start[0].vertex[0].z; for(i = 0; i < stl->stats.number_of_facets; i++){ p.x = stl->facet_start[i].vertex[0].x - p0.x; p.y = stl->facet_start[i].vertex[0].y - p0.y; p.z = stl->facet_start[i].vertex[0].z - p0.z; /* Do dot product to get distance from point to plane */ n = stl->facet_start[i].normal; height = (n.x * p.x) + (n.y * p.y) + (n.z * p.z); area = get_area(&stl->facet_start[i]); volume += (area * height) / 3.0; } return volume; }
void update_cell(t_world *world, t_view *view, t_cell *cell) { int i; t_elem *cellrunner; float tmp_dist; int tmp_radius_add; t_cell *checked_cell; float area_increment; float dist_check; check_map_borders(cell); cell->pos.x += cell->dir.x; cell->pos.y += cell->dir.y; i = -1; while (++i < world->player_number) { cellrunner = world->players[i].cells->begin; while (cellrunner) { checked_cell = cellrunner->cell; if (cell != checked_cell) { tmp_dist = op_dist(&cell->pos, &checked_cell->pos); tmp_radius_add = cell->radius + checked_cell->radius; if (tmp_dist < tmp_radius_add) { dist_check = tmp_dist > (cell->radius - checked_cell->radius); if (dist_check) { if (cell->area >= checked_cell->area) { area_increment = get_area(cell, checked_cell, &tmp_dist); cell->area += area_increment; checked_cell->area -= area_increment; cell->radius = sqrtf(cell->area / M_PI); clear_cell(cell, view->surface); clear_cell(checked_cell, view->surface); checked_cell->radius = sqrtf(checked_cell->area / M_PI); draw_cell(checked_cell, view->surface); draw_cell(cell, view->surface); } } else { cell->area += checked_cell->area; checked_cell->area = 0; cell->radius = sqrtf(cell->area / M_PI); clear_cell(cell, view->surface); clear_cell(checked_cell, view->surface); checked_cell->radius = 0; draw_cell(checked_cell, view->surface); draw_cell(cell, view->surface); } } } cellrunner = cellrunner->next; } } }
/* Try to align mapping such that we align it as much as possible. */ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, unsigned long len, unsigned long pgoff, unsigned long flags) { unsigned long align_goal, addr = -ENOMEM; unsigned long (*get_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); get_area = current->mm->get_unmapped_area; if (flags & MAP_FIXED) { /* Ok, don't mess with it. */ return get_area(NULL, orig_addr, len, pgoff, flags); } flags &= ~MAP_SHARED; align_goal = PAGE_SIZE; if (len >= (4UL * 1024 * 1024)) align_goal = (4UL * 1024 * 1024); else if (len >= (512UL * 1024)) align_goal = (512UL * 1024); else if (len >= (64UL * 1024)) align_goal = (64UL * 1024); do { addr = get_area(NULL, orig_addr, len + (align_goal - PAGE_SIZE), pgoff, flags); if (!(addr & ~PAGE_MASK)) { addr = (addr + (align_goal - 1UL)) & ~(align_goal - 1UL); break; } if (align_goal == (4UL * 1024 * 1024)) align_goal = (512UL * 1024); else if (align_goal == (512UL * 1024)) align_goal = (64UL * 1024); else align_goal = PAGE_SIZE; } while ((addr & ~PAGE_MASK) && align_goal > PAGE_SIZE); /* Mapping is smaller than 64K or larger areas could not * be obtained. */ if (addr & ~PAGE_MASK) addr = get_area(NULL, orig_addr, len, pgoff, flags); return addr; }
int main(void){ double x1 = 10, y1 = 20, x2 = 14, y2 = 28; //double radius = stdin(""); //double radius = double area = get_area(get_distance(x1, y1, x2, y2)); printf("area is: %f\n", area); return area; }
pedbox * grow_box (pedbox * alpha, pedbox *beta) { if ( alpha == NULL || beta == NULL) return NULL; if(get_area(alpha) == 0) { alpha->x0 = beta->x0; alpha->y0 = beta->y0; alpha->x1 = beta->x1; alpha->y1 = beta->y1; return alpha; } if (get_area(beta) == 0) { return alpha; } alpha->x0 = alpha->x0 < beta->x0 ? alpha->x0 : beta->x0; alpha->y0 = alpha->y0 < beta->y0 ? alpha->y0 : beta->y0; alpha->x1 = alpha->x1 > beta->x1 ? alpha->x1 : beta->x1; alpha->y1 = alpha->y1 > beta->y1 ? alpha->y1 : beta->y1; return alpha; }
float max_area(TRACE *tx, TRACE *ty, TRACE *tz , int stp, int endp) { float x,y,z; x = get_area(tx,stp,endp); y = get_area(ty,stp,endp); z = get_area(tz,stp,endp); if (x > y) { if (z > x) { return (z); } else { return (x); } } else { if (z > y) { return (z); } else { return (y); } } }
//********************LIC_14()**************************************** void LIC_14() { CMV[14]=FALSE; int j; //for(i=0;(i+PARAMETERS.E_PTS+PARAMETERS.F_PTS+1+1< NUMPOINTS);i++) //{ //double x1 = X[i]; //double x2 = X[i+PARAMETERS.E_PTS+1]; //double x3 = X[i+PARAMETERS.E_PTS+1+PARAMETERS.F_PTS+1]; //double y1 = Y[i]; //double y2 = Y[i+PARAMETERS.E_PTS+1]; //double y3 = Y[i+PARAMETERS.E_PTS+1+PARAMETERS.F_PTS+1]; //double l12 = get_distance(x1,x2,y1,y2); //double l13 = get_distance(x1,x3,y1,y3); //double l23 = get_distance(x2,x3,y2,y3); //double hp = (l12+l13+l23)/2; // calculating half-perimeter //double area = sqrt(hp*(hp-l12)*(hp-l13)*(hp-l23)); //find if the area formed by the points is greater than PARAMETER.AREA1 //if(DOUBLECOMPARE(area,PARAMETERS.AREA1)==GT) if (CMV[10]==TRUE) { for(j=0;(j+PARAMETERS.E_PTS+PARAMETERS.F_PTS+1+1< NUMPOINTS);j++) { double x1 = X[j]; double x2 = X[j+PARAMETERS.E_PTS+1]; double x3 = X[j+PARAMETERS.E_PTS+1+PARAMETERS.F_PTS+1]; double y1 = Y[j]; double y2 = Y[j+PARAMETERS.E_PTS+1]; double y3 = Y[j+PARAMETERS.E_PTS+1+PARAMETERS.F_PTS+1]; //double l12 = get_distance(x1,x2,y1,y2); //double l13 = get_distance(x1,x3,y1,y3); //double l23 = get_distance(x2,x3,y2,y3); //double hp = (l12+l13+l23)/2; // calculating half-perimeter //double result = hp*(hp-l12)*(hp-l13)*(hp-l23); //// result shouldn't be a negative number, it should be multiplying //// all positive numbers. If it is negative, some weird overflow //// occured //if (DOUBLECOMPARE(result,0)==LT) // result = 0; //double area = sqrt(result); double area = get_area(x1,y1,x2,y2,x3,y3); //find if the area formed by the points is less than PARAMETER.AREA2 if(DOUBLECOMPARE(area,PARAMETERS.AREA2)==LT) { CMV[14]=TRUE; return; } } } }//End of LIC_14
CLIP_DLLEXPORT int _clip_set_area(ClipMachine * ClipMachineMemory, long area) { DBWorkArea *wa; const char nm[] = "_clip_set_area"; int no; if (!(wa = get_area(ClipMachineMemory, area, 0, &no)) && area) return rdd_err(ClipMachineMemory, EG_BADALIAS, 0, __FILE__, __LINE__, nm, er_badalias); ClipMachineMemory->curArea = no; return 0; }
int main() { std::ifstream input("in.txt"); std::ofstream output("out.txt"); std::vector<double> x, y; double coord_x, coord_y; while (input >> coord_x >> coord_y) { x.push_back(coord_x); y.push_back(coord_y); } double ans = get_area(x, y); output << std::fixed << std::setprecision(8) << ans << '\n'; return 0; }
void map_fragment::rotate_60_ccw() { area_.clear(); for (tile_info& ti : items_) { map_location l = map_location::ZERO(); int x = ti.offset.x; int y = ti.offset.y; // rotate the X-Y axes to NORTH/NORTH_EAST - SOUTH_EAST axes' // reverse of what the cw rotation does l = l.get_direction(map_location::NORTH, (x-is_odd(x))/2); l = l.get_direction(map_location::NORTH_EAST, (x+is_odd(x))/2 ); l = l.get_direction(map_location::SOUTH_EAST, y); ti.offset = l; area_.insert(l); } if (get_area().size() != items_.size()) { throw editor_exception("Map fragment rotation resulted in duplicate entries"); } }
void map_fragment::rotate_60_cw() { area_.clear(); for (tile_info& ti : items_) { map_location l = map_location::ZERO(); int x = ti.offset.x; int y = ti.offset.y; // rotate the X-Y axes to SOUTH/SOUTH_EAST - SOUTH_WEST axes // but if x is odd, simply using x/2 + x/2 will lack a step l = l.get_direction(map_location::SOUTH, (x+is_odd(x))/2); l = l.get_direction(map_location::SOUTH_EAST, (x-is_odd(x))/2 ); l = l.get_direction(map_location::SOUTH_WEST, y); ti.offset = l; area_.insert(l); } if (get_area().size() != items_.size()) { throw editor_exception("Map fragment rotation resulted in duplicate entries"); } }
image_info get_max_rectangle(const bmp * image) { int row = image->header.height; int rowFrom, rowTo, columnFrom, columnTo; int max = 0; int area; int column = image->header.width; image_info analyzed_image; if(row == 0) { // if row equals to 0 then there's no pixels at all // means that column is equal to 0 as well. assert(column == 0); analyzed_image.top_left_x = 0; analyzed_image.top_left_y = 0; analyzed_image.bottom_right_x = 0; analyzed_image.bottom_right_y = 0; } for (rowFrom = 0; rowFrom < row; rowFrom++) { for (rowTo = rowFrom; rowTo < row; rowTo++) { for (columnFrom = 0; columnFrom < column; columnFrom++) { for (columnTo = columnFrom; columnTo < column; columnTo++) { area = get_area(image, columnFrom, columnTo, rowFrom, rowTo); if (area > max) { max = area; analyzed_image.top_left_x = columnFrom; analyzed_image.top_left_y = rowFrom; analyzed_image.bottom_right_x = columnTo; analyzed_image.bottom_right_y = rowTo; } else if(area == max && rowFrom == analyzed_image.top_left_y) { analyzed_image.top_left_x = columnFrom; analyzed_image.bottom_right_x = columnTo; } } } } } return analyzed_image; }
/** * dispatch mouse event, which requires some extra operations * * @param w: pointer to the widget * @param msg: pointer to message * @return: 1 if found and dispatched, 0 if not found **/ static struct widget* do_dispatch_mouse_event_and_returns(struct widget* w, union message* msg) { struct rectangle area; /** * calculate absolute area of the widget **/ if(w->is_window == 1) { get_area(w->gd, &area); } else { application_widget_absolute_area(w, &area); } /** * if cursor position in widget area **/ if(msg->mouse.cursor_position.x >= area.x && msg->mouse.cursor_position.x <= area.x + area.width - 1 && msg->mouse.cursor_position.y >= area.y && msg->mouse.cursor_position.y <= area.y + area.height - 1) { if(w->callback != NULL) { w->callback(w, msg); } /** * update widget keybd focus **/ application_update_keybd_focus(w); return w; } return NULL; }
int clip_RDDHANDLE(ClipMachine * ClipMachineMemory) { const char *__PROC__ = "RDDHANDLE"; int area = _clip_parni(ClipMachineMemory, 1); DBWorkArea *wa = NULL; int er; CHECKOPT1(1, NUMERIC_type_of_ClipVarType); _clip_retni(ClipMachineMemory, -1); if (_clip_parinfo(ClipMachineMemory, 1) != UNDEF_type_of_ClipVarType) wa = get_area(ClipMachineMemory, area, 0, 0); if (!wa) wa = cur_area(ClipMachineMemory); if (wa) _clip_retni(ClipMachineMemory, wa->rd_item); return 0; err: return er; }
float Triangle::pdf(const Vector3 &p, const Vector3 &wi) { return 1.f / get_area(); }
bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &result) { /* allocate and initialize list of Vertices in polygon */ int n = contour.size(); if (n < 3) return false; Vector<int> V; V.resize(n); /* we want a counter-clockwise polygon in V */ if (0.0 < get_area(contour)) for (int v = 0; v < n; v++) V.write[v] = v; else for (int v = 0; v < n; v++) V.write[v] = (n - 1) - v; bool relaxed = false; int nv = n; /* remove nv-2 Vertices, creating 1 triangle every time */ int count = 2 * nv; /* error detection */ for (int v = nv - 1; nv > 2;) { /* if we loop, it is probably a non-simple polygon */ if (0 >= (count--)) { if (relaxed) { //** Triangulate: ERROR - probable bad polygon! return false; } else { // There may be aligned vertices that the strict // checks prevent from triangulating. In this situation // we are better off adding flat triangles than // failing, so we relax the checks and try one last // round. // Only relaxing the constraints as a last resort avoids // degenerate triangles when they aren't necessary. count = 2 * nv; relaxed = true; } } /* three consecutive vertices in current polygon, <u,v,w> */ int u = v; if (nv <= u) u = 0; /* previous */ v = u + 1; if (nv <= v) v = 0; /* new v */ int w = v + 1; if (nv <= w) w = 0; /* next */ if (snip(contour, u, v, w, nv, V, relaxed)) { int a, b, c, s, t; /* true names of the vertices */ a = V[u]; b = V[v]; c = V[w]; /* output Triangle */ result.push_back(a); result.push_back(b); result.push_back(c); /* remove v from remaining polygon */ for (s = v, t = v + 1; t < nv; s++, t++) V.write[s] = V[t]; nv--; /* reset error detection counter */ count = 2 * nv; } } return true; }
static inline uint32_t get_area_increase(const SkIRect& rect1, SkIRect rect2) { join_no_empty_check(rect1, &rect2); return get_area(rect2) - get_area(rect1); }
int SkRTree::distributeChildren(Branch* children) { // We have two sides to sort by on each of two axes: const static SortSide sorts[2][2] = { {&SkIRect::fLeft, &SkIRect::fRight}, {&SkIRect::fTop, &SkIRect::fBottom} }; // We want to choose an axis to split on, then a distribution along that axis; we'll need // three pieces of info: the split axis, the side to sort by on that axis, and the index // to split the sorted array on. int32_t sortSide = -1; int32_t k = -1; int32_t axis = -1; int32_t bestS = SK_MaxS32; // Evaluate each axis, we want the min summed margin-value (s) over all distributions for (int i = 0; i < 2; ++i) { int32_t minOverlap = SK_MaxS32; int32_t minArea = SK_MaxS32; int32_t axisBestK = 0; int32_t axisBestSide = 0; int32_t s = 0; // Evaluate each sort for (int j = 0; j < 2; ++j) { SkTQSort(children, children + fMaxChildren, RectLessThan(sorts[i][j])); // Evaluate each split index for (int32_t k = 1; k <= fMaxChildren - 2 * fMinChildren + 2; ++k) { SkIRect r1 = children[0].fBounds; SkIRect r2 = children[fMinChildren + k - 1].fBounds; for (int32_t l = 1; l < fMinChildren - 1 + k; ++l) { join_no_empty_check(children[l].fBounds, &r1); } for (int32_t l = fMinChildren + k; l < fMaxChildren + 1; ++l) { join_no_empty_check(children[l].fBounds, &r2); } int32_t area = get_area(r1) + get_area(r2); int32_t overlap = get_overlap(r1, r2); s += get_margin(r1) + get_margin(r2); if (overlap < minOverlap || (overlap == minOverlap && area < minArea)) { minOverlap = overlap; minArea = area; axisBestSide = j; axisBestK = k; } } } if (s < bestS) { bestS = s; axis = i; sortSide = axisBestSide; k = axisBestK; } } // replicate the sort of the winning distribution, (we can skip this if the last // sort ended up being best) if (!(axis == 1 && sortSide == 1)) { SkTQSort(children, children + fMaxChildren, RectLessThan(sorts[axis][sortSide])); } return fMinChildren - 1 + k; }
void main(int argc , char* argv[]) { printf("input file : %s\n",argv[1]); int module_count=0; float lambda = 0; float total_size = 0; struct module_dim **module_array; struct module_dim **module_array_temp; struct module_dim *temp_module; struct module_dim *free_module; struct module *temp_modules; int i; int *polish_exp, *best_polish; int verticle, horizontal; unsigned int init_temp = 100000; struct cost cost; struct cost cost_new; struct cost cost_best; int *polish_exp_new; int *temp_polish; float delta_area; int random; float param_exp; int move_select = rand()%MOVE; float my_area; float best_temp = 1000; float cur_temp; //Calling Hotspot char *argv_hotspot[7]={ "./hotspot", "-c", "../HotSpot-5.02/hotspot.config", "-f", "../data/ev6.flp", "-p", "../data/gcc.ptrace"}; /*pseudo-random number generator is initialized using time feed*/ srand( (unsigned)time( NULL ) ); /*design file parser*/ module_count = parse_design(argv[1], &module_array, &lambda, &total_size); /*vertical and horizontal section identify with number*/ verticle = module_count + 1; horizontal = module_count + 2; /*random polish expression generator*/ //polish_exp = getRandom(module_count); polish_exp = init_polish(module_count); best_polish = polish_exp; my_area = get_area(module_count, module_array,polish_exp); //cost.area = my_area; //cost_best.area = my_area; cost.area = 3*total_size; cost_best.area = 3*total_size; printf("size: %d, lambda: %f\n",module_count,lambda); int M = 0; int MT = 1; int uphill = 0; int reject = 0; float r = 0.85; float T = 1000; int k = 50000; int n = 2*module_count-1; int N = k * n; int r_cnt = 0; float best_lambda = 1; float cur_lambda; float update_to; update_to = 400*module_count; /*performing sizing slicing on floorplan generated by polish expression*/ //cost = sizing_slicing(module_array, polish_exp,module_count); time_t rawtime; struct tm * timeinfo1; struct tm * timeinfo2; time ( &rawtime ); timeinfo1 = localtime ( &rawtime ); /* SA algorithm Starts */ while(/*(reject/MT) < 0.95 &&*/ ( T > 400) ){ while((uphill < N) && (MT<2*N)){ #ifdef PRINT while(1){ int c; print_polish(module_count, polish_exp); save_design_ev6(module_count, module_array,polish_exp); my_area = get_area(module_count, module_array,polish_exp); printf("area before : < %f >\n", my_area); printf( "Enter Something, Not That We Care Tho :P\n"); c = getchar( ); #endif #ifdef DEBUG printf("** 2 **\n"); #endif if (r_cnt > update_to){ r_cnt = 0; polish_exp = init_polish(module_count); #ifdef PROGRESS //printf("delta area : %f\n",delta_area); printf("lambda (Current): %f, Lambda for best Temperature: %f, Best Temperature: %f\n",cur_lambda,best_lambda, best_temp); #endif } r_cnt++; //no need for slides algorithm since the smart_move does it move_select = rand()%MOVE; polish_exp_new = smart_move(module_count, polish_exp,move_select); //polish_exp_new = getRandom(module_count); MT++; cost_new.area = get_area(module_count, module_array,polish_exp_new); cur_lambda = (cost_new.area-total_size)/total_size; cost.area = get_area(module_count, module_array,polish_exp); delta_area = cost_new.area - cost.area; #ifdef DEBUG printf("** 3 **\n"); #endif #ifdef PRINT print_polish(module_count, polish_exp_new); save_design_ev7(module_count, module_array,polish_exp_new); my_area = get_area(module_count, module_array,polish_exp_new); printf("area after : < %f >\n", my_area); printf( "Enter Something, Not That We Care Tho :P\n"); c = getchar( ); } #endif // generates random values between 0.1 and 0.9 random = (rand() % 9) / 10; // Acceptance probability calculation param_exp = (delta_area/init_temp); // If new cost is small if(delta_area < 0 /*|| random < exp(-(param_exp))*/){ //free(polish_exp); if(delta_area > 0) uphill++; polish_exp = polish_exp_new; if(cur_lambda < lambda && /*cur_lambda > 0 &&*/ check_for_overlap(module_count, module_array, cur_lambda, polish_exp_new)) { //printf("A design is saved %d\n",check_for_overlap(module_count, module_array, cur_lambda, polish_exp_new)); save_design_ev6(module_count, module_array, polish_exp); cur_temp = get_temp(7, argv_hotspot); if(cur_temp < best_temp){ best_lambda = cur_lambda; best_temp = cur_temp; best_polish = polish_exp; save_design_final(module_count, module_array, best_polish, lambda); save_design_ev7(module_count, module_array, best_polish); } } } else {reject++;} #ifdef PROGRESS //printf("delta area : %f\n",delta_area); //printf("lambda (Current): %f, Lambda for best Temperature: %f, Best Temperature: %f\n",cur_lambda,best_lambda, best_temp); #endif } T = r*T; MT = 1; uphill = 0; reject = 0; } /* SA algorith finish */ //printf("\ncost after SA\n"); printf("\ncost.area = %f\n", get_area(module_count, module_array,best_polish)); printf("\nFinal Lambda = %f", best_lambda); /*generates output design file */ save_design_ev6(module_count, module_array, best_polish); save_design_final(module_count, module_array, best_polish,lambda); cur_temp = get_temp(7, argv_hotspot); printf("\nMaximum Temperature: %f\n", cur_temp); printf ( "Current local time and date: %s", asctime (timeinfo1) ); time ( &rawtime ); timeinfo2 = localtime ( &rawtime ); printf ( "Current local time and date: %s", asctime (timeinfo2) ); /*free allocated dynamic memory*/ module_array_temp = module_array; for(i=0; i<module_count; i++){ temp_module = module_array_temp[i]; while(temp_module != NULL){ free_module = temp_module; temp_module = temp_module->next; free(free_module); } } free(module_array); }
int clip___DBCOPYRAW(ClipMachine * ClipMachineMemory) { const char *__PROC__ = "__RDDCOPY"; int destwa = _clip_parni(ClipMachineMemory, 1); ClipVar *bfor = _clip_spar(ClipMachineMemory, 2); ClipVar *bwhile = _clip_spar(ClipMachineMemory, 3); int next = _clip_parni(ClipMachineMemory, 4); DBWorkArea *wa = cur_area(ClipMachineMemory); DBWorkArea *dwa; void *buf = NULL; ClipVar v, *vp; int cnt = 0, er; _clip_retni(ClipMachineMemory, 0); CHECKWA(wa); CHECKARG1(1, NUMERIC_type_of_ClipVarType); dwa = get_area(ClipMachineMemory, destwa, 0, 0); CHECKWA(dwa); CHECKOPT2(2, CCODE_type_of_ClipVarType, PCODE_type_of_ClipVarType); CHECKOPT2(3, CCODE_type_of_ClipVarType, PCODE_type_of_ClipVarType); CHECKOPT1(4, NUMERIC_type_of_ClipVarType); if (bfor && bfor->ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType == UNDEF_type_of_ClipVarType) bfor = NULL; if (bwhile && bwhile->ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType == UNDEF_type_of_ClipVarType) bwhile = NULL; buf = malloc(wa->rd->recsize); if ((er = _clip_flushbuffer(ClipMachineMemory, wa, __PROC__))) goto err; READLOCK; if (dwa->rd->vtbl->_wlock(ClipMachineMemory, dwa->rd, __PROC__)) goto err_unlock; while (!wa->rd->eof) { if (bwhile) { if ((er = rdd_calc(ClipMachineMemory, wa->rd->area, bwhile, &v, 0))) goto err_unlock; vp = _clip_vptr(&v); if (vp->ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType != LOGICAL_type_of_ClipVarType) { er = rdd_err(ClipMachineMemory, EG_SYNTAX, 0, __FILE__, __LINE__, __PROC__, er_badforexpr); goto err_unlock; } if (!vp->ClipLogVar_l_of_ClipVar.value_of_ClipLogVar) { _clip_destroy(ClipMachineMemory, &v); break; } _clip_destroy(ClipMachineMemory, &v); } if (bfor) { if ((er = rdd_calc(ClipMachineMemory, wa->rd->area, bfor, &v, 0))) goto err_unlock; vp = _clip_vptr(&v); if (vp->ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType != LOGICAL_type_of_ClipVarType) { er = rdd_err(ClipMachineMemory, EG_SYNTAX, 0, __FILE__, __LINE__, __PROC__, er_badforexpr); goto err_unlock; } if (!vp->ClipLogVar_l_of_ClipVar.value_of_ClipLogVar) { _clip_destroy(ClipMachineMemory, &v); if ((er = rdd_skip(ClipMachineMemory, wa->rd, 1, __PROC__))) goto err_unlock; continue; } _clip_destroy(ClipMachineMemory, &v); } if ((er = rdd_rawread(ClipMachineMemory, wa->rd, buf, __PROC__))) goto err_unlock; if ((er = rdd_rawwrite(ClipMachineMemory, dwa->rd, buf, 1, __PROC__))) goto err_unlock; if (++cnt >= next) break; if ((er = rdd_skip(ClipMachineMemory, wa->rd, 1, __PROC__))) goto err_unlock; } if (wa->rd->vtbl->_ulock(ClipMachineMemory, wa->rd, __PROC__)) goto err_unlock; if (dwa->rd->vtbl->_ulock(ClipMachineMemory, dwa->rd, __PROC__)) goto err; free(buf); _clip_retni(ClipMachineMemory, cnt); return 0; err_unlock: wa->rd->vtbl->_ulock(ClipMachineMemory, wa->rd, __PROC__); dwa->rd->vtbl->_ulock(ClipMachineMemory, dwa->rd, __PROC__); err: if (buf) free(buf); return er; }
bool Triangulate::triangulate(const Vector<Vector2> &contour,Vector<int> &result) { /* allocate and initialize list of Vertices in polygon */ int n = contour.size(); if ( n < 3 ) return false; int *V = (int*)alloca(sizeof(int)*n); /* we want a counter-clockwise polygon in V */ if ( 0.0f < get_area(contour) ) for (int v=0; v<n; v++) V[v] = v; else for(int v=0; v<n; v++) V[v] = (n-1)-v; int nv = n; /* remove nv-2 Vertices, creating 1 triangle every time */ int count = 2*nv; /* error detection */ for(int m=0, v=nv-1; nv>2; ) { /* if we loop, it is probably a non-simple polygon */ if (0 >= (count--)) { //** Triangulate: ERROR - probable bad polygon! return false; } /* three consecutive vertices in current polygon, <u,v,w> */ int u = v ; if (nv <= u) u = 0; /* previous */ v = u+1; if (nv <= v) v = 0; /* new v */ int w = v+1; if (nv <= w) w = 0; /* next */ if ( snip(contour,u,v,w,nv,V) ) { int a,b,c,s,t; /* true names of the vertices */ a = V[u]; b = V[v]; c = V[w]; /* output Triangle */ /* result.push_back( contour[a] ); result.push_back( contour[b] ); result.push_back( contour[c] ); */ result.push_back( a ); result.push_back( b ); result.push_back( c ); m++; /* remove v from remaining polygon */ for(s=v,t=v+1;t<nv;s++,t++) V[s] = V[t]; nv--; /* resest error detection counter */ count = 2*nv; } } return true; }