Exemplo n.º 1
0
int main(int argc, char* argv[]) {
  int id=0, numprocs;
  int color;
  MPI_Comm local;
  double t1, t2;

  VT_initialize(&argc, &argv);
  VT_symdef(1, "step", "USR");
  VT_symdef(2, "sequential", "USR");
  VT_symdef(3, "p2p", "USR");
  VT_symdef(4, "parallel", "USR");
  VT_symdef(5, "main", "USR");
  VT_begin(5);

  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD, &id);
  printf("%03d: ctest-vt start\n", id);
  color = (id >= numprocs/2);
  MPI_Comm_split(MPI_COMM_WORLD, color, id, &local);

  t1 = MPI_Wtime();
  parallel(MPI_COMM_WORLD);
  parallel(local);
  parallel(MPI_COMM_WORLD);
  t2 = MPI_Wtime();

  MPI_Comm_free(&local);
  MPI_Finalize();
  printf("%03d: ctest-vt end (%12.9f)\n", id, (t2-t1));

  VT_end(5);
  VT_finalize();
  return 0;
}
Exemplo n.º 2
0
int main(int argc, char* argv[]) {
  int id=0, numprocs;
  int color;
  MPI_Comm local;
  double t1, t2;

  ELG_USER_START("main");

  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD, &id);
  printf("%03d: ctest-elg start\n", id);

  /* define Cartesian topology */
  elg_cart_create(2, (numprocs+1)/2, 0, 1, 1, 0);
  elg_cart_coords(id%2, id/2, 0);

  color = (id >= numprocs/2);
  MPI_Comm_split(MPI_COMM_WORLD, color, id, &local);

  t1 = MPI_Wtime();
  parallel(MPI_COMM_WORLD);
  parallel(local);
  parallel(MPI_COMM_WORLD);
  t2 = MPI_Wtime();

  MPI_Comm_free(&local);
  MPI_Finalize();
  printf("%03d: ctest-elg end  (%12.9f)\n", id, (t2-t1));

  ELG_USER_END("main");
  return 0;
}
Exemplo n.º 3
0
struct leib_struct time_leibniz(long int n, int nthreads, enum leib_enum flag){
	TimeStamp clk;
	clk.tic();
	struct leib_struct ans;
	int chunk = 10;
	
