int				get_next_line(int const fd, char **line)
{
	static char	*str;
	char		*buf;
	char		*tmp;
	int			ret;

	buf = ft_strnew(GET_SIZE);
	while (ft_strchr(buf, '\n') == NULL && (ret = read(fd, buf, GET_SIZE)) > 0)
	{
		buf[ret] = '\0';
		str = in_read(buf, str);
	}
	if (ret == -1)
		return (-1);
	if ((tmp = ft_strchr(str, '\n')) != NULL)
		make_line(line, &str, tmp);
	else if (ret == 0 && str != NULL && str[0] != '\0')
		make_end(line, &str);
	else
	{
		free(buf);
		return (0);
	}
	free(buf);
	return (1);
}
Пример #2
0
int			get_next_line(int const fd, char **line)
{
	static char	*stock[FD];
	char		*buffer;
	int			ret;
	char		*str;
	char		*tmp;

	buffer = ft_strnew(BUFF_SIZE);
	if (fd < 0 || line == NULL || buffer == NULL || BUFF_SIZE < 1)
		return (-1);
	if (stock[fd] == NULL)
		stock[fd] = ft_strnew(1);
	if ((ret = make_line(fd, buffer, stock)) == -1)
		return (-1);
	if ((str = ft_strchr(stock[fd], '\n')) != NULL)
	{
		*line = ft_strsub(stock[fd], 0, str - stock[fd]);
		tmp = stock[fd];
		stock[fd] = ft_strdup(str + 1);
		ft_strdel(&tmp);
		return (1);
	}
	*line = ft_strdup(stock[fd]);
	stock[fd] = NULL;
	return (ft_strlen(*line) > 0 ? 1 : 0);
}
PF mod_image_gen_mkline ( struct lxrcmd *c ) 
{
  make_line ( c->args[1].v.s, c->args[2].v.ld, c->args[3].v.ld, c->args[4].v.f, c->args[5].v.f, c->args[6].v.f, c->args[7].v.f, c->args[8].v.f);   
  
  c->results = NULL;   // NULL results block. Change as appropriate
  return(PASS);
}
Пример #4
0
void make_shape(Shape *vert)
{
	
    double	ray = 1; // radius
	int height = 1; // height
	double torus_radius = 1.2; // radius from origin to center of tube
	double tube_radius = 0.2; // tube radius
	GLfloat p0[3] = {0,0,0};
	GLfloat p1[3] = {0,1,0};
	theLine.type = LINE;
	
	float l1 = 1.0;
	float l2 = 0.75;
	float l3 = 0.50;
	
	switch(vert->type)
	{
		case HOUSE:
			make_house(vert);break;
		case SPHERE:
			make_sphere(vert, ray); break;
		case CYLINDER:
			make_cylinder(vert, ray, height); break;
		case CONE:
			make_cone(vert, height, ray); break;
		case TORUS:
			make_torus(vert,torus_radius, tube_radius); break;
		case CUBE:
			make_cube_smart(vert, 2); break;
		case LINE:
			make_line(vert, p0, p1);
		case SUPER:
			make_quadric(vert, l1, l2, l3);
	}	
}
Пример #5
0
/* Treeify a body by appending the trees of the lines.
 */ 
