Example #1
0
        void Gao(long a1, long a2, long b1, long b2) {
                a1 = f[a1], b1 = f[b1], a2 = f[a2], b2 = f[b2];
                if (a1 > a2) std::swap(a1, a2);
                if (b1 > b2) std::swap(b1, b2);
                if (a1 == b1 && a2 == b2) {c2++; return;}
                if (a1 == b1) a1 = b1 = n + 1;
                if (a1 == b2) a1 = b2 = n + 1;
                if (a2 == b1) a2 = b1 = n + 1;
                if (a2 == b2) a2 = b2 = n + 1;
 
                bool t1 = false, t2 = false ,t3 = false;
                for (long i = 0; i < 16; i++) {
                        long d = 0;
                        memset(W, 0, sizeof W);
                        if (i & 1) d += GetMax(a1);
                        else d += GetMin(a1);
                        if (i & 2) d += GetMax(a2);
                        else d += GetMin(a2);
                        if (i & 4) d -= GetMax(b1);
                        else d -= GetMin(b1);
                        if (i & 8) d -= GetMax(b2);
                        else d -= GetMin(b2);
                        if (d > 0) if (t2 || t3) return; else t1 = true;
                        if (d== 0) if (t1 || t3) return; else t2 = true;
                        if (d < 0) if (t1 || t2) return; else t3 = true;
                }
                c1 += t1, c2 += t2, c3 += t3;
        }
