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;
}
Beispiel #2
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;
        }
Beispiel #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);
}
	int GetMax( TreeNode * root)
	{
		if(root == NULL)
			return 0;
		int leftMax = GetMax(root->left);
		int rightMax = GetMax(root->right);

		int currentMax = root->val;
		if(leftMax >0)
			currentMax += leftMax;
		if(rightMax > 0)
			currentMax += rightMax;
		if(currentMax > max)
			max = currentMax;

		if(leftMax > rightMax)	
		{
			if(leftMax >0)
				return root->val + leftMax;
			else 
				return root->val;
		}
		else		
		{
			if(rightMax >0)
				return root->val + rightMax;
			else
				return root->val;	
		}
	}
Beispiel #5
0
int wxSheetArrayEdge::FindMaxEdgeIndex(int val, int edge_size) const
{
    const int index = FindIndex(val, true);
    if (index < 0) return -1;
    // we know we're inside the 'index' element (or above or below the array)
    //   find which side is closer and if < edge_size return index
    const int diff = abs(GetMax(index) - val);
    const int diff_min = (index > 0) ? abs(GetMax(index-1) - val) : diff+edge_size+1; 

    const int min_diff = wxMin(diff, diff_min);
    if (min_diff > edge_size)
        return -1;
    else if (min_diff == diff)
        return index;
    else if (min_diff == diff_min)
        return index - 1;
    
    return -1;
    
/*   
    // FIXME I wonder if this really makes complete sense? check it...
    // eg. what would happen if size of cell was only 1 pixel, you couldn't resize it?
    if ( GetSize(index) > edge_size )
    {
        // We know that we are in index, test whether we are
        // close enough to lower or upper border, respectively.
        if ( abs(GetMax(index) - val) < edge_size )
            return index;
        else if ( (index > 0) && (val - GetMin(index) < edge_size) )
            return index - 1;
    }

    return -1;
*/    
}
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;
}
Beispiel #7
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);
	}
}
Beispiel #8
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);
}
Beispiel #9
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);
}
Beispiel #12
0
int GetTreeHeightPreorder2(const BTree root)
{
    deque<const BTree> dq;
    int TreeHeight=-1;
    while(-1)
    {
        for(;root!=NULL;root=root->LChild)
        {
            dq.push_back(root);
        }
        TreeHeight=GetMax(TreeHeight,(int)dq.size()-1);
        while(1)
        {
            //若该节点无新的子树,表示已经到头
            if(dq.empty()) return TreeHeight;
            //否则,调用实现,取其右子树
            const BTree parrent=dq.back();
            const BTree RChild=parrent->RChild;
            if(RChild && root !=RChild)
            {
                root=RChild;
                break;
            }
            //每次都要从左边起,都要判断
            root=parrent;
            dq.pop_back();
        }
    }
    return TreeHeight;
}
void dgCollisionScene::CalcAABB (const dgMatrix& matrix, dgVector& p0, dgVector& p1) const
{
	dgVector origin (matrix.TransformVector(m_boxOrigin));
	dgVector size (m_boxSize.m_x * dgAbsf(matrix[0][0]) + m_boxSize.m_y * dgAbsf(matrix[1][0]) + m_boxSize.m_z * dgAbsf(matrix[2][0]) + DG_MAX_COLLISION_PADDING,  
				   m_boxSize.m_x * dgAbsf(matrix[0][1]) + m_boxSize.m_y * dgAbsf(matrix[1][1]) + m_boxSize.m_z * dgAbsf(matrix[2][1]) + DG_MAX_COLLISION_PADDING,  
				   m_boxSize.m_x * dgAbsf(matrix[0][2]) + m_boxSize.m_y * dgAbsf(matrix[1][2]) + m_boxSize.m_z * dgAbsf(matrix[2][2]) + DG_MAX_COLLISION_PADDING,
				   dgFloat32 (0.0f));

	p0 = origin - size;
	p1 = origin + size;

#ifdef DG_DEBUG_AABB
	dgInt32 i;
	dgVector q0;
	dgVector q1;
	dgMatrix trans (matrix.Transpose());
	for (i = 0; i < 3; i ++) {
		q0[i] = matrix.m_posit[i] + matrix.RotateVector (BoxSupportMapping(trans[i].Scale (-1.0f)))[i];
		q1[i] = matrix.m_posit[i] + matrix.RotateVector (BoxSupportMapping(trans[i]))[i];
	}

	dgVector err0 (p0 - q0);
	dgVector err1 (p1 - q1);
	dgFloat32 err; 
	err = GetMax (size.m_x, size.m_y, size.m_z) * 0.5f; 
	_ASSERTE ((err0 % err0) < err);
	_ASSERTE ((err1 % err1) < err);
#endif
}
Beispiel #14
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;
}
void WaveletMatrixBuilder::BuildWithAVals(WaveletMatrix& wm, vector<uint32_t>& avals){
	uint32_t max_val = GetMax(vals_);
	uint32_t max_depth = GetLen(max_val);
	wm.max_val_ = max_val;
	wm.layers_.resize(max_depth);

	vector<uint32_t> zeros;
	vector<uint32_t> ones;

	vector<uint32_t> zero_avals;
	vector<uint32_t> one_avals;
	zeros.swap(vals_);
	zero_avals = avals;
	for (uint32_t depth = 0; depth < max_depth; ++depth){
		vector<uint32_t> next_zeros;
		vector<uint32_t> next_ones;
		vector<uint32_t> next_zero_avals;
		vector<uint32_t> next_one_avals;

		RSDicBuilder rsdb;
		FilterWithAVals(zeros, zero_avals, max_depth - depth - 1, next_zeros, next_ones, next_zero_avals, next_one_avals, rsdb);
		FilterWithAVals(ones,  one_avals,  max_depth - depth - 1, next_zeros, next_ones, next_zero_avals, next_one_avals, rsdb);
		zeros.swap(next_zeros);
		ones.swap(next_ones);
		zero_avals.swap(next_zero_avals);
		one_avals.swap(next_one_avals);
		rsdb.Build(wm.layers_[depth]);
	}
	copy(zero_avals.begin(), zero_avals.end(), avals.begin());
	copy(one_avals.begin(), one_avals.end(), avals.begin() + zero_avals.size());
}
Beispiel #16
0
 long GetMax(long u) {
         if (W[u]) return W[u];
         long Max = 0;
         for (Edge* p = min[u]; p; p = p->next)
                 Max = std::max(Max, GetMax(p->y));
         return W[u] = Max + 1;
 }