void make_tree_from_body(NODE *body) {

    NODE *body_ptr, *end_ptr = NIL, *tree = NIL;

    if (body == NIL ||
	(is_tree(body) && generation__tree(body) == the_generation))
	    return;
    if (is_tree(body)) untreeify_body(body);
    for (body_ptr = body; body_ptr != NIL; body_ptr = cdr(body_ptr)) {
	tree = car(body_ptr);
	if (tree == NIL) continue;  /* skip blank line */
	this_line = tree;
	make_tree(tree);
	if (is_tree(tree)) {
	    tree = tree__tree(tree);
	    make_line(tree, car(body_ptr));
	    if (end_ptr == NIL)
		settree__tree(body, tree);
	    else
		setcdr(end_ptr, tree);
	    if (generation__tree(car(body_ptr)) == UNBOUND)
		setgeneration__tree(body, UNBOUND);
/*	    untreeify(car(body_ptr));	*/
	    while (cdr(tree) != NIL)
		tree = cdr(tree);
	    end_ptr = tree;
	} else {    /* error while treeifying */
	    untreeify(body);
	    return;
	}
    }
    settype(body, TREE);
}
Пример #6
0
void GetGridBox(const CViewPoint *view_point, CBox &ext){
	gp_Pnt sp[4];
	double zval = 0.5;
	wxSize size = wxGetApp().m_current_viewport->GetViewportSize();
	sp[0] = gp_Pnt(0, 0, zval);
	sp[1] = gp_Pnt(size.GetWidth(), 0, zval);
	sp[2] = gp_Pnt(size.GetWidth(), size.GetHeight(), zval);
	sp[3] = gp_Pnt(0, size.GetHeight(), zval);
	gp_Vec vx, vy;
	view_point->GetTwoAxes(vx, vy, false, 0);
	gp_Pnt datum(0, 0, 0);
	gp_Trsf orimat = wxGetApp().GetDrawMatrix(false);
	datum.Transform(orimat);
	orimat = make_matrix(datum, vx, vy);
	gp_Pln plane(datum, gp_Vec(0, 0, 1).Transformed(orimat));
	{
		for(int i =0; i<4; i++){
			gp_Pnt p1 = view_point->glUnproject(sp[i]);
			sp[i].SetZ(0);
			gp_Pnt p2 = view_point->glUnproject(sp[i]);
			gp_Lin line = make_line(p1, p2);
			gp_Pnt pnt;
			if(intersect(line, plane, pnt))
			{
				ext.Insert(pnt.X(), pnt.Y(), pnt.Z());
			}
		}
	}
}
Пример #7
0
	point2<T> overlap( const point2<T>& pt, const segment2<T>& segment ) {
		// check if either is null
		if( pt == point2<T>::null( ) || segment == segment2<T>::null( ) ) {
			return point2<T>::null( );
		}
		// not working??
		return overlap( pt, make_line( segment ) );
	}
Пример #8
0
/**
 * Classsifies the Triangle given by the 3 points that were specified.
 * 
 * A Triangle is classified as follows:
 *   1. Scalene | Equilateral | Isosceles
 *   2. Acute   | Obtuse      | Right
 *   3. Not A Triangle
 */
