void rotate_form(Form * form, float angle) {
 /** Rotate an form from angles degrees around his @center.
   ********************************************************/

  check_form(form);

  uint32_t c;

  for (c = 0; c < form->count; c++) {
    Pixel px, cur;

    cur.x = form->coords.x[c];
    cur.y = form->coords.y[c];

    px = rotate(form->center, angle, cur);

    form->coords.x[c] = px.x;
    form->coords.y[c] = px.y;

  }

  form->orientation = ((form->orientation + angle) >= 360.0f) ? form->orientation - 360.0f + angle : form->orientation + angle;

  return;
}
void translate_form(Form * form, float x, float y) {
 /** Translate a Form from (x, y) pixels .
   ***************************************/

  check_form(form);

  uint32_t c;

  for (c = 0; c < form->count; c++) {
    Pixel px, cur;

    cur.x = form->coords.x[c];
    cur.y = form->coords.y[c];

    px = translate(cur, x, y);

    form->coords.x[c] = px.x;
    form->coords.y[c] = px.y;

  }



  form->center.x = form->center.x + x;
  form->center.y = form->center.y + y;

  return;
}
void scale_form(Form * form, float factor) {
 /** Scale an Form from factor factor.
   * if factor > 1.0 the size of the form increase.
   * if factor < 1.0 the size from the form decrease.
   **************************************************/

  check_form(form);

  uint32_t c;

  for (c = 0; c < form->count; c++) {
    Pixel px, cur;

    cur.x = form->coords.x[c];
    cur.y = form->coords.y[c];

    px = scale(form->center, factor, cur);

    form->coords.x[c] = px.x;
    form->coords.y[c] = px.y;

  }

  form->length *= factor;
  form->real_length *= factor;  // ???

  return;
}
Пример #4
0
int	get_tetrimino_info(int fd, char *file, t_tetrimino **tetr)
{
  int	width;
  int	height;
  int	color;
  char	**form;

  form = NULL;
  if (tetri_in_list(tetr) == -1)
    return (-1);
  if ((width = get_width(fd)) == -1 ||
      (height = get_height(fd)) == -1 ||
      (color = get_color(fd)) == -1 ||
      check_form(fd, width, height, &form) == -1)
    (*tetr)->error = 1;
  else
    {
      (*tetr)->width = width;
      (*tetr)->height = height;
      (*tetr)->form = form;
      (*tetr)->color = color;
      (*tetr)->error = 0;
    }
  (*tetr)->name = get_name(file);
  return (0);
}
void mirror_form(Form * form, Pixel center, char axes) {
 /** Mirror an Form through the axes axes ['X'|'Y'].
   *
   * Your form must be absolute entire on a side of the defined center.
   *
   * No points must be over the center.x value if argument axes is 'X'.
   *
   * No points must be over the center.y value if argument axes is 'Y'.
   *
   * Else the result will be undefined.
   ********************************************************************/


  check_form(form);



  switch (axes) {

    case 'X':
      break;

    case 'Y':
      break;

    default:
      fprintf(stderr, "Wrong axe argument: 'X' or 'Y'\n");
      exit(EXIT_FAILURE);
  }

  uint32_t c;

  for (c = 0; c < form->count; c++) {
    Pixel px, cur;

    cur.x = form->coords.x[c];
    cur.y = form->coords.y[c];

    px = mirror(cur, center, axes);

    form->coords.x[c] = px.x;
    form->coords.y[c] = px.y;

  }

  Pixel px = mirror(form->center, center, axes);

  form->center.x = px.x;
  form->center.y = px.y;

  return;
}
Пример #6
0
int			check_form(char *tetri, int x, int y, int skip)
{
	if (get_pos(tetri, x, y) != '.')
	{
		if (skip == 0)
			return (1 + check_form(tetri, x + 1, y, 1)
					+ check_form(tetri, x - 1, y, -1)
					+ check_form(tetri, x, y + 1, 0));
		else if (skip == 1)
			return (1 + check_form(tetri, x + 1, y, 1) 
					+ check_form(tetri, x, y + 1, 0));
		else if (skip == -1)
			return (1 + check_form(tetri, x - 1, y, -1)
					+ check_form(tetri, x, y + 1, 0));
	}
	return (0);
}
Пример #7
0
int			check(char *tetri)
{
	int		x;
	int		y;

	if (nbhash(tetri) != 4)
		error("Error\n");
	x = 0;
	y = 0;
	while (get_pos(tetri, x, y) == '.')
	{
		x++;
		if (x == 4)
		{
			x = 0;
			y++;
		}
	}
	if (check_form(tetri, x, y, 1) < 4)
		error("Error\n");
	return (0);
}