Beispiel #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 << "}";
}
Beispiel #18
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;
}
Beispiel #19
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);
    }
  }
}
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());
}
int main (void)
{
    ImplDecl id;
    int i = 4; int j = 6;
    int k = GetMax(i, j);
    return (GlobalExt() ? k - id.MethodF(42) : 42);
}
Beispiel #22
0
int main()
{
	int iFirst = 10;
	int iSecond = 20;
	printf("The max value is %d\n",GetMax(iFirst,iSecond));
	
	return 0;
};
Float RatingBar::GetProgressPerStar()
{
    if (mNumStars > 0) {
        return 1.f * GetMax() / mNumStars;
    } else {
        return 1.f;
    }
}
Beispiel #24
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};
}
Beispiel #25
0
void Learn::test2(){
	int i=5, j=6, k;

    long l=10, m=5, n;

    k=GetMax(i,j);

    n=GetMax(l,m);

    cout << k << endl;

    cout << n << endl;

    //注意传入类型要写
    pairs<int> myobject(100, 75);
    cout<< myobject.getmax()<<endl;
}
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;
}
	int maxPathSum(TreeNode *root) {
		// Start typing your C/C++ solution below
		// DO NOT write int main() function
		if(root == NULL)
			return 0;
		max = root->val;
		GetMax(root);
		return max;
	}
Beispiel #28
0
void CXFA_Occur::SetMin(int32_t iMin) {
  iMin = (iMin < 0) ? 1 : iMin;
  m_pNode->SetInteger(XFA_ATTRIBUTE_Min, iMin, FALSE);
  int32_t iMax = GetMax();
  if (iMax > 0 && iMax < iMin) {
    iMax = iMin;
    m_pNode->SetInteger(XFA_ATTRIBUTE_Max, iMax, FALSE);
  }
}
Beispiel #29
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]);
	}
}
Beispiel #30
0
void CXFA_Occur::SetMin(int32_t iMin) {
  iMin = (iMin < 0) ? 1 : iMin;
  JSObject()->SetInteger(XFA_Attribute::Min, iMin, false);

  int32_t iMax = GetMax();
  if (iMax > 0 && iMax < iMin) {
    iMax = iMin;
    JSObject()->SetInteger(XFA_Attribute::Max, iMax, false);
  }
}