Example #2
0
dgCollisionScene::dgNode::dgNode(dgNode* const sibling, dgNode* const myNode) :
    m_parent(sibling->m_parent), m_left(sibling), m_right(myNode), m_fitnessNode(
        NULL)
{
  if (m_parent)
  {
    if (m_parent->m_left == sibling)
    {
      m_parent->m_left = this;
    }
    else
    {
      _ASSERTE(m_parent->m_right == sibling);
      m_parent->m_right = this;
    }
  }

  sibling->m_parent = this;
  myNode->m_parent = this;

  dgNode* const left = m_left;
  dgNode* const right = m_right;

  m_minBox = dgVector(GetMin(left->m_minBox.m_x, right->m_minBox.m_x),
      GetMin(left->m_minBox.m_y, right->m_minBox.m_y),
      GetMin(left->m_minBox.m_z, right->m_minBox.m_z), dgFloat32(0.0f));
  m_maxBox = dgVector(GetMax(left->m_maxBox.m_x, right->m_maxBox.m_x),
      GetMax(left->m_maxBox.m_y, right->m_maxBox.m_y),
      GetMax(left->m_maxBox.m_z, right->m_maxBox.m_z), dgFloat32(0.0f));

  dgVector side0(m_maxBox - m_minBox);
  dgVector side1(side0.m_y, side0.m_z, side0.m_x, dgFloat32(0.0f));
  m_surfaceArea = side0 % side1;
}
Example #3
0
void CGraphicOption::OnTimer(UINT nIDEvent) 
{
	if(nIDEvent==1)
	{
		m_iTick++;
		if(m_iTick>CGraphicOption_TIMERINITIAL)
		{
			// We begin doing 1/4 the pulses, then move to 1/3 after TIMERBOOST pulses, and so on
			int iBoostState=
				CGraphicOption_TIMERBOOSTSTAGES-(m_iTick-CGraphicOption_TIMERINITIAL)/CGraphicOption_TIMERBOOST;
			if(iBoostState>1 && (m_iTick%iBoostState!=0))
				return;

			// Update position
			m_iPos+=m_iTimerDirection;
			if(m_iPos<GetMin()) m_iPos=GetMax();
			if(m_iPos>GetMax()) m_iPos=GetMin();

			// Repaint text
			CRect rect(m_iButtonX,0,m_pgBackground->Width()-m_iButtonX,
				m_pgBackground->Height());
			InvalidateRect(&rect,FALSE);
		}
	}
	else
		CWnd::OnTimer(nIDEvent);
}
Example #4
0
int a_haff(Byte* in_buf, int in_count, Byte* out_buf, int* out_count){
  for (int i = 0; i < in_count; i++){
    Reapets[in_buf[i]]++;
  }

  Root* R = malloc(byte_count * sizeof(Root*)), T = malloc(byte_count * sizeof(Root*)), t, t1, t2;
  int c_R = 0, c_T = 0;
  for (int i = 0; i < 256; i++){
    if (Reapets[i] != 0){
      R[c_R] = malloc(sizeof(Root));
      (*R[c_R]).left = NULL;
      (*R[c_R]).right = NULL;
      (*R[c_R]).reapet = Reapets[i];
      (*R[c_R]).value = i;
      c_R++;
    }
  }
  while (c_R + c_T > 1){
    t1 = GetMin(R, &c_R, T, &c_T);
    t2 = GetMin(R, &c_R, T, &c_T);
    t = malloc(sizeof(Root));
    (*t).left = t1;
    (*t).right = t2;
    (*t).reapet = (*t1).reapet + (*t2).reapeat;
    AddToArray(T, &c_T, t);
  }
}
dgFloat32 dgCollisionScene::CalculateSurfaceArea (const dgNode* const node0, const dgNode* const node1, dgVector& minBox, dgVector& maxBox) const
{
	minBox = dgVector (GetMin (node0->m_minBox.m_x, node1->m_minBox.m_x), GetMin (node0->m_minBox.m_y, node1->m_minBox.m_y), GetMin (node0->m_minBox.m_z, node1->m_minBox.m_z), dgFloat32 (0.0f));
	maxBox = dgVector (GetMax (node0->m_maxBox.m_x, node1->m_maxBox.m_x), GetMax (node0->m_maxBox.m_y, node1->m_maxBox.m_y), GetMax (node0->m_maxBox.m_z, node1->m_maxBox.m_z), dgFloat32 (0.0f));		
	dgVector side0 (maxBox - minBox);
	dgVector side1 (side0.m_y, side0.m_z, side0.m_x, dgFloat32 (0.0f));
	return side0 % side1;
}
Example #6
0
void dgMatrix::TransformBBox (const dgVector& p0local, const dgVector& p1local, dgVector& p0, dgVector& p1) const
{
	dgVector box[8];

	box[0][0] = p0local[0];
	box[0][1] = p0local[1];
	box[0][2] = p0local[2];
	box[0][3] = hacd::HaF32(1.0f);

	box[1][0] = p0local[0];
	box[1][1] = p0local[1];
	box[1][2] = p1local[2];
	box[1][3] = hacd::HaF32(1.0f);

	box[2][0] = p0local[0];
	box[2][1] = p1local[1];
	box[2][2] = p0local[2];
	box[2][3] = hacd::HaF32(1.0f);

	box[3][0] = p0local[0];
	box[3][1] = p1local[1];
	box[3][2] = p1local[2];
	box[3][3] = hacd::HaF32(1.0f);

	box[4][0] = p1local[0];
	box[4][1] = p0local[1];
	box[4][2] = p0local[2];
	box[4][3] = hacd::HaF32(1.0f);

	box[5][0] = p1local[0];
	box[5][1] = p0local[1];
	box[5][2] = p1local[2];
	box[1][3] = hacd::HaF32(1.0f);

	box[6][0] = p1local[0];
	box[6][1] = p1local[1];
	box[6][2] = p0local[2];
	box[6][3] = hacd::HaF32(1.0f);

	box[7][0] = p1local[0];
	box[7][1] = p1local[1];
	box[7][2] = p1local[2];
	box[7][3] = hacd::HaF32(1.0f);

	TransformTriplex (&box[0].m_x, sizeof (dgVector), &box[0].m_x, sizeof (dgVector), 8);

	p0 = box[0];
	p1 = box[0];
	for (hacd::HaI32 i = 1; i < 8; i ++) {
		p0.m_x = GetMin (p0.m_x, box[i].m_x);
		p0.m_y = GetMin (p0.m_y, box[i].m_y);
		p0.m_z = GetMin (p0.m_z, box[i].m_z);

		p1.m_x = GetMax (p1.m_x, box[i].m_x);
		p1.m_y = GetMax (p1.m_y, box[i].m_y);
		p1.m_z = GetMax (p1.m_z, box[i].m_z);
	}
}
Example #7
0
void CGraphicOption::OnLButtonDown(UINT nFlags, CPoint point) 
{
	if(m_fOverLeft)
	{
		// Set the button as down and repaint it
		m_fOverLeft=FALSE;
		m_fDownLeft=TRUE;
		OnMouseMove(nFlags,point);

		// Change the text string
		m_iPos--;
		if(m_iPos<GetMin()) m_iPos=GetMax();

		// Repaint text
		CRect rect(m_iButtonX,0,m_pgBackground->Width()-m_iButtonX,
			m_pgBackground->Height());
		InvalidateRect(&rect,FALSE);

		// Begin timer to make more moves
		m_iTick=0;
		m_iTimerDirection=-1;
		SetTimer(1,CGraphicOption_TIMERPULSE,NULL);

		// Notify parent
		SetSel(m_iPos,TRUE);
	}
	if(m_fOverRight)
	{
		// Set the button as down and repaint it
		m_fOverRight=FALSE;
		m_fDownRight=TRUE;
		OnMouseMove(nFlags,point);

		// Change the text string
		m_iPos++;
		if(m_iPos>GetMax()) m_iPos=GetMin();

		// Repaint text
		CRect rect(m_iButtonX,0,m_pgBackground->Width()-m_iButtonX,
			m_pgBackground->Height());
		InvalidateRect(&rect,FALSE);

		// Begin timer to make more moves
		m_iTick=0;
		m_iTimerDirection=1;
		SetTimer(1,CGraphicOption_TIMERPULSE,NULL);

		// Notify parent
		SetSel(m_iPos,TRUE);
	}
	
	CWnd::OnLButtonDown(nFlags, point);
}
Example #8
0
void MAS::Progress::Draw(Bitmap &canvas) {
   Bitmap bmp = GetBitmap();
   if (orientation == 1) {
      bmp.HorizontalTile(canvas, 0, 0, 0, w(), 2);
      int ww = (int)(w()*GetPosition()/(GetMax() - GetMin()));
      bmp.HorizontalTile(canvas, 1, 0, 0, ww, 2);
   }
   else {
      bmp.VerticalTile(canvas, 0, 0, 0, h(), 2);
      int hh = (int)(h()*GetPosition()/(GetMax() - GetMin()));
      bmp.VerticalTile(canvas, 1, 0, 0, hh, 2);
   }
}
		float CAxisAlignedBoundingBox::GetLengthFromPoint(
			const Graphic::CVector3& point) const
		{
			float SqLen = 0;
			for (int i = 0; i < 3; i++)
			{
				if (point[i] < GetMin()[i])
					SqLen += (point[i] - GetMin()[i]) * (point[i] - GetMin()[i]);
				if (point[i] > GetMax()[i])
					SqLen += (point[i] - GetMax()[i]) * (point[i] - GetMax()[i]);
			}
			return sqrt(SqLen);
		};
