Example #1
0
int main (void)
{
  struct MyTime first_time = { 10, 501};
  struct MyTime second_time = { 2, 500};
  struct MyTime min_time = { 99999, 999999};
  struct MyTime max_time = { 0, 0};
  struct MyTime diff_time = { 0, 0};
  
  print_time ("First:", first_time);
  print_time ("Second:", second_time);

  print_time ("Min:", Min(first_time,second_time));
  print_time ("Max:", Max(first_time,second_time));
  print_time ("Diff:", Diff(second_time, first_time));
  
  getCurrentMyTime(& first_time);
  sleep (10);
  getCurrentMyTime(& second_time);
  
  print_time ("Average:", Avg(Diff(second_time,first_time), 10));
  
   diff_time.SEC = first_time.SEC-second_time.SEC;
   diff_time.FRAC_SEC = first_time.FRAC_SEC-second_time.FRAC_SEC;
    
  /* If the substraction results in negative answer */

   if(diff_time.FRAC_SEC < 0)
    {
        diff_time.FRAC_SEC = SCALE + diff_time.FRAC_SEC;
            if(diff_time.SEC > 0 )
               diff_time.SEC = diff_time.SEC-1;
            else
               diff_time.FRAC_SEC*=-1;
    }

   if(diff_time.FRAC_SEC < min_time.FRAC_SEC)
    min_time.FRAC_SEC = diff_time.FRAC_SEC;
  
   if(diff_time.FRAC_SEC > max_time.FRAC_SEC)
    max_time.FRAC_SEC = diff_time.FRAC_SEC;

   if(diff_time.SEC < min_time.SEC)
    min_time.SEC = diff_time.SEC;
  
   if(diff_time.SEC > max_time.SEC)
    max_time.SEC = diff_time.SEC;

   print_time("Old Min:", min_time);
   print_time("Old Max:", max_time);

  return 0;
}
Diffs Node::getDiffs (const RobotState& last, const RobotState& current)
{
  Diffs diffs;
  const ros::Time now = ros::Time::now();;
  
  // Use the fact that JointState is empty iff this is the first time around
  if (last.isEmpty() || now >= last_keyframe_+keyframe_interval_)
  {
    last_keyframe_ = now;
    if (last.isEmpty())
      cerr << "Last is empty, so using all diffs" << endl;
    else
      cerr << "Keyframe interval elapsed, so saving entire joint state" << endl;
    diffs.is_keyframe = true;
    for (size_t i=0; i<current.joint_state->position.size(); i++)
    {
      diffs.new_joint_states.push_back(Diff(i, current.joint_state->position[i]));
    }
    diffs.pose_diff = true;
    diffs.new_pose = current.pose;
  }
  else
  {
    for (size_t i=0; i<current.joint_state->position.size(); i++)
    {
      if (fabs(current.joint_state->position[i]-
               last.joint_state->position[i])>distance_threshold_ &&
          !joint_ignored_[i])
      {
        cerr << "Joint " << current.joint_state->name[i] << " value " <<
          current.joint_state->position[i] << " differs from " <<
          last.joint_state->position[i] << endl;
        diffs.new_joint_states.push_back(Diff(i, current.joint_state->position[i]));
      }
    }

    if ((current.pose.get() && !last.pose.get()) ||
        (!current.pose.get() && last.pose.get()) ||
        ((current.pose.get() && last.pose.get() &&
          poseDistance(*current.pose, *last.pose)>distance_threshold_)))
    {
      cerr << "Current pose: " << (bool)current.pose.get() << "; last pose: "
           << (bool)last.pose.get() << endl;
      diffs.pose_diff = true;
      diffs.new_pose = current.pose;
    }
  }
  return diffs;
}
Example #3
0
EXPORT_C TAny* RDbRow::SetColumnWidthL(TDbColNo aColNo,TInt aWidth)
// set the width for column aCol to Width
// add extra NULL columns to buffer as required
// return pointer to data for that column
	{
	__ASSERT(aColNo>0);
	TDbCell* pC=Column(--aColNo);
	if (pC==0)
		{		// add extra NULL columns to buffer
		if (aWidth==0)
			return 0;	// setting to NULL, don't bother padding
		TInt cFill=(aColNo-iColumn)*sizeof(TInt);
		ExtendL(cFill+TDbCell::Size(aWidth));
		pC=iCell;
		Mem::FillZ(pC,cFill);
		pC=PtrAdd(pC,cFill);		// set cache
		SetCache(pC,aColNo);
		}
	else
		{
		TInt adjust=TDbCell::Size(aWidth)-pC->Size();	// how much to add
		if (adjust!=0)
			{
			ExtendL(adjust);
			pC=iCell;		// may have moved in extension
			TDbCell* pNext=pC->Next();
			TDbCell* pAdjust=PtrAdd(pNext,adjust);
			Mem::Move(pAdjust,pNext,Diff(pAdjust,iLast));
			}
		}
	pC->SetLength(aWidth);
	return pC->Data();
	}