void classify_triangle(point *p1, point *p2, point *p3) {
    
    if ( DEBUG )
        printf("Classifying Triangle with points: (%li, %li), (%li, %li), (%li, %li)...\n", p1->x, p1->y, p2->x, p2->y, p3->x, p3->y);
    
    long int l1 = (p2->x - p1->x)*(p2->x - p1->x) + (p2->y - p1->y)*(p2->y - p1->y);    
    long int l2 = (p3->x - p2->x)*(p3->x - p2->x) + (p3->y - p2->y)*(p3->y - p2->y);
    long int l3 = (p3->x - p1->x)*(p3->x - p1->x) + (p3->y - p1->y)*(p3->y - p1->y);
    
    if ( DEBUG ) {
        printf("l1: %li\n", l1);
        printf("l2: %li\n", l2);
        printf("l3: %li\n", l3);
    }

    /* If the three points lie on the same line then they will have the same slope, otherwise
     * they make a triangle.
     *
     * Comparison comes from: http://math.stackexchange.com/a/405981
     */
    if ( make_line(p1, p2, p3) ) {
        printf("not a triangle");
	return;
    }

    if ( l1 == l2 == l3 ) {
        printf("equilateral "); 
    } else if ( l1 == l2 | l1 == l3 | l2 == l3 ) {
        printf("isosceles ");
    } else {
        printf("scalene ");
    }

    // find the longest side length
    long int a = l2, b = l3, c = l1;
    if ( l2 > c && l2 > l3 ) {
        a = l1;
        b = l3;
        c = l2;
    }
    else if (l3 > c && l3 > l2 ) {
        a = l1;
        b = l2;
        c = l3;
    }

    // classify according to angle by using Pythagorean's theorem
    // here a = a^2, b = b^2, and c = c^2 (as you can see from above)
    if ( a + b == c )
        printf("right");
    else if ( a + b > c )
    	printf("acute");
    else
  	printf("obtuse");
}
Пример #9
0
void check_balance(int dir, int max)
{
    int i;
    struct field line[max];
    
    for (i=0; i<max; i++) {
	make_line(i, dir, line);
	countline(dir, line);
	restore_line(i, dir, line);
    }
}
// ---------------------------------------------------------------------------
// 
// -----------
bool bPerpendicularLineElement::actionval(	bGenericGraphicContext* ctx,
								bStdXMLValueElement* elt,
								bGenericGeoElement* geo){
	elt->getvalue(geo,&_dr);
	if(_dr==0){
int		o[2]={0,1};
float	x=0;
float	y=0;
		ctx->setGeometry(&x,&y,1,o,2);
		return(true);
	//	return(false);
	}
	return(make_line(ctx));
}
Пример #11
0
void	make_my_shell1_2(char *line, char **av, char **path)
{
	int		i;
	int		j;
	char	*cmd;

	i = 0;
	j = -1;
	while (path[i] != NULL)
	{
		cmd = make_line(line, path[i++]);
		j = execve(cmd, av, g_my_env);
		free(cmd);
	}
	if (j == -1)
	{
		ft_putstr_fd("Error : command not found : ", 2);
		ft_putendl_fd(line, 2);
		exit(-1);
	}
}
// ---------------------------------------------------------------------------
// 
// -----------
bool bPerpendicularLineElement::actionstd(bGenericGraphicContext* ctx){
	if(_elts.count()>0){
bStdXMLValueElement*	elt=find_value();
		if(elt==NULL){
			return(true);
		}
		elt->getvalue(NULL,&_dr);
	}
	else{
char	val[_values_length_max_];
		getvalue(val);
		_dr=matof(val);		
	}
	if(_dr==0){
int		o[2]={0,1};
float	x=0;
float	y=0;
		ctx->setGeometry(&x,&y,1,o,2);
		return(true);
	//	return(false);
	}
	return(make_line(ctx));
}
Пример #13
0
int main(int argc, char *argv[]) {
  int notdone=1;
  char buf[1024];
  int val[9], i, ch, code;
  time_t starttime, curtime;
  struct timeval tv;
  struct timezone tz;
  struct tm *ltime;
  int interval = 1;

  setup_vars();
  
  printf("Hello, World!\n");
  if (get_args(argc, argv) != 0) {
    show_usage();
    exit(1);
  }
  for(ch=0;ch<CHMAX;ch++) {
    clear_reading_storage(ch);
  }
  clear_inputs(interval);
  make_line();
  if ((fd = open(dsrc, O_RDWR|O_NONBLOCK)) < 0) {
    printf("couldn't open data source file\n");
    exit(1);
  }
  start_serial_io(fd, baud);
  my_fgets(buf, 1000, fd);
  notdone = 0;
  printf("syncing time...\n");
  while (notdone < 2) {
    starttime = time(NULL);
    ltime = localtime(&starttime);
    if ((ltime->tm_sec % interval) == 0) {
      notdone++;
    } else {
      /* sleep(1); */
      my_fgets(buf, 1000, fd);
    }
    curday = ltime->tm_mday;
    set_curdatestring(ltime);
  }
  if (log_file_name != NULL) {
    start_log_file();
  }
  printf("starting at %010d\n", (int) starttime);
  notdone = 1;
  while (notdone) {
    /* take care of time first */
    curtime = time(NULL);
    if (curtime >= (starttime + interval)) {
      if (logfp != NULL) {
        fprintf(logfp, "%010d (%s)", (int) starttime, safe_ctime(&starttime));
      } else {
        printf("%010d (%s)", (int) starttime, safe_ctime(&starttime));
      }
      for (ch=0;ch<CHMAX;ch++) {
        dump_reading(ch);
        clear_reading_storage(ch);
      }
      /* dump_inputs(); */
      if (logfp != NULL) {
        fprintf(logfp, "\n");
      } else {
        printf("\n");
      }
      starttime = curtime;
      ltime = localtime(&curtime); /* ltime is needed here and ctime messes it up */
      /* check for the day change here so that the last second of yesterday
         ends up in *yesterday's* log and this days data ends up in this
         days log */
      if (ltime->tm_mday != curday) {
        set_curdatestring(ltime);
        if (log_file_name != NULL) {
          fclose(logfp);
          start_log_file();
        }
        curday = ltime->tm_mday;
      } else {
        /* flush whenever a line is written */
        if (logfp != NULL) {
          fflush(logfp);
        } else {
          fflush(stdout);
        }
      }
    }
    if (my_fgets(buf, 1000, fd) == 1) {
      if (strlen(buf) > 4) {
        /* printf("%s", buf); */
        buf[strlen(buf) - 1] = 0;
        chop_input(buf, val, &code);
        /* test_code_change(~code, curtime); */
        for (ch=0;ch<CHMAX;ch++) {
          add_reading(ch, val[ch+1]);
        }
      }
    } else { /* don't consume 100% of the processor. */
      usleep(1000);
    }
    fflush(stdout);
  }
  exit(0);
}
// ---------------------------------------------------------------------------
// 
// -----------
bool bPerpendicularLineElement::make_line(bGenericGraphicContext *ctx){
_bTrace_("bPerpendicularLineElement::make_line(bGenericGraphicContext)",false);
int		npts,*offsets,noffsets;
float	*xpts,*ypts;

	ctx->getGeometry(&xpts,&ypts,&npts,&offsets,&noffsets);

	if(npts<2){
int		lo[2]={0,1};
float	lx=0;
float	ly=0;
		ctx->setGeometry(&lx,&ly,1,lo,2);
		return(true);
	}

long	npart=0;
	for(long i=0;i<noffsets-1;i++){
		if(offsets[i+1]-offsets[i]>1){
			npart++;
		}
	}
	if(npart==0){
int		lo[2]={0,1};
float	lx=0;
float	ly=0;
		ctx->setGeometry(&lx,&ly,1,lo,2);
		return(true);
	}
	
float	*x		=(float*)malloc((npart*2L)*sizeof(float));
float	*y		=(float*)malloc((npart*2L)*sizeof(float));
int		*poff	=(int*)malloc((npart+1L)*sizeof(int));
	
	poff[0]=0;
	for(long i=1;i<=npart;i++){
		poff[i]=poff[i-1]+2;
	}
	
float	sz=ctx->getHSize();
	npart=0;
	for(long i=0;i<noffsets-1;i++){
		if(offsets[i+1]-offsets[i]>1){
			make_line(&xpts[offsets[i]],&ypts[offsets[i]],offsets[i+1]-offsets[i],sz,&x[npart*2],&y[npart*2]);
			npart++;
		}
	}
	
	ctx->setGeometry(x,y,npart*2L,poff,npart+1);
	
	if(x){
		free(x);
	}
	if(y){
		free(y);
	}
	if(poff){
		free(poff);
	}
	
	return(true);
}
Пример #15
0
static void RenderGrid(const CViewPoint *view_point, double max_number_across, bool in_between_spaces, bool miss_main_lines, const HeeksColor *bg, const HeeksColor *cc, unsigned char brightness, int plane_mode){
	gp_Pnt sp[4];
	double zval = 0.5;
	wxSize size = wxGetApp().m_current_viewport->GetViewportSize();
	sp[0] = gp_Pnt(0, 0, zval);
	sp[1] = gp_Pnt(size.GetWidth(), 0, zval);
	sp[2] = gp_Pnt(size.GetWidth(), size.GetHeight(), zval);
	sp[3] = gp_Pnt(0, size.GetHeight(), zval);
	gp_Vec vx, vy;
	int plane_mode2 = view_point->GetTwoAxes(vx, vy, false, plane_mode);
	gp_Pnt datum(0, 0, 0);
	gp_Trsf orimat = wxGetApp().GetDrawMatrix(false);
	datum.Transform(orimat);
	orimat = make_matrix(datum, vx, vy);
	gp_Vec unit_forward = view_point->forwards_vector().Normalized();
	double plane_dp = fabs(gp_Vec(0, 0, 1).Transformed(orimat) * unit_forward);
	if(plane_dp < 0.3)return;
	gp_Pln plane(gp_Pnt(0, 0, 0).Transformed(orimat), gp_Vec(0, 0, 1).Transformed(orimat));
	{
		for(int i =0; i<4; i++){
			gp_Pnt p1 = view_point->glUnproject(sp[i]);
			sp[i].SetZ(0);
			gp_Pnt p2 = view_point->glUnproject(sp[i]);
			if(p1.Distance(p2) < 0.00000000001)return;
			gp_Lin line = make_line(p1, p2);
			gp_Pnt pnt;
			if(intersect(line, plane, pnt))
			{
				sp[i].SetX((gp_Vec(pnt.XYZ()) * vx) - (gp_Vec(datum.XYZ()) * vx));
				sp[i].SetY((gp_Vec(pnt.XYZ()) * vy) - (gp_Vec(datum.XYZ()) * vy));
				sp[i].SetZ(0);
			}
		}
	}
	CBox b;
	{
		for(int i = 0; i<4; i++){
			b.Insert(sp[i].X(), sp[i].Y(), sp[i].Z());
		}
	}
	double width = b.Width();
	double height = b.Height();
	double biggest_dimension;
	if(height > width)biggest_dimension = height;
	else biggest_dimension = width;
	double widest_spacing = biggest_dimension/max_number_across;
	bool dimmer = false;
	double dimness_ratio = 1.0;
	double spacing;

	if(wxGetApp().draw_to_grid){
		spacing = wxGetApp().digitizing_grid;
		if(!miss_main_lines)spacing *= 10;
		if(spacing<0.0000000001)return;
		if(biggest_dimension / spacing > max_number_across * 1.5)return;
		if(biggest_dimension / spacing > max_number_across){
			dimmer = true;
			dimness_ratio = (max_number_across * 1.5 - biggest_dimension / spacing)/ (max_number_across * 0.5);
		}

	}
	else{
		double l = log10(widest_spacing / wxGetApp().m_view_units);

		double intl = (int)l;
		if(l>0)intl++;

		spacing = pow(10.0, intl) * wxGetApp().m_view_units;
	}

	if(wxGetApp().grid_mode == 3){
		dimmer = true;
		dimness_ratio *= plane_dp;
		dimness_ratio *= plane_dp;
	}
	double ext2d[4];
	ext2d[0] = b.m_x[0];
	ext2d[1] = b.m_x[1];
	ext2d[2] = b.m_x[3];
	ext2d[3] = b.m_x[4];
	{
		for(int i = 0; i<4; i++){
			double intval = (int)(ext2d[i]/spacing);
			if(i <2 ){
				if(ext2d[i]<0)intval--;
			}
			else{
				if(ext2d[i]>0)intval++;
			}

			ext2d[i] = intval * spacing;
		}
	}
	if(cc){
		HeeksColor col = *cc;
		if(wxGetApp().grid_mode == 3){
			switch(plane_mode2){
			case 0:
				col.green = (unsigned char)(0.6 * (double)(bg->green));
				break;
			case 1:
				col.red = (unsigned char)(0.9 * (double)(bg->red));
				break;
			case 2:
				col.blue = bg->blue;
				break;
			}
		}

		if(dimmer){
			double d_brightness = (double)brightness;
			d_brightness *= dimness_ratio;
			unsigned char uc_brightness = (unsigned char)d_brightness;

			glColor4ub(col.red, col.green, col.blue, uc_brightness);
		}
		else{
			glColor4ub(col.red, col.green, col.blue, brightness);
		}
	}
	glBegin(GL_LINES);
	double extra = 0;
	if(in_between_spaces)extra = spacing * 0.5;
	for(double x = ext2d[0] - extra; x<ext2d[2] + extra; x += spacing){
		if(miss_main_lines){
			double xr = x/spacing/5;
			if( fabs(  xr - (double)(int)(xr+ (xr>0 ? 0.5:-0.5)) ) < 0.1)continue;
		}
		gp_Pnt temp(datum.XYZ() + (vx.XYZ() * x) + (vy.XYZ() * ext2d[1]));
		glVertex3d(temp.X(), temp.Y(), temp.Z());
		temp = (datum.XYZ() + (vx.XYZ() * x) + (vy.XYZ() * ext2d[3]));
		glVertex3d(temp.X(), temp.Y(), temp.Z());
	}
	for(double y = ext2d[1] - extra; y<ext2d[3] + extra; y += spacing){
		if(miss_main_lines){
			double yr = y/spacing/5;
			if( fabs(  yr - (double)(int)(yr+(yr>0 ? 0.5:-0.5)) ) < 0.1)continue;
		}
		gp_Pnt temp = (datum.XYZ() + (vx.XYZ() * ext2d[0]) + (vy.XYZ() * y));
		glVertex3d(temp.X(), temp.Y(), temp.Z());
		temp = (datum.XYZ() + (vx.XYZ() * ext2d[2]) + (vy.XYZ() * y));
		glVertex3d(temp.X(), temp.Y(), temp.Z());
	}
	glEnd();
}
Пример #16
0
/* Start a new cluster of lines going.
   Pick their anim type, and in, mid, and out positions.
 */