void	WED_GISBoundingBox::MoveCorner(GISLayer_t l,int corner, const Vector2& delta)
{
	Point2	p1,p2;
	GetMin()->GetLocation(l,p1);
	GetMax()->GetLocation(l,p2);
	switch(corner) {
	case 0:	p1.x_ += delta.dx;	p1.y_ += delta.dy;	break;
	case 1: p2.x_ += delta.dx;	p1.y_ += delta.dy;	break;
	case 2:	p2.x_ += delta.dx;	p2.y_ += delta.dy;	break;
	case 3: p1.x_ += delta.dx;	p2.y_ += delta.dy;	break;
	}
	GetMin()->SetLocation(l,p1);
	GetMax()->SetLocation(l,p2);
}
void	WED_GISBoundingBox::GetCorners(GISLayer_t l,Point2 corners[4]) const
{
	GetMin()->GetLocation(l,corners[0]);
	GetMax()->GetLocation(l,corners[2]);
	corners[1] = Point2(corners[2].x(),corners[0].y());
	corners[3] = Point2(corners[0].x(),corners[2].y());
}
Example #12
0
void CCue::OnMouseMove(UINT nFlags, POINT point)
{
    CFlowZap *fc = ((CFlowZap *)m_Parent);
    ptr = fc->GetInstructionAtPixel(point);

    if (ptr == NULL)
    {
        ptr = oldPtr;
    }

    if (oldPtr != ptr)
    {
        // DETERMINE THE RECTANGLE TO REDRAW
        CRect r(0, GetMin(ptr->GetCenter(), oldPtr->GetCenter()) - 7 , 25, GetMax(ptr->GetCenter(), oldPtr->GetCenter()) + 7);
        CString SoundPath = ((CRobotWorldApp*)AfxGetApp())->m_DefaultPath;
        SoundPath += "/sounds/choice.wav";

        if (fc->IsSoundOn())
        {
            PlaySound(SoundPath, NULL, SND_FILENAME | SND_ASYNC);
        }

        fc->RedrawWindow(r, NULL, RDW_INVALIDATE | RDW_ERASE);
    }

    oldPtr = ptr;
}
Example #13
0
void CStatistic::PrintStats(std::string const& physicalQuantity)const
{
	std::cout << "Max " << physicalQuantity.c_str() << ":" << GetMax() << std::endl;
	std::cout << "Min " << physicalQuantity.c_str() << ":" << GetMin() << std::endl;
	std::cout << "Average " << physicalQuantity.c_str() << ":" << GetAverage() << std::endl;
	std::cout << "----------------" << std::endl;
}
Example #14
0
void MatrixStat::DumpSimple(const std::string& parent, std::ostream& os) const {
  os.setf(std::ios::fixed);
  os << std::setprecision(2); 
  os << "[matrix_stat] {\"name\": \"" << parent << "\""
     << ", \"qps\": " << GetQps()
     << ", \"count\": " << GetCount()
     << ", \"avg\": " << GetAvg()
     << ", \"max\": " << GetMax()
     << ", \"min\": " << GetMin();
  if (HasTimeDistribute()) {
    os << ", \"99\": " << GetTimeDistribute(0.99)
       << ", \"95\": " << GetTimeDistribute(0.95)
       << ", \"90\": " << GetTimeDistribute(0.9)
       << ", \"80\": " << GetTimeDistribute(0.8)
       << ", \"50\": " << GetTimeDistribute(0.5);
  } else {
    os << ", \"value\": " << GetValue();
  }
  os << "}" << std::endl;

  if (HasResult()) {
    for (const auto& pair : child_) {
      std::string sub = parent + "." + pair.first; 
      pair.second.DumpSimple(sub, os);
    }
  }
}
Example #15
0
 Node<Key, Val>* DeleteInternal(Node<Key, Val>* h, Key key){
   if (h == NULL) return NULL;
   if (Comp()(key, h->key)){
     if (!IsRED(h->left) && 
         h->left != NULL &&
         !IsRED(h->left->left)){
       h = MoveREDLeft(h);
     }
     h->left = DeleteInternal(h->left, key);
   } else {
     if (IsRED(h->left)){
       h = RotateRight(h);
     }
     if ((key == h->key) && (h->right == NULL)){
       return NULL;
     }
     if (!IsRED(h->right) && 
         h->right != NULL && 
         !IsRED(h->right->left)){
       h = MoveREDRight(h);
     }
     if (key == h->key){
       Node<Key, Val>* min_node = GetMin(h->right);
       h->key = min_node->key;
       h->val = min_node->val;
       h->right = DeleteMin(h->right);
     } else {
       h->right = DeleteInternal(h->right, key);
     }
   }
   return FixUp(h);
 }
