示例#1
0
文件: Rectangle.cpp 项目: ziz/solarus
/**
 * @brief Returns whether the specified point is inside this rectangle.
 * @param x x coordinate of the point
 * @param y y coordinate of the point
 * @return true if the point is in this rectangle
 */
bool Rectangle::contains(int x, int y) const {

  return x >= get_x() && x < get_x() + get_width() && y >= get_y() && y < get_y() + get_height();
}
示例#2
0
文件: XYZR.cpp 项目: AljGaber/imp
IMPCORE_BEGIN_NAMESPACE

void XYZR::show(std::ostream &out) const {
  out << "(" << get_x() << ", " << get_y() << ", " << get_z() << ": "
      << get_radius() << ")";
}
示例#3
0
void
update_enemies (void)
{

  int i;

  for (i = 0; i < NUM_ENEMIES; i++)
    {
      if (enemies[i].live == 1)
        {
          enemies[i].location.x += enemies[i].acceleration.x;
          enemies[i].location.y += enemies[i].acceleration.y;

          if (enemies[i].puller != NULL) //i.e., this enemy ship is being pulled
            {
              if (enemies[i].puller->live == 0) //The puller is dead; stop following him!
                {
                  enemies[i].acceleration = enemy_random_acceleration ();
                  

                }
            }
          
          //Unstuck enemies
          if(enemies[i].acceleration.x == 0 || enemies[i].acceleration.y == 0)
            {
              enemies[i].acceleration = enemy_random_acceleration ();
            }
          
          //Enemy ship x-axis alignment to the player ship:
          if (enemies[i].follow_player == 1)
            {
              if (enemies[i].location.x > get_x ())
                {
                  if (enemies[i].acceleration.x > 0)
                    enemies[i].acceleration.x *= -1; //Reverse acceleration.
                }
              else if (enemies[i].location.x < get_x ())
                {
                  if (enemies[i].acceleration.x < 0)
                    {
                      enemies[i].acceleration.x *= -1;
                    }
                }
              else if (enemies[i].location.x == get_x ())
                {
                  enemies[i].acceleration.x = 0;
                }
            }

          //Enemy ships can't leave the display
          if (enemies[i].location.x > SCREEN_W - ENEMY_W)
            {
              if (enemies[i].acceleration.x > 0)
                enemies[i].acceleration.x *= -1; //Reverse X acceleration
            }
          if (enemies[i].location.x < 0)
            {
              if (enemies[i].acceleration.x < 0)
                {
                  enemies[i].acceleration.x *= -1; //Reverse X acceleration
                }
            }
          //Enemy ships can't go too high or too close to the player ship
          if (enemies[i].location.y < 0 || enemies[i].location.y > ENEMY_Y_THRESHOLD)
            {
              enemies[i].acceleration.y *= -1; //Reverse Y acceleration.

            }

        }
      //Cleanup dead enemies
      if (enemies[i].health_pts <= 0)
        {
          enemies[i].live = 0;
        }
    }
}
示例#4
0
/**
 * @brief Moves the object.
 * @param dx number of pixels of the move on x
 * @param dy number of pixels of the move on y
 */
void Movement::translate_xy(int dx, int dy) {
  set_xy(get_x() + dx, get_y() + dy);
}
示例#5
0
static void train_estimated_velocity_update(int index, DisplayData *data, int velocity) {
    if (data->velocity == velocity) return;
    data->velocity = velocity;

    char command[128];
    char *pos = &command[0];

    pos += sprintf(pos, "\0337");
    int offset = strlen(ESTIMATED_SPEED_STRING);
    pos += sprintf(pos, "\033[%u;%uH", get_y(index, TRAIN_ESTIMATED_VELOCITY_HEIGHT), get_x(index) * TRAIN_COLUMN_WIDTH + 1 + offset);
    char velocity_buf[TRAIN_COLUMN_WIDTH];
    sprintf(velocity_buf, "%dum/tick", velocity);
    pos += sputw(pos, TRAIN_COLUMN_WRITABLE_WIDTH - offset, ' ', velocity_buf);
    pos += sprintf(pos, "\0338");

    Write(COM2, command, pos - command);
}
示例#6
0
/**
 * \brief Updates the position of the object controlled by this movement.
 *
 * This function is called repeatedly.
 */