	switch(flag){
	case LEIB:
		ans.pi = leibniz(n);
		break;
	case PLL:
		ans.pi = parallel(n, nthreads);
		break;
	case PLLX:
		ans.pi = parallel(n, nthreads);
		break;
	case FOR:
		ans.pi = ompfor(n);
		break;
	case FORCHUNK:
		ans.pi = ompforchunk(n, chunk);
		break;
	case PLLFOR:
		ans.pi = parallelfor(n, nthreads);
		break;
	case SCTN:
		ans.pi = section(n);
		break;
	default:
		assrt(0 == 1);
	}
	ans.cycles = clk.toc();
	return ans;
}
Exemplo n.º 4
0
int line_line_cross(point a1, point s1, point a2, point s2, point *res) {
    if (parallel(s1, s2))
        if (parallel(a2-a1, s1))
            return -1;
        else
            return 0;
    double k1 = cross(a2-a1,s2)/cross(s1,s2);
    *res = a1+s1*k1;
    return 1;
}
Exemplo n.º 5
0
int line_line_cross(line2 a, line2 b, point2 *res = NULL) {
	if (parallel(a.s, b.s))
		if (parallel(b.a - a.a, a.s))
			return -1;
		else
			return 0;
	double k1 = (b.a - a.a) % b.s / (a.s % b.s);
	if (res != NULL) *res = a.a + k1 * a.s;
	return 1;
}
Exemplo n.º 6
0
static void		check_lines(t_env *env, t_node *start, t_node *end)
{
	t_node		*tmp;
	t_node		*tmp2;

	tmp = (env->proj == 0) ? isometric(env, start) : parallel(env, start);
	tmp2 = (env->proj == 0) ? isometric(env, end) : parallel(env, end);
	if ((tmp->x - tmp2->x) == 0)
		draw_vertical(env, tmp, tmp2);
	else
		check_affine(env, tmp, tmp2);
}
//判断两直线的位置关系
int line_to_line(const Line &u, const Line &v)
{
    Plane s1(u.a, u.b, v.a), s2(u.a, u.b, v.b);
    if (sgn((pvec(s1) ^ pvec(s2)).norm())) return -1;//异面
    else if(parallel(u, v)) return 0;//平行
    else return 1;//相交
}
// Return delta (P to N) vectors across coupled patch
tmp<vectorField> cyclicFvPatch::delta() const
{
    vectorField patchD = fvPatch::delta();
    label sizeby2 = patchD.size()/2;

    tmp<vectorField> tpdv(new vectorField(patchD.size()));
    vectorField& pdv = tpdv();

    // To the transformation if necessary
    if (parallel())
    {
        for (label facei = 0; facei < sizeby2; facei++)
        {
            vector ddi = patchD[facei];
            vector dni = patchD[facei + sizeby2];

            pdv[facei] = ddi - dni;
            pdv[facei + sizeby2] = -pdv[facei];
        }
    }
    else
    {
        for (label facei = 0; facei < sizeby2; facei++)
        {
            vector ddi = patchD[facei];
            vector dni = patchD[facei + sizeby2];

            pdv[facei] = ddi - transform(forwardT()[0], dni);
            pdv[facei + sizeby2] = -transform(reverseT()[0], pdv[facei]);
        }
    }

    return tpdv;
}
Exemplo n.º 9
0
void	draw_grid(t_env *e, t_point **grid, int i, int j)
{
	grid = map_to_point(e);
	grid = (e->proj == 0) ? isometric(grid, e) : parallel(grid, e);
	i = 0;
	while ((i + 1) < e->map[0][0] - 1)
	{
		j = 0;
		while ((j + 1) < e->map[i + 1][0] - 1)
		{
			(grid[i][j + 1].x) ? putl(e, grid[i][j], grid[i][j + 1]) : 1;
			(grid[i + 1][j].x) ? putl(e, grid[i][j], grid[i + 1][j]) : 1;
			if (j + 1 == e->map[i + 1][0] - 2
				&& e->map[i + 1][0] <= e->map[i + 2][0])
				putl(e, grid[i][j + 1], grid[i + 1][j + 1]);
			if (i + 1 == e->map[0][0] - 2)
				putl(e, grid[i + 1][j], grid[i + 1][j + 1]);
			j++;
		}
		i++;
	}
	mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0);
	print_state(e);
	mlx_do_sync(e->mlx);
}
Exemplo n.º 10
0
int
main(int argc, char *argv[])
{
	extern char *optarg;
	extern int optind;
	int ch, seq;

	seq = 0;
	while ((ch = getopt(argc, argv, "d:s")) != -1)
		switch(ch) {
		case 'd':
			delimcnt = tr(delim = optarg);
			break;
		case 's':
			seq = 1;
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (!delim) {
		delimcnt = 1;
		delim = "\t";
	}

	if (seq)
		sequential(argv);
	else
		parallel(argv);
	exit(0);
}
Exemplo n.º 11
0
 bool intersect(const Line& l, Point& p) const {
   if (parallel(l)) return false;
   // solve system of 2 linear algebraic equations with 2 unknowns
   p.x = (l.b*c - b*l.c) / (l.a*b - a*l.b);
   if (fabs(b) > EPS) p.y = -(a*p.x + c); else p.y = -(l.a*p.x + l.c);
   return true;
 }
Exemplo n.º 12
0
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif
  
  IOShell::Interface interface;
  bool success = interface.parse_options(argc, argv);
  if (!success) {
    exit(EXIT_FAILURE);
  }
  
  Ioss::Init::Initializer io;
#ifndef NO_XDMF_SUPPORT
  Ioxf::Initializer ioxf;
#endif

#ifdef USE_CGNS
  Iocgns::Initializer iocgns;
#endif

  std::string in_file   = interface.inputFile[0];
  std::string out_file  = interface.outputFile;

  OUTPUT << "Input:    '" << in_file  << "', Type: " << interface.inFiletype  << '\n';
  OUTPUT << "Output:   '" << out_file << "', Type: " << interface.outFiletype << '\n';
  OUTPUT << '\n';
  
  double begin = timer();
  file_copy(interface);
  double end = timer();

#ifdef HAVE_MPI
  // Get total data read/written over all processors, and the max time..
  Ioss::ParallelUtils parallel(MPI_COMM_WORLD);

  // Combine these some time...
  time_read  = parallel.global_minmax(time_read,  Ioss::ParallelUtils::DO_MAX);
  time_write = parallel.global_minmax(time_write, Ioss::ParallelUtils::DO_MAX);
  data_read  = parallel.global_minmax(data_read,  Ioss::ParallelUtils::DO_SUM);
  data_write = parallel.global_minmax(data_write, Ioss::ParallelUtils::DO_SUM);
#endif

  if (interface.statistics) {
    OUTPUT << "\n\tElapsed time = " << end - begin << " seconds."
	   << " (read = " << time_read << ", write = " << time_write << ")\n"
	   << "\tTotal data read  = " << data_read  << " bytes; "
	   << data_read  / time_read  <<" bytes/second.\n"
	   << "\tTotal data write = " << data_write << " bytes; "
	   << data_write / time_write << " bytes/second.\n";
  }

  OUTPUT << "\n" << codename << " execution successful.\n";
#ifdef HAVE_MPI
  MPI_Finalize();
#endif
  return EXIT_SUCCESS;
}
Exemplo n.º 13
0
void return_to_node(double curr_coord[2], struct node* returnnode){
    printf("\t \t ### Returning to node[%d] ###\n", returnnode->name);
    move_to(curr_coord, returnnode->x, returnnode->y);
    if(no_wall_front() == 0){
        parallel(curr_coord);
    }
    usleep(1000);
}
Exemplo n.º 14
0
math_vector math_vector::perpendicular(const math_vector& source)const
{
    //cout<<"perpendicular"<<endl;
    //math_vector result(*this - source.parallel(*this));
    math_vector result(*this - parallel(source));
    //cout<<"input: "<<source.write()<<"		me:"<<write()<<"		output: "<<result.write()<<endl<<endl;
    return result;
}
Exemplo n.º 15
0
int
main(int argc, char *argv[])
{
	struct fdescr *dsc;
	Rune *delim;
	size_t i, len;
	int seq = 0, ret = 0;
	char *adelim = "\t";

	ARGBEGIN {
	case 's':
		seq = 1;
		break;
	case 'd':
		adelim = EARGF(usage());
		break;
	default:
		usage();
	} ARGEND;

	if (!argc)
		usage();

	/* populate delimiters */
	unescape(adelim);
	delim = ereallocarray(NULL, utflen(adelim) + 1, sizeof(*delim));
	len = utftorunestr(adelim, delim);
	if (!len)
		usage();

	/* populate file list */
	dsc = ereallocarray(NULL, argc, sizeof(*dsc));

	for (i = 0; i < argc; i++) {
		if (!strcmp(argv[i], "-")) {
			argv[i] = "<stdin>";
			dsc[i].fp = stdin;
		} else if (!(dsc[i].fp = fopen(argv[i], "r"))) {
			eprintf("fopen %s:", argv[i]);
		}
		dsc[i].name = argv[i];
	}

	if (seq) {
		sequential(dsc, argc, delim, len);
	} else {
		parallel(dsc, argc, delim, len);
	}

	for (i = 0; i < argc; i++)
		if (dsc[i].fp != stdin && fshut(dsc[i].fp, argv[i]))
			ret |= fshut(dsc[i].fp, argv[i]);

	ret |= fshut(stdin, "<stdin>") | fshut(stdout, "<stdout>");

	return ret;
}
	TEST(StarterKit1, ParallelFailureRequireOne)
	{
		Parallel parallel(Parallel::RequireAll, Parallel::RequireOne);
		MockBehavior children[2];
		parallel.addChild(&children[0]);
		parallel.addChild(&children[1]);
		CHECK_EQUAL(BH_RUNNING, parallel.tick());
		children[0].m_eReturnStatus = BH_FAILURE;
		CHECK_EQUAL(BH_FAILURE, parallel.tick());
	}
	TEST(StarterKit1, ParallelSucceedRequireOne)
	{
		Parallel parallel(Parallel::RequireOne, Parallel::RequireAll);
		MockBehavior children[2];
		parallel.addChild(&children[0]);
		parallel.addChild(&children[1]);
		CHECK_EQUAL(BH_RUNNING, parallel.tick());
		children[0].m_eReturnStatus = BH_SUCCESS;
		CHECK_EQUAL(BH_SUCCESS, parallel.tick());
	}
