bool
attached (poly_line pl1, poly_line pl2) {
  point p1= inf (pl1), q1= sup (pl1);
  point p2= inf (pl2), q2= sup (pl2);
  //cout << "<< " << p1 << ", " << q1 << "\n";
  //cout << ">> " << p2 << ", " << q2 << "\n";
  if (p2[1] > q1[1]) return true;
  if (p2[0] > q1[0]) return false;
  return true;
}
Beispiel #2
0
    Class* open_class(STATE, GCToken gct, CallFrame* call_frame, Module* under, Object* super, Symbol* name, bool* created) {
      bool found;

      *created = false;

      Object* obj = under->get_const(state, name, &found);

      OnStack<4> os(state, under, super, name, obj);

      if(found) {
        TypedRoot<Object*> sup(state, super);

        if(Autoload* autoload = try_as<Autoload>(obj)) {
          obj = autoload->resolve(state, gct, call_frame, true);

          // Check if an exception occurred
          if(!obj) return NULL;
        }

        // Autoload::resolve will return nil if code loading failed, in which
        // case we ignore the autoload.
        if(!obj->nil_p()) {
          return check_superclass(state, call_frame, as<Class>(obj), sup.get());
        }
      }

      *created = true;
      return add_class(state, under, super, name);
    }
Beispiel #3
0
void	annexe(char *str, char **tab, int i, char *opt)
{
  int	k;
  char	*tmp;
  int	n;

  k = 0;
  n = 0;
  tmp = my_xmalloc(sizeof(*tmp) * (my_strlen(str) + 2));
  while (str[i] != '\0')
    {
      if (str[i] == ':')
	{
	  tmp[k] = '/';
	  tab[n] = my_strcat(tmp, opt);
	  free(tmp);
	  n++;
	  tmp = my_xmalloc(sizeof(*tmp) * (my_strlen(str) + 2));
	  i++;
	  k = 0;
	}
      tmp[k++] = str[i++];
    }
  tmp[k] = '/';
  tab[n] = my_strcat(tmp, opt);
  free(tmp);
  sup(tab, n, opt);
}
Beispiel #4
0
void run_dim_bchunk_iteration_test_round(TestTool& t, int rowlen) {
	typedef P p;
	int size = 8*1024*1024;// 1 megabyte
	explib::cvec<p> dim;
	dim[0] = rowlen;
	if (P::DIM ==2 ) {
		int rows = size / rowlen;
		dim[1] = rows;
	} else {
		int rows = size / rowlen;
		rows /= 512;
		dim[1] = rows;
		dim[2] = 512;
	}
	explib::bits data;
	data.resize(dim.volume());

	for (int i = 0; i < data.size(); ++i) {
		if ((rand() % 200) == 0) { // fill around every third chunk
			data[i] = true;
		}
	}

	int true_chunks = 0;
	TimeSentry time;
	explib::dim_row_iterator<p> i(dim);
	while (i) {
		explib::cvec<p> beginv = i.begin();
		int begini = dim.offset(beginv);
		explib::bits_ref row = data.from(begini, i.length());
		auto j = row.chunk_istream2<explib::false_tail_fill>();
		while (j) {
			explib::bchunk c;
			j>>c;
			if (c) true_chunks++;
		}
		++i;
	}
	long us = time.us();

	t.record({sup()<<"rowlen:"<<rowlen, "prop:us"}, us);
	t.record({sup()<<"rowlen:"<<rowlen, "prop:true"}, true_chunks);
}
Beispiel #5
0
	void QuadTree::nn (coo z, QuadIndex & qi) const {
		if (n<=m) for (auto & w : pts) {
			int newnorm = sup (z-w);
			if (newnorm < qi.d) { qi.d = newnorm; qi.z = w; }
		} else {
			int i0 = index(z); if (store[ch+i0] -> n) store[ch+i0] -> nn (z,qi);
			for (int i=0; i<4; ++i) if (i != i0) {
				QuadTree *q = store[ch+i].get();
				if ((q -> n) && (q -> odist(z) < qi.d)) q -> nn (z,qi);
			}
		}
	}
	if(xTaskGetTickCount()-saveDRequest>(TIMEDELAYREQUEST/portTICK_RATE_MS)){
		saveDRequest=xTaskGetTickCount();
		delayRequest();
	}
	#endif

}
void printfClock(Clock clock){
			if(clock.sign==true){
				pc.printf("%lu s,%u\r\n",clock.second,(unsigned int)clock.halfmillis);
			}
			else{
				pc.printf("-%lu s,%u\r\n",clock.second,(unsigned int)clock.halfmillis);
			}
}
void updateClock(void){
		Clock diff;
		if(timeProt.correction.previousSignOffset==timeProt.offset.sign){
			timeProt.correction.previousSignOffset=timeProt.offset.sign;
			timeProt.correction.previoustimeOffset.second=timeProt.correction.currentTimeOffsetSync.second;
			timeProt.correction.previoustimeOffset.halfmillis=timeProt.correction.currentTimeOffsetSync.halfmillis;
			readClock(&timeProt.correction.currentTimeOffsetSync);
			if(timeProt.correction.previoustimeOffset.second!=0){
				if(sup(timeProt.correction.currentTimeOffsetSync,timeProt.correction.previoustimeOffset)){
												
					diff=subClock(timeProt.correction.currentTimeOffsetSync,timeProt.correction.previoustimeOffset);
					//printf("diff: ");
					//printfClock(diff);
					timeProt.correction.sumTime=sumClock(timeProt.correction.sumTime,diff);
					sumOffset=sumClock(sumOffset,timeProt.offset);
					/*printf("sumOffset: ");
					printfClock(sumOffset);
					printf("sumClock: ");
					printfClock(timeProt.correction.sumTime);
					
					printf("nb corrr  : %d",timeProt.correction.nbCorrection);
					*/
					timeProt.correction.nbCorrection++;
				}
				else{
					resetSofftwareCorrection();
				}
			}
		}
		else{
			resetSofftwareCorrection();
		}
		timeProt.correction.previousSignOffset=timeProt.offset.sign;
		Clock timeCopy;
Beispiel #7
0
// trie les membres du groupe selon un certain critère (X ou Y)
void trierSelon(Groupe *g, CRITERE c){
	int i, j;
	PP_Unit u;
	
	// réalisation du tri (tri par insertion)
	for (i = 1 ; i < g->nbMembres ; i++){
		u = g->membres[i];
		j = i;
		while (j > 0 && sup(g->membres[j-1], u, c)){
			g->membres[j] = g->membres[j - 1];
			j = j-1;
		}
		g->membres[j] = u;
	}
}
Beispiel #8
0
bool BitLatticeManipulator::mix()
{
   bool updated = false;

   for (auto & b : best)
   {
      const auto c = current.find(b.first);
      if (c != current.end())
      {
         const auto cur_lattice = c->second;
         const auto best_lattice = b.second;
         const auto sup_lattice = sup(cur_lattice, best_lattice, b.first);
         if (best_lattice !=  sup_lattice)
         {
            b.second = sup_lattice;
            updated = true;
         }
      }
   }
   return updated;
}
Beispiel #9
0
char* convertGame(game newGame)
{
    int n = game_nb_pieces(newGame);
    cpiece *arrPieces;
    arrPieces = malloc(sizeof (piece) * n);
    for (int i = 0; i < n; i++) {
        arrPieces[i] = game_piece(newGame, i);
    }
    //Sort
    for (int i = 0; i < (n - 1); i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (sup(arrPieces[j], arrPieces[j + 1])) {
                cpiece swap = arrPieces[j];
                arrPieces[j] = arrPieces[j + 1];
                arrPieces[j + 1] = swap;
            }
        }
    }
    char *parsed = serialize(arrPieces, n);
    free(arrPieces);
    return parsed;
}
Beispiel #10
0
    Class* open_class(STATE, CallFrame* call_frame, Module* under, Object* super, Symbol* name, bool* created) {
      bool found;

      *created = false;

      Object* obj = under->get_const(state, name, &found);
      if(found) {
        TypedRoot<Object*> sup(state, super);

        if(Autoload* autoload = try_as<Autoload>(obj)) {
          obj = autoload->resolve(state, call_frame);

          // Check if an exception occurred
          if(!obj) return NULL;
        }

        return check_superclass(state, call_frame, as<Class>(obj), sup.get());
      }

      *created = true;
      return add_class(state, under, super, name);
    }