void StraightMovement::update() {

  if (!is_suspended()) {
    uint32_t now = System::now();

    bool x_move_now = x_move != 0 && now >= next_move_date_x;
    bool y_move_now = y_move != 0 && now >= next_move_date_y;

    while (x_move_now || y_move_now) { // while it's time to move

      // save the current coordinates
      Rectangle old_xy(get_x(), get_y());

      if (x_move_now) {
        // it's time to make an x move

        if (y_move_now) {
          // but it's also time to make a y move

          if (next_move_date_x <= next_move_date_y) {
            // x move first
            update_x();
            if (now >= next_move_date_y) {
              update_y();
            }
          }
          else {
            // y move first
            update_y();
            if (now >= next_move_date_x) {
              update_x();
            }
          }
        }
        else {
          update_x();
        }
      }
      else {
        update_y();
      }

      if (!is_suspended() && get_entity() != NULL && !finished) {

        // the movement was successful if the entity's coordinates have changed
        // and the movement was not stopped
        bool success = (get_x() != old_xy.get_x() || get_y() != old_xy.get_y())
            && (x_move != 0 || y_move != 0);

        if (!success) {
          notify_obstacle_reached();
        }
      }

      now = System::now();

      if (!finished && max_distance != 0 && Geometry::get_distance(initial_xy.get_x(),
          initial_xy.get_y(), get_x(), get_y()) >= max_distance) {
        set_finished();
      }
      else {
        x_move_now = x_move != 0 && now >= next_move_date_x;
        y_move_now = y_move != 0 && now >= next_move_date_y;
      }
    }
  }

  // Do this at last so that Movement::update() knows whether we are finished.
  Movement::update();
}
示例#7
0
branch_obj *select_branching_object(lp_prob *p, int *cuts)
{
   LPdata *lp_data = p->lp_data;
   var_desc **vars;
   row_data *rows;
   int m;
#ifndef MAX_CHILDREN_NUM
   int maxnum;
   double *objval, *pobj;
   int *termcode, *pterm, *feasible, *pfeas, *iterd, *piter;
#ifdef COMPILE_FRAC_BRANCHING
   int *frnum, *pfrnum, **frind, **pfrind;
   double **frval, **pfrval;
#endif
#endif
   int i, j, k, branch_var, branch_row;
   double lb, ub, oldobjval;
   cut_data *cut;
   branch_obj *can, *best_can = NULL;
#ifdef COMPILE_FRAC_BRANCHING
   int *xind;
   double *xval;
#endif
   double *pseudo_costs_zero, *pseudo_costs_one;

   /* These are the return values from select_candidates_u() */
   int cand_num = 0, new_vars = 0;
   branch_obj **candidates = NULL;
#ifdef STATISTICS
   int itlim = 0, cnum = 0;
#endif

#if 0
   if (p->bc_level == 0){ 
      lp_data->pseudo_costs_zero = (double *) calloc(lp_data->n, DSIZE);
      lp_data->pseudo_costs_one  = (double *) calloc(lp_data->n, DSIZE);
#if 0
      memcpy((char *)pseudo_costs_one, (char *)lp_data->obj, lp_data->n*DSIZE);
      memcpy((char *)pseudo_costs_zero,(char *)lp_data->obj, lp_data->n*DSIZE);
#endif
   }
   
   pseudo_costs_one  = lp_data->pseudo_costs_one;
   pseudo_costs_zero = lp_data->pseudo_costs_zero;
#endif
   
   /*------------------------------------------------------------------------*\
    * First we call branch_u() to select candidates. It can
    * -- return with DO_BRANCH and a bunch of candidates, or
    * -- return with DO_NOT_BRANCH along with a bunch of violated cuts
    *    in the matrix and/or among the slack_cuts, or
    * -- return with DO_NOT_BRANCH__FATHOMED, i.e., the node can be fathomed.
   \*------------------------------------------------------------------------*/

   j = select_candidates_u(p, cuts, &new_vars, &cand_num, &candidates);
   switch (j){
    case DO_NOT_BRANCH__FATHOMED:
      *cuts = -1;
      return(NULL);

    case DO_NOT_BRANCH:
      if (cand_num)
	 *cuts += add_violated_slacks(p, cand_num, candidates);
#ifdef DO_TESTS
      if (*cuts == 0 && new_vars == 0){
	 printf("Told not to branch, but there are no cuts!\n");
	 exit(-1);
      }
#endif
      /* Free the candidates */
      if (candidates){
	 for (i=0; i<cand_num; i++){
	    free_candidate(candidates + i);
	 }
	 FREE(candidates);
      }
      return(NULL);

    case DO_BRANCH:
      break;
   }

   /* OK, now we have to branch. */

   /* First of all, send everything to the cutpool that hasn't been sent
      before and send the current node description to the TM. */
   p->comp_times.strong_branching += used_time(&p->tt);
#pragma omp critical(cut_pool)
   send_cuts_to_pool(p, -1);
   send_node_desc(p, NODE_BRANCHED_ON);
   p->comp_times.communication += used_time(&p->tt);

   /* Add all the branching cuts */
   if (p->par.branch_on_cuts)
      add_slacks_to_matrix(p, cand_num, candidates);
   m = lp_data->m;
   rows = lp_data->rows;

#ifndef MAX_CHILDREN_NUM
   /* The part below is not needed when we have MAX_CHILDREN_NUM specified */
   /* Count how many objval/termcode/feasible entry we might need
      and allocate space for it */
   for (maxnum = candidates[0]->child_num, j=0, i=1; i<cand_num; i++){
      if (maxnum < candidates[i]->child_num)
	 maxnum = candidates[i]->child_num;
   }

   objval   = (double *) malloc(maxnum * DSIZE);
   termcode = (int *) malloc(maxnum * ISIZE);
   feasible = (int *) malloc(maxnum * ISIZE);
   iterd    = (int *) malloc(maxnum * ISIZE);
#ifdef COMPILE_FRAC_BRANCHING
   frval = (double **) malloc(maxnum * sizeof(double *));
   pfrval = (double **) malloc(maxnum * sizeof(double *));
   frind = (int **) malloc(maxnum * sizeof(int *));
   pfrind = (int **) malloc(maxnum * sizeof(int *));
   frnum = (int *) malloc(maxnum * ISIZE);
   pfrnum = (int *) malloc(maxnum * ISIZE);
#endif
   pobj  = (double *) malloc(maxnum * DSIZE);
   pterm = (int *) malloc(maxnum * ISIZE);
   pfeas = (int *) malloc(maxnum * ISIZE);
   piter = (int *) malloc(maxnum * ISIZE);
#endif

   /* Set the iteration limit */
   if (p->par.max_presolve_iter > 0)
      set_itlim(lp_data, p->par.max_presolve_iter);

   vars = lp_data->vars;

   /* Look at the candidates one-by-one and presolve them. */
   oldobjval = lp_data->objval;
   for (i=0; i<cand_num; i++){

      can = candidates[i];
#ifndef MAX_CHILDREN_NUM
      can->objval = pobj;
      can->termcode = pterm;
      can->feasible = pfeas;
      can->iterd = piter;
#ifdef COMPILE_FRAC_BRANCHING
      can->frac_num = pfrnum;
      can->frac_ind = pfrind;
      can->frac_val = pfrval;
#endif
#endif
#ifdef STATISTICS
      cnum += can->child_num;
#endif

      /* Now depending on the type, adjust ub/lb or rhs/range/sense */
      switch (can->type){
       case CANDIDATE_VARIABLE:
	 branch_var = can->position;
	 if (lp_data->status[branch_var] & PERM_FIXED_TO_LB ||
	     lp_data->status[branch_var] & PERM_FIXED_TO_UB){
	    printf("Error -- candidate is fixed. Discarding.\n\n");
	    continue;
	 }
#if 0
	 if (pseudo_costs_one[can->position] ||
	     pseudo_costs_zero[can->position]){
	    can->objval[1] = oldobjval + (1 - lp_data->x[can->position]) *
	                                 pseudo_costs_one[can->position];
	    can->objval[0] = oldobjval + lp_data->x[can->position] *
	                                 pseudo_costs_zero[can->position];
	    break;
	 }
#endif 
	 lb = vars[branch_var]->lb;
	 ub = vars[branch_var]->ub;
	 for (j = 0; j < can->child_num; j++){
	    switch (can->sense[j]){
	     case 'E':
	       change_lbub(lp_data, branch_var, can->rhs[j], can->rhs[j]);
	       break;
	     case 'R':
	       change_lbub(lp_data, branch_var, can->rhs[j],
			   can->rhs[j] + can->range[j]);
	       break;
	     case 'L':
	       change_lbub(lp_data, branch_var, lb, can->rhs[j]);
	       break;
	     case 'G':
	       change_lbub(lp_data, branch_var, can->rhs[j], ub);
	       break;
	    }
	    check_ub(p);
	    /* The original basis is in lp_data->lpbas */
	    can->termcode[j] = dual_simplex(lp_data, can->iterd+j);
	    can->objval[j] = lp_data->objval;
	    if (can->termcode[j] == LP_OPTIMAL){
	       /* is_feasible_u() fills up lp_data->x, too!! */
	       if (is_feasible_u(p) == IP_FEASIBLE){
		  can->termcode[j] = LP_OPT_FEASIBLE;
		  /*NOTE: This is confusing but not all that citical...*/
		  /*The "feasible" field is only filled out for the
		    purposes of display (in vbctool) to keep track of
		    where in the tree the feasible solutions were
		    found. Since this may not be the actual candidate
		    branched on, we need to pass this info on to whatever
		    candidate does get branched on so the that the fact that
		    a feasible solution was found in presolve can be recorded*/
		  if (best_can)
		     best_can->feasible[j] = TRUE;
		  else
		     can->feasible[j] = TRUE;
	       }
	    }
#ifdef COMPILE_FRAC_BRANCHING
	    else
	       if (can->termcode[j] != LP_ABANDONED)
		  get_x(lp_data);
	    if (can->termcode[j] != LP_ABANDONED){
	       xind = lp_data->tmp.i1; /* n */
	       xval = lp_data->tmp.d; /* n */
	       can->frac_num[j] = collect_fractions(p, lp_data->x, xind, xval);
	       if (can->frac_num[j] > 0){
		  can->frac_ind[j] = (int *) malloc(can->frac_num[j] * ISIZE);
		  can->frac_val[j] = (double *) malloc(can->frac_num[j]*DSIZE);
		  memcpy(can->frac_ind[j], xind, can->frac_num[j] * ISIZE);
		  memcpy(can->frac_val[j], xval, can->frac_num[j] * DSIZE);
	       }
	    }else{
	       can->frac_num[j] = 0;
	    }
#endif
#ifdef STATISTICS
	    if (can->termcode[j] == LP_D_ITLIM)
	       itlim++;
#endif
	 }
	 change_lbub(lp_data, branch_var, lb, ub);
#if 0
	 pseudo_costs_one[can->position] =
	    (can->objval[1] - oldobjval)/lp_data->x[can->position];
	 pseudo_costs_zero[can->position] =
	    (can->objval[0] - oldobjval)/lp_data->x[can->position];
#endif
	 break;

       case CANDIDATE_CUT_IN_MATRIX:
	 branch_row = can->position;
	 for (j = 0; j < can->child_num; j++){
	    change_row(lp_data, branch_row,
		       can->sense[j], can->rhs[j], can->range[j]);
	    check_ub(p);
	    /* The original basis is in lp_data->lpbas */
	    can->termcode[j] = dual_simplex(lp_data, can->iterd+j);
	    can->objval[j] = lp_data->objval;
	    if (can->termcode[j] == LP_OPTIMAL){
	       /* is_feasible_u() fills up lp_data->x, too!! */
	       if (is_feasible_u(p) == IP_FEASIBLE){
		  can->termcode[j] = LP_OPT_FEASIBLE;
		  /*NOTE: This is confusing but not all that citical...*/
		  /*The "feasible" field is only filled out for the
		    purposes of display (in vbctool) to keep track of
		    where in the tree the feasible solutions were
		    found. Since this may not be the actual candidate
		    branched on, we need to pass this info on to whatever
		    candidate does get branched on so the that the fact that
		    a feasible solution was found in presolve can be recorded*/
		  if (best_can)
		     best_can->feasible[j] = TRUE;
		  else
		     can->feasible[j] = TRUE;
	       }
	    }
#ifdef COMPILE_FRAC_BRANCHING
	    else
	       if (can->termcode[j] != LP_ABANDONED)
		  get_x(lp_data);
	    if (can->termcode[j] != LP_ABANDONED){
	       xind = lp_data->tmp.i1; /* n */
	       xval = lp_data->tmp.d; /* n */
	       can->frac_num[j] = collect_fractions(p, lp_data->x, xind, xval);
	       if (can->frac_num[j] > 0){
		  can->frac_ind[j] = (int *) malloc(can->frac_num[j] * ISIZE);
		  can->frac_val[j] = (double *) malloc(can->frac_num[j]*DSIZE);
		  memcpy(can->frac_ind[j], xind, can->frac_num[j] * ISIZE);
		  memcpy(can->frac_val[j], xval, can->frac_num[j] * DSIZE);
	       }
	    }else{
	       can->frac_num[j] = 0;
	    }
#endif
#ifdef STATISTICS
	    if (can->termcode[j] == LP_D_ITLIM)
	       itlim++;
#endif
	 }
	 cut = rows[branch_row].cut;
	 change_row(lp_data, branch_row, cut->sense, cut->rhs, cut->range);
	 free_row_set(lp_data, 1, &branch_row);
	 break;
      }

      switch ((j = compare_candidates_u(p, oldobjval, best_can, can))){
       case FIRST_CANDIDATE_BETTER:
       case FIRST_CANDIDATE_BETTER_AND_BRANCH_ON_IT:
	 free_candidate(candidates + i);
	 break;
       case SECOND_CANDIDATE_BETTER:
       case SECOND_CANDIDATE_BETTER_AND_BRANCH_ON_IT:
#ifndef MAX_CHILDREN_NUM
	 if (best_can == NULL){
	    pobj  = objval;
	    pterm = termcode;
	    pfeas = feasible;
	    piter = iterd;
#ifdef COMPILE_FRAC_BRANCHING
	    pfrnum = frnum;
	    pfrind = frind;
	    pfrval = frval;
#endif
	 }else{
	    pobj  = best_can->objval;
	    pterm = best_can->termcode;
	    pfeas = best_can->feasible;
	    piter = best_can->iterd;
#ifdef COMPILE_FRAC_BRANCHING
	    pfrnum = best_can->frac_num;
	    pfrind = best_can->frac_ind;
	    pfrval = best_can->frac_val;
#endif
	 }
#endif
	 if (best_can){
	    for (k = can->child_num - 1; k >= 0; k--){
	       /* Again, this is only for tracking that there was a feasible
		  solution discovered in presolve for display purposes */
	       if (best_can->feasible[k])
		  can->feasible[k] = TRUE;
	    }
	    free_candidate(&best_can);
	 }
	 best_can = can;
	 candidates[i] = NULL;
	 break;
      }
      if ((j & BRANCH_ON_IT))
	 break;
   }

#ifndef MAX_CHILDREN_NUM
   FREE(pobj); FREE(pterm); FREE(pfeas); FREE(piter);
#  ifdef COMPILE_FRAC_BRANCHING
   FREE(pfrnum); FREE(pfrind); FREE(pfrval);
#  endif
#endif

   if (p->par.max_presolve_iter > 0)
      set_itlim(lp_data, -1);

#ifdef STATISTICS
   PRINT(p->par.verbosity, 5,
	 ("Itlim reached %i times out of %i .\n\n", itlim, cnum));
#endif

   for (i++; i<cand_num; i++){
      /* Free the remaining candidates */
      free_candidate(candidates + i);
   }
   FREE(candidates);

   return(best_can);
}
示例#8
0
void gaming_print_map(int y,int x)
{
    gotoxy(get_x(x),get_y(y) );
	printf("%s",get_shape(map[y][x]));
}
示例#9
0
const double Point::operator[](int x)
{
    if(x==0)
        return get_x();
    return get_y();
}
示例#10
0
int infoGuanacosPatch(){

	add_guanacospatch_message(get_x(), get_y(), get_adultos(), get_season());

	return 0;
}
示例#11
0
Vector
Surface::get_position() const
{
  return Vector(get_x(), get_y()); 
}
示例#12
0
 inline F64 get_x() const {
     return get_x(point.get_X());
 };