Exemplo n.º 18
0
//-----------------------------------------------------------------------------
// class SSegment (Stretch Segment)
//-----------------------------------------------------------------------------
logicop::SSegment::SSegment(const TP& p1, const TP& p2, int distance) : PSegment(p1,p2)
{
   assert(0 != distance);
   DBline sample(TP(0,0), TP(distance, 0));
   CTM mtrx;
   real rotation = laydata::xangle(p1,p2) + 270.0;
   mtrx.Rotate(rotation);
   mtrx.Translate(p1);
   sample = sample * mtrx;
   _moved = parallel(sample.p2());
}
Exemplo n.º 19
0
void solve() {
	point2 a, b;
	scanf("%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y);
	l1.a = a, l1.s = b - a;
	scanf("%lf%lf", &p1.x, &p1.y);
	scanf("%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y);
	l2.a = a, l2.s = b - a;
	scanf("%lf%lf", &p2.x, &p2.y);
	double l = -100000, r = 100000;
	if (parallel(l1.s, l2.s)) {
		point2 q;
		if (dis(p1 - p2) < point_line_dis(l1.a, l2) - eps || fabs(dis(p1 - p2) - point_line_dis(l1.a, l2, &q)) < eps && parallel(p2 - p1, q - l1.a) && (p2 - p1) * (q - l1.a) > 0) {
			puts("0 0 0 0");
			return;
		}
		if (perpend(p2 - p1, l1.s)) {
			point_line_dis(p1, l1, &q);
			l = (q - l1.a) * l1.s / (l1.s * l1.s);
			r = 100000;
		} else {
			double d = point_line_dis(p1, l1, &q);
			q = (q - p1) / d * dis(p2 - p1) + p1;
			q = (q + p2) / 2;
			line2 l3; l3.a = p1, l3.s = q - p1;
			point2 q1, q2;
			line_line_cross(l3, l1, &q1);
			double t = l3.s.x; l3.s.x = l3.s.y, l3.s.y = -t;
			line_line_cross(l3, l1, &q2);
			l = (q1 - l1.a) * l1.s / (l1.s * l1.s);
			r = (q2 - l1.a) * l1.s / (l1.s * l1.s);
			if (l > r) t = l, l = r, r = t;
		}
	}
	double fl = f(l), fr = f(r);
	if (fabs(fl) < eps) ;
	else if (fabs(fr) < eps) l = r;
	else {
		if (fl * fr > 0) {
			puts("0 0 0 0");
			return;
		}
		while (fabs(r-l) >= 1e-12) {
			double mid = (l+r)/2, fmid = f(mid);
			if (fmid * fl > 0) l = mid, fl = fmid;
			else r = mid, fr = fmid;
		}
	}
	line2 ans;
	ans.a = (p1 + l1.a + l * l1.s) / 2;
	ans.s = l1.a + l * l1.s - p1;
	double t = ans.s.y; ans.s.y = ans.s.x, ans.s.x = -t;
	a = ans.a, b = ans.s + ans.a;
	printf("%lf %lf %lf %lf\n", a.x, a.y, b.x, b.y);
}
Exemplo n.º 20
0
// 線分p1-p2と線分q1-q2の距離
Real distSeg(P p1, P p2, P q1, P q2) {
    if (p1==p2 && q1==q2) return q1.dist(p1);
    if (p1==p2) return distSeg(q1, q2, p1);
    if (q1==q2) return distSeg(p1, p2, q1);
    if (!parallel(p1, p2, q1, q2)) {
        P r = intersection(p1, p2, q1, q2);
        if (on_seg(p1, p2, r) && on_seg(q1, q2, r)) return 0;
    }
    Real ret = min(distSeg(p1, p2, q1), distSeg(p1, p2, q2));
    ret = min(ret, min(distSeg(q1, q2, p1), distSeg(q1, q2, p2)));
    return ret;
}
Exemplo n.º 21
0
int
main(int argc, char *argv[])
{
	int ch, rval, seq;
	wchar_t *warg;
	const char *arg;
	size_t len;

	setlocale(LC_CTYPE, "");

	seq = 0;
	while ((ch = getopt(argc, argv, "d:s")) != -1)
		switch(ch) {
		case 'd':
			arg = optarg;
			len = mbsrtowcs(NULL, &arg, 0, NULL);
			if (len == (size_t)-1)
				err(1, "delimiters");
			warg = malloc((len + 1) * sizeof(*warg));
			if (warg == NULL)
				err(1, NULL);
			arg = optarg;
			len = mbsrtowcs(warg, &arg, len + 1, NULL);
			if (len == (size_t)-1)
				err(1, "delimiters");
			delimcnt = tr(delim = warg);
			break;
		case 's':
			seq = 1;
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (*argv == NULL)
		usage();
	if (!delim) {
		delimcnt = 1;
		delim = tab;
	}

	if (seq)
		rval = sequential(argv);
	else
		rval = parallel(argv);
	exit(rval);
}
Exemplo n.º 22
0
double solve()
{
	if(l1.a.y==l1.b.y || l2.a.y==l2.b.y || (!intersect_in(l1,l2)) ||
    parallel(l1,l2))
		return 0;

	if(l1.a.y>l1.b.y+eps)	swap(l1.a,l1.b);
	if(l2.a.y>l2.b.y+eps)	swap(l2.a,l2.b);

	point ip=intersection(l1,l2);

	if(l1.b.y<ip.y || l2.b.y+eps<ip.y)
		return 0;

	point h,l;
	bool flag=true;
	if(l1.b.y>l2.b.y+eps)
	{
		h=l1.b;
		l=l2.b;
	}
	else if(l1.b.y<l2.b.y-eps)
	{
		h=l2.b;
		l=l1.b;
	}
	else
	{
	    flag=false;
	    h=l2.b;
		l=l1.b;
	}

	if(flag && ((h.x>=l.x && ip.x+eps< l.x &&(l.y-ip.y)*(h.x-ip.x) < (l.x-ip.x)*(h.y-ip.y)+eps) ||
             (h.x<=l.x && ip.x> l.x+eps&&(l.y-ip.y)*(h.x-ip.x) > (l.x-ip.x)*(h.y-ip.y)-eps)))
		return 0;

	line tmp;
	tmp.a.x=min(min(l1.a.x,l2.a.x),min(l1.b.x,l2.b.x));
	tmp.b.x=max(max(l1.a.x,l2.a.x),max(l1.b.x,l2.b.x));
	tmp.a.y=tmp.b.y=l.y;

	point p1=intersection(tmp,l1);
	point p2=intersection(tmp,l2);

	double dist=p1.x-p2.x;
	if(dist<-eps) dist*=-1;
	return dist*(l.y-ip.y)/2;
}
Exemplo n.º 23
0
int convex_gen(const convex2 &a, convex2 &b) {
	std::deque<point2> q;
	convex2 t(a);
	q.push_back(t[0]), q.push_back(t[1]);
	for (int i = 2; i < t.size(); i++) {
		while (q.size() > 1) {
			point2 p1 = t[i]-q[q.size()-1], p2 = q[q.size()-1]-q[q.size()-2];
			if (p1 % p2 > 0 || parallel(p1, p2)) q.pop_back();
			else break;
		}
		q.push_back(t[i]);
	}
	b.clear();
	for (int i = 0; i < q.size(); i++) b.push_back(q[i]);
}
Exemplo n.º 24
0
// Move to coordinate of a node, and checking walls, assigning the values in adjacent arrays
void move_to_node(double curr_coord[2], struct node* node){
    printf("\t \t ### Moving to node: %d  ###\n",node->name );
    printf("Moving to coord: x %f y %f \n",node->x, node->y );
    move_to(curr_coord, node->x, node->y);
    printf(" Arrived at node[%d] ! \n", node->name);

    // Start mapping walls
    struct node* currentnode = node;
    currentnode->visited = 1;
    int currentfront = node_in_front(face_angle, currentnode);
    int currentleft = node_on_left(face_angle, currentnode);
    int currentright = node_on_right(face_angle, currentnode);
    int i = available_adjacent(currentnode);
    int j;

    if (no_wall_front() == 1){
        if (nodes[currentfront]->visited == 0){
            currentnode->adjacent[i] = nodes[currentfront]; 
            i = available_adjacent(currentnode);           
            j = available_adjacent(nodes[currentfront]);
            nodes[currentfront]->adjacent[j] = currentnode;
        }
        printf("There is no wall front , US dist:  %d \n", get_us_dist());
    }
    else if(no_wall_front() == 0){
        parallel(curr_coord);
    }
    if (no_wall_left() == 1){
        if (nodes[currentleft]->visited == 0){
            currentnode->adjacent[i] = nodes[currentleft];
            i = available_adjacent(currentnode);
            j = available_adjacent(nodes[currentleft]);
            nodes[currentleft]->adjacent[j] = currentnode;  
        }
        printf("There is NO wall left ! LEFT IR : %d\n", get_side_ir_dist(LEFT));
    }
    if (no_wall_right() == 1){
        if (nodes[currentright]->visited == 0){
            currentnode->adjacent[i] = nodes[currentright];
            i = available_adjacent(currentnode);
            j = available_adjacent(nodes[currentright]);
            nodes[currentright]->adjacent[j] = currentnode;        
        }
        printf("There is NO wall right ! RIGHT IR : %d \n", get_side_ir_dist(RIGHT));
    }
    printf("Checking ALL for node[%d] wall done!\n", node->name);

}
Exemplo n.º 25
0
int main(int argc, char *argv[]) {
  if (argc != 3) {print_usage(argc, argv);}

  int num_tasks = atoi(argv[2]);

  if (!strcmp(argv[1], "serial")) {
    serial(num_tasks);
  } else if (!strcmp(argv[1], "parallel")) {
    parallel(num_tasks);
  }
  else {
    print_usage(argc, argv);
  }

  printf("Main completed\n");
  pthread_exit(NULL);
}
Exemplo n.º 26
0
bool operator == (const line& p, const line& q) {
	if (!parallel(p, q))
		return false;

	auto t = 0.0;

	if (0 != q.u.x)
		t = (p.a.x - q.a.x) / q.u.x;
	else
		t = (p.a.y - q.a.y) / q.u.y;

	vector a = { q.a.x + t * q.u.x, q.a.y + t * q.u.y };

	if (std::abs(a.x - p.a.x) < epsilon && std::abs(a.y - p.a.y) < epsilon) {
		return true;
	}

	return false;
}
Exemplo n.º 27
0
void defiIOTiming::print(FILE* f) const {
  fprintf(f, "IOTiming '%s' '%s'\n", inst_, pin_);

  if (hasSlewRise())
    fprintf(f, "  Slew rise  %5.2f %5.2f\n",
       slewRiseMin(),
       slewRiseMax());

  if (hasSlewFall())
    fprintf(f, "  Slew fall  %5.2f %5.2f\n",
       slewFallMin(),
       slewFallMax());

  if (hasVariableRise())
    fprintf(f, "  variable rise  %5.2f %5.2f\n",
       variableRiseMin(),
       variableRiseMax());

  if (hasVariableFall())
    fprintf(f, "  variable fall  %5.2f %5.2f\n",
       variableFallMin(),
       variableFallMax());

  if (hasCapacitance())
    fprintf(f, "  capacitance %5.2f\n",
       capacitance());

  if (hasDriveCell())
    fprintf(f, "  drive cell '%s'\n",
       driveCell());

  if (hasFrom())
    fprintf(f, "  from pin '%s'\n",
       from());

  if (hasTo())
    fprintf(f, "  to pin '%s'\n",
       to());

  if (hasParallel())
    fprintf(f, "  parallel %5.2f\n",
       parallel());
}
static size_t computeEdgesAndIntersect(const GrMatrix& matrix,
                                       const GrMatrix& inverse,
                                       GrPoint* vertices,
                                       size_t numVertices,
                                       GrEdgeArray* edges,
                                       float sign) {
    if (numVertices < 3) {
        return 0;
    }
    matrix.mapPoints(vertices, numVertices);
    if (sign == 0.0f) {
        sign = isCCW(vertices, numVertices) ? -1.0f : 1.0f;
    }
    GrPoint p = sanitizePoint(vertices[numVertices - 1]);
    for (size_t i = 0; i < numVertices; ++i) {
        GrPoint q = sanitizePoint(vertices[i]);
        if (p == q) {
            continue;
        }
        GrDrawState::Edge edge = computeEdge(p, q, sign);
        edge.fZ += 0.5f;    // Offset by half a pixel along the tangent.
        *edges->append() = edge;
        p = q;
    }
    int count = edges->count();
    if (count == 0) {
        return 0;
    }
    GrDrawState::Edge prev_edge = edges->at(0);
    for (int i = 0; i < count; ++i) {
        GrDrawState::Edge edge = edges->at(i < count - 1 ? i + 1 : 0);
        if (parallel(edge, prev_edge)) {
            // 3 points are collinear; offset by half the tangent instead
            vertices[i].fX -= edge.fX * 0.5f;
            vertices[i].fY -= edge.fY * 0.5f;
        } else {
            vertices[i] = prev_edge.intersect(edge);
        }
        inverse.mapPoints(&vertices[i], 1);
        prev_edge = edge;
    }
    return edges->count();
}
Exemplo n.º 29
0
int main(){

    connect_to_robot();
    initialize_robot();
    set_origin();
    set_ir_angle(LEFT, -45);
    set_ir_angle(RIGHT, 45);
    initialize_maze();
    reset_motor_encoders();
    int i;
    for (i = 0; i < 17; i++){
        set_point(nodes[i]->x, nodes[i]->y);
    }
    double curr_coord[2] = {0, 0};
    map(curr_coord, nodes[0]);
    breadthFirstSearch(nodes[0]);
    reversePath(nodes[16]);
    printPath(nodes[0]);

    struct point* tail = malloc(sizeof(struct point));
    tail->x = nodes[0]->x;
    tail->y = nodes[0]->y;
    struct point* startpoint = tail;

    build_path(tail, nodes[0]);
    
    // Traverse to end node.
    while(tail->next){
        set_point(tail->x, tail->y); // Visual display for Simulator only.
        tail = tail->next;
    }
    tail->next = NULL; // Final node point to null.
    printf("tail: X = %f Y = %f \n", tail->x, tail->y);
    parallel(curr_coord);
    spin(curr_coord, to_rad(180));
    
    sleep(2);
    set_ir_angle(LEFT, 45);
    set_ir_angle(RIGHT, -45);

    mazeRace(curr_coord, nodes[0]);
    return 0;
}
// case with only one point in container
// the fitting plane must be horizontal by default
void test_one_point()
{
  std::list<Point> points;
  points.push_back(Point(FT(0),FT(0),FT(0)));

  // fit plane
  Plane plane;
  Line line;
  fit_point_set(points,plane,line);

  Point point(FT(0),FT(0),FT(0));
  Vector vec(FT(0),FT(0),FT(1));
  Plane horizontal_plane(point,vec);
  if(!parallel(horizontal_plane,plane))
  {
    std::cout << "failure" << std::endl;
    std::exit(1); // failure
  }
}