Beispiel #11
0
bool BitLatticeManipulator::update_current(std::deque<bit_lattice> res, unsigned int output_uid)
{
   bool out_is_signed =
      signed_var.find(output_uid) != signed_var.end() or
      tree_helper::is_int(TM, output_uid);
   if (res.size() > 0)
   {
      sign_reduce_bitstring(res, out_is_signed);
   }
   if (res.size() > 0)
   {
      auto cur_lattice = current.at(output_uid);
      auto best_lattice = best.at(output_uid);
      auto sup_lattice = sup(res, best_lattice, output_uid);
      if (cur_lattice !=  sup_lattice)
      {
         current[output_uid] = sup_lattice;
         return true;
      }
   }
   return false;
}
Beispiel #12
0
int main()
{
  Employee empl("John Burke", 25.0);
  Manager mgr("Jan Kovacs", 1200.0, true);
  Supervisor sup("Denise Zephyr", 780.0, "Accounting");

  // Assume all employees worked 40 hours this period.

  cout << "For Employee:" << endl;
  cout << "Name: " << empl.getName() << endl;
  cout << "Pay: " << empl.pay(40.0) << endl;

  cout << "Changing the Employee's name..." << endl;
  empl.setName("Doug Conners");
  cout << "New Name: " << empl.getName() << endl;

  cout << endl;
  cout << "For Manager:" << endl;
  cout << "Name: " << mgr.getName() << endl;
  cout << "Salaried: " << mgr.getSalaried() << endl;
  cout << "Pay: " << mgr.pay(40.0) << endl;

  cout << "Changing the Manager's salaried status..." << endl;
  mgr.setSalaried(false);
  cout << "New Pay: " << mgr.pay(40.0) << endl;

  cout << endl;
  cout << "For Supervisor:" << endl;
  cout << "Name: " << sup.getName() << endl;
  cout << "Pay: " << sup.pay(40.0) << endl;
  cout << "Dept: " << sup.getDept() << endl;

  cout << "Changing the Supervisor's pay rate..." << endl;
  sup.setPayRate(900.0);
  cout << "New Pay: " << sup.pay(40.0) << endl;

  return 0;
}
Beispiel #13
0
fcppt::random::distribution::parameters::uniform_real<
	FloatType