示例#13
0
			inline bool is_inside(const Uint16 x, const Uint16 y)
			{
				return (x >= get_x()) && (y >= get_y()) &&
					(x < (get_x() + get_width())) &&
					(y< (get_y() + get_height()));
			}
示例#14
0
double vert(coordinate d, double f, double R, double t, double r, double g){
    double s;
    double tmp;
    double rt = R-t;    //안쪽 반지름
    char st;    //첫 gap(삼각형일때)
    
    double tx1, tx2, ty1, ty2;  //임시변수
    double th;  //각도
    double savedx = d.x;
    
    s = 0;
    st = 1;
    
    while(d.x*d.x + d.y*d.y < rt*rt){
        if((d.y+g)*(d.y+g)+(d.x+g)*(d.x+g) > rt*rt){
            if((d.x+g)*(d.x+g)+d.y*d.y > rt*rt){
                if(st){
                    tx1 = get_x(d.y, rt);
                    ty1 = rt / sqrt(2);
                    tx2 = get_x(ty1, rt);
                    th = get_theta(tx1, d.y, tx2, ty1, rt);
                    tmp = ((ty1 - d.y)*(tx1 - d.x) / 2.0); // 삼각형 면적
                    tmp += area_arc(th, rt);
                    st = 0;
                }else{
                    if((d.y+g)*(d.y+g)+d.x*d.x > rt*rt){
                        tx1 = get_x(d.y, rt);
                        ty1 = get_y(d.x, rt);
                        th = get_theta(tx1, d.y, d.x, ty1, rt);
                        tmp = (tx1-d.x)*(ty1-d.y)/2 + area_arc(th, rt);
                    }else{
                        double a1, a2;
                        tx1 = get_x(d.y, rt);
                        a1 = (tx1-d.x)*g/2.0;
                        tx2 = get_x(d.y+g, rt);
                        a2 = (tx2-d.x)*g/2.0;
                        tmp = a1+a2;
                        th = get_theta(tx1, d.y, tx2, d.y+g, rt);
                        tmp += area_arc(th, rt);
                    }
                }
            }else{
                if(st){
                    double a1, a2, a3;
                    tx1 = d.x+g;
                    ty2 = rt/sqrt(2.0);
                    tx2 = get_x(ty2, rt);
                    ty1 = get_y(tx1, rt);
                    a1 = (tx2 - d.x)*(ty2-d.y)/2.0;
                    a2 = (ty1-d.y)*(tx1-tx2);
                    a3 = (ty2-ty1)*(tx1-tx2)/2.0;
                    th = get_theta(tx1, ty1, tx2, ty2, rt);
                    tmp = a1+a2+a3+area_arc(th, rt);
                    st = 0;
                }else{
                    double a1, a2, a3;
                    tx1 = d.x+g;
                    ty1 = get_y(tx1, rt);
                    ty2 = d.y+g;
                    tx2 = get_x(ty2, rt);
                    a1 = (tx2-d.x)*g;
                    a2 = (ty1-d.y)*(d.x+g-tx2);
                    a3 = (ty2-ty1)*(tx1-tx2)/2.0;
                    th = get_theta(tx1, ty1, tx2, ty2, rt);
                    tmp = a1+a2+a3+area_arc(th, rt);
                }
            }
        } else{
            if(st){
                tmp = g*g/2.0;
                st = 0;
            }else{
                tmp = g*g;
            }
        }
        
        d.x += g+2*r;
        s += tmp;
    }
    
    d.x = savedx;
    return s;
}
示例#15
0
文件: game.c 项目: H3lly/rush-hour
bool game_over_hr(cgame g) {
    return (get_x(g->piece_list[0])==4) && (get_y(g->piece_list[0])==3);
}
int VWindowGUI::translation_event()
{
	mwindow->session->vwindow_x = get_x();
	mwindow->session->vwindow_y = get_y();
	return 0;
}
示例#17
0
文件: game.c 项目: H3lly/rush-hour
// @brief Check if the piece p is out of the grid of the game g.
bool out_of_grid(cpiece p, cgame g) {
    //used only once but enhances readibility
    return (get_x(p)<0||get_x(p)+get_width(p)>game_width(g)||(get_y(p)<0||get_y(p)+get_height(p)>game_height(g)));
}
示例#18
0
文件: bounds.c 项目: kbranigan/tubes
int main(int argc, char ** argv)
{
	if (stdout_is_piped()) // other wise you don't see the seg fault
		setup_segfault_handling(argv);
	
	assert_stdin_is_piped();
	//assert_stdout_is_piped();
	//assert_stdin_or_out_is_piped();
	
	static char clamp_bbox_char[1000] = "";
	static int debug = 0;
	static double clamp_bbox[4] = {-FLT_MAX, -FLT_MAX, FLT_MAX, FLT_MAX};
	
	int c;
	while (1) {
		static struct option long_options[] = {
			{"bbox", required_argument, 0, 'b'},
			{"debug", no_argument, &debug, 1},
			{0, 0, 0, 0}
		};
		
		int option_index = 0;
		c = getopt_long(argc, argv, "b:", long_options, &option_index);
		if (c == -1) break;
		
		switch (c) {
			case 0: break;
			case 'b': strncpy(clamp_bbox_char, optarg, sizeof(clamp_bbox_char)); break;
			default: abort();
		}
	}
	
	if (clamp_bbox_char[0] != 0) {
		char * ptr = strtok(clamp_bbox_char, " ,");
		if (ptr == NULL) fprintf(stderr, "ERROR: Usage: %s --bbox=\"0,0,1,1\"	(min_x,max_x,min_y,max_y)", argv[0]);
		clamp_bbox[0] = atof(ptr);
		ptr = strtok(NULL, " ,");
		if (ptr == NULL) fprintf(stderr, "ERROR: Usage: %s --bbox=\"0,0,1,1\"	(min_x,min_y,max_x,max_y)", argv[0]);
		clamp_bbox[1] = atof(ptr);
		ptr = strtok(NULL, " ,");
		if (ptr == NULL) fprintf(stderr, "ERROR: Usage: %s --bbox=\"0,0,1,1\"	(min_x,min_y,max_x,max_y)", argv[0]);
		clamp_bbox[2] = atof(ptr);
		ptr = strtok(NULL, " ,");
		if (ptr == NULL) fprintf(stderr, "ERROR: Usage: %s --bbox=\"0,0,1,1\"	(min_x,min_y,max_x,max_y)", argv[0]);
		clamp_bbox[3] = atof(ptr);
		
		fprintf(stderr, "clamp x,y to: {%f,%f,%f,%f}\n", clamp_bbox[0], clamp_bbox[1], clamp_bbox[2], clamp_bbox[3]);
	}
	
	struct Block * block = NULL;
	while ((block = read_block(stdin))) {
		
		if (clamp_bbox_char[0] != 0) {
			block = add_command(block, argc, argv);
		}
		
		double bbox[2][2] = {{FLT_MAX, -FLT_MAX}, {FLT_MAX, -FLT_MAX}};
		
		int i;
		for (i = 0 ; i < block->num_rows ; i++) {
			double x = get_x(block, i);
			double y = get_y(block, i);
			
			if (x < bbox[0][0]) bbox[0][0] = x; if (x > bbox[0][1]) bbox[0][1] = x;
			if (y < bbox[1][0]) bbox[1][0] = y; if (y > bbox[1][1]) bbox[1][1] = y;
		}
		
		if (clamp_bbox_char[0] != 0) {
			double dx = clamp_bbox[0] - clamp_bbox[2];
			double dy = clamp_bbox[1] - clamp_bbox[3];
			for (i = 0 ; i < block->num_rows ; i++) {
				double x = get_x(block, i);
				double y = get_y(block, i);
				//fprintf(stderr, "%f inside %f,%f (%f), dx = %f\n", x, bbox[0][0], bbox[0][1], ((x-bbox[0][0])/(bbox[0][1]-bbox[0][0])), dx);
				//fprintf(stderr, "%f,%f\n", x, y);
				set_xy(block, i, ((x-bbox[0][0])/(bbox[0][1]-bbox[0][0]))*dx+clamp_bbox[0], ((y-bbox[1][0])/(bbox[1][1]-bbox[1][0]))*dy+clamp_bbox[1]);
				x = get_x(block, i);
				y = get_y(block, i);
				//fprintf(stderr, "becomes %f,%f\n", x, y);
			}
		} else {
		
			long * offsets = alloca(sizeof(long)*block->num_columns);
			memset(offsets, 0, sizeof(long)*block->num_columns);
			
			int i,j;
			for (i = 0 ; i < block->num_columns ; i++)
				offsets[i] = get_cell(block, 0, i) - get_row(block, 0);
			
			for (i = 0 ; i < block->num_columns ; i++)
			{
				struct Column * column = get_column(block, i);
				if (column->type == TYPE_INT && column->bsize == 4)
				{
					int min = *(int*)(get_row(block, 0)+offsets[i]);
					int max = min;
					for (j = 0 ; j < block->num_rows ; j++)
					{
						void * row = get_row(block, j);
						int value = *(int*)(row+offsets[i]);
						if (value > max) max = value;
						if (value < min) min = value;
					}
					fprintf(stderr, "%s: %d to %d\n", column_get_name(column), min, max);
				}
				else if (column->type == TYPE_INT && column->bsize == 8)
				{
					long min = *(long*)(get_row(block, 0)+offsets[i]);
					long max = min;
					for (j = 0 ; j < block->num_rows ; j++)
					{
						void * row = get_row(block, j);
						long value = *(long*)(row+offsets[i]);
						if (value > max) max = value;
						if (value < min) min = value;
					}
					fprintf(stderr, "%s: %ld to %ld\n", column_get_name(column), min, max);
				}
				else if (column->type == TYPE_FLOAT && column->bsize == 4)
				{
					float min = *(float*)(get_row(block, 0)+offsets[i]);
					float max = min;
					for (j = 0 ; j < block->num_rows ; j++)
					{
						void * row = get_row(block, j);
						float value = *(float*)(row+offsets[i]);
						if (value > max) max = value;
						if (value < min) min = value;
					}
					fprintf(stderr, "%s: %f to %f\n", column_get_name(column), min, max);
				}
				else if (column->type == TYPE_FLOAT && column->bsize == 8)
				{
					double min = *(double*)(get_row(block, 0)+offsets[i]);
					double max = min;
					for (j = 0 ; j < block->num_rows ; j++)
					{
						void * row = get_row(block, j);
						double value = *(double*)(row+offsets[i]);
						if (value > max) max = value;
						if (value < min) min = value;
					}
					fprintf(stderr, "%s: %lf to %lf\n", column_get_name(column), min, max);
				}
				else if (column->type == TYPE_CHAR)
				{
					int max = 0, count = 0;
					for (j = 0 ; j < block->num_rows ; j++)
					{
						void * row = get_row(block, j);
						int value = strlen((char*)(row+offsets[i]));
						if (value > max) { max = value; count = 1; }
						else if (value == max) count++;
					}
					fprintf(stderr, "%s: max strlen = %d (field size is %d), %d rows at that length\n", column_get_name(column), max, column->bsize, count);
				}
				else
					fprintf(stderr, "doesn't do %s %d\n", column_get_name(column), column->type);
			}
		}
		
		if (stdout_is_piped()) {
			write_block(stdout, block);
		}
		
		free_block(block);
	}
}
示例#19
0
文件: active.cpp 项目: mattl/anaconda
int Active::get_action_x()
{
    return get_x() + action_x;
}
示例#20
0
文件: utils.cpp 项目: tedher/aztecc
// FUNCTION : generate a public key
//
// Input : username, 
//         a4, a6 -> elliptic curve constants
//         xp, yp -> point's coordinate
//				 prime field
//         passphrase
// Output : file username.pkf which contains all
//          of those information
// 
// AUTHOR : TH <*****@*****.**>, Jan 2000
//
void gen_pubkey(const char* pkfilename, int blocksize)
{
	// declaration of variables
	char username[MAX];
	point P,H;
	bigmod a4,a6,xp,yp;
	bigint xdp,ydp,q;

	banner();
	cout<<"Before you can use encryption/decryption you must generate your public key.";
	cout<<"\nThe following process will guide you through generating your public key.";
	cout<<"\n\nTo achieve a cryptographically secure elliptic curve cryptosystem, you must ";
	cout<<"\nsupply a relatively big prime finite field (q), a good a, b";
	cout<<"\nfor elliptic curve equation and a point that lies on the curve.";

	//get EC parameters from user
	cout<<"\n\nGENERATE PUBLIC KEY\n";
	cout<<"-------------------";
	cout<<"\nPlease enter your user name : ";cin>>username;
		
	get_ecparm(a4,a6,xp,yp,q);
	
	// EC initialization
	P.init_curve(a4,a6);
	P.set_point(xp,yp);

	if (pkfilename==" ")
		pkfilename=PKFILENAME;

	// open public key file
	FILE* pkfile;
	pkfile=fopen(pkfilename,"a+");
	if(!pkfile)
	{
		cout<<"\nAZTECC ERROR : Error writing file ["<<pkfilename<<"]"<<endl;
		exit(1);
	}
	
	bigint d;
	get_passphrase(d,blocksize,username);
	
	// multiply the private key with EC point
	mul_point(H,d,P);
	
	// compute hash(d)
	char* sd=new char[MAX];
	bigint_to_string(d,sd);
	char* hash_d=new char[MAX];
	hash_d=MD5_hex_digest(sd);
	
	// convert the EC coordinate to string
	get_x(xdp,H);
	char* sxdp=new char[MAX];
	bigint_to_string(xdp,sxdp);
	get_y(ydp,H);
	char* sydp=new char[MAX];
	bigint_to_string(ydp,sydp);

	// convert a4, a6, xp, yp to string
	char* sa4=new char[MAX];
	bigmod_to_string(a4,sa4);
	char* sa6=new char[MAX];
	bigmod_to_string(a6,sa6);
	char* sxp=new char[MAX];
	bigmod_to_string(xp,sxp);
	char* syp=new char[MAX];
	bigmod_to_string(yp,syp);
	char* sq=new char[MAX];
	bigint_to_string(q,sq);
	
	// save all the info to public key file
   fputc('\n',pkfile);
	fprintf(pkfile,"%s#%s#%s#%s#%s#%s#%s#%s#%s",username,hash_d,sa4,sa6,sxp,syp,sxdp,sydp,sq);
	fclose(pkfile);
	cout<<"\nDone saving your public key to ["<<pkfilename<<"]"<<endl;

	//cleaning up
	delete[] sd;
	delete[] sxdp;
	delete[] sydp;
	delete[] sa4;
	delete[] sa6;
	delete[] sxp;
	delete[] syp;
	delete[] sq;
}
示例#21
0
/**
 * @brief Sets the y position of the object controlled by this movement.
 * @param y the new y position
 */