Example #4
0
void Camera::rotate( float x, float y )
{
    Vector po = getVSpherePos((float) m_LastMouseX, m_LastMouseY);
    Vector pn = getVSpherePos(x, y);
    
    if((po-pn).lengthSquared() < 0.0001f )
        return;
    
    float cosangle = po.dot(pn);
    if(cosangle>1.0f) cosangle=1.0f;
    if(cosangle<-1.0f) cosangle=-1.0f;
    
    const float angle = acos(cosangle);
    Vector RotAxis = pn.cross(po);
    RotAxis.normalize();
    
    
    //Vector Diff = m_Position-m_Target;
    Vector Diff(0,0,(m_Position-m_Target).length());
    
    Vector RotDiff = rotateAxisAngle(Diff, RotAxis, angle);
    
    Vector cdir = m_Target-m_Position;
    cdir.normalize();
    Vector cup = m_Up;
    Vector cright = cdir.cross(cup);
    cright.normalize();
    cup = cright.cross(cdir);

    Vector RotDiffW;
    RotDiffW.X = cright.X * RotDiff.X + cup.X * RotDiff.Y +  -cdir.X * RotDiff.Z;
    RotDiffW.Y = cright.Y * RotDiff.X + cup.Y * RotDiff.Y +  -cdir.Y * RotDiff.Z;
    RotDiffW.Z = cright.Z * RotDiff.X + cup.Z * RotDiff.Y +  -cdir.Z * RotDiff.Z;
    m_Rotation = RotDiffW - (m_Position-m_Target);
}
Example #5
0
 Diff diff_to_index(Repository const & repo, Tree & t, git_diff_options const & opts)
 {
     git_diff * diff;
     auto op_res = git_diff_tree_to_index(&diff, repo.ptr(), t.ptr(), nullptr, &opts);
     assert(op_res == 0);
     return Diff(diff);
 }
bool DiffWrapperBase<T, TDiff>::GetElementDiffs(
    google::protobuf::RepeatedPtrField<ElementDiff> *dst,
    const google::protobuf::RepeatedPtrField<Element> &old_elements,
    const google::protobuf::RepeatedPtrField<Element> &new_elements) {
  bool differs = false;
  assert(dst != nullptr);
  int i = 0;
  int j = 0;
  while (i < old_elements.size() && j < new_elements.size()) {
    const Element &old_element = old_elements.Get(i);
    const Element &new_element = new_elements.Get(i);

    if (Diff(old_element, new_element)) {
      ElementDiff *diff = dst->Add();
      Element *old_elementp = nullptr;
      Element *new_elementp = nullptr;
      if (!diff || !(old_elementp = diff->mutable_old()) ||
          !(new_elementp = diff->mutable_new_())) {
        llvm::errs() << "Failed to add diff element\n";
        ::exit(1);
      }
      *old_elementp = old_element;
      *new_elementp = new_element;
      diff->set_index(i);
      differs = true;
    }
    i++;
    j++;
  }
  if (old_elements.size() != new_elements.size()) {
    GetExtraElementDiffs(dst, i, j, old_elements, new_elements);
    differs = true;
  }
  return differs;
}
Example #7
0
 Diff diff_index_to_workdir(Repository const & repo, git_diff_options const & opts)
 {
     git_diff * diff;
     auto op_res = git_diff_index_to_workdir(&diff, repo.ptr(), nullptr, &opts);
     assert(op_res == 0);
     return Diff(diff);
 }
