示例#1
0
void	init_fonc(char **maze, t_check *check, t_path **path)
{
  check->check = -1;
  check->width = get_width(maze[0]);
  check->length = get_length(maze);
  add_coor(path, 0, 0);
  add_coor(path, 0, 0);
  srand(time(NULL));
}
示例#2
0
/* draw chain
 *   s - scale
 *   ch - chain number 
 *   rotation - degrees CCW from East
 */
int stroke_chain(SYMBPART *part, int ch, double s, double rotation)
{
    int k, l, first;
    SYMBEL *elem;
    SYMBCHAIN *chain;
    double r;
    double a1, a2, da;
    double x, y, x0, y0;

    G_debug(5, "  stroke_chain(): ch = %d", ch);
    chain = part->chain[ch];

    G_debug(5, "    element count = %d", chain->count);
    first = 1;
    for (k = 0; k < chain->count; k++) {
	elem = chain->elem[k];
	switch (elem->type) {
	case S_LINE:
	    G_debug(5, "    LINE count = %d", elem->coor.line.count);
	    for (l = 0; l < elem->coor.line.count; l++) {
		x = s * elem->coor.line.x[l];
		y = s * elem->coor.line.y[l];

		if (rotation != 0.0)
		    G_rotate_around_point(0, 0, &x, &y, rotation);

		add_coor(chain, x, y);
		if (first) {
		    x0 = x;
		    y0 = y;
		    first = 0;
		}
	    }
	    break;
	case S_ARC:
	    if (s >= 50)
		da = 1 * PI / 180;  /* later calc from size and tolerance */
	    else
		da = 10 * PI / 180;

	    r = elem->coor.arc.r;
	    G_debug(5, "    ARC da = %f r = %f", da, r);

	    /* convert to positive angles */
	    a1 = PI * elem->coor.arc.a1 / 180;
	    if (a1 < 0)
		a1 += 2 * PI;
	    a2 = PI * elem->coor.arc.a2 / 180;
	    if (a2 < 0)
		a2 += 2 * PI;

	    if (elem->coor.arc.clock) {	/* clockwise */
		while (1) {
		    x = s * elem->coor.arc.x + s * r * cos(a1);
		    y = s * elem->coor.arc.y + s * r * sin(a1);

		    if (rotation != 0.0)
			G_rotate_around_point(0, 0, &x, &y, rotation);

		    add_coor(chain, x, y);
		    if (first) {
			x0 = x;
			y0 = y;
			first = 0;
		    }
		    if (a1 == a2)
			break;
		    a1 -= da;
		    if (a1 < a2)
			a1 = a2;
		}

	    }
	    else {
		while (1) {
		    x = s * elem->coor.arc.x + s * r * cos(a1);
		    y = s * elem->coor.arc.y + s * r * sin(a1);

		    if (rotation != 0.0)
			G_rotate_around_point(0, 0, &x, &y, rotation);

		    add_coor(chain, x, y);
		    if (first) {
			x0 = x;
			y0 = y;
			first = 0;
		    }
		    if (a1 == a2)
			break;
		    a1 += da;
		    if (a1 > a2)
			a1 = a2;
		}
	    }
	    break;
	}
    }
    if (part->type == S_POLYGON) {
	add_coor(chain, x0, y0);	/* Close ring */
    }

    return 0;
}