Example #16
0
 long GetMin(long u) {
         if (W[u]) return W[u];
         long Min = 4;
         for (Edge* p = max[u]; p; p = p->next)
                 Min = std::min(Min, GetMin(p->y));
         return W[u] = Min - 1;
 }
Example #17
0
void MatrixStat::Dump(std::ostream& os) const {
  os.setf(std::ios::fixed);
  os << std::setprecision(2); 
  os << "{\"qps\": " << GetQps()
     << ", \"count\": " << GetCount()
     << ", \"avg\": " << GetAvg()
     << ", \"max\": " << GetMax()
     << ", \"min\": " << GetMin();
  if (HasTimeDistribute()) {
    os << ", \"99\": " << GetTimeDistribute(0.99)
       << ", \"95\": " << GetTimeDistribute(0.95)
       << ", \"90\": " << GetTimeDistribute(0.9)
       << ", \"80\": " << GetTimeDistribute(0.8)
       << ", \"50\": " << GetTimeDistribute(0.5);
  } else {
    os << ", \"value\": " << GetValue();
  }
  if (HasResult()) {
    os << ",\n    \"Result\": {";
    bool first = true;
    for (const auto& pair : child_) {
      if (first == true) {
        first = false;
        os << "\n      ";
      } else {
        os << ",\n      ";
      }
      os << "\"" << pair.first << "\": ";
      pair.second.Dump(os);
    }
    os << "}";
  }
  os << "}";
}
void			WED_GISBoundingBox::GetBounds		(GISLayer_t l,   Bbox2&  bounds) const
{
	CacheBuild(cache_Spatial);
	Bbox2	b2;
	GetMin()->GetBounds(l,bounds);
	GetMax()->GetBounds(l,b2);
	bounds += b2;
}
Example #19
0
int32_t CXFA_Occur::GetMax() {
  int32_t iMax = 1;
  if (m_pNode) {
    if (!m_pNode->TryInteger(XFA_ATTRIBUTE_Max, iMax, TRUE))
      iMax = GetMin();
  }
  return iMax;
}
Example #20
0
std::tuple<int32_t, int32_t, int32_t> CXFA_Occur::GetOccurInfo() {
  int32_t iMin = GetMin();
  int32_t iMax = GetMax();

  Optional<int32_t> init =
      JSObject()->TryInteger(XFA_Attribute::Initial, false);
  return {iMin, iMax, init && *init >= iMin ? *init : iMin};
}
Example #21
0
void Triangle::AccumulateMinMax(Vector3d &min, Vector3d &max, Matrix4d T)
{
	Vector3d tmin = GetMin(T);
	Vector3d tmax = GetMax(T);
	for (uint i = 0; i < 3; i++) {
		min[i] = MIN(tmin[i], min[i]);
		max[i] = MAX(tmax[i], max[i]);
	}
}
Example #22
0
void CXFA_Occur::SetMax(int32_t iMax) {
  iMax = (iMax != -1 && iMax < 1) ? 1 : iMax;
  m_pNode->SetInteger(XFA_ATTRIBUTE_Max, iMax, FALSE);
  int32_t iMin = GetMin();
  if (iMax != -1 && iMax < iMin) {
    iMin = iMax;
    m_pNode->SetInteger(XFA_ATTRIBUTE_Min, iMin, FALSE);
  }
}
Example #23
0
void CXFA_Occur::SetMax(int32_t iMax) {
  iMax = (iMax != -1 && iMax < 1) ? 1 : iMax;
  JSObject()->SetInteger(XFA_Attribute::Max, iMax, false);

  int32_t iMin = GetMin();
  if (iMax != -1 && iMax < iMin) {
    iMin = iMax;
    JSObject()->SetInteger(XFA_Attribute::Min, iMin, false);
  }
}
Example #24
0
void CRulerItem::TrackHorzPosTwips(int nXPos, BOOL /*bOnRuler*/)
{
    int nMin = GetMin();
    int nMax = GetMax();
    if (nXPos < nMin)
        nXPos = nMin;
    if (nXPos > nMax)
        nXPos = nMax;
    SetHorzPosTwips(nXPos);
}
Example #25
0
void dgThreads::CreateThreaded(dgInt32 threads)
{
  if (m_numOfThreads)
  {
    DestroydgThreads();
  }

#ifdef _WIN32
  if ((threads > 1) && (m_numberOfCPUCores > 1))
  {
    m_numOfThreads = GetMin(threads, m_numberOfCPUCores);

    m_emptySlot = CreateSemaphoreA(NULL, DG_MAXQUEUE, DG_MAXQUEUE, NULL);
    m_workToDo = CreateSemaphoreA(NULL, 0, DG_MAXQUEUE, NULL);
    m_exit = CreateEventA(NULL, TRUE, FALSE, NULL);

    InitializeCriticalSection(&m_criticalSection);

    m_topIndex = 0;
    m_bottomIndex = 0;
    m_workInProgress = 0;
    for (dgInt32 i = 0; i < m_numOfThreads; i++)
    {
      m_threadhandles[i] = (HANDLE) _beginthreadex(NULL, 0, ThreadExecute,
          &m_localData[i], 0, NULL);
    }
  }
#else
  if ((threads > 1) && (m_numberOfCPUCores > 1))
  {
#ifdef TARGET_OS_IPHONE
    m_numOfThreads = 0;
#else
    m_numOfThreads = (threads<m_numberOfCPUCores ? threads : m_numberOfCPUCores);
#endif

    m_emptySlot = DG_MAXQUEUE;
    m_workToDo = 0;
    m_workToDoSpinLock = 0;
    m_exit = false;
    m_criticalSection = 0;

    m_topIndex = 0;
    m_bottomIndex = 0;
    m_workInProgress = 0;

#ifndef TARGET_OS_IPHONE
    for(dgInt32 i=0; i < m_numOfThreads; i++)
    {
      pthread_create( &m_threadhandles[i], NULL, ThreadExecute, &m_localData[i]);
    }
#endif
  }
#endif
}
Example #26
0
void CGraphicOption::SetSel(const int iIndex,const BOOL fNotify)
{
	ASSERT(iIndex>=GetMin() && iIndex<=GetMax());
	m_iPos=iIndex;

	// Post a combo-box selchange message
	if(fNotify)
		GetParent()->PostMessage(WM_COMMAND,
			(CBN_SELCHANGE << 16) | GetDlgCtrlID(),
			(LPARAM)GetSafeHwnd());
}
Example #27
0
// add all these to get shape volume
double Triangle::projectedvolume(Matrix4d T) const
{
  if (Normal.z==0) return 0;
  Triangle xyproj = Triangle(Vector3d(A.x,A.y,0),
			     Vector3d(B.x,B.y,0),
			     Vector3d(C.x,C.y,0));
  Vector3d min = GetMin(T);
  Vector3d max = GetMax(T);
  double vol =  xyproj.area()*0.5*(max.z+min.z);
  if (Normal.z<0) vol=-vol; 
  return vol;
}
Example #28
0
void dgApi GetMinMax (dgVector &minOut, dgVector &maxOut, const dgFloat32* const vertexArray, dgInt32 vCount, dgInt32 strideInBytes)
{
	dgInt32 stride = dgInt32 (strideInBytes / sizeof (dgFloat32));
	const dgFloat32* vArray = vertexArray + stride;

	_ASSERTE (stride >= 3);
 	minOut = dgVector (vertexArray[0], vertexArray[1], vertexArray[2], dgFloat32 (0.0f)); 
	maxOut = dgVector (vertexArray[0], vertexArray[1], vertexArray[2], dgFloat32 (0.0f)); 

	for (dgInt32 i = 1; i < vCount; i ++) {
		minOut.m_x = GetMin (minOut.m_x, vArray[0]);
		minOut.m_y = GetMin (minOut.m_y, vArray[1]);
		minOut.m_z = GetMin (minOut.m_z, vArray[2]);

		maxOut.m_x = GetMax (maxOut.m_x, vArray[0]);
		maxOut.m_y = GetMax (maxOut.m_y, vArray[1]);
		maxOut.m_z = GetMax (maxOut.m_z, vArray[2]);

		vArray += stride;
	}
}
Example #29
0
    Range Range::Intersect(const Range& range) const
    {
        size_t min = std::max(GetMin(), range.GetMin());
        size_t max = std::min(GetMax(), range.GetMax());

        if(min >= max) // No intersection.
        {
            return InvalidRange();
        }

        return Range(min, max);
    }
Example #30
0
bool LineSegLineSegIntersect(const LineSegment * line1, const LineSegment * line2)
{
	Point3D point1 = line1->GetPoint1();
	Point3D point2 = line2->GetPoint1();
	Point3D point3 = line1->GetPoint2();
	Point3D point4 = line2->GetPoint2();

	Float innerLeft = GetMax(point1.GetX(), point2.GetX());
	Float innerRight = GetMin(point3.GetX(), point4.GetX());

	return ((line1->GetValueAt(innerLeft) >= line2->GetValueAt(innerLeft)) == (line1->GetValueAt(innerRight) >= line2->GetValueAt(innerRight)));
}