Example #8
0
 Matrix<double,ndim,1> Edge::jacobian(const double & t) const
 {
   GeoPoint & a = *M_points[0];
   GeoPoint & b = *M_points[1];
   GeoPoint Diff(b-a);
   return Matrix<double,ndim,1>(Diff[0],Diff[1]);
 }
Example #9
0
// B here is the "reduced" matrix.  Square matrices w/ Row=Domain=Range only.
double test_with_matvec_reduced_maps(const Epetra_CrsMatrix &A, const Epetra_CrsMatrix &B, const Epetra_Map & Bfullmap){
  const Epetra_Map & Amap  = A.DomainMap();
  Epetra_Vector Xa(Amap), Ya(Amap), Diff(Amap);
  const Epetra_Map *Bmap  = Bfullmap.NumMyElements() > 0 ? &B.DomainMap() : 0;
  Epetra_Vector *Xb = Bmap ? new Epetra_Vector(*Bmap) : 0;
  Epetra_Vector *Yb = Bmap ? new Epetra_Vector(*Bmap) : 0;

  Epetra_Vector Xb_alias(View,Bfullmap, Bmap ? Xb->Values(): 0);
  Epetra_Vector Yb_alias(View,Bfullmap, Bmap ? Yb->Values(): 0);

  Epetra_Import Ximport(Bfullmap,Amap);

  // Set the input vector
  Xa.SetSeed(24601);
  Xa.Random();
  Xb_alias.Import(Xa,Ximport,Insert);

  // Do the multiplies
  A.Apply(Xa,Ya);
  if(Bmap) B.Apply(*Xb,*Yb);

  // Check solution
  Epetra_Import Yimport(Amap,Bfullmap);
  Diff.Import(Yb_alias,Yimport,Insert);


  Diff.Update(-1.0,Ya,1.0);
  double norm;
  Diff.Norm2(&norm);

  delete Xb; delete Yb;
  return norm;
}
Example #10
0
 Diff diff(Repository const & repo, Tree & a, Tree & b, git_diff_options const & opts)
 {
     git_diff * diff;
     auto op_res = git_diff_tree_to_tree(&diff, repo.ptr(), a.ptr(), b.ptr(), &opts);
     assert(op_res == 0);
     return Diff(diff);
 }
Example #11
0
 double Fem::Edge::measure() const
 {
   Point const & a=*M_points[0];
   Point const & b=*M_points[1];
   GeoPoint Diff(b-a);
   return std::sqrt(Diff[0]*Diff[0]+Diff[1]*Diff[1]);
 }