>
fcppt::random::distribution::parameters::uniform_real<
	FloatType
>::convert_to(
	distribution const &_dist
)
{
	return
		uniform_real(
			min(
				fcppt::random::distribution::decorated_value(
					_dist.a()
				)
			),
			sup(
				fcppt::random::distribution::decorated_value(
					_dist.b()
				)
			)
		);
}
	void test_block_tridiagonal_solve () {
		// io::parameters <double> params ("../input/block_parameters.txt");
		// omp_set_num_threads(params.nmp);

		int id = process_messenger->get_id ();
		int np = process_messenger->get_np ();
		int n = 60, nrhs = 70, ntop = 0, nbot = 0;
		if (id != 0) {
			ntop = 1;
		}
		if (id != np - 1) {
			nbot = 1;
		}

		std::vector <double> sub (n * nrhs, 0.0);
		std::vector <double> diag (n * nrhs, 0.0);
		std::vector <double> sup (n * nrhs, 0.0);
		std::vector <double> subcopy (n * nrhs, 0.0);
		std::vector <double> diagcopy (n * nrhs, 0.0);
		std::vector <double> supcopy (n * nrhs, 0.0);
		std::vector <double> supsup (n * nrhs, 0.0);
		std::vector <int> ipiv (n * nrhs, 0);

		std::vector <double> x (2 * n * nrhs + 8 * np * nrhs, 0.0);
		std::vector <int> xipiv (2 * np * nrhs, 0);

		std::vector <double> b (n * nrhs, 0.0);
		std::vector <double> bcopy (n * nrhs, 0.0);

		int info;

		srand (1);
		for (int i = 0; i < nrhs; ++i) {
			for (int j = 0; j < n; ++j) {
				sub [i * n + j] = rand () % 100;
				subcopy [i * n + j] = sub [i * n + j];
				diag [i * n + j] = rand () % 100;
				diagcopy [i * n + j] = diag [i * n + j];
				sup [i * n + j] = rand () % 100;
				supcopy [i * n + j] = sup [i * n + j];
				b [i * n + j] = rand () % 100;
				bcopy [i * n + j] = b [i * n + j];
			}
		}
		
		try {
			linalg::block::tridiag_factorize (id, np, n - ntop - nbot, &sub [0], &diag [0], &sup [0], &supsup [0], &ipiv [0], &x [0], &xipiv [0], &info, nrhs);

			linalg::block::tridiag_solve (id, np, n - ntop - nbot,  &sub [0], &diag [0], &sup [0], &supsup [0], &ipiv [0], &b [0], &x [0], &xipiv [0], &info, nrhs);
		} catch (std::exception& except) {
			std::cout << except.what () << '\n';
		}

		for (int j = 0; j < nrhs; ++j) {
			bcopy [j * n] -= diagcopy [j * n] * b [j * n] + supcopy [j * n] * b [1 + j * n];
			for (int i = 1; i < n - 1; ++i) {
				bcopy [i + j * n] -= subcopy [i + j * n] * b [i - 1 + j * n] + diagcopy [i + j * n] * b [i + j * n] + supcopy [i + j * n] * b [i + 1 + j * n];
			}
			bcopy [n - 1 + j * n] -= subcopy [n - 1 + j * n] * b [n - 2 + j * n] + diagcopy [n - 1 + j * n] * b [n - 1 + j * n];
		}
	
		std::vector <double> edge_0 (nrhs), edge_n (nrhs), redge_0 (nrhs), redge_n (nrhs);
	
		for (int i = 0; i < nrhs; ++i) {
			edge_0 [i] = b [i * n];
			edge_n [i] = b [i * n + n - 1];
		}

		if (id != 0) {
			process_messenger->send (nrhs, &edge_0 [0], id - 1, 0);
		}
		if (id != np - 1) {
			process_messenger->recv (nrhs, &redge_n [0], id + 1, 0);
			for (int i = 0; i < nrhs; ++i) {
				bcopy [i * n + n - 1] -= supcopy [i * n + n - 1] * redge_n [i];
			}
		}
		if (id != np - 1) {
			process_messenger->send (nrhs, &edge_n [0], id + 1, 1);
		}
		if (id != 0) {
			process_messenger->recv (nrhs, &redge_0 [0], id - 1, 1);
			for (int i = 0; i < nrhs; ++i) {
				bcopy [i * n] -= subcopy [i * n] * redge_0 [i];
			}
		}
		
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < nrhs; ++j) {
				TSM_ASSERT_DELTA ("Tridiagonal block solver failure", bcopy [j * n + i], 0.0, TEST_TINY);
			}
		}
	}