void Movement::set_y(int y) {
  set_xy(get_x(), y);
}
示例#22
0
//---------------------------------------------------------------------------
int uv_widget::get_absolute_x()
{
    if(myparent)
        return (myparent->get_absolute_x()+get_x());
    return 0;
};
示例#23
0
void update_map() {
	static U8 ready=FALSE;
	static int last_pos_x = 0;
	static int last_pos_y = 0;
	//Stores the average value of walls
	static int count_front_walls = 0;
	static int count_left_walls = 0;
	static int count_right_walls = 0;

	// If not ready (not enough inside the cell), return
	if(!ready) {
		if(is_inside_square(get_realX(),get_realY(),MAPPING_RES)) ready=TRUE;
		return;
	}

	int pos_x = get_x();
	int pos_y = get_y();
	// If out of the map, return
	if (is_out_of_map(pos_x,pos_y)) return;
	U8 data;

	// If just enter in a new cell
	if ( ( last_pos_y != pos_y ) || ( last_pos_x != pos_x ) ) {
		count_front_walls = 0;
		count_left_walls = 0;
		count_right_walls = 0;
		ready=FALSE;

		if(pos_x<__min_x) __min_x=pos_x;
		else if(pos_x>__max_x) __max_x=pos_x;
		if(pos_y<__min_y) __min_y=pos_y;
		else if(pos_y>__max_y) __max_y=pos_y;

		int direction = direction_of_next_cell(pos_x,pos_y,last_pos_x,last_pos_y);
		last_pos_x = pos_x;
		last_pos_y = pos_y;

		coord_to_table_index(&pos_x,&pos_y);
		data = _map[pos_x][pos_y];

		if(direction != NO_CARD) {
			set_wall_state(&data, direction, NO_WALL);
			_map[pos_x][pos_y]=data;
		}

		return;
	}
	else {
		coord_to_table_index(&pos_x,&pos_y);
		data = _map[pos_x][pos_y];
	}

	int cardinal_point = get_cardinal_point();
	// Do measurements only if in a good direction
	if(is_cp(cardinal_point)) {
		int left_wall = detect_wall(get_distanceL());
		int right_wall = detect_wall(get_distanceR());
		int front_wall = detect_wall(get_distanceF());

		//Add plus one for is wall and substract one for no wall
		count_front_walls = front_wall ? count_front_walls + 1 : count_front_walls - 1;
		count_left_walls = left_wall ? count_left_walls + 1 : count_left_walls - 1;
		count_right_walls = right_wall ? count_right_walls + 1 : count_right_walls - 1;

		if(count_front_walls>0) set_wall_state(&data, cardinal_point, IS_WALL);
		else set_wall_state(&data, cardinal_point, NO_WALL);

		if(count_right_walls>0) set_wall_state(&data, next_cp(cardinal_point), IS_WALL);
		else set_wall_state(&data, next_cp(cardinal_point), NO_WALL);

		if(count_left_walls>0) set_wall_state(&data, previous_cp(cardinal_point), IS_WALL);
		else set_wall_state(&data, previous_cp(cardinal_point), NO_WALL);
	}

	_map[pos_x][pos_y]=data;
}
示例#24
0
void recurssive_define_paths(adjacency_t *adj, int *allowed, int *traversed,
    int pos, int size, int offset, int prev)
{
    int x, y, top, right, bottom, left, i; 
    int top_left, top_right, bot_left, bot_right;
    int check_top, check_right, check_bot, check_left;
    int can_move = 1;
    int direction[] = {NORTH, EAST, SOUTH, WEST};
    check_top = check_right = check_bot = check_left = 1;
    x = get_x(pos, offset);
    y = get_y(pos, offset);

    if(check_out_of_bounds(x, y, offset, offset))
    {
        return;
    }

    if(traversed[pos] == 1)
    {
        return;
    }

    top = pos + 1;
    bottom = pos - 1;
    left = pos - offset;
    right = pos + offset;
    top_left = pos + 1 - offset;
    top_right = pos + 1 + offset;
    bot_left = pos - 1 - offset;
    bot_right = pos - 1 + offset;

    if(y == offset - 1)
    {
        // upper most cell .`. dont check top
        check_top = 0;
        check_right = 0;
    }
    if(y == 0)
    {
        // lowest most cell .`. dont check bottom
        check_bot = 0;
        check_left = 0;
    }
    if(x == 0)
    {
        // closest cell .`. don't check left
        check_top = 0;
        check_left = 0;
    }
    if(x == offset - 1)
    {
        //furthest most cell .`. don't check right
        check_bot = 0;
        check_right = 0;
    }

    if(check_top)
    {
        check_valid_move(top, top_left, left, allowed, &can_move);
    }
    if(check_right)
    {
        check_valid_move(right, top_right, top, allowed, &can_move);
    }
    if(check_bot)
    {
        check_valid_move(bottom, bot_right, right, allowed, &can_move);
    }
    if(check_left)
    {
        check_valid_move(left, bot_left, bottom, allowed, &can_move);
    }

    allowed[pos] = can_move;
    traversed[pos] = 1;

    shuffle_array(direction, 4, prev);
    for(i=0; i<4; i++)
    {
        switch (direction[i])
        {
        case 0:
            recurssive_define_paths(adj, allowed, traversed, top, size, offset, SOUTH);
            break;
        case 1:
            recurssive_define_paths(adj, allowed, traversed, right, size, offset, WEST);
            break;
        case 2:
            recurssive_define_paths(adj, allowed, traversed, bottom, size, offset, NORTH);
            break;
        case 3:
            recurssive_define_paths(adj, allowed, traversed, left, size, offset, EAST);
            break;
        }
    }

}
示例#25
0
文件: Enemy.cpp 项目: j4b0l/solarus
/**
 * \brief Updates the enemy.
 */