void DiffSideBySidePanel::OnVertical(wxRibbonButtonBarEvent& event)
{
    m_splitter->Unsplit();
    m_splitter->SplitVertically(m_splitterPageLeft, m_splitterPageRight);
    m_config.SetViewMode(DiffConfig::kViewVerticalSplit);
    Diff();
}
void DiffSideBySidePanel::OnHorizontal(wxCommandEvent& event)
{
    m_splitter->Unsplit();
    m_splitter->SplitHorizontally(m_splitterPageLeft, m_splitterPageRight);
    m_config.SetViewMode(DiffConfig::kViewHorizontalSplit);
    Diff();
}
Example #14
0
int main(){
    int len = 3000;
    gsl_vector *v = gsl_vector_alloc(len);
    for (double i=0; i< len; i++) gsl_vector_set(v, i, 1./(i+1));
    double square;
    gsl_blas_ddot(v, v, &square);
    printf("1 + (1/2)^2 + (1/3)^2 + ...= %g\n", square);

    double pi_over_six = gsl_pow_2(M_PI)/6.;
    Diff(square, pi_over_six);

    /* Now using apop_dot, in a few forms.
       First, vector-as-data dot itself.
       If one of the inputs is a vector,
       apop_dot puts the output in a vector-as-data:*/
    apop_data *v_as_data = &(apop_data){.vector=v};
    apop_data *vdotv = apop_dot(v_as_data, v_as_data);
    Diff(gsl_vector_get(vdotv->vector, 0), pi_over_six);

    /* Wrap matrix in an apop_data set. */
    gsl_matrix *v_as_matrix = apop_vector_to_matrix(v);
    apop_data dm = (apop_data){.matrix=v_as_matrix};

    // (1 X len) vector dot (len X 1) matrix --- produce a scalar (one item vector).
    apop_data *mdotv = apop_dot(v_as_data, &dm);
    double scalarval = apop_data_get(mdotv);
    Diff(scalarval, pi_over_six);

    //(len X 1) dot (len X 1) --- bad dimensions.
    apop_opts.verbose=-1; //don't print an error.
    apop_data *mdotv2 = apop_dot(&dm, v_as_data);
    apop_opts.verbose=0; //back to safety.
    assert(mdotv2->error);

    // If we want (len X 1) dot (1 X len) --> (len X len),
    // use apop_vector_to_matrix.
    apop_data dmr = (apop_data){.matrix=apop_vector_to_matrix(v, .row_col='r')};
    apop_data *product_matrix = apop_dot(&dm, &dmr);
    //The trace is the sum of squares:
    gsl_vector_view trace = gsl_matrix_diagonal(product_matrix->matrix);
    double tracesum = apop_sum(&trace.vector);
    Diff(tracesum, pi_over_six);

    apop_data_free(product_matrix);
    gsl_matrix_free(dmr.matrix);
}
Example #15
0
// Find the SnapPoint nearest to time t
int SnapManager::Find(double t)
{
   int len = (int)mSnapPoints->GetCount();
   int index = Find(t, 0, len);

   // At this point, either index is the closest, or the next one
   // to the right is.  Keep moving to the right until we get a
   // different value
   int next = index + 1;
   while(next+1 < len && Get(next) == Get(index))
      next++;

   // Now return whichever one is closer to time t
   if (next < len && Diff(t, next) < Diff(t, index))
      return next;
   else
      return index;
}
Example #16
0
int main(int argc, char *argv[])
{
  Value I(1), m(4);
  for(int a = 0; a < 1000; a++)
    m = Diff (I, m);

  if (!(m / 4 == I))
    abort ();
  return 0;
}
void DiffSideBySidePanel::OnRefreshDiff(wxCommandEvent& event)
{
    if(m_stcLeft->IsModified() || m_stcRight->IsModified()) {
        wxStandardID res = ::PromptForYesNoDialogWithCheckbox(
            _("Refreshing the view will lose all your changes\nDo you want to continue?"), "DiffRefreshViewDlg");
        if(res != wxID_YES) {
            return;
        }
    }
    Diff();
}
Example #18
0
//return 1 if _cost can be paid with current data, 0 otherwise
int ManaCost::canAfford(ManaCost * _cost)
{
    ManaCost * diff = Diff(_cost);
    int positive = diff->isPositive();
    delete diff;
    if (positive)
    {
        return 1;
    }
    return 0;
}
Example #19
0
double BinaryImage::SSD(const BinaryImage& T)
{
	Matrix Diff(32, 32, 1);
	double sum = 0;
	for (int i = 0; i < 32; i++)
	{
		for (int j = 0; j < 32; j++)
		{
			Diff.Set(i, j, (Get(i, j) - T.Get(i, j)));
			sum += Diff.Get(i, j)*Diff.Get(i, j);
		}
	}
	return sum;
}
int main(void)
{
	int a = 7;
	int b = 6;
	printf("a = %d,b = %d",a,b);
	a = a^b;
	b = a^b;
	a = a^b;
	printf("a = %d,b = %d",a,b);
	int d = Number(11);
	int c = Diff(9,6);
	printf("c = %d",c);
	return 0;
}
Example #21
0
HRESULT STDMETHODCALLTYPE CPopupMenu::InvokeCommand( __in CMINVOKECOMMANDINFO *pici)
{
	if(HIWORD(((CMINVOKECOMMANDINFOEX *)pici)->lpVerbW)){
		return S_OK;
	}
	else
	{
		if(1 == LOWORD(pici->lpVerb)){
			SetEnv();
		}
		else if(2 == LOWORD(pici->lpVerb)){
			Update();
		}
		else if(3 == LOWORD(pici->lpVerb)){
			Checkout();
		}
		else if(4 == LOWORD(pici->lpVerb)){
			Commit();
		}
		else if(5 == LOWORD(pici->lpVerb)){
			Checkin();
		}
		else if(6 == LOWORD(pici->lpVerb)){
			Cancel();
		}
		else if(7 == LOWORD(pici->lpVerb)){
			Add();
		}
		else if(8 == LOWORD(pici->lpVerb)){
			Revert();
		}
		else if(9 == LOWORD(pici->lpVerb)){
			Merge();
		}
		else if(10 == LOWORD(pici->lpVerb)){
			ShowLog();
		}
		else if(11 == LOWORD(pici->lpVerb)){
			Diff();
		}
		else if(12 == LOWORD(pici->lpVerb)){
			Compare();
		}
		else if(13 == LOWORD(pici->lpVerb)){
			UpdateRelyFiles();
		}
	}

	return S_OK;
}
Example #22
0
 void OnConnect() {
   gettime(&m_connect, NULL);
   m_b_active = true;
   {
     double tconnect = Diff(m_create, m_connect);
     //
     g_min_time = tconnect < g_min_time ? tconnect : g_min_time;
     g_max_time = tconnect > g_max_time ? tconnect : g_max_time;
     g_tot_time += tconnect;
     g_ant += 1;
   }
   SendBlock();
   m_b_client = true;
 }