static void
reset_lines (ModeInfo *mi)
{
  fliptext_configuration *sc = &scs[MI_SCREEN(mi)];
  int i;
  line *prev = 0;
  GLfloat minx, maxx, miny, maxy, minz, maxz, maxw, maxh;

  sc->rotation.x = 5 - BELLRAND(10);
  sc->rotation.y = 5 - BELLRAND(10);
  sc->rotation.z = 5 - BELLRAND(10);

  switch (random() % 8)
    {
    case 0:  sc->anim_type = SCROLL_TOP;    break;
    case 1:  sc->anim_type = SCROLL_BOTTOM; break;
    default: sc->anim_type = SPIN;          break;
    }

  minx = sc->left_margin  * 0.9;
  maxx = sc->right_margin * 0.9;

  miny = sc->bottom_margin * 0.9;
  maxy = sc->top_margin    * 0.9;

  minz = sc->left_margin  * 5;
  maxz = sc->right_margin * 2;

  maxw = sc->font_wrap_pixels * sc->font_scale;
  maxh = max_lines * sc->line_height * sc->font_scale;
 
  if (maxw > maxx - minx)
    maxw = maxx - minx;
  if (maxh > maxy - miny)
    maxh = maxy - miny;
      
  if (alignment_random_p)
    sc->alignment = (random() % 3) - 1;

  if      (sc->alignment == -1) maxx -= maxw;
  else if (sc->alignment ==  1) minx += maxw;
  else                          minx += maxw/2, maxx -= maxw/2;

  miny += maxh/2;
  maxy -= maxh/2;

  sc->mid.x = minx + frand (maxx - minx);
  if (sc->anim_type == SPIN)
    sc->mid.y = miny + BELLRAND (maxy - miny);
  else
    sc->mid.y = miny + frand (maxy - miny);

  sc->in.x  = BELLRAND(sc->right_margin * 2) - sc->right_margin;
  sc->out.x = BELLRAND(sc->right_margin * 2) - sc->right_margin;

  sc->in.y  = miny + frand(maxy - miny);
  sc->out.y = miny + frand(maxy - miny);

  sc->in.z  = minz + frand(maxz - minz);
  sc->out.z = minz + frand(maxz - minz);

  sc->mid.z = 0;

  if (sc->anim_type == SPIN && sc->in.z  > 0) sc->in.z  /= 4;
  if (sc->anim_type == SPIN && sc->out.z > 0) sc->out.z /= 4;

  for (i = 0; i < max_lines; i++)
    {
      line *line = make_line (sc, (i == 0));
      if (!line) break;			/* no text available */
      if (i >= min_lines &&
          (!line->text || !*line->text))	/* blank after min */
        break;
    }

  for (i = 0; i < sc->nlines; i++)
    {
      line *line = sc->lines[i];
      if (!prev)
        {
          line->from.y = sc->bottom_margin;
          line->to.y   = 0;
        }
      else
        {
          line->from.y = prev->from.y - prev->height;
          line->to.y   = prev->to.y   - prev->height;
        }
      line->cluster_pos = i;
      line->cluster_size = sc->nlines;
      prev = line;
    }
}