void Enemy::update() {

  Detector::update();

  if (is_suspended() || !is_enabled()) {
    return;
  }

  uint32_t now = System::now();

  if (being_hurt) {

    // see if we should stop the animation "hurt"
    if (now >= stop_hurt_date) {
      being_hurt = false;
      set_movement_events_enabled(true);

      if (life <= 0) {
        kill();
      }
      else if (is_immobilized()) {
        clear_movement();
        set_animation("immobilized");
        notify_immobilized();
      }
      else {
        clear_movement();
        restart();
      }
    }
  }

  if (life > 0 && invulnerable && now >= vulnerable_again_date && !being_hurt) {
    invulnerable = false;
  }

  if (life > 0 && !can_attack && !is_immobilized()
      && can_attack_again_date != 0 && now >= can_attack_again_date) {
    can_attack = true;
  }

  if (is_immobilized() && !is_killed() && now >= end_shaking_date &&
      get_sprite().get_current_animation() == "shaking") {

    restart();
  }

  if (is_immobilized() && !is_killed() && !is_being_hurt() && now >= start_shaking_date &&
      get_sprite().get_current_animation() != "shaking") {

    end_shaking_date = now + 2000;
    set_animation("shaking");
  }

  if (exploding) {
    uint32_t now = System::now();
    if (now >= next_explosion_date) {

      // create an explosion
      Rectangle xy;
      xy.set_x(get_top_left_x() + Random::get_number(get_width()));
      xy.set_y(get_top_left_y() + Random::get_number(get_height()));
      get_entities().add_entity(new Explosion("", LAYER_HIGH, xy, false));
      Sound::play("explosion");

      next_explosion_date = now + 200;
      nb_explosions++;

      if (nb_explosions >= 15) {
        exploding = false;
      }
    }
  }

  if (is_killed() && is_dying_animation_finished()) {

    // Create the pickable treasure if any.
    get_entities().add_entity(Pickable::create(get_game(),
        "", get_layer(), get_x(), get_y(),
        treasure, FALLING_HIGH, false));

    // Remove the enemy.
    remove_from_map();

    // Notify Lua that this enemy is dead.
    // We need to do this after remove_from_map() so that this enemy is
    // considered dead in functions like map:has_entities(prefix).
    notify_dead();
  }

  get_lua_context().entity_on_update(*this);
}
bool TGLobject_FX_explosion2::cycle(VirtualController *k,class TGLmap *map,GLTManager *GLTM,SFXManager *SFXM,int sfx_volume)
{
	// Wave
	if (m_cycle==0) {
		map->insert_auxiliary_front_object(new TGLobject_FX_particle(get_x(),get_y(),0,0,0,0,false,
										0.5f,0.5f,
										0.5f,0.5f,
										1,1,
										1,0,m_maxsize/512.0f,m_maxsize/32.0f,m_duration,GLTM->get("objects/ripple-back")));
		map->add_auxiliary_front_object(new TGLobject_FX_particle(get_x(),get_y(),0,0,0,0,false,
										0.5f,0.5f,
										0.5f,0.5f,
										1,1,
										1,0,m_maxsize/512.0f,m_maxsize/32.0f,m_duration,GLTM->get("objects/ripple-front")));
	} // if 

	// fire:
	{
		int i;
		int range=100;
		range=int(m_maxsize/16);
		if (range<1) range=1;
		for(i=0;i<(m_duration-m_cycle*4);i+=8) {
			int r=rand()%range;
			int a=rand()%360;
			if ((rand()%128)==0) {
				map->insert_auxiliary_front_object(new TGLobject_FX_particle(get_x(),get_y(),rand()%360,float(r*cos_degree(a))/16,float(r*sin_degree(a))/16,4,true,
																		 0.5f,0.5f,
																		 0.5f,0.5f,
																		 0.5f,0.5f,
																		 1,0,0.25f,0.35f,m_duration/2,GLTM->get("objects/explosion")));
			} else {
				if (r<range/2) {
					map->add_auxiliary_front_object(new TGLobject_FX_particle(get_x(),get_y(),rand()%360,float(r*cos_degree(a))/32,float(r*sin_degree(a))/32,4,false,
																			 1,1,
																			 1,1,
																			 1,1,
																			 1,0,0.25f,0.35f,m_duration/4,GLTM->get("objects/explosion")));
				} else {
					map->insert_auxiliary_front_object(new TGLobject_FX_particle(get_x(),get_y(),rand()%360,float(r*cos_degree(a))/32,float(r*sin_degree(a))/32,4,false,
																			 0.5f,0.5f,
																			 0.5f,0.5f,
																			 1,1,
																			 1,0,0.25f,0.35f,m_duration/4,GLTM->get("objects/explosion")));
				} // if 
			} // if 
		} // for
	}

	// smoke:
	// ...

	// particles:
	if (m_cycle==0) {
		int i;
		int range=100;
		range=int(m_maxsize);
		if (range<1) range=1;
		for(i=0;i<m_duration/2;i++) map->add_auxiliary_back_object(new TGLobject_FX_particle(get_x(),get_y(),rand()%60,float((rand()%(range*2+1))-range),float((rand()%(range*2+1))-range),4,true,0.5f,0.5f,0.5f,0.5f,1,1,1.0f,0,0.25f,0.25f,m_duration,GLTM->get("objects/particle1")));
	} // if

	m_cycle++;
	if (m_cycle>m_duration) return false;
	return true;
} /* TGLobject_FX_explosion2::cycle */ 
示例#27
0
/*
 *--------------------------------------------------------------------------------------
 *       Class:  Point
 *      Method:  set_y
 *--------------------------------------------------------------------------------------
 */
void Point::set_y ( uint64_t value ) {
    set_xy( get_x(), value ); // there may be faster ways of doing this
}		/* -----  end of method Point::set_y  ----- */
示例#28
0
int ChannelEditWindow::translation_event()
{
	channel_picker->mwindow->session->channels_x = get_x();
	channel_picker->mwindow->session->channels_y = get_y();
	return 0;
}
示例#29
0
void Score::draw()
{
	if(score_img!=NULL)
		SDLW::draw_surf(score_img, Engine::get_buffer(),(int)get_x(),(int)get_y());
}
示例#30
0
文件: Rectangle.cpp 项目: ziz/solarus
/**
 * @brief Returns the center point of this rectangle
 * @return the center point (represented as a zero-sized rectangle)
 */
Rectangle Rectangle::get_center() {

  return Rectangle(get_x() + get_width() / 2, get_y() + get_height() / 2);
}