Example #23
0
int ManaCost::pay(ManaCost * _cost)
{
    int result = MANA_PAID;
    ManaCost * toPay = NEW ManaCost();
    toPay->copy(_cost);
    ManaCost * diff = Diff(toPay);
    for (int i = 0; i < Constants::NB_Colors; i++)
    {
        cost[i] = diff->getCost(i);
    }
    delete diff;
    delete toPay;
    return result;
    //TODO return 0 if can't afford the cost!
}
Example #24
0
int main()
{
#ifndef _WIN32
	Mutex mutex;
	Semaphore sema(1);
	struct timeval start;
	struct timeval tt;
	double d;

	Utility::GetTime(&start);
	for (int i = 0; i < 100000; i++)
		lock(mutex, i);
	Utility::GetTime(&tt);
	d = Diff(start, tt);
	printf("%.4f sec\n", d);

	Utility::GetTime(&start);
	for (int i = 0; i < 100000; i++)
		lock(sema, i);
	Utility::GetTime(&tt);
	d = Diff(start, tt);
	printf("%.4f sec\n", d);
#endif
}
Example #25
0
  void OnContent() {
//    std::cout << GetContentLength() << std::endl;
    gettime(&m_reply, NULL);
    {
      double treply = Diff(m_send, m_reply);
      //
      g_min_time2 = treply < g_min_time2 ? treply : g_min_time2;
      g_max_time2 = treply > g_max_time2 ? treply : g_max_time2;
      g_tot_time2 += treply;
      g_ant2 += 1;
    }
    gBytesIn += GetBytesReceived(true);
    gBytesOut += GetBytesSent(true);
    CreateNew();
  }
