Beispiel #1
0
static int		get_map(char **tab, t_env *env)
{
	int		**map;
	char	**tmp;
	int		i;
	int		j;

	if (check_for_char(env) == 0)
		return (0);
	get_max_x(env->tab, env);
	map = (int **)malloc(sizeof(int *) * env->y);
	i = -1;
	while (tab[++i])
	{
		j = -1;
		map[i] = (int *)malloc(sizeof(int) * env->x);
		tmp = ft_strsplit(tab[i], ' ');
		while (tmp[++j])
			map[i][j] = ft_atoi(tmp[j]);
		while (j < env->x)
		{
			map[i][j] = 0;
			j++;
		}
	}
	env->map = map;
	return (0);
}
Beispiel #2
0
int256_t P2(int128_t x, int threads)
{
  if (x < 1)
    return 0;

  double alpha = get_alpha_deleglise_rivat(x);
  string limit = get_max_x(alpha);

  if (x > to_int128(limit))
    throw primesum_error("P2(x): x must be <= " + limit);

  if (is_print())
    set_print_variables(true);

  int64_t y = (int64_t) (iroot<3>(x) * alpha);
  return P2(x, y, threads);
}
Beispiel #3
0
int256_t S2_hard(int128_t x, int threads)
{
  if (x < 1)
    return 0;

  double alpha = get_alpha_deleglise_rivat(x);
  string limit = get_max_x(alpha);

  if (x > to_int128(limit))
    throw primesum_error("S2_hard(x): x must be <= " + limit);

  if (is_print())
    set_print_variables(true);

  int64_t y = (int64_t) (iroot<3>(x) * alpha);
  int64_t z = (int64_t) (x / y);
  int64_t c = PhiTiny::get_c(y);

  return S2_hard(x, y, z, c, threads);
}
Beispiel #4
0
maxint_t P2(maxint_t x, int threads)
{
  if (x < 1)
    return 0;

  double alpha = get_alpha_deleglise_rivat(x);
  string limit = get_max_x(alpha);

  if (x > to_maxint(limit))
    throw primecount_error("P2(x): x must be <= " + limit);

  if (is_print())
    set_print_variables(true);

  int64_t y = (int64_t) (iroot<3>(x) * alpha);

  if (x <= numeric_limits<int64_t>::max())
    return P2((int64_t) x, y, threads);
  else
    return P2(x, y, threads);
}
Beispiel #5
0
maxint_t S2_hard(maxint_t x, int threads)
{
  if (x < 1)
    return 0;

  double alpha = get_alpha_deleglise_rivat(x);
  string limit = get_max_x(alpha);

  if (x > to_maxint(limit))
    throw primecount_error("S2_hard(x): x must be <= " + limit);

  if (is_print())
    set_print_variables(true);

  int64_t y = (int64_t) (iroot<3>(x) * alpha);
  int64_t z = (int64_t) (x / y);
  int64_t c = PhiTiny::get_c(y);

  if (x <= numeric_limits<int64_t>::max())
    return S2_hard((int64_t) x, y, z, c, (int64_t) Ri(x), threads);
  else
    return S2_hard(x, y, z, c, Ri(x), threads);
}
Beispiel #6
0
void help_text_area::handle_jump_cfg(const config &cfg)
{
	const std::string amount_str = cfg["amount"];
	const std::string to_str = cfg["to"];
	if (amount_str == "" && to_str == "") {
		throw parse_error("Jump markup must have either a to or an amount attribute.");
	}
	unsigned jump_to = curr_loc_.first;
	if (amount_str != "") {
		unsigned amount;
		try {
			amount = lexical_cast<unsigned, std::string>(amount_str);
		}
		catch (bad_lexical_cast) {
			throw parse_error("Invalid amount the amount attribute in jump markup.");
		}
		jump_to += amount;
	}
	if (to_str != "") {
		unsigned to;
		try {
			to = lexical_cast<unsigned, std::string>(to_str);
		}
		catch (bad_lexical_cast) {
			throw parse_error("Invalid amount in the to attribute in jump markup.");
		}
		if (to < jump_to) {
			down_one_line();
		}
		jump_to = to;
	}
	if (jump_to != 0 && static_cast<int>(jump_to) <
            get_max_x(curr_loc_.first, curr_row_height_)) {

		curr_loc_.first = jump_to;
	}
}
Beispiel #7
0
void QCanvas::xor_with_line(QColor color,QColor background,bool time_sleep)
{
    if (obj_lines.isEmpty())
        return;
    size_t min_x =  get_min_x().x();
    size_t max_x =  get_max_x().x();

    size_t line_x = (min_x+max_x)/2;

    if( min_x == SIZE_MAX || max_x == SIZE_MAX)
        return;

    QImage im = pix->toImage();
    Clear_canvas();
    for(size_t i = 0; i<obj_lines.size(); ++i)
    {
        QPointF S = obj_lines.value(i).S;
        QPointF F = obj_lines.value(i).F;

        if(S.y() > F.y())
            std::swap(S,F);

        for(size_t j = S.y(); j<F.y(); ++j)
        {
            size_t x = func(S,F,j);
            size_t y = j;
            while(x < line_x)
            {
                if(enabled_pix(color,QPointF(x,y)))
                    im.setPixel(x,y,background.rgb());
                else
                    im.setPixel(x,y,color.rgb());
                x++;
            }
            if(x == line_x)
            {
                if(enabled_pix(color,QPointF(x,y)))
                    im.setPixel(x,y,background.rgb());
                else
                    im.setPixel(x,y,color.rgb());
            }
            while (x > line_x)
            {
                if(enabled_pix(color,QPointF(x,y)))
                    im.setPixel(x,y,background.rgb());
                else
                    im.setPixel(x,y,color.rgb());
                x--;
            }

            pix->convertFromImage(im);
            for(size_t j = 0; j<i+1; ++j)
                Add_lines(obj_lines.value(j).S,obj_lines.value(j).F,Qt::black);

            this->setPixmap(*pix);
        }
        if(time_sleep)
        {
            QTime dieTime= QTime::currentTime().addSecs(1);
            while (QTime::currentTime() < dieTime)
                QCoreApplication::processEvents(QEventLoop::AllEvents, 10);
        }

    }
    draw_all_save_obj();
}
Beispiel #8
0
int help_text_area::get_remaining_width()
{
	const int total_w = get_max_x(curr_loc_.second, curr_row_height_);
	return total_w - curr_loc_.first;
}