void CMemoryViewMIPSWnd::RefreshLayout() { auto rc = GetClientRect(); const int addressEditHeight = Framework::Win32::PointsToPixels(21); m_addressEdit->SetSize(rc.Right(), addressEditHeight); m_memoryView->SetPosition(0, addressEditHeight); m_memoryView->SetSize(rc.Right(), rc.Bottom() - addressEditHeight); }
App::PointInt Viewer::calculateWindowTopLeft(ResizePositionMethod method, const SizeInt &newSize ) { wxDisplay display(DisplayFromPointFallback(PositionScreen())); auto rtDesktop = wxToRect(display.GetClientArea()); switch (method) { case ResizePositionMethod::PositionToScreen: return rtDesktop.TopLeft() + RoundCast((rtDesktop.Dimensions() - newSize) * 0.5f); case ResizePositionMethod::PositionToCurrent: { auto pt = AnchorCenter() + RoundCast(newSize * -0.5f); if ((pt.X + newSize.Width) > rtDesktop.Right()) { pt.X = rtDesktop.Right() - newSize.Width; } else if (pt.X < rtDesktop.Left()) { pt.X = rtDesktop.Left(); } if (pt.Y + newSize.Height > rtDesktop.Bottom()) { pt.Y = rtDesktop.Bottom() - newSize.Height; } else if (pt.Y < rtDesktop.Top()) { pt.Y = rtDesktop.Top(); } AnchorTL(pt); return pt; } case ResizePositionMethod::PositionNothing: { // Cap to screen PointInt pt = AnchorTL(); if ((pt.X + newSize.Width) > rtDesktop.Right()) pt.X=rtDesktop.Right()-newSize.Width; else if (pt.X < rtDesktop.Left()) pt.X = rtDesktop.Left(); if ((pt.Y + newSize.Height) > rtDesktop.Bottom()) pt.Y=rtDesktop.Bottom()-newSize.Height; else if (pt.Y < rtDesktop.Top()) pt.Y=rtDesktop.Top(); AnchorCenter(pt + RoundCast(newSize * 0.5f)); return pt; } default: DO_THROW(Err::InvalidParam, "Invalid reposition method: " + ToAString(method)); } }
void IR5(void *p) { while(1) { UpdateLeftPWM(400); //Velocity Setting UpdateRightPWM(400); //Velocity Setting if( sen_dat[2]<170) //IR 5 { Stop(); vTaskSuspend(xforward); if( ADC_Data[2]<180) { //DelaymSec(200); Soft_Left(); DelaymSec(50); } else if(sen_dat[0]<190) { Right(); DelaymSec(50); } else { Back(); DelaymSec(50); } if(sen_dat[2]>170) { vTaskResume(xforward); } } } }
bool Rectangle::Intersect(const Rectangle& other) const { return (Left() < other.Right()) && (Right() > other.Left()) && (Top() < other.Bottom()) && (Bottom() > other.Top()); }
bool BoundConjunctiveConstraint::Subsume(BoundConstraint* that) const { BoundConstraint* left = Left(); BoundConstraint* right = Right(); if (that->IsBinaryConstraint()) { BoundBinaryConstraint* thatBinaryConstraint = static_cast<BoundBinaryConstraint*>(that); BoundConstraint* thatLeft = thatBinaryConstraint->Left(); BoundConstraint* thatRight = thatBinaryConstraint->Right(); bool leftSubsumeThatLeft = left->Subsume(thatLeft); bool rightSubsumeThatLeft = right->Subsume(thatLeft); bool leftSubsumeThatRight = left->Subsume(thatRight); bool rightSubsumeThatRight = right->Subsume(thatRight); bool leftOrRightSubsumeThatLeft = leftSubsumeThatLeft || rightSubsumeThatLeft; bool leftOrRightSubsumeThatRight = leftSubsumeThatRight || rightSubsumeThatRight; if (that->IsConjunctiveConstraint()) { return leftOrRightSubsumeThatLeft && leftOrRightSubsumeThatRight; } else if (that->IsDisjunctiveConstraint()) { return leftOrRightSubsumeThatLeft || leftOrRightSubsumeThatRight; } else // assert(false) { return false; } } else { bool leftSubsumeThat = left->Subsume(that); bool righSubsumeThat = right->Subsume(that); return leftSubsumeThat || righSubsumeThat; } }
main () { freopen ("os.in", "r", stdin); // freopen ("os.out", "w", stdout); FILE *out = fopen("os.out", "w"); int m, n, a, b; item *T, *R, *A, *B, *C; scanf("%ld%ld", &m, &n); for (int i = 0; i < n; i++) { scanf ("%ld%ld", &a, &b); process(beg, end, a, b); process(end, beg, a, b); split(beg, B, C, b); T = Right(B, a, b); if(T)remove(end, T->pr->x, T->pr), remove(B, T->x, T); merge(beg, B, C); T = new item(a, b, 0); R = new item(b, a, T); T->pr = R; insert(beg, T); insert(end, R); } int res = gocount(beg); fprintf(out, "%ld\n", res); return 0; }
void LeftistHeap::Merge (MergeablePriorityQueue& queue) { LeftistHeap& arg = dynamic_cast<LeftistHeap&> (queue); if (IsEmpty ()) SwapContents (arg); else if (!arg.IsEmpty ()) { if (*key > *arg.key) SwapContents (arg); Right ().Merge (arg); if (Left ().nullPathLength < Right ().nullPathLength) Swap (left, right); nullPathLength = 1 + Min (Left ().nullPathLength, Right ().nullPathLength); } }
void CText::DrawHotPoints(CDC *pDC) { LOGPEN tLogPen; tLogPen.lopnColor=RGB(0,0,0); tLogPen.lopnStyle=PS_DOT; tLogPen.lopnWidth.x=1; CPen tPen; tPen.CreatePenIndirect(&tLogPen); CPen *pOldPen=(CPen *)pDC->SelectObject(&tPen); CBrush *pOldBrush=(CBrush *)pDC->SelectStockObject(NULL_BRUSH); pDC->SetROP2(R2_NOTXORPEN); long x1,y1,x2,y2; UPtoLP(Left()-DELTA,Top()-DELTA,&x1,&y1); UPtoLP(Right()+DELTA,Bottom()+DELTA,&x2,&y2); pDC->Rectangle(x1,y1,x2,y2); /* pDC->SelectStockObject(GRAY_BRUSH); pDC->SelectStockObject(NULL_PEN); pDC->SetROP2(R2_NOT); long x5,y5,x6,y6; UPtoLP((m_lx1+m_lx2)/2,m_ly1-DELTA,&x5,&y5); UPtoLP((m_lx1+m_lx2)/2,m_ly2+DELTA,&x6,&y6); DrawHotPoint(pDC,x5,y5); DrawHotPoint(pDC,x6,y6); */ pDC->SetROP2(R2_COPYPEN); pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); pDC->SelectObject(pOldBrush); }
/** Function that takes in vector of Trash objects and openCV Mat image @param trash std::vector<Trash> @param &frame cv::Mat @return void */ void drawObject(std::vector<Trash> trash, Mat &frame) { for (int i = 0; i < trash.size(); i++) { int distance = trash.at(i).getDistance(); int angle = trash.at(i).getAngle(); cv::circle(frame,cv::Point(trash.at(i).getXPos(),trash.at(i).getYPos()),5,cv::Scalar(0,0,255)); cv::putText(frame,intToString(trash.at(i).getXPos())+ " , " + intToString(trash.at(i).getYPos()),cv::Point(trash.at(i).getXPos(), trash.at(i).getYPos()+20),1,1,Scalar(0,255,0)); cv::putText(frame,"Distance: "+ intToString(trash.at(i).getDistance()) + " cm",cv::Point(trash.at(i).getXPos()+10,trash.at(i).getYPos()-10),1,1,trash.at(i).getColor()); cv::putText(frame,trash.at(i).getType(),cv::Point(trash.at(i).getXPos(),trash.at(i).getYPos()-30),1,2,trash.at(i).getColor()); cv::putText(frame,"Angle: "+ intToString(trash.at(i).getAngle()) + " degrees",cv::Point(trash.at(i).getXPos()+5,trash.at(i).getYPos()+10),1,1,trash.at(i).getColor()); ROS_INFO("\n\n\t\t\t\tDistance: %i Angle: %i", distance, angle); if (pickupZone(trash.at(i).getXPos())) { ROS_INFO("Trash in pickup zone"); } else if (Left(trash.at(i).getXPos())) { ROS_INFO("Trash detected to the left of pickup zone"); } else if (Right(trash.at(i).getXPos())) { ROS_INFO("Trash detected to the right of pickup zone"); } } }
/** * @function MaxHeapify */ void MaxHeapify( std::vector<int> &_A, int _i ) { int heapSize = _A.size(); int largest; int temp; int l = Left(_i); int r = Right(_i); if( l < heapSize && _A[l] > _A[_i] ) { largest = l; } else { largest = _i; } if( r < heapSize && _A[r] > _A[largest] ) { largest = r; } if( largest != _i ) { // Exchange temp = _A[_i]; _A[_i] = _A[largest]; _A[largest] = temp; MaxHeapify( _A, largest ); } }
bool WString::ReplaceOnce(const WString &findWhat,const WString &replaceWith) { int pos = Find(findWhat); if (pos == -1) return false; (*this) = Left(pos)+replaceWith+Right(pos+replaceWith.GetLength()); return true; }
WString WString::TrimLeft(wchar_t *trimChars) const { const wchar_t *proStr = GetString(); int p = 0; while (proStr[p] && wcschr(trimChars,proStr[p]!= NULL)) p++; return Right(p); }
void TextDisplay::ShowCaret () { if (Interactor::ValidCanvas(canvas) && caretline >= topline && caretline <= bottomline ) { IntCoord l = Left(caretline, caretindex); IntCoord r = Right(caretline, caretindex); IntCoord b = Base(caretline); IntCoord t = Top(caretline); if (l >= xmin && r <= xmax) { switch (caretstyle) { case NoCaret: break; case DefaultCaret: case BarCaret: painter->FillRect(canvas, l, b, l, t); break; case UnderscoreCaret: painter->FillRect(canvas, l, b, r, b+1); break; case OutlineCaret: painter->Rect(canvas, l, b, r, t); break; } } } }
void VUMeter::drawBorder(QPainter *painter) { painter->save(); QColor light = Qt::white; QColor dark = colorBg.darker(140); painter->setPen(QPen(colorBg, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); QLinearGradient linGrad(5, 250, 10, 250); linGrad.setColorAt(0, light); linGrad.setColorAt(1, colorBg); linGrad.setSpread(QGradient::PadSpread); painter->setBrush(linGrad); QRectF border(5, 5, 90, 530); painter->drawRoundRect(border, 30, 5); QLinearGradient linGrad1(85, 250, 95, 250); linGrad1.setColorAt(0, colorBg); linGrad1.setColorAt(1, dark); linGrad1.setSpread(QGradient::PadSpread); painter->setBrush(linGrad1); QRectF border1(20, 5, 75, 530); painter->drawRoundRect(border1, 30, 5); //绘制左右文字 painter->setPen(QPen(colorValue, 2)); QRectF Left(20, 505, 25, 20); QRectF Right(55, 505, 25, 20); QFont valFont("Arial", 12, QFont::Bold); painter->setFont(valFont); painter->drawText(Left, Qt::AlignCenter, "左"); painter->drawText(Right, Qt::AlignCenter, "右"); painter->restore(); }
inline bool IsCollidedRect(const cRectf& rect) { return (!((Right()<rect.Left()) ||(Left()>rect.Right()) ||(Top()>rect.Bottom()) ||(Bottom()<rect.Top()))); }
StrPP& StrPP::Justify(char type, int len, char mode) { if(mode&TRIM) Trim(); // delete outter whitespace if(strLen >= len && !(mode&CLIP)) // check for out-of-bounds return *this; if(strLen > len && (mode&CLIP)) // check for clipping { if(type == LEFT) Left(len); else if(type == CENTER) Mid((strLen-len)/2, len); else if(type == RIGHT) Right(len); return *this; // return clipped string } if(type == LEFT) *this = *this + StrPP(' ', len-strLen); else if(type == CENTER) *this = StrPP(' ', (len-strLen)/2) + *this + StrPP(' ', len - (len+strLen)/2); else if(type == RIGHT) *this = StrPP(' ', len-strLen) + *this; strLen = strlen(strPtr); return *this; // return normal string }
CBSString CBSString::SkipSpace() { CBSString ct; ct = SpanIncluding(separators); // skip white space return (Right(GetLength() - ct.GetLength())); }
/* * display_tape() shows the local area of the tape around the head. */ void display_tape(int nLeft) { int pos; static int count = 0; for(pos = 0; pos < nLeft; pos++) { putchar(' '); } putchar('v'); putchar('\n'); for(pos = 0; pos < nLeft; pos++) { Left(); } for(pos = 0; pos < 79; pos++) { putchar(tape->symbol); Right(); } for(pos = 0; pos <(79 - nLeft); pos++) { Left(); } putchar('\n'); ++count; }
void ToStruct(JOYSTICK_FEATURE& feature) const { feature.name = new char[m_name.length() + 1]; feature.type = m_type; switch (m_type) { case JOYSTICK_FEATURE_TYPE_SCALAR: Primitive().ToStruct(feature.scalar.primitive); break; case JOYSTICK_FEATURE_TYPE_ANALOG_STICK: Up().ToStruct(feature.analog_stick.up); Down().ToStruct(feature.analog_stick.down); Right().ToStruct(feature.analog_stick.right); Left().ToStruct(feature.analog_stick.left); break; case JOYSTICK_FEATURE_TYPE_ACCELEROMETER: PositiveX().ToStruct(feature.accelerometer.positive_x); PositiveY().ToStruct(feature.accelerometer.positive_y); PositiveZ().ToStruct(feature.accelerometer.positive_z); break; case JOYSTICK_FEATURE_TYPE_MOTOR: Primitive().ToStruct(feature.motor.primitive); break; default: break; } std::strcpy(feature.name, m_name.c_str()); }
int main() { COORD pos; HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); int i, leftB, rightB, upB, downB; leftB = 11; rightB = 67; upB = 11; downB = 13; pos.Y = 12; pos.X = 66; for (i = 0; i < 12; i++) { pos = Left (pos, leftB); leftB--; pos = Up (pos, upB); upB--; pos = Right (pos, rightB); rightB++; pos = Down (pos, downB); downB++; } pos = Left (pos, leftB); leftB--; if (leftB == 0) { printf("*"); } pos.X = 0; pos.Y = 25; SetConsoleCursorPosition(hConsole, pos); SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); return 0; }
TBool CPage::KeyEvent(int aKeyCode) { ASSERT(iLayout); TBool result = ETrue; switch(aKeyCode) { case EKeyDevice3: Execute(); break; case EKeyLeftArrow: Left(); break; case EKeyRightArrow: Right(); break; case EKeyUpArrow: Up(); break; case EKeyDownArrow: Down(); break; default: result = EFalse; break; } return result; }
// Collision bool Sprite::CollisionBoundingBox(System::Graphics::Sprite* Other, int offset){ if (Bottom() - Other->Top() <= offset) return false; if (Other->Bottom() - Top() <= offset) return false; if (Right() - Other->Left() <= offset) return false; if (Other->Right() - Left() <= offset) return false; return true; }
menu_t *MenuProcessButtonCmd(menu_t *menu, int cmd) { if (AnyButton(cmd) || (!MenuTypeLeftRightMoves(menu->type) && (Left(cmd) || Right(cmd)))) { menu_t *subMenu = &menu->u.normal.subMenus[menu->u.normal.index]; switch (subMenu->type) { case MENU_TYPE_NORMAL: case MENU_TYPE_OPTIONS: case MENU_TYPE_CAMPAIGNS: case MENU_TYPE_KEYS: return subMenu; case MENU_TYPE_CAMPAIGN_ITEM: MenuLoadCampaign(&subMenu->u.campaign); return subMenu; // caller will check if subMenu type is CAMPAIGN_ITEM case MENU_TYPE_BACK: return menu->parentMenu; case MENU_TYPE_QUIT: return subMenu; // caller will check if subMenu type is QUIT case MENU_TYPE_RETURN: return subMenu; default: MenuActivate(subMenu, cmd); break; } } return NULL; }
// return : "txt" CString CFileString::GetFileExt() { int iLen = GetLength(), iLoc = ReverseFind('.'); if (iLoc == -1) return ""; return Right(iLen - iLoc - 1); }
/** * <param name="gameTime"></param> * <param name="horizontalAxis_"> value between -1.0 and 1.0 </param> * <param name="verticalAxis_"> value between -1.0 and 1.0 </param> * <param name="rollAxis_"> value between -1.0 and 1.0 </param> * <param name="zoom"> zoom value </param> */ void ArcBallCameraController::HandleControls(const GameTime& gameTime_, float rightAxis_, float upAxis_, float forwardAxis_, float horizontalOrbit_, float verticalOrbit_, float /*rollOrbit_*/, float zoom_) { float r = rightAxis_ * gameTime_.FrameTime() * m_fInputDisplacementRate; float u = upAxis_ * gameTime_.FrameTime() * m_fInputDisplacementRate; float f = forwardAxis_ * gameTime_.FrameTime() * m_fInputDisplacementRate; float dH = horizontalOrbit_ * gameTime_.FrameTime() * m_fInputTurnRate; float dV = verticalOrbit_ * gameTime_.FrameTime() * m_fInputTurnRate; //float dR = rollOrbit_ * gameTime_.FrameTime() * m_fInputTurnRate; if ( dH != 0.0f ) RotateTargetRight(dH);//OrbitUp( dH ); if ( dV != 0.0f ) RotateTargetUp(dV); //OrbitRight( dV ); //if ( dR != 0.0f ) RotateClockwise( dR ); //decrease distance to target m_fDistance += zoom_ * gameTime_.FrameTime() * m_fInputDistanceRate; if ( m_fDistance < 0.001f ) m_fDistance = 0.001f; if ( r != 0.0f || u != 0.0f || f != 0.0f ) { Vector3F pos = Target() + (Right() * r) + (Up() * u) + (Direction() * f); Target(pos); /*Vector3F target = pos; target.Normalize(); target *= m_fDistance; target += pos; SetCamera(pos, target, Up());*/ } }
void Maxheap(int Arr[],int ind){ //printf("came\n"); int lt=Left(ind)-1; //printf(" ld %d\n",lt); int largest; int rt=Right(ind)-1; //printf(" rd %d\n",rt); //printf(" heapsize %d\n",Hesize); if(lt<=Hesize) { //printf("if ld %d\n",lt); if(Arr[lt]>Arr[ind]){ largest=lt;} } else largest=ind; if(rt<=Hesize ){ //printf("if rd %d\n",rt); if(Arr[rt]>Arr[largest]) { largest=rt;} } if(largest!=ind) { Exg(ind,largest); Maxheap(Arr,largest); } }
/* * Maintain the heap order property (parent is smaller than children) which * may only be violated at ELM downwards. Assumes caller has locked the heap. */ static void _heap_ify_down(heap * hp, heap_node * elm) { heap_node *kid; int left = 0, right = 0; int true = 1; while (true) { left = Left(elm->id); right = Right(elm->id); if (!_heap_node_exist(hp, left)) { /* At the bottom of the heap (no child). */ assert(!_heap_node_exist(hp, right)); break; } else if (!_heap_node_exist(hp, right)) /* Only left child exists. */ kid = hp->nodes[left]; else { if (hp->nodes[right]->key < hp->nodes[left]->key) kid = hp->nodes[right]; else kid = hp->nodes[left]; } if (elm->key <= kid->key) break; _heap_swap_element(hp, kid, elm); } }
// Precondition: Valid parameters have been passed to the function. // Postcondition: The function MIN-HEAPIFY, as outlined in // chapter 6 of "Introduction to Algorithms", by // Thomas Cormen has been executed. void MinPriority::minHeapify(MinPriority* A, int i) { int smallest = i; int l = Left(i); int r = Right(i); if(l < A->heapSize && A->m_array[l]->m_key < A->m_array[smallest]->m_key) { smallest = l; } if(r < A->heapSize && A->m_array[r]->m_key < A->m_array[smallest]->m_key) { smallest = r; } if(smallest != i) { // Get the nodes to be swapped MinPriorityNode *smallestNode = A->m_array[smallest]; MinPriorityNode * currentNode = A->m_array[i]; // Swap node positions A->m_position[smallestNode->m_value] = i; A->m_position[currentNode->m_value] = smallest; // Swap nodes A->swapMinPriorityNode(&A->m_array[smallest], &A->m_array[i]); minHeapify(A, smallest); } }
void TextObject::Update(float delta) { if (Game::GetInstance()->GetIsLevelEditMode()) { m_alpha = 1.0f; return; } // get the distance to the player const Player * player = GameObjectManager::Instance()->GetPlayer(); if (player) { // check is the player inside the bounds of this sprite // if so then fade alpha if (player->X() > Left() && player->X() < Right() && player->Y() > Bottom() && player->Y() < Top()) { if (!mHasShown) { mHasShown = true; AudioManager::Instance()->PlaySoundEffect("boomy_intro.wav"); } } if (mHasShown && mTimeToShow > 0.0f) { if (m_alpha < 1.0f) { m_alpha += 1.4f * delta; } else { m_alpha = 1.0f; } } else { if (m_alpha > 0.0f) { m_alpha -= 0.9f * delta; } else { m_alpha = 0.0f; } } } if (mHasShown) { mTimeToShow -= delta; } UpdateToParent(); }
long CGsRegisterWriteListView::OnSize(unsigned int, unsigned int, unsigned int) { auto clientRect = GetClientRect(); Framework::Win32::CRect packetsTreeViewRect(0, Framework::Win32::PointsToPixels(30), clientRect.Right(), clientRect.Bottom()); m_packetsTreeView->SetSizePosition(packetsTreeViewRect); return TRUE; }