Example #26
0
void SRKIICalc(double AL, double AConst, double K,double Rx,iol_formula* SRKIIValues)
{
  double i;
  double Emmetropia, Emmetropia_Rounded,Emmetropia_New,CR,REFR1;
  double Diff_In_Emmetropia, Diff_Add;
  double REFR;
  int Loop;
  printf("\r\nSRK II\n");
  if (AL < 20.0)
   AConst = AConst + 3;
  else if ((AL >= 20.0) & (AL < 21.0))
   AConst = AConst + 2;
  else if ((AL >= 21.0) & (AL < 22.0))
   AConst = AConst + 1;
  else if ((AL >= 22) & (AL < 24.5))
   AConst = AConst;
  else if (AL >= 24.5)
   AConst = AConst - 0.5;

  Emmetropia = AConst - (0.9 * K) - (2.5 * AL);
  SRKIIValues->PEMM = Emmetropia;

  Emmetropia_Rounded = floor(Emmetropia);

  Diff_In_Emmetropia = Emmetropia - Emmetropia_Rounded;


  if (Emmetropia < 14.0)
   CR = 1.0;
  else if (Emmetropia >= 14.0)
   CR = 1.25;

  Diff_Add = Diff(Diff_In_Emmetropia);

  Emmetropia_New = Emmetropia_Rounded + Diff_Add;
  Diff_In_Emmetropia = Emmetropia - Emmetropia_New;
  REFR1 = Diff_In_Emmetropia / CR;
  Loop=0;
  for (i = Emmetropia_New - 1.0; i <= Emmetropia_New + 1.0; i = i + 0.5)
   {
    REFR = (REFR1 + (Emmetropia_New - i) / CR);
	SRKIIValues->PORx[Loop] = REFR;
    SRKIIValues->IOLPower[Loop] = i;
//	printf("\r\n%5.2f,%5.2f",SRKIIValues->IOLPower[Loop],SRKIIValues->PORx[Loop]);
	Loop++;
 }
 //printf("\r\n");
}
Example #27
0
void Life::tick()
{
    if( running && has_focus )
    {
        if( sec_scope.nextScope_skip() )
        {
            speed=Diff(step_number,map.getStepNumber());
        }

        if( divider.tick() )
        {
            map.step();

            redraw();
        }
    }
}
Example #28
0
TInt RDbRow::ReallocL(TInt aMaxSize)
//
// Grow the buffer to aMaxSize, return the offset of buffer movement
// leave iLast and cache untouched
//
	{
	__ASSERT(aMaxSize>MaxSize());
	if (!Owned())
		__LEAVE(KErrTooBig);	// cannot reallocate if not owned
//
	aMaxSize+=EGranularity-1;
	aMaxSize&=~(EGranularity-1);
	TDbCell* buf=(TDbCell*)User::ReAllocL(iFirst,aMaxSize);
	TInt move=Diff(iFirst,buf);
	iFirst=buf;
	iEnd=PtrAdd(buf,aMaxSize);
	return move;
	}
Example #29
0
int CGitDiff::DiffCommit(const CTGitPath& path1, const CTGitPath& path2, const CString& r1, const CString& r2, bool bAlternative)
{
	if (path1.GetWinPathString().IsEmpty())
	{
		CFileDiffDlg dlg;
		dlg.SetDiff(nullptr, r2, r1);
		dlg.DoModal();
	}
	else if (path1.IsDirectory())
	{
		CFileDiffDlg dlg;
		dlg.SetDiff(&path1, r2, r1);
		dlg.DoModal();
	}
	else
		Diff(&path1, &path2, r1, r2, false, false, 0, bAlternative);
	return 0;
}
Example #30
0
  void OnConnect() {
    gettime(&m_connect, NULL);
    {
      double tconnect = Diff(m_create, m_connect);
      //
      g_min_time = tconnect < g_min_time ? tconnect : g_min_time;
      g_max_time = tconnect > g_max_time ? tconnect : g_max_time;
      g_tot_time += tconnect;
      g_ant += 1;
    }
    gettime(&m_send, NULL);

    // send request header
    HttpGetSocket::OnConnect();

    // send body
    Send(g_data);
  }