Beispiel #15
0
EXPORT(do_inf)(value vy, value vb)
{
  /* noalloc */
  I_VAL(vy) = interval(Double_val(vb), sup(I_VAL(vy)));
  return(Val_unit);
}
	if(xTaskGetTickCount()-saveDRequest>(TIMEDELAYREQUEST/portTICK_RATE_MS)){
		saveDRequest=xTaskGetTickCount();
		delayRequest();
	}
	#endif

}
void printfClock(Clock clock){
			if(clock.sign==true){
				hmi.printf("%lu s,%u\r\n",clock.second,(unsigned int)clock.halfmillis);
			}
			else{
				hmi.printf("-%lu s,%u\r\n",clock.second,(unsigned int)clock.halfmillis);
			}
}
void updateClock(void){
		Clock diff;
		if(timeProt.correction.previousSignOffset==timeProt.offset.sign){
			timeProt.correction.previousSignOffset=timeProt.offset.sign;
			timeProt.correction.previoustimeOffset.second=timeProt.correction.currentTimeOffsetSync.second;
			timeProt.correction.previoustimeOffset.halfmillis=timeProt.correction.currentTimeOffsetSync.halfmillis;
			readClock(&timeProt.correction.currentTimeOffsetSync);
			if(timeProt.correction.previoustimeOffset.second!=0){
				if(sup(timeProt.correction.currentTimeOffsetSync,timeProt.correction.previoustimeOffset)){
												
					diff=subClock(timeProt.correction.currentTimeOffsetSync,timeProt.correction.previoustimeOffset);
					//printf("diff: ");
					//printfClock(diff);
					timeProt.correction.sumTime=sumClock(timeProt.correction.sumTime,diff);
					sumOffset=sumClock(sumOffset,timeProt.offset);
					/*printf("sumOffset: ");
					printfClock(sumOffset);
					printf("sumClock: ");
					printfClock(timeProt.correction.sumTime);
					
					printf("nb corrr  : %d",timeProt.correction.nbCorrection);
					*/
					timeProt.correction.nbCorrection++;
				}
				else{
					resetSofftwareCorrection();
				}
			}
		}
		else{
			resetSofftwareCorrection();
		}
		timeProt.correction.previousSignOffset=timeProt.offset.sign;
		Clock timeCopy;
		readClock(&timeCopy);


		
		timeCopy=sumClock(timeCopy,timeProt.offset);//add offset
		writeClock(timeCopy);
		uint8_t state;
		state=stateLed;
		report(timeProt.offset);
		if(timeManage.halfmillis<(RTC_FREQ/2)){//all 500ms
			stateLed=LOW;
		}
		else{
			stateLed=HIGH;